@qvac/inference 0.19.1 → 0.20.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 (137) hide show
  1. package/NOTICE +43 -11
  2. package/dist/api/audio-gen.d.ts +42 -1
  3. package/dist/api/audio-gen.js +137 -51
  4. package/dist/api/index.d.ts +2 -1
  5. package/dist/api/index.js +2 -1
  6. package/dist/api/text-to-speech.d.ts +31 -4
  7. package/dist/api/text-to-speech.js +117 -21
  8. package/dist/api/vector-index.d.ts +142 -0
  9. package/dist/api/vector-index.js +168 -0
  10. package/dist/api/world.d.ts +2 -2
  11. package/dist/errors/index.d.ts +12 -0
  12. package/dist/errors/index.js +21 -0
  13. package/dist/handlers/vector-index.d.ts +2 -0
  14. package/dist/handlers/vector-index.js +40 -0
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.js +1 -1
  17. package/dist/models/registry/models.d.ts +351 -12
  18. package/dist/models/registry/models.js +2271 -1957
  19. package/dist/models/registry/resource-profiles.js +135 -0
  20. package/dist/plugins/builtin/audiogen-ggml/ops/audio-edit-stream.d.ts +2 -0
  21. package/dist/plugins/builtin/audiogen-ggml/ops/audio-edit-stream.js +65 -0
  22. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-input.d.ts +9 -1
  23. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-input.js +24 -7
  24. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-run.d.ts +46 -0
  25. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-run.js +218 -0
  26. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.d.ts +1 -1
  27. package/dist/plugins/builtin/audiogen-ggml/ops/audio-gen-stream.js +56 -225
  28. package/dist/plugins/builtin/audiogen-ggml/ops/audio-understand.d.ts +8 -0
  29. package/dist/plugins/builtin/audiogen-ggml/ops/audio-understand.js +28 -0
  30. package/dist/plugins/builtin/audiogen-ggml/plugin.d.ts +248 -0
  31. package/dist/plugins/builtin/audiogen-ggml/plugin.js +17 -1
  32. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.d.ts +5 -2
  33. package/dist/plugins/builtin/bci-whispercpp-transcription/plugin.js +1 -2
  34. package/dist/plugins/builtin/ggml-ocr/plugin.d.ts +1 -1
  35. package/dist/plugins/builtin/ggml-ocr/plugin.js +1 -2
  36. package/dist/plugins/builtin/llamacpp-completion/ops/batch-completion-stream.js +6 -4
  37. package/dist/plugins/builtin/llamacpp-completion/ops/cache-logger.d.ts +1 -2
  38. package/dist/plugins/builtin/llamacpp-completion/ops/cache-logger.js +0 -4
  39. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.d.ts +1 -0
  40. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stats.js +3 -0
  41. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.d.ts +9 -0
  42. package/dist/plugins/builtin/llamacpp-completion/ops/completion-stream.js +96 -89
  43. package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.d.ts +0 -1
  44. package/dist/plugins/builtin/llamacpp-completion/ops/context-overflow.js +0 -31
  45. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.d.ts +40 -24
  46. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-session.js +187 -123
  47. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-state.d.ts +11 -4
  48. package/dist/plugins/builtin/llamacpp-completion/ops/kv-cache-state.js +18 -16
  49. package/dist/plugins/builtin/llamacpp-completion/plugin.d.ts +8 -4
  50. package/dist/plugins/builtin/llamacpp-completion/plugin.js +1 -2
  51. package/dist/plugins/builtin/llamacpp-embedding/plugin.d.ts +1 -2
  52. package/dist/plugins/builtin/llamacpp-embedding/plugin.js +2 -38
  53. package/dist/plugins/builtin/llamacpp-embedding/transform.d.ts +9 -0
  54. package/dist/plugins/builtin/llamacpp-embedding/transform.js +42 -0
  55. package/dist/plugins/builtin/nmtcpp-translation/plugin.d.ts +1 -1
  56. package/dist/plugins/builtin/nmtcpp-translation/plugin.js +1 -2
  57. package/dist/plugins/builtin/parakeet-transcription/plugin.d.ts +1 -1
  58. package/dist/plugins/builtin/parakeet-transcription/plugin.js +1 -2
  59. package/dist/plugins/builtin/sdcpp-generation/ops/video.d.ts +1 -0
  60. package/dist/plugins/builtin/sdcpp-generation/ops/video.js +8 -2
  61. package/dist/plugins/builtin/sdcpp-generation/plugin.d.ts +9 -4
  62. package/dist/plugins/builtin/sdcpp-generation/plugin.js +51 -19
  63. package/dist/plugins/builtin/tts-ggml/ops/cancel-binding.d.ts +29 -0
  64. package/dist/plugins/builtin/tts-ggml/ops/cancel-binding.js +66 -0
  65. package/dist/plugins/builtin/tts-ggml/ops/parler-options.js +10 -0
  66. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.d.ts +3 -5
  67. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech-stream.js +143 -28
  68. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.d.ts +5 -2
  69. package/dist/plugins/builtin/tts-ggml/ops/text-to-speech.js +182 -66
  70. package/dist/plugins/builtin/tts-ggml/plugin.d.ts +267 -22
  71. package/dist/plugins/builtin/tts-ggml/plugin.js +94 -35
  72. package/dist/plugins/builtin/whispercpp-transcription/plugin.d.ts +1 -1
  73. package/dist/plugins/builtin/whispercpp-transcription/plugin.js +1 -2
  74. package/dist/plugins/index.d.ts +1 -1
  75. package/dist/plugins/index.js +1 -1
  76. package/dist/plugins/ops/load-model.js +22 -2
  77. package/dist/plugins/ops/translate.js +58 -12
  78. package/dist/plugins/ops/translatepsy-utils.d.ts +17 -0
  79. package/dist/plugins/ops/translatepsy-utils.js +32 -0
  80. package/dist/plugins/registry.d.ts +15 -0
  81. package/dist/plugins/registry.js +133 -15
  82. package/dist/plugins/turbovec-backend.d.ts +17 -0
  83. package/dist/plugins/turbovec-backend.js +99 -0
  84. package/dist/registry.js +4 -0
  85. package/dist/resources/model-fit/native-probe/advisory-fit.d.ts +46 -0
  86. package/dist/resources/model-fit/native-probe/advisory-fit.js +214 -0
  87. package/dist/resources/model-fit/native-probe/create-llama-fit-request.d.ts +26 -0
  88. package/dist/resources/model-fit/native-probe/create-llama-fit-request.js +171 -0
  89. package/dist/resources/model-fit/native-probe/run-in-process-fit.d.ts +42 -0
  90. package/dist/resources/model-fit/native-probe/run-in-process-fit.js +192 -0
  91. package/dist/resources/model-fit/native-probe/run-isolated-fit.d.ts +70 -0
  92. package/dist/resources/model-fit/native-probe/run-isolated-fit.js +372 -0
  93. package/dist/runtime/env.d.ts +2 -0
  94. package/dist/runtime/env.js +9 -2
  95. package/dist/runtime/lifecycle.js +2 -0
  96. package/dist/runtime/model-registry.d.ts +3 -1
  97. package/dist/runtime/model-registry.js +2 -1
  98. package/dist/runtime/request-context.js +17 -0
  99. package/dist/runtime/vector-index-backend.d.ts +25 -0
  100. package/dist/runtime/vector-index-backend.js +1 -0
  101. package/dist/runtime/vector-index-registry.d.ts +76 -0
  102. package/dist/runtime/vector-index-registry.js +161 -0
  103. package/dist/schemas/assess-model-fit.d.ts +44 -0
  104. package/dist/schemas/assess-model-fit.js +40 -0
  105. package/dist/schemas/audio-gen.d.ts +479 -4
  106. package/dist/schemas/audio-gen.js +376 -17
  107. package/dist/schemas/batch-completion-stream.d.ts +7 -0
  108. package/dist/schemas/batch-completion-stream.js +5 -3
  109. package/dist/schemas/common.d.ts +749 -15
  110. package/dist/schemas/common.js +8 -1
  111. package/dist/schemas/completion-event.d.ts +11 -1
  112. package/dist/schemas/completion-event.js +3 -0
  113. package/dist/schemas/completion-stream.d.ts +20 -0
  114. package/dist/schemas/completion-stream.js +41 -4
  115. package/dist/schemas/config.d.ts +48 -30
  116. package/dist/schemas/errors.d.ts +4 -0
  117. package/dist/schemas/errors.js +22 -0
  118. package/dist/schemas/index.d.ts +1 -0
  119. package/dist/schemas/index.js +1 -0
  120. package/dist/schemas/llamacpp-config.d.ts +4 -8
  121. package/dist/schemas/llamacpp-config.js +4 -4
  122. package/dist/schemas/load-model.d.ts +2503 -139
  123. package/dist/schemas/model-config-schemas.d.ts +228 -5
  124. package/dist/schemas/plugin.d.ts +10 -0
  125. package/dist/schemas/sdcpp-config.d.ts +221 -4
  126. package/dist/schemas/sdcpp-config.js +128 -22
  127. package/dist/schemas/text-to-speech.d.ts +780 -19
  128. package/dist/schemas/text-to-speech.js +298 -44
  129. package/dist/schemas/transcription-config.js +7 -4
  130. package/dist/schemas/vector-index.d.ts +194 -0
  131. package/dist/schemas/vector-index.js +185 -0
  132. package/dist/utils/addon-responses.d.ts +29 -3
  133. package/dist/utils/aggregate-events.d.ts +3 -1
  134. package/dist/utils/aggregate-events.js +7 -1
  135. package/dist/utils/tts-stats.d.ts +15 -11
  136. package/dist/utils/tts-stats.js +33 -11
  137. package/package.json +28 -25
@@ -0,0 +1,194 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Storage modes of the native vector index. The `TURBOVEC_*` modes are the
4
+ * quantised TurboVec formats and require a dimension divisible by 8 and no
5
+ * greater than 1024. `F32`, `Q8` and `Q4` are the generic stores of the same
6
+ * addon and accept any dimension. Declared as a name-to-value map, like
7
+ * `ModelType`, so the contract carries the names for generated clients.
8
+ */
9
+ export declare const VectorIndexStorage: {
10
+ readonly F32: "f32";
11
+ readonly Q8: "q8";
12
+ readonly Q4: "q4";
13
+ readonly TURBOVEC_Q4: "turbovec-q4";
14
+ readonly TURBOVEC_Q2: "turbovec-q2";
15
+ };
16
+ export type VectorIndexStorage = (typeof VectorIndexStorage)[keyof typeof VectorIndexStorage];
17
+ export declare const vectorIndexStorageSchema: z.ZodEnum<{
18
+ readonly F32: "f32";
19
+ readonly Q8: "q8";
20
+ readonly Q4: "q4";
21
+ readonly TURBOVEC_Q4: "turbovec-q4";
22
+ readonly TURBOVEC_Q2: "turbovec-q2";
23
+ }>;
24
+ export declare const DEFAULT_VECTOR_INDEX_STORAGE: VectorIndexStorage;
25
+ /**
26
+ * The native index pads short search result rows with UINT64_MAX, so that
27
+ * value can never be used as an id.
28
+ */
29
+ export declare const VECTOR_ID_RESERVED = "18446744073709551615";
30
+ /**
31
+ * An id as it travels over the wire: a decimal string holding an unsigned
32
+ * 64-bit integer, or a non-negative safe integer. Results always use the
33
+ * string form so values above 2^53 survive JSON.
34
+ */
35
+ export declare const vectorIdWireSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
36
+ export type VectorIdWire = z.infer<typeof vectorIdWireSchema>;
37
+ /** An id as callers pass it. A `bigint` is converted to its decimal string before sending. */
38
+ export type VectorId = VectorIdWire | bigint;
39
+ export declare const createVectorIndexParamsSchema: z.ZodObject<{
40
+ dim: z.ZodNumber;
41
+ storage: z.ZodDefault<z.ZodEnum<{
42
+ readonly F32: "f32";
43
+ readonly Q8: "q8";
44
+ readonly Q4: "q4";
45
+ readonly TURBOVEC_Q4: "turbovec-q4";
46
+ readonly TURBOVEC_Q2: "turbovec-q2";
47
+ }>>;
48
+ }, z.core.$strip>;
49
+ export declare const loadVectorIndexParamsSchema: z.ZodObject<{
50
+ path: z.ZodString;
51
+ }, z.core.$strip>;
52
+ export declare const vectorIndexAddParamsSchema: z.ZodObject<{
53
+ ids: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
54
+ vectors: z.ZodArray<z.ZodArray<z.ZodNumber>>;
55
+ }, z.core.$strip>;
56
+ export declare const vectorIndexSearchParamsSchema: z.ZodObject<{
57
+ queries: z.ZodArray<z.ZodArray<z.ZodNumber>>;
58
+ k: z.ZodNumber;
59
+ }, z.core.$strip>;
60
+ export declare const vectorIndexIdsParamsSchema: z.ZodObject<{
61
+ ids: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
62
+ }, z.core.$strip>;
63
+ export declare const vectorIndexWriteParamsSchema: z.ZodObject<{
64
+ path: z.ZodString;
65
+ }, z.core.$strip>;
66
+ export declare const vectorIndexRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
67
+ dim: z.ZodNumber;
68
+ storage: z.ZodDefault<z.ZodEnum<{
69
+ readonly F32: "f32";
70
+ readonly Q8: "q8";
71
+ readonly Q4: "q4";
72
+ readonly TURBOVEC_Q4: "turbovec-q4";
73
+ readonly TURBOVEC_Q2: "turbovec-q2";
74
+ }>>;
75
+ operation: z.ZodLiteral<"create">;
76
+ type: z.ZodLiteral<"vectorIndex">;
77
+ }, z.core.$strip>, z.ZodObject<{
78
+ path: z.ZodString;
79
+ operation: z.ZodLiteral<"load">;
80
+ type: z.ZodLiteral<"vectorIndex">;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ ids: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
83
+ vectors: z.ZodArray<z.ZodArray<z.ZodNumber>>;
84
+ operation: z.ZodLiteral<"add">;
85
+ indexId: z.ZodString;
86
+ type: z.ZodLiteral<"vectorIndex">;
87
+ }, z.core.$strip>, z.ZodObject<{
88
+ queries: z.ZodArray<z.ZodArray<z.ZodNumber>>;
89
+ k: z.ZodNumber;
90
+ operation: z.ZodLiteral<"search">;
91
+ indexId: z.ZodString;
92
+ type: z.ZodLiteral<"vectorIndex">;
93
+ }, z.core.$strip>, z.ZodObject<{
94
+ ids: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
95
+ operation: z.ZodLiteral<"remove">;
96
+ indexId: z.ZodString;
97
+ type: z.ZodLiteral<"vectorIndex">;
98
+ }, z.core.$strip>, z.ZodObject<{
99
+ ids: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
100
+ operation: z.ZodLiteral<"contains">;
101
+ indexId: z.ZodString;
102
+ type: z.ZodLiteral<"vectorIndex">;
103
+ }, z.core.$strip>, z.ZodObject<{
104
+ path: z.ZodString;
105
+ operation: z.ZodLiteral<"write">;
106
+ indexId: z.ZodString;
107
+ type: z.ZodLiteral<"vectorIndex">;
108
+ }, z.core.$strip>, z.ZodObject<{
109
+ operation: z.ZodLiteral<"dispose">;
110
+ indexId: z.ZodString;
111
+ type: z.ZodLiteral<"vectorIndex">;
112
+ }, z.core.$strip>], "operation">;
113
+ export declare const vectorIndexHitSchema: z.ZodObject<{
114
+ id: z.ZodString;
115
+ score: z.ZodNumber;
116
+ }, z.core.$strip>;
117
+ export declare const vectorIndexResponseSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
118
+ type: z.ZodLiteral<"vectorIndex">;
119
+ operation: z.ZodLiteral<"create">;
120
+ indexId: z.ZodString;
121
+ dim: z.ZodNumber;
122
+ storage: z.ZodEnum<{
123
+ readonly F32: "f32";
124
+ readonly Q8: "q8";
125
+ readonly Q4: "q4";
126
+ readonly TURBOVEC_Q4: "turbovec-q4";
127
+ readonly TURBOVEC_Q2: "turbovec-q2";
128
+ }>;
129
+ length: z.ZodNumber;
130
+ }, z.core.$strip>, z.ZodObject<{
131
+ type: z.ZodLiteral<"vectorIndex">;
132
+ operation: z.ZodLiteral<"load">;
133
+ indexId: z.ZodString;
134
+ dim: z.ZodNumber;
135
+ storage: z.ZodOptional<z.ZodEnum<{
136
+ readonly F32: "f32";
137
+ readonly Q8: "q8";
138
+ readonly Q4: "q4";
139
+ readonly TURBOVEC_Q4: "turbovec-q4";
140
+ readonly TURBOVEC_Q2: "turbovec-q2";
141
+ }>>;
142
+ length: z.ZodNumber;
143
+ }, z.core.$strip>, z.ZodObject<{
144
+ type: z.ZodLiteral<"vectorIndex">;
145
+ operation: z.ZodLiteral<"add">;
146
+ length: z.ZodNumber;
147
+ }, z.core.$strip>, z.ZodObject<{
148
+ type: z.ZodLiteral<"vectorIndex">;
149
+ operation: z.ZodLiteral<"search">;
150
+ results: z.ZodArray<z.ZodArray<z.ZodObject<{
151
+ id: z.ZodString;
152
+ score: z.ZodNumber;
153
+ }, z.core.$strip>>>;
154
+ }, z.core.$strip>, z.ZodObject<{
155
+ type: z.ZodLiteral<"vectorIndex">;
156
+ operation: z.ZodLiteral<"remove">;
157
+ removed: z.ZodArray<z.ZodBoolean>;
158
+ length: z.ZodNumber;
159
+ }, z.core.$strip>, z.ZodObject<{
160
+ type: z.ZodLiteral<"vectorIndex">;
161
+ operation: z.ZodLiteral<"contains">;
162
+ present: z.ZodArray<z.ZodBoolean>;
163
+ }, z.core.$strip>, z.ZodObject<{
164
+ type: z.ZodLiteral<"vectorIndex">;
165
+ operation: z.ZodLiteral<"write">;
166
+ path: z.ZodString;
167
+ }, z.core.$strip>, z.ZodObject<{
168
+ type: z.ZodLiteral<"vectorIndex">;
169
+ operation: z.ZodLiteral<"dispose">;
170
+ disposed: z.ZodBoolean;
171
+ }, z.core.$strip>], "operation">;
172
+ export type VectorIndexRequest = z.input<typeof vectorIndexRequestSchema>;
173
+ export type VectorIndexResponse = z.infer<typeof vectorIndexResponseSchema>;
174
+ export type VectorIndexHit = z.infer<typeof vectorIndexHitSchema>;
175
+ export type CreateVectorIndexParams = z.input<typeof createVectorIndexParamsSchema>;
176
+ export type LoadVectorIndexParams = z.infer<typeof loadVectorIndexParamsSchema>;
177
+ export interface VectorIndexAddParams {
178
+ ids: VectorId[];
179
+ vectors: number[][];
180
+ }
181
+ export interface VectorIndexIdsParams {
182
+ ids: VectorId[];
183
+ }
184
+ export type VectorIndexSearchParams = {
185
+ query: number[];
186
+ k: number;
187
+ } | {
188
+ queries: number[][];
189
+ k: number;
190
+ };
191
+ export type VectorIndexWriteParams = z.infer<typeof vectorIndexWriteParamsSchema>;
192
+ export declare function toWireVectorIds(ids: readonly VectorId[]): VectorIdWire[];
193
+ /** Index of the first row whose length differs from `dim`, or -1 when every row matches. */
194
+ export declare function findVectorRowLengthMismatch(rows: readonly (readonly number[])[], dim: number): number;
@@ -0,0 +1,185 @@
1
+ import { z } from 'zod';
2
+ // ============== Storage vocabulary ==============
3
+ /**
4
+ * Storage modes of the native vector index. The `TURBOVEC_*` modes are the
5
+ * quantised TurboVec formats and require a dimension divisible by 8 and no
6
+ * greater than 1024. `F32`, `Q8` and `Q4` are the generic stores of the same
7
+ * addon and accept any dimension. Declared as a name-to-value map, like
8
+ * `ModelType`, so the contract carries the names for generated clients.
9
+ */
10
+ export const VectorIndexStorage = {
11
+ F32: 'f32',
12
+ Q8: 'q8',
13
+ Q4: 'q4',
14
+ TURBOVEC_Q4: 'turbovec-q4',
15
+ TURBOVEC_Q2: 'turbovec-q2'
16
+ };
17
+ export const vectorIndexStorageSchema = z.enum(VectorIndexStorage);
18
+ export const DEFAULT_VECTOR_INDEX_STORAGE = VectorIndexStorage.TURBOVEC_Q4;
19
+ // ============== Ids ==============
20
+ /**
21
+ * The native index pads short search result rows with UINT64_MAX, so that
22
+ * value can never be used as an id.
23
+ */
24
+ export const VECTOR_ID_RESERVED = '18446744073709551615';
25
+ const RESERVED_ID = BigInt(VECTOR_ID_RESERVED);
26
+ const VECTOR_ID_PATTERN = /^(0|[1-9][0-9]{0,19})$/;
27
+ // Zod runs every check even after the regex fails, so the range check must
28
+ // not call BigInt on a string the pattern already rejected.
29
+ const vectorIdStringSchema = z
30
+ .string()
31
+ .regex(VECTOR_ID_PATTERN, 'id must be a decimal unsigned 64-bit integer')
32
+ .refine((value) => VECTOR_ID_PATTERN.test(value) && BigInt(value) < RESERVED_ID, `id must be below ${VECTOR_ID_RESERVED}`);
33
+ const vectorIdNumberSchema = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
34
+ /**
35
+ * An id as it travels over the wire: a decimal string holding an unsigned
36
+ * 64-bit integer, or a non-negative safe integer. Results always use the
37
+ * string form so values above 2^53 survive JSON.
38
+ */
39
+ export const vectorIdWireSchema = z
40
+ .union([vectorIdStringSchema, vectorIdNumberSchema])
41
+ .meta({ title: 'VectorId' });
42
+ const vectorIdsSchema = z.array(vectorIdWireSchema).min(1, 'at least one id is required');
43
+ const vectorRowSchema = z.array(z.number()).min(1);
44
+ const vectorRowsSchema = z.array(vectorRowSchema).min(1, 'at least one vector is required');
45
+ const indexIdSchema = z.string().min(1);
46
+ const snapshotPathSchema = z.string().min(1, 'path cannot be empty');
47
+ const lengthSchema = z.number().int().min(0);
48
+ // ============== Operation params ==============
49
+ export const createVectorIndexParamsSchema = z.object({
50
+ dim: z.number().int().positive(),
51
+ storage: vectorIndexStorageSchema.default(DEFAULT_VECTOR_INDEX_STORAGE)
52
+ });
53
+ export const loadVectorIndexParamsSchema = z.object({
54
+ path: snapshotPathSchema
55
+ });
56
+ export const vectorIndexAddParamsSchema = z.object({
57
+ ids: vectorIdsSchema,
58
+ vectors: vectorRowsSchema
59
+ });
60
+ export const vectorIndexSearchParamsSchema = z.object({
61
+ queries: vectorRowsSchema,
62
+ k: z.number().int().positive()
63
+ });
64
+ export const vectorIndexIdsParamsSchema = z.object({
65
+ ids: vectorIdsSchema
66
+ });
67
+ export const vectorIndexWriteParamsSchema = z.object({
68
+ path: snapshotPathSchema
69
+ });
70
+ // ============== Requests ==============
71
+ const vectorIndexTypeField = { type: z.literal('vectorIndex') };
72
+ const handleField = { indexId: indexIdSchema };
73
+ const vectorIndexCreateRequestSchema = createVectorIndexParamsSchema.extend({
74
+ ...vectorIndexTypeField,
75
+ operation: z.literal('create')
76
+ });
77
+ const vectorIndexLoadRequestSchema = loadVectorIndexParamsSchema.extend({
78
+ ...vectorIndexTypeField,
79
+ operation: z.literal('load')
80
+ });
81
+ const vectorIndexAddRequestSchema = vectorIndexAddParamsSchema.extend({
82
+ ...vectorIndexTypeField,
83
+ ...handleField,
84
+ operation: z.literal('add')
85
+ });
86
+ const vectorIndexSearchRequestSchema = vectorIndexSearchParamsSchema.extend({
87
+ ...vectorIndexTypeField,
88
+ ...handleField,
89
+ operation: z.literal('search')
90
+ });
91
+ const vectorIndexRemoveRequestSchema = vectorIndexIdsParamsSchema.extend({
92
+ ...vectorIndexTypeField,
93
+ ...handleField,
94
+ operation: z.literal('remove')
95
+ });
96
+ const vectorIndexContainsRequestSchema = vectorIndexIdsParamsSchema.extend({
97
+ ...vectorIndexTypeField,
98
+ ...handleField,
99
+ operation: z.literal('contains')
100
+ });
101
+ const vectorIndexWriteRequestSchema = vectorIndexWriteParamsSchema.extend({
102
+ ...vectorIndexTypeField,
103
+ ...handleField,
104
+ operation: z.literal('write')
105
+ });
106
+ const vectorIndexDisposeRequestSchema = z.object({
107
+ ...vectorIndexTypeField,
108
+ ...handleField,
109
+ operation: z.literal('dispose')
110
+ });
111
+ export const vectorIndexRequestSchema = z.discriminatedUnion('operation', [
112
+ vectorIndexCreateRequestSchema,
113
+ vectorIndexLoadRequestSchema,
114
+ vectorIndexAddRequestSchema,
115
+ vectorIndexSearchRequestSchema,
116
+ vectorIndexRemoveRequestSchema,
117
+ vectorIndexContainsRequestSchema,
118
+ vectorIndexWriteRequestSchema,
119
+ vectorIndexDisposeRequestSchema
120
+ ]);
121
+ // ============== Responses ==============
122
+ export const vectorIndexHitSchema = z.object({
123
+ id: z.string(),
124
+ score: z.number()
125
+ });
126
+ const vectorIndexResponseBaseSchema = z.object(vectorIndexTypeField);
127
+ const vectorIndexCreateResponseSchema = vectorIndexResponseBaseSchema.extend({
128
+ operation: z.literal('create'),
129
+ indexId: indexIdSchema,
130
+ dim: z.number().int().positive(),
131
+ storage: vectorIndexStorageSchema,
132
+ length: lengthSchema
133
+ });
134
+ // A loaded snapshot reports its storage only when the backend can derive it;
135
+ // the native index exposes a bit width, and 4 bits is ambiguous.
136
+ const vectorIndexLoadResponseSchema = vectorIndexResponseBaseSchema.extend({
137
+ operation: z.literal('load'),
138
+ indexId: indexIdSchema,
139
+ dim: z.number().int().positive(),
140
+ storage: vectorIndexStorageSchema.optional(),
141
+ length: lengthSchema
142
+ });
143
+ const vectorIndexAddResponseSchema = vectorIndexResponseBaseSchema.extend({
144
+ operation: z.literal('add'),
145
+ length: lengthSchema
146
+ });
147
+ const vectorIndexSearchResponseSchema = vectorIndexResponseBaseSchema.extend({
148
+ operation: z.literal('search'),
149
+ results: z.array(z.array(vectorIndexHitSchema))
150
+ });
151
+ const vectorIndexRemoveResponseSchema = vectorIndexResponseBaseSchema.extend({
152
+ operation: z.literal('remove'),
153
+ removed: z.array(z.boolean()),
154
+ length: lengthSchema
155
+ });
156
+ const vectorIndexContainsResponseSchema = vectorIndexResponseBaseSchema.extend({
157
+ operation: z.literal('contains'),
158
+ present: z.array(z.boolean())
159
+ });
160
+ const vectorIndexWriteResponseSchema = vectorIndexResponseBaseSchema.extend({
161
+ operation: z.literal('write'),
162
+ path: z.string()
163
+ });
164
+ const vectorIndexDisposeResponseSchema = vectorIndexResponseBaseSchema.extend({
165
+ operation: z.literal('dispose'),
166
+ disposed: z.boolean()
167
+ });
168
+ export const vectorIndexResponseSchema = z.discriminatedUnion('operation', [
169
+ vectorIndexCreateResponseSchema,
170
+ vectorIndexLoadResponseSchema,
171
+ vectorIndexAddResponseSchema,
172
+ vectorIndexSearchResponseSchema,
173
+ vectorIndexRemoveResponseSchema,
174
+ vectorIndexContainsResponseSchema,
175
+ vectorIndexWriteResponseSchema,
176
+ vectorIndexDisposeResponseSchema
177
+ ]);
178
+ // ============== Helpers shared by the in-process and RPC clients ==============
179
+ export function toWireVectorIds(ids) {
180
+ return ids.map((id) => (typeof id === 'bigint' ? id.toString() : id));
181
+ }
182
+ /** Index of the first row whose length differs from `dim`, or -1 when every row matches. */
183
+ export function findVectorRowLengthMismatch(rows, dim) {
184
+ return rows.findIndex((row) => row.length !== dim);
185
+ }
@@ -8,6 +8,7 @@ export interface LlmStats {
8
8
  promptTokens?: number;
9
9
  generatedTokens?: number;
10
10
  avgConcurrentSeq?: number;
11
+ toolDefinitionsDropped?: number;
11
12
  backendDevice?: 'cpu' | 'gpu';
12
13
  stopReason?: 'none' | 'eos' | 'antiprompt' | 'predictionLimit' | 'sequenceLimit' | 'contextOverflow';
13
14
  }
@@ -17,17 +18,42 @@ export interface LlmResponse {
17
18
  }
18
19
  export type NmtStats = TranslationNmtcpp.RuntimeStats;
19
20
  export type NmtResponse = TranslationNmtcpp.TranslationResponse;
21
+ /**
22
+ * @qvac/tts-ggml `RuntimeStats`. Restated here rather than imported from the
23
+ * addon so a typecheck does not depend on which addon version happens to be
24
+ * installed; keep it in step with the addon's `RuntimeStats`.
25
+ */
20
26
  export interface TtsStats {
21
27
  audioDurationMs?: number;
28
+ totalTime?: number;
29
+ realTimeFactor?: number;
30
+ tokensPerSecond?: number;
22
31
  totalSamples?: number;
32
+ /** Audio8 only: codec frames generated, on a fixed 46 ms grid. */
33
+ generatedFrames?: number;
34
+ backendDevice?: number;
35
+ backendId?: number;
36
+ gpuUnsupported?: number;
23
37
  enhancerBackendDevice?: number;
24
38
  enhancerBackendId?: number;
25
39
  }
40
+ /**
41
+ * @qvac/tts-ggml `TTSOutputChunk & SentenceStreamChunkMeta`. The chunker runs
42
+ * for `runStream()` and for `run({ streamOutput: true })` alike, so the meta
43
+ * fields are populated on both paths.
44
+ */
45
+ export interface TtsOutputChunk {
46
+ outputArray: ArrayLike<number>;
47
+ /** Rate of `outputArray`; moves with `outputSampleRate` and the enhancer. */
48
+ sampleRate?: number;
49
+ chunkIndex?: number;
50
+ sentenceChunk?: string;
51
+ /** True on the final pre-chunked output; undefined when it is not known up front. */
52
+ isLast?: boolean;
53
+ }
26
54
  export interface TtsResponse {
27
55
  stats?: TtsStats;
28
- iterate(): AsyncIterable<{
29
- outputArray: ArrayLike<number>;
30
- }>;
56
+ iterate(): AsyncIterable<TtsOutputChunk>;
31
57
  }
32
58
  export interface EmbedStats {
33
59
  total_time_ms?: number;
@@ -1,10 +1,12 @@
1
- import type { CompletionError, CompletionEvent, CompletionFinal, CompletionStats, StopReason, ToolCall } from '../schemas/index.js';
1
+ import type { CompletionError, CompletionEvent, CompletionFinal, CompletionStats, StopReason, ToolCall, ToolCallError } from '../schemas/index.js';
2
2
  import { type ToolHandlerMap } from './tool-helpers.js';
3
3
  export type AggregatedEvents = {
4
4
  contentText: string;
5
5
  thinkingText: string;
6
6
  stats: CompletionStats | undefined;
7
7
  toolCalls: ToolCall[];
8
+ /** Tool-call regions that failed to parse or validate; see `CompletionFinal.toolErrors`. */
9
+ toolErrors: ToolCallError[];
8
10
  rawFullText: string | undefined;
9
11
  error: CompletionError | undefined;
10
12
  stopReason: StopReason | undefined;
@@ -9,6 +9,7 @@ export function aggregateEvents(events) {
9
9
  let stopReason;
10
10
  let cancelled = false;
11
11
  const toolCalls = [];
12
+ const toolErrors = [];
12
13
  for (const event of events) {
13
14
  if (event.type === 'contentDelta') {
14
15
  contentText += event.text;
@@ -22,6 +23,9 @@ export function aggregateEvents(events) {
22
23
  else if (event.type === 'toolCall') {
23
24
  toolCalls.push(event.call);
24
25
  }
26
+ else if (event.type === 'toolError') {
27
+ toolErrors.push(event.error);
28
+ }
25
29
  else if (event.type === 'completionDone') {
26
30
  if ('raw' in event && event.raw) {
27
31
  rawFullText = event.raw.fullText;
@@ -47,6 +51,7 @@ export function aggregateEvents(events) {
47
51
  thinkingText,
48
52
  stats,
49
53
  toolCalls,
54
+ toolErrors,
50
55
  rawFullText,
51
56
  error,
52
57
  stopReason,
@@ -54,7 +59,7 @@ export function aggregateEvents(events) {
54
59
  };
55
60
  }
56
61
  export function buildFinalFromEvents(events, handlers) {
57
- const { contentText, thinkingText, stats, toolCalls, rawFullText, error, stopReason, cancelled } = aggregateEvents(events);
62
+ const { contentText, thinkingText, stats, toolCalls, toolErrors, rawFullText, error, stopReason, cancelled } = aggregateEvents(events);
58
63
  const attachedToolCalls = attachHandlersToToolCalls(toolCalls, handlers);
59
64
  const fullText = rawFullText ?? contentText;
60
65
  const cacheableAssistantContent = attachedToolCalls.length === 0 ? normalizeAssistantCacheContent(fullText) : undefined;
@@ -62,6 +67,7 @@ export function buildFinalFromEvents(events, handlers) {
62
67
  contentText,
63
68
  ...(thinkingText && { thinkingText }),
64
69
  toolCalls: attachedToolCalls,
70
+ ...(toolErrors.length > 0 && { toolErrors }),
65
71
  ...(stats && { stats }),
66
72
  raw: { fullText },
67
73
  ...(cacheableAssistantContent !== undefined && {
@@ -1,25 +1,29 @@
1
1
  import type { TtsStats } from '../schemas/index.js';
2
+ import type { TtsStats as AddonTtsStats, TtsOutputChunk } from './addon-responses.js';
2
3
  /**
3
4
  * Shared types and utilities for TTS operations.
4
5
  * Used by both text-to-speech.ts and text-to-speech-stream.ts.
5
6
  */
6
- export type TtsStreamChunk = {
7
- outputArray: ArrayLike<number>;
8
- chunkIndex?: number;
9
- sentenceChunk?: string;
10
- };
7
+ export type TtsStreamChunk = TtsOutputChunk;
11
8
  export type TtsOpYield = {
12
9
  buffer: number[];
10
+ sampleRate?: number;
13
11
  chunkIndex?: number;
14
12
  sentenceChunk?: string;
13
+ isLast?: boolean;
15
14
  };
16
- type AddonTtsStats = {
17
- audioDurationMs?: number;
18
- totalSamples?: number;
19
- enhancerBackendDevice?: number;
20
- enhancerBackendId?: number;
15
+ /**
16
+ * Everything an addon chunk carries beyond its PCM. Shared by both TTS ops so
17
+ * the plain `stream: true` path and the sentence-stream path emit the same
18
+ * shape — they run the same addon chunker, and previously only the latter
19
+ * forwarded the metadata.
20
+ */
21
+ export declare function chunkMetadata(chunk: TtsStreamChunk): {
22
+ isLast?: boolean;
23
+ sentenceChunk?: string;
24
+ chunkIndex?: number;
25
+ sampleRate?: number;
21
26
  };
22
27
  export declare function collectTtsStats(response: {
23
28
  stats?: AddonTtsStats;
24
29
  }): TtsStats;
25
- export {};
@@ -1,16 +1,38 @@
1
+ /**
2
+ * Everything an addon chunk carries beyond its PCM. Shared by both TTS ops so
3
+ * the plain `stream: true` path and the sentence-stream path emit the same
4
+ * shape — they run the same addon chunker, and previously only the latter
5
+ * forwarded the metadata.
6
+ */
7
+ export function chunkMetadata(chunk) {
8
+ return {
9
+ ...(chunk.sampleRate !== undefined ? { sampleRate: chunk.sampleRate } : {}),
10
+ ...(chunk.chunkIndex !== undefined ? { chunkIndex: chunk.chunkIndex } : {}),
11
+ ...(typeof chunk.sentenceChunk === 'string' && chunk.sentenceChunk.length > 0
12
+ ? { sentenceChunk: chunk.sentenceChunk }
13
+ : {}),
14
+ ...(chunk.isLast !== undefined ? { isLast: chunk.isLast } : {})
15
+ };
16
+ }
17
+ // Field-for-field, apart from `audioDurationMs` -> `audioDuration`, which keeps
18
+ // the name the SDK has always exposed.
1
19
  export function collectTtsStats(response) {
20
+ const stats = response.stats;
21
+ if (!stats)
22
+ return {};
2
23
  return {
3
- ...(response.stats?.audioDurationMs !== undefined && {
4
- audioDuration: response.stats.audioDurationMs
5
- }),
6
- ...(response.stats?.totalSamples !== undefined && {
7
- totalSamples: response.stats.totalSamples
8
- }),
9
- ...(response.stats?.enhancerBackendDevice !== undefined && {
10
- enhancerBackendDevice: response.stats.enhancerBackendDevice
24
+ ...(stats.audioDurationMs !== undefined && { audioDuration: stats.audioDurationMs }),
25
+ ...(stats.totalTime !== undefined && { totalTime: stats.totalTime }),
26
+ ...(stats.realTimeFactor !== undefined && { realTimeFactor: stats.realTimeFactor }),
27
+ ...(stats.tokensPerSecond !== undefined && { tokensPerSecond: stats.tokensPerSecond }),
28
+ ...(stats.totalSamples !== undefined && { totalSamples: stats.totalSamples }),
29
+ ...(stats.generatedFrames !== undefined && { generatedFrames: stats.generatedFrames }),
30
+ ...(stats.backendDevice !== undefined && { backendDevice: stats.backendDevice }),
31
+ ...(stats.backendId !== undefined && { backendId: stats.backendId }),
32
+ ...(stats.gpuUnsupported !== undefined && { gpuUnsupported: stats.gpuUnsupported }),
33
+ ...(stats.enhancerBackendDevice !== undefined && {
34
+ enhancerBackendDevice: stats.enhancerBackendDevice
11
35
  }),
12
- ...(response.stats?.enhancerBackendId !== undefined && {
13
- enhancerBackendId: response.stats.enhancerBackendId
14
- })
36
+ ...(stats.enhancerBackendId !== undefined && { enhancerBackendId: stats.enhancerBackendId })
15
37
  };
16
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qvac/inference",
3
- "version": "0.19.1",
3
+ "version": "0.20.0",
4
4
  "description": "Bare-only in-process core of the QVAC SDK. Runs inference directly on the Bare runtime with explicit plugin assembly and no RPC, worker, or subprocess layer.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -163,6 +163,7 @@
163
163
  "dependencies": {
164
164
  "@qvac/error": "^0.1.1",
165
165
  "@qvac/logging": "^0.1.1",
166
+ "@qvac/model-fit": "^0.12.0",
166
167
  "@qvac/rag": "^0.8.1",
167
168
  "@qvac/registry-client": "^0.6.1",
168
169
  "bare-abort-controller": "^1.1.2",
@@ -177,6 +178,7 @@
177
178
  "bare-os": "^3.9.3",
178
179
  "bare-path": "^3.1.1",
179
180
  "bare-rpc": "^1.3.8",
181
+ "bare-runtime": "^1.24.2",
180
182
  "bare-stream": "^2.13.3",
181
183
  "bare-url": "^2.4.5",
182
184
  "bare-zlib": "^1.4.0",
@@ -187,22 +189,23 @@
187
189
  "hyperswarm": "^4.17.0",
188
190
  "semver": "^7.8.5",
189
191
  "tar-stream": "^3.2.0",
192
+ "which-runtime": "^1.2.1",
190
193
  "zod": "^4.4.3"
191
194
  },
192
195
  "peerDependencies": {
193
- "@qvac/asr-ggml": "^0.3.1",
194
- "@qvac/audiogen-ggml": "^0.3.2",
195
- "@qvac/bci-whispercpp": "^0.8.0",
196
- "@qvac/classification-ggml": "^0.23.0",
197
- "@qvac/decoder-audio": "^0.5.0",
198
- "@qvac/diffusion-cpp": "^0.21.0",
199
- "@qvac/embed-llamacpp": "^0.37.0",
196
+ "@qvac/asr-ggml": "^0.5.3",
197
+ "@qvac/audiogen-ggml": "^0.4.0",
198
+ "@qvac/bci-whispercpp": "^0.9.1",
199
+ "@qvac/classification-ggml": "^0.26.1",
200
+ "@qvac/decoder-audio": "^0.6.0",
201
+ "@qvac/diffusion-cpp": "^0.24.0",
202
+ "@qvac/embed-llamacpp": "^0.41.1",
200
203
  "@qvac/langdetect-text": "^0.1.2",
201
- "@qvac/llm-llamacpp": "^0.49.1",
202
- "@qvac/ocr-ggml": "^0.21.0",
203
- "@qvac/translation-nmtcpp": "^0.13.0",
204
- "@qvac/tts-ggml": "^0.8.0",
205
- "@qvac/vla-ggml": "^0.24.0"
204
+ "@qvac/llm-llamacpp": "^0.53.0",
205
+ "@qvac/ocr-ggml": "^0.24.1",
206
+ "@qvac/translation-nmtcpp": "^0.16.1",
207
+ "@qvac/tts-ggml": "^0.9.1",
208
+ "@qvac/vla-ggml": "^0.27.1"
206
209
  },
207
210
  "peerDependenciesMeta": {
208
211
  "@qvac/asr-ggml": {
@@ -246,19 +249,19 @@
246
249
  }
247
250
  },
248
251
  "devDependencies": {
249
- "@qvac/asr-ggml": "^0.3.1",
250
- "@qvac/audiogen-ggml": "^0.3.2",
251
- "@qvac/bci-whispercpp": "^0.8.0",
252
- "@qvac/classification-ggml": "^0.23.0",
253
- "@qvac/decoder-audio": "^0.5.0",
254
- "@qvac/diffusion-cpp": "^0.21.0",
255
- "@qvac/embed-llamacpp": "^0.37.0",
252
+ "@qvac/asr-ggml": "^0.5.3",
253
+ "@qvac/audiogen-ggml": "^0.4.0",
254
+ "@qvac/bci-whispercpp": "^0.9.1",
255
+ "@qvac/classification-ggml": "^0.26.1",
256
+ "@qvac/decoder-audio": "^0.6.0",
257
+ "@qvac/diffusion-cpp": "^0.24.0",
258
+ "@qvac/embed-llamacpp": "^0.41.1",
256
259
  "@qvac/langdetect-text": "^0.1.2",
257
- "@qvac/llm-llamacpp": "^0.49.1",
258
- "@qvac/ocr-ggml": "^0.21.0",
259
- "@qvac/translation-nmtcpp": "^0.13.0",
260
- "@qvac/tts-ggml": "^0.8.0",
261
- "@qvac/vla-ggml": "^0.24.0",
260
+ "@qvac/llm-llamacpp": "^0.53.0",
261
+ "@qvac/ocr-ggml": "^0.24.1",
262
+ "@qvac/translation-nmtcpp": "^0.16.1",
263
+ "@qvac/tts-ggml": "^0.9.1",
264
+ "@qvac/vla-ggml": "^0.27.1",
262
265
  "@types/brittle": "^3.5.0",
263
266
  "bare": "*",
264
267
  "bare-console": "*",