@bivy/bivy 0.12.0-staging.404 → 0.12.0-staging.405

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.
Files changed (2) hide show
  1. package/dist/server.js +29 -0
  2. package/package.json +1 -1
package/dist/server.js CHANGED
@@ -2878,6 +2878,17 @@ const RELAY_COMMANDS = {
2878
2878
  });
2879
2879
  return;
2880
2880
  }
2881
+ const remoteSessionRequestId = requestId ?? randomUUID();
2882
+ const sessionAdmission = await admitRelaySessionCreate(remoteSessionRequestId);
2883
+ if (!sessionAdmission.allowed) {
2884
+ relay?.sendEvent({
2885
+ type: "session.error",
2886
+ code: sessionAdmission.code || "remote_session_limit",
2887
+ error: sessionAdmission.error,
2888
+ requestId,
2889
+ });
2890
+ return;
2891
+ }
2881
2892
  let record;
2882
2893
  try {
2883
2894
  // Deduped by requestId so a client's post-reconnect retry adopts the
@@ -3131,6 +3142,24 @@ async function modelAuthFetch(pathname, init = {}) {
3131
3142
  headers.set("content-type", "application/json");
3132
3143
  return fetch(`${sessionAdvertiseTarget.controlPlaneUrl.replace(/\/$/, "")}${pathname}`, { ...init, headers });
3133
3144
  }
3145
+ async function admitRelaySessionCreate(idempotencyKey) {
3146
+ // Self-hosted/direct deployments without an account extension stay unrestricted:
3147
+ // the control plane answers allowed when no deployment extension is configured.
3148
+ const res = await modelAuthFetch("/node/policy/check", {
3149
+ method: "POST",
3150
+ body: JSON.stringify({ operation: "session.create", idempotencyKey }),
3151
+ });
3152
+ if (!res)
3153
+ return { allowed: true };
3154
+ const decision = await res.json().catch(() => ({}));
3155
+ if (res.ok && decision.allowed !== false)
3156
+ return { allowed: true };
3157
+ return {
3158
+ allowed: false,
3159
+ code: decision.code,
3160
+ error: decision.reason || decision.error || "This account has reached its remote session allowance.",
3161
+ };
3162
+ }
3134
3163
  // Debounced model-auth sync trigger. A relay wake (`work.available`) fires this
3135
3164
  // so peers answer a new node's vault-key request promptly (event-driven) instead
3136
3165
  // of on the steady 30s poll. Coalesces a burst of wakes into one sync.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bivy/bivy",
3
- "version": "0.12.0-staging.404",
3
+ "version": "0.12.0-staging.405",
4
4
  "type": "module",
5
5
  "license": "AGPL-3.0-only",
6
6
  "description": "Run coding agents on machines you own. Open-source, self-hostable agent workspace.",