@north-light/api 0.3.733 → 0.3.735

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.
@@ -1,5 +1,5 @@
1
1
  /** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
2
- export declare const CONTRACT_LEVEL = "1.72";
2
+ export declare const CONTRACT_LEVEL = "1.73";
3
3
  /** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
4
4
  export declare const REQUIRED_CONTRACT_HEADER = "Crouter-Required-Contract";
5
5
  /** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
@@ -12,7 +12,7 @@
12
12
  //
13
13
  // PURITY (spec §3.1): Node built-ins + `src/api/*` only.
14
14
  /** The contract level this build serves and requires. Written by `scripts/contract.mjs release`; never edit by hand. */
15
- export const CONTRACT_LEVEL = '1.72';
15
+ export const CONTRACT_LEVEL = '1.73';
16
16
  /** Request header naming the one contract level the caller needs, e.g. `1.3`. Optional: absent means no check. */
17
17
  export const REQUIRED_CONTRACT_HEADER = 'Crouter-Required-Contract';
18
18
  /** Response header listing the contract levels the server serves, comma-separated, one per major, e.g. `1.3`. */
@@ -13,18 +13,18 @@ const rotate = defineLeaf({
13
13
  output: [{ name: 'environment_id', type: 'string', required: true, constraint: 'The machine environment the new credential belongs to.' }],
14
14
  outputKind: 'object',
15
15
  effects: [
16
- 'Calls `POST /v1/imports/<run>/machine-credential?rotate=1`, which replaces the stored hash for this machine environment, then writes the new secret to `runtime/secrets/machine-credential` (mode 0600). Authenticates with the person\'s sign-in (`crtr sys signin`; `not_signed_in` without one). Fails when `runtime/machine.json` is missing: this install was not imported as a machine.',
16
+ 'Calls `POST /v1/machines?rotate=1` naming the machine environment in `runtime/machine.json`, which replaces the stored hash for this machine environment, then writes the new secret to `runtime/secrets/machine-credential` (mode 0600). Authenticates with the person\'s sign-in (`crtr sys signin`; `not_signed_in` without one). Fails when `runtime/machine.json` is missing: this install was not imported as a machine.',
17
17
  'The old credential stops opening links as soon as the control plane has replaced it, and the link it already holds is closed within 15 seconds; the Mac reconnects with the new credential.',
18
18
  ],
19
19
  },
20
20
  run: async () => {
21
21
  const config = readMachineConfig();
22
22
  if (config === undefined)
23
- throw usage('this install was not imported as a machine: runtime/machine.json is missing');
23
+ throw usage('this computer is not a Northlight machine: runtime/machine.json is missing');
24
24
  // The sign-in stored by `crtr sys signin` (or by the import): the same person who imported this Mac.
25
25
  const token = await personBearer(config.directoryUrl);
26
- const url = new URL(`/v1/imports/${encodeURIComponent(config.runId)}/machine-credential?rotate=1`, config.apiUrl);
27
- const response = await fetch(url, { method: 'POST', headers: { authorization: `Bearer ${token}` }, signal: AbortSignal.timeout(30_000) });
26
+ const url = new URL('/v1/machines?rotate=1', config.apiUrl);
27
+ const response = await fetch(url, { method: 'POST', headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' }, body: JSON.stringify({ environment_id: config.environmentId }), signal: AbortSignal.timeout(30_000) });
28
28
  const text = await response.text();
29
29
  if (!response.ok)
30
30
  throw general(`the control plane answered ${response.status}: ${text.slice(0, 300)}`);
@@ -83,5 +83,7 @@ export interface BlaxelClient {
83
83
  /** Creates (or adopts) a private preview on `port` and returns its URL. */
84
84
  ensurePreview(sandboxName: string, previewName: string, port: number): Promise<string>;
85
85
  createPreviewToken(sandboxName: string, previewName: string, expiresAt: Date): Promise<PreviewToken>;
86
+ /** Deleting an absent preview (or one of an absent sandbox) is not an error. */
87
+ deletePreview(sandboxName: string, previewName: string): Promise<void>;
86
88
  }
87
89
  export declare function createBlaxelClient(config: BlaxelConfig): BlaxelClient;
@@ -143,5 +143,8 @@ export function createBlaxelClient(config) {
143
143
  const spec = json.spec;
144
144
  return { token: spec.token, expiresAt: spec.expiresAt };
145
145
  },
146
+ async deletePreview(sandboxName, previewName) {
147
+ await call(`${control}/sandboxes/${encodeName(sandboxName)}/previews/${encodeName(previewName)}`, 'DELETE', undefined, [404]);
148
+ },
146
149
  };
147
150
  }
@@ -56,6 +56,7 @@ export function createBlaxelRunner(deps) {
56
56
  // "Name taken" means an earlier start created it: the client adopts it, files and all. One on an older image is replaced.
57
57
  let sandbox = await client.createSandbox(spec);
58
58
  if (sandbox.image !== context.image) {
59
+ await client.deletePreview(name, VIEW_PREVIEW);
59
60
  await client.deleteSandbox(name);
60
61
  previewTokens.delete(name);
61
62
  sandbox = await client.createSandbox(spec);
@@ -145,6 +146,8 @@ export function createBlaxelRunner(deps) {
145
146
  }
146
147
  },
147
148
  async delete(nodeId) {
149
+ // Blaxel counts a preview against the account quota until the preview itself is deleted; deleting the sandbox alone leaks it.
150
+ await client.deletePreview(sandboxNameFor(nodeId), VIEW_PREVIEW);
148
151
  await client.deleteSandbox(sandboxNameFor(nodeId));
149
152
  previewTokens.delete(sandboxNameFor(nodeId));
150
153
  },
@@ -204,6 +204,7 @@ export const OPERATIONS = [
204
204
  { name: 'import.load', method: 'POST', path: '/v1/imports/:run_id/load', classes: ['person', 'import'], resource: 'none' },
205
205
  { name: 'import.get', method: 'GET', path: '/v1/imports/:run_id', classes: ['person', 'import'], resource: 'none' },
206
206
  { name: 'import.rollback', method: 'POST', path: '/v1/imports/:run_id/rollback', classes: ['person'], resource: 'none' },
207
+ { name: 'machine.register', method: 'POST', path: '/v1/machines', classes: ['person'], resource: 'none' },
207
208
  { name: 'import.machine-credential', method: 'POST', path: '/v1/imports/:run_id/machine-credential', classes: ['person'], resource: 'none' },
208
209
  { name: 'execution.import-unpacked', method: 'POST', path: '/v1/executions/:execution_id/import-unpacked', classes: ['broker'], resource: 'none' },
209
210
  { name: 'execution.start', method: 'GET', path: '/v1/executions/:execution_id/start', classes: ['broker'], resource: 'none' },
@@ -4,7 +4,7 @@
4
4
  import { liveExecutionForNode, endExecution, recordExecutionAwake, endLaunchingExecution, requestExecutionStop } from '../../../core/canvas/executions.js';
5
5
  import { openDb } from '../../../core/canvas/db.js';
6
6
  import { isCloudRole } from '../../../core/canvas/person-state.js';
7
- import { getRow } from '../../../core/canvas/index.js';
7
+ import { getRow, recordRespawnAttempt } from '../../../core/canvas/index.js';
8
8
  import { fullName } from '../../../core/canvas/labels.js';
9
9
  import { publishNotice } from '../../../core/runtime/close.js';
10
10
  import { emitEvent } from '../../../core/events/emit.js';
@@ -145,6 +145,8 @@ export async function recoverLaunching(nodeId, now) {
145
145
  }
146
146
  else {
147
147
  const wake = `Child crashed — ${fullName(row)} (${nodeId}) failed ${attempt.failures} consecutive sandbox launches (${message}) and is now dead. It stays dead until you revive it — \`crtr node lifecycle revive ${nodeId}\`.`;
148
+ // The count stays as the record; the backoff is cleared so a later revive cannot be read as still mid-sequence.
149
+ await recordRespawnAttempt(nodeId, { failures: attempt.failures, notBefore: null });
148
150
  emitEvent({ level: 'error', event: 'broker.respawn.exhausted', node_id: nodeId });
149
151
  await transition(nodeId, 'crash', { reason: 'crash_looped', outcome: { detail: { schema: 'crtr.node-outcome-detail/v1', message: wake, respawn_failures: attempt.failures } } });
150
152
  await publishNotice(nodeId, 'notice.crash', wake, { reason: 'child-crashed', child: nodeId });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/api",
3
- "version": "0.3.733",
3
+ "version": "0.3.735",
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",