@nemesis-oss/ollama-sdk 1.20.1 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -2519,8 +2519,14 @@ declare class OllamaClient {
2519
2519
  *
2520
2520
  * For the low-level generated API (without the generic wrapper), use
2521
2521
  * `client.native.systemOne(request)` directly.
2522
+ *
2523
+ * @param options.signal Cancels the whole call, including the cloud-model
2524
+ * version probe that runs first, so the gate never extends a caller's
2525
+ * deadline. An abort rejects with an {@link OllamaAbortError}.
2522
2526
  */
2523
- systemOne<Q extends SystemOneQuestions = SystemOneQuestions>(request: SystemOneRequest<Q>): Promise<SystemOneResponse<Q>>;
2527
+ systemOne<Q extends SystemOneQuestions = SystemOneQuestions>(request: SystemOneRequest<Q>, options?: {
2528
+ readonly signal?: AbortSignal;
2529
+ }): Promise<SystemOneResponse<Q>>;
2524
2530
  /**
2525
2531
  * Cloud-model version gate for {@link systemOne} — throws
2526
2532
  * {@link OllamaCloudModelVersionError} when a cloud model is requested
package/dist/index.d.ts CHANGED
@@ -2519,8 +2519,14 @@ declare class OllamaClient {
2519
2519
  *
2520
2520
  * For the low-level generated API (without the generic wrapper), use
2521
2521
  * `client.native.systemOne(request)` directly.
2522
+ *
2523
+ * @param options.signal Cancels the whole call, including the cloud-model
2524
+ * version probe that runs first, so the gate never extends a caller's
2525
+ * deadline. An abort rejects with an {@link OllamaAbortError}.
2522
2526
  */
2523
- systemOne<Q extends SystemOneQuestions = SystemOneQuestions>(request: SystemOneRequest<Q>): Promise<SystemOneResponse<Q>>;
2527
+ systemOne<Q extends SystemOneQuestions = SystemOneQuestions>(request: SystemOneRequest<Q>, options?: {
2528
+ readonly signal?: AbortSignal;
2529
+ }): Promise<SystemOneResponse<Q>>;
2524
2530
  /**
2525
2531
  * Cloud-model version gate for {@link systemOne} — throws
2526
2532
  * {@link OllamaCloudModelVersionError} when a cloud model is requested
package/dist/index.js CHANGED
@@ -2624,6 +2624,24 @@ function createTimeoutSignal(timeoutMs, userSignal) {
2624
2624
  };
2625
2625
  return { signal: controller.signal, cancel };
2626
2626
  }
2627
+ function untilAborted(promise, signal, message) {
2628
+ if (signal === void 0) return promise;
2629
+ return new Promise((resolve, reject) => {
2630
+ const onAbort = () => reject(new OllamaAbortError(message));
2631
+ promise.then(
2632
+ (value) => {
2633
+ signal.removeEventListener("abort", onAbort);
2634
+ resolve(value);
2635
+ },
2636
+ (error) => {
2637
+ signal.removeEventListener("abort", onAbort);
2638
+ reject(error);
2639
+ }
2640
+ );
2641
+ if (signal.aborted) onAbort();
2642
+ else signal.addEventListener("abort", onAbort, { once: true });
2643
+ });
2644
+ }
2627
2645
 
2628
2646
  // src/keep-alive.ts
2629
2647
  var KEEP_ALIVE_UNLOAD = 0;
@@ -5651,15 +5669,13 @@ var FailoverHttpClient = class {
5651
5669
  async request(options) {
5652
5670
  const { model, ...httpOptions } = options;
5653
5671
  return this.client.executeWithFailover(
5654
- async (http, signal) => {
5655
- const mergedOptions = {
5656
- ...httpOptions,
5657
- ...httpOptions.signal !== void 0 ? { signal } : { signal }
5658
- };
5659
- return http.request(mergedOptions);
5660
- },
5672
+ // The signal handed to the operation already combines the caller's signal
5673
+ // (passed below) with the failover scope and timeout. Using it, rather than
5674
+ // the caller's, keeps the request cancellable by `destroy()` as well.
5675
+ async (http, signal) => http.request({ ...httpOptions, signal }),
5661
5676
  {
5662
5677
  singleEndpoint: false,
5678
+ ...httpOptions.signal !== void 0 ? { signal: httpOptions.signal } : {},
5663
5679
  ...model !== void 0 ? { model } : {}
5664
5680
  }
5665
5681
  );
@@ -6499,12 +6515,18 @@ var OllamaClient = class _OllamaClient {
6499
6515
  *
6500
6516
  * For the low-level generated API (without the generic wrapper), use
6501
6517
  * `client.native.systemOne(request)` directly.
6518
+ *
6519
+ * @param options.signal Cancels the whole call, including the cloud-model
6520
+ * version probe that runs first, so the gate never extends a caller's
6521
+ * deadline. An abort rejects with an {@link OllamaAbortError}.
6502
6522
  */
6503
- async systemOne(request) {
6504
- await this.assertCloudModelSupported(request.model);
6505
- return this.native.systemOne(
6506
- request
6507
- );
6523
+ async systemOne(request, options = {}) {
6524
+ await this.assertCloudModelSupported(request.model, options.signal);
6525
+ return this.runtime.invoke({
6526
+ operation: systemOneOp,
6527
+ body: request,
6528
+ ...options.signal !== void 0 ? { signal: options.signal } : {}
6529
+ });
6508
6530
  }
6509
6531
  /**
6510
6532
  * Cloud-model version gate for {@link systemOne} — throws
@@ -6516,19 +6538,25 @@ var OllamaClient = class _OllamaClient {
6516
6538
  * so a later gated call retries), so at most one extra round-trip happens
6517
6539
  * across all gated calls.
6518
6540
  */
6519
- async assertCloudModelSupported(model) {
6541
+ async assertCloudModelSupported(model, signal) {
6520
6542
  if (!isCloudModel(model)) return;
6521
6543
  const candidates = this.registry.candidates();
6522
6544
  const baseUrl = candidates[0]?.baseUrl ?? DEFAULT_BASE_URL;
6523
6545
  if (inferRuntimeMode(baseUrl) !== "local") return;
6546
+ if (this.serverVersionCache === void 0) {
6547
+ this.serverVersionCache = this.native.version().then((v) => v.version);
6548
+ }
6549
+ const probe = this.serverVersionCache;
6524
6550
  let version;
6525
6551
  try {
6526
- if (this.serverVersionCache === void 0) {
6527
- this.serverVersionCache = this.native.version().then((v) => v.version);
6528
- }
6529
- version = await this.serverVersionCache;
6530
- } catch {
6531
- this.serverVersionCache = void 0;
6552
+ version = await untilAborted(
6553
+ probe,
6554
+ signal,
6555
+ "System One call aborted while probing the Ollama server version"
6556
+ );
6557
+ } catch (error) {
6558
+ if (signal?.aborted) throw error;
6559
+ if (this.serverVersionCache === probe) this.serverVersionCache = void 0;
6532
6560
  return;
6533
6561
  }
6534
6562
  if (version && compareOllamaVersions(version, CLOUD_MODEL_MIN_OLLAMA_VERSION) < 0) {