@opengeni/core 3.0.1 → 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 +4 -4
- package/dist/access/index.d.ts +131 -7
- package/dist/access/service-initiator.d.ts +3 -0
- package/dist/application/archived-session-imports.d.ts +6 -0
- package/dist/application/composer-submit.d.ts +1 -1
- package/dist/application/connect-operation.d.ts +6 -0
- package/dist/application/external-workspace-members.d.ts +13 -1
- package/dist/application/modal-native-live-declaration-join.d.ts +37 -0
- package/dist/application/modal-native-original-configuration.d.ts +79 -0
- package/dist/application/modal-native-worker-host-transport.d.ts +297 -0
- package/dist/application/new-session-drafts.d.ts +29 -2
- package/dist/application/organization-privacy.d.ts +57 -0
- package/dist/application/prepared-mcp-connection.d.ts +31 -0
- package/dist/application/sandbox-recovery.d.ts +58 -0
- package/dist/application/session-commands.d.ts +3 -0
- package/dist/application/session-tenancy.d.ts +13 -4
- package/dist/billing/agent-run-admission.d.ts +21 -0
- package/dist/billing/limits.d.ts +27 -1
- package/dist/billing/model-call-admission.d.ts +34 -0
- package/dist/billing/model-usage-settlement.d.ts +112 -0
- package/dist/canonical-human-identities.js +1 -1
- package/dist/{chunk-VCZFFEPB.js → chunk-7T2SZ7BI.js} +16 -2
- package/dist/chunk-7T2SZ7BI.js.map +1 -0
- package/dist/{chunk-ZYCNLYGH.js → chunk-OMJFIIWK.js} +178 -12
- package/dist/chunk-OMJFIIWK.js.map +1 -0
- package/dist/{chunk-H7X52RI2.js → chunk-QI2M2B2K.js} +83 -8
- package/dist/chunk-QI2M2B2K.js.map +1 -0
- package/dist/{chunk-OF65T3PM.js → chunk-TTWTXQB2.js} +94 -6
- package/dist/chunk-TTWTXQB2.js.map +1 -0
- package/dist/codex-model-availability.d.ts +55 -0
- package/dist/default-session-model.d.ts +192 -0
- package/dist/dependencies.d.ts +41 -7
- package/dist/developer-setup-credential-ceiling.d.ts +10 -0
- package/dist/domain/agent-config-resolution.d.ts +49 -0
- package/dist/domain/automations.d.ts +8 -1
- package/dist/domain/capabilities.d.ts +112 -8
- package/dist/domain/connection-account-selection-error.d.ts +8 -0
- package/dist/domain/connector-tool-permissions.d.ts +62 -0
- package/dist/domain/direct-model-provider.d.ts +3 -0
- package/dist/domain/editable-artifacts/agent-application.d.ts +10 -1
- package/dist/domain/editable-artifacts/durable-export.d.ts +22 -1
- package/dist/domain/editable-artifacts/ports.d.ts +10 -0
- package/dist/domain/editable-artifacts/service.d.ts +3 -1
- package/dist/domain/editable-artifacts/types.d.ts +1 -1
- package/dist/domain/encryption-key.d.ts +12 -0
- package/dist/domain/insights-timing.d.ts +16 -0
- package/dist/domain/insights-usage.d.ts +27 -0
- package/dist/domain/insights.d.ts +21 -3
- package/dist/domain/knowledge-files.d.ts +1 -1
- package/dist/domain/knowledge-preparation.d.ts +10 -0
- package/dist/domain/knowledge-preparation.test.d.ts +1 -0
- package/dist/domain/knowledge-search.d.ts +15 -76
- package/dist/domain/mcp-account-bindings.d.ts +17 -0
- package/dist/domain/mcp-account-routes.d.ts +21 -0
- package/dist/domain/native-mcp-connection-admission.d.ts +3 -0
- package/dist/domain/organization-integration-catalog.d.ts +15 -0
- package/dist/domain/personal-connection-delegations.d.ts +73 -12
- package/dist/domain/pr-review.d.ts +121 -6
- package/dist/domain/realtime-voice-billing.d.ts +103 -0
- package/dist/domain/resources.d.ts +17 -1
- package/dist/domain/scheduled-task-access.d.ts +265 -0
- package/dist/domain/scheduled-task-account-audit.d.ts +27 -0
- package/dist/domain/scheduled-task-audience.d.ts +70 -0
- package/dist/domain/scheduled-tasks.d.ts +61 -18
- package/dist/domain/session-connection-accounts.d.ts +53 -0
- package/dist/domain/session-file-access.d.ts +4 -0
- package/dist/domain/session-native-connection-replacement.d.ts +14 -0
- package/dist/domain/session-start-timing.d.ts +7 -0
- package/dist/domain/session-tool-policy.d.ts +102 -4
- package/dist/domain/sessions.d.ts +179 -15
- package/dist/domain/site-audience.d.ts +52 -0
- package/dist/domain/skills.d.ts +29 -1
- package/dist/domain/slack-bot.d.ts +46 -1
- package/dist/domain/slack-publication-secret-safety.d.ts +1 -1
- package/dist/domain/vaults/index.d.ts +7 -0
- package/dist/domain/vaults/mapping.d.ts +25 -0
- package/dist/domain/vaults/provider-registry.d.ts +72 -0
- package/dist/domain/vaults/provider-sync.d.ts +176 -0
- package/dist/domain/vaults/provider-writes.d.ts +57 -0
- package/dist/domain/vaults/secret-resolver.d.ts +34 -0
- package/dist/domain/vaults/types.d.ts +24 -0
- package/dist/domain/vaults/vault-service.d.ts +35 -0
- package/dist/domain/voice-input-billing.d.ts +77 -0
- package/dist/domain/web-search-billing.d.ts +51 -0
- package/dist/domain/workspace-credits.d.ts +7 -0
- package/dist/editable-artifact-live/application.d.ts +2 -1
- package/dist/editable-artifact-live/server.d.ts +5 -1
- package/dist/editable-artifact-live/ticket.d.ts +2 -1
- package/dist/editable-artifact-live/types.d.ts +9 -0
- package/dist/editable-artifact-live.js +2 -2
- package/dist/editable-artifacts.js +10 -2
- package/dist/goal-admission.d.ts +627 -0
- package/dist/host-session-usage-limit.d.ts +15 -0
- package/dist/index.d.ts +43 -8
- package/dist/index.js +22682 -11743
- package/dist/index.js.map +1 -1
- package/dist/managed-session.d.ts +110 -7
- package/dist/model-call.d.ts +58 -0
- package/dist/model-catalog.d.ts +29 -3
- package/dist/model-provider-credentials.d.ts +43 -0
- package/dist/product-usage-metrics.d.ts +30 -0
- package/dist/rigs/index.d.ts +1 -13
- package/dist/sandbox/fleet.d.ts +58 -4
- package/dist/sandbox/routing.d.ts +42 -2
- package/dist/sandbox/runtime-settings.d.ts +27 -17
- package/dist/session-authorization.d.ts +10 -0
- package/dist/session-usage-limit-metrics.d.ts +60 -0
- package/dist/session-usage-limits.d.ts +89 -0
- package/dist/site-agent-clamp.d.ts +71 -0
- package/dist/site-session-origin.d.ts +39 -2
- package/dist/transcription.d.ts +120 -3
- package/dist/turn-surface.d.ts +20 -0
- package/dist/user-presence.d.ts +32 -0
- package/dist/workflow-wake-contract.d.ts +13 -1
- package/package.json +15 -22
- package/src/access/index.ts +961 -38
- package/src/access/service-initiator.ts +50 -0
- package/src/application/api-integration-servers.ts +9 -0
- package/src/application/archived-session-imports.ts +161 -0
- package/src/application/composer-submit.ts +3 -2
- package/src/application/connect-authority.ts +3 -3
- package/src/application/connect-operation.ts +37 -3
- package/src/application/external-continuation.ts +20 -3
- package/src/application/external-link-work-admission.ts +3 -0
- package/src/application/external-workspace-members.ts +51 -3
- package/src/application/modal-native-live-declaration-join.ts +196 -0
- package/src/application/modal-native-original-configuration.ts +261 -0
- package/src/application/modal-native-worker-host-transport.ts +263 -0
- package/src/application/new-session-drafts.ts +172 -55
- package/src/application/organization-privacy.ts +161 -0
- package/src/application/prepared-mcp-connection.ts +133 -0
- package/src/application/sandbox-recovery.ts +78 -0
- package/src/application/session-commands.ts +73 -1
- package/src/application/session-mcp-credential-rotation.ts +61 -18
- package/src/application/session-tenancy.ts +262 -44
- package/src/application/user-resource-grants.ts +1 -29
- package/src/billing/agent-run-admission.ts +117 -0
- package/src/billing/limits.ts +138 -14
- package/src/billing/model-call-admission.ts +118 -0
- package/src/billing/model-usage-settlement.ts +472 -0
- package/src/codex-model-availability.ts +264 -0
- package/src/default-session-model.ts +692 -0
- package/src/dependencies.ts +48 -6
- package/src/developer-setup-credential-ceiling.ts +60 -0
- package/src/domain/agent-config-resolution.ts +148 -0
- package/src/domain/automations.ts +76 -2
- package/src/domain/capabilities.ts +830 -181
- package/src/domain/connection-account-selection-error.ts +19 -0
- package/src/domain/connector-tool-permissions.ts +572 -0
- package/src/domain/direct-model-provider.ts +62 -0
- package/src/domain/editable-artifacts/agent-application.ts +44 -6
- package/src/domain/editable-artifacts/durable-export.ts +100 -5
- package/src/domain/editable-artifacts/in-memory.ts +6 -0
- package/src/domain/editable-artifacts/ports.ts +11 -0
- package/src/domain/editable-artifacts/service.ts +20 -0
- package/src/domain/editable-artifacts/types.ts +1 -1
- package/src/domain/encryption-key.ts +26 -0
- package/src/domain/file-owner.ts +16 -1
- package/src/domain/github-action-policies.ts +1 -1
- package/src/domain/github-skill-source.ts +3 -1
- package/src/domain/insights-timing.ts +95 -0
- package/src/domain/insights-usage.ts +67 -0
- package/src/domain/insights.ts +167 -43
- package/src/domain/knowledge-files.ts +10 -3
- package/src/domain/knowledge-messages.ts +1 -0
- package/src/domain/knowledge-preparation.test.ts +276 -0
- package/src/domain/knowledge-preparation.ts +147 -0
- package/src/domain/knowledge-search.test.ts +617 -5
- package/src/domain/knowledge-search.ts +240 -23
- package/src/domain/mcp-account-bindings.ts +169 -0
- package/src/domain/mcp-account-routes.ts +152 -0
- package/src/domain/native-mcp-connection-admission.ts +14 -0
- package/src/domain/organization-integration-catalog.ts +88 -0
- package/src/domain/personal-connection-delegations.ts +399 -257
- package/src/domain/pr-review.ts +24 -8
- package/src/domain/realtime-voice-billing.ts +425 -0
- package/src/domain/resources.ts +50 -4
- package/src/domain/scheduled-task-access.ts +1089 -0
- package/src/domain/scheduled-task-account-audit.ts +90 -0
- package/src/domain/scheduled-task-audience.ts +249 -0
- package/src/domain/scheduled-tasks.ts +1313 -374
- package/src/domain/session-connection-accounts.ts +239 -0
- package/src/domain/session-file-access.ts +47 -0
- package/src/domain/session-native-connection-replacement.ts +64 -0
- package/src/domain/session-start-timing.ts +60 -0
- package/src/domain/session-tool-policy.ts +489 -14
- package/src/domain/sessions.ts +2254 -717
- package/src/domain/site-audience.ts +130 -0
- package/src/domain/skills.ts +9 -0
- package/src/domain/slack-bot.ts +141 -4
- package/src/domain/slack-publication-secret-safety.ts +1 -1
- package/src/domain/vaults/index.ts +19 -0
- package/src/domain/vaults/mapping.ts +190 -0
- package/src/domain/vaults/provider-registry.ts +201 -0
- package/src/domain/vaults/provider-sync.ts +531 -0
- package/src/domain/vaults/provider-writes.ts +288 -0
- package/src/domain/vaults/secret-resolver.ts +464 -0
- package/src/domain/vaults/types.ts +26 -0
- package/src/domain/vaults/vault-service.ts +1316 -0
- package/src/domain/voice-input-billing.ts +330 -0
- package/src/domain/web-search-billing.ts +169 -0
- package/src/domain/workspace-credits.ts +13 -0
- package/src/editable-artifact-live/application.ts +8 -1
- package/src/editable-artifact-live/server.ts +154 -6
- package/src/editable-artifact-live/ticket.ts +86 -1
- package/src/editable-artifact-live/types.ts +10 -0
- package/src/goal-admission.ts +220 -0
- package/src/host-session-usage-limit.ts +25 -0
- package/src/index.ts +75 -11
- package/src/managed-session.ts +137 -6
- package/src/model-call.ts +79 -0
- package/src/model-catalog.ts +345 -91
- package/src/model-provider-credentials.ts +394 -0
- package/src/product-usage-metrics.ts +101 -0
- package/src/rigs/index.ts +23 -111
- package/src/sandbox/fleet.ts +253 -28
- package/src/sandbox/routing.ts +204 -43
- package/src/sandbox/runtime-settings.ts +159 -85
- package/src/session-authorization.ts +172 -23
- package/src/session-usage-limit-metrics.ts +95 -0
- package/src/session-usage-limits.ts +415 -0
- package/src/site-agent-clamp.ts +226 -0
- package/src/site-session-origin.ts +84 -5
- package/src/transcription.ts +123 -4
- package/src/turn-surface.ts +47 -0
- package/src/user-presence.ts +134 -0
- package/src/workflow-wake-contract.ts +14 -1
- package/dist/application/host-mcp-owner.d.ts +0 -6
- package/dist/application/host-mcp-resolvers.d.ts +0 -13
- package/dist/chunk-5WZYFL45.js +0 -266
- package/dist/chunk-5WZYFL45.js.map +0 -1
- package/dist/chunk-H7X52RI2.js.map +0 -1
- package/dist/chunk-OF65T3PM.js.map +0 -1
- package/dist/chunk-VCZFFEPB.js.map +0 -1
- package/dist/chunk-ZYCNLYGH.js.map +0 -1
- package/dist/domain/connection-authority.d.ts +0 -97
- package/dist/domain/connection-authority.js +0 -169
- package/dist/domain/connection-authority.js.map +0 -1
- package/dist/domain/environments.d.ts +0 -33
- package/dist/domain/host-mcp-authority-source-admission.d.ts +0 -10
- package/dist/domain/host-mcp-task-admission.d.ts +0 -18
- package/dist/domain/packs.d.ts +0 -59
- package/dist/domain/product-integration-pack.d.ts +0 -44
- package/dist/domain/product-integration-skill.gen.d.ts +0 -5
- package/dist/remote-mcp-credentials.d.ts +0 -23
- package/dist/remote-mcp-credentials.js +0 -11
- package/dist/remote-mcp-credentials.js.map +0 -1
- package/src/application/host-mcp-owner.ts +0 -41
- package/src/application/host-mcp-resolvers.ts +0 -84
- package/src/domain/connection-authority.ts +0 -329
- package/src/domain/environments.ts +0 -120
- package/src/domain/host-mcp-authority-source-admission.ts +0 -25
- package/src/domain/host-mcp-task-admission.ts +0 -121
- package/src/domain/packs.ts +0 -699
- package/src/domain/product-integration-pack.ts +0 -42
- package/src/domain/product-integration-skill.gen.ts +0 -52
- package/src/remote-mcp-credentials.ts +0 -361
package/src/index.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
export { readSessionAttachmentFiles } from "./domain/session-file-access";
|
|
2
|
+
export { verifyDirectModelAccess } from "./domain/direct-model-provider";
|
|
1
3
|
export * from "./domain/skills";
|
|
4
|
+
export * from "./domain/mcp-account-bindings";
|
|
5
|
+
export * from "./domain/mcp-account-routes";
|
|
6
|
+
export * from "./domain/session-connection-accounts";
|
|
7
|
+
export * from "./domain/organization-integration-catalog";
|
|
2
8
|
export * from "./domain/knowledge";
|
|
3
9
|
export * from "./domain/knowledge-search";
|
|
4
|
-
|
|
10
|
+
export * from "./domain/voice-input-billing";
|
|
11
|
+
export * from "./domain/web-search-billing";
|
|
12
|
+
export * from "./domain/realtime-voice-billing";
|
|
13
|
+
// @opengeni/core — the framework-agnostic Opengeni core.
|
|
5
14
|
//
|
|
6
|
-
// WHAT THIS PACKAGE IS: the
|
|
15
|
+
// WHAT THIS PACKAGE IS: the Opengeni domain, access, and billing layers carved
|
|
7
16
|
// out of `apps/api` into an importable library, so a host (e.g. cloudgeni) can
|
|
8
|
-
// call the
|
|
17
|
+
// call the Opengeni core DIRECTLY, off-HTTP — e.g. `createSessionForRequest(
|
|
9
18
|
// deps, grant, workspaceId, input)` — without standing up the Hono router.
|
|
10
19
|
// `apps/api` (@opengeni/api-router) and `apps/worker` (@opengeni/worker-bundle)
|
|
11
20
|
// remain the STANDALONE RUNNERS that consume this library; nothing about the
|
|
@@ -30,7 +39,11 @@ export * from "./domain/knowledge-search";
|
|
|
30
39
|
// The central dependency type surface (AppDependencies, ApiRouteDeps,
|
|
31
40
|
// SessionWorkflowClient, DocumentIndexClient, ObjectStorageDependency).
|
|
32
41
|
export * from "./dependencies";
|
|
42
|
+
export * from "./domain/vaults/provider-registry";
|
|
43
|
+
export * from "./domain/vaults/provider-sync";
|
|
33
44
|
export * from "./workflow-wake-contract";
|
|
45
|
+
export * from "./user-presence";
|
|
46
|
+
export * from "./product-usage-metrics";
|
|
34
47
|
|
|
35
48
|
// Boundary type slots referenced by dependencies.ts. The IMPLEMENTATIONS that
|
|
36
49
|
// construct these (the real sandbox client / Better Auth instance) stay in
|
|
@@ -44,6 +57,12 @@ export {
|
|
|
44
57
|
getManagedAuthRequestActorEpoch,
|
|
45
58
|
getManagedAuthRequestActorLeaseStamp,
|
|
46
59
|
getManagedSession,
|
|
60
|
+
getNativeAppManagedSession,
|
|
61
|
+
NATIVE_APP_CREDENTIAL_PREFIX,
|
|
62
|
+
recordManagedAuthLoggedFailure,
|
|
63
|
+
withManagedAuthSessionLookup,
|
|
64
|
+
configureManagedUserAdmission,
|
|
65
|
+
assertManagedUserAdmission,
|
|
47
66
|
ManagedAuthActorLeaseOutcomeUnknownError,
|
|
48
67
|
markManagedAuthRequestActorTransitionApplied,
|
|
49
68
|
releaseManagedAuthRequestActorLease,
|
|
@@ -53,6 +72,10 @@ export {
|
|
|
53
72
|
} from "./managed-session";
|
|
54
73
|
export * from "./transcription";
|
|
55
74
|
export * from "./model-catalog";
|
|
75
|
+
export * from "./model-provider-credentials";
|
|
76
|
+
export * from "./goal-admission";
|
|
77
|
+
export * from "./codex-model-availability";
|
|
78
|
+
export * from "./default-session-model";
|
|
56
79
|
|
|
57
80
|
// Sandbox fleet/routing service — the closure of `domain/sessions.ts`
|
|
58
81
|
// (`swapActiveSandbox` + `FleetContext`). apps/api re-imports these for its MCP
|
|
@@ -65,40 +88,49 @@ export * from "./sandbox/runtime-settings";
|
|
|
65
88
|
export * from "./access";
|
|
66
89
|
export * from "./application/external-workspace-members";
|
|
67
90
|
export * from "./application/external-identity-lifecycle";
|
|
68
|
-
export * from "./application/host-mcp-resolvers";
|
|
69
91
|
export * from "./application/external-continuation";
|
|
70
92
|
export * from "./application/session-mcp-credential-rotation";
|
|
71
93
|
export * from "./application/external-link-work-admission";
|
|
72
94
|
export * from "./application/connect-authority";
|
|
73
|
-
export * from "./application/host-mcp-owner";
|
|
74
95
|
export * from "./application/connect-operation";
|
|
96
|
+
export * from "./application/prepared-mcp-connection";
|
|
75
97
|
export * from "./session-authorization";
|
|
76
98
|
|
|
77
99
|
// Billing / usage-limit admission (checkLimit / requireLimit / recordWorkspaceUsage).
|
|
78
100
|
export * from "./billing/limits";
|
|
101
|
+
export * from "./billing/agent-run-admission";
|
|
102
|
+
export * from "./billing/model-usage-settlement";
|
|
103
|
+
export * from "./billing/model-call-admission";
|
|
104
|
+
export * from "./model-call";
|
|
79
105
|
|
|
80
106
|
// Domain layer — the off-HTTP V2 surface (createSessionForRequest,
|
|
81
|
-
|
|
107
|
+
|
|
82
108
|
// scheduled-task/workspace-member logic, …).
|
|
83
109
|
export * from "./domain/capabilities";
|
|
84
|
-
export * from "./domain/
|
|
110
|
+
export * from "./domain/native-mcp-connection-admission";
|
|
85
111
|
export * from "./domain/skill-imports";
|
|
86
112
|
export * from "./domain/skill-search";
|
|
87
113
|
export * from "./domain/github-skill-source";
|
|
88
|
-
export * from "./domain/
|
|
114
|
+
export * from "./domain/encryption-key";
|
|
115
|
+
export * from "./domain/vaults";
|
|
89
116
|
export * from "./rigs";
|
|
90
|
-
export * from "./domain/packs";
|
|
91
117
|
export * from "./domain/automations";
|
|
92
118
|
export * from "./domain/pr-review";
|
|
93
|
-
|
|
119
|
+
|
|
94
120
|
export * from "./domain/personal-connection-delegations";
|
|
95
121
|
export * from "./domain/resources";
|
|
96
122
|
export * from "./domain/github-repository-bindings";
|
|
97
123
|
export * from "./domain/github-action-policies";
|
|
98
124
|
export * from "./domain/session-tool-policy";
|
|
125
|
+
export * from "./domain/agent-config-resolution";
|
|
99
126
|
export * from "./domain/scheduled-tasks";
|
|
127
|
+
export * from "./domain/scheduled-task-access";
|
|
128
|
+
export * from "./domain/scheduled-task-account-audit";
|
|
129
|
+
export * from "./domain/scheduled-task-audience";
|
|
130
|
+
export * from "./domain/site-audience";
|
|
100
131
|
export * from "./domain/sessions";
|
|
101
132
|
export * from "./domain/insights";
|
|
133
|
+
export * from "./domain/insights-usage";
|
|
102
134
|
export * from "./domain/memory-slack-publication";
|
|
103
135
|
export * from "./domain/memory-slack-delivery";
|
|
104
136
|
export * from "./domain/governed-learning-slack-publication";
|
|
@@ -115,7 +147,10 @@ export * from "./domain/organization-membership-lifecycle";
|
|
|
115
147
|
export * from "./application/new-session-drafts";
|
|
116
148
|
export * from "./application/composer-submit";
|
|
117
149
|
export * from "./application/session-commands";
|
|
150
|
+
export * from "./application/archived-session-imports";
|
|
118
151
|
export * from "./application/session-tenancy";
|
|
152
|
+
export * from "./application/organization-privacy";
|
|
153
|
+
export * from "./application/sandbox-recovery";
|
|
119
154
|
export * from "./application/user-resource-grants";
|
|
120
155
|
export * from "./application/api-integration-servers";
|
|
121
156
|
|
|
@@ -124,10 +159,39 @@ export * from "./editable-artifact-live";
|
|
|
124
159
|
|
|
125
160
|
// Transport-neutral editable-artifact domain service, ports, and contracts.
|
|
126
161
|
export * from "./editable-artifacts";
|
|
127
|
-
export {
|
|
162
|
+
export {
|
|
163
|
+
currentSiteSessionOrigin,
|
|
164
|
+
siteOriginsMatch,
|
|
165
|
+
siteSessionOriginFromMetadata,
|
|
166
|
+
withSiteOriginMetadata,
|
|
167
|
+
withSiteSessionOrigin,
|
|
168
|
+
type SiteSessionOrigin,
|
|
169
|
+
} from "./site-session-origin";
|
|
170
|
+
export {
|
|
171
|
+
assertNotSiteClampedAgent,
|
|
172
|
+
assertSiteAgentMayChooseCompute,
|
|
173
|
+
SITE_AGENT_COMPUTE_MESSAGE,
|
|
174
|
+
siteAgentClamp,
|
|
175
|
+
siteAgentMayReachSession,
|
|
176
|
+
siteClampedAgentMessage,
|
|
177
|
+
siteSessionClamp,
|
|
178
|
+
type SiteAgentClamp,
|
|
179
|
+
type SiteClampedResource,
|
|
180
|
+
} from "./site-agent-clamp";
|
|
181
|
+
export {
|
|
182
|
+
currentHostSessionUsageLimit,
|
|
183
|
+
withHostSessionUsageLimit,
|
|
184
|
+
type HostSessionUsageLimit,
|
|
185
|
+
} from "./host-session-usage-limit";
|
|
186
|
+
export { resolveTurnSurface } from "./turn-surface";
|
|
128
187
|
|
|
129
188
|
export { fileOwnerContextForAccess, fileOwnerContextForAgent } from "./domain/file-owner";
|
|
130
189
|
|
|
131
190
|
export { prepareKnowledgeFile } from "./domain/knowledge-files";
|
|
191
|
+
export { prepareKnowledgeSave } from "./domain/knowledge-preparation";
|
|
132
192
|
|
|
133
193
|
export { retainKnowledgeMessage } from "./domain/knowledge-messages";
|
|
194
|
+
|
|
195
|
+
export * from "./domain/connector-tool-permissions";
|
|
196
|
+
export * from "./session-usage-limits";
|
|
197
|
+
export * from "./session-usage-limit-metrics";
|
package/src/managed-session.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createHmac } from "node:crypto";
|
|
3
|
+
import { managedUserEmailAllowed } from "@opengeni/config";
|
|
1
4
|
import type { Context } from "hono";
|
|
2
5
|
import type { ManagedAuth } from "./managed-auth-type";
|
|
3
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
DatabaseUnavailableError,
|
|
8
|
+
isDatabaseConnectionLoss,
|
|
9
|
+
isRetryableDatabaseTransportFailure,
|
|
10
|
+
type Database,
|
|
11
|
+
} from "@opengeni/db";
|
|
4
12
|
import {
|
|
5
13
|
acquireManagedAuthActorMutationLease,
|
|
6
14
|
getManagedAuthAdoptedSessionSnapshot,
|
|
@@ -22,6 +30,52 @@ import {
|
|
|
22
30
|
type ManagedAuthSessionAdapter,
|
|
23
31
|
} from "./managed-auth-session-sets";
|
|
24
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Better Auth's session endpoint replaces every non-API failure with a generic
|
|
35
|
+
* INTERNAL_SERVER_ERROR and passes the original only to its logger. A lookup run
|
|
36
|
+
* through `withManagedAuthSessionLookup` collects what the logger saw, so a lost
|
|
37
|
+
* database connection is reported as a retryable outage instead of an opaque 500.
|
|
38
|
+
*/
|
|
39
|
+
const managedAuthLookupFailures = new AsyncLocalStorage<{ errors: unknown[] }>();
|
|
40
|
+
const MANAGED_AUTH_LOOKUP_FAILURE_LIMIT = 8;
|
|
41
|
+
|
|
42
|
+
/** Better Auth `logger.log` sink; a no-op outside a managed-auth session lookup. */
|
|
43
|
+
export function recordManagedAuthLoggedFailure(args: readonly unknown[]): void {
|
|
44
|
+
const store = managedAuthLookupFailures.getStore();
|
|
45
|
+
if (!store) return;
|
|
46
|
+
for (const value of args) {
|
|
47
|
+
if (store.errors.length >= MANAGED_AUTH_LOOKUP_FAILURE_LIMIT) return;
|
|
48
|
+
if (value && typeof value === "object") store.errors.push(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isBetterAuthInternalServerError(error: unknown): boolean {
|
|
53
|
+
if (!error || typeof error !== "object") return false;
|
|
54
|
+
const candidate = error as { status?: unknown; statusCode?: unknown };
|
|
55
|
+
return candidate.status === "INTERNAL_SERVER_ERROR" || candidate.statusCode === 500;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function withManagedAuthSessionLookup<T>(lookup: () => Promise<T>): Promise<T> {
|
|
59
|
+
const store = { errors: [] as unknown[] };
|
|
60
|
+
try {
|
|
61
|
+
return await managedAuthLookupFailures.run(store, lookup);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
// Better Auth's session endpoint only reads its database adapter, so a
|
|
64
|
+
// socket failure it logged is that adapter's connection, not another service.
|
|
65
|
+
if (
|
|
66
|
+
isBetterAuthInternalServerError(error) &&
|
|
67
|
+
store.errors.some(
|
|
68
|
+
(logged) => isDatabaseConnectionLoss(logged) || isRetryableDatabaseTransportFailure(logged),
|
|
69
|
+
)
|
|
70
|
+
) {
|
|
71
|
+
throw new DatabaseUnavailableError("managed auth session store unavailable", {
|
|
72
|
+
cause: error,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
25
79
|
const ACTOR_MUTATION_LEASE_SECONDS = 15 * 60;
|
|
26
80
|
const ACTOR_MUTATION_LEASE_REFRESH_MS = 5 * 60 * 1_000;
|
|
27
81
|
const ACTOR_MUTATION_HANDLER_DEADLINE_MS = 10 * 60 * 1_000;
|
|
@@ -68,7 +122,82 @@ const managedActorAdmissionByRequest = new WeakMap<Request, ManagedAuthActorAdmi
|
|
|
68
122
|
* Programmatic callers must explicitly request and forward the returned cookie
|
|
69
123
|
* headers; the HTTP handler does this automatically, but direct API calls do not.
|
|
70
124
|
*/
|
|
71
|
-
|
|
125
|
+
const managedUserAllowlists = new WeakMap<ManagedAuth, readonly string[]>();
|
|
126
|
+
|
|
127
|
+
/** Bind admission to this auth instance, including all session-set modes. */
|
|
128
|
+
export function configureManagedUserAdmission(
|
|
129
|
+
auth: ManagedAuth,
|
|
130
|
+
emails: readonly string[] | undefined,
|
|
131
|
+
): void {
|
|
132
|
+
if (emails === undefined) managedUserAllowlists.delete(auth);
|
|
133
|
+
else managedUserAllowlists.set(auth, [...emails]);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function getManagedSession(...args: Parameters<typeof resolveManagedSession>) {
|
|
137
|
+
const session = await resolveManagedSession(...args);
|
|
138
|
+
assertManagedUserAdmission(args[1], session?.user);
|
|
139
|
+
return session;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Bearer prefix of a native app credential. The credential is a dedicated
|
|
144
|
+
* Better Auth session the person approved from a signed-in browser (see the
|
|
145
|
+
* native app sign-in route); the prefix only routes it to this resolver.
|
|
146
|
+
*/
|
|
147
|
+
export const NATIVE_APP_CREDENTIAL_PREFIX = "ogapp_";
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Resolve a native app credential exactly as the legacy managed cookie path
|
|
151
|
+
* resolves a browser session: Better Auth validates expiry and renews the
|
|
152
|
+
* durable session, then the canonical human session must still be valid. A
|
|
153
|
+
* native credential never reads or selects a browser session set; each app
|
|
154
|
+
* account holds its own independently revocable session.
|
|
155
|
+
*/
|
|
156
|
+
export async function getNativeAppManagedSession(
|
|
157
|
+
auth: ManagedAuth,
|
|
158
|
+
credential: string,
|
|
159
|
+
db: Database | undefined,
|
|
160
|
+
) {
|
|
161
|
+
if (!credential.startsWith(NATIVE_APP_CREDENTIAL_PREFIX)) return null;
|
|
162
|
+
const token = credential.slice(NATIVE_APP_CREDENTIAL_PREFIX.length);
|
|
163
|
+
if (!/^[A-Za-z0-9]{16,128}$/u.test(token)) return null;
|
|
164
|
+
const context = await auth.$context;
|
|
165
|
+
const signed = encodeURIComponent(
|
|
166
|
+
`${token}.${createHmac("sha256", context.secret).update(token, "utf8").digest("base64")}`,
|
|
167
|
+
);
|
|
168
|
+
const session = await withManagedAuthSessionLookup(() =>
|
|
169
|
+
auth.api.getSession({
|
|
170
|
+
headers: new Headers({ cookie: `${context.authCookies.sessionToken.name}=${signed}` }),
|
|
171
|
+
// Never serve a cached cookie snapshot: the app's session row is authoritative.
|
|
172
|
+
query: { disableCookieCache: true },
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
if (!session?.user) return null;
|
|
176
|
+
assertManagedUserAdmission(auth, session.user);
|
|
177
|
+
if (!db) return session;
|
|
178
|
+
const authSessionId = session.session?.id;
|
|
179
|
+
if (typeof authSessionId !== "string") return null;
|
|
180
|
+
const valid = await validateCanonicalHumanSession(db, {
|
|
181
|
+
authSessionId,
|
|
182
|
+
authUserId: session.user.id,
|
|
183
|
+
});
|
|
184
|
+
return valid ? session : null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function assertManagedUserAdmission(
|
|
188
|
+
auth: ManagedAuth,
|
|
189
|
+
user: { email: string; emailVerified: boolean } | null | undefined,
|
|
190
|
+
): void {
|
|
191
|
+
const emails = managedUserAllowlists.get(auth);
|
|
192
|
+
if (
|
|
193
|
+
user &&
|
|
194
|
+
emails !== undefined &&
|
|
195
|
+
(!user.emailVerified || !managedUserEmailAllowed(emails, user.email))
|
|
196
|
+
)
|
|
197
|
+
throw new HTTPException(403, { message: "Account is not permitted on this deployment" });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function resolveManagedSession(
|
|
72
201
|
c: Context,
|
|
73
202
|
auth: ManagedAuth,
|
|
74
203
|
options?: {
|
|
@@ -229,10 +358,12 @@ export async function getManagedSession(
|
|
|
229
358
|
throw error;
|
|
230
359
|
}
|
|
231
360
|
}
|
|
232
|
-
const result = await
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
361
|
+
const result = await withManagedAuthSessionLookup(() =>
|
|
362
|
+
auth.api.getSession({
|
|
363
|
+
headers: c.req.raw.headers,
|
|
364
|
+
returnHeaders: true,
|
|
365
|
+
}),
|
|
366
|
+
);
|
|
236
367
|
|
|
237
368
|
for (const cookie of setCookieHeaders(result.headers)) {
|
|
238
369
|
c.header("set-cookie", cookie, { append: true });
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { AccessGrant } from "@opengeni/contracts";
|
|
2
|
+
import type { SingleModelCallRequest, SingleModelCallResult } from "@opengeni/runtime";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Stateless single model calls: one request to one workspace model with no
|
|
6
|
+
* tools, no agent loop and no session. The public chat completions endpoint
|
|
7
|
+
* is the transport; agentic work uses sessions. The host-owned service picks
|
|
8
|
+
* the model, credential and subscription account exactly as a turn would,
|
|
9
|
+
* admits the call against the same funding rules and settles actual usage.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type ModelCallCaller = {
|
|
13
|
+
grant: AccessGrant;
|
|
14
|
+
accountId: string;
|
|
15
|
+
workspaceId: string;
|
|
16
|
+
/** The authenticated subject whose model and subscription authority apply. */
|
|
17
|
+
subjectId: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type ModelCallInput = ModelCallCaller & {
|
|
21
|
+
/** Product model id or alias; null selects the workspace default model. */
|
|
22
|
+
model: string | null;
|
|
23
|
+
request: Omit<SingleModelCallRequest, "signal">;
|
|
24
|
+
/** Server-generated identity; the settlement idempotency key derives from it. */
|
|
25
|
+
requestId: string;
|
|
26
|
+
signal?: AbortSignal;
|
|
27
|
+
onTextDelta?: (delta: string) => void | Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type ModelCallOutput = {
|
|
31
|
+
/** Canonical product model id that served the call. */
|
|
32
|
+
model: string;
|
|
33
|
+
result: SingleModelCallResult;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ModelCallModel = {
|
|
37
|
+
id: string;
|
|
38
|
+
label: string;
|
|
39
|
+
providerLabel: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface ModelCallService {
|
|
43
|
+
/** Models the caller may use for a single call, in catalog order. */
|
|
44
|
+
listModels(caller: ModelCallCaller): Promise<ModelCallModel[]>;
|
|
45
|
+
call(input: ModelCallInput): Promise<ModelCallOutput>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type ModelCallErrorType =
|
|
49
|
+
| "invalid_request_error"
|
|
50
|
+
| "not_found_error"
|
|
51
|
+
| "insufficient_quota"
|
|
52
|
+
| "rate_limit_error"
|
|
53
|
+
| "api_error"
|
|
54
|
+
| "service_unavailable";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A refusal or failure with a public status and an OpenAI-style error type.
|
|
58
|
+
* Messages are safe to return to the caller.
|
|
59
|
+
*/
|
|
60
|
+
export class ModelCallError extends Error {
|
|
61
|
+
readonly status: number;
|
|
62
|
+
readonly type: ModelCallErrorType;
|
|
63
|
+
readonly code: string | null;
|
|
64
|
+
readonly param: string | null;
|
|
65
|
+
constructor(input: {
|
|
66
|
+
status: number;
|
|
67
|
+
type: ModelCallErrorType;
|
|
68
|
+
message: string;
|
|
69
|
+
code?: string | null;
|
|
70
|
+
param?: string | null;
|
|
71
|
+
}) {
|
|
72
|
+
super(input.message);
|
|
73
|
+
this.name = "ModelCallError";
|
|
74
|
+
this.status = input.status;
|
|
75
|
+
this.type = input.type;
|
|
76
|
+
this.code = input.code ?? null;
|
|
77
|
+
this.param = input.param ?? null;
|
|
78
|
+
}
|
|
79
|
+
}
|