@opengeni/sdk 0.2.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.js CHANGED
@@ -426,7 +426,138 @@ var OpenGeniClient = class {
426
426
  async compactSessionContext(workspaceId, sessionId) {
427
427
  return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/context/compact`, {});
428
428
  }
429
+ // --- Channel-A structured services (P4.4) ------------------------------------
430
+ // FileSystem (Pierre tree), Git (Pierre diff), Terminal (exec + PTY). Each is a
431
+ // synchronous API-direct point query; the fs.changed/git.changed/terminal.pty.*
432
+ // notifications + the PTY output stream arrive on the existing event SSE.
433
+ /** FileSystem: list a directory tree (feeds the Pierre file tree). */
434
+ async fsList(workspaceId, sessionId, request = {}) {
435
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/fs/list`, request);
436
+ }
437
+ /** FileSystem: read a file (text or base64; binary-safe, size-capped). */
438
+ async fsRead(workspaceId, sessionId, request) {
439
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/fs/read`, request);
440
+ }
441
+ /** FileSystem: write a file (last-writer-wins; emits fs.changed). */
442
+ async fsWrite(workspaceId, sessionId, request) {
443
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/fs/write`, request);
444
+ }
445
+ /** FileSystem: delete a path (emits fs.changed). */
446
+ async fsDelete(workspaceId, sessionId, request) {
447
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/fs/delete`, request);
448
+ }
449
+ /** FileSystem: move/rename a path (emits fs.changed; 409 if destination exists and overwrite is false). */
450
+ async fsMove(workspaceId, sessionId, request) {
451
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/fs/move`, request);
452
+ }
453
+ /** FileSystem: create a directory (emits fs.changed; recursive defaults to true). */
454
+ async fsMkdir(workspaceId, sessionId, request) {
455
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/fs/mkdir`, request);
456
+ }
457
+ /** Git: working-tree/index status (the Pierre file-status feed). */
458
+ async gitStatus(workspaceId, sessionId, request = {}) {
459
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/git/status`, request);
460
+ }
461
+ /** Git: structured diff hunks (the Pierre diff feed). */
462
+ async gitDiff(workspaceId, sessionId, request = {}) {
463
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/git/diff`, request);
464
+ }
465
+ /** Git: commit log. */
466
+ async gitLog(workspaceId, sessionId, request = {}) {
467
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/git/log`, request);
468
+ }
469
+ /** Git: show a commit (diff vs first parent) or fetch a raw blob at a ref. */
470
+ async gitShow(workspaceId, sessionId, request) {
471
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/git/show`, request);
472
+ }
473
+ /** Terminal: run a bounded command, returning buffered stdout/stderr inline. */
474
+ async terminalExec(workspaceId, sessionId, request) {
475
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/terminal/exec`, request);
476
+ }
477
+ /** Terminal: open an interactive PTY. Output streams on the event SSE as
478
+ * terminal.pty.output.delta; drive it with terminalPtyWrite. */
479
+ async terminalPtyOpen(workspaceId, sessionId, request = {}) {
480
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/terminal/pty`, request);
481
+ }
482
+ /** Terminal: send stdin to an open PTY (output rides A1). */
483
+ async terminalPtyWrite(workspaceId, sessionId, request) {
484
+ await this.requestVoid("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/terminal/pty/write`, request);
485
+ }
486
+ /** Terminal: resize an open PTY. */
487
+ async terminalPtyResize(workspaceId, sessionId, request) {
488
+ await this.requestVoid("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/terminal/pty/resize`, request);
489
+ }
490
+ /** Terminal: close an open PTY (idempotent). */
491
+ async terminalPtyClose(workspaceId, sessionId, request) {
492
+ await this.requestVoid("POST", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/terminal/pty/close`, request);
493
+ }
494
+ // --- Stream surfacing: capability negotiation + viewer lifecycle (Phase 5) ---
495
+ // The capability doc is the single source of UI truth (degradation is always a
496
+ // value, never a crash). The desktop pixel plane (Channel B) is gated behind an
497
+ // un-redacted-acknowledgment + a viewer holder; the structured terminal/files/
498
+ // git surfaces (Channel A) ride the methods above and the event SSE.
499
+ /** Read the negotiated capability doc for a session WITHOUT acquiring a viewer
500
+ * holder (no warm, no spawn). Drives capability-gated rendering: which
501
+ * surfaces mount, the per-surface unavailability reasons, and the lease
502
+ * liveness the client polls on while `cold`/`warming`. The desktop URL/token
503
+ * are minted in-process only when the box is warm AND the principal has
504
+ * acknowledged the un-redacted plane. */
505
+ async getStreamCapabilities(workspaceId, sessionId) {
506
+ return await this.requestJson(
507
+ "GET",
508
+ `/v1/workspaces/${workspaceId}/sessions/${sessionId}/stream-capabilities`
509
+ );
510
+ }
511
+ /** Record the calling principal's acknowledgment of the un-redacted desktop
512
+ * pixel plane (and, when the box is shared, the shared-exposure disclosure).
513
+ * The desktop viewer-attach path returns 409 until this is recorded. */
514
+ async acknowledgeStream(workspaceId, sessionId, request = {}) {
515
+ return await this.requestJson(
516
+ "POST",
517
+ `/v1/workspaces/${workspaceId}/sessions/${sessionId}/stream-capabilities/acknowledge`,
518
+ request
519
+ );
520
+ }
521
+ /** Attach a viewer holder (refcounted liveness — keeps the box warm while
522
+ * watched/used), spinning the box up in-process when cold, and mint the scoped
523
+ * direct-to-provider URLs for the requested plane(s). `request.desktop:true`
524
+ * opts into the un-redacted pixel plane and mints the noVNC URL — that plane
525
+ * alone throws `OpenGeniApiError(409)` when the un-redacted/shared
526
+ * acknowledgment is missing (the consent gate). A terminal-only attach
527
+ * (`desktop` omitted/false) warms the box + mints the pty-ws terminal cell with
528
+ * NO consent gate. An omitted `viewerId` mints a fresh one. */
529
+ async attachViewer(workspaceId, sessionId, request = {}) {
530
+ return await this.requestJson(
531
+ "POST",
532
+ `/v1/workspaces/${workspaceId}/sessions/${sessionId}/viewers`,
533
+ request
534
+ );
535
+ }
536
+ /** Heartbeat a viewer holder (Channel-A app-level liveness). A closed laptop
537
+ * stops sending these → the reaper drops the holder within ~90s. Echoes
538
+ * `leaseEpoch` so a superseded epoch is rejected (`alive:false` → re-attach). */
539
+ async heartbeatViewer(workspaceId, sessionId, viewerId, request) {
540
+ return await this.requestJson(
541
+ "POST",
542
+ `/v1/workspaces/${workspaceId}/sessions/${sessionId}/viewers/${viewerId}/heartbeat`,
543
+ request
544
+ );
545
+ }
546
+ /** Detach a viewer (delete this holder; idempotent delete-my-row). */
547
+ async detachViewer(workspaceId, sessionId, viewerId) {
548
+ await this.requestVoid("DELETE", `/v1/workspaces/${workspaceId}/sessions/${sessionId}/viewers/${viewerId}`);
549
+ }
429
550
  // --- Access + workspaces -----------------------------------------------------
551
+ /**
552
+ * The deployment's public client bootstrap config: the host-exposed models
553
+ * (provider-grouped in `models`, flat in `allowedModels` for back-compat),
554
+ * reasoning efforts, MCP servers, file-upload limits, and how the client is
555
+ * expected to authenticate. Drives a composer's model picker without prior
556
+ * knowledge of the host setup; safe to call before any auth is established.
557
+ */
558
+ async getClientConfig() {
559
+ return await this.requestJson("GET", "/v1/config/client");
560
+ }
430
561
  /** The caller's access context: subject, account + workspace grants, defaults. */
431
562
  async getAccessContext() {
432
563
  return await this.requestJson("GET", "/v1/access/me");
@@ -443,6 +574,40 @@ var OpenGeniClient = class {
443
574
  async updateWorkspace(workspaceId, request) {
444
575
  return await this.requestJson("PATCH", `/v1/workspaces/${workspaceId}`, request);
445
576
  }
577
+ /**
578
+ * Delete a workspace and everything in it. Refused (409) for the account's
579
+ * only workspace and while it still has a running session. Irreversible.
580
+ */
581
+ async deleteWorkspace(workspaceId) {
582
+ await this.requestVoid("DELETE", `/v1/workspaces/${workspaceId}`);
583
+ }
584
+ // --- Members ("People with access") -------------------------------------------
585
+ /** The workspace's members (user + api_key subjects). */
586
+ async listWorkspaceMembers(workspaceId) {
587
+ const response = await this.requestJson("GET", `/v1/workspaces/${workspaceId}/members`);
588
+ return response.members;
589
+ }
590
+ /**
591
+ * Add an already-registered user by email. 404s when no user with that email
592
+ * exists (email invites for unknown users are deferred).
593
+ */
594
+ async addWorkspaceMember(workspaceId, request) {
595
+ return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/members`, request);
596
+ }
597
+ async updateWorkspaceMember(workspaceId, subjectId, request) {
598
+ return await this.requestJson(
599
+ "PATCH",
600
+ `/v1/workspaces/${workspaceId}/members/${encodeURIComponent(subjectId)}`,
601
+ request
602
+ );
603
+ }
604
+ /**
605
+ * Remove a member. Refused (409) for your own membership and for the last
606
+ * member who can still manage the workspace.
607
+ */
608
+ async removeWorkspaceMember(workspaceId, subjectId) {
609
+ await this.requestVoid("DELETE", `/v1/workspaces/${workspaceId}/members/${encodeURIComponent(subjectId)}`);
610
+ }
446
611
  // --- Scheduled tasks (write + runs) -------------------------------------------
447
612
  async createScheduledTask(workspaceId, request) {
448
613
  return await this.requestJson("POST", `/v1/workspaces/${workspaceId}/scheduled-tasks`, request);
@@ -588,6 +753,16 @@ var OpenGeniClient = class {
588
753
  `/v1/workspaces/${workspaceId}/document-bases/${baseId}/documents/${documentId}/reindex`
589
754
  );
590
755
  }
756
+ /**
757
+ * Delete a document from a base. Removes the document row and its indexed
758
+ * chunks while leaving the uploaded file asset available for other uses.
759
+ */
760
+ async deleteDocument(workspaceId, baseId, documentId) {
761
+ await this.requestVoid(
762
+ "DELETE",
763
+ `/v1/workspaces/${workspaceId}/document-bases/${baseId}/documents/${documentId}`
764
+ );
765
+ }
591
766
  async searchDocuments(workspaceId, baseId, request) {
592
767
  return await this.requestJson(
593
768
  "POST",
@@ -865,6 +1040,94 @@ function proxySessionEventStream(client, workspaceId, sessionId, options = {}) {
865
1040
  });
866
1041
  }
867
1042
 
1043
+ // src/desktop.ts
1044
+ function desktopSocketUrl(cap) {
1045
+ if (!cap.url) {
1046
+ throw new Error("desktop capability has no url (transport is null)");
1047
+ }
1048
+ const u = new URL(cap.url);
1049
+ if (u.protocol === "https:") {
1050
+ u.protocol = "wss:";
1051
+ } else if (u.protocol === "http:") {
1052
+ u.protocol = "ws:";
1053
+ }
1054
+ if (/\/vnc(_lite)?\.html$/.test(u.pathname)) {
1055
+ u.pathname = u.pathname.replace(/\/vnc(_lite)?\.html$/, "/websockify");
1056
+ u.search = "";
1057
+ u.hash = "";
1058
+ }
1059
+ return u.toString();
1060
+ }
1061
+ function nextDesktopState(current, ev) {
1062
+ switch (ev.type) {
1063
+ case "negotiated":
1064
+ return "connecting";
1065
+ case "connected":
1066
+ return "connected";
1067
+ case "rotate":
1068
+ return current === "connected" ? "rotating" : current;
1069
+ case "disconnected":
1070
+ return current === "ended" ? "ended" : "reconnecting";
1071
+ case "fail":
1072
+ return "error";
1073
+ case "abort":
1074
+ return "ended";
1075
+ default:
1076
+ return current;
1077
+ }
1078
+ }
1079
+ function applyUrlRotation(cap, payload, knownEpoch) {
1080
+ if (payload.leaseEpoch < knownEpoch) {
1081
+ return null;
1082
+ }
1083
+ return { ...cap, url: payload.url, token: payload.token, expiresAt: payload.expiresAt };
1084
+ }
1085
+
1086
+ // src/terminal.ts
1087
+ function terminalSocketUrl(cap) {
1088
+ if (!cap.url) {
1089
+ throw new Error("terminal capability has no url (transport is not pty-ws)");
1090
+ }
1091
+ const u = new URL(cap.url);
1092
+ if (u.protocol === "https:") {
1093
+ u.protocol = "wss:";
1094
+ } else if (u.protocol === "http:") {
1095
+ u.protocol = "ws:";
1096
+ }
1097
+ return u.toString();
1098
+ }
1099
+ var TTYD_SUBPROTOCOL = "tty";
1100
+ var TtydClientCommand = {
1101
+ /** stdin: "0" + raw input bytes. */
1102
+ INPUT: "0",
1103
+ /** window resize: "1" + JSON.stringify({ columns, rows }). */
1104
+ RESIZE: "1",
1105
+ /** flow-control pause (back-pressure): "2". */
1106
+ PAUSE: "2",
1107
+ /** flow-control resume: "3". */
1108
+ RESUME: "3"
1109
+ };
1110
+ var TtydServerCommand = {
1111
+ /** stdout/stderr: "0" + raw output bytes (write the rest into xterm). */
1112
+ OUTPUT: "0",
1113
+ /** set the window title: "1" + title string. */
1114
+ SET_WINDOW_TITLE: "1",
1115
+ /** ttyd client preferences JSON: "2" + json (ignored by us). */
1116
+ SET_PREFERENCES: "2"
1117
+ };
1118
+ function ttydAuthFrame(opts) {
1119
+ const frame = { AuthToken: "" };
1120
+ if (opts?.columns && opts.columns > 0) frame.columns = opts.columns;
1121
+ if (opts?.rows && opts.rows > 0) frame.rows = opts.rows;
1122
+ return JSON.stringify(frame);
1123
+ }
1124
+ function ttydInputFrame(data) {
1125
+ return TtydClientCommand.INPUT + data;
1126
+ }
1127
+ function ttydResizeFrame(columns, rows) {
1128
+ return TtydClientCommand.RESIZE + JSON.stringify({ columns, rows });
1129
+ }
1130
+
868
1131
  // src/types.ts
869
1132
  var SESSION_EVENT_TYPES = [
870
1133
  "session.created",
@@ -898,7 +1161,24 @@ var SESSION_EVENT_TYPES = [
898
1161
  "goal.completed",
899
1162
  "goal.paused",
900
1163
  "goal.resumed",
901
- "goal.continuation"
1164
+ "goal.continuation",
1165
+ // Channel-B desktop pixel-plane signals (mirror of contracts SessionEventType;
1166
+ // the contract-parity test asserts sorted equality).
1167
+ "stream.url.rotated",
1168
+ "stream.opened",
1169
+ "stream.closed",
1170
+ "stream.revoked",
1171
+ // Channel-B recording signals (P4.3 — "agent films itself proving the fix").
1172
+ "recording.started",
1173
+ "recording.available",
1174
+ "recording.failed",
1175
+ // Channel-A structured-service notifications (P4.4; mirror of contracts
1176
+ // SessionEventType — the contract-parity test asserts sorted equality).
1177
+ "fs.changed",
1178
+ "git.changed",
1179
+ "terminal.pty.started",
1180
+ "terminal.pty.output.delta",
1181
+ "terminal.pty.exited"
902
1182
  ];
903
1183
  var KNOWN_PERMISSIONS = [
904
1184
  "account:read",
@@ -912,8 +1192,17 @@ var KNOWN_PERMISSIONS = [
912
1192
  "sessions:create",
913
1193
  "sessions:read",
914
1194
  "sessions:control",
1195
+ // Sandbox-surfacing (mirror of @opengeni/contracts Permission). stream:view is
1196
+ // strictly broader than sessions:read (un-redacted pixels); stream:control is
1197
+ // the never-granted-v1 raw-input plane; stream:acknowledge is the secret-leak
1198
+ // consent gate.
1199
+ "stream:view",
1200
+ "stream:control",
1201
+ "stream:acknowledge",
915
1202
  "files:upload",
916
1203
  "files:read",
1204
+ "files:write",
1205
+ "terminal:attach",
917
1206
  "documents:manage",
918
1207
  "documents:search",
919
1208
  "scheduled_tasks:manage",
@@ -934,7 +1223,10 @@ var KNOWN_USAGE_EVENT_TYPES = [
934
1223
  "file.deleted",
935
1224
  "document.indexed",
936
1225
  "scheduled_task.fired",
937
- "api_key.request"
1226
+ "api_key.request",
1227
+ // sandbox warm-time metering (P2.1) — mirrors contracts UsageEventType.
1228
+ "sandbox.warm_seconds",
1229
+ "sandbox.warm_cost"
938
1230
  ];
939
1231
  export {
940
1232
  KNOWN_PERMISSIONS,
@@ -943,13 +1235,23 @@ export {
943
1235
  OpenGeniClient,
944
1236
  OpenGeniStreamError,
945
1237
  SESSION_EVENT_TYPES,
1238
+ TTYD_SUBPROTOCOL,
1239
+ TtydClientCommand,
1240
+ TtydServerCommand,
1241
+ applyUrlRotation,
1242
+ desktopSocketUrl,
946
1243
  formatSseEvent,
947
1244
  isRetryableStreamError,
1245
+ nextDesktopState,
948
1246
  parseSseStream,
949
1247
  proxySessionEventStream,
950
1248
  resumeSequenceFromRequest,
951
1249
  sessionEventsToSseResponse,
952
1250
  sessionEventsToSseStream,
953
- streamSessionEvents
1251
+ streamSessionEvents,
1252
+ terminalSocketUrl,
1253
+ ttydAuthFrame,
1254
+ ttydInputFrame,
1255
+ ttydResizeFrame
954
1256
  };
955
1257
  //# sourceMappingURL=index.js.map