@capybara-hq/kernel 0.1.0-rc.70 → 0.1.0-rc.72

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/bootstrap.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "schemaVersion": 1,
4
4
  "marketplace": {
5
5
  "url": "https://github.com/capybara-hq/plugins.git",
6
- "commit": "ae3c41845e672ece6210d202a325056b6e784c08"
6
+ "commit": "8f3fcf3ca8014008352ceeb8cee8ddfeff1909ec"
7
7
  },
8
8
  "plugins": [
9
9
  {
@@ -94,6 +94,15 @@
94
94
  "integrity": "sha512-cbxrv0s9YfMT8rw4TygcRYxrb6x0JPVF2WwtdQtT13lHsQmyOSxIT1GJAHxs5GxUZeRIwrt38AaIGXL/NIqvJA==",
95
95
  "required": false
96
96
  },
97
+ {
98
+ "name": "device-local",
99
+ "source": "npm",
100
+ "npm": "@capybara-hq/plugin-device-local",
101
+ "version": "0.1.0-rc.1",
102
+ "integrity": "sha512-Hf/yjU3T9M4v9yD4jg0rHwXBgJq3/TI4RngE+7bq6naItkPF7R6njJkYoJ+sMIhuT6S47/RT8fgdwrJsJc78dA==",
103
+ "required": false,
104
+ "scope": "all"
105
+ },
97
106
  {
98
107
  "name": "todo",
99
108
  "source": "npm",
@@ -203,7 +203,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
203
203
  /** The host versions (an entry's `minKernel` is judged against them). */
204
204
  export declare const HOST_VERSIONS: {
205
205
  readonly kernel: string;
206
- readonly sdk: "0.1.0-rc.55";
206
+ readonly sdk: "0.1.0-rc.56";
207
207
  };
208
208
  /** Whether this deployment satisfies the entry's `minKernel`. */
209
209
  export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
@@ -62,7 +62,7 @@ export interface KernelDeps {
62
62
  * served by the calling extension. Absent (a ctx built alone in a test): `ctx.dialIn` calls
63
63
  * reject.
64
64
  */
65
- dialIn?: Pick<DialInAccess, "serves" | "request" | "online" | "stop">;
65
+ dialIn?: Pick<DialInAccess, "serves" | "request" | "online" | "capacity" | "stop">;
66
66
  /**
67
67
  * What `ctx.devices` is built from (`DeviceReports`): `changed` reads a device's report again
68
68
  * from the calling provider and refuses (`not-served`) a device bound to another one. Absent
@@ -314,6 +314,7 @@ export function createExtensionContext(deps, manifest, deploymentConfig, extensi
314
314
  });
315
315
  },
316
316
  online: async (deviceId) => access.online(await served(deviceId)),
317
+ capacity: async (deviceId) => access.capacity(await served(deviceId)),
317
318
  stop: async (deviceId, reason) => {
318
319
  if (reason !== "drain" && reason !== "stop")
319
320
  throw new TypeError(`plugin ${name}: ctx.dialIn.stop reason must be drain or stop`);
@@ -8,7 +8,7 @@ import { DialInRelay, type DialInRequestOptions } from "./relay.js";
8
8
  export declare class DialInAccess {
9
9
  private readonly kdb;
10
10
  private readonly relay;
11
- constructor(kdb: KernelDb, relay: Pick<DialInRelay, "request" | "online" | "stop">);
11
+ constructor(kdb: KernelDb, relay: Pick<DialInRelay, "request" | "online" | "capacity" | "stop">);
12
12
  /**
13
13
  * Whether `deviceId` is a live device (in a live org) whose `devices.provider` is `plugin`, and
14
14
  * `plugin` is enabled in the device's org. Read from PG at every call. The full availability
@@ -19,5 +19,8 @@ export declare class DialInAccess {
19
19
  /** {@link DialInRelay.request} with only the options an extension may pass. */
20
20
  request(deviceId: string, body: unknown, opts: Pick<DialInRequestOptions, "timeoutMs" | "signal">): Promise<unknown>;
21
21
  online(deviceId: string): Promise<boolean>;
22
+ capacity(deviceId: string): Promise<{
23
+ maxFrameBytes: number;
24
+ } | null>;
22
25
  stop(deviceId: string, reason: "drain" | "stop"): Promise<void>;
23
26
  }
@@ -52,6 +52,9 @@ let DialInAccess = class DialInAccess {
52
52
  online(deviceId) {
53
53
  return this.relay.online(deviceId);
54
54
  }
55
+ capacity(deviceId) {
56
+ return this.relay.capacity(deviceId);
57
+ }
55
58
  stop(deviceId, reason) {
56
59
  return this.relay.stop(deviceId, reason);
57
60
  }
@@ -142,6 +142,8 @@ declare class DeviceConnection {
142
142
  * provider that accepted the hello why the connection ended (`onClose`).
143
143
  */
144
144
  shutdown(): Promise<void>;
145
+ /** The machine and connection a provider callback is about (a fresh object per call). */
146
+ private info;
145
147
  /** The provider's `onClose`, after the lease is handed back; its failure is only logged. */
146
148
  private tellClosed;
147
149
  }
@@ -348,7 +348,7 @@ class DeviceConnection {
348
348
  const signal = AbortSignal.any([this.ended.signal, AbortSignal.timeout(HELLO_TIMEOUT_MS)]);
349
349
  let timer;
350
350
  try {
351
- const answer = serving.handler.onHello(this.deviceId, body, signal);
351
+ const answer = serving.handler.onHello(this.deviceId, body, signal, this.info());
352
352
  const r = await Promise.race([
353
353
  answer,
354
354
  new Promise((_, reject) => {
@@ -382,7 +382,7 @@ class DeviceConnection {
382
382
  const serving = await this.gw.handlers.forDevice(this.deviceId);
383
383
  if ("unavailable" in serving || serving.plugin !== this.accepted.plugin)
384
384
  return;
385
- await serving.handler.onFrame?.(this.deviceId, body);
385
+ await serving.handler.onFrame?.(this.deviceId, body, this.info());
386
386
  }
387
387
  catch (e) {
388
388
  this.gw.log.warn("device provider failed a frame", {
@@ -705,6 +705,10 @@ class DeviceConnection {
705
705
  })();
706
706
  return this.released;
707
707
  }
708
+ /** The machine and connection a provider callback is about (a fresh object per call). */
709
+ info() {
710
+ return { machineId: this.identity.machineId, connectionId: this.connectionId };
711
+ }
708
712
  /** The provider's `onClose`, after the lease is handed back; its failure is only logged. */
709
713
  tellClosed() {
710
714
  const accepted = this.accepted;
@@ -712,7 +716,7 @@ class DeviceConnection {
712
716
  return;
713
717
  this.accepted = undefined;
714
718
  try {
715
- const r = accepted.handler.onClose?.(this.deviceId, this.closeReason);
719
+ const r = accepted.handler.onClose?.(this.deviceId, this.closeReason, this.info());
716
720
  if (r instanceof Promise)
717
721
  r.catch((e) => this.gw.log.warn("device provider failed onClose", {
718
722
  deviceId: this.deviceId,
@@ -27,7 +27,7 @@ export declare class DialInHandlers {
27
27
  private readonly providers;
28
28
  private readonly selection;
29
29
  private readonly registry;
30
- constructor(kdb: KernelDb, providers: Pick<DeviceProviders, "forDevice">, selection: Pick<DeviceProviderSelection, "isOnInOrg" | "onInOrg">, registry: Pick<ExtensionRegistry, "current">);
30
+ constructor(kdb: KernelDb, providers: Pick<DeviceProviders, "forDevice" | "loaded">, selection: Pick<DeviceProviderSelection, "isOnInOrg" | "onInOrg">, registry: Pick<ExtensionRegistry, "current">);
31
31
  forDevice(deviceId: string): Promise<DialInServing | DialInUnavailable>;
32
32
  /**
33
33
  * The dial-in providers that serve `orgId` now, each with the protocol its machines speak: the
@@ -38,6 +38,15 @@ export declare class DialInHandlers {
38
38
  plugin: string;
39
39
  protocol: string;
40
40
  }[]>;
41
+ /**
42
+ * The dial-in providers loaded in this process, in any org or none, each with the protocol its
43
+ * machines speak (registry order). Read at every call; `GET /api/v1/meta` reports from it
44
+ * whether machines running `capybara-device` can connect at all.
45
+ */
46
+ loaded(): {
47
+ plugin: string;
48
+ protocol: string;
49
+ }[];
41
50
  /**
42
51
  * The protocol a provider's machines speak, when it serves devices over the dial-in channel:
43
52
  * its manifest's `permissions.dialIn.protocol` and a `DeviceProvider.dialIn` handler (an
@@ -63,6 +63,20 @@ let DialInHandlers = class DialInHandlers {
63
63
  }
64
64
  return out;
65
65
  }
66
+ /**
67
+ * The dial-in providers loaded in this process, in any org or none, each with the protocol its
68
+ * machines speak (registry order). Read at every call; `GET /api/v1/meta` reports from it
69
+ * whether machines running `capybara-device` can connect at all.
70
+ */
71
+ loaded() {
72
+ const out = [];
73
+ for (const e of this.providers.loaded()) {
74
+ const protocol = this.protocolOf(e);
75
+ if (protocol !== undefined)
76
+ out.push({ plugin: e.plugin, protocol });
77
+ }
78
+ return out;
79
+ }
66
80
  /**
67
81
  * The protocol a provider's machines speak, when it serves devices over the dial-in channel:
68
82
  * its manifest's `permissions.dialIn.protocol` and a `DeviceProvider.dialIn` handler (an
@@ -81,6 +81,16 @@ export declare class DialInRelay {
81
81
  constructor(redis: Redis, bus: ExtensionContext["bus"], locks: Pick<LockService, "holderOf">, config: Pick<KernelConfigService, "get">, log: Pick<KernelLogger, "warn">, targets: Pick<DeviceTargets, "state" | "current">);
82
82
  /** Whether a gateway replica holds the machine's connection now. */
83
83
  online(deviceId: string): Promise<boolean>;
84
+ /**
85
+ * The negotiated frame capacity of the machine's current connection (`ctx.dialIn.capacity`):
86
+ * the `maxFrameBytes` the holder published with its lease and sent in `ready`, read from Redis
87
+ * under the exact lease (never current config, never process memory), so any replica answers.
88
+ * Null when no replica holds the machine's connection; throws while the holder has not
89
+ * published its capacity yet ({@link DeviceTargets.current}).
90
+ */
91
+ capacity(deviceId: string): Promise<{
92
+ maxFrameBytes: number;
93
+ } | null>;
84
94
  /**
85
95
  * The negotiated transport of the machine's current connection. Liveness is checked first
86
96
  * (ruling R27): no holder throws `device.not_found` for a deleted device, `device.forbidden` for
@@ -121,6 +121,17 @@ let DialInRelay = class DialInRelay {
121
121
  async online(deviceId) {
122
122
  return (await this.locks.holderOf(deviceLeaseKey(deviceId))) !== null;
123
123
  }
124
+ /**
125
+ * The negotiated frame capacity of the machine's current connection (`ctx.dialIn.capacity`):
126
+ * the `maxFrameBytes` the holder published with its lease and sent in `ready`, read from Redis
127
+ * under the exact lease (never current config, never process memory), so any replica answers.
128
+ * Null when no replica holds the machine's connection; throws while the holder has not
129
+ * published its capacity yet ({@link DeviceTargets.current}).
130
+ */
131
+ async capacity(deviceId) {
132
+ const current = await this.targets.current(deviceId);
133
+ return current ? { maxFrameBytes: current.maxFrameBytes } : null;
134
+ }
124
135
  /**
125
136
  * The negotiated transport of the machine's current connection. Liveness is checked first
126
137
  * (ruling R27): no holder throws `device.not_found` for a deleted device, `device.forbidden` for
@@ -45,6 +45,7 @@ import { DevicesController } from "../devices/devices.controller.js";
45
45
  import { DevicesModule } from "../devices/devices.module.js";
46
46
  import { DialInAuthController } from "../dial-in/auth.controller.js";
47
47
  import { DialInAuthModule } from "../dial-in/auth.module.js";
48
+ import { DialInModule } from "../dial-in/dial-in.module.js";
48
49
  import { EvalsModule } from "../evals/evals.module.js";
49
50
  import { EvalRunsController } from "../evals/runs.controller.js";
50
51
  import { EvalSetsController } from "../evals/sets.controller.js";
@@ -239,6 +240,8 @@ ApiModule = __decorate([
239
240
  BackgroundModule,
240
241
  DevicesModule,
241
242
  DialInAuthModule,
243
+ // the loaded dial-in providers GET /api/v1/meta reports (MetaController)
244
+ DialInModule,
242
245
  RuntimeModule,
243
246
  ChannelsModule,
244
247
  EvalsModule,
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { DialInHandlers } from "../dial-in/handlers.js";
2
3
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
3
4
  import { PushProviderHost } from "../push/provider-host.js";
4
5
  import { PlatformIconService } from "../themes/platform-icon.service.js";
@@ -28,12 +29,21 @@ export declare const MetaResponseSchema: z.ZodObject<{
28
29
  appRedirectUris: z.ZodArray<z.ZodString>;
29
30
  }, z.core.$strip>;
30
31
  export type MetaResponse = z.infer<typeof MetaResponseSchema>;
32
+ /**
33
+ * The `capybara-device` majors the given dial-in protocols name (`<name>/<major>`, already checked
34
+ * against `DIAL_IN_PROTOCOL_RE` when the provider loaded), as a range; null when none does.
35
+ */
36
+ export declare function deviceProtocolRange(protocols: readonly string[]): {
37
+ min: number;
38
+ max: number;
39
+ } | null;
31
40
  /** `GET /api/v1/meta`: public, never cached, reveals only what a client needs before signing in. */
32
41
  export declare class MetaController {
33
42
  private readonly config;
34
43
  private readonly icons;
35
44
  private readonly push;
36
- constructor(config: KernelConfigService, icons: PlatformIconService, push: PushProviderHost);
45
+ private readonly dialIn;
46
+ constructor(config: KernelConfigService, icons: PlatformIconService, push: PushProviderHost, dialIn: Pick<DialInHandlers, "loaded">);
37
47
  meta(): Promise<MetaResponse>;
38
48
  /** A customised platform icon's versioned URL (the one the manifest uses); null for the default. */
39
49
  private iconUrl;
@@ -7,9 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { DEVICE_PROTOCOL_VERSION } from "@capybara-hq/plugin-sdk/device-protocol";
10
+ import { DEVICE_DIAL_IN_PROTOCOL, DEVICE_PROTOCOL_VERSION, } from "@capybara-hq/plugin-sdk/device-protocol";
11
11
  import { Controller, Get, Header, Inject } from "@nestjs/common";
12
12
  import { z } from "zod";
13
+ import { DialInHandlers } from "../dial-in/handlers.js";
13
14
  import { Public } from "../identity/principal.js";
14
15
  import { KernelConfigService } from "../infra/config/kernel-config.service.js";
15
16
  import { PushProviderHost } from "../push/provider-host.js";
@@ -24,9 +25,14 @@ export const MetaResponseSchema = z.object({
24
25
  favicon: z.string().nullable(),
25
26
  }),
26
27
  protocols: z.object({
28
+ /**
29
+ * The `capybara-device` protocol majors the loaded dial-in providers speak (their
30
+ * `permissions.dialIn.protocol`); without any, the SDK's major, and `localDevices` is false.
31
+ */
27
32
  device: z.object({ min: z.number().int(), max: z.number().int() }),
28
33
  }),
29
34
  features: z.object({
35
+ /** A dial-in provider speaking `capybara-device/<major>` (device-local) is loaded. */
30
36
  localDevices: z.boolean(),
31
37
  appSignIn: z.boolean(),
32
38
  /** App ids a push provider covers with the providers that do; `[]` without `http.publicUrl`. */
@@ -35,15 +41,33 @@ export const MetaResponseSchema = z.object({
35
41
  /** The redirect URIs app sign-in accepts (`auth.appRedirectUris`); [] while appSignIn is off. */
36
42
  appRedirectUris: z.array(z.string()),
37
43
  });
44
+ /** The protocol name `capybara-device` speaks (`capybara-device` of `capybara-device/<major>`). */
45
+ const DEVICE_PROTOCOL_NAME = DEVICE_DIAL_IN_PROTOCOL.slice(0, DEVICE_DIAL_IN_PROTOCOL.indexOf("/"));
46
+ /**
47
+ * The `capybara-device` majors the given dial-in protocols name (`<name>/<major>`, already checked
48
+ * against `DIAL_IN_PROTOCOL_RE` when the provider loaded), as a range; null when none does.
49
+ */
50
+ export function deviceProtocolRange(protocols) {
51
+ const majors = protocols
52
+ .map((p) => p.split("/"))
53
+ .filter(([name]) => name === DEVICE_PROTOCOL_NAME)
54
+ .map(([, major]) => Number(major))
55
+ .filter((n) => Number.isInteger(n));
56
+ if (majors.length === 0)
57
+ return null;
58
+ return { min: Math.min(...majors), max: Math.max(...majors) };
59
+ }
38
60
  /** `GET /api/v1/meta`: public, never cached, reveals only what a client needs before signing in. */
39
61
  let MetaController = class MetaController {
40
62
  config;
41
63
  icons;
42
64
  push;
43
- constructor(config, icons, push) {
65
+ dialIn;
66
+ constructor(config, icons, push, dialIn) {
44
67
  this.config = config;
45
68
  this.icons = icons;
46
69
  this.push = push;
70
+ this.dialIn = dialIn;
47
71
  }
48
72
  async meta() {
49
73
  const config = this.config.get();
@@ -53,13 +77,18 @@ let MetaController = class MetaController {
53
77
  this.iconUrl("favicon"),
54
78
  ]);
55
79
  const appSignIn = Boolean(config.http.publicUrl);
80
+ // Local devices exist only while a dial-in provider speaking capybara-device is loaded
81
+ // (device-local); the shells offer "connect this machine" only then.
82
+ const devices = deviceProtocolRange(this.dialIn.loaded().map((p) => p.protocol));
56
83
  return {
57
84
  name: config.platform.name ?? null,
58
85
  icon: app,
59
86
  icons: { app, maskable, favicon },
60
- protocols: { device: { min: DEVICE_PROTOCOL_VERSION, max: DEVICE_PROTOCOL_VERSION } },
87
+ protocols: {
88
+ device: devices ?? { min: DEVICE_PROTOCOL_VERSION, max: DEVICE_PROTOCOL_VERSION },
89
+ },
61
90
  features: {
62
- localDevices: true,
91
+ localDevices: devices !== null,
63
92
  // The authorize route answers app_auth.unavailable without http.publicUrl.
64
93
  appSignIn,
65
94
  // A push message carries the deployment origin, which needs http.publicUrl.
@@ -83,6 +112,7 @@ MetaController = __decorate([
83
112
  Controller("api/v1/meta"),
84
113
  __param(0, Inject(KernelConfigService)),
85
114
  __param(1, Inject(PlatformIconService)),
86
- __param(2, Inject(PushProviderHost))
115
+ __param(2, Inject(PushProviderHost)),
116
+ __param(3, Inject(DialInHandlers))
87
117
  ], MetaController);
88
118
  export { MetaController };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capybara-hq/kernel",
3
- "version": "0.1.0-rc.70",
3
+ "version": "0.1.0-rc.72",
4
4
  "description": "Capybara kernel: config, database, plugin host and HTTP API of the Capybara agent platform",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "yaml": "^2.9.1",
67
67
  "yauzl": "3.4.0",
68
68
  "zod": "^4.6.7",
69
- "@capybara-hq/plugin-sdk": "^0.1.0-rc.55"
69
+ "@capybara-hq/plugin-sdk": "^0.1.0-rc.56"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@langchain/langgraph-checkpoint-validation": "^1.2.0",