@opengeni/sdk 3.1.0 → 3.1.2
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 +1037 -71
- package/dist/accounts.d.ts +5 -1
- package/dist/accounts.js +13 -1
- package/dist/accounts.js.map +1 -1
- package/dist/adapters/express.d.ts +31 -0
- package/dist/adapters/express.js +87 -0
- package/dist/adapters/express.js.map +1 -0
- package/dist/adapters/hono.d.ts +16 -0
- package/dist/adapters/hono.js +8 -0
- package/dist/adapters/hono.js.map +1 -0
- package/dist/adapters/next.d.ts +29 -0
- package/dist/adapters/next.js +22 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/allowance-refusal.d.ts +2 -0
- package/dist/allowance-refusal.js +50 -0
- package/dist/allowance-refusal.js.map +1 -0
- package/dist/app-links.d.ts +42 -0
- package/dist/app-links.js +66 -0
- package/dist/app-links.js.map +1 -0
- package/dist/artifact-catalog.d.ts +40 -0
- package/dist/artifact-client.d.ts +20 -8
- package/dist/artifacts.d.ts +1 -1
- package/dist/artifacts.js +8 -6
- package/dist/automations.js +8 -2
- package/dist/automations.js.map +1 -1
- package/dist/azure-live-transport.d.ts +32 -0
- package/dist/browser.d.ts +7 -2
- package/dist/browser.js +27 -5
- package/dist/chat/fold.d.ts +75 -0
- package/dist/chat/handler.d.ts +41 -0
- package/dist/chat/http.d.ts +67 -0
- package/dist/chat/ids.d.ts +34 -0
- package/dist/chat/index.d.ts +9 -0
- package/dist/chat/index.js +1703 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat/openai.d.ts +30 -0
- package/dist/chat/opengeni.d.ts +129 -0
- package/dist/chat/types.d.ts +207 -0
- package/dist/chat/vercel.d.ts +49 -0
- package/dist/chats.d.ts +8 -0
- package/dist/chunk-4AHR4KGA.js +301 -0
- package/dist/chunk-4AHR4KGA.js.map +1 -0
- package/dist/chunk-6HZGAIUE.js +1665 -0
- package/dist/chunk-6HZGAIUE.js.map +1 -0
- package/dist/chunk-7EWT3PV6.js +368 -0
- package/dist/chunk-7EWT3PV6.js.map +1 -0
- package/dist/{chunk-VYCTL62C.js → chunk-GZQSWAKD.js} +1 -1
- package/dist/chunk-GZQSWAKD.js.map +1 -0
- package/dist/chunk-JXXCTW5W.js +1392 -0
- package/dist/chunk-JXXCTW5W.js.map +1 -0
- package/dist/{chunk-YTAWBDO2.js → chunk-KADZ5PGG.js} +28 -2
- package/dist/chunk-KADZ5PGG.js.map +1 -0
- package/dist/{chunk-YKZME56C.js → chunk-KWADQ227.js} +3 -3
- package/dist/{chunk-YKZME56C.js.map → chunk-KWADQ227.js.map} +1 -1
- package/dist/{chunk-7ZXBPJZP.js → chunk-NEM5N6C6.js} +3902 -1457
- package/dist/chunk-NEM5N6C6.js.map +1 -0
- package/dist/{chunk-GW3EJ2GP.js → chunk-O7KANXC3.js} +86 -13
- package/dist/chunk-O7KANXC3.js.map +1 -0
- package/dist/{chunk-VUQZAB3O.js → chunk-OAKHWFSV.js} +28 -32
- package/dist/chunk-OAKHWFSV.js.map +1 -0
- package/dist/chunk-P7UWKORG.js +561 -0
- package/dist/chunk-P7UWKORG.js.map +1 -0
- package/dist/chunk-QGEIL4TR.js +195 -0
- package/dist/chunk-QGEIL4TR.js.map +1 -0
- package/dist/chunk-RJHCBZF7.js +270 -0
- package/dist/chunk-RJHCBZF7.js.map +1 -0
- package/dist/chunk-S3D75WSQ.js +340 -0
- package/dist/chunk-S3D75WSQ.js.map +1 -0
- package/dist/chunk-UM4ZXXJR.js +9 -0
- package/dist/chunk-UM4ZXXJR.js.map +1 -0
- package/dist/chunk-VPVMLM7Q.js +15 -0
- package/dist/chunk-VPVMLM7Q.js.map +1 -0
- package/dist/{chunk-C2H7HBNP.js → chunk-WVCJRSGJ.js} +119 -14
- package/dist/chunk-WVCJRSGJ.js.map +1 -0
- package/dist/chunk-XA7HVIHI.js +126 -0
- package/dist/chunk-XA7HVIHI.js.map +1 -0
- package/dist/{chunk-TX3EIENU.js → chunk-YDVPI7WT.js} +73 -2
- package/dist/chunk-YDVPI7WT.js.map +1 -0
- package/dist/chunk-YKIHNLWD.js +153 -0
- package/dist/chunk-YKIHNLWD.js.map +1 -0
- package/dist/chunk-ZDUBPV33.js +277 -0
- package/dist/chunk-ZDUBPV33.js.map +1 -0
- package/dist/client.d.ts +1065 -124
- package/dist/codex-realtime-controller.d.ts +13 -0
- package/dist/codex-realtime-controller.js +4 -2
- package/dist/codex-realtime-v3-wire.d.ts +3 -2
- package/dist/codex-realtime.d.ts +5 -1
- package/dist/company-brain.d.ts +1 -11
- package/dist/company-profile.d.ts +13 -0
- package/dist/core.d.ts +7 -2
- package/dist/core.js +25 -6
- package/dist/deprecation.d.ts +47 -0
- package/dist/document-authority-client.d.ts +24 -2
- package/dist/document-authority.js +7 -5
- package/dist/editable-artifacts/index.d.ts +1 -1
- package/dist/editable-artifacts/types.d.ts +12 -2
- package/dist/editable-artifacts.js +19 -3
- package/dist/editable-artifacts.js.map +1 -1
- package/dist/embedding-client.d.ts +129 -0
- package/dist/errors.d.ts +76 -1
- package/dist/feedback.d.ts +23 -0
- package/dist/gateway-realtime-transport.js +1 -1
- package/dist/github-repositories.d.ts +10 -0
- package/dist/github-repositories.js +36 -0
- package/dist/github-repositories.js.map +1 -0
- package/dist/index.d.ts +64 -11
- package/dist/index.js +566 -141
- package/dist/index.js.map +1 -1
- package/dist/insights-usage.d.ts +33 -0
- package/dist/insights-usage.js +7 -0
- package/dist/insights-usage.js.map +1 -0
- package/dist/interaction.d.ts +103 -71
- package/dist/interaction.js +4 -2
- package/dist/knowledge.d.ts +7 -0
- package/dist/knowledge.js +20 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/known-tools.d.ts +4 -0
- package/dist/message-links.d.ts +68 -0
- package/dist/model-context.d.ts +68 -0
- package/dist/model-display.d.ts +2 -0
- package/dist/model-display.js +17 -0
- package/dist/model-display.js.map +1 -0
- package/dist/model-picker-order.d.ts +1 -0
- package/dist/model-picker-order.js +10 -0
- package/dist/model-picker-order.js.map +1 -0
- package/dist/organization-integration-policy.d.ts +26 -0
- package/dist/organization-integration-policy.js +26 -0
- package/dist/organization-integration-policy.js.map +1 -0
- package/dist/pr-review-client.d.ts +1 -1
- package/dist/pr-review.d.ts +1 -1
- package/dist/pr-review.js.map +1 -1
- package/dist/preference-registry.d.ts +1 -1
- package/dist/prepared-mcp-setup.d.ts +5 -0
- package/dist/proxy.d.ts +13 -11
- package/dist/realtime.d.ts +4 -2
- package/dist/realtime.js +253 -7
- package/dist/realtime.js.map +1 -1
- package/dist/session-history-import.d.ts +22 -0
- package/dist/session-history-import.js +36 -0
- package/dist/session-history-import.js.map +1 -0
- package/dist/session-list-entries.d.ts +1 -0
- package/dist/session-list-entries.js +7 -0
- package/dist/session-list-entries.js.map +1 -0
- package/dist/session-message-search.d.ts +53 -0
- package/dist/session-proxy-client.d.ts +28 -0
- package/dist/session-proxy.d.ts +334 -0
- package/dist/session-proxy.js +24 -0
- package/dist/session-proxy.js.map +1 -0
- package/dist/session-titles.d.ts +2 -0
- package/dist/session-usage-limits.d.ts +10 -0
- package/dist/session-usage-limits.js +43 -0
- package/dist/session-usage-limits.js.map +1 -0
- package/dist/shared-catalog-loader.d.ts +34 -0
- package/dist/site-bridge-host.d.ts +112 -0
- package/dist/site-bridge-host.js +285 -0
- package/dist/site-bridge-host.js.map +1 -0
- package/dist/site-browser-entry.d.ts +1 -0
- package/dist/site-browser-runtime.gen.d.ts +1 -0
- package/dist/site-data.d.ts +178 -0
- package/dist/site-document.d.ts +5 -0
- package/dist/site-document.js +20 -0
- package/dist/site-document.js.map +1 -0
- package/dist/site-document.test.d.ts +1 -0
- package/dist/site-http.d.ts +17 -0
- package/dist/site-sql.d.ts +31 -0
- package/dist/site-tool-bridge.d.ts +57 -0
- package/dist/site.d.ts +182 -0
- package/dist/site.js +62 -0
- package/dist/site.js.map +1 -0
- package/dist/skills.d.ts +75 -0
- package/dist/sse.d.ts +1 -1
- package/dist/stream.d.ts +2 -0
- package/dist/tenant-workspaces.d.ts +47 -0
- package/dist/tenant-workspaces.js +8 -0
- package/dist/tenant-workspaces.js.map +1 -0
- package/dist/tool-auth.d.ts +87 -0
- package/dist/tool-auth.js +23 -0
- package/dist/tool-auth.js.map +1 -0
- package/dist/tool-display-metadata.d.ts +3 -0
- package/dist/tools-37DCTCNZ.js +12 -0
- package/dist/tools-37DCTCNZ.js.map +1 -0
- package/dist/tools.d.ts +81 -0
- package/dist/transcription.d.ts +1 -1
- package/dist/types.d.ts +2848 -573
- package/dist/usage-allowances.d.ts +36 -0
- package/dist/usage-allowances.js +80 -0
- package/dist/usage-allowances.js.map +1 -0
- package/dist/vault-types.d.ts +236 -0
- package/dist/vaults-api.d.ts +57 -0
- package/dist/workspace-artifacts.d.ts +47 -5
- package/dist/workspace-instruction-policies.d.ts +2 -2
- package/dist/workspace-integrations.d.ts +74 -0
- package/dist/workspace-integrations.js +65 -0
- package/dist/workspace-integrations.js.map +1 -0
- package/dist/workspace-state.d.ts +8 -71
- package/package.json +99 -5
- package/src/accounts.ts +18 -0
- package/src/adapters/express.ts +136 -0
- package/src/adapters/hono.ts +18 -0
- package/src/adapters/next.ts +42 -0
- package/src/allowance-refusal.ts +5 -0
- package/src/app-links.ts +117 -0
- package/src/artifact-catalog.ts +51 -0
- package/src/artifact-client.ts +40 -49
- package/src/artifacts.ts +1 -0
- package/src/automations-client.ts +8 -2
- package/src/azure-live-transport.ts +286 -0
- package/src/browser.ts +37 -0
- package/src/chat/fold.ts +431 -0
- package/src/chat/handler.ts +240 -0
- package/src/chat/http.ts +257 -0
- package/src/chat/ids.ts +85 -0
- package/src/chat/index.ts +88 -0
- package/src/chat/openai.ts +439 -0
- package/src/chat/opengeni.ts +737 -0
- package/src/chat/types.ts +219 -0
- package/src/chat/vercel.ts +204 -0
- package/src/chats.ts +16 -0
- package/src/client.ts +5822 -1847
- package/src/codex-realtime-controller.ts +163 -8
- package/src/codex-realtime-v3-wire.ts +4 -3
- package/src/codex-realtime-v3.ts +12 -3
- package/src/codex-realtime.ts +11 -3
- package/src/company-brain.ts +0 -40
- package/src/company-profile.ts +13 -0
- package/src/core.ts +20 -0
- package/src/deprecation.ts +149 -0
- package/src/document-authority-client.ts +104 -1
- package/src/editable-artifacts/controller.ts +36 -2
- package/src/editable-artifacts/index.ts +1 -0
- package/src/editable-artifacts/types.ts +29 -16
- package/src/embedding-client.ts +519 -0
- package/src/errors.ts +303 -4
- package/src/feedback.ts +20 -0
- package/src/gateway-realtime-transport.ts +3 -3
- package/src/github-repositories.ts +60 -0
- package/src/index.ts +611 -64
- package/src/insights-usage.ts +61 -0
- package/src/interaction.ts +274 -93
- package/src/knowledge.ts +72 -0
- package/src/known-tools.ts +279 -0
- package/src/message-links.ts +178 -0
- package/src/model-context.ts +113 -0
- package/src/model-display.ts +11 -0
- package/src/model-picker-order.ts +6 -0
- package/src/organization-integration-policy.ts +54 -0
- package/src/pr-review-client.ts +1 -1
- package/src/pr-review.ts +1 -1
- package/src/preference-registry.ts +2 -0
- package/src/prepared-mcp-setup.ts +123 -0
- package/src/proxy.ts +23 -12
- package/src/realtime.ts +16 -6
- package/src/session-history-import.ts +84 -0
- package/src/session-list-entries.ts +1 -0
- package/src/session-message-search.ts +47 -0
- package/src/session-proxy-client.ts +68 -0
- package/src/session-proxy.ts +2098 -0
- package/src/session-titles.ts +10 -0
- package/src/session-usage-limits.ts +71 -0
- package/src/shared-catalog-loader.ts +169 -0
- package/src/site-bridge-host.ts +422 -0
- package/src/site-browser-entry.ts +6 -0
- package/src/site-browser-runtime.gen.ts +2 -0
- package/src/site-data.ts +372 -0
- package/src/site-document.test.ts +64 -0
- package/src/site-document.ts +18 -0
- package/src/site-http.ts +171 -0
- package/src/site-sql.ts +153 -0
- package/src/site-tool-bridge.ts +401 -0
- package/src/site.ts +867 -0
- package/src/skills.ts +69 -0
- package/src/sse.ts +9 -3
- package/src/stream.ts +33 -10
- package/src/tenant-workspaces.ts +148 -0
- package/src/tool-auth.ts +301 -0
- package/src/tool-display-metadata.ts +27 -0
- package/src/tools.ts +452 -0
- package/src/transcription.ts +3 -0
- package/src/types.ts +3216 -581
- package/src/usage-allowances.ts +189 -0
- package/src/vault-types.ts +293 -0
- package/src/vaults-api.ts +288 -0
- package/src/workspace-artifacts.ts +55 -6
- package/src/workspace-instruction-policies.ts +2 -1
- package/src/workspace-integrations.ts +402 -0
- package/src/workspace-state.ts +8 -82
- package/dist/chunk-7ZXBPJZP.js.map +0 -1
- package/dist/chunk-C2H7HBNP.js.map +0 -1
- package/dist/chunk-C4DJPZRU.js +0 -119
- package/dist/chunk-C4DJPZRU.js.map +0 -1
- package/dist/chunk-GW3EJ2GP.js.map +0 -1
- package/dist/chunk-TX3EIENU.js.map +0 -1
- package/dist/chunk-VUQZAB3O.js.map +0 -1
- package/dist/chunk-VYCTL62C.js.map +0 -1
- package/dist/chunk-YTAWBDO2.js.map +0 -1
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Literal Unicode case-insensitive substring. Whitespace is significant. */
|
|
2
|
+
export type SessionMessageSearchRequest = {
|
|
3
|
+
query: string;
|
|
4
|
+
sessionId?: string | undefined;
|
|
5
|
+
/** Workspace-only first hit per session; cannot combine with sessionId. */
|
|
6
|
+
groupBy?: "session" | undefined;
|
|
7
|
+
archiveStatus?: "active" | "archived" | "all" | undefined;
|
|
8
|
+
limit?: number | undefined;
|
|
9
|
+
cursor?: string | undefined;
|
|
10
|
+
};
|
|
11
|
+
export type SessionMessageSearchMatch = {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
sessionTitle: string | null;
|
|
14
|
+
eventId: string;
|
|
15
|
+
sequence: number;
|
|
16
|
+
turnId: string | null;
|
|
17
|
+
role: "user" | "assistant";
|
|
18
|
+
messageId: string | null;
|
|
19
|
+
/** Zero-based UTF-16 offset in the complete visible message. */
|
|
20
|
+
messageMatchOffset: number;
|
|
21
|
+
/** Zero-based UTF-16 offsets in text; matchEnd is exclusive. */
|
|
22
|
+
snippet: {
|
|
23
|
+
text: string;
|
|
24
|
+
matchStart: number;
|
|
25
|
+
matchEnd: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export type SessionMessageSearchResponse = {
|
|
29
|
+
matches: SessionMessageSearchMatch[];
|
|
30
|
+
nextCursor: string | null;
|
|
31
|
+
/** Empty advancing pages are valid. Continue until false. */
|
|
32
|
+
hasMore: boolean;
|
|
33
|
+
/** Cumulative distinct messages visited in this live traversal. */
|
|
34
|
+
scannedMessages: number;
|
|
35
|
+
/** Cumulative matching messages, or session representatives with groupBy=session. */
|
|
36
|
+
matchedMessageCount: number;
|
|
37
|
+
/** Cumulative occurrences, or session representatives with groupBy=session. */
|
|
38
|
+
matchedOccurrenceCount: number;
|
|
39
|
+
/** True only on exhaustion. Concurrent mutations require a fresh traversal. */
|
|
40
|
+
countIsExact: boolean;
|
|
41
|
+
};
|
|
42
|
+
/** Exact selected event reference from a search match; no payload fields are read. */
|
|
43
|
+
export type SessionMessagePreviewReference = {
|
|
44
|
+
eventId: string;
|
|
45
|
+
sequence: number;
|
|
46
|
+
};
|
|
47
|
+
/** A complete visible message, or an explicit over-12,000-UTF-16-unit result. */
|
|
48
|
+
export type SessionMessagePreview = {
|
|
49
|
+
status: "available";
|
|
50
|
+
text: string;
|
|
51
|
+
} | {
|
|
52
|
+
status: "unavailable";
|
|
53
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { OpenGeniEmbeddingClient } from "./embedding-client.js";
|
|
2
|
+
import type { OpenGeniRequestOptions, FetchResponse } from "./client.js";
|
|
3
|
+
import type { AccessGrant } from "./types.js";
|
|
4
|
+
/** Maximum actual UTF-8 bytes forwarded for one embedded Site HTML response. */
|
|
5
|
+
export declare const SESSION_PROXY_SITE_HTML_MAX_BYTES: number;
|
|
6
|
+
/** A streaming Site download exceeded the host proxy's actual-byte ceiling. */
|
|
7
|
+
export declare class SessionProxySiteHtmlTooLargeError extends Error {
|
|
8
|
+
readonly code = "site_html_too_large";
|
|
9
|
+
readonly limitBytes: number;
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
12
|
+
/** Server-only effective grant read; never derive external authority from access/me snapshots. */
|
|
13
|
+
export declare function getSessionProxyWorkspaceGrant(client: Pick<OpenGeniEmbeddingClient, "requestJson">, workspaceId: string, options?: OpenGeniRequestOptions): Promise<AccessGrant>;
|
|
14
|
+
/**
|
|
15
|
+
* Exact association read. The API reauthorizes the source session on every
|
|
16
|
+
* call. `retained` proves a generated image or video, or a published sandbox
|
|
17
|
+
* file, originated in that session.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getSessionProxyArtifactAssociation(client: Pick<OpenGeniEmbeddingClient, "requestJson">, workspaceId: string, sessionId: string, kind: "editable" | "site" | "retained", artifactId: string, options?: OpenGeniRequestOptions): Promise<{
|
|
20
|
+
sessionId: string;
|
|
21
|
+
artifactId: string;
|
|
22
|
+
kind: "editable" | "site" | "retained";
|
|
23
|
+
}>;
|
|
24
|
+
/** Authenticated response stream for the server proxy; does not buffer Site HTML. */
|
|
25
|
+
export declare function downloadSessionProxySiteHtml(client: Pick<OpenGeniEmbeddingClient, "requestJsonResponse">, workspaceId: string, artifactId: string, options: {
|
|
26
|
+
versionId: string;
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}): Promise<FetchResponse>;
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import type { OpenGeniEmbeddingClient } from "./embedding-client.js";
|
|
2
|
+
import { type Chats } from "./chats.js";
|
|
3
|
+
import type { WorkspaceIdOptions, WorkspaceIdTarget } from "./tenant-workspaces.js";
|
|
4
|
+
import type { CreateSessionRequest, FileResourceRef, LatencyMode, ReasoningEffort, SessionMcpCredentialUpdateInput } from "./types.js";
|
|
5
|
+
export { downloadSessionProxySiteHtml, getSessionProxyArtifactAssociation, getSessionProxyWorkspaceGrant, SESSION_PROXY_SITE_HTML_MAX_BYTES, SessionProxySiteHtmlTooLargeError, } from "./session-proxy-client.js";
|
|
6
|
+
/**
|
|
7
|
+
* Packaged same-origin backend for the React conversation surfaces.
|
|
8
|
+
*
|
|
9
|
+
* Mount the handler at a catch-all route (for example `/api/opengeni/*`) and
|
|
10
|
+
* point an unmodified browser `OpenGeniClient({ baseUrl: "/api/opengeni" })`
|
|
11
|
+
* at it. Every request is authenticated by the host's `resolve` hook, pinned
|
|
12
|
+
* to the resolved workspace, executed as the resolved external user through
|
|
13
|
+
* `asUser` (never the organization key's own service authority), and limited
|
|
14
|
+
* to the exact native routes `SessionConversation` and its hooks use. It is
|
|
15
|
+
* an explicit dispatcher, not an arbitrary upstream proxy.
|
|
16
|
+
*/
|
|
17
|
+
type ProxyClient = OpenGeniEmbeddingClient;
|
|
18
|
+
/** The `@opengeni/sdk/chat` `Opengeni` facade, structurally. */
|
|
19
|
+
type ProxyFacade = {
|
|
20
|
+
readonly client: ProxyClient;
|
|
21
|
+
readonly source: string;
|
|
22
|
+
workspaceId(target: {
|
|
23
|
+
tenant: string;
|
|
24
|
+
}): Promise<string>;
|
|
25
|
+
workspaceIdFor?(target: WorkspaceIdTarget, options: WorkspaceIdOptions): Promise<string>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Who the authenticated request acts as, in your own ids. Never derive any of
|
|
29
|
+
* it from the request body or path. `{ user, tenant }`: one workspace per
|
|
30
|
+
* tenant. `{ user }`: one workspace per user. `{ user, workspaceId }`: your
|
|
31
|
+
* own workspace. Tenant and per-user mapping require the `Opengeni` facade
|
|
32
|
+
* from `@opengeni/sdk/chat`; workspaces are created on first use and Opengeni
|
|
33
|
+
* adds the user on their first request.
|
|
34
|
+
*/
|
|
35
|
+
export type SessionProxyResolution = ({
|
|
36
|
+
workspaceId: string;
|
|
37
|
+
tenant?: undefined;
|
|
38
|
+
} | {
|
|
39
|
+
tenant: string;
|
|
40
|
+
workspaceId?: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
tenant?: undefined;
|
|
43
|
+
workspaceId?: undefined;
|
|
44
|
+
}) & {
|
|
45
|
+
/** Host-authenticated external user id; every call runs through `asUser(user)`. */
|
|
46
|
+
user: string;
|
|
47
|
+
/** External identity source. Defaults to the facade's `source`, else `"default"`. */
|
|
48
|
+
source?: string | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The user is an anonymous visitor your product has not signed in, for
|
|
51
|
+
* example a website visitor keyed by a cookie. Visitors cannot upload
|
|
52
|
+
* composer file attachments unless the handler sets `visitorUploads: true`;
|
|
53
|
+
* everything else is unchanged.
|
|
54
|
+
*/
|
|
55
|
+
visitor?: boolean | undefined;
|
|
56
|
+
};
|
|
57
|
+
/** Host auth hook: return the resolution, or a `Response` (for example 401) to reject. */
|
|
58
|
+
export type SessionProxyResolve = (request: Request) => Promise<SessionProxyResolution | Response> | SessionProxyResolution | Response;
|
|
59
|
+
export type SessionProxyContext = {
|
|
60
|
+
request: Request;
|
|
61
|
+
workspaceId: string;
|
|
62
|
+
user: string;
|
|
63
|
+
source: string;
|
|
64
|
+
/** The `asUser` client the proxy uses for this request. */
|
|
65
|
+
client: ProxyClient;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The only fields a browser may send when creating a session through the proxy.
|
|
69
|
+
* After the `createSession` hook returns, the proxy adds the attached files to
|
|
70
|
+
* the created request (deduplicated by file id) and, when `modelSelection` is
|
|
71
|
+
* not `false`, applies the browser's explicit model choices over the hook's,
|
|
72
|
+
* exactly as follow-up messages carry them. Return a `Response` from the hook
|
|
73
|
+
* to refuse an input.
|
|
74
|
+
*/
|
|
75
|
+
export type SessionProxyCreateInput = {
|
|
76
|
+
/** Empty for a voice-first session; no initial user message is fabricated. */
|
|
77
|
+
initialMessage: string;
|
|
78
|
+
/** Available only while the proxy permits realtime voice. */
|
|
79
|
+
startMode?: "realtime" | undefined;
|
|
80
|
+
/** Browser retry key; replay is scoped to the acting user by the API. */
|
|
81
|
+
idempotencyKey?: string | undefined;
|
|
82
|
+
/** Files attached to the first message (uploaded through this proxy). */
|
|
83
|
+
resources?: FileResourceRef[] | undefined;
|
|
84
|
+
/** The user's model choice; only when `modelSelection` is not `false`. */
|
|
85
|
+
model?: string | undefined;
|
|
86
|
+
/** The user's reasoning choice; only when `modelSelection` is not `false`. */
|
|
87
|
+
reasoningEffort?: ReasoningEffort | undefined;
|
|
88
|
+
/** The user's latency choice; only when `modelSelection` is not `false`. */
|
|
89
|
+
latencyMode?: LatencyMode | undefined;
|
|
90
|
+
};
|
|
91
|
+
/** Which browser action is about to forward a user message or response. */
|
|
92
|
+
export type SessionProxyMessageInput = {
|
|
93
|
+
/** Absent for `create`. */
|
|
94
|
+
sessionId?: string | undefined;
|
|
95
|
+
/** An empty voice-first session shell, not an initial model-producing turn. */
|
|
96
|
+
startMode?: "realtime" | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* `realtime` is live voice: once when a call starts (refuse it, or rotate
|
|
99
|
+
* MCP credentials), and before each batch of finalized transcripts and spoken
|
|
100
|
+
* requests is saved (refuse it, or add `modelContext`).
|
|
101
|
+
*/
|
|
102
|
+
delivery: "create" | "send" | "steer" | "submit" | "realtime";
|
|
103
|
+
};
|
|
104
|
+
/** Server-side additions the host attaches to one forwarded user message or response. */
|
|
105
|
+
export type SessionProxyMessageExtras = {
|
|
106
|
+
/**
|
|
107
|
+
* Model-visible context for this message (current page, time zone, today's
|
|
108
|
+
* date). Placed before any context the browser sent. Not secret. Ignored for
|
|
109
|
+
* approval decisions and human-input responses, which are not new messages,
|
|
110
|
+
* and when a live voice call starts. Keep it stable for the same message:
|
|
111
|
+
* a retried voice entry must carry the same context to be accepted.
|
|
112
|
+
*/
|
|
113
|
+
modelContext?: string | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Header-only credential rotation for MCP servers already attached to the
|
|
116
|
+
* session (for example a fresh short-lived per-user bearer), applied
|
|
117
|
+
* atomically as the message or response is accepted. Ignored for `create`,
|
|
118
|
+
* where the `createSession` hook sets the initial headers.
|
|
119
|
+
*/
|
|
120
|
+
mcpCredentialUpdates?: SessionMcpCredentialUpdateInput[] | undefined;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Your product's own MCP tool server, attached to every session this proxy
|
|
124
|
+
* creates with a per-user bearer token. Verify it on every MCP request with
|
|
125
|
+
* `verifyToolRequest` from `@opengeni/sdk/tool-auth`. Tools always act as the
|
|
126
|
+
* chat's creator: in a shared chat, other members' messages do not change it.
|
|
127
|
+
*/
|
|
128
|
+
export type SessionProxyToolServer = {
|
|
129
|
+
/**
|
|
130
|
+
* Public HTTPS URL of your MCP endpoint, e.g. `https://app.example.com/api/mcp`.
|
|
131
|
+
* Defaults to `OPENGENI_TOOL_SERVER_URL`, which `verifyToolRequest` also reads.
|
|
132
|
+
*/
|
|
133
|
+
url?: string | undefined;
|
|
134
|
+
/** Session MCP server id (model-facing tool prefix). Defaults to `"app"`. */
|
|
135
|
+
id?: string | undefined;
|
|
136
|
+
/** Display name. */
|
|
137
|
+
name?: string | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Tools the user must approve before each call: list your write tools here
|
|
140
|
+
* (unprefixed MCP tool names), or `true` for every tool. Others run directly.
|
|
141
|
+
*/
|
|
142
|
+
approvals?: {
|
|
143
|
+
ask: string[] | true;
|
|
144
|
+
} | undefined;
|
|
145
|
+
/** Token signing secret. Defaults to `OPENGENI_API_KEY`; `verifyToolRequest` must use the same. */
|
|
146
|
+
secret?: string | undefined;
|
|
147
|
+
/** Token lifetime in seconds. Defaults to 24 hours; refreshed on every message, approval, and answer. */
|
|
148
|
+
ttlSeconds?: number | undefined;
|
|
149
|
+
};
|
|
150
|
+
export type SessionProxyHandlerOptions = {
|
|
151
|
+
/**
|
|
152
|
+
* Private (default) uses personal Knowledge and session-only reach; shared uses
|
|
153
|
+
* workspace Knowledge and reach. Isolated also gives each user their own tenant workspace.
|
|
154
|
+
*/
|
|
155
|
+
chats?: Chats | undefined;
|
|
156
|
+
/** Mandatory host auth hook, called on every request. */
|
|
157
|
+
resolve: SessionProxyResolve;
|
|
158
|
+
/**
|
|
159
|
+
* Host CSRF/session policy for non-GET requests. Without it the proxy only
|
|
160
|
+
* rejects `Sec-Fetch-Site: cross-site` mutations and requires JSON bodies;
|
|
161
|
+
* cookie-authenticated hosts should supply their existing CSRF check.
|
|
162
|
+
*/
|
|
163
|
+
authorizeMutation?: ((request: Request) => boolean | Promise<boolean>) | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Optional product-level session check (for example "this ticket's session
|
|
166
|
+
* belongs to this user"). Opengeni still enforces membership and private
|
|
167
|
+
* visibility on every call.
|
|
168
|
+
*/
|
|
169
|
+
authorizeSession?: ((sessionId: string, context: SessionProxyContext) => boolean | Promise<boolean>) | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Server-controlled session creation. The browser supplies only
|
|
172
|
+
* {@link SessionProxyCreateInput}; this hook returns the complete create
|
|
173
|
+
* request (agent, tools, MCP servers, Skills, instructions, model policy). Omit it
|
|
174
|
+
* to disable browser-initiated creation entirely.
|
|
175
|
+
*/
|
|
176
|
+
createSession?: ((input: SessionProxyCreateInput, context: SessionProxyContext) => CreateSessionRequest | Response | Promise<CreateSessionRequest | Response>) | undefined;
|
|
177
|
+
/**
|
|
178
|
+
* Called before every forwarded user message (send, steer, composer submit,
|
|
179
|
+
* and browser-started create), approval decision, human-input response, and
|
|
180
|
+
* live voice start and transcript save (`delivery: "realtime"`).
|
|
181
|
+
* Return server-owned `modelContext` (messages and voice transcripts only)
|
|
182
|
+
* and MCP credential rotations, or a `Response` to reject the action.
|
|
183
|
+
*/
|
|
184
|
+
beforeForwardMessage?: ((input: SessionProxyMessageInput, context: SessionProxyContext) => SessionProxyMessageExtras | Response | undefined | Promise<SessionProxyMessageExtras | Response | undefined>) | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* Attach your product's MCP tool server to every session the `createSession`
|
|
187
|
+
* hook creates, authenticated as the resolved user. The proxy mints the
|
|
188
|
+
* token, adds the `mcpServers` entry (plus an eager ref when the hook lists
|
|
189
|
+
* explicit `tools`), and rotates the token on every send, steer, submit,
|
|
190
|
+
* approval decision, and human-input answer.
|
|
191
|
+
*/
|
|
192
|
+
toolServer?: SessionProxyToolServer | undefined;
|
|
193
|
+
/** Mount prefix, e.g. `/api/opengeni`. Defaults to everything before the first `/v1/`. */
|
|
194
|
+
basePath?: string | undefined;
|
|
195
|
+
/** Maximum JSON request body. Defaults to 1 MiB. */
|
|
196
|
+
maxBodyBytes?: number | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Expose composer file attachments (upload begin/complete, download URL) and
|
|
199
|
+
* the media agents produce in a session: generated images, browser and
|
|
200
|
+
* computer screenshots, published sandbox files, and generated video
|
|
201
|
+
* playback. Workspace-level artifact reads must name their session in the
|
|
202
|
+
* `x-opengeni-session-id` header (`SessionConversation` does this); the proxy
|
|
203
|
+
* runs `authorizeSession` and only forwards an artifact Opengeni proves that
|
|
204
|
+
* session produced. Defaults to true.
|
|
205
|
+
*/
|
|
206
|
+
files?: boolean | undefined;
|
|
207
|
+
/**
|
|
208
|
+
* Let anonymous visitors (`resolve` returned `visitor: true`) upload composer
|
|
209
|
+
* file attachments. Defaults to false: for a visitor the client config reports
|
|
210
|
+
* file uploads off, so stock UIs hide the attach button, and the upload routes
|
|
211
|
+
* are refused. Agent-produced media stays readable under `files`. Signed-in
|
|
212
|
+
* users follow `files` alone.
|
|
213
|
+
*/
|
|
214
|
+
visitorUploads?: boolean | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Forward composer voice input (`POST .../transcriptions`, one recording per
|
|
217
|
+
* request) as the resolved user; Opengeni still requires that user's
|
|
218
|
+
* `sessions:create` permission and the workspace's voice-input setting.
|
|
219
|
+
* `false` reports voice input unavailable in the client config so stock UIs
|
|
220
|
+
* hide the microphone. Defaults to true.
|
|
221
|
+
*/
|
|
222
|
+
voiceInput?: boolean | undefined;
|
|
223
|
+
/**
|
|
224
|
+
* Forward live speech-to-speech voice for existing chats as the resolved
|
|
225
|
+
* user: the voice model catalog and the call lifecycle routes under
|
|
226
|
+
* `.../sessions/{id}/realtime`. Opengeni still requires that user's
|
|
227
|
+
* `sessions:control` permission, binds the call to that user and browser,
|
|
228
|
+
* runs spoken requests as ordinary steers of the chat, and meters
|
|
229
|
+
* deployment-funded voice against the organization's credits. Defaults to
|
|
230
|
+
* true. The stock conversation's voice button is opt-in: explicit `true`
|
|
231
|
+
* reports `realtimeVoice: true` in the client config so `SessionConversation`
|
|
232
|
+
* and `OpenGeniChat` show it (when a voice model is available), as does their
|
|
233
|
+
* own `realtimeVoice` prop. `false` reports `realtimeVoice: false` so stock
|
|
234
|
+
* UIs hide it, and refuses the routes.
|
|
235
|
+
*/
|
|
236
|
+
realtimeVoice?: boolean | undefined;
|
|
237
|
+
/**
|
|
238
|
+
* Let the browser read a file from the session's sandbox (`POST .../fs/read`)
|
|
239
|
+
* so `sandbox:` links in agent replies can be downloaded. Only `path`,
|
|
240
|
+
* `encoding`, and `maxBytes` are forwarded; Opengeni still requires the
|
|
241
|
+
* user's `files:read` permission on that session. Explicit opt-in, default
|
|
242
|
+
* false. Reads are confined to its working directory, including on Connected
|
|
243
|
+
* Machines; symlinked paths are refused.
|
|
244
|
+
*/
|
|
245
|
+
sandboxFiles?: boolean | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Serve the embedded artifact viewer and inline Site previews: reads of the
|
|
248
|
+
* editable artifacts and Sites a session produced, and live-ticket minting
|
|
249
|
+
* for the editor. Explicit opt-in, default false.
|
|
250
|
+
*
|
|
251
|
+
* Every request must name its session in the `x-opengeni-session-id` header
|
|
252
|
+
* (`SessionArtifactViewer` and `SessionConversation` do this). The proxy
|
|
253
|
+
* runs `authorizeSession`, then only forwards an artifact Opengeni associates with
|
|
254
|
+
* that session, so the browser cannot open other workspace artifacts through
|
|
255
|
+
* it. Editing still requires the user's own `artifacts:publish` grant. Site
|
|
256
|
+
* tool calls are not proxied.
|
|
257
|
+
*
|
|
258
|
+
* The editor's live socket is ticket-authenticated and connects to Opengeni
|
|
259
|
+
* directly; the ticket binds the source session and the API revalidates its
|
|
260
|
+
* authority while connected. `editableLiveUrl` overrides the derived URL.
|
|
261
|
+
* Site HTML streams with backpressure and cancellation, with a 25 MiB
|
|
262
|
+
* actual-byte ceiling (`SESSION_PROXY_SITE_HTML_MAX_BYTES`). Oversize streams
|
|
263
|
+
* fail with `SessionProxySiteHtmlTooLargeError` / `site_html_too_large`;
|
|
264
|
+
* headers cannot be replaced once streaming has begun.
|
|
265
|
+
*/
|
|
266
|
+
artifacts?: boolean | {
|
|
267
|
+
editableLiveUrl?: string | undefined;
|
|
268
|
+
} | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Read the workspace's Sites without naming a session: list, detail,
|
|
271
|
+
* content and HTML of published artifacts the signed-in user may read, for
|
|
272
|
+
* pages that belong to the workspace rather than to one chat (for example a
|
|
273
|
+
* page several sessions keep up to date, shown with `SiteDetail`). Read-only:
|
|
274
|
+
* publishing, rollback and status changes stay closed. Requests that send
|
|
275
|
+
* `x-opengeni-session-id` keep the session-scoped `artifacts` checks.
|
|
276
|
+
* Explicit opt-in, default false.
|
|
277
|
+
*/
|
|
278
|
+
sites?: boolean | undefined;
|
|
279
|
+
/**
|
|
280
|
+
* Chat list for `SessionList` / `OpenGeniChat` (`listSessionPage` only).
|
|
281
|
+
* `"mine"` (default) lists sessions the resolved user created; `"visible"`
|
|
282
|
+
* lists every session Opengeni lets that user read in the workspace (shared
|
|
283
|
+
* chats included); `false` disables listing.
|
|
284
|
+
*/
|
|
285
|
+
sessionList?: "mine" | "visible" | false | undefined;
|
|
286
|
+
/** Let the user archive or restore their own chats. Defaults to true. */
|
|
287
|
+
archive?: boolean | undefined;
|
|
288
|
+
/**
|
|
289
|
+
* Let the browser choose model, reasoning effort, and latency per message,
|
|
290
|
+
* draft, or new chat (still limited by the workspace model catalog). When
|
|
291
|
+
* false those choices are removed from messages and draft saves, and refused
|
|
292
|
+
* on create. Saves use the actor's
|
|
293
|
+
* server-owned draft policy (initially the session defaults). Submit must repeat
|
|
294
|
+
* the saved policy unchanged as an integrity fence, not a new selection: the
|
|
295
|
+
* API atomically checks the saved revision/content or replays the original
|
|
296
|
+
* receipt. Hide the composer's model picker to match. Defaults to true.
|
|
297
|
+
* Pass `true` explicitly to also show end users the stock model picker
|
|
298
|
+
* (`SessionConversation`/`OpenGeniChat` hide it unless asked). The picker
|
|
299
|
+
* lists the workspace's model catalog, so the workspace's allowed-model
|
|
300
|
+
* settings decide which models end users see.
|
|
301
|
+
*/
|
|
302
|
+
modelSelection?: boolean | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* SSE heartbeat interval. Defaults to 5 seconds, under Bun.serve's default
|
|
305
|
+
* 10-second `idleTimeout`, which otherwise closes a quiet event stream.
|
|
306
|
+
*/
|
|
307
|
+
heartbeatMs?: number | undefined;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* Create the packaged session proxy. Returns a web-standard
|
|
311
|
+
* `(Request) => Promise<Response>` for Next.js route handlers, Hono, Bun.serve,
|
|
312
|
+
* Cloudflare Workers, and similar hosts.
|
|
313
|
+
*/
|
|
314
|
+
export declare function createSessionProxyHandler(target: ProxyClient | ProxyFacade, options: SessionProxyHandlerOptions): (request: Request) => Promise<Response>;
|
|
315
|
+
/**
|
|
316
|
+
* The client-config `artifacts` capability a custom host proxy reports so
|
|
317
|
+
* `SessionArtifactViewer` can open editable artifacts: the live socket URL
|
|
318
|
+
* (ticket-authenticated, reached directly) and the proxied user's browser cache
|
|
319
|
+
* partition. `client` acts as that user (for example `asUser(...)`).
|
|
320
|
+
*/
|
|
321
|
+
export declare function artifactViewerCapability(input: {
|
|
322
|
+
client: Pick<ProxyClient, "getAccessContext" | "apiUrl"> & Partial<Pick<ProxyClient, "requestJson">>;
|
|
323
|
+
workspaceId: string;
|
|
324
|
+
/** Stable namespace of the host's user identities, mixed into the partition. */
|
|
325
|
+
source?: string | undefined;
|
|
326
|
+
editableLiveUrl?: string | undefined;
|
|
327
|
+
}): Promise<{
|
|
328
|
+
editableLiveUrl: string;
|
|
329
|
+
cachePartition: {
|
|
330
|
+
accountId: string;
|
|
331
|
+
principalId: string;
|
|
332
|
+
authorizationEpoch: string;
|
|
333
|
+
};
|
|
334
|
+
}>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SESSION_PROXY_SITE_HTML_MAX_BYTES,
|
|
3
|
+
SessionProxySiteHtmlTooLargeError,
|
|
4
|
+
artifactViewerCapability,
|
|
5
|
+
createSessionProxyHandler,
|
|
6
|
+
downloadSessionProxySiteHtml,
|
|
7
|
+
getSessionProxyArtifactAssociation,
|
|
8
|
+
getSessionProxyWorkspaceGrant
|
|
9
|
+
} from "./chunk-6HZGAIUE.js";
|
|
10
|
+
import "./chunk-UM4ZXXJR.js";
|
|
11
|
+
import "./chunk-QGEIL4TR.js";
|
|
12
|
+
import "./chunk-4AHR4KGA.js";
|
|
13
|
+
import "./chunk-KADZ5PGG.js";
|
|
14
|
+
import "./chunk-7EWT3PV6.js";
|
|
15
|
+
export {
|
|
16
|
+
SESSION_PROXY_SITE_HTML_MAX_BYTES,
|
|
17
|
+
SessionProxySiteHtmlTooLargeError,
|
|
18
|
+
artifactViewerCapability,
|
|
19
|
+
createSessionProxyHandler,
|
|
20
|
+
downloadSessionProxySiteHtml,
|
|
21
|
+
getSessionProxyArtifactAssociation,
|
|
22
|
+
getSessionProxyWorkspaceGrant
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=session-proxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { AUTOMATIC_SESSION_TITLE_FALLBACK, deriveAutomaticSessionTitlePreview, deriveSessionDisplayTitle, sessionTitleIsPending, } from "@opengeni/contracts/session-titles";
|
|
2
|
+
export type { SessionDisplayTitleInput, SessionDisplayTitleOptions, } from "@opengeni/contracts/session-titles";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { OpenGeniClient, OpenGeniRequestOptions } from "./client.js";
|
|
2
|
+
import type { SessionUsageLimit, SetSessionUsageLimitRequest } from "@opengeni/contracts/session-usage-limits";
|
|
3
|
+
export type { SessionUsageLimit, SessionUsageLimitHistory, SessionUsageLimitReachedRefusal, SessionUsageLimitStatus, SetSessionUsageLimitRequest, } from "@opengeni/contracts/session-usage-limits";
|
|
4
|
+
export { formatSessionUsageMicros, parseSessionUsageLimitReachedRefusal, SESSION_USAGE_LIMIT_GOAL_PAUSED_REASON, SESSION_USAGE_LIMIT_SEGMENT, sessionUsageLimitReachedMessage, } from "@opengeni/contracts/session-usage-limit-refusal";
|
|
5
|
+
export type { ParsedSessionUsageLimitReachedRefusal } from "@opengeni/contracts/session-usage-limit-refusal";
|
|
6
|
+
type RequestJsonClient = Pick<OpenGeniClient, "requestJson">;
|
|
7
|
+
/** Read a task's usage limit state (a child returns its root's, `inherited: true`). */
|
|
8
|
+
export declare function getSessionUsageLimit(client: RequestJsonClient, workspaceId: string, sessionId: string, options?: OpenGeniRequestOptions): Promise<SessionUsageLimit>;
|
|
9
|
+
/** Compare-and-set a root task's limit; `limitMicros: null` clears it. Never resumes work. */
|
|
10
|
+
export declare function setSessionUsageLimit(client: RequestJsonClient, workspaceId: string, sessionId: string, request: SetSessionUsageLimitRequest): Promise<SessionUsageLimit>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SESSION_USAGE_LIMIT_GOAL_PAUSED_REASON,
|
|
3
|
+
SESSION_USAGE_LIMIT_SEGMENT,
|
|
4
|
+
formatSessionUsageMicros,
|
|
5
|
+
parseSessionUsageLimitReachedRefusal,
|
|
6
|
+
sessionUsageLimitNotConfirmed,
|
|
7
|
+
sessionUsageLimitReachedMessage
|
|
8
|
+
} from "./chunk-7EWT3PV6.js";
|
|
9
|
+
|
|
10
|
+
// src/session-usage-limits.ts
|
|
11
|
+
function usageLimitPath(workspaceId, sessionId) {
|
|
12
|
+
return `/v1/workspaces/${encodeURIComponent(workspaceId)}/sessions/${encodeURIComponent(sessionId)}/usage-limit`;
|
|
13
|
+
}
|
|
14
|
+
async function getSessionUsageLimit(client, workspaceId, sessionId, options = {}) {
|
|
15
|
+
return await client.requestJson(
|
|
16
|
+
"GET",
|
|
17
|
+
usageLimitPath(workspaceId, sessionId),
|
|
18
|
+
void 0,
|
|
19
|
+
{},
|
|
20
|
+
options
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
async function setSessionUsageLimit(client, workspaceId, sessionId, request) {
|
|
24
|
+
const committed = await client.requestJson(
|
|
25
|
+
"PUT",
|
|
26
|
+
usageLimitPath(workspaceId, sessionId),
|
|
27
|
+
request
|
|
28
|
+
);
|
|
29
|
+
if (committed.limitMicros !== request.limitMicros) {
|
|
30
|
+
throw sessionUsageLimitNotConfirmed(sessionId);
|
|
31
|
+
}
|
|
32
|
+
return committed;
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
SESSION_USAGE_LIMIT_GOAL_PAUSED_REASON,
|
|
36
|
+
SESSION_USAGE_LIMIT_SEGMENT,
|
|
37
|
+
formatSessionUsageMicros,
|
|
38
|
+
getSessionUsageLimit,
|
|
39
|
+
parseSessionUsageLimitReachedRefusal,
|
|
40
|
+
sessionUsageLimitReachedMessage,
|
|
41
|
+
setSessionUsageLimit
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=session-usage-limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/session-usage-limits.ts"],"sourcesContent":["// @opengeni/sdk/session-usage-limits — per-task usage limit helpers that are\n// safe in browsers and React Native. Reads and writes use the root client's\n// `getSessionUsageLimit` / `setSessionUsageLimit`, or these free functions over\n// any client's `requestJson`.\n//\n// Amounts are integer USD micros of API-equivalent model usage (the\n// pre-margin provider list-price estimate), not your bill. The limit is\n// checked before each new model request: requests already running can take\n// recorded usage above it. See docs/session-usage-limits.md.\nimport type { OpenGeniClient, OpenGeniRequestOptions } from \"./client\";\nimport { sessionUsageLimitNotConfirmed } from \"./errors\";\nimport type {\n SessionUsageLimit,\n SetSessionUsageLimitRequest,\n} from \"@opengeni/contracts/session-usage-limits\";\n\nexport type {\n SessionUsageLimit,\n SessionUsageLimitHistory,\n SessionUsageLimitReachedRefusal,\n SessionUsageLimitStatus,\n SetSessionUsageLimitRequest,\n} from \"@opengeni/contracts/session-usage-limits\";\nexport {\n formatSessionUsageMicros,\n parseSessionUsageLimitReachedRefusal,\n SESSION_USAGE_LIMIT_GOAL_PAUSED_REASON,\n SESSION_USAGE_LIMIT_SEGMENT,\n sessionUsageLimitReachedMessage,\n} from \"@opengeni/contracts/session-usage-limit-refusal\";\nexport type { ParsedSessionUsageLimitReachedRefusal } from \"@opengeni/contracts/session-usage-limit-refusal\";\n\ntype RequestJsonClient = Pick<OpenGeniClient, \"requestJson\">;\n\nfunction usageLimitPath(workspaceId: string, sessionId: string): string {\n return `/v1/workspaces/${encodeURIComponent(workspaceId)}/sessions/${encodeURIComponent(sessionId)}/usage-limit`;\n}\n\n/** Read a task's usage limit state (a child returns its root's, `inherited: true`). */\nexport async function getSessionUsageLimit(\n client: RequestJsonClient,\n workspaceId: string,\n sessionId: string,\n options: OpenGeniRequestOptions = {},\n): Promise<SessionUsageLimit> {\n return await client.requestJson<SessionUsageLimit>(\n \"GET\",\n usageLimitPath(workspaceId, sessionId),\n undefined,\n {},\n options,\n );\n}\n\n/** Compare-and-set a root task's limit; `limitMicros: null` clears it. Never resumes work. */\nexport async function setSessionUsageLimit(\n client: RequestJsonClient,\n workspaceId: string,\n sessionId: string,\n request: SetSessionUsageLimitRequest,\n): Promise<SessionUsageLimit> {\n const committed = await client.requestJson<SessionUsageLimit>(\n \"PUT\",\n usageLimitPath(workspaceId, sessionId),\n request,\n );\n if (committed.limitMicros !== request.limitMicros) {\n throw sessionUsageLimitNotConfirmed(sessionId);\n }\n return committed;\n}\n"],"mappings":";;;;;;;;;;AAkCA,SAAS,eAAe,aAAqB,WAA2B;AACtE,SAAO,kBAAkB,mBAAmB,WAAW,CAAC,aAAa,mBAAmB,SAAS,CAAC;AACpG;AAGA,eAAsB,qBACpB,QACA,aACA,WACA,UAAkC,CAAC,GACP;AAC5B,SAAO,MAAM,OAAO;AAAA,IAClB;AAAA,IACA,eAAe,aAAa,SAAS;AAAA,IACrC;AAAA,IACA,CAAC;AAAA,IACD;AAAA,EACF;AACF;AAGA,eAAsB,qBACpB,QACA,aACA,WACA,SAC4B;AAC5B,QAAM,YAAY,MAAM,OAAO;AAAA,IAC7B;AAAA,IACA,eAAe,aAAa,SAAS;AAAA,IACrC;AAAA,EACF;AACA,MAAI,UAAU,gBAAgB,QAAQ,aAAa;AACjD,UAAM,8BAA8B,SAAS;AAAA,EAC/C;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single-flight loader for one digest-pinned tool catalog.
|
|
3
|
+
*
|
|
4
|
+
* - Concurrent cold callers share one request instead of each fetching.
|
|
5
|
+
* - A waiter's AbortSignal cancels only its own wait. The shared request is
|
|
6
|
+
* cancelled once every waiter has aborted, and the next caller then starts
|
|
7
|
+
* a new request. A waiter without a signal keeps the shared request alive
|
|
8
|
+
* for every joiner until it settles (bounded by transport/server timeouts).
|
|
9
|
+
* - A failed load is never cached; the next caller starts a new request.
|
|
10
|
+
* - An explicit refresh, or a stale rejection, always obtains a catalog from a
|
|
11
|
+
* request started after that refresh/rejection. Callers rejected on the same
|
|
12
|
+
* stale digest share one post-rejection request while it is still current.
|
|
13
|
+
* - A load started before an invalidation never overwrites the newer state.
|
|
14
|
+
*/
|
|
15
|
+
export type SharedCatalogLoader<T extends {
|
|
16
|
+
digest: string;
|
|
17
|
+
}> = {
|
|
18
|
+
load(options?: {
|
|
19
|
+
refresh?: boolean;
|
|
20
|
+
signal?: AbortSignal;
|
|
21
|
+
}): Promise<T>;
|
|
22
|
+
/** Reload after the server rejected `staleDigest` as a stale catalog. */
|
|
23
|
+
reloadAfterStale(staleDigest: string, signal?: AbortSignal): Promise<T>;
|
|
24
|
+
/** Drop the cached catalog when it is `digest`, without fetching. */
|
|
25
|
+
invalidate(digest: string): void;
|
|
26
|
+
};
|
|
27
|
+
export declare function createSharedCatalogLoader<T extends {
|
|
28
|
+
digest: string;
|
|
29
|
+
}>(
|
|
30
|
+
/**
|
|
31
|
+
* `refresh` is true when this load follows an invalidation or explicit
|
|
32
|
+
* refresh. `signal` aborts only when every waiter has abandoned the load.
|
|
33
|
+
*/
|
|
34
|
+
fetchCatalog: (refresh: boolean, signal: AbortSignal) => Promise<T>): SharedCatalogLoader<T>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-free host side of the Site MessagePort bridge. The console's
|
|
3
|
+
* `PublishedHtmlArtifactFrame` and the published-Site gateway shell both run
|
|
4
|
+
* this code; each injects its own tool transport, Site HTTP handler, viewer
|
|
5
|
+
* provider and sign-in action.
|
|
6
|
+
*
|
|
7
|
+
* Protocol (v2): the host posts a ready message with a bootstrap port to the
|
|
8
|
+
* frame window once per document load; each SDK client connects through that
|
|
9
|
+
* port with its own MessagePort. Requests are tracked per port so a cancel or
|
|
10
|
+
* a document teardown aborts exactly the requests it owns. A second load of
|
|
11
|
+
* the same frame (a navigation inside the Site) revokes the bridge instead of
|
|
12
|
+
* handing a fresh port to an unknown document.
|
|
13
|
+
*/
|
|
14
|
+
import type { SiteViewer } from "@opengeni/contracts";
|
|
15
|
+
import { type OpenGeniSiteBridgeReadyMessage, type OpenGeniSiteBridgeRequestMessage, type OpenGeniSiteSignInResult, type OpenGeniSiteToolCatalog } from "./site.js";
|
|
16
|
+
import { type SiteHttpRequest } from "./site-http.js";
|
|
17
|
+
import type { ToolGatewayCallRequest, ToolGatewayCallResponse, ToolGatewayDeclarationsResponse, ToolGatewayInvokeRequest, ToolGatewayInvokeResponse, ToolGatewayResolveRequest, ToolGatewayResolvedTool } from "./types.js";
|
|
18
|
+
export type { SiteHttpRequest } from "./site-http.js";
|
|
19
|
+
/** Tool and Site HTTP handlers a host supplies. Credentials stay inside these functions. */
|
|
20
|
+
export type SiteBridgeToolHandlers = {
|
|
21
|
+
resolve?: (request: ToolGatewayResolveRequest, options: {
|
|
22
|
+
signal: AbortSignal;
|
|
23
|
+
}) => Promise<ToolGatewayResolvedTool>;
|
|
24
|
+
invoke?: (request: ToolGatewayInvokeRequest, options: {
|
|
25
|
+
signal: AbortSignal;
|
|
26
|
+
}) => Promise<ToolGatewayInvokeResponse>;
|
|
27
|
+
/** Serves the ordinary SDK's HTTP requests (sessions, Site Data) over the Site HTTP channel. */
|
|
28
|
+
fetch?: (request: SiteHttpRequest, signal: AbortSignal) => Promise<Response>;
|
|
29
|
+
/**
|
|
30
|
+
* Advertise Site Data and Site SQL: `fetch` serves `published-artifacts/current`
|
|
31
|
+
* routes (data, files and `sql/queries/<name>`) for the pinned Site.
|
|
32
|
+
*/
|
|
33
|
+
siteData?: boolean;
|
|
34
|
+
catalog: (options: {
|
|
35
|
+
signal: AbortSignal;
|
|
36
|
+
}) => Promise<OpenGeniSiteToolCatalog>;
|
|
37
|
+
call: (request: ToolGatewayCallRequest, options: {
|
|
38
|
+
signal: AbortSignal;
|
|
39
|
+
}) => Promise<ToolGatewayCallResponse>;
|
|
40
|
+
declarations?: (options: {
|
|
41
|
+
signal: AbortSignal;
|
|
42
|
+
}) => Promise<ToolGatewayDeclarationsResponse>;
|
|
43
|
+
};
|
|
44
|
+
/** Viewer identity and sign-in, answered by the host itself (advertised as `viewer: 1`). */
|
|
45
|
+
export type SiteBridgeViewerHandlers = {
|
|
46
|
+
viewer: (options: {
|
|
47
|
+
signal: AbortSignal;
|
|
48
|
+
}) => Promise<SiteViewer> | SiteViewer;
|
|
49
|
+
/** Defaults to `{ started: false }`: the viewer is already signed in or the host has no sign-in. */
|
|
50
|
+
signIn?: (options: {
|
|
51
|
+
signal: AbortSignal;
|
|
52
|
+
}) => Promise<OpenGeniSiteSignInResult> | OpenGeniSiteSignInResult;
|
|
53
|
+
};
|
|
54
|
+
export type SiteBridgeRequestValue = OpenGeniSiteToolCatalog | ToolGatewayCallResponse | ToolGatewayDeclarationsResponse | ToolGatewayResolvedTool | ToolGatewayInvokeResponse | SiteViewer | OpenGeniSiteSignInResult;
|
|
55
|
+
/** Capabilities the host advertises when a Site connects; Sites never ask for more. */
|
|
56
|
+
export declare function siteBridgeReadyMessage(bridge: SiteBridgeToolHandlers | undefined, viewer?: SiteBridgeViewerHandlers): OpenGeniSiteBridgeReadyMessage;
|
|
57
|
+
/**
|
|
58
|
+
* The inline script a host puts at the top of Site HTML. It accepts exactly
|
|
59
|
+
* one ready message with one port from the parent window and keeps that port
|
|
60
|
+
* on a window global so SDK clients created later can still connect.
|
|
61
|
+
*/
|
|
62
|
+
export declare const SITE_BRIDGE_BOOTSTRAP_SCRIPT: string;
|
|
63
|
+
/** Insert the bootstrap script right after a leading doctype (or at the start). */
|
|
64
|
+
export declare function injectSiteBridgeBootstrap(html: string): string;
|
|
65
|
+
export type SiteBridgeHostSource = {
|
|
66
|
+
/** Read on every request, so a host can swap handlers without reconnecting the Site. */
|
|
67
|
+
tools: () => SiteBridgeToolHandlers | undefined;
|
|
68
|
+
viewer?: () => SiteBridgeViewerHandlers | undefined;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* One frame's bridge host. Call `load(frame.contentWindow)` from the frame's
|
|
72
|
+
* load event and `close()` when the frame goes away.
|
|
73
|
+
*/
|
|
74
|
+
export declare class SiteBridgeHost {
|
|
75
|
+
private readonly source;
|
|
76
|
+
private readonly requests;
|
|
77
|
+
private readonly lease;
|
|
78
|
+
constructor(source: SiteBridgeHostSource, options?: {
|
|
79
|
+
createMessageChannel?: () => MessageChannel;
|
|
80
|
+
});
|
|
81
|
+
/** Offer the bootstrap port to a freshly loaded document. Returns false (and revokes) on reload. */
|
|
82
|
+
load(frameWindow: Pick<Window, "postMessage">): boolean;
|
|
83
|
+
close(): void;
|
|
84
|
+
private attachToolPort;
|
|
85
|
+
}
|
|
86
|
+
export declare class SiteBridgeRequestRegistry {
|
|
87
|
+
private readonly controllersByPort;
|
|
88
|
+
addPort(port: MessagePort): void;
|
|
89
|
+
start(port: MessagePort, requestId: string): AbortController | null;
|
|
90
|
+
cancel(port: MessagePort, requestId: string): void;
|
|
91
|
+
complete(port: MessagePort, requestId: string, controller: AbortController): void;
|
|
92
|
+
closePort(port: MessagePort): void;
|
|
93
|
+
closeAll(): void;
|
|
94
|
+
}
|
|
95
|
+
export declare class SiteBridgeDocumentLease {
|
|
96
|
+
private readonly attachToolPort;
|
|
97
|
+
private readonly closeActivePorts;
|
|
98
|
+
private readonly createMessageChannel;
|
|
99
|
+
private loaded;
|
|
100
|
+
private bootstrapPort;
|
|
101
|
+
constructor(attachToolPort: (data: unknown, ports: readonly MessagePort[]) => void, closeActivePorts: () => void, createMessageChannel?: () => MessageChannel);
|
|
102
|
+
load(frameWindow: Pick<Window, "postMessage">): boolean;
|
|
103
|
+
close(): void;
|
|
104
|
+
}
|
|
105
|
+
export declare function openGeniSiteBridgePortFromBootstrap(data: unknown, ports: readonly MessagePort[]): MessagePort | null;
|
|
106
|
+
export declare function handleSiteBridgeRequest(bridge: SiteBridgeToolHandlers | undefined, message: OpenGeniSiteBridgeRequestMessage, signal: AbortSignal, viewer?: SiteBridgeViewerHandlers): Promise<SiteBridgeRequestValue>;
|
|
107
|
+
export declare function siteBridgeError(error: unknown, legacyCall?: boolean): {
|
|
108
|
+
code: string;
|
|
109
|
+
message: string;
|
|
110
|
+
retryable: boolean;
|
|
111
|
+
outcomeUnknown: boolean;
|
|
112
|
+
};
|