@qvac/sdk 0.10.1 → 0.11.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 (201) hide show
  1. package/NOTICE +92 -54
  2. package/dist/client/api/cancel.d.ts +24 -32
  3. package/dist/client/api/cancel.js +58 -31
  4. package/dist/client/api/client-request-id.d.ts +17 -0
  5. package/dist/client/api/client-request-id.js +27 -0
  6. package/dist/client/api/completion-stream.d.ts +1 -1
  7. package/dist/client/api/completion-stream.js +34 -3
  8. package/dist/client/api/diffusion.d.ts +46 -0
  9. package/dist/client/api/diffusion.js +50 -1
  10. package/dist/client/api/download-asset.d.ts +12 -2
  11. package/dist/client/api/download-asset.js +21 -3
  12. package/dist/client/api/embed.d.ts +8 -4
  13. package/dist/client/api/embed.js +14 -1
  14. package/dist/client/api/get-model-info.d.ts +1 -1
  15. package/dist/client/api/index.d.ts +1 -0
  16. package/dist/client/api/index.js +1 -0
  17. package/dist/client/api/load-model.d.ts +12 -4
  18. package/dist/client/api/load-model.js +25 -1
  19. package/dist/client/api/rag.d.ts +9 -3
  20. package/dist/client/api/rag.js +23 -3
  21. package/dist/client/api/transcribe.d.ts +20 -8
  22. package/dist/client/api/transcribe.js +58 -4
  23. package/dist/client/api/unload-model.d.ts +5 -2
  24. package/dist/client/api/unload-model.js +9 -4
  25. package/dist/client/api/upscale.d.ts +45 -0
  26. package/dist/client/api/upscale.js +99 -0
  27. package/dist/client/rpc/expo-rpc-client.js +2 -1
  28. package/dist/client/rpc/node-rpc-client.js +18 -7
  29. package/dist/client/rpc/rpc-client.d.ts +2 -2
  30. package/dist/client/rpc/rpc-client.js +10 -4
  31. package/dist/client/rpc/rpc-error.d.ts +9 -0
  32. package/dist/client/rpc/rpc-error.js +92 -0
  33. package/dist/examples/cancel-by-request-id.d.ts +38 -0
  34. package/dist/examples/cancel-by-request-id.js +103 -0
  35. package/dist/examples/diffusion-esrgan-upscale.d.ts +2 -0
  36. package/dist/examples/diffusion-esrgan-upscale.js +78 -0
  37. package/dist/examples/download-with-cancel.js +10 -10
  38. package/dist/examples/embed-multi-gpu.d.ts +2 -0
  39. package/dist/examples/embed-multi-gpu.js +46 -0
  40. package/dist/examples/llamacpp-multi-gpu.d.ts +2 -0
  41. package/dist/examples/llamacpp-multi-gpu.js +57 -0
  42. package/dist/examples/rag/rag-hyperdb/cancellation.js +20 -17
  43. package/dist/examples/tools/llamacpp-tools-gemma4.d.ts +2 -0
  44. package/dist/examples/tools/llamacpp-tools-gemma4.js +76 -0
  45. package/dist/examples/tools/llamacpp-tools-qwen35.d.ts +2 -0
  46. package/dist/examples/tools/llamacpp-tools-qwen35.js +70 -0
  47. package/dist/examples/transcription/whispercpp-microphone-conversation.d.ts +2 -0
  48. package/dist/examples/transcription/whispercpp-microphone-conversation.js +102 -0
  49. package/dist/examples/tts/supertonic.js +1 -1
  50. package/dist/expo/plugins/withMobileBundle.d.ts +20 -4
  51. package/dist/expo/plugins/withMobileBundle.js +44 -6
  52. package/dist/index.d.ts +5 -2
  53. package/dist/index.js +21 -1
  54. package/dist/models/registry/models.d.ts +186 -318
  55. package/dist/models/registry/models.js +1522 -1667
  56. package/dist/pear/pre.d.ts +3 -0
  57. package/dist/pear/pre.js +3 -0
  58. package/dist/schemas/cancel.d.ts +167 -28
  59. package/dist/schemas/cancel.js +119 -19
  60. package/dist/schemas/common.d.ts +427 -208
  61. package/dist/schemas/common.js +3 -1
  62. package/dist/schemas/completion-event.d.ts +14 -0
  63. package/dist/schemas/completion-event.js +11 -1
  64. package/dist/schemas/completion-stream.d.ts +15 -1
  65. package/dist/schemas/completion-stream.js +25 -7
  66. package/dist/schemas/download-asset.d.ts +15 -9
  67. package/dist/schemas/download-asset.js +17 -6
  68. package/dist/schemas/embed.d.ts +1 -0
  69. package/dist/schemas/embed.js +5 -0
  70. package/dist/schemas/error.d.ts +31 -0
  71. package/dist/schemas/error.js +29 -1
  72. package/dist/schemas/finetune.d.ts +2 -0
  73. package/dist/schemas/finetune.js +5 -0
  74. package/dist/schemas/get-model-info.d.ts +6 -6
  75. package/dist/schemas/llamacpp-config.d.ts +54 -8
  76. package/dist/schemas/llamacpp-config.js +12 -0
  77. package/dist/schemas/load-model.d.ts +1911 -1260
  78. package/dist/schemas/load-model.js +15 -0
  79. package/dist/schemas/model-src-utils.d.ts +14 -14
  80. package/dist/schemas/model-types.d.ts +10 -10
  81. package/dist/schemas/ocr.d.ts +3 -3
  82. package/dist/schemas/plugin.d.ts +40 -1
  83. package/dist/schemas/plugin.js +10 -1
  84. package/dist/schemas/rag.d.ts +9 -0
  85. package/dist/schemas/rag.js +17 -9
  86. package/dist/schemas/registry.d.ts +30 -30
  87. package/dist/schemas/reload-config.d.ts +14 -14
  88. package/dist/schemas/sdcpp-config.d.ts +131 -17
  89. package/dist/schemas/sdcpp-config.js +163 -1
  90. package/dist/schemas/sdk-config.d.ts +649 -271
  91. package/dist/schemas/sdk-errors-client.d.ts +1 -0
  92. package/dist/schemas/sdk-errors-client.js +5 -0
  93. package/dist/schemas/sdk-errors-server.d.ts +5 -0
  94. package/dist/schemas/sdk-errors-server.js +25 -0
  95. package/dist/schemas/text-to-speech.d.ts +78 -78
  96. package/dist/schemas/transcription-config.d.ts +24 -24
  97. package/dist/schemas/transcription.d.ts +56 -2
  98. package/dist/schemas/transcription.js +27 -0
  99. package/dist/schemas/translate.d.ts +2 -0
  100. package/dist/schemas/translate.js +13 -2
  101. package/dist/schemas/translation-config.d.ts +40 -40
  102. package/dist/schemas/unload-model.d.ts +2 -1
  103. package/dist/schemas/unload-model.js +4 -1
  104. package/dist/scripts/run-unit-tests.js +15 -2
  105. package/dist/server/bare/delegate-rpc-client.js +10 -8
  106. package/dist/server/bare/ops/cancel.d.ts +27 -1
  107. package/dist/server/bare/ops/cancel.js +36 -10
  108. package/dist/server/bare/ops/embed.d.ts +3 -3
  109. package/dist/server/bare/ops/embed.js +144 -28
  110. package/dist/server/bare/ops/kv-cache-utils.d.ts +0 -7
  111. package/dist/server/bare/ops/kv-cache-utils.js +8 -47
  112. package/dist/server/bare/ops/transcribe.d.ts +10 -5
  113. package/dist/server/bare/ops/transcribe.js +196 -41
  114. package/dist/server/bare/ops/translate.d.ts +1 -1
  115. package/dist/server/bare/ops/translate.js +197 -88
  116. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.d.ts +12 -3
  117. package/dist/server/bare/plugins/llamacpp-completion/ops/completion-stream.js +170 -172
  118. package/dist/server/bare/plugins/llamacpp-completion/ops/finetune.js +125 -21
  119. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.d.ts +154 -0
  120. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-session.js +448 -0
  121. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.d.ts +21 -73
  122. package/dist/server/bare/plugins/llamacpp-completion/ops/kv-cache-state.js +18 -101
  123. package/dist/server/bare/plugins/llamacpp-completion/plugin.d.ts +30 -3
  124. package/dist/server/bare/plugins/llamacpp-completion/plugin.js +157 -85
  125. package/dist/server/bare/plugins/llamacpp-completion/transform.d.ts +10 -0
  126. package/dist/server/bare/plugins/llamacpp-completion/transform.js +34 -0
  127. package/dist/server/bare/plugins/llamacpp-embedding/plugin.d.ts +7 -0
  128. package/dist/server/bare/plugins/llamacpp-embedding/plugin.js +10 -1
  129. package/dist/server/bare/plugins/nmtcpp-translation/plugin.d.ts +17 -15
  130. package/dist/server/bare/plugins/nmtcpp-translation/plugin.js +5 -1
  131. package/dist/server/bare/plugins/onnx-ocr/plugin.d.ts +3 -3
  132. package/dist/server/bare/plugins/onnx-ocr/plugin.js +3 -0
  133. package/dist/server/bare/plugins/onnx-tts/plugin.d.ts +39 -39
  134. package/dist/server/bare/plugins/onnx-tts/plugin.js +6 -0
  135. package/dist/server/bare/plugins/parakeet-transcription/plugin.d.ts +29 -21
  136. package/dist/server/bare/plugins/parakeet-transcription/plugin.js +4 -1
  137. package/dist/server/bare/plugins/sdcpp-generation/ops/diffusion.js +8 -0
  138. package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.d.ts +3 -0
  139. package/dist/server/bare/plugins/sdcpp-generation/ops/upscale.js +40 -0
  140. package/dist/server/bare/plugins/sdcpp-generation/plugin.d.ts +91 -16
  141. package/dist/server/bare/plugins/sdcpp-generation/plugin.js +97 -7
  142. package/dist/server/bare/plugins/whispercpp-transcription/plugin.d.ts +22 -3
  143. package/dist/server/bare/plugins/whispercpp-transcription/plugin.js +50 -14
  144. package/dist/server/bare/rag-hyperdb/index.d.ts +1 -1
  145. package/dist/server/bare/rag-hyperdb/index.js +1 -1
  146. package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +26 -4
  147. package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +65 -28
  148. package/dist/server/bare/runtime/disposable-scope.d.ts +36 -0
  149. package/dist/server/bare/runtime/disposable-scope.js +69 -0
  150. package/dist/server/bare/runtime/index.d.ts +8 -0
  151. package/dist/server/bare/runtime/index.js +3 -0
  152. package/dist/server/bare/runtime/request-context.d.ts +49 -0
  153. package/dist/server/bare/runtime/request-context.js +1 -0
  154. package/dist/server/bare/runtime/request-id.d.ts +12 -0
  155. package/dist/server/bare/runtime/request-id.js +14 -0
  156. package/dist/server/bare/runtime/request-registry-singleton.d.ts +4 -0
  157. package/dist/server/bare/runtime/request-registry-singleton.js +27 -0
  158. package/dist/server/bare/runtime/request-registry.d.ts +136 -0
  159. package/dist/server/bare/runtime/request-registry.js +297 -0
  160. package/dist/server/bare/runtime/with-request-context.d.ts +22 -0
  161. package/dist/server/bare/runtime/with-request-context.js +53 -0
  162. package/dist/server/bare/types/addon-responses.d.ts +11 -1
  163. package/dist/server/rpc/handler-registry.js +26 -7
  164. package/dist/server/rpc/handlers/cancel-delegated.js +28 -31
  165. package/dist/server/rpc/handlers/cancelHandler.d.ts +30 -1
  166. package/dist/server/rpc/handlers/cancelHandler.js +54 -22
  167. package/dist/server/rpc/handlers/delete-cache.d.ts +9 -0
  168. package/dist/server/rpc/handlers/delete-cache.js +13 -15
  169. package/dist/server/rpc/handlers/download-asset.js +133 -40
  170. package/dist/server/rpc/handlers/index.d.ts +2 -0
  171. package/dist/server/rpc/handlers/index.js +2 -0
  172. package/dist/server/rpc/handlers/load-model/download-manager.d.ts +60 -2
  173. package/dist/server/rpc/handlers/load-model/download-manager.js +141 -8
  174. package/dist/server/rpc/handlers/load-model/handler.js +213 -98
  175. package/dist/server/rpc/handlers/load-model/http.js +3 -3
  176. package/dist/server/rpc/handlers/load-model/hyperdrive.js +1 -1
  177. package/dist/server/rpc/handlers/load-model/registry.js +1 -1
  178. package/dist/server/rpc/handlers/load-model/resolve-session.d.ts +20 -1
  179. package/dist/server/rpc/handlers/load-model/resolve-session.js +6 -5
  180. package/dist/server/rpc/handlers/load-model/resolve.d.ts +3 -2
  181. package/dist/server/rpc/handlers/load-model/resolve.js +9 -6
  182. package/dist/server/rpc/handlers/load-model/types.d.ts +24 -0
  183. package/dist/server/rpc/handlers/rag.js +133 -15
  184. package/dist/server/rpc/handlers/upscale-stream.d.ts +3 -0
  185. package/dist/server/rpc/handlers/upscale-stream.js +4 -0
  186. package/dist/server/utils/completion-normalizer.js +8 -0
  187. package/dist/server/utils/tools/dialect.js +4 -0
  188. package/dist/server/utils/tools/parser.js +16 -1
  189. package/dist/server/utils/tools/parsers/gemma4native.d.ts +4 -0
  190. package/dist/server/utils/tools/parsers/gemma4native.js +60 -0
  191. package/dist/server/utils/tools/parsers/qwen35.d.ts +4 -0
  192. package/dist/server/utils/tools/parsers/qwen35.js +120 -0
  193. package/dist/utils/aggregate-events.d.ts +9 -0
  194. package/dist/utils/aggregate-events.js +18 -3
  195. package/dist/utils/decorate-promise.d.ts +34 -0
  196. package/dist/utils/decorate-promise.js +35 -0
  197. package/dist/utils/errors-client.d.ts +3 -0
  198. package/dist/utils/errors-client.js +5 -0
  199. package/dist/utils/errors-server.d.ts +85 -0
  200. package/dist/utils/errors-server.js +97 -0
  201. package/package.json +20 -15
@@ -5,6 +5,9 @@
5
5
  * 1. Generate `qvac/worker.pear.entry.mjs` with selected plugins
6
6
  * 2. Persist `pear.stage.entrypoints` to package.json for routing
7
7
  *
8
+ * Note: `qvac verify bundle` is not wired here yet — run it manually
9
+ * (locally and/or in CI) before `pear stage` / `pear run`.
10
+ *
8
11
  * @example package.json configuration
9
12
  * ```json
10
13
  * {
package/dist/pear/pre.js CHANGED
@@ -5,6 +5,9 @@
5
5
  * 1. Generate `qvac/worker.pear.entry.mjs` with selected plugins
6
6
  * 2. Persist `pear.stage.entrypoints` to package.json for routing
7
7
  *
8
+ * Note: `qvac verify bundle` is not wired here yet — run it manually
9
+ * (locally and/or in CI) before `pear stage` / `pear run`.
10
+ *
8
11
  * @example package.json configuration
9
12
  * ```json
10
13
  * {
@@ -1,55 +1,194 @@
1
1
  import { z } from "zod";
2
+ /**
3
+ * Public-API base for the broad-cancel escape hatch. Kept exported so
4
+ * the bare-side `cancel({ modelId, kind? })` helper can parse the
5
+ * `modelId` field consistently with the wire envelope.
6
+ */
2
7
  export declare const cancelInferenceBaseSchema: z.ZodObject<{
3
8
  modelId: z.ZodString;
4
9
  }, z.core.$strip>;
5
- declare const cancelParamsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
10
+ /**
11
+ * Coarse kind narrowing for the broad-cancel escape hatch. Matches the
12
+ * server-side `RequestKind` union in `server/bare/runtime/request-context.ts`
13
+ * — keep the two lists in sync. The kind is optional; omitting it
14
+ * cancels every in-flight request on the model regardless of kind
15
+ * (the "cancel everything on this model" sweep used by model-unload
16
+ * and app-shutdown paths).
17
+ */
18
+ declare const cancelKindSchema: z.ZodEnum<{
19
+ completion: "completion";
20
+ embeddings: "embeddings";
21
+ transcribe: "transcribe";
22
+ translate: "translate";
23
+ diffusion: "diffusion";
24
+ tts: "tts";
25
+ ocr: "ocr";
26
+ finetune: "finetune";
27
+ loadModel: "loadModel";
28
+ downloadAsset: "downloadAsset";
29
+ rag: "rag";
30
+ }>;
31
+ /**
32
+ * Targeted cancel by `requestId` — the primary cancel path in
33
+ * SDK 0.11.0. Pair with the `requestId` field exposed on
34
+ * `CompletionRun` (and the decorated promises returned by
35
+ * `loadModel(...)`, `downloadAsset(...)`, `embed(...)`,
36
+ * `transcribe(...)`, `rag*(...)` etc.) to cancel a specific in-flight
37
+ * request rather than every request running on a given model.
38
+ *
39
+ * `clearCache` is honoured only when the targeted request is a
40
+ * `downloadAsset` — it propagates onto the underlying download
41
+ * transfer so the partial file is deleted when the last subscriber
42
+ * leaves. Ignored for other kinds.
43
+ */
44
+ declare const cancelByRequestIdParamsSchema: z.ZodObject<{
45
+ operation: z.ZodLiteral<"request">;
46
+ requestId: z.ZodString;
47
+ clearCache: z.ZodOptional<z.ZodBoolean>;
48
+ }, z.core.$strip>;
49
+ /**
50
+ * Broad cancel escape hatch — abort every in-flight request running on
51
+ * a model (optionally narrowed by `kind`). Kept indefinitely as the
52
+ * non-`requestId` cancel surface for model-unload, app-shutdown, and
53
+ * admin sweeps where the caller doesn't have a `requestId` to hand.
54
+ *
55
+ * Replaces the legacy per-kind discriminator arms (`"inference"`,
56
+ * `"embeddings"`, `"downloadAsset"`, `"rag"`) with a single `"broad"`
57
+ * arm plus an optional `kind` field. The old arms went away as part
58
+ * of the 0.11.0 cleanup once every handler was on the registry; the
59
+ * wire shape collapse is a `[bc]` for any external caller hand-rolling
60
+ * the old RPC envelope. The public-API `cancel(...)` function in
61
+ * `client/api/cancel.ts` keeps the old `{ operation: "inference", modelId }`
62
+ * / `{ operation: "embeddings", modelId }` forms callable and translates
63
+ * them into this new shape at the client boundary, so consumers using
64
+ * the official SDK client see no change.
65
+ */
66
+ declare const cancelBroadParamsSchema: z.ZodObject<{
67
+ operation: z.ZodLiteral<"broad">;
6
68
  modelId: z.ZodString;
7
- operation: z.ZodLiteral<"inference">;
8
- }, z.core.$strip>, z.ZodObject<{
9
- operation: z.ZodLiteral<"downloadAsset">;
10
- downloadKey: z.ZodString;
69
+ kind: z.ZodOptional<z.ZodEnum<{
70
+ completion: "completion";
71
+ embeddings: "embeddings";
72
+ transcribe: "transcribe";
73
+ translate: "translate";
74
+ diffusion: "diffusion";
75
+ tts: "tts";
76
+ ocr: "ocr";
77
+ finetune: "finetune";
78
+ loadModel: "loadModel";
79
+ downloadAsset: "downloadAsset";
80
+ rag: "rag";
81
+ }>>;
82
+ }, z.core.$strip>;
83
+ declare const cancelParamsSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
84
+ operation: z.ZodLiteral<"request">;
85
+ requestId: z.ZodString;
11
86
  clearCache: z.ZodOptional<z.ZodBoolean>;
12
- delegate: z.ZodOptional<z.ZodObject<{
13
- providerPublicKey: z.ZodString;
14
- timeout: z.ZodOptional<z.ZodNumber>;
15
- healthCheckTimeout: z.ZodOptional<z.ZodNumber>;
16
- }, z.core.$strip>>;
17
- }, z.core.$strip>, z.ZodObject<{
18
- operation: z.ZodLiteral<"rag">;
19
- workspace: z.ZodOptional<z.ZodString>;
20
87
  }, z.core.$strip>, z.ZodObject<{
88
+ operation: z.ZodLiteral<"broad">;
21
89
  modelId: z.ZodString;
22
- operation: z.ZodLiteral<"embeddings">;
90
+ kind: z.ZodOptional<z.ZodEnum<{
91
+ completion: "completion";
92
+ embeddings: "embeddings";
93
+ transcribe: "transcribe";
94
+ translate: "translate";
95
+ diffusion: "diffusion";
96
+ tts: "tts";
97
+ ocr: "ocr";
98
+ finetune: "finetune";
99
+ loadModel: "loadModel";
100
+ downloadAsset: "downloadAsset";
101
+ rag: "rag";
102
+ }>>;
23
103
  }, z.core.$strip>], "operation">;
24
104
  export declare const cancelRequestSchema: z.ZodIntersection<z.ZodObject<{
25
105
  type: z.ZodLiteral<"cancel">;
26
106
  }, z.core.$strip>, z.ZodDiscriminatedUnion<[z.ZodObject<{
27
- modelId: z.ZodString;
28
- operation: z.ZodLiteral<"inference">;
29
- }, z.core.$strip>, z.ZodObject<{
30
- operation: z.ZodLiteral<"downloadAsset">;
31
- downloadKey: z.ZodString;
107
+ operation: z.ZodLiteral<"request">;
108
+ requestId: z.ZodString;
32
109
  clearCache: z.ZodOptional<z.ZodBoolean>;
33
- delegate: z.ZodOptional<z.ZodObject<{
34
- providerPublicKey: z.ZodString;
35
- timeout: z.ZodOptional<z.ZodNumber>;
36
- healthCheckTimeout: z.ZodOptional<z.ZodNumber>;
37
- }, z.core.$strip>>;
38
- }, z.core.$strip>, z.ZodObject<{
39
- operation: z.ZodLiteral<"rag">;
40
- workspace: z.ZodOptional<z.ZodString>;
41
110
  }, z.core.$strip>, z.ZodObject<{
111
+ operation: z.ZodLiteral<"broad">;
42
112
  modelId: z.ZodString;
43
- operation: z.ZodLiteral<"embeddings">;
113
+ kind: z.ZodOptional<z.ZodEnum<{
114
+ completion: "completion";
115
+ embeddings: "embeddings";
116
+ transcribe: "transcribe";
117
+ translate: "translate";
118
+ diffusion: "diffusion";
119
+ tts: "tts";
120
+ ocr: "ocr";
121
+ finetune: "finetune";
122
+ loadModel: "loadModel";
123
+ downloadAsset: "downloadAsset";
124
+ rag: "rag";
125
+ }>>;
44
126
  }, z.core.$strip>], "operation">>;
45
127
  export declare const cancelResponseSchema: z.ZodObject<{
46
128
  type: z.ZodLiteral<"cancel">;
47
129
  success: z.ZodBoolean;
130
+ cancelled: z.ZodOptional<z.ZodNumber>;
48
131
  error: z.ZodOptional<z.ZodString>;
49
132
  }, z.core.$strip>;
133
+ /**
134
+ * Sugar for the most common new path — `cancel({ requestId })`. The
135
+ * client accepts either this shape (no `operation`) or the explicit
136
+ * `{ operation: "request", requestId }` and normalises before sending.
137
+ */
138
+ export declare const cancelByRequestIdSugarSchema: z.ZodObject<{
139
+ requestId: z.ZodString;
140
+ clearCache: z.ZodOptional<z.ZodBoolean>;
141
+ }, z.core.$strict>;
142
+ /**
143
+ * Sugar for the broad-cancel escape hatch — `cancel({ modelId, kind? })`.
144
+ * Translates to `{ operation: "broad", modelId, kind? }` at the client
145
+ * boundary.
146
+ */
147
+ export declare const cancelBroadSugarSchema: z.ZodObject<{
148
+ modelId: z.ZodString;
149
+ kind: z.ZodOptional<z.ZodEnum<{
150
+ completion: "completion";
151
+ embeddings: "embeddings";
152
+ transcribe: "transcribe";
153
+ translate: "translate";
154
+ diffusion: "diffusion";
155
+ tts: "tts";
156
+ ocr: "ocr";
157
+ finetune: "finetune";
158
+ loadModel: "loadModel";
159
+ downloadAsset: "downloadAsset";
160
+ rag: "rag";
161
+ }>>;
162
+ }, z.core.$strict>;
163
+ /**
164
+ * Legacy per-kind broad-cancel sugars retained at the public-API
165
+ * boundary so existing callers of `cancel({ operation: "inference",
166
+ * modelId })` / `cancel({ operation: "embeddings", modelId })` keep
167
+ * working without code changes. The client wrapper translates these
168
+ * into the new `{ operation: "broad", modelId, kind: ... }` wire
169
+ * shape. New callers should prefer `cancel({ requestId })` or
170
+ * `cancel({ modelId, kind? })`.
171
+ */
172
+ export declare const cancelLegacyInferenceSugarSchema: z.ZodObject<{
173
+ operation: z.ZodLiteral<"inference">;
174
+ modelId: z.ZodString;
175
+ }, z.core.$strip>;
176
+ export declare const cancelLegacyEmbeddingsSugarSchema: z.ZodObject<{
177
+ operation: z.ZodLiteral<"embeddings">;
178
+ modelId: z.ZodString;
179
+ }, z.core.$strip>;
50
180
  export type CancelParams = z.infer<typeof cancelParamsSchema>;
51
181
  export type CancelInferenceBaseParams = z.infer<typeof cancelInferenceBaseSchema>;
182
+ export type CancelByRequestIdParams = z.infer<typeof cancelByRequestIdParamsSchema>;
183
+ export type CancelBroadParams = z.infer<typeof cancelBroadParamsSchema>;
184
+ export type CancelByRequestIdSugar = z.infer<typeof cancelByRequestIdSugarSchema>;
185
+ export type CancelBroadSugar = z.infer<typeof cancelBroadSugarSchema>;
186
+ export type CancelLegacyInferenceSugar = z.infer<typeof cancelLegacyInferenceSugarSchema>;
187
+ export type CancelLegacyEmbeddingsSugar = z.infer<typeof cancelLegacyEmbeddingsSugarSchema>;
188
+ export type CancelKind = z.infer<typeof cancelKindSchema>;
52
189
  export type CancelRequest = z.infer<typeof cancelRequestSchema>;
53
190
  export type CancelResponse = z.infer<typeof cancelResponseSchema>;
191
+ /** Public client-API input — accepts the wire union *or* the requestId/broad sugars and the legacy per-kind sugars. */
192
+ export type CancelClientInput = CancelParams | CancelByRequestIdSugar | CancelBroadSugar | CancelLegacyInferenceSugar | CancelLegacyEmbeddingsSugar;
54
193
  export {};
55
194
  //# sourceMappingURL=cancel.d.ts.map
@@ -1,39 +1,139 @@
1
1
  import { z } from "zod";
2
- import { delegateBaseSchema } from "./delegate.js";
3
2
  const cancelBaseSchema = z.object({
4
3
  type: z.literal("cancel"),
5
4
  });
5
+ /**
6
+ * Public-API base for the broad-cancel escape hatch. Kept exported so
7
+ * the bare-side `cancel({ modelId, kind? })` helper can parse the
8
+ * `modelId` field consistently with the wire envelope.
9
+ */
6
10
  export const cancelInferenceBaseSchema = z.object({
7
11
  modelId: z.string().describe("The model ID to cancel inference for"),
8
12
  });
9
- const cancelInferenceParamsSchema = cancelInferenceBaseSchema.extend({
10
- operation: z.literal("inference").describe("Operation type"),
11
- });
12
- const cancelDownloadParamsSchema = z.object({
13
- operation: z.literal("downloadAsset").describe("Operation type"),
14
- downloadKey: z.string().describe("The download key to cancel"),
13
+ /**
14
+ * Coarse kind narrowing for the broad-cancel escape hatch. Matches the
15
+ * server-side `RequestKind` union in `server/bare/runtime/request-context.ts`
16
+ * — keep the two lists in sync. The kind is optional; omitting it
17
+ * cancels every in-flight request on the model regardless of kind
18
+ * (the "cancel everything on this model" sweep used by model-unload
19
+ * and app-shutdown paths).
20
+ */
21
+ const cancelKindSchema = z
22
+ .enum([
23
+ "completion",
24
+ "embeddings",
25
+ "transcribe",
26
+ "translate",
27
+ "diffusion",
28
+ "tts",
29
+ "ocr",
30
+ "finetune",
31
+ "loadModel",
32
+ "downloadAsset",
33
+ "rag",
34
+ ])
35
+ .describe("Optional kind narrowing for the broad cancel. Omitting it cancels every in-flight request on the model.");
36
+ /**
37
+ * Targeted cancel by `requestId` — the primary cancel path in
38
+ * SDK 0.11.0. Pair with the `requestId` field exposed on
39
+ * `CompletionRun` (and the decorated promises returned by
40
+ * `loadModel(...)`, `downloadAsset(...)`, `embed(...)`,
41
+ * `transcribe(...)`, `rag*(...)` etc.) to cancel a specific in-flight
42
+ * request rather than every request running on a given model.
43
+ *
44
+ * `clearCache` is honoured only when the targeted request is a
45
+ * `downloadAsset` — it propagates onto the underlying download
46
+ * transfer so the partial file is deleted when the last subscriber
47
+ * leaves. Ignored for other kinds.
48
+ */
49
+ const cancelByRequestIdParamsSchema = z.object({
50
+ operation: z.literal("request").describe("Operation type"),
51
+ requestId: z
52
+ .string()
53
+ .min(1)
54
+ .describe("Identifier of the specific in-flight request to cancel — the value exposed on the result object returned by long-running calls (e.g. `completion(...)`, `loadModel(...)`, `downloadAsset(...)`)."),
15
55
  clearCache: z
16
56
  .boolean()
17
57
  .optional()
18
- .describe("If true, deletes the partial download file"),
19
- delegate: delegateBaseSchema.optional(),
20
- });
21
- const cancelRagParamsSchema = z.object({
22
- operation: z.literal("rag").describe("Operation type"),
23
- workspace: z.string().optional().describe("The RAG workspace to cancel"),
58
+ .describe("Download-only: if true, deletes the partial download file when the subscriber leaves. Ignored for non-download kinds."),
24
59
  });
25
- const cancelEmbeddingsParamsSchema = cancelInferenceBaseSchema.extend({
26
- operation: z.literal("embeddings").describe("Operation type"),
60
+ /**
61
+ * Broad cancel escape hatch — abort every in-flight request running on
62
+ * a model (optionally narrowed by `kind`). Kept indefinitely as the
63
+ * non-`requestId` cancel surface for model-unload, app-shutdown, and
64
+ * admin sweeps where the caller doesn't have a `requestId` to hand.
65
+ *
66
+ * Replaces the legacy per-kind discriminator arms (`"inference"`,
67
+ * `"embeddings"`, `"downloadAsset"`, `"rag"`) with a single `"broad"`
68
+ * arm plus an optional `kind` field. The old arms went away as part
69
+ * of the 0.11.0 cleanup once every handler was on the registry; the
70
+ * wire shape collapse is a `[bc]` for any external caller hand-rolling
71
+ * the old RPC envelope. The public-API `cancel(...)` function in
72
+ * `client/api/cancel.ts` keeps the old `{ operation: "inference", modelId }`
73
+ * / `{ operation: "embeddings", modelId }` forms callable and translates
74
+ * them into this new shape at the client boundary, so consumers using
75
+ * the official SDK client see no change.
76
+ */
77
+ const cancelBroadParamsSchema = z.object({
78
+ operation: z.literal("broad").describe("Operation type"),
79
+ modelId: z
80
+ .string()
81
+ .describe("Cancel every in-flight request on this model"),
82
+ kind: cancelKindSchema.optional(),
27
83
  });
28
84
  const cancelParamsSchema = z.discriminatedUnion("operation", [
29
- cancelInferenceParamsSchema,
30
- cancelDownloadParamsSchema,
31
- cancelRagParamsSchema,
32
- cancelEmbeddingsParamsSchema,
85
+ cancelByRequestIdParamsSchema,
86
+ cancelBroadParamsSchema,
33
87
  ]);
34
88
  export const cancelRequestSchema = z.intersection(cancelBaseSchema, cancelParamsSchema);
35
89
  export const cancelResponseSchema = z.object({
36
90
  type: z.literal("cancel"),
37
91
  success: z.boolean(),
92
+ /**
93
+ * Number of in-flight contexts that this call flipped to
94
+ * `cancelling` (already-cancelled contexts are not counted, so
95
+ * callers can rely on the value to log "n requests cancelled" once
96
+ * without double-counting). Always present on `success: true`.
97
+ */
98
+ cancelled: z.number().int().nonnegative().optional(),
38
99
  error: z.string().optional(),
39
100
  });
101
+ /**
102
+ * Sugar for the most common new path — `cancel({ requestId })`. The
103
+ * client accepts either this shape (no `operation`) or the explicit
104
+ * `{ operation: "request", requestId }` and normalises before sending.
105
+ */
106
+ export const cancelByRequestIdSugarSchema = z
107
+ .object({
108
+ requestId: z.string().min(1),
109
+ clearCache: z.boolean().optional(),
110
+ })
111
+ .strict();
112
+ /**
113
+ * Sugar for the broad-cancel escape hatch — `cancel({ modelId, kind? })`.
114
+ * Translates to `{ operation: "broad", modelId, kind? }` at the client
115
+ * boundary.
116
+ */
117
+ export const cancelBroadSugarSchema = z
118
+ .object({
119
+ modelId: z.string().min(1),
120
+ kind: cancelKindSchema.optional(),
121
+ })
122
+ .strict();
123
+ /**
124
+ * Legacy per-kind broad-cancel sugars retained at the public-API
125
+ * boundary so existing callers of `cancel({ operation: "inference",
126
+ * modelId })` / `cancel({ operation: "embeddings", modelId })` keep
127
+ * working without code changes. The client wrapper translates these
128
+ * into the new `{ operation: "broad", modelId, kind: ... }` wire
129
+ * shape. New callers should prefer `cancel({ requestId })` or
130
+ * `cancel({ modelId, kind? })`.
131
+ */
132
+ export const cancelLegacyInferenceSugarSchema = z.object({
133
+ operation: z.literal("inference"),
134
+ modelId: z.string().min(1),
135
+ });
136
+ export const cancelLegacyEmbeddingsSugarSchema = z.object({
137
+ operation: z.literal("embeddings"),
138
+ modelId: z.string().min(1),
139
+ });