@opengeni/sdk 7.4.0-canary.36844267522001 → 7.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/README.md +0 -20
- package/dist/adapters/next.js +4 -4
- package/dist/artifacts.js +7 -7
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +6 -8
- package/dist/chat/index.js +8 -8
- package/dist/{chunk-Y7UZBXVN.js → chunk-6NEPJ7NC.js} +2 -2
- package/dist/{chunk-HUU666SV.js → chunk-7HIA2AI3.js} +2 -2
- package/dist/{chunk-ZVXGB2XR.js → chunk-A73QXCBW.js} +6 -387
- package/dist/chunk-A73QXCBW.js.map +1 -0
- package/dist/{chunk-W4ZUQGOC.js → chunk-BX5ETUM7.js} +2 -2
- package/dist/{chunk-G4JBTVCL.js → chunk-FLOL2IES.js} +2 -2
- package/dist/{chunk-KSPK3BF4.js → chunk-FMLDFJ2Q.js} +2 -2
- package/dist/{chunk-UNUSADDA.js → chunk-GT2I4X7R.js} +4 -9
- package/dist/chunk-GT2I4X7R.js.map +1 -0
- package/dist/{chunk-GFCK4T7J.js → chunk-HGGK2BW2.js} +2 -2
- package/dist/{chunk-GMY3TIKM.js → chunk-HZH5DJNN.js} +4 -4
- package/dist/{chunk-5K6KZAAK.js → chunk-MV2PNVU4.js} +1 -4
- package/dist/chunk-MV2PNVU4.js.map +1 -0
- package/dist/{chunk-KCE5UPK5.js → chunk-OO5LPTO7.js} +1 -40
- package/dist/chunk-OO5LPTO7.js.map +1 -0
- package/dist/{chunk-TCRXQEFG.js → chunk-QSCQUITU.js} +19 -102
- package/dist/chunk-QSCQUITU.js.map +1 -0
- package/dist/{chunk-NOEFKMPG.js → chunk-VF2IW4M5.js} +2 -91
- package/dist/chunk-VF2IW4M5.js.map +1 -0
- package/dist/client.d.ts +2 -32
- package/dist/codex-realtime-controller.js +2 -2
- package/dist/core.js +7 -7
- package/dist/document-authority.js +6 -6
- package/dist/editable-artifacts.js +1 -1
- package/dist/embedding-client.d.ts +0 -39
- package/dist/errors.d.ts +0 -13
- package/dist/index.d.ts +5 -6
- package/dist/index.js +141 -39
- package/dist/index.js.map +1 -1
- package/dist/interaction.js +2 -2
- package/dist/message-links.d.ts +0 -5
- package/dist/realtime.js +2 -2
- package/dist/session-proxy.d.ts +1 -44
- package/dist/site-browser-runtime.gen.d.ts +1 -1
- package/dist/site-document.js +1 -1
- package/dist/site-document.js.map +1 -1
- package/dist/site.js +7 -7
- package/dist/{tools-52AEE64Y.js → tools-FSTY4FAY.js} +3 -3
- package/dist/types.d.ts +3 -55
- package/dist/workspace-integrations.d.ts +2 -5
- package/dist/workspace-integrations.js +1 -1
- package/package.json +3 -11
- package/src/browser.ts +0 -1
- package/src/client.ts +13 -134
- package/src/embedding-client.ts +0 -130
- package/src/errors.ts +0 -56
- package/src/index.ts +1 -33
- package/src/message-links.ts +0 -6
- package/src/session-proxy.ts +1 -309
- package/src/site-browser-runtime.gen.ts +1 -1
- package/src/types.ts +2 -60
- package/src/workspace-integrations.ts +3 -17
- package/dist/allowance-refusal.d.ts +0 -2
- package/dist/allowance-refusal.js +0 -50
- package/dist/allowance-refusal.js.map +0 -1
- package/dist/chunk-5K6KZAAK.js.map +0 -1
- package/dist/chunk-KCE5UPK5.js.map +0 -1
- package/dist/chunk-NOEFKMPG.js.map +0 -1
- package/dist/chunk-TCRXQEFG.js.map +0 -1
- package/dist/chunk-UNUSADDA.js.map +0 -1
- package/dist/chunk-ZVXGB2XR.js.map +0 -1
- package/dist/session-proxy-client.d.ts +0 -24
- package/dist/session-proxy.js +0 -22
- package/dist/tools-52AEE64Y.js.map +0 -1
- package/src/allowance-refusal.ts +0 -5
- package/src/session-proxy-client.ts +0 -64
- /package/dist/{chunk-Y7UZBXVN.js.map → chunk-6NEPJ7NC.js.map} +0 -0
- /package/dist/{chunk-HUU666SV.js.map → chunk-7HIA2AI3.js.map} +0 -0
- /package/dist/{chunk-W4ZUQGOC.js.map → chunk-BX5ETUM7.js.map} +0 -0
- /package/dist/{chunk-G4JBTVCL.js.map → chunk-FLOL2IES.js.map} +0 -0
- /package/dist/{chunk-KSPK3BF4.js.map → chunk-FMLDFJ2Q.js.map} +0 -0
- /package/dist/{chunk-GFCK4T7J.js.map → chunk-HGGK2BW2.js.map} +0 -0
- /package/dist/{chunk-GMY3TIKM.js.map → chunk-HZH5DJNN.js.map} +0 -0
- /package/dist/{session-proxy.js.map → tools-FSTY4FAY.js.map} +0 -0
package/README.md
CHANGED
|
@@ -25,26 +25,6 @@ bearer design, but an organization API key belongs on the product server.
|
|
|
25
25
|
Browser cookies are accepted cross-origin only from operator-configured trusted
|
|
26
26
|
origins; arbitrary embedding origins never receive credentialed CORS responses.
|
|
27
27
|
|
|
28
|
-
## Allowance lifecycle recovery
|
|
29
|
-
|
|
30
|
-
`getWorkspaceAllowance(workspaceId)` still returns nullable configuration.
|
|
31
|
-
Use `getWorkspaceAllowanceState(workspaceId)` when you also need the lifecycle
|
|
32
|
-
version: `{ version: 0, config: null }` means never configured, while a positive
|
|
33
|
-
version with null configuration means cleared. Recreation uses that exact
|
|
34
|
-
version as `expectedVersion`.
|
|
35
|
-
|
|
36
|
-
`clearWorkspaceAllowance(workspaceId, { expectedVersion, operationId })` returns
|
|
37
|
-
`{ version }`. The optional operation ID makes a lost response recoverable:
|
|
38
|
-
reuse the same actor, operation ID and exact request. Replay rechecks current
|
|
39
|
-
authority and returns 409 after any later allowance lifecycle change. On 409,
|
|
40
|
-
read the current state and decide whether a new operation is intended; never
|
|
41
|
-
guess a CAS version. The SDK does not automatically retry mutations.
|
|
42
|
-
|
|
43
|
-
State reads require the same budget-read authority as configuration reads.
|
|
44
|
-
Full usage additionally requires target workspace access; organization budget
|
|
45
|
-
authority alone does not expose the member roster. Agents cannot read or
|
|
46
|
-
change allowances.
|
|
47
|
-
|
|
48
28
|
## Embed the conversation (default)
|
|
49
29
|
|
|
50
30
|
The default product integration is the full OpenGeni conversation:
|
package/dist/adapters/next.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createSessionProxyHandler
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-A73QXCBW.js";
|
|
4
|
+
import "../chunk-BX5ETUM7.js";
|
|
5
|
+
import "../chunk-MV2PNVU4.js";
|
|
6
|
+
import "../chunk-OO5LPTO7.js";
|
|
7
7
|
|
|
8
8
|
// src/adapters/next.ts
|
|
9
9
|
function toNextRouteHandlers(handler) {
|
package/dist/artifacts.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniClient
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-7HIA2AI3.js";
|
|
4
|
+
import "./chunk-HGGK2BW2.js";
|
|
5
|
+
import "./chunk-QSCQUITU.js";
|
|
6
|
+
import "./chunk-BX5ETUM7.js";
|
|
7
|
+
import "./chunk-MV2PNVU4.js";
|
|
8
|
+
import "./chunk-FLOL2IES.js";
|
|
9
|
+
import "./chunk-OO5LPTO7.js";
|
|
10
10
|
export {
|
|
11
11
|
OpenGeniClient
|
|
12
12
|
};
|
package/dist/browser.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type { SessionMessageSearchRequest, SessionMessageSearchMatch, SessionMes
|
|
|
4
4
|
export { OpenGeniToolCallError, OpenGeniToolReapprovalRequiredError, OpenGeniToolsClient, } from "./tools.js";
|
|
5
5
|
export type { OpenGeniGeneratedTools, OpenGeniDynamicToolNode, OpenGeniToolCallOptions, OpenGeniToolFunction, OpenGeniToolsFacade, OpenGeniWorkspaceTools, } from "./tools.js";
|
|
6
6
|
export type { FetchLike, FetchResponse, GetSessionOptions, OpenGeniClientOptions, OpenGeniRequestOptions, SendMessageInput, SteerMessageResult, TranscribeAudioInput, WorkspaceControlEventPage, } from "./client.js";
|
|
7
|
-
export { OpenGeniApiContractMismatchError, OpenGeniApiError,
|
|
7
|
+
export { OpenGeniApiContractMismatchError, OpenGeniApiError, OpenGeniSecureContextRequiredError, OpenGeniSessionListCursorError, OpenGeniStreamError, isRetryableStreamError, } from "./errors.js";
|
|
8
8
|
export type { OpenGeniSecureContextRequiredReason } from "./errors.js";
|
|
9
9
|
export { resolveWorkspaceVoiceInputEnabled } from "./transcription.js";
|
|
10
10
|
export { OPENGENI_API_CONTRACT_HEADER, OPENGENI_API_CONTRACT_REVISION } from "./types.js";
|
package/dist/browser.js
CHANGED
|
@@ -5,29 +5,27 @@ import {
|
|
|
5
5
|
OpenGeniToolCallError,
|
|
6
6
|
OpenGeniToolReapprovalRequiredError,
|
|
7
7
|
OpenGeniToolsClient
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-FMLDFJ2Q.js";
|
|
9
9
|
import {
|
|
10
10
|
OpenGeniClient
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-QSCQUITU.js";
|
|
12
|
+
import "./chunk-BX5ETUM7.js";
|
|
13
13
|
import {
|
|
14
14
|
OPENGENI_API_CONTRACT_HEADER,
|
|
15
15
|
OPENGENI_API_CONTRACT_REVISION
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-MV2PNVU4.js";
|
|
17
|
+
import "./chunk-FLOL2IES.js";
|
|
18
18
|
import {
|
|
19
|
-
OpenGeniAllowanceExhaustedError,
|
|
20
19
|
OpenGeniApiContractMismatchError,
|
|
21
20
|
OpenGeniApiError,
|
|
22
21
|
OpenGeniSecureContextRequiredError,
|
|
23
22
|
OpenGeniSessionListCursorError,
|
|
24
23
|
OpenGeniStreamError,
|
|
25
24
|
isRetryableStreamError
|
|
26
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-OO5LPTO7.js";
|
|
27
26
|
export {
|
|
28
27
|
OPENGENI_API_CONTRACT_HEADER,
|
|
29
28
|
OPENGENI_API_CONTRACT_REVISION,
|
|
30
|
-
OpenGeniAllowanceExhaustedError,
|
|
31
29
|
OpenGeniApiContractMismatchError,
|
|
32
30
|
OpenGeniApiError,
|
|
33
31
|
OpenGeniClient as OpenGeniBrowserClient,
|
package/dist/chat/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniEmbeddingClient
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-VF2IW4M5.js";
|
|
4
|
+
import "../chunk-7HIA2AI3.js";
|
|
5
|
+
import "../chunk-HGGK2BW2.js";
|
|
6
|
+
import "../chunk-QSCQUITU.js";
|
|
7
7
|
import {
|
|
8
8
|
parseSseStream
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import "../chunk-
|
|
11
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-BX5ETUM7.js";
|
|
10
|
+
import "../chunk-MV2PNVU4.js";
|
|
11
|
+
import "../chunk-FLOL2IES.js";
|
|
12
12
|
import {
|
|
13
13
|
OpenGeniApiError
|
|
14
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-OO5LPTO7.js";
|
|
15
15
|
|
|
16
16
|
// src/chat/types.ts
|
|
17
17
|
var OpenGeniChatError = class extends Error {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniApiError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-OO5LPTO7.js";
|
|
4
4
|
|
|
5
5
|
// src/codex-realtime-v3-wire.ts
|
|
6
6
|
var CODEX_REALTIME_INITIAL_ITEMS_MAX_COUNT = 128;
|
|
@@ -2278,4 +2278,4 @@ export {
|
|
|
2278
2278
|
hasStoredSessionRealtimeOwnerProof,
|
|
2279
2279
|
createCodexRealtimeController
|
|
2280
2280
|
};
|
|
2281
|
-
//# sourceMappingURL=chunk-
|
|
2281
|
+
//# sourceMappingURL=chunk-6NEPJ7NC.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OpenGeniDocumentAuthorityClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HGGK2BW2.js";
|
|
4
4
|
|
|
5
5
|
// src/artifact-client.ts
|
|
6
6
|
var OpenGeniClient = class extends OpenGeniDocumentAuthorityClient {
|
|
@@ -121,4 +121,4 @@ var OpenGeniClient = class extends OpenGeniDocumentAuthorityClient {
|
|
|
121
121
|
export {
|
|
122
122
|
OpenGeniClient
|
|
123
123
|
};
|
|
124
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-7HIA2AI3.js.map
|
|
@@ -1,128 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
sessionEventStreamCoveredThrough
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-BX5ETUM7.js";
|
|
4
4
|
import {
|
|
5
5
|
OPENGENI_API_CONTRACT_HEADER,
|
|
6
6
|
OPENGENI_API_CONTRACT_REVISION
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MV2PNVU4.js";
|
|
8
8
|
import {
|
|
9
9
|
OpenGeniApiError
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
|
|
12
|
-
// src/message-links.ts
|
|
13
|
-
var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/iu;
|
|
14
|
-
var EDITABLE_ID = /^[0-9a-f]{32}$/iu;
|
|
15
|
-
var WORKSPACE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/u;
|
|
16
|
-
var SANDBOX_SCHEME = "sandbox:";
|
|
17
|
-
var LEGACY_WORKSPACE_PREFIX = "/workspace/";
|
|
18
|
-
var TRAILING_LINE = /:([0-9]+)$/u;
|
|
19
|
-
var TRAILING_INVALID_LINE = /:-(?:[0-9]+)$|:[0-9]+-[0-9]+$/u;
|
|
20
|
-
var CONTROL_CHARACTER = /[\u0000-\u001f\u007f]/u;
|
|
21
|
-
function openGeniLinkScheme(href) {
|
|
22
|
-
const scheme = /^([a-z]+):/iu.exec(href ?? "")?.[1]?.toLowerCase();
|
|
23
|
-
return scheme === "artifact" || scheme === "sandbox" ? scheme : null;
|
|
24
|
-
}
|
|
25
|
-
function isReservedOpenGeniLink(href) {
|
|
26
|
-
if (!href) return false;
|
|
27
|
-
if (openGeniLinkScheme(href) || href.startsWith(LEGACY_WORKSPACE_PREFIX)) return true;
|
|
28
|
-
try {
|
|
29
|
-
return /^\/workspaces\/[^/]+\/artifacts(?:\/|[?#]|$)/u.test(decodeURIComponent(href));
|
|
30
|
-
} catch {
|
|
31
|
-
return /^\/workspaces\/[^/]+\/artifacts/u.test(href);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function parseSandboxLink(href) {
|
|
35
|
-
if (!href) return null;
|
|
36
|
-
const encodedLocation = openGeniLinkScheme(href) === "sandbox" ? href.slice(SANDBOX_SCHEME.length) : href.startsWith(LEGACY_WORKSPACE_PREFIX) ? href : null;
|
|
37
|
-
if (!encodedLocation || encodedLocation.includes("?") || encodedLocation.includes("#")) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
if (TRAILING_INVALID_LINE.test(encodedLocation)) return null;
|
|
41
|
-
const lineMatch = TRAILING_LINE.exec(encodedLocation);
|
|
42
|
-
const encodedPath = lineMatch ? encodedLocation.slice(0, -lineMatch[0].length) : encodedLocation;
|
|
43
|
-
const line = lineMatch?.[1] ? Number(lineMatch[1]) : null;
|
|
44
|
-
if (line !== null && (!Number.isSafeInteger(line) || line < 1)) return null;
|
|
45
|
-
if (!encodedPath) return null;
|
|
46
|
-
try {
|
|
47
|
-
const path = decodeURIComponent(encodedPath);
|
|
48
|
-
return path && !CONTROL_CHARACTER.test(path) ? { path, line } : null;
|
|
49
|
-
} catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
function parseRetainedFileReference(href) {
|
|
54
|
-
if (openGeniLinkScheme(href) !== "artifact") return null;
|
|
55
|
-
if (!href) return null;
|
|
56
|
-
const id = href.slice("artifact:".length);
|
|
57
|
-
return UUID.test(id) ? id.toLowerCase() : null;
|
|
58
|
-
}
|
|
59
|
-
function parseOpenGeniLink(href) {
|
|
60
|
-
if (!href) return null;
|
|
61
|
-
const fileId = parseRetainedFileReference(href);
|
|
62
|
-
if (fileId) return { kind: "file", fileId, workspaceId: null };
|
|
63
|
-
if (openGeniLinkScheme(href) === "sandbox" || href.startsWith(LEGACY_WORKSPACE_PREFIX)) {
|
|
64
|
-
const location = parseSandboxLink(href);
|
|
65
|
-
return location ? { kind: "sandbox-file", ...location } : null;
|
|
66
|
-
}
|
|
67
|
-
if (!href.startsWith("/workspaces/") || href.includes("#")) return null;
|
|
68
|
-
const separator = href.indexOf("?");
|
|
69
|
-
const pathname = separator < 0 ? href : href.slice(0, separator);
|
|
70
|
-
const search = separator < 0 ? void 0 : href.slice(separator + 1);
|
|
71
|
-
let fromSession;
|
|
72
|
-
if (search !== void 0) {
|
|
73
|
-
const params = new URLSearchParams(search);
|
|
74
|
-
const keys = [...params.keys()];
|
|
75
|
-
if (keys.some((key) => key !== "fromSession") || keys.length > 1) return null;
|
|
76
|
-
if (!UUID.test(params.get("fromSession") ?? "")) return null;
|
|
77
|
-
fromSession = params.get("fromSession").toLowerCase();
|
|
78
|
-
}
|
|
79
|
-
const parts = pathname.split("/");
|
|
80
|
-
const workspaceId = parts[2] ?? "";
|
|
81
|
-
if (parts[1] !== "workspaces" || parts[3] !== "artifacts" || !WORKSPACE_SEGMENT.test(workspaceId))
|
|
82
|
-
return null;
|
|
83
|
-
if (parts.length === 6 && parts[4] === "editable" && EDITABLE_ID.test(parts[5] ?? "")) {
|
|
84
|
-
return {
|
|
85
|
-
kind: "editable-artifact",
|
|
86
|
-
artifactId: parts[5].toLowerCase(),
|
|
87
|
-
workspaceId,
|
|
88
|
-
...fromSession ? { fromSession } : {}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
if (parts.length === 6 && parts[4] === "files" && UUID.test(parts[5] ?? "")) {
|
|
92
|
-
return {
|
|
93
|
-
kind: "file",
|
|
94
|
-
fileId: parts[5].toLowerCase(),
|
|
95
|
-
workspaceId,
|
|
96
|
-
...fromSession ? { fromSession } : {}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
if (parts.length === 5 && UUID.test(parts[4] ?? "")) {
|
|
100
|
-
return {
|
|
101
|
-
kind: "site",
|
|
102
|
-
artifactId: parts[4].toLowerCase(),
|
|
103
|
-
workspaceId,
|
|
104
|
-
...fromSession ? { fromSession } : {}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return null;
|
|
108
|
-
}
|
|
109
|
-
function openGeniConsolePath(target, workspaceId) {
|
|
110
|
-
const workspace = encodeURIComponent(
|
|
111
|
-
target.kind === "sandbox-file" ? workspaceId : target.workspaceId ?? workspaceId
|
|
112
|
-
);
|
|
113
|
-
const search = target.kind !== "sandbox-file" && target.fromSession && UUID.test(target.fromSession) ? `?fromSession=${encodeURIComponent(target.fromSession)}` : "";
|
|
114
|
-
switch (target.kind) {
|
|
115
|
-
case "file":
|
|
116
|
-
return `/workspaces/${workspace}/artifacts/files/${target.fileId}${search}`;
|
|
117
|
-
case "editable-artifact":
|
|
118
|
-
return `/workspaces/${workspace}/artifacts/editable/${target.artifactId}${search}`;
|
|
119
|
-
case "site":
|
|
120
|
-
return `/workspaces/${workspace}/artifacts/${target.artifactId}${search}`;
|
|
121
|
-
case "sandbox-file":
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
var SESSION_SCOPE_HEADER = "x-opengeni-session-id";
|
|
10
|
+
} from "./chunk-OO5LPTO7.js";
|
|
126
11
|
|
|
127
12
|
// src/proxy.ts
|
|
128
13
|
function formatSseEvent(event) {
|
|
@@ -222,42 +107,6 @@ function proxySessionEventStream(client, workspaceId, sessionId, options = {}) {
|
|
|
222
107
|
});
|
|
223
108
|
}
|
|
224
109
|
|
|
225
|
-
// src/session-proxy-client.ts
|
|
226
|
-
var SESSION_PROXY_SITE_HTML_MAX_BYTES = 25 * 1024 * 1024;
|
|
227
|
-
var SessionProxySiteHtmlTooLargeError = class extends Error {
|
|
228
|
-
code = "site_html_too_large";
|
|
229
|
-
limitBytes = SESSION_PROXY_SITE_HTML_MAX_BYTES;
|
|
230
|
-
constructor() {
|
|
231
|
-
super(`Site HTML exceeds the ${SESSION_PROXY_SITE_HTML_MAX_BYTES}-byte proxy limit.`);
|
|
232
|
-
this.name = "SessionProxySiteHtmlTooLargeError";
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
function getSessionProxyWorkspaceGrant(client, workspaceId, options = {}) {
|
|
236
|
-
return client.requestJson(
|
|
237
|
-
"GET",
|
|
238
|
-
`/v1/workspaces/${encodeURIComponent(workspaceId)}/access/grant`,
|
|
239
|
-
void 0,
|
|
240
|
-
{},
|
|
241
|
-
options
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
function getSessionProxyArtifactAssociation(client, workspaceId, sessionId, kind, artifactId, options = {}) {
|
|
245
|
-
return client.requestJson(
|
|
246
|
-
"GET",
|
|
247
|
-
`/v1/workspaces/${encodeURIComponent(workspaceId)}/sessions/${encodeURIComponent(sessionId)}/artifact-associations/${encodeURIComponent(artifactId)}`,
|
|
248
|
-
void 0,
|
|
249
|
-
{ kind },
|
|
250
|
-
options
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
function downloadSessionProxySiteHtml(client, workspaceId, artifactId, options) {
|
|
254
|
-
return client.requestJsonResponse(
|
|
255
|
-
`/v1/workspaces/${encodeURIComponent(workspaceId)}/published-artifacts/${encodeURIComponent(artifactId)}/html`,
|
|
256
|
-
{ versionId: options.versionId },
|
|
257
|
-
options
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
110
|
// src/session-proxy.ts
|
|
262
111
|
var DEFAULT_MAX_BODY_BYTES = 1024 * 1024;
|
|
263
112
|
var SEGMENT = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
|
|
@@ -296,10 +145,6 @@ function createSessionProxyHandler(target, options) {
|
|
|
296
145
|
const maxBodyBytes = options.maxBodyBytes ?? DEFAULT_MAX_BODY_BYTES;
|
|
297
146
|
const filesEnabled = options.files ?? true;
|
|
298
147
|
const sandboxFilesEnabled = options.sandboxFiles === true;
|
|
299
|
-
const artifactsEnabled = options.artifacts !== void 0 && options.artifacts !== false;
|
|
300
|
-
const editableLiveUrl = artifactsEnabled ? liveSocketUrl(
|
|
301
|
-
(typeof options.artifacts === "object" ? options.artifacts.editableLiveUrl : void 0) ?? service.apiUrl(EDITABLE_ARTIFACT_LIVE_PATH)
|
|
302
|
-
) : null;
|
|
303
148
|
const modelSelection = options.modelSelection ?? true;
|
|
304
149
|
const heartbeatMs = options.heartbeatMs ?? 15e3;
|
|
305
150
|
const sessionList = options.sessionList ?? "mine";
|
|
@@ -380,27 +225,10 @@ function createSessionProxyHandler(target, options) {
|
|
|
380
225
|
query,
|
|
381
226
|
call
|
|
382
227
|
);
|
|
383
|
-
let artifacts = null;
|
|
384
|
-
if (editableLiveUrl) {
|
|
385
|
-
try {
|
|
386
|
-
artifacts = {
|
|
387
|
-
editableLiveUrl,
|
|
388
|
-
cachePartition: await cachePartition(
|
|
389
|
-
await getSessionProxyWorkspaceGrant(client, workspaceId, call),
|
|
390
|
-
workspaceId,
|
|
391
|
-
source
|
|
392
|
-
)
|
|
393
|
-
};
|
|
394
|
-
} catch (error) {
|
|
395
|
-
if (!(error instanceof OpenGeniApiError) || error.status !== 404) throw error;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
const { artifacts: _upstreamArtifacts, ...conversationConfig } = config;
|
|
399
228
|
return json({
|
|
400
|
-
...
|
|
229
|
+
...config,
|
|
401
230
|
apiContractRevision: OPENGENI_API_CONTRACT_REVISION,
|
|
402
231
|
sandboxFiles: sandboxFilesEnabled,
|
|
403
|
-
...artifacts ? { artifacts } : {},
|
|
404
232
|
...modelSelection ? {} : { modelSelection: false }
|
|
405
233
|
});
|
|
406
234
|
}
|
|
@@ -414,12 +242,6 @@ function createSessionProxyHandler(target, options) {
|
|
|
414
242
|
return errorJson(403, "workspace_not_allowed", "This workspace is not available.");
|
|
415
243
|
}
|
|
416
244
|
const base = `/v1/workspaces/${workspaceId}`;
|
|
417
|
-
if (area === "usage" && tail.length === 1 && tail[0] === "me" && method === "GET") {
|
|
418
|
-
if (Object.keys(query).some((key) => key !== "period")) {
|
|
419
|
-
return errorJson(400, "invalid_usage_query", "Only period is accepted for own usage.");
|
|
420
|
-
}
|
|
421
|
-
return await read(`${base}/usage/me`);
|
|
422
|
-
}
|
|
423
245
|
if (area === void 0 && method === "GET") return await read(base);
|
|
424
246
|
if (area === "model-catalog" && tail.length === 0 && method === "GET") {
|
|
425
247
|
return await read(`${base}/model-catalog`);
|
|
@@ -460,65 +282,6 @@ function createSessionProxyHandler(target, options) {
|
|
|
460
282
|
}
|
|
461
283
|
return errorJson(404, "route_not_allowed", "Not found.");
|
|
462
284
|
}
|
|
463
|
-
if (area === "editable-artifacts" || area === "published-artifacts") {
|
|
464
|
-
if (!artifactsEnabled) return errorJson(404, "route_not_allowed", "Not found.");
|
|
465
|
-
const [artifactId, ...artifactOp] = tail;
|
|
466
|
-
const route2 = `${method} ${artifactOp.join("/")}`;
|
|
467
|
-
const editable = area === "editable-artifacts";
|
|
468
|
-
const allowed = editable ? route2 === "GET " || route2 === "POST live-ticket" : route2 === "GET " || route2 === "GET html";
|
|
469
|
-
if (!artifactId || !SEGMENT.test(artifactId) || !allowed) {
|
|
470
|
-
return errorJson(404, "route_not_allowed", "Not found.");
|
|
471
|
-
}
|
|
472
|
-
const sessionId2 = request.headers.get(SESSION_SCOPE_HEADER)?.trim() ?? "";
|
|
473
|
-
if (!SEGMENT.test(sessionId2)) {
|
|
474
|
-
reject(400, "session_scope_required", "Artifact reads must name their session.");
|
|
475
|
-
}
|
|
476
|
-
if (options.authorizeSession && !await options.authorizeSession(sessionId2, context)) {
|
|
477
|
-
return errorJson(404, "session_not_found", "Session not found.");
|
|
478
|
-
}
|
|
479
|
-
await getSessionProxyArtifactAssociation(
|
|
480
|
-
client,
|
|
481
|
-
workspaceId,
|
|
482
|
-
sessionId2,
|
|
483
|
-
editable ? "editable" : "site",
|
|
484
|
-
artifactId,
|
|
485
|
-
call
|
|
486
|
-
);
|
|
487
|
-
const item = `${base}/${area}/${artifactId}`;
|
|
488
|
-
if (route2 === "GET ") {
|
|
489
|
-
const replicaId = editable ? query.replicaId : void 0;
|
|
490
|
-
return json(
|
|
491
|
-
await client.requestJson(
|
|
492
|
-
"GET",
|
|
493
|
-
item,
|
|
494
|
-
void 0,
|
|
495
|
-
typeof replicaId === "string" ? { replicaId } : {},
|
|
496
|
-
call
|
|
497
|
-
)
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
if (route2 === "POST live-ticket") {
|
|
501
|
-
const body2 = await readJsonBody(request, maxBodyBytes);
|
|
502
|
-
return json(
|
|
503
|
-
await client.requestJson("POST", `${item}/live-ticket`, {
|
|
504
|
-
...pick(body2, TICKET_FIELDS),
|
|
505
|
-
sourceSessionId: sessionId2
|
|
506
|
-
}),
|
|
507
|
-
201
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
const versionId = query.versionId;
|
|
511
|
-
if (typeof versionId !== "string" || !SEGMENT.test(versionId)) {
|
|
512
|
-
reject(400, "version_required", "versionId is required.");
|
|
513
|
-
}
|
|
514
|
-
const html = await downloadSessionProxySiteHtml(client, workspaceId, artifactId, {
|
|
515
|
-
versionId,
|
|
516
|
-
signal: request.signal
|
|
517
|
-
});
|
|
518
|
-
return new Response(boundedSiteHtml(html.body, request.signal), {
|
|
519
|
-
headers: SITE_HTML_HEADERS
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
285
|
if (area !== "sessions") return errorJson(404, "route_not_allowed", "Not found.");
|
|
523
286
|
if (tail.length === 0 && method === "GET") {
|
|
524
287
|
if (!sessionList) return errorJson(404, "route_not_allowed", "Not found.");
|
|
@@ -652,137 +415,6 @@ function createSessionProxyHandler(target, options) {
|
|
|
652
415
|
};
|
|
653
416
|
}
|
|
654
417
|
var UPLOAD_FIELDS = ["scope", "filename", "contentType", "sizeBytes", "sha256"];
|
|
655
|
-
var EDITABLE_ARTIFACT_LIVE_PATH = "/v1/editable-artifacts/live";
|
|
656
|
-
var TICKET_FIELDS = [
|
|
657
|
-
"replicaId",
|
|
658
|
-
"modality",
|
|
659
|
-
"liveProtocolVersion",
|
|
660
|
-
"kernelVersion",
|
|
661
|
-
"modelSchemaVersion",
|
|
662
|
-
"snapshotVersion",
|
|
663
|
-
"commandProtocolVersion",
|
|
664
|
-
"committedTransactionProtocolVersion"
|
|
665
|
-
];
|
|
666
|
-
var SITE_HTML_HEADERS = {
|
|
667
|
-
"Content-Type": "text/html; charset=utf-8",
|
|
668
|
-
"Cache-Control": "private, no-store",
|
|
669
|
-
"Content-Security-Policy": "sandbox allow-scripts",
|
|
670
|
-
"Cross-Origin-Resource-Policy": "same-origin",
|
|
671
|
-
"X-Content-Type-Options": "nosniff",
|
|
672
|
-
"Content-Disposition": 'attachment; filename="site.html"'
|
|
673
|
-
};
|
|
674
|
-
function liveSocketUrl(value) {
|
|
675
|
-
const url = new URL(value);
|
|
676
|
-
if (url.protocol === "https:") url.protocol = "wss:";
|
|
677
|
-
else if (url.protocol === "http:") url.protocol = "ws:";
|
|
678
|
-
if (url.protocol !== "wss:" && url.protocol !== "ws:") {
|
|
679
|
-
throw new TypeError("editableLiveUrl must be an HTTP(S) or WS(S) URL");
|
|
680
|
-
}
|
|
681
|
-
return url.href;
|
|
682
|
-
}
|
|
683
|
-
function boundedSiteHtml(body, signal) {
|
|
684
|
-
const reader = body?.getReader();
|
|
685
|
-
let bytes = 0;
|
|
686
|
-
let settled = false;
|
|
687
|
-
let controller;
|
|
688
|
-
const cleanup = () => signal.removeEventListener("abort", abort);
|
|
689
|
-
const cancel = async (reason) => {
|
|
690
|
-
if (settled) return;
|
|
691
|
-
settled = true;
|
|
692
|
-
cleanup();
|
|
693
|
-
await reader?.cancel(reason).catch(() => void 0);
|
|
694
|
-
reader?.releaseLock();
|
|
695
|
-
};
|
|
696
|
-
const abort = () => {
|
|
697
|
-
if (settled) return;
|
|
698
|
-
controller.error(signal.reason);
|
|
699
|
-
void cancel(signal.reason);
|
|
700
|
-
};
|
|
701
|
-
return new ReadableStream(
|
|
702
|
-
{
|
|
703
|
-
start(value) {
|
|
704
|
-
controller = value;
|
|
705
|
-
if (signal.aborted) abort();
|
|
706
|
-
else signal.addEventListener("abort", abort, { once: true });
|
|
707
|
-
},
|
|
708
|
-
async pull(value) {
|
|
709
|
-
if (settled) return;
|
|
710
|
-
try {
|
|
711
|
-
const chunk = await reader?.read();
|
|
712
|
-
if (settled) return;
|
|
713
|
-
if (!chunk || chunk.done) {
|
|
714
|
-
settled = true;
|
|
715
|
-
cleanup();
|
|
716
|
-
reader?.releaseLock();
|
|
717
|
-
value.close();
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
bytes += chunk.value.byteLength;
|
|
721
|
-
if (bytes > SESSION_PROXY_SITE_HTML_MAX_BYTES) {
|
|
722
|
-
const error = new SessionProxySiteHtmlTooLargeError();
|
|
723
|
-
value.error(error);
|
|
724
|
-
await cancel(error);
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
value.enqueue(chunk.value);
|
|
728
|
-
} catch (error) {
|
|
729
|
-
if (settled) return;
|
|
730
|
-
value.error(error);
|
|
731
|
-
await cancel(error);
|
|
732
|
-
}
|
|
733
|
-
},
|
|
734
|
-
cancel
|
|
735
|
-
},
|
|
736
|
-
// Read only when the downstream consumer requests a chunk.
|
|
737
|
-
{ highWaterMark: 0 }
|
|
738
|
-
);
|
|
739
|
-
}
|
|
740
|
-
async function artifactViewerCapability(input) {
|
|
741
|
-
return {
|
|
742
|
-
editableLiveUrl: liveSocketUrl(
|
|
743
|
-
input.editableLiveUrl ?? input.client.apiUrl(EDITABLE_ARTIFACT_LIVE_PATH)
|
|
744
|
-
),
|
|
745
|
-
cachePartition: await cachePartition(
|
|
746
|
-
input.client.requestJson ? await getSessionProxyWorkspaceGrant(
|
|
747
|
-
input.client,
|
|
748
|
-
input.workspaceId
|
|
749
|
-
) : await legacyViewerGrant(input.client, input.workspaceId),
|
|
750
|
-
input.workspaceId,
|
|
751
|
-
input.source ?? "default"
|
|
752
|
-
)
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
|
-
async function cachePartition(grant, workspaceId, source) {
|
|
756
|
-
if (grant.workspaceId !== workspaceId) {
|
|
757
|
-
reject(403, "workspace_not_allowed", "This workspace is not available.");
|
|
758
|
-
}
|
|
759
|
-
const digest = await crypto.subtle.digest(
|
|
760
|
-
"SHA-256",
|
|
761
|
-
new TextEncoder().encode(
|
|
762
|
-
JSON.stringify({
|
|
763
|
-
source,
|
|
764
|
-
subjectId: grant.subjectId,
|
|
765
|
-
accountId: grant.accountId,
|
|
766
|
-
workspaceId,
|
|
767
|
-
permissions: [...grant.permissions].sort(),
|
|
768
|
-
// Effective external grants carry live identity/link revisions. Include
|
|
769
|
-
// them even when a revoke/regrant restores an identical permission set.
|
|
770
|
-
externalActor: grant.metadata?.externalActor ?? null
|
|
771
|
-
})
|
|
772
|
-
)
|
|
773
|
-
);
|
|
774
|
-
return {
|
|
775
|
-
accountId: grant.accountId,
|
|
776
|
-
principalId: grant.subjectId,
|
|
777
|
-
authorizationEpoch: `sha256:${[...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("")}`
|
|
778
|
-
};
|
|
779
|
-
}
|
|
780
|
-
async function legacyViewerGrant(client, workspaceId) {
|
|
781
|
-
const access = await client.getAccessContext();
|
|
782
|
-
const grant = access.workspaceGrants.find((candidate) => candidate.workspaceId === workspaceId);
|
|
783
|
-
if (!grant) reject(403, "workspace_not_allowed", "This workspace is not available.");
|
|
784
|
-
return grant;
|
|
785
|
-
}
|
|
786
418
|
function sandboxRead(body) {
|
|
787
419
|
const path = body?.path;
|
|
788
420
|
const encoding = body?.encoding;
|
|
@@ -1049,24 +681,11 @@ function errorResponse(error) {
|
|
|
1049
681
|
}
|
|
1050
682
|
|
|
1051
683
|
export {
|
|
1052
|
-
openGeniLinkScheme,
|
|
1053
|
-
isReservedOpenGeniLink,
|
|
1054
|
-
parseSandboxLink,
|
|
1055
|
-
parseRetainedFileReference,
|
|
1056
|
-
parseOpenGeniLink,
|
|
1057
|
-
openGeniConsolePath,
|
|
1058
|
-
SESSION_SCOPE_HEADER,
|
|
1059
684
|
formatSseEvent,
|
|
1060
685
|
sessionEventsToSseStream,
|
|
1061
686
|
sessionEventsToSseResponse,
|
|
1062
687
|
resumeSequenceFromRequest,
|
|
1063
688
|
proxySessionEventStream,
|
|
1064
|
-
|
|
1065
|
-
SessionProxySiteHtmlTooLargeError,
|
|
1066
|
-
getSessionProxyWorkspaceGrant,
|
|
1067
|
-
getSessionProxyArtifactAssociation,
|
|
1068
|
-
downloadSessionProxySiteHtml,
|
|
1069
|
-
createSessionProxyHandler,
|
|
1070
|
-
artifactViewerCapability
|
|
689
|
+
createSessionProxyHandler
|
|
1071
690
|
};
|
|
1072
|
-
//# sourceMappingURL=chunk-
|
|
691
|
+
//# sourceMappingURL=chunk-A73QXCBW.js.map
|