@opengeni/contracts 0.3.0 → 0.4.0
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/dist/index.d.ts +619 -1
- package/dist/index.js +500 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +836 -11
package/src/index.ts
CHANGED
|
@@ -10,9 +10,11 @@ export const SessionStatus = z.enum([
|
|
|
10
10
|
]);
|
|
11
11
|
export type SessionStatus = z.infer<typeof SessionStatus>;
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
// `packages/sdk/test/contract-parity.test.ts`.
|
|
15
|
-
// positions
|
|
13
|
+
// 11 backends; 3-way enum parity (contracts / sdk / deployment) is pinned by
|
|
14
|
+
// `packages/sdk/test/contract-parity.test.ts`. Every member is ADDITIVE AT THE
|
|
15
|
+
// END (the parity test pins positions): the original four, then the six cloud
|
|
16
|
+
// backends, then `selfhosted` (bring-your-own-compute — a user's own machine
|
|
17
|
+
// enrolled as a first-class sandbox).
|
|
16
18
|
export const SandboxBackend = z.enum([
|
|
17
19
|
"docker",
|
|
18
20
|
"modal",
|
|
@@ -24,6 +26,7 @@ export const SandboxBackend = z.enum([
|
|
|
24
26
|
"blaxel",
|
|
25
27
|
"cloudflare",
|
|
26
28
|
"vercel",
|
|
29
|
+
"selfhosted",
|
|
27
30
|
]);
|
|
28
31
|
export type SandboxBackend = z.infer<typeof SandboxBackend>;
|
|
29
32
|
|
|
@@ -350,6 +353,53 @@ export const CAPABILITY_DESCRIPTORS: Record<SandboxBackend, CapabilityDescriptor
|
|
|
350
353
|
persistable: false,
|
|
351
354
|
supportsRunAs: false,
|
|
352
355
|
},
|
|
356
|
+
// Bring-your-own-compute: the user's OWN machine, enrolled via a Rust agent,
|
|
357
|
+
// becomes ONE shared whole-machine sandbox (the agent IS the box). It is the
|
|
358
|
+
// first backend to make macOS/Windows reachable (default linux). Desktop is
|
|
359
|
+
// capability-PROCLAIMED ("vnc-ws") — the agent serves a native display stack
|
|
360
|
+
// (Linux X11/Xvfb, macOS CGEvent/ScreenCaptureKit) consent-gated at enroll;
|
|
361
|
+
// the online/offline/consent/display negotiation lives in select.ts (M3), this
|
|
362
|
+
// row is the static feasibility ceiling. Always-on (process-lifetime, never
|
|
363
|
+
// idle-reaped) and NOT persistable — OpenGeni cannot snapshot the user's disk,
|
|
364
|
+
// so resume = "is the agent's subject live?", never a cold re-create. Ports
|
|
365
|
+
// surface on-demand through the stateless relay edge, which lands behind the
|
|
366
|
+
// `resolveExposedPort` swap-seam later; until then it reuses the existing
|
|
367
|
+
// `provider-tunnel` exposure kind (the relay IS the provider tunnel for the
|
|
368
|
+
// agent) so no new PortExposureKind literal — and no new switch arms — are
|
|
369
|
+
// introduced. supportsOnDemandPorts:true: the agent opens a stream channel for
|
|
370
|
+
// a port on request rather than pre-declaring 6080/7681 at construction.
|
|
371
|
+
selfhosted: {
|
|
372
|
+
backend: "selfhosted",
|
|
373
|
+
backendId: "selfhosted",
|
|
374
|
+
tier: "desktop",
|
|
375
|
+
os: { supported: ["linux", "macos", "windows"], default: "linux" },
|
|
376
|
+
capabilities: {
|
|
377
|
+
FileSystem: { available: true, readOnly: false },
|
|
378
|
+
Terminal: { available: true, transport: "pty-ws", pty: true }, // real PTY over the relay
|
|
379
|
+
Git: { available: true },
|
|
380
|
+
DesktopStream: { available: true, transport: "vnc-ws" }, // proclaimed; consent-gated at enroll
|
|
381
|
+
Recording: { available: true }, // boot invariant: == DesktopStream.available
|
|
382
|
+
},
|
|
383
|
+
lifetime: {
|
|
384
|
+
// Whole-machine, always-there: online while the agent process runs, offline
|
|
385
|
+
// when it stops. The lease is NEVER idle-killed (it's the user's machine,
|
|
386
|
+
// not a reapable cloud box) and there is nothing to suspend/resume — the
|
|
387
|
+
// machine simply is or isn't reachable.
|
|
388
|
+
requiresSnapshotRollover: false,
|
|
389
|
+
hasIdleKiller: false,
|
|
390
|
+
supportsSuspendResume: false,
|
|
391
|
+
resumeIsLockFree: true, // resume = address the live NATS subject; no provider lock
|
|
392
|
+
},
|
|
393
|
+
// persistable:false forces snapshot.kind:"none" (the descriptor invariant
|
|
394
|
+
// `persistable ⇒ snapshot.kind!=="none"`): OpenGeni cannot snapshot the
|
|
395
|
+
// user's disk — the machine itself is the persistence.
|
|
396
|
+
snapshot: { kind: "none", hasTarFallback: false },
|
|
397
|
+
portExposure: { kind: "provider-tunnel", supportsOnDemandPorts: true },
|
|
398
|
+
workspaceRoot: "/", // agent-reported machine root (the whole machine is the sandbox)
|
|
399
|
+
nativeBucketMount: false,
|
|
400
|
+
persistable: false,
|
|
401
|
+
supportsRunAs: false,
|
|
402
|
+
},
|
|
353
403
|
};
|
|
354
404
|
|
|
355
405
|
export const ReasoningEffort = z.enum(["none", "minimal", "low", "medium", "high", "xhigh"]);
|
|
@@ -437,6 +487,13 @@ export const Permission = z.enum([
|
|
|
437
487
|
"environments:manage",
|
|
438
488
|
"environments:use",
|
|
439
489
|
"goals:manage",
|
|
490
|
+
// Bring-your-own-compute (M5). enrollments:read lists a workspace's machines;
|
|
491
|
+
// enrollments:manage approves a device-flow enrollment (the LOUD whole-machine
|
|
492
|
+
// consent) + revokes a machine. Distinct from sessions/stream perms because an
|
|
493
|
+
// enrollment grants WHOLE-MACHINE access to a user's own hardware — a high-trust,
|
|
494
|
+
// admin-shaped action. workspace:admin is the super-wildcard over both.
|
|
495
|
+
"enrollments:read",
|
|
496
|
+
"enrollments:manage",
|
|
440
497
|
]);
|
|
441
498
|
export type Permission = z.infer<typeof Permission>;
|
|
442
499
|
|
|
@@ -555,6 +612,125 @@ export async function verifyDelegatedAccessToken(secret: string, token: string,
|
|
|
555
612
|
return payload.data;
|
|
556
613
|
}
|
|
557
614
|
|
|
615
|
+
// --- Enrollment bearer credential (bring-your-own-compute M5, dossier §10.2) ---
|
|
616
|
+
//
|
|
617
|
+
// The signed bearer the agent presents to the control plane after enrollment (the
|
|
618
|
+
// EnrollmentCredentials.bearer the poll returns). REUSES the SAME HMAC envelope as
|
|
619
|
+
// the delegated/stream tokens (base64Url payload + hmacSha256Base64Url) with a
|
|
620
|
+
// distinct `oge_` prefix so it can never be confused with an `ogd_` access token or
|
|
621
|
+
// an `ogs_` stream token. It binds (workspaceId, agentId, enrollmentId) so the
|
|
622
|
+
// control plane can verify the agent owns the subject `agent.<ws>.<id>` it
|
|
623
|
+
// subscribes to. Signed with resolveEnrollmentSigningSecret; the secret value is
|
|
624
|
+
// NEVER logged. The real per-workspace NATS Account creds binding is infra-deferred
|
|
625
|
+
// (M4/relay) — this bearer is the application-tier identity proof.
|
|
626
|
+
export const EnrollmentBearerPayload = z.object({
|
|
627
|
+
workspaceId: z.string().uuid(),
|
|
628
|
+
agentId: z.string().uuid(),
|
|
629
|
+
enrollmentId: z.string().uuid(),
|
|
630
|
+
// The Account-scoped control-plane subject prefix the agent subscribes to.
|
|
631
|
+
subjectPrefix: z.string().min(1),
|
|
632
|
+
exp: z.number().int().positive(),
|
|
633
|
+
});
|
|
634
|
+
export type EnrollmentBearerPayload = z.infer<typeof EnrollmentBearerPayload>;
|
|
635
|
+
|
|
636
|
+
export async function signEnrollmentBearer(secret: string, payload: EnrollmentBearerPayload): Promise<string> {
|
|
637
|
+
const encodedPayload = base64UrlEncode(JSON.stringify(EnrollmentBearerPayload.parse(payload)));
|
|
638
|
+
const signature = await hmacSha256Base64Url(secret, encodedPayload);
|
|
639
|
+
return `oge_${encodedPayload}.${signature}`;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export async function verifyEnrollmentBearer(secret: string, token: string, nowSeconds = Math.floor(Date.now() / 1000)): Promise<EnrollmentBearerPayload | null> {
|
|
643
|
+
if (!token.startsWith("oge_")) {
|
|
644
|
+
return null;
|
|
645
|
+
}
|
|
646
|
+
const withoutPrefix = token.slice("oge_".length);
|
|
647
|
+
const dot = withoutPrefix.lastIndexOf(".");
|
|
648
|
+
if (dot <= 0) {
|
|
649
|
+
return null;
|
|
650
|
+
}
|
|
651
|
+
const encodedPayload = withoutPrefix.slice(0, dot);
|
|
652
|
+
const signature = withoutPrefix.slice(dot + 1);
|
|
653
|
+
const expected = await hmacSha256Base64Url(secret, encodedPayload);
|
|
654
|
+
if (!constantTimeEqual(signature, expected)) {
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
const payload = EnrollmentBearerPayload.safeParse(JSON.parse(base64UrlDecode(encodedPayload)));
|
|
658
|
+
if (!payload.success || payload.data.exp < nowSeconds) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
return payload.data;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// --- Non-interactive enroll token (self-hosted enrollment UX §A2.1) ----------
|
|
665
|
+
//
|
|
666
|
+
// The SHORT-TTL, secret, workspace-scoped token the headless/fleet enroll path
|
|
667
|
+
// presents to /v1/enrollments/token/exchange. The token IS the grant — there is
|
|
668
|
+
// no human approve step — so it is stateless-signed (no DB row): the holder of an
|
|
669
|
+
// unexpired token can enroll ONE machine identity into ONE workspace.
|
|
670
|
+
//
|
|
671
|
+
// It REUSES the SAME HMAC envelope as signEnrollmentBearer (base64Url payload +
|
|
672
|
+
// hmacSha256Base64Url) with a DISTINCT `oget_` prefix and a `typ: "enroll"` claim.
|
|
673
|
+
// DOMAIN SEPARATION: even though it shares the signing secret with the `oge_`
|
|
674
|
+
// bearer, the prefix + typ claim make an enroll token unusable as an `oge_`
|
|
675
|
+
// bearer (verifyEnrollmentBearer's `oge_` prefix check rejects it) and vice-versa
|
|
676
|
+
// (verifyEnrollToken's `oget_` prefix + typ check rejects an `oge_` bearer). The
|
|
677
|
+
// secret value is NEVER logged.
|
|
678
|
+
export const EnrollTokenPayload = z.object({
|
|
679
|
+
// Domain-separation claim — fixed "enroll" so an `oge_`/`ogd_`/`ogs_` payload (no
|
|
680
|
+
// typ, or a different typ) can never satisfy verifyEnrollToken even past the prefix.
|
|
681
|
+
typ: z.literal("enroll"),
|
|
682
|
+
workspaceId: z.string().uuid(),
|
|
683
|
+
accountId: z.string().uuid(),
|
|
684
|
+
// The screen-control consent baked into the token at mint (the minting user's
|
|
685
|
+
// decision); the exchange records it as consentedScreenControl on the enrollment.
|
|
686
|
+
allowScreenControl: z.boolean(),
|
|
687
|
+
iat: z.number().int().nonnegative(),
|
|
688
|
+
exp: z.number().int().positive(),
|
|
689
|
+
});
|
|
690
|
+
export type EnrollTokenPayload = z.infer<typeof EnrollTokenPayload>;
|
|
691
|
+
|
|
692
|
+
export async function signEnrollToken(secret: string, payload: EnrollTokenPayload): Promise<string> {
|
|
693
|
+
const encodedPayload = base64UrlEncode(JSON.stringify(EnrollTokenPayload.parse(payload)));
|
|
694
|
+
const signature = await hmacSha256Base64Url(secret, encodedPayload);
|
|
695
|
+
return `oget_${encodedPayload}.${signature}`;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Verify an enroll token: rejects (returns null) on a bad prefix (NOT `oget_`),
|
|
700
|
+
* a malformed envelope, a bad HMAC signature (constant-time), schema-invalid
|
|
701
|
+
* claims (which includes `typ !== "enroll"` — the `z.literal` rejects it), or an
|
|
702
|
+
* expired token (`exp < now`). Mirrors verifyEnrollmentBearer exactly. An `oge_`
|
|
703
|
+
* bearer fails the prefix gate; a same-secret token that lacks the typ claim fails
|
|
704
|
+
* the schema gate — both halves of the domain separation are enforced here.
|
|
705
|
+
*/
|
|
706
|
+
export async function verifyEnrollToken(secret: string, token: string, nowSeconds = Math.floor(Date.now() / 1000)): Promise<EnrollTokenPayload | null> {
|
|
707
|
+
if (!token.startsWith("oget_")) {
|
|
708
|
+
return null;
|
|
709
|
+
}
|
|
710
|
+
const withoutPrefix = token.slice("oget_".length);
|
|
711
|
+
const dot = withoutPrefix.lastIndexOf(".");
|
|
712
|
+
if (dot <= 0) {
|
|
713
|
+
return null;
|
|
714
|
+
}
|
|
715
|
+
const encodedPayload = withoutPrefix.slice(0, dot);
|
|
716
|
+
const signature = withoutPrefix.slice(dot + 1);
|
|
717
|
+
const expected = await hmacSha256Base64Url(secret, encodedPayload);
|
|
718
|
+
if (!constantTimeEqual(signature, expected)) {
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
let decoded: unknown;
|
|
722
|
+
try {
|
|
723
|
+
decoded = JSON.parse(base64UrlDecode(encodedPayload));
|
|
724
|
+
} catch {
|
|
725
|
+
return null;
|
|
726
|
+
}
|
|
727
|
+
const payload = EnrollTokenPayload.safeParse(decoded);
|
|
728
|
+
if (!payload.success || payload.data.exp < nowSeconds) {
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
return payload.data;
|
|
732
|
+
}
|
|
733
|
+
|
|
558
734
|
// --- Scoped data-plane stream token (master-spine §C.3 / crosscut PART 1.3) ---
|
|
559
735
|
//
|
|
560
736
|
// REUSES the existing HMAC envelope (sign/verifyDelegatedAccessToken's
|
|
@@ -633,6 +809,83 @@ export async function verifyStreamToken(secret: string, token: string, nowSecond
|
|
|
633
809
|
return payload.data;
|
|
634
810
|
}
|
|
635
811
|
|
|
812
|
+
// --- Relay PRODUCER token (bring-your-own-compute M8b, dossier §10.5) ---
|
|
813
|
+
//
|
|
814
|
+
// The token the AGENT presents to the relay edge when it registers a pty/desktop
|
|
815
|
+
// stream channel (role=AGENT) — distinct from the viewer's `ogs_` token. It is
|
|
816
|
+
// minted by the control plane at enrollment and threaded into EnrollmentCredentials
|
|
817
|
+
// (proto field `relay_token`); the relay verifies it on its own merits, then pairs
|
|
818
|
+
// the producer with the consumer by the shared channel key.
|
|
819
|
+
//
|
|
820
|
+
// REUSES the EXACT SAME HMAC envelope as the `ogs_`/`ogd_`/`oge_` tokens
|
|
821
|
+
// (base64Url JSON payload + hmacSha256Base64Url) — NOT a second crypto — with a
|
|
822
|
+
// distinct `ogr_` prefix so it can never be confused with the others. The claim
|
|
823
|
+
// set binds (workspaceId, agentId): the relay reads the channel-key's ws+agent
|
|
824
|
+
// from the StreamOpen and asserts the producer token claims the SAME pair, so a
|
|
825
|
+
// producer token for workspace A can never register a channel for workspace B.
|
|
826
|
+
// Signed with resolveRelayTokenSecret (the relay-token HMAC secret); the value is
|
|
827
|
+
// NEVER logged. Long-lived by design (it is enrollment-scoped, not per-stream —
|
|
828
|
+
// the agent presents it on every channel registration for the life of the
|
|
829
|
+
// enrollment); the relay additionally validates the channel key + (for the
|
|
830
|
+
// viewer's `ogs_`) the lease/active-epoch fence.
|
|
831
|
+
//
|
|
832
|
+
// The Rust relay re-implements this verify (the same base64url(JSON) + HMAC-SHA256
|
|
833
|
+
// + prefix split) so TS-mint and Rust-verify provably agree — see the cross-stack
|
|
834
|
+
// fixture in agent/crates/opengeni-relay/tests and the relay's `token` module doc.
|
|
835
|
+
export const RelayTokenPayload = z.object({
|
|
836
|
+
// The workspace the agent (and its channels) belong to — the relay asserts this
|
|
837
|
+
// equals the channel-key's ws so a producer can only register its own channels.
|
|
838
|
+
workspaceId: z.string().uuid(),
|
|
839
|
+
// The agent (machine) id — the relay asserts this equals the channel-key's agent.
|
|
840
|
+
agentId: z.string().uuid(),
|
|
841
|
+
// Expiry (unix seconds). Enrollment-scoped horizon (re-minted on re-enroll).
|
|
842
|
+
exp: z.number().int().positive(),
|
|
843
|
+
});
|
|
844
|
+
export type RelayTokenPayload = z.infer<typeof RelayTokenPayload>;
|
|
845
|
+
|
|
846
|
+
export async function signRelayToken(secret: string, payload: RelayTokenPayload): Promise<string> {
|
|
847
|
+
const encodedPayload = base64UrlEncode(JSON.stringify(RelayTokenPayload.parse(payload)));
|
|
848
|
+
const signature = await hmacSha256Base64Url(secret, encodedPayload);
|
|
849
|
+
return `ogr_${encodedPayload}.${signature}`;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* Verify a relay producer token: rejects (returns null) on a bad prefix, malformed
|
|
854
|
+
* envelope, bad HMAC signature (constant-time), schema-invalid claims, or expiry.
|
|
855
|
+
* Mirrors verifyStreamToken exactly. The relay (Rust) re-implements this verify;
|
|
856
|
+
* the TS verify here proves the format for the cross-stack fixture + any TS caller.
|
|
857
|
+
*
|
|
858
|
+
* The channel-key scope (claim.workspaceId/agentId vs the StreamOpen channel key)
|
|
859
|
+
* is enforced by the relay at USE — verify proves authenticity + freshness only.
|
|
860
|
+
*/
|
|
861
|
+
export async function verifyRelayToken(secret: string, token: string, nowSeconds = Math.floor(Date.now() / 1000)): Promise<RelayTokenPayload | null> {
|
|
862
|
+
if (!token.startsWith("ogr_")) {
|
|
863
|
+
return null;
|
|
864
|
+
}
|
|
865
|
+
const withoutPrefix = token.slice("ogr_".length);
|
|
866
|
+
const dot = withoutPrefix.lastIndexOf(".");
|
|
867
|
+
if (dot <= 0) {
|
|
868
|
+
return null;
|
|
869
|
+
}
|
|
870
|
+
const encodedPayload = withoutPrefix.slice(0, dot);
|
|
871
|
+
const signature = withoutPrefix.slice(dot + 1);
|
|
872
|
+
const expected = await hmacSha256Base64Url(secret, encodedPayload);
|
|
873
|
+
if (!constantTimeEqual(signature, expected)) {
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
let decoded: unknown;
|
|
877
|
+
try {
|
|
878
|
+
decoded = JSON.parse(base64UrlDecode(encodedPayload));
|
|
879
|
+
} catch {
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
882
|
+
const payload = RelayTokenPayload.safeParse(decoded);
|
|
883
|
+
if (!payload.success || payload.data.exp < nowSeconds) {
|
|
884
|
+
return null;
|
|
885
|
+
}
|
|
886
|
+
return payload.data;
|
|
887
|
+
}
|
|
888
|
+
|
|
636
889
|
export const CreateWorkspaceRequest = z.object({
|
|
637
890
|
accountId: z.string().uuid().optional(),
|
|
638
891
|
name: z.string().min(1),
|
|
@@ -790,6 +1043,155 @@ export const LimitDecision = z.discriminatedUnion("allowed", [
|
|
|
790
1043
|
]);
|
|
791
1044
|
export type LimitDecision = z.infer<typeof LimitDecision>;
|
|
792
1045
|
|
|
1046
|
+
// ============ P3 — Entitlements port (§7.5) ============
|
|
1047
|
+
//
|
|
1048
|
+
// The host-providable admission seam over OpenGeni's TWO existing admission
|
|
1049
|
+
// sites: the API edge (`checkLimit`/`requireLimit`, billing/limits.ts) AND the
|
|
1050
|
+
// worker edge (`ensureRunAllowed`, agent-turn.ts — both turn-entry and the
|
|
1051
|
+
// mid-stream budget valve). A host that owns its OWN ledger/meter binds this to
|
|
1052
|
+
// keep OpenGeni from re-deriving admission from its local ledger.
|
|
1053
|
+
//
|
|
1054
|
+
// CRITICAL CONTRACT: `admitRun` returns a transport-neutral allow/deny decision
|
|
1055
|
+
// (+ optional structured reason + the echoed quantity it admitted) and NEVER
|
|
1056
|
+
// exposes `getBillingBalance` or any ledger internals — the host's balance math
|
|
1057
|
+
// stays on the host side of the boundary. This is what lets the same port serve
|
|
1058
|
+
// both PUSH (host funds OpenGeni's ledger; admission is a LOCAL read of that
|
|
1059
|
+
// funded ledger) and PULL (a network callback to the host's own meter).
|
|
1060
|
+
//
|
|
1061
|
+
// `action` is a free `string` (NOT the internal `LimitAction` enum) so a host
|
|
1062
|
+
// meter can key on actions OpenGeni does not model. `quantity` is the units the
|
|
1063
|
+
// caller is about to consume (tokens, bytes, 1 run, …); the decision MAY echo
|
|
1064
|
+
// the admitted quantity so a PULL host can grant a partial allowance.
|
|
1065
|
+
export const EntitlementDecision = z.discriminatedUnion("allowed", [
|
|
1066
|
+
z.object({ allowed: z.literal(true), quantity: z.number().optional() }),
|
|
1067
|
+
z.object({ allowed: z.literal(false), reason: z.string(), code: z.string().optional(), quantity: z.number().optional() }),
|
|
1068
|
+
]);
|
|
1069
|
+
export type EntitlementDecision = z.infer<typeof EntitlementDecision>;
|
|
1070
|
+
|
|
1071
|
+
export type AdmitRunInput = {
|
|
1072
|
+
accountId: string;
|
|
1073
|
+
workspaceId: string;
|
|
1074
|
+
action: string;
|
|
1075
|
+
quantity: number;
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
export type EntitlementsPort = {
|
|
1079
|
+
admitRun(input: AdmitRunInput): Promise<EntitlementDecision>;
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
// ============ P4a — Connection-credential provider (§7.6) ============
|
|
1083
|
+
//
|
|
1084
|
+
// The host-providable per-run credential-mint seam over OpenGeni's TWO
|
|
1085
|
+
// run-scoped credential sites in the worker:
|
|
1086
|
+
// - GIT credentials: the GitHub App installation token minted in
|
|
1087
|
+
// `sandboxEnvironmentForRun` (today `createGitHubAppInstallationToken`
|
|
1088
|
+
// from `settings`) and injected as `GH_TOKEN`/`GITHUB_TOKEN`/the git
|
|
1089
|
+
// extraheader.
|
|
1090
|
+
// - SANDBOX secrets: the decrypted workspace environment values loaded in
|
|
1091
|
+
// `loadWorkspaceEnvironmentForRun` (today decrypted with
|
|
1092
|
+
// `environmentsEncryptionKeyBytes(settings)`).
|
|
1093
|
+
//
|
|
1094
|
+
// In embedded/separate topologies the HOST owns these external connections
|
|
1095
|
+
// (its GitHub App, its secret vault + encryption key). When a host binds this
|
|
1096
|
+
// port, OpenGeni asks the host to mint/decrypt per-run instead of self-minting
|
|
1097
|
+
// from `settings`. Unset (standalone default) → byte-for-byte today's
|
|
1098
|
+
// self-mint.
|
|
1099
|
+
//
|
|
1100
|
+
// FORK-7 CROSS-CHECK (the host-mapping safety guardrail): a credential
|
|
1101
|
+
// provider returns the `workspaceId` it scoped the credential to, and the
|
|
1102
|
+
// activity ASSERTS it agrees with the run's workspace BEFORE injecting
|
|
1103
|
+
// `GH_TOKEN` (or applying the decrypted values). A host mapping bug that
|
|
1104
|
+
// returns tenant B's creds while the run is tenant A is thereby caught at the
|
|
1105
|
+
// seam, never silently injected into tenant A's sandbox.
|
|
1106
|
+
|
|
1107
|
+
export type GitCredentialsRequest = {
|
|
1108
|
+
accountId: string;
|
|
1109
|
+
workspaceId: string;
|
|
1110
|
+
// The GitHub App installation the run's repository resources resolved to,
|
|
1111
|
+
// and the specific repositories the token must be scoped to. Mirrors the
|
|
1112
|
+
// shape `createGitHubAppInstallationToken` consumes today.
|
|
1113
|
+
installationId: number;
|
|
1114
|
+
repositoryIds: number[];
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
export type GitCredentials = {
|
|
1118
|
+
// The minted installation token the activity injects as GH_TOKEN/GITHUB_TOKEN
|
|
1119
|
+
// and into the git http extraheader (identical downstream handling to the
|
|
1120
|
+
// self-mint path).
|
|
1121
|
+
token: string;
|
|
1122
|
+
// FORK-7 echo: the workspace the provider scoped this token to. The activity
|
|
1123
|
+
// asserts `workspaceId === request.workspaceId` before injecting.
|
|
1124
|
+
workspaceId: string;
|
|
1125
|
+
// Optional git identity override. When omitted the activity falls back to
|
|
1126
|
+
// today's `githubAppBotIdentity(settings)`.
|
|
1127
|
+
identity?: { name: string; email: string } | null;
|
|
1128
|
+
};
|
|
1129
|
+
|
|
1130
|
+
export type SandboxSecretsRequest = {
|
|
1131
|
+
accountId: string;
|
|
1132
|
+
workspaceId: string;
|
|
1133
|
+
// The workspace environment the run's session declares (null = unattached;
|
|
1134
|
+
// the provider, like the self-mint path, returns null values for it).
|
|
1135
|
+
environmentId: string;
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
export type SandboxSecrets = {
|
|
1139
|
+
// The decrypted environment values the run injects, replacing the local
|
|
1140
|
+
// `environmentsEncryptionKeyBytes` decrypt. Same shape the self-mint path
|
|
1141
|
+
// produces (plaintext name→value).
|
|
1142
|
+
values: Record<string, string>;
|
|
1143
|
+
// FORK-7 echo: the workspace the provider scoped these secrets to.
|
|
1144
|
+
workspaceId: string;
|
|
1145
|
+
// Optional environment metadata; when omitted the activity uses the
|
|
1146
|
+
// environmentId as both id and name (the local decrypt carries the row's
|
|
1147
|
+
// id/name/description, but only `id` is load-bearing downstream).
|
|
1148
|
+
id?: string;
|
|
1149
|
+
name?: string;
|
|
1150
|
+
description?: string | null;
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
export type ConnectionCredentialsPort = {
|
|
1154
|
+
// Both legs are optional: a host may drive ONLY git creds (BYO-GitHub-App)
|
|
1155
|
+
// and leave sandbox secrets to OpenGeni's local decrypt, or vice-versa. An
|
|
1156
|
+
// unset leg falls through to today's self-mint for THAT leg only.
|
|
1157
|
+
gitCredentials?: (input: GitCredentialsRequest) => Promise<GitCredentials>;
|
|
1158
|
+
sandboxSecrets?: (input: SandboxSecretsRequest) => Promise<SandboxSecrets>;
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1161
|
+
// ============ P4a — GitHub App API port (BYO-App, §7.6 / SPIKE-2 remainder) ===
|
|
1162
|
+
//
|
|
1163
|
+
// The host-driven GitHub-API credential leg. SPIKE-2 closed the establishment +
|
|
1164
|
+
// gate (storage) axis; this closes the credential leg by making the two live
|
|
1165
|
+
// GitHub-API calls host-PROVIDABLE so a BYO-GitHub-App host drives its OWN App
|
|
1166
|
+
// credentials (its own JWT-signing key, its own OAuth client) instead of
|
|
1167
|
+
// OpenGeni self-minting from `settings`:
|
|
1168
|
+
// - verifyInstallationAccessForUser: the OAuth code→token + installation
|
|
1169
|
+
// lookup that PROVES the install is real (today
|
|
1170
|
+
// `verifyGitHubInstallationAccessForUser(settings, …)`).
|
|
1171
|
+
// - listRepositories: the installation-scoped repo listing behind
|
|
1172
|
+
// `GET /v1/workspaces/:id/github/repositories` (today
|
|
1173
|
+
// `listGitHubAppRepositories(settings, …)`).
|
|
1174
|
+
//
|
|
1175
|
+
// Unset (standalone default) → today's `settings`-based self-mint runs
|
|
1176
|
+
// byte-for-byte (the live GitHub-API verify/list against OpenGeni's own App).
|
|
1177
|
+
|
|
1178
|
+
export type GitHubInstallationSummary = {
|
|
1179
|
+
installationId: number;
|
|
1180
|
+
accountLogin: string | null;
|
|
1181
|
+
accountType: string | null;
|
|
1182
|
+
suspended: boolean;
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
export type GitHubAppApiPort = {
|
|
1186
|
+
verifyInstallationAccessForUser?: (input: {
|
|
1187
|
+
code: string;
|
|
1188
|
+
installationId: number;
|
|
1189
|
+
}) => Promise<GitHubInstallationSummary>;
|
|
1190
|
+
listRepositories?: (input: {
|
|
1191
|
+
installationIds?: number[];
|
|
1192
|
+
}) => Promise<GitHubRepository[]>;
|
|
1193
|
+
};
|
|
1194
|
+
|
|
793
1195
|
export const BillingBalance = z.object({
|
|
794
1196
|
accountId: z.string().uuid(),
|
|
795
1197
|
balanceMicros: z.number().int(),
|
|
@@ -949,6 +1351,16 @@ export type DocumentSearchRequest = z.infer<typeof DocumentSearchRequest>;
|
|
|
949
1351
|
export const ToolRef = z.object({
|
|
950
1352
|
kind: z.literal("mcp"),
|
|
951
1353
|
id: z.string().min(1),
|
|
1354
|
+
// Non-fatal-on-connect marker for an AUTO-ATTACHED (workspace-default)
|
|
1355
|
+
// capability MCP server: when true, a connect / tools-list failure (e.g. an
|
|
1356
|
+
// expired capability credential returning 401) must SKIP that server with a
|
|
1357
|
+
// logged warning and let the turn proceed, rather than failing the whole
|
|
1358
|
+
// turn before the model runs. Absent/false ⇒ STRICT: an unavailable server
|
|
1359
|
+
// fails the turn (the contract for EXPLICITLY-requested tools). This flag is
|
|
1360
|
+
// set server-side only, at the default-capability auto-attach seam; it is
|
|
1361
|
+
// stripped from client-supplied tool refs so an explicit request always
|
|
1362
|
+
// stays strict.
|
|
1363
|
+
optional: z.boolean().optional(),
|
|
952
1364
|
});
|
|
953
1365
|
export type ToolRef = z.infer<typeof ToolRef>;
|
|
954
1366
|
|
|
@@ -960,17 +1372,26 @@ export class ResourceRefConflictError extends Error {
|
|
|
960
1372
|
}
|
|
961
1373
|
|
|
962
1374
|
export function mergeToolRefs(existing: ToolRef[], additions: ToolRef[]): ToolRef[] {
|
|
963
|
-
const
|
|
964
|
-
const
|
|
1375
|
+
const byKey = new Map<string, ToolRef>();
|
|
1376
|
+
const order: string[] = [];
|
|
965
1377
|
for (const tool of [...existing, ...additions]) {
|
|
966
1378
|
const key = `${tool.kind}:${tool.id}`;
|
|
967
|
-
|
|
1379
|
+
const prior = byKey.get(key);
|
|
1380
|
+
if (!prior) {
|
|
1381
|
+
byKey.set(key, tool);
|
|
1382
|
+
order.push(key);
|
|
968
1383
|
continue;
|
|
969
1384
|
}
|
|
970
|
-
|
|
971
|
-
|
|
1385
|
+
// Strict wins: if the same server appears both auto-attached (optional) and
|
|
1386
|
+
// explicitly requested (non-optional), the explicit occurrence upgrades the
|
|
1387
|
+
// merged ref to strict — a later explicit request of an already-defaulted
|
|
1388
|
+
// capability MCP must still fail the turn when the server is unavailable.
|
|
1389
|
+
if (prior.optional === true && tool.optional !== true) {
|
|
1390
|
+
const { optional: _dropped, ...strict } = prior;
|
|
1391
|
+
byKey.set(key, strict);
|
|
1392
|
+
}
|
|
972
1393
|
}
|
|
973
|
-
return
|
|
1394
|
+
return order.map((key) => byKey.get(key)!);
|
|
974
1395
|
}
|
|
975
1396
|
|
|
976
1397
|
export function mergeResourceRefs(
|
|
@@ -1735,6 +2156,13 @@ export const Session = z.object({
|
|
|
1735
2156
|
// own id for a singleton group (today's 1:1 default); equals the parent's
|
|
1736
2157
|
// group when spawned shared (both sessions run in ONE box).
|
|
1737
2158
|
sandboxGroupId: z.string().uuid(),
|
|
2159
|
+
// The first-class swappable-sandbox POINTER (bring-your-own-compute M2). NULL
|
|
2160
|
+
// resolves to the session's own group sandbox (the backward-compat default);
|
|
2161
|
+
// a swap sets it to the target sandbox row. active_epoch is the second epoch
|
|
2162
|
+
// ABOVE the lease epoch, bumped on every swap so the routing proxy can fence a
|
|
2163
|
+
// stale in-flight op and retry against the new active sandbox.
|
|
2164
|
+
activeSandboxId: z.string().uuid().nullable(),
|
|
2165
|
+
activeEpoch: z.number().int().nonnegative(),
|
|
1738
2166
|
environmentId: z.string().uuid().nullable(),
|
|
1739
2167
|
// Non-default first-party MCP token permissions (manager-style sessions);
|
|
1740
2168
|
// null means the fixed worker default set.
|
|
@@ -1755,6 +2183,12 @@ export const Session = z.object({
|
|
|
1755
2183
|
// signal. Null until a turn with usage has completed.
|
|
1756
2184
|
lastInputTokens: z.number().int().nonnegative().nullable(),
|
|
1757
2185
|
lastSequence: z.number().int().nonnegative(),
|
|
2186
|
+
// Multi-account Codex (P1). codexPinnedCredentialId: the account this session is
|
|
2187
|
+
// manually PINNED to (null ⇒ follow the workspace active pointer).
|
|
2188
|
+
// codexLastCredentialId: the account the most recent turn actually ran on (the
|
|
2189
|
+
// "Running on:" indicator's source). Both are credential-row ids, null until set.
|
|
2190
|
+
codexPinnedCredentialId: z.string().uuid().nullable(),
|
|
2191
|
+
codexLastCredentialId: z.string().uuid().nullable(),
|
|
1758
2192
|
createdAt: z.string(),
|
|
1759
2193
|
updatedAt: z.string(),
|
|
1760
2194
|
});
|
|
@@ -1821,6 +2255,10 @@ export const SessionEventType = z.enum([
|
|
|
1821
2255
|
"terminal.pty.output.delta", // PTY stdout/stderr bytes (separate from command.output)
|
|
1822
2256
|
"terminal.pty.exited", // PTY session ended (exitCode/reason)
|
|
1823
2257
|
"session.title_set",
|
|
2258
|
+
// Multi-account Codex (P1): the account a session's turn runs on changed
|
|
2259
|
+
// (manual switch in P1; failover/rotation in P3 reuse the same event). Drives
|
|
2260
|
+
// the in-session "Running on:" indicator's live flip.
|
|
2261
|
+
"codex.account.switched",
|
|
1824
2262
|
]);
|
|
1825
2263
|
export type SessionEventType = z.infer<typeof SessionEventType>;
|
|
1826
2264
|
|
|
@@ -2306,6 +2744,17 @@ export const CreateSessionRequest = z.object({
|
|
|
2306
2744
|
model: z.string().min(1).optional(),
|
|
2307
2745
|
reasoningEffort: ReasoningEffort.optional(),
|
|
2308
2746
|
sandboxBackend: SandboxBackend.optional(),
|
|
2747
|
+
// The enrolled machine (a sandbox id) to run this session on; seeds the
|
|
2748
|
+
// active-sandbox pointer at creation so the FIRST turn routes to the chosen
|
|
2749
|
+
// machine (race-free: the pointer is committed before the worker turn
|
|
2750
|
+
// workflow can read it). An invalid/unowned/offline target fails the create.
|
|
2751
|
+
targetSandboxId: z.string().uuid().optional(),
|
|
2752
|
+
// The working directory the targeted machine runs the session under — the
|
|
2753
|
+
// path/cwd base for its agent exec, terminal, and file dock. Free-form pass-
|
|
2754
|
+
// through: a launch-workspace_root-relative subdir or an absolute machine path
|
|
2755
|
+
// (the agent's resolve_cwd handles both). Only valid WITH targetSandboxId
|
|
2756
|
+
// (workingDir alone is a 422); omitted ⇒ the machine's default workspace_root.
|
|
2757
|
+
workingDir: z.string().min(1).optional(),
|
|
2309
2758
|
// Workspace environment attachment is fixed at session creation; follow-up
|
|
2310
2759
|
// user.message events cannot switch or add one.
|
|
2311
2760
|
environmentId: z.string().uuid().optional(),
|
|
@@ -2335,6 +2784,11 @@ export const CreateSessionRequest = z.object({
|
|
|
2335
2784
|
// A shared spawn inherits the box's (backend, os) — it is literally the same
|
|
2336
2785
|
// box; the child cannot pick its own backend. Cross-workspace sharing is
|
|
2337
2786
|
// forbidden by construction (the parent/group reads are RLS-workspace-scoped).
|
|
2787
|
+
// ENV-AWARE: the box's environment is fixed at creation, so a share requires
|
|
2788
|
+
// the SAME environmentId as the creator's box. On a mismatch the inherited
|
|
2789
|
+
// default silently falls back to an own box; an explicit "shared"/{groupId}
|
|
2790
|
+
// request 422s at create (instead of the first turn dying on the SDK's
|
|
2791
|
+
// manifest-env guard).
|
|
2338
2792
|
sandbox: z.union([
|
|
2339
2793
|
z.literal("shared"),
|
|
2340
2794
|
z.literal("new"),
|
|
@@ -2432,6 +2886,12 @@ export const CapabilityUnavailableReason = z.enum([
|
|
|
2432
2886
|
"disabled_by_policy",
|
|
2433
2887
|
"lease_cold",
|
|
2434
2888
|
"tier_headless",
|
|
2889
|
+
// Selfhosted (bring-your-own-compute) negotiation states (M1 additive; the
|
|
2890
|
+
// selfhosted negotiation in select.ts wires them in M3):
|
|
2891
|
+
"agent_offline", // the enrolled agent process is not running / unreachable
|
|
2892
|
+
"agent_reconnecting", // a transient blip — the agent is reconnecting (warmable)
|
|
2893
|
+
"consent_required", // whole-machine / screen-control consent not yet acknowledged
|
|
2894
|
+
"display_unavailable", // headless machine with no display stack (no DesktopStream)
|
|
2435
2895
|
]);
|
|
2436
2896
|
export type CapabilityUnavailableReason = z.infer<typeof CapabilityUnavailableReason>;
|
|
2437
2897
|
|
|
@@ -2472,8 +2932,11 @@ export const SessionCapabilities = z.object({
|
|
|
2472
2932
|
reason: CapabilityUnavailableReason.nullable(),
|
|
2473
2933
|
}),
|
|
2474
2934
|
DesktopStream: z.object({
|
|
2475
|
-
|
|
2476
|
-
|
|
2935
|
+
// "relay-frames" is the selfhosted framebuffer stream: PNG-per-frame protobuf
|
|
2936
|
+
// datagrams spliced over the relay (NOT RFB). The viewer renders it with the
|
|
2937
|
+
// "frames" client (a canvas painter), distinct from Modal's "vnc-ws"/"novnc".
|
|
2938
|
+
transport: z.enum(["vnc-ws", "rdp-ws", "webrtc", "relay-frames"]).nullable(),
|
|
2939
|
+
client: z.enum(["novnc", "web-rdp", "frames"]).nullable(),
|
|
2477
2940
|
mode: z.enum(["read-only", "interactive"]).default("read-only"),
|
|
2478
2941
|
url: z.string().url().nullable(),
|
|
2479
2942
|
token: z.string().nullable(),
|
|
@@ -2589,6 +3052,368 @@ export const ViewerHeartbeatResponse = z.object({
|
|
|
2589
3052
|
});
|
|
2590
3053
|
export type ViewerHeartbeatResponse = z.infer<typeof ViewerHeartbeatResponse>;
|
|
2591
3054
|
|
|
3055
|
+
// =============================================================================
|
|
3056
|
+
// Bring-your-own-compute (M5) — enrollment device-flow HTTP contract.
|
|
3057
|
+
//
|
|
3058
|
+
// The HTTP shapes mirror the @opengeni/agent-proto device-flow messages
|
|
3059
|
+
// (DeviceAuthStart*, DeviceAuthPoll*, EnrollmentCredentials) so the Rust agent's
|
|
3060
|
+
// `enroll` command (which runs the flow over HTTP before it has NATS creds)
|
|
3061
|
+
// decodes the SAME field names (the proto's ts-proto JSON is camelCase). The
|
|
3062
|
+
// request bodies additionally carry the consent-relevant fields the dossier brief
|
|
3063
|
+
// mandates (the agent ed25519 pubkey + can-offer-display + requests-screen-control).
|
|
3064
|
+
// =============================================================================
|
|
3065
|
+
|
|
3066
|
+
export const EnrollmentOs = z.enum(["linux", "macos", "windows"]);
|
|
3067
|
+
export type EnrollmentOs = z.infer<typeof EnrollmentOs>;
|
|
3068
|
+
export const EnrollmentArch = z.enum(["x86_64", "aarch64"]);
|
|
3069
|
+
export type EnrollmentArch = z.infer<typeof EnrollmentArch>;
|
|
3070
|
+
|
|
3071
|
+
// POST /enrollments/device/start (agent-side, unauthenticated-at-the-user-level,
|
|
3072
|
+
// rate-limited). The agent presents its ed25519 public key + os/arch + the
|
|
3073
|
+
// requested whole-machine exposure + whether it can offer a display + whether it
|
|
3074
|
+
// requests screen control.
|
|
3075
|
+
export const DeviceEnrollmentStartRequest = z.object({
|
|
3076
|
+
// The agent's ed25519 public key (the machine identity the enrollment binds to).
|
|
3077
|
+
publicKey: z.string().min(1).max(1024),
|
|
3078
|
+
os: EnrollmentOs.default("linux"),
|
|
3079
|
+
arch: EnrollmentArch.default("x86_64"),
|
|
3080
|
+
// Human-friendly machine name (hostname by default).
|
|
3081
|
+
machineName: z.string().min(1).max(256).optional(),
|
|
3082
|
+
// v1 only supports whole-machine; kept explicit so the consent is recorded.
|
|
3083
|
+
exposure: z.literal("whole-machine").default("whole-machine"),
|
|
3084
|
+
// The agent can offer a display (a real screen / Xvfb is available).
|
|
3085
|
+
canOfferDisplay: z.boolean().default(false),
|
|
3086
|
+
// The agent requests screen control (computer-use); the user's allow_screen_control
|
|
3087
|
+
// at approve is the AUTHORITATIVE consent.
|
|
3088
|
+
requestsScreenControl: z.boolean().default(false),
|
|
3089
|
+
// The workspace this machine is enrolling into. The agent is told this at install
|
|
3090
|
+
// (the user picks the workspace, or the install/enroll token carries it). The user
|
|
3091
|
+
// who approves must hold a grant in THIS workspace — that binding is what makes
|
|
3092
|
+
// the (user-unauthenticated) start safe: it cannot grant access to a workspace no
|
|
3093
|
+
// authorized user later approves in.
|
|
3094
|
+
workspaceId: z.string().uuid(),
|
|
3095
|
+
});
|
|
3096
|
+
export type DeviceEnrollmentStartRequest = z.infer<typeof DeviceEnrollmentStartRequest>;
|
|
3097
|
+
|
|
3098
|
+
// The DeviceAuthStart response (field names match the proto's JSON).
|
|
3099
|
+
export const DeviceEnrollmentStartResponse = z.object({
|
|
3100
|
+
deviceCode: z.string(),
|
|
3101
|
+
userCode: z.string(),
|
|
3102
|
+
verificationUri: z.string(),
|
|
3103
|
+
verificationUriComplete: z.string(),
|
|
3104
|
+
intervalSeconds: z.number().int().positive(),
|
|
3105
|
+
expiresInSeconds: z.number().int().positive(),
|
|
3106
|
+
});
|
|
3107
|
+
export type DeviceEnrollmentStartResponse = z.infer<typeof DeviceEnrollmentStartResponse>;
|
|
3108
|
+
|
|
3109
|
+
// POST /enrollments/device/approve (USER-authenticated, workspace-gated). The
|
|
3110
|
+
// LOUD CONSENT step. whole-machine is mandatory (implicit); screen-control is
|
|
3111
|
+
// opt-in per allow_screen_control.
|
|
3112
|
+
export const DeviceEnrollmentApproveRequest = z.object({
|
|
3113
|
+
userCode: z.string().min(1).max(64),
|
|
3114
|
+
allowScreenControl: z.boolean().default(false),
|
|
3115
|
+
});
|
|
3116
|
+
export type DeviceEnrollmentApproveRequest = z.infer<typeof DeviceEnrollmentApproveRequest>;
|
|
3117
|
+
|
|
3118
|
+
export const DeviceEnrollmentApproveResponse = z.object({
|
|
3119
|
+
approved: z.boolean(),
|
|
3120
|
+
enrollmentId: z.string().uuid(),
|
|
3121
|
+
sandboxId: z.string().uuid(),
|
|
3122
|
+
allowScreenControl: z.boolean(),
|
|
3123
|
+
});
|
|
3124
|
+
export type DeviceEnrollmentApproveResponse = z.infer<typeof DeviceEnrollmentApproveResponse>;
|
|
3125
|
+
|
|
3126
|
+
// POST /enrollments/device/poll (agent-side). The poll state machine.
|
|
3127
|
+
export const DeviceEnrollmentPollRequest = z.object({
|
|
3128
|
+
deviceCode: z.string().min(1).max(256),
|
|
3129
|
+
});
|
|
3130
|
+
export type DeviceEnrollmentPollRequest = z.infer<typeof DeviceEnrollmentPollRequest>;
|
|
3131
|
+
|
|
3132
|
+
export const DeviceEnrollmentState = z.enum(["pending", "authorized", "denied", "expired", "disabled"]);
|
|
3133
|
+
export type DeviceEnrollmentState = z.infer<typeof DeviceEnrollmentState>;
|
|
3134
|
+
|
|
3135
|
+
// The EnrollmentCredentials (field names match the proto's JSON). natsAccountCreds
|
|
3136
|
+
// is a PLACEHOLDER — the real per-workspace NATS Account creds binding is
|
|
3137
|
+
// infra-deferred (M4/relay); the bearer + subjectPrefix are the application-tier
|
|
3138
|
+
// identity the agent presents today.
|
|
3139
|
+
export const EnrollmentCredentialsResponse = z.object({
|
|
3140
|
+
agentId: z.string().uuid(),
|
|
3141
|
+
workspaceId: z.string().uuid(),
|
|
3142
|
+
// The signed bearer the agent presents to the control plane (the `oge_` token).
|
|
3143
|
+
bearer: z.string(),
|
|
3144
|
+
// The Account-scoped control-plane subject prefix the agent subscribes to:
|
|
3145
|
+
// agent.<workspaceId>.<agentId>.
|
|
3146
|
+
subjectPrefix: z.string(),
|
|
3147
|
+
// Connect info for the control plane + stream relay (may be empty when not yet
|
|
3148
|
+
// configured for this deployment — the agent surfaces "control plane unconfigured").
|
|
3149
|
+
natsUrls: z.array(z.string()),
|
|
3150
|
+
relayUrl: z.string(),
|
|
3151
|
+
// The agent's PRODUCER token for the relay edge (the `ogr_` token; M8b). Presented
|
|
3152
|
+
// as StreamOpen.token when the agent registers a pty/desktop channel; the relay
|
|
3153
|
+
// verifies it then pairs the producer with the viewer (whose `ogs_` token the
|
|
3154
|
+
// relay also verifies). Empty when the relay-token plane is unconfigured for this
|
|
3155
|
+
// deployment (graceful degrade — the agent then presents an empty token the relay
|
|
3156
|
+
// rejects, surfacing the gap loudly rather than silently producing a dead stream).
|
|
3157
|
+
relayToken: z.string(),
|
|
3158
|
+
// VESTIGIAL (M-AUTH): there is no per-machine NATS Account creds file. The agent
|
|
3159
|
+
// presents the `bearer` above as the NATS connect AUTH-TOKEN; the server's
|
|
3160
|
+
// auth-callout responder validates it and mints a workspace-scoped user JWT. This
|
|
3161
|
+
// field echoes the bearer so a consumer reading it as the connect credential still
|
|
3162
|
+
// works; new consumers should read `bearer` directly.
|
|
3163
|
+
natsAccountCreds: z.string(),
|
|
3164
|
+
// The minisign public key the agent pins for self-update verification.
|
|
3165
|
+
updatePublicKey: z.string(),
|
|
3166
|
+
consentedWholeMachine: z.boolean(),
|
|
3167
|
+
consentedScreenControl: z.boolean(),
|
|
3168
|
+
});
|
|
3169
|
+
export type EnrollmentCredentialsResponse = z.infer<typeof EnrollmentCredentialsResponse>;
|
|
3170
|
+
|
|
3171
|
+
export const DeviceEnrollmentPollResponse = z.object({
|
|
3172
|
+
state: DeviceEnrollmentState,
|
|
3173
|
+
// Present only when state === "authorized".
|
|
3174
|
+
credentials: EnrollmentCredentialsResponse.optional(),
|
|
3175
|
+
});
|
|
3176
|
+
export type DeviceEnrollmentPollResponse = z.infer<typeof DeviceEnrollmentPollResponse>;
|
|
3177
|
+
|
|
3178
|
+
// GET /enrollments — a workspace's machines (the Machines dashboard surface).
|
|
3179
|
+
export const EnrollmentSummary = z.object({
|
|
3180
|
+
id: z.string().uuid(),
|
|
3181
|
+
pubkey: z.string(),
|
|
3182
|
+
exposure: z.literal("whole-machine"),
|
|
3183
|
+
hasDisplay: z.boolean(),
|
|
3184
|
+
allowScreenControl: z.boolean(),
|
|
3185
|
+
status: z.enum(["active", "revoked"]),
|
|
3186
|
+
os: EnrollmentOs,
|
|
3187
|
+
arch: z.string(),
|
|
3188
|
+
lastSeenAt: z.string().nullable(),
|
|
3189
|
+
createdAt: z.string(),
|
|
3190
|
+
revokedAt: z.string().nullable(),
|
|
3191
|
+
});
|
|
3192
|
+
export type EnrollmentSummary = z.infer<typeof EnrollmentSummary>;
|
|
3193
|
+
|
|
3194
|
+
export const ListEnrollmentsResponse = z.object({
|
|
3195
|
+
enrollments: z.array(EnrollmentSummary),
|
|
3196
|
+
});
|
|
3197
|
+
export type ListEnrollmentsResponse = z.infer<typeof ListEnrollmentsResponse>;
|
|
3198
|
+
|
|
3199
|
+
export const RevokeEnrollmentResponse = z.object({
|
|
3200
|
+
revoked: z.boolean(),
|
|
3201
|
+
});
|
|
3202
|
+
export type RevokeEnrollmentResponse = z.infer<typeof RevokeEnrollmentResponse>;
|
|
3203
|
+
|
|
3204
|
+
// =============================================================================
|
|
3205
|
+
// Enrollment UX (self-hosted enrollment UX, design 11): the click-Grant approve
|
|
3206
|
+
// page lookup/deny + the headless enroll-token mint/exchange. These sit beside the
|
|
3207
|
+
// device-flow contracts above and REUSE EnrollmentCredentialsResponse for the
|
|
3208
|
+
// exchange's credential payload (identical shape to the poll authorized branch).
|
|
3209
|
+
// =============================================================================
|
|
3210
|
+
|
|
3211
|
+
// POST /v1/enrollments/device/lookup (USER-authenticated, NO workspace in the
|
|
3212
|
+
// path). The approve page (EnrollmentConsent) needs the machine details for a
|
|
3213
|
+
// user_code WITHOUT consuming the request. The user_code is globally unique among
|
|
3214
|
+
// pending rows; the route resolves its workspace, authorizes (enrollments:read),
|
|
3215
|
+
// and returns the machine details — or 404 (never revealing cross-workspace
|
|
3216
|
+
// existence) when the grant check fails or no live pending row matches.
|
|
3217
|
+
export const DeviceEnrollmentLookupRequest = z.object({
|
|
3218
|
+
userCode: z.string().min(1).max(64),
|
|
3219
|
+
});
|
|
3220
|
+
export type DeviceEnrollmentLookupRequest = z.infer<typeof DeviceEnrollmentLookupRequest>;
|
|
3221
|
+
|
|
3222
|
+
// The presentational machine details the consent screen renders (a subset of the
|
|
3223
|
+
// pending request — NO secrets, NO device_code).
|
|
3224
|
+
export const DeviceEnrollmentLookupMachine = z.object({
|
|
3225
|
+
machineName: z.string().nullable(),
|
|
3226
|
+
os: EnrollmentOs,
|
|
3227
|
+
arch: z.string(),
|
|
3228
|
+
canOfferDisplay: z.boolean(),
|
|
3229
|
+
requestsScreenControl: z.boolean(),
|
|
3230
|
+
});
|
|
3231
|
+
export type DeviceEnrollmentLookupMachine = z.infer<typeof DeviceEnrollmentLookupMachine>;
|
|
3232
|
+
|
|
3233
|
+
export const DeviceEnrollmentLookupResponse = z.object({
|
|
3234
|
+
workspaceId: z.string().uuid(),
|
|
3235
|
+
userCode: z.string(),
|
|
3236
|
+
machine: DeviceEnrollmentLookupMachine,
|
|
3237
|
+
expiresAt: z.string(),
|
|
3238
|
+
});
|
|
3239
|
+
export type DeviceEnrollmentLookupResponse = z.infer<typeof DeviceEnrollmentLookupResponse>;
|
|
3240
|
+
|
|
3241
|
+
// POST /v1/workspaces/:workspaceId/enrollments/device/deny (USER-authenticated,
|
|
3242
|
+
// enrollments:manage). The explicit "no" at the approve page — mirrors approve.
|
|
3243
|
+
export const DeviceEnrollmentDenyRequest = z.object({
|
|
3244
|
+
userCode: z.string().min(1).max(64),
|
|
3245
|
+
});
|
|
3246
|
+
export type DeviceEnrollmentDenyRequest = z.infer<typeof DeviceEnrollmentDenyRequest>;
|
|
3247
|
+
|
|
3248
|
+
export const DeviceEnrollmentDenyResponse = z.object({
|
|
3249
|
+
denied: z.boolean(),
|
|
3250
|
+
});
|
|
3251
|
+
export type DeviceEnrollmentDenyResponse = z.infer<typeof DeviceEnrollmentDenyResponse>;
|
|
3252
|
+
|
|
3253
|
+
// POST /v1/workspaces/:workspaceId/enrollments/token (USER-authenticated,
|
|
3254
|
+
// enrollments:manage). Mints the short-TTL headless enroll token (the `oget_`
|
|
3255
|
+
// token). allowScreenControl bakes the screen-control consent into the token.
|
|
3256
|
+
export const MintEnrollTokenRequest = z.object({
|
|
3257
|
+
allowScreenControl: z.boolean().default(false),
|
|
3258
|
+
});
|
|
3259
|
+
export type MintEnrollTokenRequest = z.infer<typeof MintEnrollTokenRequest>;
|
|
3260
|
+
|
|
3261
|
+
export const MintEnrollTokenResponse = z.object({
|
|
3262
|
+
// The `oget_` token. SECRET — the UI shows it once with a copy-now warning.
|
|
3263
|
+
token: z.string(),
|
|
3264
|
+
expiresAt: z.string(),
|
|
3265
|
+
expiresInSeconds: z.number().int().positive(),
|
|
3266
|
+
});
|
|
3267
|
+
export type MintEnrollTokenResponse = z.infer<typeof MintEnrollTokenResponse>;
|
|
3268
|
+
|
|
3269
|
+
// POST /v1/enrollments/token/exchange (UNAUTHENTICATED — the token IS the auth).
|
|
3270
|
+
// The agent presents the same identity fields it sends to device/start plus the
|
|
3271
|
+
// enroll token. On a valid token the control plane performs the SAME finalize as
|
|
3272
|
+
// approve and returns the IDENTICAL EnrollmentCredentialsResponse shape (so the
|
|
3273
|
+
// agent's existing credential parsing is reused).
|
|
3274
|
+
export const EnrollTokenExchangeRequest = z.object({
|
|
3275
|
+
// The `oget_` enroll token (the auth + the workspace/account/consent grant).
|
|
3276
|
+
token: z.string().min(1),
|
|
3277
|
+
// The agent's ed25519 public key (the machine identity the enrollment binds to).
|
|
3278
|
+
publicKey: z.string().min(1).max(1024),
|
|
3279
|
+
os: EnrollmentOs.default("linux"),
|
|
3280
|
+
arch: EnrollmentArch.default("x86_64"),
|
|
3281
|
+
machineName: z.string().min(1).max(256).optional(),
|
|
3282
|
+
// v1 only supports whole-machine; kept explicit so the consent is recorded.
|
|
3283
|
+
exposure: z.literal("whole-machine").default("whole-machine"),
|
|
3284
|
+
canOfferDisplay: z.boolean().default(false),
|
|
3285
|
+
// The agent's REQUEST; the token's allowScreenControl is the AUTHORITATIVE consent.
|
|
3286
|
+
requestsScreenControl: z.boolean().default(false),
|
|
3287
|
+
});
|
|
3288
|
+
export type EnrollTokenExchangeRequest = z.infer<typeof EnrollTokenExchangeRequest>;
|
|
3289
|
+
|
|
3290
|
+
// The exchange wraps the EXISTING EnrollmentCredentialsResponse — IDENTICAL to the
|
|
3291
|
+
// poll authorized branch's `credentials` (NOT a redefined credential shape).
|
|
3292
|
+
export const EnrollTokenExchangeResponse = z.object({
|
|
3293
|
+
credentials: EnrollmentCredentialsResponse,
|
|
3294
|
+
});
|
|
3295
|
+
export type EnrollTokenExchangeResponse = z.infer<typeof EnrollTokenExchangeResponse>;
|
|
3296
|
+
|
|
3297
|
+
// ── Machines dashboard + per-machine metrics (M10, dossier §10.7) ────────────
|
|
3298
|
+
//
|
|
3299
|
+
// The SHARED data contract M10 (backend) implements + M9 (UI) renders. THE
|
|
3300
|
+
// orchestrator owns this shape; M9 imports these types so the dashboard never
|
|
3301
|
+
// drifts from the API. The fields mirror the agent's MetricsSample wire shape
|
|
3302
|
+
// (`@opengeni/agent-proto`) projected to the dashboard's JSON, plus the derived
|
|
3303
|
+
// machine state matrix (the M3 liveness + the consent/display reasons).
|
|
3304
|
+
|
|
3305
|
+
/**
|
|
3306
|
+
* A point-in-time machine metrics sample as the dashboard reads it. `cpuPct` and
|
|
3307
|
+
* the load averages are 0..N doubles; the byte figures are integers; `gpuUtilPct`
|
|
3308
|
+
* / `gpuMemBytes` are null when no GPU was present at sample time (the wire
|
|
3309
|
+
* contract: absence == not-reported, NEVER a real zero). `runQueue` is the
|
|
3310
|
+
* runnable-count contention signal. `sampledAt` is an ISO-8601 instant.
|
|
3311
|
+
*/
|
|
3312
|
+
export const MetricSample = z.object({
|
|
3313
|
+
cpuPct: z.number(),
|
|
3314
|
+
load1: z.number(),
|
|
3315
|
+
load5: z.number(),
|
|
3316
|
+
load15: z.number(),
|
|
3317
|
+
memUsedBytes: z.number().int(),
|
|
3318
|
+
memTotalBytes: z.number().int(),
|
|
3319
|
+
diskUsedBytes: z.number().int(),
|
|
3320
|
+
diskTotalBytes: z.number().int(),
|
|
3321
|
+
gpuUtilPct: z.number().nullable(),
|
|
3322
|
+
gpuMemBytes: z.number().int().nullable(),
|
|
3323
|
+
runQueue: z.number(),
|
|
3324
|
+
sampledAt: z.string(),
|
|
3325
|
+
});
|
|
3326
|
+
export type MetricSample = z.infer<typeof MetricSample>;
|
|
3327
|
+
|
|
3328
|
+
/** The derived dashboard state of a machine. The M3 liveness
|
|
3329
|
+
* (online/reconnecting/offline) plus the enrollment-derived consent/display
|
|
3330
|
+
* reasons (consent_required / display_unavailable) and the in-flight device-flow
|
|
3331
|
+
* (enrolling). */
|
|
3332
|
+
export const MachineState = z.enum([
|
|
3333
|
+
"online",
|
|
3334
|
+
"reconnecting",
|
|
3335
|
+
"offline",
|
|
3336
|
+
"consent_required",
|
|
3337
|
+
"display_unavailable",
|
|
3338
|
+
"enrolling",
|
|
3339
|
+
]);
|
|
3340
|
+
export type MachineState = z.infer<typeof MachineState>;
|
|
3341
|
+
|
|
3342
|
+
export const MachineKind = z.enum(["modal", "selfhosted"]);
|
|
3343
|
+
export type MachineKind = z.infer<typeof MachineKind>;
|
|
3344
|
+
|
|
3345
|
+
/**
|
|
3346
|
+
* A machine as the Machines dashboard renders it. The workspace's enrolled
|
|
3347
|
+
* selfhosted machines PLUS the session's synthetic Modal group box
|
|
3348
|
+
* (`isSessionGroup: true`). `active` marks the session's currently-active
|
|
3349
|
+
* routing target. `sharedSessionCount` is the lease refcount (how many sessions
|
|
3350
|
+
* share this whole machine). `metrics` is the latest sample, or null when none
|
|
3351
|
+
* has landed yet (just enrolled / offline before a first heartbeat).
|
|
3352
|
+
*/
|
|
3353
|
+
export const MachineView = z.object({
|
|
3354
|
+
sandboxId: z.string(),
|
|
3355
|
+
enrollmentId: z.string().nullable(),
|
|
3356
|
+
name: z.string(),
|
|
3357
|
+
kind: MachineKind,
|
|
3358
|
+
state: MachineState,
|
|
3359
|
+
active: z.boolean(),
|
|
3360
|
+
isSessionGroup: z.boolean(),
|
|
3361
|
+
os: z.string(),
|
|
3362
|
+
arch: z.string(),
|
|
3363
|
+
hasDisplay: z.boolean(),
|
|
3364
|
+
allowScreenControl: z.boolean(),
|
|
3365
|
+
sharedSessionCount: z.number().int(),
|
|
3366
|
+
lastSeenAt: z.string().nullable(),
|
|
3367
|
+
metrics: MetricSample.nullable(),
|
|
3368
|
+
});
|
|
3369
|
+
export type MachineView = z.infer<typeof MachineView>;
|
|
3370
|
+
|
|
3371
|
+
/**
|
|
3372
|
+
* GET /v1/workspaces/:ws/machines — the dashboard list. `activeSandboxId` /
|
|
3373
|
+
* `activeEpoch` echo the session's epoch-fenced active-sandbox pointer (null
|
|
3374
|
+
* activeSandboxId == the session's own group box is active).
|
|
3375
|
+
*/
|
|
3376
|
+
export const MachinesResponse = z.object({
|
|
3377
|
+
activeSandboxId: z.string().nullable(),
|
|
3378
|
+
activeEpoch: z.number().int(),
|
|
3379
|
+
machines: z.array(MachineView),
|
|
3380
|
+
});
|
|
3381
|
+
export type MachinesResponse = z.infer<typeof MachinesResponse>;
|
|
3382
|
+
|
|
3383
|
+
/**
|
|
3384
|
+
* POST /v1/workspaces/:ws/sessions/:sessionId/active-sandbox — the user-
|
|
3385
|
+
* authenticated swap of a session's active sandbox (the same epoch-fenced
|
|
3386
|
+
* mechanic the M7 `sandbox_swap` MCP tool exposes to the agent). `target` is a
|
|
3387
|
+
* `MachinesResponse` machine's `sandboxId`, or "session"/"default" to swap back
|
|
3388
|
+
* to the session's own group box.
|
|
3389
|
+
*/
|
|
3390
|
+
export const SwapActiveSandboxRequest = z.object({
|
|
3391
|
+
target: z.string().min(1),
|
|
3392
|
+
});
|
|
3393
|
+
export type SwapActiveSandboxRequest = z.infer<typeof SwapActiveSandboxRequest>;
|
|
3394
|
+
|
|
3395
|
+
/**
|
|
3396
|
+
* The swap outcome (mirrors the server `FleetSwapResult`). `swapped` is true on a
|
|
3397
|
+
* successful repoint OR a no-op (already pointed there); `reason` carries the
|
|
3398
|
+
* failure detail (unowned/offline target, or a lost epoch fence) when false.
|
|
3399
|
+
*/
|
|
3400
|
+
export const SwapActiveSandboxResponse = z.object({
|
|
3401
|
+
swapped: z.boolean(),
|
|
3402
|
+
activeSandboxId: z.string().nullable(),
|
|
3403
|
+
activeEpoch: z.number().int(),
|
|
3404
|
+
reason: z.string().optional(),
|
|
3405
|
+
});
|
|
3406
|
+
export type SwapActiveSandboxResponse = z.infer<typeof SwapActiveSandboxResponse>;
|
|
3407
|
+
|
|
3408
|
+
/**
|
|
3409
|
+
* GET /v1/workspaces/:ws/machines/:enrollmentId/metrics/series?window=1h — the
|
|
3410
|
+
* downsampled (~1/min) history the dashboard time-range reads.
|
|
3411
|
+
*/
|
|
3412
|
+
export const MachineMetricsSeriesResponse = z.object({
|
|
3413
|
+
samples: z.array(MetricSample),
|
|
3414
|
+
});
|
|
3415
|
+
export type MachineMetricsSeriesResponse = z.infer<typeof MachineMetricsSeriesResponse>;
|
|
3416
|
+
|
|
2592
3417
|
/**
|
|
2593
3418
|
* A single host-exposed model + the provider that serves it, as surfaced to
|
|
2594
3419
|
* clients (SDK + React composer) by GET /v1/config/client. The wire `api`
|