@opengeni/sdk 0.3.1 → 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 +628 -5
- package/dist/index.js +261 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/src/client.ts +185 -0
- package/src/desktop.ts +152 -0
- package/src/index.ts +98 -0
- package/src/terminal.ts +91 -0
- package/src/types.ts +359 -1
package/dist/index.js
CHANGED
|
@@ -426,6 +426,127 @@ 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 -----------------------------------------------------
|
|
430
551
|
/**
|
|
431
552
|
* The deployment's public client bootstrap config: the host-exposed models
|
|
@@ -632,6 +753,16 @@ var OpenGeniClient = class {
|
|
|
632
753
|
`/v1/workspaces/${workspaceId}/document-bases/${baseId}/documents/${documentId}/reindex`
|
|
633
754
|
);
|
|
634
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
|
+
}
|
|
635
766
|
async searchDocuments(workspaceId, baseId, request) {
|
|
636
767
|
return await this.requestJson(
|
|
637
768
|
"POST",
|
|
@@ -909,6 +1040,94 @@ function proxySessionEventStream(client, workspaceId, sessionId, options = {}) {
|
|
|
909
1040
|
});
|
|
910
1041
|
}
|
|
911
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
|
+
|
|
912
1131
|
// src/types.ts
|
|
913
1132
|
var SESSION_EVENT_TYPES = [
|
|
914
1133
|
"session.created",
|
|
@@ -942,7 +1161,24 @@ var SESSION_EVENT_TYPES = [
|
|
|
942
1161
|
"goal.completed",
|
|
943
1162
|
"goal.paused",
|
|
944
1163
|
"goal.resumed",
|
|
945
|
-
"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"
|
|
946
1182
|
];
|
|
947
1183
|
var KNOWN_PERMISSIONS = [
|
|
948
1184
|
"account:read",
|
|
@@ -956,8 +1192,17 @@ var KNOWN_PERMISSIONS = [
|
|
|
956
1192
|
"sessions:create",
|
|
957
1193
|
"sessions:read",
|
|
958
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",
|
|
959
1202
|
"files:upload",
|
|
960
1203
|
"files:read",
|
|
1204
|
+
"files:write",
|
|
1205
|
+
"terminal:attach",
|
|
961
1206
|
"documents:manage",
|
|
962
1207
|
"documents:search",
|
|
963
1208
|
"scheduled_tasks:manage",
|
|
@@ -978,7 +1223,10 @@ var KNOWN_USAGE_EVENT_TYPES = [
|
|
|
978
1223
|
"file.deleted",
|
|
979
1224
|
"document.indexed",
|
|
980
1225
|
"scheduled_task.fired",
|
|
981
|
-
"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"
|
|
982
1230
|
];
|
|
983
1231
|
export {
|
|
984
1232
|
KNOWN_PERMISSIONS,
|
|
@@ -987,13 +1235,23 @@ export {
|
|
|
987
1235
|
OpenGeniClient,
|
|
988
1236
|
OpenGeniStreamError,
|
|
989
1237
|
SESSION_EVENT_TYPES,
|
|
1238
|
+
TTYD_SUBPROTOCOL,
|
|
1239
|
+
TtydClientCommand,
|
|
1240
|
+
TtydServerCommand,
|
|
1241
|
+
applyUrlRotation,
|
|
1242
|
+
desktopSocketUrl,
|
|
990
1243
|
formatSseEvent,
|
|
991
1244
|
isRetryableStreamError,
|
|
1245
|
+
nextDesktopState,
|
|
992
1246
|
parseSseStream,
|
|
993
1247
|
proxySessionEventStream,
|
|
994
1248
|
resumeSequenceFromRequest,
|
|
995
1249
|
sessionEventsToSseResponse,
|
|
996
1250
|
sessionEventsToSseStream,
|
|
997
|
-
streamSessionEvents
|
|
1251
|
+
streamSessionEvents,
|
|
1252
|
+
terminalSocketUrl,
|
|
1253
|
+
ttydAuthFrame,
|
|
1254
|
+
ttydInputFrame,
|
|
1255
|
+
ttydResizeFrame
|
|
998
1256
|
};
|
|
999
1257
|
//# sourceMappingURL=index.js.map
|