@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,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPENGENI_DELIVERY_ID_HEADER,
|
|
3
|
+
OPENGENI_EVENT_ID_HEADER,
|
|
4
|
+
OPENGENI_SIGNATURE_HEADER,
|
|
5
|
+
OPENGENI_TEST_REQUEST_NIL_ID,
|
|
6
|
+
OPENGENI_WEBHOOK_HEADERS,
|
|
7
|
+
OPENGENI_WEBHOOK_TEST_EVENT_TYPE,
|
|
8
|
+
OpenGeniSignatureError,
|
|
9
|
+
WORKSPACE_WEBHOOK_EVENT_TYPES,
|
|
10
|
+
createOrganizationWebhook,
|
|
11
|
+
deleteOrganizationCredentialProvider,
|
|
12
|
+
deleteOrganizationWebhook,
|
|
13
|
+
getOrganizationCredentialProvider,
|
|
14
|
+
getOrganizationWebhook,
|
|
15
|
+
getWorkspaceInheritedIntegrations,
|
|
16
|
+
getWorkspaceWebhook,
|
|
17
|
+
listOrganizationWebhookDeliveries,
|
|
18
|
+
listOrganizationWebhooks,
|
|
19
|
+
putOrganizationCredentialProvider,
|
|
20
|
+
redeliverOrganizationWebhookDelivery,
|
|
21
|
+
rotateOrganizationCredentialProviderSecret,
|
|
22
|
+
rotateOrganizationWebhookSecret,
|
|
23
|
+
rotateWorkspaceCredentialProviderSecret,
|
|
24
|
+
rotateWorkspaceWebhookSecret,
|
|
25
|
+
signOpenGeniPayload,
|
|
26
|
+
testWorkspaceCredentialProvider,
|
|
27
|
+
testWorkspaceWebhook,
|
|
28
|
+
updateOrganizationWebhook,
|
|
29
|
+
verifyCredentialProviderRequest,
|
|
30
|
+
verifyOpenGeniSignature,
|
|
31
|
+
verifyWebhookEvent
|
|
32
|
+
} from "./chunk-RJHCBZF7.js";
|
|
33
|
+
export {
|
|
34
|
+
OPENGENI_DELIVERY_ID_HEADER,
|
|
35
|
+
OPENGENI_EVENT_ID_HEADER,
|
|
36
|
+
OPENGENI_SIGNATURE_HEADER,
|
|
37
|
+
OPENGENI_TEST_REQUEST_NIL_ID,
|
|
38
|
+
OPENGENI_WEBHOOK_HEADERS,
|
|
39
|
+
OPENGENI_WEBHOOK_TEST_EVENT_TYPE,
|
|
40
|
+
OpenGeniSignatureError,
|
|
41
|
+
WORKSPACE_WEBHOOK_EVENT_TYPES,
|
|
42
|
+
createOrganizationWebhook,
|
|
43
|
+
deleteOrganizationCredentialProvider,
|
|
44
|
+
deleteOrganizationWebhook,
|
|
45
|
+
getOrganizationCredentialProvider,
|
|
46
|
+
getOrganizationWebhook,
|
|
47
|
+
getWorkspaceInheritedIntegrations,
|
|
48
|
+
getWorkspaceWebhook,
|
|
49
|
+
listOrganizationWebhookDeliveries,
|
|
50
|
+
listOrganizationWebhooks,
|
|
51
|
+
putOrganizationCredentialProvider,
|
|
52
|
+
redeliverOrganizationWebhookDelivery,
|
|
53
|
+
rotateOrganizationCredentialProviderSecret,
|
|
54
|
+
rotateOrganizationWebhookSecret,
|
|
55
|
+
rotateWorkspaceCredentialProviderSecret,
|
|
56
|
+
rotateWorkspaceWebhookSecret,
|
|
57
|
+
signOpenGeniPayload,
|
|
58
|
+
testWorkspaceCredentialProvider,
|
|
59
|
+
testWorkspaceWebhook,
|
|
60
|
+
updateOrganizationWebhook,
|
|
61
|
+
verifyCredentialProviderRequest,
|
|
62
|
+
verifyOpenGeniSignature,
|
|
63
|
+
verifyWebhookEvent
|
|
64
|
+
};
|
|
65
|
+
//# sourceMappingURL=workspace-integrations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,41 +1,4 @@
|
|
|
1
1
|
import type { WorkspaceInstructionPolicyKind, WorkspaceInstructionPolicyProvenanceSource, WorkspaceInstructionPolicyScope } from "./workspace-instruction-policies.js";
|
|
2
|
-
export type WorkspaceStateDocumentStatusCounts = {
|
|
3
|
-
queued: number;
|
|
4
|
-
indexing: number;
|
|
5
|
-
ready: number;
|
|
6
|
-
failed: number;
|
|
7
|
-
};
|
|
8
|
-
export type WorkspaceStateSourceKindCounts = {
|
|
9
|
-
manual_upload: number;
|
|
10
|
-
meeting_transcript: number;
|
|
11
|
-
repository: number;
|
|
12
|
-
email: number;
|
|
13
|
-
chat: number;
|
|
14
|
-
document: number;
|
|
15
|
-
web: number;
|
|
16
|
-
other: number;
|
|
17
|
-
};
|
|
18
|
-
export type WorkspaceStateDocumentAuthorityKindCounts = {
|
|
19
|
-
organization: number;
|
|
20
|
-
workspace: number;
|
|
21
|
-
personal: number;
|
|
22
|
-
};
|
|
23
|
-
export type WorkspaceStateMemoryStatusCounts = {
|
|
24
|
-
proposed: number;
|
|
25
|
-
approved: number;
|
|
26
|
-
rejected: number;
|
|
27
|
-
active: number;
|
|
28
|
-
superseded: number;
|
|
29
|
-
archived: number;
|
|
30
|
-
};
|
|
31
|
-
export type WorkspaceStateMemoryKindCounts = {
|
|
32
|
-
semantic: number;
|
|
33
|
-
episodic: number;
|
|
34
|
-
procedural: number;
|
|
35
|
-
decision: number;
|
|
36
|
-
preference: number;
|
|
37
|
-
};
|
|
38
|
-
export type WorkspaceStateGapCode = "no_document_bases" | "no_visible_documents" | "failed_documents" | "processing_documents" | "missing_topic_coverage" | "no_memory_records" | "pending_memory_review" | "partial_inventory";
|
|
39
2
|
export type WorkspaceStateGovernanceDriftStatus = "identical" | "changed" | "superseded" | "missing" | "unavailable" | "truncated";
|
|
40
3
|
export type WorkspaceStateGetOptions = {
|
|
41
4
|
attemptId?: string;
|
|
@@ -164,42 +127,16 @@ export type WorkspaceStateResponse = {
|
|
|
164
127
|
requiredPermission: "documents:search";
|
|
165
128
|
} | {
|
|
166
129
|
availability: "available";
|
|
130
|
+
authority: "knowledge_entries";
|
|
167
131
|
coverage: "complete" | "partial";
|
|
168
|
-
|
|
169
|
-
|
|
132
|
+
sampleLimit: 50;
|
|
133
|
+
entries: Array<{
|
|
170
134
|
id: string;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
basesTruncated: boolean;
|
|
177
|
-
inspectedVisibleDocumentCount: number;
|
|
178
|
-
documentStatusCounts: WorkspaceStateDocumentStatusCounts;
|
|
179
|
-
sourceKindCounts: WorkspaceStateSourceKindCounts;
|
|
180
|
-
authorityKindCounts: WorkspaceStateDocumentAuthorityKindCounts;
|
|
181
|
-
topics: Array<{
|
|
182
|
-
name: string;
|
|
183
|
-
documentCount: number;
|
|
184
|
-
}>;
|
|
185
|
-
topicsTruncated: boolean;
|
|
186
|
-
latestDocumentUpdatedAt: string | null;
|
|
187
|
-
memorySample: {
|
|
188
|
-
recordCount: number;
|
|
189
|
-
sampleLimit: 100;
|
|
190
|
-
limitReached: boolean;
|
|
191
|
-
statusCounts: WorkspaceStateMemoryStatusCounts;
|
|
192
|
-
kindCounts: WorkspaceStateMemoryKindCounts;
|
|
193
|
-
preferenceAuthority: {
|
|
194
|
-
kindCountSource: "knowledge_memories_legacy_observations";
|
|
195
|
-
activeAuthority: "structured_preference_registry";
|
|
196
|
-
};
|
|
197
|
-
latestUpdatedAt: string | null;
|
|
198
|
-
};
|
|
199
|
-
gaps: Array<{
|
|
200
|
-
code: WorkspaceStateGapCode;
|
|
201
|
-
severity: "info" | "warning";
|
|
202
|
-
relatedCount: number | null;
|
|
135
|
+
revisionId: string;
|
|
136
|
+
title: string;
|
|
137
|
+
kind: "source" | "fact" | "decision" | "requirement" | "incident" | "note" | "group";
|
|
138
|
+
scope: "organization" | "workspace" | "personal";
|
|
139
|
+
updatedAt: string;
|
|
203
140
|
}>;
|
|
204
141
|
};
|
|
205
142
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/sdk",
|
|
3
|
-
"version": "3.1.
|
|
4
|
-
"description": "Framework-agnostic TypeScript SDK for the
|
|
3
|
+
"version": "3.1.2",
|
|
4
|
+
"description": "Framework-agnostic TypeScript SDK for the Opengeni API: typed client, session lifecycle, SSE event streaming with reconnect + replay-by-sequence, and proxy re-streaming helpers.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
"module": "./dist/index.js",
|
|
23
23
|
"types": "./dist/index.d.ts",
|
|
24
24
|
"exports": {
|
|
25
|
+
"./allowance-refusal": {
|
|
26
|
+
"types": "./dist/allowance-refusal.d.ts",
|
|
27
|
+
"import": "./dist/allowance-refusal.js"
|
|
28
|
+
},
|
|
29
|
+
"./app-links": {
|
|
30
|
+
"types": "./dist/app-links.d.ts",
|
|
31
|
+
"import": "./dist/app-links.js"
|
|
32
|
+
},
|
|
25
33
|
".": {
|
|
26
34
|
"types": "./dist/index.d.ts",
|
|
27
35
|
"import": "./dist/index.js"
|
|
@@ -34,6 +42,46 @@
|
|
|
34
42
|
"types": "./dist/browser.d.ts",
|
|
35
43
|
"import": "./dist/browser.js"
|
|
36
44
|
},
|
|
45
|
+
"./site-document": {
|
|
46
|
+
"types": "./dist/site-document.d.ts",
|
|
47
|
+
"import": "./dist/site-document.js"
|
|
48
|
+
},
|
|
49
|
+
"./site": {
|
|
50
|
+
"types": "./dist/site.d.ts",
|
|
51
|
+
"import": "./dist/site.js"
|
|
52
|
+
},
|
|
53
|
+
"./site-bridge-host": {
|
|
54
|
+
"types": "./dist/site-bridge-host.d.ts",
|
|
55
|
+
"import": "./dist/site-bridge-host.js"
|
|
56
|
+
},
|
|
57
|
+
"./github-repositories": {
|
|
58
|
+
"types": "./dist/github-repositories.d.ts",
|
|
59
|
+
"import": "./dist/github-repositories.js"
|
|
60
|
+
},
|
|
61
|
+
"./knowledge": {
|
|
62
|
+
"types": "./dist/knowledge.d.ts",
|
|
63
|
+
"import": "./dist/knowledge.js"
|
|
64
|
+
},
|
|
65
|
+
"./usage-allowances": {
|
|
66
|
+
"types": "./dist/usage-allowances.d.ts",
|
|
67
|
+
"import": "./dist/usage-allowances.js"
|
|
68
|
+
},
|
|
69
|
+
"./session-usage-limits": {
|
|
70
|
+
"types": "./dist/session-usage-limits.d.ts",
|
|
71
|
+
"import": "./dist/session-usage-limits.js"
|
|
72
|
+
},
|
|
73
|
+
"./insights-usage": {
|
|
74
|
+
"types": "./dist/insights-usage.d.ts",
|
|
75
|
+
"import": "./dist/insights-usage.js"
|
|
76
|
+
},
|
|
77
|
+
"./workspace-integrations": {
|
|
78
|
+
"types": "./dist/workspace-integrations.d.ts",
|
|
79
|
+
"import": "./dist/workspace-integrations.js"
|
|
80
|
+
},
|
|
81
|
+
"./session-history-import": {
|
|
82
|
+
"types": "./dist/session-history-import.d.ts",
|
|
83
|
+
"import": "./dist/session-history-import.js"
|
|
84
|
+
},
|
|
37
85
|
"./document-authority": {
|
|
38
86
|
"types": "./dist/document-authority.d.ts",
|
|
39
87
|
"import": "./dist/document-authority.js"
|
|
@@ -58,6 +106,10 @@
|
|
|
58
106
|
"types": "./dist/pr-review.d.ts",
|
|
59
107
|
"import": "./dist/pr-review.js"
|
|
60
108
|
},
|
|
109
|
+
"./organization-integration-policy": {
|
|
110
|
+
"types": "./dist/organization-integration-policy.d.ts",
|
|
111
|
+
"import": "./dist/organization-integration-policy.js"
|
|
112
|
+
},
|
|
61
113
|
"./organization-private-session-settings": {
|
|
62
114
|
"types": "./dist/organization-private-session-settings.d.ts",
|
|
63
115
|
"import": "./dist/organization-private-session-settings.js"
|
|
@@ -89,7 +141,48 @@
|
|
|
89
141
|
"./gateway-realtime-transport": {
|
|
90
142
|
"types": "./dist/gateway-realtime-transport.d.ts",
|
|
91
143
|
"import": "./dist/gateway-realtime-transport.js"
|
|
92
|
-
}
|
|
144
|
+
},
|
|
145
|
+
"./model-picker-order": {
|
|
146
|
+
"types": "./dist/model-picker-order.d.ts",
|
|
147
|
+
"import": "./dist/model-picker-order.js"
|
|
148
|
+
},
|
|
149
|
+
"./model-display": {
|
|
150
|
+
"types": "./dist/model-display.d.ts",
|
|
151
|
+
"import": "./dist/model-display.js"
|
|
152
|
+
},
|
|
153
|
+
"./chat": {
|
|
154
|
+
"types": "./dist/chat/index.d.ts",
|
|
155
|
+
"import": "./dist/chat/index.js"
|
|
156
|
+
},
|
|
157
|
+
"./tenant-workspaces": {
|
|
158
|
+
"types": "./dist/tenant-workspaces.d.ts",
|
|
159
|
+
"import": "./dist/tenant-workspaces.js"
|
|
160
|
+
},
|
|
161
|
+
"./session-proxy": {
|
|
162
|
+
"types": "./dist/session-proxy.d.ts",
|
|
163
|
+
"import": "./dist/session-proxy.js"
|
|
164
|
+
},
|
|
165
|
+
"./tool-auth": {
|
|
166
|
+
"types": "./dist/tool-auth.d.ts",
|
|
167
|
+
"import": "./dist/tool-auth.js"
|
|
168
|
+
},
|
|
169
|
+
"./next": {
|
|
170
|
+
"types": "./dist/adapters/next.d.ts",
|
|
171
|
+
"import": "./dist/adapters/next.js"
|
|
172
|
+
},
|
|
173
|
+
"./express": {
|
|
174
|
+
"types": "./dist/adapters/express.d.ts",
|
|
175
|
+
"import": "./dist/adapters/express.js"
|
|
176
|
+
},
|
|
177
|
+
"./hono": {
|
|
178
|
+
"types": "./dist/adapters/hono.d.ts",
|
|
179
|
+
"import": "./dist/adapters/hono.js"
|
|
180
|
+
},
|
|
181
|
+
"./session-list-entries": {
|
|
182
|
+
"types": "./dist/session-list-entries.d.ts",
|
|
183
|
+
"import": "./dist/session-list-entries.js"
|
|
184
|
+
},
|
|
185
|
+
"./package.json": "./package.json"
|
|
93
186
|
},
|
|
94
187
|
"publishConfig": {
|
|
95
188
|
"access": "public",
|
|
@@ -97,11 +190,12 @@
|
|
|
97
190
|
},
|
|
98
191
|
"scripts": {
|
|
99
192
|
"typecheck": "tsc --noEmit",
|
|
100
|
-
"build": "bun ../../scripts/build-typescript-package.ts",
|
|
193
|
+
"build": "bun ../../scripts/generate-site-browser-runtime.ts && bun ../../scripts/build-typescript-package.ts",
|
|
101
194
|
"prepublishOnly": "bash ../../scripts/prepublish-guard"
|
|
102
195
|
},
|
|
103
196
|
"dependencies": {
|
|
104
|
-
"@opengeni/
|
|
197
|
+
"@opengeni/connect": "3.1.2",
|
|
198
|
+
"@opengeni/contracts": "3.1.2"
|
|
105
199
|
},
|
|
106
200
|
"engines": {
|
|
107
201
|
"node": ">=18"
|
package/src/accounts.ts
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
ManagedAuthSessionSetErrorCode,
|
|
16
16
|
ResolveManagedAuthDeepLinkRequest,
|
|
17
17
|
SelectManagedAuthLoginSlotRequest,
|
|
18
|
+
StartManagedAuthSocialTransactionRequest,
|
|
19
|
+
StartManagedAuthSocialTransactionResponse,
|
|
18
20
|
type BeginManagedAuthLoginTransactionRequest as BeginManagedAuthLoginTransactionRequestType,
|
|
19
21
|
type BootstrapManagedAuthSessionSetRequest as BootstrapManagedAuthSessionSetRequestType,
|
|
20
22
|
type CancelManagedAuthLoginTransactionRequest as CancelManagedAuthLoginTransactionRequestType,
|
|
@@ -28,6 +30,8 @@ import {
|
|
|
28
30
|
type ManagedAuthSessionSetProjection as ManagedAuthSessionSetProjectionType,
|
|
29
31
|
type ResolveManagedAuthDeepLinkRequest as ResolveManagedAuthDeepLinkRequestType,
|
|
30
32
|
type SelectManagedAuthLoginSlotRequest as SelectManagedAuthLoginSlotRequestType,
|
|
33
|
+
type StartManagedAuthSocialTransactionRequest as StartManagedAuthSocialTransactionRequestType,
|
|
34
|
+
type StartManagedAuthSocialTransactionResponse as StartManagedAuthSocialTransactionResponseType,
|
|
31
35
|
} from "@opengeni/contracts/managed-auth-session-sets";
|
|
32
36
|
import type { z } from "zod";
|
|
33
37
|
|
|
@@ -53,6 +57,9 @@ export interface BrowserAccountsClientLike {
|
|
|
53
57
|
completeEmailPasswordTransaction(
|
|
54
58
|
request: CompleteManagedAuthEmailPasswordTransactionRequestType,
|
|
55
59
|
): Promise<CompleteManagedAuthLoginTransactionResponseType>;
|
|
60
|
+
startSocialTransaction?(
|
|
61
|
+
request: StartManagedAuthSocialTransactionRequestType,
|
|
62
|
+
): Promise<StartManagedAuthSocialTransactionResponseType>;
|
|
56
63
|
cancelLoginTransaction(
|
|
57
64
|
request: CancelManagedAuthLoginTransactionRequestType,
|
|
58
65
|
): Promise<ManagedAuthSessionSetProjectionType>;
|
|
@@ -178,6 +185,17 @@ export class BrowserAccountsClient implements BrowserAccountsClientLike {
|
|
|
178
185
|
return response;
|
|
179
186
|
}
|
|
180
187
|
|
|
188
|
+
async startSocialTransaction(request: StartManagedAuthSocialTransactionRequestType) {
|
|
189
|
+
return StartManagedAuthSocialTransactionResponse.parse(
|
|
190
|
+
await this.#mutation(
|
|
191
|
+
"POST",
|
|
192
|
+
"/v1/auth/session-set/transactions/social",
|
|
193
|
+
StartManagedAuthSocialTransactionRequest,
|
|
194
|
+
request,
|
|
195
|
+
),
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
181
199
|
async cancelLoginTransaction(request: CancelManagedAuthLoginTransactionRequestType) {
|
|
182
200
|
return this.#projectionResponse(
|
|
183
201
|
"DELETE",
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
|
|
4
|
+
/** Any web-standard handler: `createSessionProxyHandler`, `createChatHandler`, or your own. */
|
|
5
|
+
export type WebHandler = (request: Request) => Promise<Response>;
|
|
6
|
+
|
|
7
|
+
/** Express/Connect request: Node's `IncomingMessage` plus what those frameworks add. */
|
|
8
|
+
export type NodeRequestLike = IncomingMessage & {
|
|
9
|
+
originalUrl?: string | undefined;
|
|
10
|
+
/** Set when a body parser (for example `express.json()`) already consumed the body. */
|
|
11
|
+
body?: unknown;
|
|
12
|
+
protocol?: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type NodeMiddleware = (
|
|
16
|
+
request: NodeRequestLike,
|
|
17
|
+
response: ServerResponse,
|
|
18
|
+
next?: (error?: unknown) => void,
|
|
19
|
+
) => void;
|
|
20
|
+
|
|
21
|
+
export type NodeMiddlewareOptions = {
|
|
22
|
+
/** Origin used to build the request URL. Defaults to the Host header over http(s). */
|
|
23
|
+
origin?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Expose a web-standard handler as Express/Connect (or plain `node:http`)
|
|
28
|
+
* middleware. Mount it with the same path the browser client uses:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* app.use("/api/opengeni", toNodeMiddleware(handler));
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* The full original URL is forwarded (Express strips the mount path from
|
|
35
|
+
* `req.url`), bodies stream through unless a body parser already consumed
|
|
36
|
+
* them, responses (including SSE) are written as they arrive, and a client
|
|
37
|
+
* disconnect aborts the request signal.
|
|
38
|
+
*/
|
|
39
|
+
export function toNodeMiddleware(
|
|
40
|
+
handler: WebHandler,
|
|
41
|
+
options: NodeMiddlewareOptions = {},
|
|
42
|
+
): NodeMiddleware {
|
|
43
|
+
return (request, response, next) => {
|
|
44
|
+
void (async () => {
|
|
45
|
+
const abort = new AbortController();
|
|
46
|
+
response.once("close", () => {
|
|
47
|
+
if (!response.writableFinished) abort.abort();
|
|
48
|
+
});
|
|
49
|
+
const web = await handler(toWebRequest(request, abort.signal, options));
|
|
50
|
+
await writeWebResponse(web, response);
|
|
51
|
+
})().catch((error: unknown) => {
|
|
52
|
+
if (next) next(error);
|
|
53
|
+
else if (!response.headersSent) {
|
|
54
|
+
response.statusCode = 500;
|
|
55
|
+
response.end();
|
|
56
|
+
} else response.destroy(error instanceof Error ? error : undefined);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Express/Connect naming alias. */
|
|
62
|
+
export const toExpressMiddleware = toNodeMiddleware;
|
|
63
|
+
|
|
64
|
+
function toWebRequest(
|
|
65
|
+
request: NodeRequestLike,
|
|
66
|
+
signal: AbortSignal,
|
|
67
|
+
options: NodeMiddlewareOptions,
|
|
68
|
+
): Request {
|
|
69
|
+
const encrypted = (request.socket as { encrypted?: boolean } | undefined)?.encrypted === true;
|
|
70
|
+
const origin =
|
|
71
|
+
options.origin?.replace(/\/+$/, "") ??
|
|
72
|
+
`${request.protocol ?? (encrypted ? "https" : "http")}://${request.headers.host ?? "localhost"}`;
|
|
73
|
+
const url = new URL(request.originalUrl ?? request.url ?? "/", origin);
|
|
74
|
+
const headers = new Headers();
|
|
75
|
+
for (const [name, value] of Object.entries(request.headers)) {
|
|
76
|
+
if (value === undefined) continue;
|
|
77
|
+
if (Array.isArray(value)) for (const item of value) headers.append(name, item);
|
|
78
|
+
else headers.set(name, value);
|
|
79
|
+
}
|
|
80
|
+
const method = request.method ?? "GET";
|
|
81
|
+
let body: BodyInit | undefined;
|
|
82
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
83
|
+
if (request.body !== undefined && (request.readableEnded || request.complete)) {
|
|
84
|
+
// A body parser consumed the stream: forward what it parsed.
|
|
85
|
+
body =
|
|
86
|
+
typeof request.body === "string" || request.body instanceof Uint8Array
|
|
87
|
+
? (request.body as string | Uint8Array<ArrayBuffer>)
|
|
88
|
+
: JSON.stringify(request.body);
|
|
89
|
+
headers.delete("content-length");
|
|
90
|
+
} else {
|
|
91
|
+
body = Readable.toWeb(request) as unknown as ReadableStream<Uint8Array>;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return new Request(url, {
|
|
95
|
+
method,
|
|
96
|
+
headers,
|
|
97
|
+
signal,
|
|
98
|
+
...(body !== undefined ? { body, duplex: "half" } : {}),
|
|
99
|
+
} as RequestInit);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function writeWebResponse(web: Response, response: ServerResponse): Promise<void> {
|
|
103
|
+
response.statusCode = web.status;
|
|
104
|
+
const cookies = web.headers.getSetCookie?.() ?? [];
|
|
105
|
+
web.headers.forEach((value, name) => {
|
|
106
|
+
if (name.toLowerCase() !== "set-cookie") response.setHeader(name, value);
|
|
107
|
+
});
|
|
108
|
+
if (cookies.length > 0) response.setHeader("set-cookie", cookies);
|
|
109
|
+
if (!web.body) {
|
|
110
|
+
response.end();
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
// Send headers now so SSE clients see the stream open before the first event.
|
|
114
|
+
response.flushHeaders();
|
|
115
|
+
const reader = web.body.getReader();
|
|
116
|
+
response.once("close", () => {
|
|
117
|
+
void reader.cancel().catch(() => undefined);
|
|
118
|
+
});
|
|
119
|
+
for (;;) {
|
|
120
|
+
const { done, value } = await reader.read();
|
|
121
|
+
if (done) break;
|
|
122
|
+
if (!response.write(value)) {
|
|
123
|
+
await new Promise<void>((resolve) => {
|
|
124
|
+
const settle = () => {
|
|
125
|
+
response.off("drain", settle);
|
|
126
|
+
response.off("close", settle);
|
|
127
|
+
resolve();
|
|
128
|
+
};
|
|
129
|
+
response.once("drain", settle);
|
|
130
|
+
response.once("close", settle);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (response.destroyed) break;
|
|
134
|
+
}
|
|
135
|
+
response.end();
|
|
136
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Any web-standard handler: `createSessionProxyHandler`, `createChatHandler`, or your own. */
|
|
2
|
+
export type WebHandler = (request: Request) => Promise<Response>;
|
|
3
|
+
|
|
4
|
+
/** The part of Hono's context this adapter uses (no Hono dependency). */
|
|
5
|
+
export type HonoContextLike = { req: { raw: Request } };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Expose a web-standard handler as a Hono handler:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* app.all("/api/opengeni/*", toHonoHandler(handler));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export function toHonoHandler(
|
|
15
|
+
handler: WebHandler,
|
|
16
|
+
): (context: HonoContextLike) => Promise<Response> {
|
|
17
|
+
return async (context) => await handler(context.req.raw);
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createSessionProxyHandler, type SessionProxyHandlerOptions } from "../session-proxy";
|
|
2
|
+
|
|
3
|
+
/** Any web-standard handler: `createSessionProxyHandler`, `createChatHandler`, or your own. */
|
|
4
|
+
export type WebHandler = (request: Request) => Promise<Response>;
|
|
5
|
+
|
|
6
|
+
/** Route handlers for a Next.js App Router catch-all route. */
|
|
7
|
+
export type NextRouteHandlers = {
|
|
8
|
+
GET: WebHandler;
|
|
9
|
+
POST: WebHandler;
|
|
10
|
+
PUT: WebHandler;
|
|
11
|
+
PATCH: WebHandler;
|
|
12
|
+
DELETE: WebHandler;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Expose a web-standard handler as Next.js App Router route handlers.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* // app/api/opengeni/[...path]/route.ts
|
|
20
|
+
* export const dynamic = "force-dynamic";
|
|
21
|
+
* export const { GET, POST, PUT, PATCH, DELETE } = toNextRouteHandlers(handler);
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Next passes the full request URL (including any `basePath`), so the proxy's
|
|
25
|
+
* own `/v1/` detection routes it; responses, including SSE, stream as-is.
|
|
26
|
+
*/
|
|
27
|
+
export function toNextRouteHandlers(handler: WebHandler): NextRouteHandlers {
|
|
28
|
+
// Next calls route handlers with (request, context); only the request matters.
|
|
29
|
+
const route: WebHandler = async (request) => await handler(request);
|
|
30
|
+
return { GET: route, POST: route, PUT: route, PATCH: route, DELETE: route };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* `createSessionProxyHandler` as Next.js App Router route handlers, for
|
|
35
|
+
* `app/<mount>/[...path]/route.ts`.
|
|
36
|
+
*/
|
|
37
|
+
export function createSessionProxyRoute(
|
|
38
|
+
target: Parameters<typeof createSessionProxyHandler>[0],
|
|
39
|
+
options: SessionProxyHandlerOptions,
|
|
40
|
+
): NextRouteHandlers {
|
|
41
|
+
return toNextRouteHandlers(createSessionProxyHandler(target, options));
|
|
42
|
+
}
|
package/src/app-links.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Opengeni web links that a native app (phone or desktop) can show itself, and
|
|
2
|
+
// the account each belongs to. Pure: no platform modules, so every app shares it.
|
|
3
|
+
|
|
4
|
+
/** A deployment address as typed: trimmed, https by default, no trailing slash. */
|
|
5
|
+
export function normalizeServerUrl(input: string): string | null {
|
|
6
|
+
const raw = input.trim();
|
|
7
|
+
if (!raw) return null;
|
|
8
|
+
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//iu.test(raw) ? raw : `https://${raw}`;
|
|
9
|
+
const match = /^(https?):\/\/([a-z0-9.-]+(?::\d{1,5})?)(?:[/?#].*)?$/iu.exec(withScheme);
|
|
10
|
+
return match ? `${match[1]!.toLowerCase()}://${match[2]!.toLowerCase()}` : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The host a person recognizes, e.g. app.opengeni.ai. */
|
|
14
|
+
export function serverLabel(baseUrl: string): string {
|
|
15
|
+
return baseUrl.replace(/^https?:\/\//iu, "");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** The part of a signed-in app account that link routing reads. */
|
|
19
|
+
export interface AppLinkAccount {
|
|
20
|
+
id: string;
|
|
21
|
+
/** The deployment's web origin, e.g. https://app.opengeni.ai. */
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
/** The workspace last used with this account. */
|
|
24
|
+
workspaceId: string | null;
|
|
25
|
+
/** Set when the deployment rejected the credential. */
|
|
26
|
+
signedOut?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A web link the app can show itself: a conversation or a workspace on some
|
|
31
|
+
* deployment. Everything else on the web (settings, organization, artifacts)
|
|
32
|
+
* stays in the browser.
|
|
33
|
+
*/
|
|
34
|
+
export interface AppLink {
|
|
35
|
+
/** The deployment's origin, normalized like a stored account's baseUrl. */
|
|
36
|
+
origin: string;
|
|
37
|
+
/** Absent for the web's workspace-less `/sessions/:id` links. */
|
|
38
|
+
workspaceId: string | null;
|
|
39
|
+
/** Absent for a link to the workspace itself. */
|
|
40
|
+
sessionId: string | null;
|
|
41
|
+
/** The session moment the link points at (`?at=`). */
|
|
42
|
+
at: number | null;
|
|
43
|
+
/** The web address the link came from, for the browser fallback. */
|
|
44
|
+
webUrl: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The app's own scheme for links handed over from the web: opengeni://open?url=… */
|
|
48
|
+
const HANDOFF = /^opengeni:\/\/open\/?\?(.*)$/iu;
|
|
49
|
+
const WEB_URL = /^(https?:\/\/[^/?#]+)(\/[^?#]*)?(\?[^#]*)?(#.*)?$/iu;
|
|
50
|
+
const ID = "([A-Za-z0-9][A-Za-z0-9_-]{0,127})";
|
|
51
|
+
const SESSION_PATH = new RegExp(`^/workspaces/${ID}/sessions/${ID}/?$`, "u");
|
|
52
|
+
const WORKSPACE_PATH = new RegExp(`^/workspaces/${ID}(?:/sessions)?/?$`, "u");
|
|
53
|
+
const BARE_SESSION_PATH = new RegExp(`^/sessions/${ID}/?$`, "u");
|
|
54
|
+
|
|
55
|
+
function queryParam(query: string | undefined, name: string): string | null {
|
|
56
|
+
for (const part of (query ?? "").replace(/^\?/u, "").split("&")) {
|
|
57
|
+
const [key, value = ""] = part.split("=");
|
|
58
|
+
if (key !== name) continue;
|
|
59
|
+
try {
|
|
60
|
+
return decodeURIComponent(value.replace(/\+/gu, " "));
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The web link a raw URL points at, unwrapping the web's "Open in app" handoff. */
|
|
69
|
+
export function parseAppLink(raw: string): AppLink | null {
|
|
70
|
+
const trimmed = raw.trim();
|
|
71
|
+
const handoff = HANDOFF.exec(trimmed);
|
|
72
|
+
const webUrl = handoff ? queryParam(handoff[1], "url") : trimmed;
|
|
73
|
+
if (!webUrl) return null;
|
|
74
|
+
const match = WEB_URL.exec(webUrl);
|
|
75
|
+
if (!match) return null;
|
|
76
|
+
const origin = normalizeServerUrl(match[1]!);
|
|
77
|
+
if (!origin) return null;
|
|
78
|
+
const path = match[2] ?? "/";
|
|
79
|
+
const atRaw = queryParam(match[3], "at");
|
|
80
|
+
const at = atRaw && /^[1-9][0-9]{0,15}$/u.test(atRaw) ? Number(atRaw) : null;
|
|
81
|
+
const session = SESSION_PATH.exec(path);
|
|
82
|
+
if (session) return { origin, workspaceId: session[1]!, sessionId: session[2]!, at, webUrl };
|
|
83
|
+
const bare = BARE_SESSION_PATH.exec(path);
|
|
84
|
+
if (bare) return { origin, workspaceId: null, sessionId: bare[1]!, at, webUrl };
|
|
85
|
+
const workspace = WORKSPACE_PATH.exec(path);
|
|
86
|
+
if (workspace) return { origin, workspaceId: workspace[1]!, sessionId: null, at: null, webUrl };
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The signed-in account a link belongs to, or null when the app has none on
|
|
92
|
+
* that deployment (the browser opens it instead). With several accounts on the
|
|
93
|
+
* same deployment: the one last used in the link's workspace, else the active
|
|
94
|
+
* one, else the first.
|
|
95
|
+
*/
|
|
96
|
+
export function accountForAppLink<Account extends AppLinkAccount>(
|
|
97
|
+
link: AppLink,
|
|
98
|
+
accounts: readonly Account[],
|
|
99
|
+
activeId: string | null,
|
|
100
|
+
): Account | null {
|
|
101
|
+
const candidates = accounts.filter(
|
|
102
|
+
(account) => !account.signedOut && normalizeServerUrl(account.baseUrl) === link.origin,
|
|
103
|
+
);
|
|
104
|
+
return (
|
|
105
|
+
(link.workspaceId
|
|
106
|
+
? candidates.find((account) => account.workspaceId === link.workspaceId)
|
|
107
|
+
: undefined) ??
|
|
108
|
+
candidates.find((account) => account.id === activeId) ??
|
|
109
|
+
candidates[0] ??
|
|
110
|
+
null
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The web's handoff link that opens a web page in the app. */
|
|
115
|
+
export function appHandoffUrl(webUrl: string): string {
|
|
116
|
+
return `opengeni://open?url=${encodeURIComponent(webUrl)}`;
|
|
117
|
+
}
|