@north-light/cli 0.3.716 → 0.3.717

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.716",
3
+ "version": "0.3.717",
4
4
  "description": "crtr — agent runtime with memory, plugins, and marketplaces",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -158,8 +158,8 @@
158
158
  },
159
159
  "license": "UNLICENSED",
160
160
  "dependencies": {
161
- "@north-light/identity": "0.3.716",
162
- "@north-light/plugin": "0.3.716",
161
+ "@north-light/identity": "0.3.717",
162
+ "@north-light/plugin": "0.3.717",
163
163
  "@earendil-works/chord": "1.5.2",
164
164
  "@earendil-works/pi-agent-core": "1.5.2",
165
165
  "@earendil-works/pi-ai": "1.5.2",
@@ -627,6 +627,16 @@ onConnected) {
627
627
  // The release selected on this machine, never the daemon's: a signed-in viewer's status call is answered by the server.
628
628
  const selected = selectedGeneration().generation?.id;
629
629
  if (mine !== undefined && selected !== undefined && selected !== mine && selected !== restartedFor && !lifecycle.isTornDown()) {
630
+ // The new process reads the account's settings before it paints and exits when it cannot. A welcome right after the computer
631
+ // wakes can come before its network does, so make that request first and leave the restart to a later welcome if it fails.
632
+ try {
633
+ await cliClient({ timeoutMs: 5_000 }).getSettings();
634
+ }
635
+ catch {
636
+ return;
637
+ }
638
+ if (lifecycle.isTornDown())
639
+ return;
630
640
  restartViewer({ CRTR_ATTACH_RESTARTED_FOR: selected });
631
641
  }
632
642
  };
@@ -197,6 +197,14 @@ function llmUrl() {
197
197
  function llmFetch() {
198
198
  return brokerApiUrl() === undefined ? socketFetch(apiSocketPath()) : globalThis.fetch;
199
199
  }
200
+ /** Before a retry, ask this broker's own gateway whether it can serve `model` now (`GET /healthz?model=`); no wait means no answer. */
201
+ export async function askGateway(model) {
202
+ const response = await llmFetch()(llmUrl().replace(/\/v1\/llm$/, `/healthz?model=${encodeURIComponent(model)}`), { signal: AbortSignal.timeout(5_000) }).catch(() => null);
203
+ if (response?.status === 200)
204
+ return { ok: true };
205
+ const seconds = response?.status === 503 ? (await response.json().catch(() => null))?.error?.retry_after_s : undefined;
206
+ return typeof seconds === 'number' ? { ok: false, waitMs: seconds * 1000, reason: `waiting for ${model}: model unavailable` } : { ok: false, reason: `waiting for ${model}: gateway not answering` };
207
+ }
200
208
  /** The real response under a deferred-head framing (`daemon/api/deferred-head.ts`): the magic line, keep-alive
201
209
  * blank lines, one JSON head line, then the body unchanged. Any other response is returned as it is. */
202
210
  export async function unwrapDeferredHead(response) {
@@ -304,7 +312,7 @@ export function streamBrokerModel(model, context, options = {}, intent, causedBy
304
312
  // stamping it as a refusal would record it as fatal and park the node.
305
313
  if (typeof seconds !== 'number' || !Number.isFinite(seconds) || seconds <= 0) {
306
314
  // Named by code, not prose: `upstream_model_unavailable` is a connection fault with automatic retry (RT-LLM-65).
307
- throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message) : new Error(error.message);
315
+ throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message, { cause: error.details?.breaker }) : new Error(error.message);
308
316
  }
309
317
  // A wait that outlasts what is left of the retry window cannot end in a
310
318
  // retry here, so sleeping first only delays the same failure. Fail now
@@ -337,7 +345,7 @@ export function streamBrokerModel(model, context, options = {}, intent, causedBy
337
345
  applyServedModel(message, refusalRoute(error));
338
346
  if (error.retryable !== true)
339
347
  throw new LlmRefusalError(error.message, undefined, refusalRateLimit(error), error.code, undefined, refusalPayment(error));
340
- throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message) : new Error(error.message);
348
+ throw error.code === UPSTREAM_MODEL_UNAVAILABLE ? new UpstreamModelUnavailableError(error.message, { cause: error.details?.breaker }) : new Error(error.message);
341
349
  }
342
350
  if (chunk.served_model) {
343
351
  receivedServedModel = true;
@@ -431,8 +439,9 @@ export function streamBrokerModel(model, context, options = {}, intent, causedBy
431
439
  : []),
432
440
  ];
433
441
  }
442
+ // A breaker mark (`open` or `test`) tells the fault retry not to count this attempt.
434
443
  if (error instanceof UpstreamModelUnavailableError)
435
- message.diagnostics = [providerFailureDiagnostic({ status: 503, code: UPSTREAM_MODEL_UNAVAILABLE })];
444
+ message.diagnostics = [providerFailureDiagnostic({ status: 503, code: UPSTREAM_MODEL_UNAVAILABLE, ...(error.cause === undefined ? {} : { body: 'breaker' }) })];
436
445
  if (error instanceof ContentFilteredError && message.stopReason === 'error')
437
446
  message.rawStopReason = 'content_filter';
438
447
  stream.push({ type: 'error', reason: message.stopReason, error: message });
@@ -1,19 +1,19 @@
1
1
  const POLICIES = {
2
- connection: { kind: 'connection', gate: 'online', max: 8, baseDelayMs: 5_000, capDelayMs: 60_000, fatal: false },
3
- 'rate-limit': { kind: 'rate-limit', gate: 'time', max: 6, baseDelayMs: 30_000, capDelayMs: 5 * 60_000, fatal: false },
4
- overloaded: { kind: 'overloaded', gate: 'time', max: 6, baseDelayMs: 10_000, capDelayMs: 2 * 60_000, fatal: false },
5
- auth: { kind: 'auth', gate: 'none', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
6
- protocol: { kind: 'protocol', gate: 'none', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
7
- 'context-overflow': { kind: 'context-overflow', gate: 'none', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
8
- other: { kind: 'other', gate: 'none', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
2
+ connection: { kind: 'connection', max: 8, baseDelayMs: 5_000, capDelayMs: 60_000, fatal: false },
3
+ 'rate-limit': { kind: 'rate-limit', max: 6, baseDelayMs: 30_000, capDelayMs: 5 * 60_000, fatal: false },
4
+ overloaded: { kind: 'overloaded', max: 6, baseDelayMs: 10_000, capDelayMs: 2 * 60_000, fatal: false },
5
+ auth: { kind: 'auth', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
6
+ protocol: { kind: 'protocol', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
7
+ 'context-overflow': { kind: 'context-overflow', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
8
+ other: { kind: 'other', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
9
9
  // A wedge is a daemon-detected stall, never auto-retried — recovery is a
10
10
  // deliberate agent/operator decision (kill the runaway subprocess), not a
11
11
  // provider back-off.
12
- wedged: { kind: 'wedged', gate: 'none', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
12
+ wedged: { kind: 'wedged', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
13
13
  // A launch-time model resolution failure (unregistered/unauthenticated spec) —
14
14
  // never auto-retried, since retrying with the same unresolved model would just
15
15
  // fail again identically. Fixing it requires a new --model or new credentials.
16
- 'model-not-found': { kind: 'model-not-found', gate: 'none', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
16
+ 'model-not-found': { kind: 'model-not-found', max: 0, baseDelayMs: 0, capDelayMs: 0, fatal: true },
17
17
  };
18
18
  export function policyFor(kind) {
19
19
  return POLICIES[kind];
@@ -23,14 +23,7 @@ function clampDelay(delayMs, capMs) {
23
23
  return 0;
24
24
  return Math.min(Math.max(1, Math.round(delayMs)), capMs);
25
25
  }
26
- function defaultOverloadedJitterMs(fault, attempt) {
27
- const seed = `${fault.link}|${fault.kind}|${fault.message}|${fault.since}|${attempt}`;
28
- let hash = 0;
29
- for (let i = 0; i < seed.length; i++) {
30
- hash = (hash * 33 + seed.charCodeAt(i)) >>> 0;
31
- }
32
- return hash % 1_000;
33
- }
26
+ /** Full jitter for connection and overloaded faults: a random delay between zero and the doubled delay, so nodes that failed together do not retry together. */
34
27
  function retryDelayMs(fault, attempt, opts) {
35
28
  const policy = policyFor(fault.kind);
36
29
  if (policy.fatal)
@@ -38,11 +31,7 @@ function retryDelayMs(fault, attempt, opts) {
38
31
  if (fault.kind === 'rate-limit' && typeof opts?.retryAfterMs === 'number' && Number.isFinite(opts.retryAfterMs)) {
39
32
  return clampDelay(opts.retryAfterMs, policy.capDelayMs);
40
33
  }
41
- const delay = policy.baseDelayMs * 2 ** Math.max(0, attempt - 1);
42
- const jitter = fault.kind === 'overloaded'
43
- ? Math.max(0, Math.round(opts?.jitterMs?.(fault, attempt) ?? defaultOverloadedJitterMs(fault, attempt)))
44
- : 0;
45
- return clampDelay(delay + jitter, policy.capDelayMs);
34
+ return clampDelay((fault.kind === 'rate-limit' ? 1 : Math.random()) * Math.min(policy.capDelayMs, policy.baseDelayMs * 2 ** Math.max(0, attempt - 1)), policy.capDelayMs);
46
35
  }
47
36
  export function nextFaultRetry(fault, now, opts) {
48
37
  const policy = policyFor(fault.kind);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.716",
3
+ "version": "0.3.717",
4
4
  "description": "Typed crtrd /v1 API contract — DTOs, route builders, the error contract, the CrtrClient, and the command-plugin manifest format. Zero runtime dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/api/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.716",
3
+ "version": "0.3.717",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/plugin",
3
- "version": "0.3.716",
3
+ "version": "0.3.717",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "postpack": "node ../../scripts/pack-minify.mjs postpack packages/crouter-plugin"
28
28
  },
29
29
  "dependencies": {
30
- "@north-light/api": "0.3.716",
31
- "@north-light/identity": "0.3.716"
30
+ "@north-light/api": "0.3.717",
31
+ "@north-light/identity": "0.3.717"
32
32
  },
33
33
  "license": "UNLICENSED",
34
34
  "publishConfig": {
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.716",
3
+ "version": "0.3.717",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.716",
9
+ "version": "0.3.717",
10
10
  "hasInstallScript": true,
11
11
  "license": "UNLICENSED",
12
12
  "workspaces": [
@@ -28,8 +28,8 @@
28
28
  "@milkdown/preset-gfm": "^7.22.3",
29
29
  "@milkdown/prose": "^7.22.3",
30
30
  "@milkdown/utils": "^7.22.3",
31
- "@north-light/identity": "0.3.716",
32
- "@north-light/plugin": "0.3.716",
31
+ "@north-light/identity": "0.3.717",
32
+ "@north-light/plugin": "0.3.717",
33
33
  "cron-parser": "^5.6.0",
34
34
  "esbuild": "0.28.2",
35
35
  "jose": "^6.2.12",
@@ -11902,17 +11902,17 @@
11902
11902
  },
11903
11903
  "packages/crouter-api": {
11904
11904
  "name": "@north-light/api",
11905
- "version": "0.3.716",
11905
+ "version": "0.3.717",
11906
11906
  "license": "UNLICENSED"
11907
11907
  },
11908
11908
  "packages/crouter-env-docker": {
11909
11909
  "name": "@north-light/env-docker",
11910
- "version": "0.3.716",
11910
+ "version": "0.3.717",
11911
11911
  "license": "UNLICENSED"
11912
11912
  },
11913
11913
  "packages/crouter-identity": {
11914
11914
  "name": "@north-light/identity",
11915
- "version": "0.3.716",
11915
+ "version": "0.3.717",
11916
11916
  "license": "UNLICENSED",
11917
11917
  "dependencies": {
11918
11918
  "jose": "^6.2.1"
@@ -11920,21 +11920,21 @@
11920
11920
  },
11921
11921
  "packages/crouter-plugin": {
11922
11922
  "name": "@north-light/plugin",
11923
- "version": "0.3.716",
11923
+ "version": "0.3.717",
11924
11924
  "license": "UNLICENSED",
11925
11925
  "dependencies": {
11926
- "@north-light/api": "0.3.716",
11927
- "@north-light/identity": "0.3.716"
11926
+ "@north-light/api": "0.3.717",
11927
+ "@north-light/identity": "0.3.717"
11928
11928
  }
11929
11929
  },
11930
11930
  "packages/crouter-sdk": {
11931
11931
  "name": "@north-light/sdk",
11932
- "version": "0.3.716",
11932
+ "version": "0.3.717",
11933
11933
  "license": "UNLICENSED",
11934
11934
  "dependencies": {
11935
- "@north-light/api": "0.3.716",
11936
- "@north-light/identity": "0.3.716",
11937
- "@north-light/plugin": "0.3.716",
11935
+ "@north-light/api": "0.3.717",
11936
+ "@north-light/identity": "0.3.717",
11937
+ "@north-light/plugin": "0.3.717",
11938
11938
  "jose": "^6.2.1"
11939
11939
  },
11940
11940
  "bin": {