@openllmsh/sdk 2.10.13 → 2.10.15-alpha.1

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.
@@ -1390,6 +1390,8 @@ export declare const DaemonProviderConnection: S.Struct<{
1390
1390
  readonly host_signed_in: S.optional<S.Boolean>;
1391
1391
  readonly detail: S.optional<S.String>;
1392
1392
  readonly last_login_at_ms: S.optional<S.NullOr<S.Number>>;
1393
+ /** Wall-clock time of the latest real provider status observation. */
1394
+ readonly last_probed_at_ms: S.optional<S.Number>;
1393
1395
  /** A LIVE device-code flow awaiting the user (codex/kimi on a remote box):
1394
1396
  * the verification URL + one-time code to surface so the dashboard can
1395
1397
  * render a synced "open this link, enter this code" panel. Present only
@@ -1685,6 +1687,8 @@ export declare const DaemonStatus: S.Struct<{
1685
1687
  readonly host_signed_in: S.optional<S.Boolean>;
1686
1688
  readonly detail: S.optional<S.String>;
1687
1689
  readonly last_login_at_ms: S.optional<S.NullOr<S.Number>>;
1690
+ /** Wall-clock time of the latest real provider status observation. */
1691
+ readonly last_probed_at_ms: S.optional<S.Number>;
1688
1692
  /** A LIVE device-code flow awaiting the user (codex/kimi on a remote box):
1689
1693
  * the verification URL + one-time code to surface so the dashboard can
1690
1694
  * render a synced "open this link, enter this code" panel. Present only
@@ -899,6 +899,8 @@ export const DaemonProviderConnection = S.Struct({
899
899
  host_signed_in: S.optional(S.Boolean),
900
900
  detail: S.optional(S.String),
901
901
  last_login_at_ms: S.optional(S.NullOr(S.Number)),
902
+ /** Wall-clock time of the latest real provider status observation. */
903
+ last_probed_at_ms: S.optional(S.Number),
902
904
  /** A LIVE device-code flow awaiting the user (codex/kimi on a remote box):
903
905
  * the verification URL + one-time code to surface so the dashboard can
904
906
  * render a synced "open this link, enter this code" panel. Present only
@@ -38,6 +38,7 @@ export declare const DeviceState: S.Struct<{
38
38
  readonly host_signed_in: S.optional<S.Boolean>;
39
39
  readonly detail: S.optional<S.String>;
40
40
  readonly last_login_at_ms: S.optional<S.NullOr<S.Number>>;
41
+ readonly last_probed_at_ms: S.optional<S.Number>;
41
42
  readonly pending_auth: S.optional<S.NullOr<S.Struct<{
42
43
  readonly url: S.optional<S.String>;
43
44
  readonly code: S.optional<S.String>;
@@ -147,6 +148,7 @@ export declare const RelayDeviceStateFrame: S.Union<readonly [S.Struct<{
147
148
  readonly host_signed_in: S.optional<S.Boolean>;
148
149
  readonly detail: S.optional<S.String>;
149
150
  readonly last_login_at_ms: S.optional<S.NullOr<S.Number>>;
151
+ readonly last_probed_at_ms: S.optional<S.Number>;
150
152
  readonly pending_auth: S.optional<S.NullOr<S.Struct<{
151
153
  readonly url: S.optional<S.String>;
152
154
  readonly code: S.optional<S.String>;
@@ -984,8 +984,9 @@ export declare const ExtendedModel: S.Struct<{
984
984
  /**
985
985
  * Host-paid included models only: the monthly token allowance each plan
986
986
  * tier gets on OpenLLM's own key. Catalog-owned so a limit change ships
987
- * with a catalog update. An included model also LEADS every default chain
988
- * it belongs to (see `compareDefaultChainMembers`).
987
+ * with a catalog update. An included model TRAILS every default chain it
988
+ * belongs to (see `compareDefaultChainMembers`): the user's own
989
+ * subscriptions, local servers and keys answer first.
989
990
  */
990
991
  readonly included_usage: S.optional<S.Struct<{
991
992
  readonly free: S.Int;
@@ -572,8 +572,9 @@ export const ExtendedModel = S.Struct({
572
572
  /**
573
573
  * Host-paid included models only: the monthly token allowance each plan
574
574
  * tier gets on OpenLLM's own key. Catalog-owned so a limit change ships
575
- * with a catalog update. An included model also LEADS every default chain
576
- * it belongs to (see `compareDefaultChainMembers`).
575
+ * with a catalog update. An included model TRAILS every default chain it
576
+ * belongs to (see `compareDefaultChainMembers`): the user's own
577
+ * subscriptions, local servers and keys answer first.
577
578
  */
578
579
  included_usage: S.optional(IncludedUsage),
579
580
  deprecated: S.optional(S.Boolean),
@@ -197,6 +197,14 @@ export declare const TunnelForwardHeaders: S.Struct<{
197
197
  * bound to the key's cap hold. Uncapped keys omit it.
198
198
  */
199
199
  readonly hop_grant: S.optional<S.String>;
200
+ /**
201
+ * The subscription provider a fleet consumer could not serve itself and
202
+ * is asking this peer for. Mapped to {@link FLEET_PROVIDER_HEADER}; a peer
203
+ * that can't serve it answers with {@link FLEET_DECLINE_HEADER} instead of
204
+ * walking on to a later hop.
205
+ */
206
+ readonly fleet_provider: S.optional<S.String>;
207
+ readonly fleet_model: S.optional<S.String>;
200
208
  }>;
201
209
  export type TTunnelForwardHeaders = S.Schema.Type<typeof TunnelForwardHeaders>;
202
210
  /** Response metadata carried by the mux `res_head` CTRL payload.
@@ -206,6 +214,14 @@ export type TTunnelForwardHeaders = S.Schema.Type<typeof TunnelForwardHeaders>;
206
214
  */
207
215
  export declare const TUNNEL_RESOLVED_MODEL_MAX = 256;
208
216
  export declare const TUNNEL_CHAIN_MAX = 4096;
217
+ /** Request header: the provider a fleet consumer wants this peer to serve. */
218
+ export declare const FLEET_PROVIDER_HEADER = "x-openllm-fleet-provider";
219
+ export declare const FLEET_MODEL_HEADER = "x-openllm-fleet-model";
220
+ /** Response header: this peer can't serve the requested fleet provider. */
221
+ export declare const FLEET_DECLINE_HEADER = "x-openllm-fleet-decline";
222
+ export declare const FLEET_DECLINE_CAUSES: readonly ["not_signed_in", "no_quota", "cooling", "unavailable"];
223
+ export type TFleetDeclineCause = (typeof FLEET_DECLINE_CAUSES)[number];
224
+ export declare const isFleetDeclineCause: (value: string | null) => value is TFleetDeclineCause;
209
225
  export declare const TunnelResponseHeaders: S.Struct<{
210
226
  readonly media_url: S.optional<S.String>;
211
227
  readonly media_persistence: S.optional<S.Literal<"browser">>;
@@ -217,6 +233,8 @@ export declare const TunnelResponseHeaders: S.Struct<{
217
233
  readonly resolved_model: S.optional<S.String>;
218
234
  /** Comma-separated attempted hops — maps to {@link OPENLLM_CHAIN_HEADER}. */
219
235
  readonly chain: S.optional<S.String>;
236
+ /** Maps to {@link FLEET_DECLINE_HEADER}. */
237
+ readonly fleet_decline: S.optional<S.Literals<readonly ["not_signed_in", "no_quota", "cooling", "unavailable"]>>;
220
238
  }>;
221
239
  export type TTunnelResponseHeaders = S.Schema.Type<typeof TunnelResponseHeaders>;
222
240
  /** Copy closed mux res_head fields onto an HTTP Headers object. */
@@ -264,6 +282,14 @@ export declare const TunnelStreamOpenPayload: S.Struct<{
264
282
  * bound to the key's cap hold. Uncapped keys omit it.
265
283
  */
266
284
  readonly hop_grant: S.optional<S.String>;
285
+ /**
286
+ * The subscription provider a fleet consumer could not serve itself and
287
+ * is asking this peer for. Mapped to {@link FLEET_PROVIDER_HEADER}; a peer
288
+ * that can't serve it answers with {@link FLEET_DECLINE_HEADER} instead of
289
+ * walking on to a later hop.
290
+ */
291
+ readonly fleet_provider: S.optional<S.String>;
292
+ readonly fleet_model: S.optional<S.String>;
267
293
  }>>;
268
294
  readonly consumer: S.optional<S.Literals<readonly ["browser", "daemon"]>>;
269
295
  }>;
@@ -303,6 +329,14 @@ export declare const StreamOpenPayload: S.Union<readonly [S.Struct<{
303
329
  * bound to the key's cap hold. Uncapped keys omit it.
304
330
  */
305
331
  readonly hop_grant: S.optional<S.String>;
332
+ /**
333
+ * The subscription provider a fleet consumer could not serve itself and
334
+ * is asking this peer for. Mapped to {@link FLEET_PROVIDER_HEADER}; a peer
335
+ * that can't serve it answers with {@link FLEET_DECLINE_HEADER} instead of
336
+ * walking on to a later hop.
337
+ */
338
+ readonly fleet_provider: S.optional<S.String>;
339
+ readonly fleet_model: S.optional<S.String>;
306
340
  }>>;
307
341
  readonly consumer: S.optional<S.Literals<readonly ["browser", "daemon"]>>;
308
342
  }>, S.Struct<{
@@ -341,6 +375,8 @@ export declare const StreamCtrlPayload: S.Union<readonly [S.Struct<{
341
375
  readonly resolved_model: S.optional<S.String>;
342
376
  /** Comma-separated attempted hops — maps to {@link OPENLLM_CHAIN_HEADER}. */
343
377
  readonly chain: S.optional<S.String>;
378
+ /** Maps to {@link FLEET_DECLINE_HEADER}. */
379
+ readonly fleet_decline: S.optional<S.Literals<readonly ["not_signed_in", "no_quota", "cooling", "unavailable"]>>;
344
380
  }>>;
345
381
  }>, S.Struct<{
346
382
  readonly t: S.Literal<"replay_done">;
@@ -361,6 +361,14 @@ export const TunnelForwardHeaders = S.Struct({
361
361
  * bound to the key's cap hold. Uncapped keys omit it.
362
362
  */
363
363
  hop_grant: S.optional(S.String.check(S.isMaxLength(HOP_GRANT_B64_MAX))),
364
+ /**
365
+ * The subscription provider a fleet consumer could not serve itself and
366
+ * is asking this peer for. Mapped to {@link FLEET_PROVIDER_HEADER}; a peer
367
+ * that can't serve it answers with {@link FLEET_DECLINE_HEADER} instead of
368
+ * walking on to a later hop.
369
+ */
370
+ fleet_provider: S.optional(S.String.check(S.isMaxLength(64))),
371
+ fleet_model: S.optional(S.String.check(S.isMaxLength(256))),
364
372
  });
365
373
  /** Response metadata carried by the mux `res_head` CTRL payload.
366
374
  *
@@ -369,6 +377,19 @@ export const TunnelForwardHeaders = S.Struct({
369
377
  */
370
378
  export const TUNNEL_RESOLVED_MODEL_MAX = 256;
371
379
  export const TUNNEL_CHAIN_MAX = 4096;
380
+ /** Request header: the provider a fleet consumer wants this peer to serve. */
381
+ export const FLEET_PROVIDER_HEADER = "x-openllm-fleet-provider";
382
+ export const FLEET_MODEL_HEADER = "x-openllm-fleet-model";
383
+ /** Response header: this peer can't serve the requested fleet provider. */
384
+ export const FLEET_DECLINE_HEADER = "x-openllm-fleet-decline";
385
+ export const FLEET_DECLINE_CAUSES = [
386
+ "not_signed_in",
387
+ "no_quota",
388
+ "cooling",
389
+ "unavailable",
390
+ ];
391
+ export const isFleetDeclineCause = (value) => value !== null &&
392
+ FLEET_DECLINE_CAUSES.includes(value);
372
393
  export const TunnelResponseHeaders = S.Struct({
373
394
  media_url: S.optional(S.String.check(S.isMaxLength(TUNNEL_MEDIA_URL_MAX_LENGTH))),
374
395
  media_persistence: S.optional(S.Literal(MEDIA_PERSISTENCE_BROWSER)),
@@ -380,6 +401,8 @@ export const TunnelResponseHeaders = S.Struct({
380
401
  resolved_model: S.optional(S.String.check(S.isMaxLength(TUNNEL_RESOLVED_MODEL_MAX))),
381
402
  /** Comma-separated attempted hops — maps to {@link OPENLLM_CHAIN_HEADER}. */
382
403
  chain: S.optional(S.String.check(S.isMaxLength(TUNNEL_CHAIN_MAX))),
404
+ /** Maps to {@link FLEET_DECLINE_HEADER}. */
405
+ fleet_decline: S.optional(S.Literals(FLEET_DECLINE_CAUSES)),
383
406
  });
384
407
  const boundedOptional = (value, max) => {
385
408
  if (value === null || value.length === 0 || value.length > max)
@@ -406,6 +429,9 @@ export const applyTunnelResponseHeadersToHttp = (headers, res) => {
406
429
  if (res.chain !== undefined) {
407
430
  headers.set(OPENLLM_CHAIN_HEADER, res.chain);
408
431
  }
432
+ if (res.fleet_decline !== undefined) {
433
+ headers.set(FLEET_DECLINE_HEADER, res.fleet_decline);
434
+ }
409
435
  };
410
436
  /** Project HTTP response headers onto the closed mux res_head struct. */
411
437
  export const tunnelResponseHeadersFromHttp = (headers) => {
@@ -429,6 +455,11 @@ export const tunnelResponseHeadersFromHttp = (headers) => {
429
455
  is_sse: contentType?.includes("text/event-stream") === true,
430
456
  ...(resolved === undefined ? {} : { resolved_model: resolved }),
431
457
  ...(chain === undefined ? {} : { chain }),
458
+ ...(isFleetDeclineCause(headers.get(FLEET_DECLINE_HEADER))
459
+ ? {
460
+ fleet_decline: headers.get(FLEET_DECLINE_HEADER),
461
+ }
462
+ : {}),
432
463
  };
433
464
  };
434
465
  /** A channel-level admission failure. */
@@ -613,6 +644,8 @@ export const parseStreamOpenPayload = (value) => {
613
644
  "video_id",
614
645
  "team_grant",
615
646
  "hop_grant",
647
+ "fleet_provider",
648
+ "fleet_model",
616
649
  ])) {
617
650
  return null;
618
651
  }
@@ -7,10 +7,11 @@ export declare const PEER_LINK_DEFAULTS: {
7
7
  readonly rtcIceMs: 20000;
8
8
  readonly idleTtlMs: 90000;
9
9
  readonly failureTtlMs: 60000;
10
+ readonly presenceFailureTtlMs: 5000;
10
11
  };
11
12
  export type TPeerLinkPath = "rtc" | "mux";
12
13
  export type TPeerLinkRtcMode = "use-if-open+warm" | "probe";
13
- export type TPeerLinkFailureReason = "aborted" | "not_capable" | "daemon_outdated" | "overloaded" | "tunnel_busy" | "transport" | "unknown";
14
+ export type TPeerLinkFailureReason = "aborted" | "presence" | "relay_unavailable" | "timeout" | "nack" | "not_capable" | "daemon_outdated" | "overloaded" | "tunnel_busy" | "transport" | "unknown";
14
15
  export type TPeerLinkEvent = {
15
16
  readonly type: "selected" | "failed" | "fallback" | "released";
16
17
  readonly path: TPeerLinkPath;
@@ -66,6 +67,7 @@ export type TPeerLinkFailureCache = {
66
67
  /** Clear one transport's failures without erasing the independent rung. */
67
68
  readonly clearPath: (path: TPeerLinkPath) => void;
68
69
  readonly has: (target: string, path: TPeerLinkPath, now?: number) => boolean;
70
+ readonly reason: (target: string, path: TPeerLinkPath, now?: number) => TPeerLinkFailureReason | null;
69
71
  readonly until: (target: string, path: TPeerLinkPath, now?: number) => number | null;
70
72
  readonly set: (target: string, path: TPeerLinkPath, reason: TPeerLinkFailureReason, now?: number) => void;
71
73
  };
@@ -6,6 +6,7 @@ export const PEER_LINK_DEFAULTS = {
6
6
  rtcIceMs: 20_000,
7
7
  idleTtlMs: 90_000,
8
8
  failureTtlMs: 60_000,
9
+ presenceFailureTtlMs: 5_000,
9
10
  };
10
11
  const failureTtlMs = (reason) => {
11
12
  switch (reason) {
@@ -14,9 +15,10 @@ const failureTtlMs = (reason) => {
14
15
  case "overloaded":
15
16
  case "tunnel_busy":
16
17
  return 2_000;
18
+ case "presence":
17
19
  case "not_capable":
18
20
  case "daemon_outdated":
19
- return 5_000;
21
+ return PEER_LINK_DEFAULTS.presenceFailureTtlMs;
20
22
  default:
21
23
  return PEER_LINK_DEFAULTS.failureTtlMs;
22
24
  }
@@ -31,8 +33,8 @@ const cacheKeyOf = (target, path) => `${target}\u0000${path}`;
31
33
  export const createPeerLinkFailureCache = () => {
32
34
  const failureCache = new Map();
33
35
  const sweepFailureCache = (now) => {
34
- for (const [key, until] of failureCache) {
35
- if (until <= now)
36
+ for (const [key, entry] of failureCache) {
37
+ if (entry.until <= now)
36
38
  failureCache.delete(key);
37
39
  }
38
40
  while (failureCache.size > MAX_FAILURE_CACHE_ENTRIES) {
@@ -68,18 +70,22 @@ export const createPeerLinkFailureCache = () => {
68
70
  const until = failureCache.get(key);
69
71
  if (until === undefined)
70
72
  return false;
71
- if (until > now)
73
+ if (until.until > now)
72
74
  return true;
73
75
  failureCache.delete(key);
74
76
  return false;
75
77
  },
78
+ reason(target, path, now = Date.now()) {
79
+ const entry = failureCache.get(cacheKeyOf(target, path));
80
+ return entry !== undefined && entry.until > now ? entry.reason : null;
81
+ },
76
82
  until(target, path, now = Date.now()) {
77
83
  const key = cacheKeyOf(target, path);
78
84
  const until = failureCache.get(key);
79
85
  if (until === undefined)
80
86
  return null;
81
- if (until > now)
82
- return until;
87
+ if (until.until > now)
88
+ return until.until;
83
89
  failureCache.delete(key);
84
90
  return null;
85
91
  },
@@ -89,7 +95,7 @@ export const createPeerLinkFailureCache = () => {
89
95
  if (ttl > 0) {
90
96
  const key = cacheKeyOf(target, path);
91
97
  failureCache.delete(key);
92
- failureCache.set(key, now + ttl);
98
+ failureCache.set(key, { until: now + ttl, reason });
93
99
  sweepFailureCache(now);
94
100
  }
95
101
  },
@@ -101,6 +107,8 @@ export const createPeerLinkFailureCache = () => {
101
107
  */
102
108
  export const peerLinkFailureCache = createPeerLinkFailureCache();
103
109
  export const peerLinkFailureReasonOf = (error) => {
110
+ if (error instanceof DOMException && error.name === "TimeoutError")
111
+ return "timeout";
104
112
  if (error instanceof DOMException && error.name === "AbortError") {
105
113
  return "aborted";
106
114
  }
@@ -126,7 +134,9 @@ export const createPeerLink = (options) => {
126
134
  const openBudgetMs = options.policy?.openBudgetMs ?? PEER_LINK_DEFAULTS.muxAckSameUserMs;
127
135
  const rtcProbeMs = options.policy?.rtcProbeMs ?? Math.min(2_000, openBudgetMs);
128
136
  const idleTtlMs = options.policy?.idleTtlMs ?? PEER_LINK_DEFAULTS.idleTtlMs;
129
- const classify = options.policy?.classifyFailure ?? peerLinkFailureReasonOf;
137
+ const classify = (error) => error instanceof DOMException && error.name === "TimeoutError"
138
+ ? "timeout"
139
+ : (options.policy?.classifyFailure ?? peerLinkFailureReasonOf)(error);
130
140
  // Retrying a dispatched inference can duplicate provider work. Callers must
131
141
  // prove that the failure happened before dispatch to opt into a fallback.
132
142
  const retrySafe = options.policy?.retrySafe ?? (() => false);
@@ -168,8 +178,8 @@ export const createPeerLink = (options) => {
168
178
  let timer;
169
179
  const timedOut = new Promise((_, reject) => {
170
180
  timer = setTimeout(() => {
181
+ reject(new DOMException("Timed out", "TimeoutError"));
171
182
  controller.abort();
172
- reject(new DOMException("Timed out", "AbortError"));
173
183
  }, timeoutMs);
174
184
  });
175
185
  try {
@@ -249,8 +259,35 @@ export const createPeerLink = (options) => {
249
259
  cache(resolved.path, error);
250
260
  const dialer = resolved.path === "rtc" ? options.rtc : options.mux;
251
261
  dialer?.drop?.(resolved.channel);
252
- if (resolved.path !== "rtc")
253
- throw error;
262
+ if (resolved.path === "mux") {
263
+ if (dialer?.drop === undefined)
264
+ throw error;
265
+ peerLinkFailureCache.clear(options.target, "mux");
266
+ const startedAt = now();
267
+ let fresh;
268
+ try {
269
+ fresh = await dialWithin(options.mux, openBudgetMs);
270
+ }
271
+ catch (dialError) {
272
+ cache("mux", dialError);
273
+ throw error;
274
+ }
275
+ if (fresh === null || fresh === resolved.channel)
276
+ throw error;
277
+ const reopened = fresh;
278
+ try {
279
+ return await fn(resultOf("mux", options.mux, reopened, false, startedAt));
280
+ }
281
+ catch (retryError) {
282
+ // One reopen only: a second pre-dispatch failure is cached and its
283
+ // channel dropped, so the next request honours the failure TTL.
284
+ if (retrySafe(retryError)) {
285
+ cache("mux", retryError);
286
+ dialer.drop(reopened);
287
+ }
288
+ throw retryError;
289
+ }
290
+ }
254
291
  emit({
255
292
  type: "fallback",
256
293
  path: "rtc",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openllmsh/sdk",
3
- "version": "2.10.13",
3
+ "version": "2.10.15-alpha.1",
4
4
  "private": false,
5
5
  "description": "The OpenLLM SDK: typed API contracts, wire-format adapters, the device tunnel, client-side vault crypto, the OpenAPI spec and MCP tools.",
6
6
  "keywords": [