@opengeni/sdk 3.3.2 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1007 -72
- 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 +1369 -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-6GYGMLX4.js +332 -0
- package/dist/chunk-6GYGMLX4.js.map +1 -0
- package/dist/chunk-7EWT3PV6.js +368 -0
- package/dist/chunk-7EWT3PV6.js.map +1 -0
- package/dist/chunk-FTWVVPR6.js +1665 -0
- package/dist/chunk-FTWVVPR6.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-KGEABAID.js +71 -0
- package/dist/chunk-KGEABAID.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-JUS2UYRP.js → chunk-NCU5OAN7.js} +27 -2
- package/dist/chunk-NCU5OAN7.js.map +1 -0
- package/dist/{chunk-YXQX7RQT.js → chunk-OI5YLASH.js} +73 -2
- package/dist/chunk-OI5YLASH.js.map +1 -0
- package/dist/chunk-OV3POE62.js +359 -0
- package/dist/chunk-OV3POE62.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-TRNI7KEO.js → chunk-S2NLS3ES.js} +3669 -1281
- package/dist/chunk-S2NLS3ES.js.map +1 -0
- package/dist/chunk-UM4ZXXJR.js +9 -0
- package/dist/chunk-UM4ZXXJR.js.map +1 -0
- package/dist/{chunk-QT3KFVDP.js → chunk-UME3X7CP.js} +28 -32
- package/dist/chunk-UME3X7CP.js.map +1 -0
- package/dist/chunk-VT4YM4XQ.js +210 -0
- package/dist/chunk-VT4YM4XQ.js.map +1 -0
- package/dist/chunk-WSYYXONG.js +1602 -0
- package/dist/chunk-WSYYXONG.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-X5ITQVXE.js +15 -0
- package/dist/chunk-X5ITQVXE.js.map +1 -0
- package/dist/chunk-XA7HVIHI.js +126 -0
- package/dist/chunk-XA7HVIHI.js.map +1 -0
- package/dist/{chunk-KKRO2VCP.js → chunk-YJCHB7R3.js} +60 -12
- package/dist/chunk-YJCHB7R3.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 +1068 -118
- 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/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/external-vault-receiver.d.ts +203 -0
- package/dist/external-vault-receiver.js +564 -0
- package/dist/external-vault-receiver.js.map +1 -0
- 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 +62 -11
- package/dist/index.js +557 -338
- 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 +165 -71
- package/dist/interaction.js +2 -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 +1 -1
- 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 -28
- 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-ai.d.ts +35 -0
- package/dist/site-bridge-host.d.ts +112 -0
- package/dist/site-bridge-host.js +286 -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 +186 -0
- package/dist/site.js +63 -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 +2807 -583
- 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 +324 -0
- package/dist/vaults-api.d.ts +65 -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 +67 -0
- package/dist/workspace-integrations.js.map +1 -0
- package/dist/workspace-state.d.ts +8 -71
- package/package.json +103 -5
- 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 +5697 -1833
- 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/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/external-vault-receiver.ts +914 -0
- 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 +603 -65
- package/src/insights-usage.ts +64 -0
- package/src/interaction.ts +315 -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 +15 -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 +8 -82
- package/src/session-usage-limits.ts +71 -0
- package/src/shared-catalog-loader.ts +169 -0
- package/src/site-ai.ts +284 -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 +878 -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 +3170 -582
- package/src/usage-allowances.ts +189 -0
- package/src/vault-types.ts +379 -0
- package/src/vaults-api.ts +339 -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-C2H7HBNP.js.map +0 -1
- package/dist/chunk-C4DJPZRU.js +0 -119
- package/dist/chunk-C4DJPZRU.js.map +0 -1
- package/dist/chunk-JUS2UYRP.js.map +0 -1
- package/dist/chunk-KKRO2VCP.js.map +0 -1
- package/dist/chunk-QT3KFVDP.js.map +0 -1
- package/dist/chunk-TRNI7KEO.js.map +0 -1
- package/dist/chunk-VYCTL62C.js.map +0 -1
- package/dist/chunk-YXQX7RQT.js.map +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { CredentialProviderRequest, WorkspaceWebhookEvent } from "@opengeni/contracts";
|
|
2
|
+
import type { OpenGeniClient } from "./client.js";
|
|
3
|
+
import type { CreateOrganizationWebhookRequest, CreateOrganizationWebhookResponse, GetOrganizationCredentialProviderResponse, ListOrganizationWebhookDeliveriesResponse, ListOrganizationWebhooksResponse, OrganizationWebhook, OrganizationWebhookDelivery, PutOrganizationCredentialProviderRequest, PutOrganizationCredentialProviderResponse, RotateWorkspaceCredentialProviderSecretResponse, RotateOrganizationCredentialProviderSecretResponse, RotateWorkspaceWebhookSecretResponse, RotateOrganizationWebhookSecretResponse, TestWorkspaceCredentialProviderResponse, TestWorkspaceWebhookResponse, UpdateOrganizationWebhookRequest, WorkspaceInheritedIntegrationsResponse, WorkspaceWebhook } from "@opengeni/contracts";
|
|
4
|
+
export type { CreateOrganizationWebhookRequest, CreateOrganizationWebhookResponse, CreateWorkspaceWebhookRequest, CreateWorkspaceWebhookResponse, CredentialProviderRequest, CredentialProviderInitiatorContext, CredentialProviderResponse, CredentialProviderMcpHeaders, CredentialProviderMcpMaterial, GetOrganizationCredentialProviderResponse, GetWorkspaceCredentialProviderResponse, InitiatingHuman, IntegrationEndpointTestResult, IntegrationWorkspaceFilter, ListOrganizationWebhookDeliveriesResponse, ListOrganizationWebhooksResponse, ListWorkspaceWebhookDeliveriesResponse, ListWorkspaceWebhooksResponse, PutWorkspaceCredentialProviderRequest, PutWorkspaceCredentialProviderResponse, PutOrganizationCredentialProviderRequest, PutOrganizationCredentialProviderResponse, RotateWorkspaceCredentialProviderSecretResponse, RotateOrganizationCredentialProviderSecretResponse, RotateWorkspaceWebhookSecretResponse, RotateOrganizationWebhookSecretResponse, TestWorkspaceCredentialProviderResponse, TestWorkspaceWebhookResponse, OrganizationCredentialProvider, OrganizationWebhook, OrganizationWebhookDelivery, UpdateOrganizationWebhookRequest, UpdateWorkspaceWebhookRequest, WorkspaceCredentialProvider, WorkspaceInheritedIntegrationsResponse, WorkspaceTestWebhookEvent, WorkspaceWebhook, WorkspaceWebhookDelivery, WorkspaceWebhookEvent, WorkspaceWebhookEventType, SessionWorkspaceWebhookEvent, WorkspaceUsageWebhookEvent, } from "@opengeni/contracts";
|
|
5
|
+
export { OPENGENI_DELIVERY_ID_HEADER, OPENGENI_EVENT_ID_HEADER, OPENGENI_SIGNATURE_HEADER, OPENGENI_TEST_REQUEST_NIL_ID, OPENGENI_WEBHOOK_TEST_EVENT_TYPE, WORKSPACE_WEBHOOK_EVENT_TYPES, signOpenGeniPayload, verifyOpenGeniSignature, } from "@opengeni/contracts/workspace-integration-wire";
|
|
6
|
+
export type WorkspaceSandboxImages = {
|
|
7
|
+
images: string[];
|
|
8
|
+
selected: string | null;
|
|
9
|
+
};
|
|
10
|
+
export declare class OpenGeniSignatureError extends Error {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
type SignedRequest = {
|
|
14
|
+
/** The exact raw request body. Parse it only after verification. */
|
|
15
|
+
body: string;
|
|
16
|
+
headers: Headers | Record<string, string | string[] | undefined>;
|
|
17
|
+
secret: string;
|
|
18
|
+
toleranceSeconds?: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Verify and parse one webhook delivery. Delivery is at least once: dedupe on
|
|
22
|
+
* `event.id` (also sent as the `OpenGeni-Event-Id` header). A `webhook.test`
|
|
23
|
+
* event (from "Send test event") names no session: acknowledge it with 2xx.
|
|
24
|
+
*/
|
|
25
|
+
export declare function verifyWebhookEvent(input: SignedRequest): Promise<{
|
|
26
|
+
event: WorkspaceWebhookEvent;
|
|
27
|
+
deliveryId: string | null;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Verify the exact bytes and parse a provider request, including its frozen
|
|
31
|
+
* initiatorContext when sent by an upgraded worker. Provenance grants no access.
|
|
32
|
+
*/
|
|
33
|
+
export declare function verifyCredentialProviderRequest(input: SignedRequest): Promise<CredentialProviderRequest>;
|
|
34
|
+
/** Identity header names, for receivers that log or dedupe. */
|
|
35
|
+
export declare const OPENGENI_WEBHOOK_HEADERS: {
|
|
36
|
+
readonly signature: "OpenGeni-Signature";
|
|
37
|
+
readonly eventId: "OpenGeni-Event-Id";
|
|
38
|
+
readonly deliveryId: "OpenGeni-Delivery-Id";
|
|
39
|
+
};
|
|
40
|
+
/** Server-side integration administration is opt-in, outside the eager browser client. */
|
|
41
|
+
export declare function getOrganizationCredentialProvider(client: Pick<OpenGeniClient, "requestJson">, organizationId: string): Promise<GetOrganizationCredentialProviderResponse>;
|
|
42
|
+
/** Replace configuration; explicit filter required. Store the first returned signing secret. */
|
|
43
|
+
export declare function putOrganizationCredentialProvider(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, request: PutOrganizationCredentialProviderRequest): Promise<PutOrganizationCredentialProviderResponse>;
|
|
44
|
+
export declare function deleteOrganizationCredentialProvider(client: Pick<OpenGeniClient, "requestJson">, organizationId: string): Promise<void>;
|
|
45
|
+
export declare function listOrganizationWebhooks(client: Pick<OpenGeniClient, "requestJson">, organizationId: string): Promise<ListOrganizationWebhooksResponse>;
|
|
46
|
+
/** Create a webhook and return its signing secret once. */
|
|
47
|
+
export declare function createOrganizationWebhook(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, request: CreateOrganizationWebhookRequest): Promise<CreateOrganizationWebhookResponse>;
|
|
48
|
+
export declare function getOrganizationWebhook(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, webhookId: string): Promise<OrganizationWebhook>;
|
|
49
|
+
export declare function updateOrganizationWebhook(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, webhookId: string, request: UpdateOrganizationWebhookRequest): Promise<OrganizationWebhook>;
|
|
50
|
+
export declare function deleteOrganizationWebhook(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, webhookId: string): Promise<void>;
|
|
51
|
+
export declare function listOrganizationWebhookDeliveries(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, webhookId: string, options?: {
|
|
52
|
+
limit?: number;
|
|
53
|
+
}): Promise<ListOrganizationWebhookDeliveriesResponse>;
|
|
54
|
+
/** Requeue a settled delivery with a fresh attempt budget. */
|
|
55
|
+
export declare function redeliverOrganizationWebhookDelivery(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, webhookId: string, deliveryId: string): Promise<OrganizationWebhookDelivery>;
|
|
56
|
+
export declare function getWorkspaceWebhook(client: Pick<OpenGeniClient, "requestJson">, workspaceId: string, webhookId: string): Promise<WorkspaceWebhook>;
|
|
57
|
+
/** Rotate immediately. Store the new secret; the old signing secret stops working. */
|
|
58
|
+
export declare function rotateWorkspaceCredentialProviderSecret(client: Pick<OpenGeniClient, "requestJson">, workspaceId: string): Promise<RotateWorkspaceCredentialProviderSecretResponse>;
|
|
59
|
+
export declare function rotateOrganizationCredentialProviderSecret(client: Pick<OpenGeniClient, "requestJson">, organizationId: string): Promise<RotateOrganizationCredentialProviderSecretResponse>;
|
|
60
|
+
export declare function rotateOrganizationWebhookSecret(client: Pick<OpenGeniClient, "requestJson">, organizationId: string, webhookId: string): Promise<RotateOrganizationWebhookSecretResponse>;
|
|
61
|
+
export declare function rotateWorkspaceWebhookSecret(client: Pick<OpenGeniClient, "requestJson">, workspaceId: string, webhookId: string): Promise<RotateWorkspaceWebhookSecretResponse>;
|
|
62
|
+
/**
|
|
63
|
+
* Send one signed `webhook.test` event to a workspace webhook now and return
|
|
64
|
+
* what the endpoint answered. Nothing is queued or retried.
|
|
65
|
+
*/
|
|
66
|
+
export declare function testWorkspaceWebhook(client: Pick<OpenGeniClient, "requestJson">, workspaceId: string, webhookId: string): Promise<TestWorkspaceWebhookResponse>;
|
|
67
|
+
/**
|
|
68
|
+
* Send one signed `purpose: "test"` request to the credential provider this
|
|
69
|
+
* workspace's runs use (its own, else the organization's). Only the names of
|
|
70
|
+
* returned credentials come back, never their values.
|
|
71
|
+
*/
|
|
72
|
+
export declare function testWorkspaceCredentialProvider(client: Pick<OpenGeniClient, "requestJson">, workspaceId: string): Promise<TestWorkspaceCredentialProviderResponse>;
|
|
73
|
+
/** Organization registrations that reach this workspace. Workspace administrators only. */
|
|
74
|
+
export declare function getWorkspaceInheritedIntegrations(client: Pick<OpenGeniClient, "requestJson">, workspaceId: string): Promise<WorkspaceInheritedIntegrationsResponse>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OPENGENI_WEBHOOK_HEADERS,
|
|
3
|
+
OpenGeniSignatureError,
|
|
4
|
+
createOrganizationWebhook,
|
|
5
|
+
deleteOrganizationCredentialProvider,
|
|
6
|
+
deleteOrganizationWebhook,
|
|
7
|
+
getOrganizationCredentialProvider,
|
|
8
|
+
getOrganizationWebhook,
|
|
9
|
+
getWorkspaceInheritedIntegrations,
|
|
10
|
+
getWorkspaceWebhook,
|
|
11
|
+
listOrganizationWebhookDeliveries,
|
|
12
|
+
listOrganizationWebhooks,
|
|
13
|
+
putOrganizationCredentialProvider,
|
|
14
|
+
redeliverOrganizationWebhookDelivery,
|
|
15
|
+
rotateOrganizationCredentialProviderSecret,
|
|
16
|
+
rotateOrganizationWebhookSecret,
|
|
17
|
+
rotateWorkspaceCredentialProviderSecret,
|
|
18
|
+
rotateWorkspaceWebhookSecret,
|
|
19
|
+
testWorkspaceCredentialProvider,
|
|
20
|
+
testWorkspaceWebhook,
|
|
21
|
+
updateOrganizationWebhook,
|
|
22
|
+
verifyCredentialProviderRequest,
|
|
23
|
+
verifyWebhookEvent
|
|
24
|
+
} from "./chunk-VT4YM4XQ.js";
|
|
25
|
+
import {
|
|
26
|
+
OPENGENI_DELIVERY_ID_HEADER,
|
|
27
|
+
OPENGENI_EVENT_ID_HEADER,
|
|
28
|
+
OPENGENI_SIGNATURE_HEADER,
|
|
29
|
+
OPENGENI_TEST_REQUEST_NIL_ID,
|
|
30
|
+
OPENGENI_WEBHOOK_TEST_EVENT_TYPE,
|
|
31
|
+
WORKSPACE_WEBHOOK_EVENT_TYPES,
|
|
32
|
+
signOpenGeniPayload,
|
|
33
|
+
verifyOpenGeniSignature
|
|
34
|
+
} from "./chunk-KGEABAID.js";
|
|
35
|
+
export {
|
|
36
|
+
OPENGENI_DELIVERY_ID_HEADER,
|
|
37
|
+
OPENGENI_EVENT_ID_HEADER,
|
|
38
|
+
OPENGENI_SIGNATURE_HEADER,
|
|
39
|
+
OPENGENI_TEST_REQUEST_NIL_ID,
|
|
40
|
+
OPENGENI_WEBHOOK_HEADERS,
|
|
41
|
+
OPENGENI_WEBHOOK_TEST_EVENT_TYPE,
|
|
42
|
+
OpenGeniSignatureError,
|
|
43
|
+
WORKSPACE_WEBHOOK_EVENT_TYPES,
|
|
44
|
+
createOrganizationWebhook,
|
|
45
|
+
deleteOrganizationCredentialProvider,
|
|
46
|
+
deleteOrganizationWebhook,
|
|
47
|
+
getOrganizationCredentialProvider,
|
|
48
|
+
getOrganizationWebhook,
|
|
49
|
+
getWorkspaceInheritedIntegrations,
|
|
50
|
+
getWorkspaceWebhook,
|
|
51
|
+
listOrganizationWebhookDeliveries,
|
|
52
|
+
listOrganizationWebhooks,
|
|
53
|
+
putOrganizationCredentialProvider,
|
|
54
|
+
redeliverOrganizationWebhookDelivery,
|
|
55
|
+
rotateOrganizationCredentialProviderSecret,
|
|
56
|
+
rotateOrganizationWebhookSecret,
|
|
57
|
+
rotateWorkspaceCredentialProviderSecret,
|
|
58
|
+
rotateWorkspaceWebhookSecret,
|
|
59
|
+
signOpenGeniPayload,
|
|
60
|
+
testWorkspaceCredentialProvider,
|
|
61
|
+
testWorkspaceWebhook,
|
|
62
|
+
updateOrganizationWebhook,
|
|
63
|
+
verifyCredentialProviderRequest,
|
|
64
|
+
verifyOpenGeniSignature,
|
|
65
|
+
verifyWebhookEvent
|
|
66
|
+
};
|
|
67
|
+
//# 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.
|
|
4
|
-
"description": "Framework-agnostic TypeScript SDK for the
|
|
3
|
+
"version": "3.4.0",
|
|
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,50 @@
|
|
|
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
|
+
"./external-vault-receiver": {
|
|
82
|
+
"types": "./dist/external-vault-receiver.d.ts",
|
|
83
|
+
"import": "./dist/external-vault-receiver.js"
|
|
84
|
+
},
|
|
85
|
+
"./session-history-import": {
|
|
86
|
+
"types": "./dist/session-history-import.d.ts",
|
|
87
|
+
"import": "./dist/session-history-import.js"
|
|
88
|
+
},
|
|
37
89
|
"./document-authority": {
|
|
38
90
|
"types": "./dist/document-authority.d.ts",
|
|
39
91
|
"import": "./dist/document-authority.js"
|
|
@@ -58,6 +110,10 @@
|
|
|
58
110
|
"types": "./dist/pr-review.d.ts",
|
|
59
111
|
"import": "./dist/pr-review.js"
|
|
60
112
|
},
|
|
113
|
+
"./organization-integration-policy": {
|
|
114
|
+
"types": "./dist/organization-integration-policy.d.ts",
|
|
115
|
+
"import": "./dist/organization-integration-policy.js"
|
|
116
|
+
},
|
|
61
117
|
"./organization-private-session-settings": {
|
|
62
118
|
"types": "./dist/organization-private-session-settings.d.ts",
|
|
63
119
|
"import": "./dist/organization-private-session-settings.js"
|
|
@@ -89,7 +145,48 @@
|
|
|
89
145
|
"./gateway-realtime-transport": {
|
|
90
146
|
"types": "./dist/gateway-realtime-transport.d.ts",
|
|
91
147
|
"import": "./dist/gateway-realtime-transport.js"
|
|
92
|
-
}
|
|
148
|
+
},
|
|
149
|
+
"./model-picker-order": {
|
|
150
|
+
"types": "./dist/model-picker-order.d.ts",
|
|
151
|
+
"import": "./dist/model-picker-order.js"
|
|
152
|
+
},
|
|
153
|
+
"./model-display": {
|
|
154
|
+
"types": "./dist/model-display.d.ts",
|
|
155
|
+
"import": "./dist/model-display.js"
|
|
156
|
+
},
|
|
157
|
+
"./chat": {
|
|
158
|
+
"types": "./dist/chat/index.d.ts",
|
|
159
|
+
"import": "./dist/chat/index.js"
|
|
160
|
+
},
|
|
161
|
+
"./tenant-workspaces": {
|
|
162
|
+
"types": "./dist/tenant-workspaces.d.ts",
|
|
163
|
+
"import": "./dist/tenant-workspaces.js"
|
|
164
|
+
},
|
|
165
|
+
"./session-proxy": {
|
|
166
|
+
"types": "./dist/session-proxy.d.ts",
|
|
167
|
+
"import": "./dist/session-proxy.js"
|
|
168
|
+
},
|
|
169
|
+
"./tool-auth": {
|
|
170
|
+
"types": "./dist/tool-auth.d.ts",
|
|
171
|
+
"import": "./dist/tool-auth.js"
|
|
172
|
+
},
|
|
173
|
+
"./next": {
|
|
174
|
+
"types": "./dist/adapters/next.d.ts",
|
|
175
|
+
"import": "./dist/adapters/next.js"
|
|
176
|
+
},
|
|
177
|
+
"./express": {
|
|
178
|
+
"types": "./dist/adapters/express.d.ts",
|
|
179
|
+
"import": "./dist/adapters/express.js"
|
|
180
|
+
},
|
|
181
|
+
"./hono": {
|
|
182
|
+
"types": "./dist/adapters/hono.d.ts",
|
|
183
|
+
"import": "./dist/adapters/hono.js"
|
|
184
|
+
},
|
|
185
|
+
"./session-list-entries": {
|
|
186
|
+
"types": "./dist/session-list-entries.d.ts",
|
|
187
|
+
"import": "./dist/session-list-entries.js"
|
|
188
|
+
},
|
|
189
|
+
"./package.json": "./package.json"
|
|
93
190
|
},
|
|
94
191
|
"publishConfig": {
|
|
95
192
|
"access": "public",
|
|
@@ -97,11 +194,12 @@
|
|
|
97
194
|
},
|
|
98
195
|
"scripts": {
|
|
99
196
|
"typecheck": "tsc --noEmit",
|
|
100
|
-
"build": "bun ../../scripts/build-typescript-package.ts",
|
|
197
|
+
"build": "bun ../../scripts/generate-site-browser-runtime.ts && bun ../../scripts/build-typescript-package.ts",
|
|
101
198
|
"prepublishOnly": "bash ../../scripts/prepublish-guard"
|
|
102
199
|
},
|
|
103
200
|
"dependencies": {
|
|
104
|
-
"@opengeni/
|
|
201
|
+
"@opengeni/connect": "3.4.0",
|
|
202
|
+
"@opengeni/contracts": "3.4.0"
|
|
105
203
|
},
|
|
106
204
|
"engines": {
|
|
107
205
|
"node": ">=18"
|
|
@@ -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
|
+
}
|