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

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.
@@ -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,
@@ -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
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.71",
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",