@opengeni/sdk 0.36.1 → 0.37.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/README.md +6 -1
- package/dist/chunk-DXDL7EEW.js +573 -0
- package/dist/chunk-DXDL7EEW.js.map +1 -0
- package/dist/chunk-OB5PGV6N.js +1988 -0
- package/dist/chunk-OB5PGV6N.js.map +1 -0
- package/dist/chunk-OINSI33U.js +97 -0
- package/dist/chunk-OINSI33U.js.map +1 -0
- package/dist/{chunk-B7E4FPNZ.js → chunk-VOQ235WN.js} +136 -106
- package/dist/chunk-VOQ235WN.js.map +1 -0
- package/dist/client.d.ts +35 -2
- package/dist/codex-realtime-controller.d.ts +109 -0
- package/dist/codex-realtime-controller.js +12 -0
- package/dist/codex-realtime-controller.js.map +1 -0
- package/dist/codex-realtime-lifecycle.d.ts +18 -0
- package/dist/codex-realtime-v3-wire.d.ts +86 -0
- package/dist/codex-realtime-v3.d.ts +52 -0
- package/dist/codex-realtime.d.ts +68 -0
- package/dist/core.js +6 -4
- package/dist/gateway-realtime-transport.d.ts +2 -0
- package/dist/gateway-realtime-transport.js +7 -0
- package/dist/gateway-realtime-transport.js.map +1 -0
- package/dist/index.d.ts +10 -1
- package/dist/index.js +38 -6
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +193 -3
- package/package.json +10 -1
- package/src/client.ts +211 -17
- package/src/codex-realtime-controller.ts +1427 -0
- package/src/codex-realtime-lifecycle.ts +97 -0
- package/src/codex-realtime-v3-wire.ts +349 -0
- package/src/codex-realtime-v3.ts +575 -0
- package/src/codex-realtime.ts +411 -0
- package/src/gateway-realtime-transport.ts +650 -0
- package/src/index.ts +71 -0
- package/src/types.ts +238 -3
- package/dist/chunk-B7E4FPNZ.js.map +0 -1
|
@@ -1,90 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
body;
|
|
10
|
-
constructor(status, body, options = {}) {
|
|
11
|
-
const decoded = decodeApiErrorBody(body);
|
|
12
|
-
const correlationId = decoded?.requestId ?? boundedCorrelationId(options.correlationId);
|
|
13
|
-
const gatewayFailure = status >= 502 && status <= 504;
|
|
14
|
-
const fromResponse = options.mutation !== void 0;
|
|
15
|
-
const message = decoded?.message ?? (fromResponse ? "Request failed." : body || "(empty body)");
|
|
16
|
-
const displayMessage = options.displayMessage ?? (gatewayFailure && fromResponse ? "OpenGeni is temporarily unavailable \u2014 retry." : `OpenGeni API ${status}: ${message}`);
|
|
17
|
-
super(correlationId ? `${displayMessage} Reference: ${correlationId}.` : displayMessage);
|
|
18
|
-
this.name = "OpenGeniApiError";
|
|
19
|
-
this.status = status;
|
|
20
|
-
this.code = options.code ?? decoded?.code ?? (gatewayFailure && fromResponse ? "upstream_unavailable" : void 0);
|
|
21
|
-
this.retryable = options.retryable ?? decoded?.retryable ?? retryableApiStatus(status);
|
|
22
|
-
this.correlationId = correlationId;
|
|
23
|
-
this.outcomeUnknown = options.outcomeUnknown ?? (gatewayFailure && !!options.mutation && !decoded);
|
|
24
|
-
this.body = !fromResponse || decoded ? body : "";
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
function decodeApiErrorBody(body) {
|
|
28
|
-
if (!body) return null;
|
|
29
|
-
try {
|
|
30
|
-
const decoded = JSON.parse(body);
|
|
31
|
-
if (!decoded || typeof decoded !== "object" || Array.isArray(decoded)) return null;
|
|
32
|
-
const record = decoded;
|
|
33
|
-
const nested = record.error && typeof record.error === "object" && !Array.isArray(record.error) ? record.error : record;
|
|
34
|
-
const code = boundedApiField(nested.code);
|
|
35
|
-
const message = boundedApiField(nested.message);
|
|
36
|
-
const requestId = boundedCorrelationId(nested.requestId);
|
|
37
|
-
const retryable = typeof nested.retryable === "boolean" ? nested.retryable : void 0;
|
|
38
|
-
if (!code && !message && !requestId && retryable === void 0) return null;
|
|
39
|
-
return {
|
|
40
|
-
code,
|
|
41
|
-
message,
|
|
42
|
-
requestId,
|
|
43
|
-
retryable
|
|
44
|
-
};
|
|
45
|
-
} catch {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function boundedApiField(value) {
|
|
50
|
-
if (typeof value !== "string") return;
|
|
51
|
-
const bytes = new TextEncoder().encode(value);
|
|
52
|
-
return bytes.byteLength <= 512 ? value : new TextDecoder().decode(bytes.slice(0, 512));
|
|
53
|
-
}
|
|
54
|
-
function retryableApiStatus(status) {
|
|
55
|
-
return status === 408 || status === 409 || status === 425 || status === 429 || status >= 500;
|
|
56
|
-
}
|
|
57
|
-
function boundedCorrelationId(value) {
|
|
58
|
-
if (typeof value !== "string" || value.length > 128 || !/^[\w.:-]+$/.test(value)) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
return value;
|
|
62
|
-
}
|
|
63
|
-
var OpenGeniSessionListCursorError = class extends OpenGeniApiError {
|
|
64
|
-
};
|
|
65
|
-
var OpenGeniApiContractMismatchError = class extends Error {
|
|
66
|
-
expected;
|
|
67
|
-
actual;
|
|
68
|
-
constructor(expected, actual) {
|
|
69
|
-
super(`OpenGeni API contract mismatch: client expects ${expected}, API serves ${actual}`);
|
|
70
|
-
this.name = "OpenGeniApiContractMismatchError";
|
|
71
|
-
this.expected = expected;
|
|
72
|
-
this.actual = actual;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
var OpenGeniStreamError = class extends Error {
|
|
76
|
-
constructor(message) {
|
|
77
|
-
super(message);
|
|
78
|
-
this.name = "OpenGeniStreamError";
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
function isAbortError(error) {
|
|
82
|
-
return error instanceof DOMException && error.name === "AbortError" || error instanceof Error && error.name === "AbortError";
|
|
83
|
-
}
|
|
84
|
-
function isRetryableStreamError(error) {
|
|
85
|
-
if (error instanceof OpenGeniApiError) return error.retryable;
|
|
86
|
-
return error instanceof TypeError;
|
|
87
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
OpenGeniApiContractMismatchError,
|
|
3
|
+
OpenGeniApiError,
|
|
4
|
+
OpenGeniSessionListCursorError,
|
|
5
|
+
OpenGeniStreamError,
|
|
6
|
+
isAbortError,
|
|
7
|
+
isRetryableStreamError
|
|
8
|
+
} from "./chunk-OINSI33U.js";
|
|
88
9
|
|
|
89
10
|
// src/sse.ts
|
|
90
11
|
async function* parseSseStream(stream) {
|
|
@@ -347,6 +268,8 @@ var SESSION_EVENT_TYPES = [
|
|
|
347
268
|
// Defensive bounded projection for malformed/legacy oversized envelopes.
|
|
348
269
|
"session.event.envelope_omitted",
|
|
349
270
|
"session.status.changed",
|
|
271
|
+
"session.realtime.started",
|
|
272
|
+
"session.realtime.ended",
|
|
350
273
|
"session.requiresAction",
|
|
351
274
|
"session.humanInput.requested",
|
|
352
275
|
"session.context.compaction.requested",
|
|
@@ -714,6 +637,68 @@ var OpenGeniClient = class {
|
|
|
714
637
|
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/lineage`
|
|
715
638
|
);
|
|
716
639
|
}
|
|
640
|
+
/** Negotiate one server-mediated connected-Codex GPT-Live V3 WebRTC call. */
|
|
641
|
+
async negotiateCodexRealtimeWebrtc(workspaceId, sessionId, request, options = {}) {
|
|
642
|
+
return await this.requestJson(
|
|
643
|
+
"POST",
|
|
644
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime/webrtc`,
|
|
645
|
+
request,
|
|
646
|
+
{},
|
|
647
|
+
{ signal: options.signal }
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
/** Mint a short-lived browser token for one AI Gateway realtime connection. */
|
|
651
|
+
async negotiateGatewayRealtime(workspaceId, sessionId, request, options = {}) {
|
|
652
|
+
return await this.requestJson(
|
|
653
|
+
"POST",
|
|
654
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime/gateway`,
|
|
655
|
+
request,
|
|
656
|
+
{},
|
|
657
|
+
{ signal: options.signal }
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
/** Promote a negotiated connection only after its browser data channel is ready. */
|
|
661
|
+
async activateCodexRealtimeConnection(workspaceId, sessionId, realtimeId, connectionId, request, options = {}) {
|
|
662
|
+
return await this.requestJson(
|
|
663
|
+
"POST",
|
|
664
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime/${realtimeId}/connections/${connectionId}/activate`,
|
|
665
|
+
request,
|
|
666
|
+
{},
|
|
667
|
+
{ signal: options.signal }
|
|
668
|
+
);
|
|
669
|
+
}
|
|
670
|
+
/** Atomically enter realtime mode for this ordinary session. */
|
|
671
|
+
async beginSessionRealtime(workspaceId, sessionId, request) {
|
|
672
|
+
return await this.requestJson(
|
|
673
|
+
"POST",
|
|
674
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime`,
|
|
675
|
+
request
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
/** Renew the exact authenticated browser owner's realtime lease. */
|
|
679
|
+
async heartbeatSessionRealtime(workspaceId, sessionId, realtimeId, request) {
|
|
680
|
+
return await this.requestJson(
|
|
681
|
+
"PATCH",
|
|
682
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime/${realtimeId}/heartbeat`,
|
|
683
|
+
request
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
/** Persist finalized V3 events, acknowledge delivery, and replay pending outbound context. */
|
|
687
|
+
async syncSessionRealtimeLedger(workspaceId, sessionId, realtimeId, request) {
|
|
688
|
+
return await this.requestJson(
|
|
689
|
+
"POST",
|
|
690
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime/${realtimeId}/sync`,
|
|
691
|
+
request
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
/** End realtime mode and restore ordinary text workflow admission. */
|
|
695
|
+
async endSessionRealtime(workspaceId, sessionId, realtimeId, request) {
|
|
696
|
+
return await this.requestJson(
|
|
697
|
+
"DELETE",
|
|
698
|
+
`/v1/workspaces/${workspaceId}/sessions/${sessionId}/realtime/${realtimeId}`,
|
|
699
|
+
request
|
|
700
|
+
);
|
|
701
|
+
}
|
|
717
702
|
async listTurns(workspaceId, sessionId, options = {}) {
|
|
718
703
|
return await this.requestJson(
|
|
719
704
|
"GET",
|
|
@@ -787,7 +772,10 @@ var OpenGeniClient = class {
|
|
|
787
772
|
return await this.requestJson(
|
|
788
773
|
"POST",
|
|
789
774
|
`/v1/workspaces/${workspaceId}/enrollments/device/approve`,
|
|
790
|
-
{
|
|
775
|
+
{
|
|
776
|
+
userCode: request.userCode,
|
|
777
|
+
allowScreenControl: request.allowScreenControl ?? false
|
|
778
|
+
}
|
|
791
779
|
);
|
|
792
780
|
}
|
|
793
781
|
/** Deny a pending device-enrollment flow (the explicit "no" at the approve page). */
|
|
@@ -887,7 +875,10 @@ var OpenGeniClient = class {
|
|
|
887
875
|
);
|
|
888
876
|
assertApiContractResponse(response);
|
|
889
877
|
if (!response.ok) {
|
|
890
|
-
throw await apiErrorFromResponse(response, {
|
|
878
|
+
throw await apiErrorFromResponse(response, {
|
|
879
|
+
method: "GET",
|
|
880
|
+
correlationId
|
|
881
|
+
});
|
|
891
882
|
}
|
|
892
883
|
await assertJsonResponse(response, { method: "GET", correlationId });
|
|
893
884
|
const body = await response.json();
|
|
@@ -933,7 +924,9 @@ var OpenGeniClient = class {
|
|
|
933
924
|
* never creates a model turn. `latest: "receipt"` aliases `tool_receipt`;
|
|
934
925
|
* turn generation remains scoped retry metadata.
|
|
935
926
|
*/
|
|
936
|
-
async getLatestEventResult(workspaceId, sessionId, options = {
|
|
927
|
+
async getLatestEventResult(workspaceId, sessionId, options = {
|
|
928
|
+
latest: "terminal"
|
|
929
|
+
}) {
|
|
937
930
|
return await this.listEventPage(workspaceId, sessionId, {
|
|
938
931
|
...options,
|
|
939
932
|
resultMode: "compact"
|
|
@@ -1025,7 +1018,10 @@ var OpenGeniClient = class {
|
|
|
1025
1018
|
});
|
|
1026
1019
|
assertApiContractResponse(response);
|
|
1027
1020
|
if (!response.ok) {
|
|
1028
|
-
throw await apiErrorFromResponse(response, {
|
|
1021
|
+
throw await apiErrorFromResponse(response, {
|
|
1022
|
+
method: "GET",
|
|
1023
|
+
correlationId
|
|
1024
|
+
});
|
|
1029
1025
|
}
|
|
1030
1026
|
if (!response.body) {
|
|
1031
1027
|
throw new OpenGeniApiError(response.status, "SSE response did not include a readable body");
|
|
@@ -1095,6 +1091,19 @@ var OpenGeniClient = class {
|
|
|
1095
1091
|
...options.expectedControlEtag ? { expectedControlEtag: options.expectedControlEtag } : {}
|
|
1096
1092
|
});
|
|
1097
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Terminally cancel a session subtree. Unlike pause, cancellation drains
|
|
1096
|
+
* queued work and permanently fences new prompts for the session and every
|
|
1097
|
+
* descendant.
|
|
1098
|
+
*/
|
|
1099
|
+
async cancelSession(workspaceId, sessionId, options = {}) {
|
|
1100
|
+
return await this.controlSession(workspaceId, sessionId, {
|
|
1101
|
+
action: "cancel",
|
|
1102
|
+
clientEventId: options.clientEventId ?? crypto.randomUUID(),
|
|
1103
|
+
...options.reason ? { reason: options.reason } : {},
|
|
1104
|
+
...options.expectedControlEtag ? { expectedControlEtag: options.expectedControlEtag } : {}
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1098
1107
|
async setWorkspaceInferenceState(workspaceId, request) {
|
|
1099
1108
|
return await this.requestJson(
|
|
1100
1109
|
"POST",
|
|
@@ -1120,7 +1129,10 @@ var OpenGeniClient = class {
|
|
|
1120
1129
|
);
|
|
1121
1130
|
assertApiContractResponse(response);
|
|
1122
1131
|
if (!response.ok) {
|
|
1123
|
-
throw await apiErrorFromResponse(response, {
|
|
1132
|
+
throw await apiErrorFromResponse(response, {
|
|
1133
|
+
method: "GET",
|
|
1134
|
+
correlationId
|
|
1135
|
+
});
|
|
1124
1136
|
}
|
|
1125
1137
|
await assertJsonResponse(response, { method: "GET", correlationId });
|
|
1126
1138
|
const events = await response.json();
|
|
@@ -1154,13 +1166,19 @@ var OpenGeniClient = class {
|
|
|
1154
1166
|
}),
|
|
1155
1167
|
{
|
|
1156
1168
|
method: "GET",
|
|
1157
|
-
headers: {
|
|
1169
|
+
headers: {
|
|
1170
|
+
...this.headers(correlationId),
|
|
1171
|
+
Accept: "text/event-stream"
|
|
1172
|
+
},
|
|
1158
1173
|
...options.signal ? { signal: options.signal } : {}
|
|
1159
1174
|
}
|
|
1160
1175
|
);
|
|
1161
1176
|
assertApiContractResponse(response);
|
|
1162
1177
|
if (!response.ok) {
|
|
1163
|
-
throw await apiErrorFromResponse(response, {
|
|
1178
|
+
throw await apiErrorFromResponse(response, {
|
|
1179
|
+
method: "GET",
|
|
1180
|
+
correlationId
|
|
1181
|
+
});
|
|
1164
1182
|
}
|
|
1165
1183
|
if (!response.body) {
|
|
1166
1184
|
throw new OpenGeniApiError(response.status, "SSE response did not include a readable body");
|
|
@@ -1478,6 +1496,13 @@ var OpenGeniClient = class {
|
|
|
1478
1496
|
`/v1/workspaces/${workspaceId}/model-catalog`
|
|
1479
1497
|
);
|
|
1480
1498
|
}
|
|
1499
|
+
/** Authenticated realtime voice models and credential readiness. */
|
|
1500
|
+
async getWorkspaceRealtimeModelCatalog(workspaceId) {
|
|
1501
|
+
return await this.requestJson(
|
|
1502
|
+
"GET",
|
|
1503
|
+
`/v1/workspaces/${workspaceId}/realtime-model-catalog`
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1481
1506
|
/** The caller's access context: subject, account + workspace grants, defaults. */
|
|
1482
1507
|
async getAccessContext() {
|
|
1483
1508
|
return await this.requestJson("GET", "/v1/access/me");
|
|
@@ -1735,7 +1760,9 @@ var OpenGeniClient = class {
|
|
|
1735
1760
|
"GET",
|
|
1736
1761
|
`/v1/workspaces/${workspaceId}/scheduled-tasks/${taskId}/runs`,
|
|
1737
1762
|
void 0,
|
|
1738
|
-
{
|
|
1763
|
+
{
|
|
1764
|
+
...options.limit !== void 0 ? { limit: String(options.limit) } : {}
|
|
1765
|
+
}
|
|
1739
1766
|
);
|
|
1740
1767
|
}
|
|
1741
1768
|
// --- VariableSets --------------------------------------------------------------
|
|
@@ -1996,7 +2023,10 @@ var OpenGeniClient = class {
|
|
|
1996
2023
|
throw error;
|
|
1997
2024
|
}
|
|
1998
2025
|
if (!response.ok) {
|
|
1999
|
-
throw await apiErrorFromResponse(response, {
|
|
2026
|
+
throw await apiErrorFromResponse(response, {
|
|
2027
|
+
method: "GET",
|
|
2028
|
+
correlationId
|
|
2029
|
+
});
|
|
2000
2030
|
}
|
|
2001
2031
|
if (response.status !== 200 && response.status !== 206) {
|
|
2002
2032
|
await cancelResponseBody(response, "unexpected retained artifact response status");
|
|
@@ -2282,6 +2312,14 @@ var OpenGeniClient = class {
|
|
|
2282
2312
|
request
|
|
2283
2313
|
);
|
|
2284
2314
|
}
|
|
2315
|
+
async listOpenGeniSlackReactionChannels(workspaceId, connectionId, cursor) {
|
|
2316
|
+
const query = new URLSearchParams({ connectionId });
|
|
2317
|
+
if (cursor) query.set("cursor", cursor);
|
|
2318
|
+
return await this.requestJson(
|
|
2319
|
+
"GET",
|
|
2320
|
+
`/v1/workspaces/${workspaceId}/integrations/slack/reaction-channels?${query}`
|
|
2321
|
+
);
|
|
2322
|
+
}
|
|
2285
2323
|
async updateConnection(workspaceId, connectionId, request) {
|
|
2286
2324
|
const response = await this.requestJson(
|
|
2287
2325
|
"PATCH",
|
|
@@ -2536,10 +2574,7 @@ var OpenGeniClient = class {
|
|
|
2536
2574
|
}
|
|
2537
2575
|
/** Disconnect ONE Codex account by id (re-picks active when the removed one was active). */
|
|
2538
2576
|
async disconnectCodexAccount(workspaceId, accountId) {
|
|
2539
|
-
return await this.requestJson(
|
|
2540
|
-
"DELETE",
|
|
2541
|
-
`/v1/workspaces/${workspaceId}/codex/accounts/${accountId}`
|
|
2542
|
-
);
|
|
2577
|
+
return await this.requestJson("DELETE", `/v1/workspaces/${workspaceId}/codex/accounts/${accountId}`);
|
|
2543
2578
|
}
|
|
2544
2579
|
/** Rename a Codex account (label only in P1). */
|
|
2545
2580
|
async renameCodexAccount(workspaceId, accountId, label) {
|
|
@@ -2976,11 +3011,6 @@ function isNullableBoundedNumber(value, maximum) {
|
|
|
2976
3011
|
}
|
|
2977
3012
|
|
|
2978
3013
|
export {
|
|
2979
|
-
OpenGeniApiError,
|
|
2980
|
-
OpenGeniSessionListCursorError,
|
|
2981
|
-
OpenGeniApiContractMismatchError,
|
|
2982
|
-
OpenGeniStreamError,
|
|
2983
|
-
isRetryableStreamError,
|
|
2984
3014
|
parseSseStream,
|
|
2985
3015
|
streamSessionEvents,
|
|
2986
3016
|
streamWorkspaceControlEvents,
|
|
@@ -2999,4 +3029,4 @@ export {
|
|
|
2999
3029
|
authorizeTranscriptionAdapter,
|
|
3000
3030
|
createTranscriptionSessionRequest
|
|
3001
3031
|
};
|
|
3002
|
-
//# sourceMappingURL=chunk-
|
|
3032
|
+
//# sourceMappingURL=chunk-VOQ235WN.js.map
|