@opengeni/core 2.6.4 → 2.7.5-canary.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/dist/access/index.d.ts +10 -0
- package/dist/application/api-integration-servers.d.ts +20 -0
- package/dist/billing/limits.d.ts +5 -0
- package/dist/dependencies.d.ts +12 -1
- package/dist/domain/host-mcp-authority-source-admission.d.ts +10 -0
- package/dist/domain/packs.d.ts +1 -0
- package/dist/domain/pr-review.d.ts +1 -1
- package/dist/domain/product-integration-pack.d.ts +50 -0
- package/dist/domain/sessions.d.ts +25 -11
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2360 -687
- package/dist/index.js.map +1 -1
- package/dist/model-catalog.d.ts +105 -0
- package/dist/sandbox/fleet.d.ts +19 -0
- package/package.json +12 -10
- package/src/access/index.ts +25 -0
- package/src/application/api-integration-servers.ts +215 -0
- package/src/application/session-commands.ts +2 -2
- package/src/billing/limits.ts +52 -22
- package/src/dependencies.ts +17 -1
- package/src/domain/capabilities.ts +19 -3
- package/src/domain/host-mcp-authority-source-admission.ts +25 -0
- package/src/domain/insights.ts +32 -0
- package/src/domain/packs.ts +48 -18
- package/src/domain/personal-connection-delegations.ts +14 -6
- package/src/domain/product-integration-pack.ts +494 -0
- package/src/domain/scheduled-tasks.ts +43 -1
- package/src/domain/sessions.ts +964 -386
- package/src/index.ts +4 -0
- package/src/model-catalog.ts +742 -0
- package/src/sandbox/fleet.ts +85 -23
- package/src/sandbox/routing.ts +6 -9
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { type ConfiguredModel, type Settings } from "@opengeni/config";
|
|
2
|
+
import { type ModelAvailabilityV1, type ModelCredentialReadinessV1, type WorkspaceModelPolicyContract } from "@opengeni/contracts";
|
|
3
|
+
import { type Database } from "@opengeni/db";
|
|
4
|
+
export type ResolvedCatalogSettings = {
|
|
5
|
+
settings: Settings;
|
|
6
|
+
source: "code" | "database";
|
|
7
|
+
version: number | null;
|
|
8
|
+
modelNotes: Record<string, string>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Curated workspace Gateway products and workspace-owned custom slugs share
|
|
12
|
+
* one public prefix. Only the latter have a mutable catalog row whose active
|
|
13
|
+
* generation must be rechecked at a fresh acceptance commit boundary.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isWorkspaceGatewayCustomModelId(settings: Settings, modelId: string): boolean;
|
|
16
|
+
export declare function isWorkspaceOpenRouterCustomModelId(settings: Settings, modelId: string): boolean;
|
|
17
|
+
export type WorkspaceCustomModelReference = {
|
|
18
|
+
scope: "workspace" | "organization";
|
|
19
|
+
providerKind: "vercel_gateway" | "openrouter";
|
|
20
|
+
upstreamModelId: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function workspaceCustomModelReference(settings: Settings, modelId: string): WorkspaceCustomModelReference | null;
|
|
23
|
+
export declare function isWorkspaceCustomModelId(settings: Settings, modelId: string): boolean;
|
|
24
|
+
export declare function lockActiveCustomModelForAdmission(db: Database, input: {
|
|
25
|
+
accountId: string;
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
reference: WorkspaceCustomModelReference;
|
|
28
|
+
}): Promise<boolean>;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve the deployment catalog without making synchronous env settings read
|
|
31
|
+
* Postgres. Database mode fails closed when the singleton is absent or invalid;
|
|
32
|
+
* code mode preserves the already-validated env catalog.
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveCatalogSettings(db: Database, envSettings: Settings): Promise<ResolvedCatalogSettings>;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the deployment catalog and add only the custom Gateway slugs owned by
|
|
37
|
+
* one workspace. Use this at model-bearing workspace boundaries; public config
|
|
38
|
+
* and deployment-operator surfaces must continue to use `resolveCatalogSettings`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveWorkspaceCatalogSettings(db: Database, envSettings: Settings, input: {
|
|
41
|
+
accountId: string;
|
|
42
|
+
workspaceId: string;
|
|
43
|
+
retainedProductModelId?: string | null;
|
|
44
|
+
retainedProductModelIds?: readonly (string | null | undefined)[];
|
|
45
|
+
}): Promise<ResolvedCatalogSettings>;
|
|
46
|
+
export type ModelAvailabilityObservation = {
|
|
47
|
+
status: "available" | "degraded" | "unavailable";
|
|
48
|
+
reason: "not_entitled" | "provider_unhealthy" | null;
|
|
49
|
+
checkedAt: string;
|
|
50
|
+
};
|
|
51
|
+
export type ModelCredentialReadinessObservation = {
|
|
52
|
+
status: "ready";
|
|
53
|
+
checkedAt: string;
|
|
54
|
+
} | {
|
|
55
|
+
status: "not_ready";
|
|
56
|
+
reason: "prerequisites_missing" | "needs_reauth";
|
|
57
|
+
checkedAt: string;
|
|
58
|
+
} | {
|
|
59
|
+
status: "error";
|
|
60
|
+
reason: "resolver_error";
|
|
61
|
+
checkedAt: string;
|
|
62
|
+
};
|
|
63
|
+
export declare const MODEL_CREDENTIAL_READINESS_OBSERVATION_MAX_AGE_MS: number;
|
|
64
|
+
export type WorkspaceModelSelectionInput = {
|
|
65
|
+
settings: Settings;
|
|
66
|
+
policy: WorkspaceModelPolicyContract | null;
|
|
67
|
+
codexSubscriptionActive: boolean;
|
|
68
|
+
xaiSubscriptionActive?: boolean;
|
|
69
|
+
workspaceGatewayConnectionActive?: boolean;
|
|
70
|
+
workspaceOpenRouterConnectionActive?: boolean;
|
|
71
|
+
organizationGatewayConnectionActive?: boolean;
|
|
72
|
+
organizationOpenRouterConnectionActive?: boolean;
|
|
73
|
+
workspaceGatewayCustomModels?: readonly {
|
|
74
|
+
upstreamModelId: string;
|
|
75
|
+
label?: string | null;
|
|
76
|
+
}[];
|
|
77
|
+
workspaceOpenRouterCustomModels?: readonly {
|
|
78
|
+
upstreamModelId: string;
|
|
79
|
+
label?: string | null;
|
|
80
|
+
}[];
|
|
81
|
+
organizationGatewayCustomModels?: readonly {
|
|
82
|
+
upstreamModelId: string;
|
|
83
|
+
label?: string | null;
|
|
84
|
+
}[];
|
|
85
|
+
organizationOpenRouterCustomModels?: readonly {
|
|
86
|
+
upstreamModelId: string;
|
|
87
|
+
label?: string | null;
|
|
88
|
+
}[];
|
|
89
|
+
credentialReadinessObservations?: Readonly<Record<string, ModelCredentialReadinessObservation>> | undefined;
|
|
90
|
+
observations?: Readonly<Record<string, ModelAvailabilityObservation>> | undefined;
|
|
91
|
+
now?: Date | undefined;
|
|
92
|
+
credentialReadinessMaxAgeMs?: number | undefined;
|
|
93
|
+
};
|
|
94
|
+
export type WorkspaceModelSelection = {
|
|
95
|
+
model: ConfiguredModel;
|
|
96
|
+
credentialReadiness: ModelCredentialReadinessV1;
|
|
97
|
+
policyAllowed: boolean;
|
|
98
|
+
availability: ModelAvailabilityV1;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* One shared picker/tool decision. Catalog membership, credential readiness,
|
|
102
|
+
* workspace policy, and optional provider-health observations are evaluated in
|
|
103
|
+
* configured catalog order so every consumer exposes the same selectable set.
|
|
104
|
+
*/
|
|
105
|
+
export declare function resolveWorkspaceModelSelection(input: WorkspaceModelSelectionInput): WorkspaceModelSelection[];
|
package/dist/sandbox/fleet.d.ts
CHANGED
|
@@ -128,6 +128,24 @@ export type FleetSwapResult = {
|
|
|
128
128
|
* means no compute is attached.
|
|
129
129
|
*/
|
|
130
130
|
export declare function listFleet(services: FleetServices, ctx: FleetContext): Promise<FleetListResult>;
|
|
131
|
+
type FleetResourceContext = Pick<FleetContext, "accountId" | "workspaceId" | "subjectId">;
|
|
132
|
+
export type CreateTimeSandboxTargetPreflight = {
|
|
133
|
+
ok: true;
|
|
134
|
+
targetSandboxId: string;
|
|
135
|
+
workingDir: string | null;
|
|
136
|
+
} | {
|
|
137
|
+
ok: false;
|
|
138
|
+
reason: string;
|
|
139
|
+
code: BackendUnresolvableCode | "invalid_working_directory";
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Validate a named create-time machine target before any session row exists.
|
|
143
|
+
* The caller still commits the pointer with `setActiveSandbox` inside the
|
|
144
|
+
* session-create transaction, which rechecks durable ownership/enrollment
|
|
145
|
+
* authority and closes the remove/revoke race without holding database locks
|
|
146
|
+
* across the liveness probe.
|
|
147
|
+
*/
|
|
148
|
+
export declare function preflightCreateTimeSandboxTarget(services: FleetServices, ctx: FleetResourceContext, target: string, workingDir: string | null): Promise<CreateTimeSandboxTargetPreflight>;
|
|
131
149
|
/**
|
|
132
150
|
* THE SWAP (and attach — identical mechanic). Validate the target's ownership +
|
|
133
151
|
* liveness, then repoint the session via the epoch-fenced CAS `setActiveSandbox`:
|
|
@@ -238,3 +256,4 @@ export declare function provisionSandbox(services: FleetServices, ctx: FleetCont
|
|
|
238
256
|
kind: "selfhosted" | "modal";
|
|
239
257
|
name?: string;
|
|
240
258
|
}): Promise<ProvisionResult>;
|
|
259
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.5-canary.0",
|
|
4
4
|
"description": "OpenGeni framework-agnostic core: the domain, access, and billing layers (neutral access, off-HTTP V2 surface). Behavior-preserving extraction from apps/api — keeps Hono's HTTPException for error throwing (typed-errors cleanup deferred).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -54,15 +54,17 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
57
|
-
"@opengeni/
|
|
58
|
-
"@opengeni/
|
|
59
|
-
"@opengeni/
|
|
60
|
-
"@opengeni/
|
|
61
|
-
"@opengeni/
|
|
62
|
-
"@opengeni/
|
|
63
|
-
"@opengeni/
|
|
64
|
-
"@opengeni/
|
|
65
|
-
"@opengeni/
|
|
57
|
+
"@opengeni/capabilities": "^0.3.2-canary.0",
|
|
58
|
+
"@opengeni/codex": "^0.2.21-canary.0",
|
|
59
|
+
"@opengeni/config": "^1.0.0-canary.0",
|
|
60
|
+
"@opengeni/contracts": "^2.13.0-canary.0",
|
|
61
|
+
"@opengeni/db": "^4.0.0-canary.0",
|
|
62
|
+
"@opengeni/documents": "^0.8.19-canary.0",
|
|
63
|
+
"@opengeni/events": "^0.4.17-canary.0",
|
|
64
|
+
"@opengeni/network": "^0.3.0-canary.0",
|
|
65
|
+
"@opengeni/observability": "^0.8.19-canary.0",
|
|
66
|
+
"@opengeni/runtime": "^2.3.0-canary.0",
|
|
67
|
+
"@opengeni/storage": "^0.2.120-canary.0",
|
|
66
68
|
"hono": "^4.12.18",
|
|
67
69
|
"zod": "^4.2.1"
|
|
68
70
|
},
|
package/src/access/index.ts
CHANGED
|
@@ -243,6 +243,31 @@ export function requireAccountAdminAuthorizationStamp(
|
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Verify that an access authorization was minted by the canonical request
|
|
248
|
+
* resolver for this exact subject and workspace.
|
|
249
|
+
*
|
|
250
|
+
* This is the protocol-neutral boundary for request-local services that need
|
|
251
|
+
* the authenticated grant rather than a caller-supplied grant-shaped object.
|
|
252
|
+
* Object identity is intentional: matching fields alone are not proof that the
|
|
253
|
+
* request authenticated the named subject.
|
|
254
|
+
*/
|
|
255
|
+
export function requireResolvedAccessGrantAuthorization(
|
|
256
|
+
authorization: AccessGrantAuthorization,
|
|
257
|
+
workspaceId: string,
|
|
258
|
+
): AccessGrant {
|
|
259
|
+
const { grant } = authorization;
|
|
260
|
+
if (
|
|
261
|
+
!resolvedAccessGrantAuthorizations.has(authorization) ||
|
|
262
|
+
!authorization.contextIntegrity ||
|
|
263
|
+
authorization.authenticatedSubjectId !== grant.subjectId ||
|
|
264
|
+
grant.workspaceId !== workspaceId
|
|
265
|
+
) {
|
|
266
|
+
throw new HTTPException(403, { message: "workspace access authorization is invalid" });
|
|
267
|
+
}
|
|
268
|
+
return grant;
|
|
269
|
+
}
|
|
270
|
+
|
|
246
271
|
/**
|
|
247
272
|
* Resolve the exact built-in single-user local administrator for an account.
|
|
248
273
|
*
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createGraphqlMcpServer,
|
|
3
|
+
createOpenApiMcpServer,
|
|
4
|
+
createPinnedIntegrationTransport,
|
|
5
|
+
directIntegrationTransport,
|
|
6
|
+
IntegrationInvocationError,
|
|
7
|
+
type IntegrationCredentialResolver,
|
|
8
|
+
type IntegrationInvocationAuthority,
|
|
9
|
+
type IntegrationTransport,
|
|
10
|
+
} from "@opengeni/capabilities";
|
|
11
|
+
import type { Settings } from "@opengeni/config";
|
|
12
|
+
import type { ToolAuthNeededPayload } from "@opengeni/contracts";
|
|
13
|
+
import type {
|
|
14
|
+
ApiIntegrationRuntime,
|
|
15
|
+
ResolveConnectionCredentialInput,
|
|
16
|
+
ResolveConnectionCredentialResult,
|
|
17
|
+
} from "@opengeni/db";
|
|
18
|
+
import type { FetchLike } from "@opengeni/network";
|
|
19
|
+
import type { LocalMcpServerRegistration } from "@opengeni/runtime";
|
|
20
|
+
|
|
21
|
+
export type BuildApiIntegrationServersInput = {
|
|
22
|
+
settings: Settings;
|
|
23
|
+
integrations: readonly ApiIntegrationRuntime[];
|
|
24
|
+
authority: Omit<IntegrationInvocationAuthority, "connectionRef">;
|
|
25
|
+
resolveCredential: (
|
|
26
|
+
input: ResolveConnectionCredentialInput,
|
|
27
|
+
) => Promise<ResolveConnectionCredentialResult>;
|
|
28
|
+
onAuthNeeded?: (payload: ToolAuthNeededPayload) => Promise<void> | void;
|
|
29
|
+
fetchImpl?: FetchLike;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Compile active persisted API facets into ordinary in-process MCP providers.
|
|
34
|
+
* The caller supplies its authority resolver, so agent attempts and current
|
|
35
|
+
* humans use the same provider assembly without sharing credentials or policy.
|
|
36
|
+
*/
|
|
37
|
+
export function buildApiIntegrationMcpServers(
|
|
38
|
+
input: BuildApiIntegrationServersInput,
|
|
39
|
+
): LocalMcpServerRegistration[] {
|
|
40
|
+
const transport = createPinnedIntegrationTransport({
|
|
41
|
+
network: input.settings,
|
|
42
|
+
...(input.fetchImpl ? { fetchImpl: input.fetchImpl } : {}),
|
|
43
|
+
});
|
|
44
|
+
return input.integrations.map((integration) => {
|
|
45
|
+
const authority: IntegrationInvocationAuthority = {
|
|
46
|
+
...input.authority,
|
|
47
|
+
...(integration.connectionRef?.connectionId
|
|
48
|
+
? { connectionRef: integration.connectionRef.connectionId }
|
|
49
|
+
: {}),
|
|
50
|
+
};
|
|
51
|
+
const credentialResolver = integration.connectionRef
|
|
52
|
+
? integrationCredentialResolver(input, integration, "execution")
|
|
53
|
+
: undefined;
|
|
54
|
+
const buildServer = (
|
|
55
|
+
serverTransport: IntegrationTransport,
|
|
56
|
+
serverCredentialResolver = credentialResolver,
|
|
57
|
+
) =>
|
|
58
|
+
integration.revision.protocol === "openapi"
|
|
59
|
+
? createOpenApiMcpServer({
|
|
60
|
+
revision: integration.revision,
|
|
61
|
+
transport: serverTransport,
|
|
62
|
+
authority,
|
|
63
|
+
...(serverCredentialResolver ? { credentialResolver: serverCredentialResolver } : {}),
|
|
64
|
+
})
|
|
65
|
+
: createGraphqlMcpServer({
|
|
66
|
+
revision: integration.revision,
|
|
67
|
+
endpoint: integration.baseUrl,
|
|
68
|
+
transport: serverTransport,
|
|
69
|
+
authority,
|
|
70
|
+
...(serverCredentialResolver ? { credentialResolver: serverCredentialResolver } : {}),
|
|
71
|
+
});
|
|
72
|
+
const server = buildServer(transport);
|
|
73
|
+
const preflightCredentialResolver = integration.connectionRef
|
|
74
|
+
? integrationCredentialResolver(input, integration, "preflight")
|
|
75
|
+
: undefined;
|
|
76
|
+
const preflightServer = preflightCredentialResolver
|
|
77
|
+
? buildServer(providerBlockingPreflightTransport, preflightCredentialResolver)
|
|
78
|
+
: null;
|
|
79
|
+
return {
|
|
80
|
+
id: integration.serverId,
|
|
81
|
+
server,
|
|
82
|
+
approvalAuthority: {
|
|
83
|
+
kind: "api_integration",
|
|
84
|
+
capabilityId: integration.capabilityId,
|
|
85
|
+
pluginKey: integration.pluginKey,
|
|
86
|
+
pluginInstallationId: integration.pluginInstallationId,
|
|
87
|
+
installationVersion: integration.installationVersion,
|
|
88
|
+
instanceId: integration.instanceId,
|
|
89
|
+
instanceKey: integration.instanceKey,
|
|
90
|
+
instanceVersion: integration.instanceVersion,
|
|
91
|
+
definitionId: integration.definitionId,
|
|
92
|
+
definitionProvenance: integration.definitionProvenance,
|
|
93
|
+
revisionId: integration.revision.id,
|
|
94
|
+
baseUrl: integration.baseUrl,
|
|
95
|
+
providerDomain: integration.providerDomain,
|
|
96
|
+
connectionRef: integration.connectionRef,
|
|
97
|
+
connectionAuthorityGeneration: integration.connectionAuthorityGeneration,
|
|
98
|
+
},
|
|
99
|
+
...(integration.connectionRef?.connectionId
|
|
100
|
+
? { resolvedConnectionId: integration.connectionRef.connectionId }
|
|
101
|
+
: {}),
|
|
102
|
+
...(credentialResolver
|
|
103
|
+
? {
|
|
104
|
+
preflightCall: async (
|
|
105
|
+
toolName: string,
|
|
106
|
+
args: Record<string, unknown>,
|
|
107
|
+
options?: { signal?: AbortSignal },
|
|
108
|
+
) => await preflightApiIntegrationCall(preflightServer!, toolName, args, options),
|
|
109
|
+
}
|
|
110
|
+
: {}),
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const providerBlockingPreflightTransport = directIntegrationTransport(async () => {
|
|
116
|
+
throw new Error("integration provider request blocked by preflight");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
async function preflightApiIntegrationCall(
|
|
120
|
+
server: LocalMcpServerRegistration["server"],
|
|
121
|
+
toolName: string,
|
|
122
|
+
args: Record<string, unknown>,
|
|
123
|
+
options?: { signal?: AbortSignal },
|
|
124
|
+
): Promise<void> {
|
|
125
|
+
try {
|
|
126
|
+
await server.callTool(toolName, args, null, options);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (error instanceof IntegrationInvocationError && error.code === "request_failed") return;
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
throw new Error("integration preflight unexpectedly crossed the provider request boundary");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function integrationCredentialResolver(
|
|
135
|
+
input: BuildApiIntegrationServersInput,
|
|
136
|
+
integration: ApiIntegrationRuntime,
|
|
137
|
+
credentialResolutionMode: "execution" | "preflight",
|
|
138
|
+
): IntegrationCredentialResolver {
|
|
139
|
+
const connectionRef = integration.connectionRef;
|
|
140
|
+
if (!connectionRef) throw new Error("Integration credential resolver requires a connection");
|
|
141
|
+
const expectedAuthorityGeneration = integration.connectionAuthorityGeneration;
|
|
142
|
+
if (expectedAuthorityGeneration === null) {
|
|
143
|
+
throw new Error("Integration credential resolver requires a connection authority generation");
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
resolve: async (request) => {
|
|
147
|
+
const result = await input.resolveCredential({
|
|
148
|
+
workspaceId: input.authority.workspaceId,
|
|
149
|
+
serverId: integration.serverId,
|
|
150
|
+
toolName: request.operationKey,
|
|
151
|
+
connectionRef,
|
|
152
|
+
destinationUrl: request.destinationUrl,
|
|
153
|
+
credentialTarget: "http_api",
|
|
154
|
+
forceRefresh: request.forceRefresh === true,
|
|
155
|
+
credentialResolutionMode,
|
|
156
|
+
expectedAuthorityGeneration,
|
|
157
|
+
});
|
|
158
|
+
if (result.status === "auth_needed") {
|
|
159
|
+
await publishAuthNeeded(
|
|
160
|
+
input,
|
|
161
|
+
integration.serverId,
|
|
162
|
+
request.operationKey,
|
|
163
|
+
result,
|
|
164
|
+
connectionRef,
|
|
165
|
+
);
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
const destination = new URL(request.destinationUrl);
|
|
169
|
+
return {
|
|
170
|
+
audience: { origin: destination.origin, pathPrefix: "/" },
|
|
171
|
+
placements:
|
|
172
|
+
result.placements ??
|
|
173
|
+
Object.entries(result.headers).map(([name, value]) => ({
|
|
174
|
+
carrier: "header" as const,
|
|
175
|
+
name,
|
|
176
|
+
value,
|
|
177
|
+
})),
|
|
178
|
+
...(result.authorizeProviderRequest
|
|
179
|
+
? { authorizeProviderRequest: result.authorizeProviderRequest }
|
|
180
|
+
: {}),
|
|
181
|
+
...(result.expiresAt ? { expiresAt: result.expiresAt.toISOString() } : {}),
|
|
182
|
+
...(connectionRef.scopes ? { scope: [...connectionRef.scopes] } : {}),
|
|
183
|
+
};
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function publishAuthNeeded(
|
|
189
|
+
input: BuildApiIntegrationServersInput,
|
|
190
|
+
serverId: string,
|
|
191
|
+
toolName: string,
|
|
192
|
+
result: Extract<ResolveConnectionCredentialResult, { status: "auth_needed" }>,
|
|
193
|
+
connectionRef: NonNullable<ApiIntegrationRuntime["connectionRef"]>,
|
|
194
|
+
): Promise<void> {
|
|
195
|
+
try {
|
|
196
|
+
await input.onAuthNeeded?.({
|
|
197
|
+
serverId,
|
|
198
|
+
toolName,
|
|
199
|
+
providerDomain: result.providerDomain,
|
|
200
|
+
...(result.provider ? { provider: result.provider } : {}),
|
|
201
|
+
reason: result.reason,
|
|
202
|
+
...(result.connectionId ? { connectionId: result.connectionId } : {}),
|
|
203
|
+
...(result.authoritySource === "host" || connectionRef.authoritySource === "host"
|
|
204
|
+
? { authoritySource: "host" as const }
|
|
205
|
+
: {}),
|
|
206
|
+
...(result.scopes ? { scopes: result.scopes } : {}),
|
|
207
|
+
...(result.resource ? { resource: result.resource } : {}),
|
|
208
|
+
...(result.selectedResources ? { selectedResources: result.selectedResources } : {}),
|
|
209
|
+
...(result.authorizationUrl ? { authorizationUrl: result.authorizationUrl } : {}),
|
|
210
|
+
});
|
|
211
|
+
} catch {
|
|
212
|
+
// Authentication notices are advisory UI/audit signals. The local tool
|
|
213
|
+
// still returns the fixed connection-required result when publication fails.
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -555,7 +555,7 @@ export async function controlAgentSessionWorkstream(
|
|
|
555
555
|
wakeRevision: result.workflowWake.wakeRevision,
|
|
556
556
|
shouldSignal: true,
|
|
557
557
|
interruptionCount: result.interruptionCount,
|
|
558
|
-
controlRequested:
|
|
558
|
+
controlRequested: input.action === "pause",
|
|
559
559
|
});
|
|
560
560
|
},
|
|
561
561
|
},
|
|
@@ -928,7 +928,7 @@ export async function controlHumanSessionWorkstreamWithOutcome(
|
|
|
928
928
|
wakeRevision: result.workflowWake.wakeRevision,
|
|
929
929
|
shouldSignal: true,
|
|
930
930
|
interruptionCount: result.interruptionCount,
|
|
931
|
-
controlRequested:
|
|
931
|
+
controlRequested: input.action === "pause",
|
|
932
932
|
});
|
|
933
933
|
},
|
|
934
934
|
},
|
package/src/billing/limits.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
configuredStaticUsageLimits,
|
|
3
|
+
resolveModelProviderForTurn,
|
|
4
|
+
type Settings,
|
|
5
|
+
} from "@opengeni/config";
|
|
2
6
|
import type {
|
|
3
7
|
LimitAction,
|
|
4
8
|
LimitDecision,
|
|
@@ -26,14 +30,35 @@ export type LimitCheckInput = {
|
|
|
26
30
|
workspaceId?: string;
|
|
27
31
|
action: LimitAction;
|
|
28
32
|
quantity?: number;
|
|
29
|
-
// The turn's model id, when the action represents an agent turn.
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
// statically ready by definition. Non-model infra actions leave this undefined.
|
|
33
|
+
// The turn's model id, when the action represents an agent turn. The model's
|
|
34
|
+
// deployment cost controls credit/cost gates; upstream metering independently
|
|
35
|
+
// controls the token cap. Connected subscriptions still require live workspace
|
|
36
|
+
// readiness. Non-model infra actions leave this undefined.
|
|
34
37
|
model?: string | null;
|
|
35
38
|
};
|
|
36
39
|
|
|
40
|
+
export function modelFundingForAdmission(
|
|
41
|
+
settings: Settings,
|
|
42
|
+
model: string | null | undefined,
|
|
43
|
+
codexBilled: boolean,
|
|
44
|
+
): { fundedWithoutCredits: boolean; countsTowardTokenCap: boolean } {
|
|
45
|
+
const resolvedModel = model ? resolveModelProviderForTurn(settings, model)?.model : null;
|
|
46
|
+
const codexSubscriptionModel =
|
|
47
|
+
resolvedModel?.credentialSource.kind === "connected_subscription" &&
|
|
48
|
+
resolvedModel.credentialSource.provider === "codex";
|
|
49
|
+
return {
|
|
50
|
+
// A Codex namespace/definition never bypasses credits by itself: the live
|
|
51
|
+
// workspace credential predicate above remains authoritative. SuperGrok's
|
|
52
|
+
// static overlay is likewise secret-free; its worker/provider admission
|
|
53
|
+
// owns live account selection before any upstream request can occur.
|
|
54
|
+
fundedWithoutCredits:
|
|
55
|
+
codexBilled ||
|
|
56
|
+
(resolvedModel != null && !codexSubscriptionModel && resolvedModel.cost !== "credits"),
|
|
57
|
+
countsTowardTokenCap:
|
|
58
|
+
!codexBilled && resolvedModel != null && resolvedModel.billing.upstreamPayer === "deployment",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
37
62
|
export async function requireLimit(deps: LimitDependencies, input: LimitCheckInput): Promise<void> {
|
|
38
63
|
const decision = await checkLimit(deps, input);
|
|
39
64
|
if (decision.allowed) {
|
|
@@ -59,25 +84,22 @@ export async function checkLimit(
|
|
|
59
84
|
model: input.model,
|
|
60
85
|
})
|
|
61
86
|
: false;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
resolved.model.credentialSource.mechanism === "none"
|
|
69
|
-
);
|
|
70
|
-
})()
|
|
71
|
-
: false;
|
|
72
|
-
const externallyBilled = codexBilled || credentialFreeExternal;
|
|
73
|
-
const creditDecision = await checkCreditBalance(deps, input, externallyBilled);
|
|
87
|
+
const { fundedWithoutCredits, countsTowardTokenCap } = modelFundingForAdmission(
|
|
88
|
+
deps.settings,
|
|
89
|
+
input.model,
|
|
90
|
+
codexBilled,
|
|
91
|
+
);
|
|
92
|
+
const creditDecision = await checkCreditBalance(deps, input, fundedWithoutCredits);
|
|
74
93
|
if (!creditDecision.allowed) {
|
|
75
94
|
return creditDecision;
|
|
76
95
|
}
|
|
77
96
|
if (deps.settings.usageLimitsMode !== "static" && deps.settings.usageLimitsMode !== "managed") {
|
|
78
97
|
return { allowed: true };
|
|
79
98
|
}
|
|
80
|
-
return await checkStaticCaps(deps, input,
|
|
99
|
+
return await checkStaticCaps(deps, input, {
|
|
100
|
+
fundedWithoutCredits,
|
|
101
|
+
countsTowardTokenCap,
|
|
102
|
+
});
|
|
81
103
|
}
|
|
82
104
|
|
|
83
105
|
async function checkCreditBalance(
|
|
@@ -101,10 +123,14 @@ async function checkCreditBalance(
|
|
|
101
123
|
async function checkStaticCaps(
|
|
102
124
|
deps: LimitDependencies,
|
|
103
125
|
input: LimitCheckInput,
|
|
104
|
-
|
|
126
|
+
funding: { fundedWithoutCredits: boolean; countsTowardTokenCap: boolean },
|
|
105
127
|
): Promise<LimitDecision> {
|
|
106
128
|
const limits = configuredStaticUsageLimits(deps.settings);
|
|
107
|
-
if (
|
|
129
|
+
if (
|
|
130
|
+
limits.maxMonthlyCostMicrosPerAccount &&
|
|
131
|
+
isCostlyAction(input.action) &&
|
|
132
|
+
!funding.fundedWithoutCredits
|
|
133
|
+
) {
|
|
108
134
|
const used = await sumUsageQuantity(deps.db, {
|
|
109
135
|
accountId: input.accountId,
|
|
110
136
|
eventType: "model.cost",
|
|
@@ -185,7 +211,11 @@ async function checkStaticCaps(
|
|
|
185
211
|
);
|
|
186
212
|
}
|
|
187
213
|
case "tokens:consume": {
|
|
188
|
-
if (
|
|
214
|
+
if (
|
|
215
|
+
!funding.countsTowardTokenCap ||
|
|
216
|
+
!limits.maxMonthlyTokensPerWorkspace ||
|
|
217
|
+
!input.workspaceId
|
|
218
|
+
) {
|
|
189
219
|
return { allowed: true };
|
|
190
220
|
}
|
|
191
221
|
const used = await sumUsageQuantity(deps.db, {
|
package/src/dependencies.ts
CHANGED
|
@@ -19,6 +19,7 @@ import type { ManagedAuthSessionAdapter } from "./managed-auth-session-sets";
|
|
|
19
19
|
import type { ApiSandboxClient, ResumeBoxByIdInput, ResumedSandboxSession } from "./sandbox-types";
|
|
20
20
|
import type { TranscriptionSegmenter, TranscriptionService } from "./transcription";
|
|
21
21
|
import type { EditableArtifactApplicationPort } from "./editable-artifact-live";
|
|
22
|
+
import type { ResolvedCatalogSettings } from "./model-catalog";
|
|
22
23
|
import type {
|
|
23
24
|
EditableArtifactAgentApplication,
|
|
24
25
|
EditableArtifactDurableExportService,
|
|
@@ -129,6 +130,13 @@ export type ManagedEmailTransport = {
|
|
|
129
130
|
|
|
130
131
|
export type AppDependencies = {
|
|
131
132
|
settings: Settings;
|
|
133
|
+
/**
|
|
134
|
+
* Original deployment settings when `settings` is already overlaid with a
|
|
135
|
+
* deployment/workspace catalog snapshot. Model-bearing request adapters set
|
|
136
|
+
* this marker so core admission never feeds a synthetic reviewed provider
|
|
137
|
+
* back through deployment validation.
|
|
138
|
+
*/
|
|
139
|
+
catalogSourceSettings?: Settings;
|
|
132
140
|
db: Database;
|
|
133
141
|
/**
|
|
134
142
|
* Host-composed editable artifact engine. Standalone startup binds the same
|
|
@@ -186,6 +194,8 @@ export type AppDependencies = {
|
|
|
186
194
|
codexFetch?: typeof fetch;
|
|
187
195
|
/** Injectable GitHub transport for deterministic personal-OAuth tests. */
|
|
188
196
|
githubPersonalFetch?: typeof fetch;
|
|
197
|
+
/** Injectable credential-free GitHub transport for public repository verification tests. */
|
|
198
|
+
githubAnonymousFetch?: typeof fetch;
|
|
189
199
|
/** Injectable xAI OAuth/subscription transport for deterministic API/provider tests. */
|
|
190
200
|
xaiFetch?: typeof fetch;
|
|
191
201
|
/** Injectable Slack Web API transport for deterministic bot-connection tests. */
|
|
@@ -225,6 +235,7 @@ export type AppDependencies = {
|
|
|
225
235
|
export type ObjectStorageDependency = ReturnType<typeof createObjectStorage>;
|
|
226
236
|
|
|
227
237
|
export type ApiRouteDeps = AppDependencies & {
|
|
238
|
+
resolveCatalogSettings: () => Promise<ResolvedCatalogSettings>;
|
|
228
239
|
managedEmailTransport: ManagedEmailTransport;
|
|
229
240
|
objectStorage: ObjectStorageDependency;
|
|
230
241
|
githubStateSecret: string;
|
|
@@ -244,7 +255,12 @@ export type ApiRouteDeps = AppDependencies & {
|
|
|
244
255
|
*/
|
|
245
256
|
export type AcceptSessionUserMessageDependencies = Pick<
|
|
246
257
|
AppDependencies,
|
|
247
|
-
|
|
258
|
+
| "settings"
|
|
259
|
+
| "catalogSourceSettings"
|
|
260
|
+
| "db"
|
|
261
|
+
| "bus"
|
|
262
|
+
| "sessionAuthorization"
|
|
263
|
+
| "schedulePromptPostCommit"
|
|
248
264
|
> & {
|
|
249
265
|
workflowClient: Pick<SessionWorkflowClient, "wakeSessionWorkflow">;
|
|
250
266
|
objectStorage: ObjectStorageDependency;
|
|
@@ -57,6 +57,7 @@ import { hasPermission } from "../access";
|
|
|
57
57
|
import { isFikenConnection, preferredFikenConnection } from "./fiken";
|
|
58
58
|
import { listSkillLibraryEntries, type SkillLibraryEntry } from "@opengeni/runtime/skill-library";
|
|
59
59
|
import { listCapabilityPacks, listWorkspaceCapabilityPacks } from "./packs";
|
|
60
|
+
import { assertHostMcpAuthoritySourceAdmissionEnabled } from "./host-mcp-authority-source-admission";
|
|
60
61
|
|
|
61
62
|
const officialMcpRegistryUrl = "https://registry.modelcontextprotocol.io";
|
|
62
63
|
const firstPartyMcpServerIds = new Set(["opengeni", "files", "docs"]);
|
|
@@ -403,7 +404,7 @@ function normalizedMcpCredentialHeaders(
|
|
|
403
404
|
}
|
|
404
405
|
|
|
405
406
|
async function validateMcpCapabilityConnectionRef(
|
|
406
|
-
input: { db: Database; grant: AccessGrant; workspaceId: string },
|
|
407
|
+
input: { db: Database; grant: AccessGrant; workspaceId: string; settings: Settings },
|
|
407
408
|
item: CapabilityCatalogItem,
|
|
408
409
|
ref: McpServerConnectionRef,
|
|
409
410
|
): Promise<McpServerConnectionRef> {
|
|
@@ -426,6 +427,7 @@ async function validateMcpCapabilityConnectionRef(
|
|
|
426
427
|
providerDomain: ref.providerDomain.trim(),
|
|
427
428
|
subjectScope,
|
|
428
429
|
...(ref.connectionId ? { connectionId: ref.connectionId } : {}),
|
|
430
|
+
...(ref.authoritySource === "host" ? { authoritySource: "host" as const } : {}),
|
|
429
431
|
...(ref.provider ? { provider: ref.provider.trim() } : {}),
|
|
430
432
|
...(ref.kind ? { kind: ref.kind } : {}),
|
|
431
433
|
...(ref.scopes ? { scopes: uniqueStrings(ref.scopes) } : {}),
|
|
@@ -449,6 +451,10 @@ async function validateMcpCapabilityConnectionRef(
|
|
|
449
451
|
"MCP capabilities need a remote streamable HTTP endpoint before they can use a connectionRef",
|
|
450
452
|
});
|
|
451
453
|
}
|
|
454
|
+
if (normalized.authoritySource === "host") {
|
|
455
|
+
assertHostMcpAuthoritySourceAdmissionEnabled(input.settings, normalized);
|
|
456
|
+
return normalized;
|
|
457
|
+
}
|
|
452
458
|
|
|
453
459
|
let connection = normalized.connectionId
|
|
454
460
|
? await getConnectionMetadata(
|
|
@@ -1680,12 +1686,22 @@ function installationConnectionRef(
|
|
|
1680
1686
|
if (!ref || typeof ref !== "object") {
|
|
1681
1687
|
return null;
|
|
1682
1688
|
}
|
|
1683
|
-
const { connectionId, providerDomain, kind, subjectScope } = ref as Record<
|
|
1689
|
+
const { authoritySource, connectionId, providerDomain, kind, subjectScope } = ref as Record<
|
|
1690
|
+
string,
|
|
1691
|
+
unknown
|
|
1692
|
+
>;
|
|
1684
1693
|
if (typeof providerDomain !== "string" || typeof kind !== "string") {
|
|
1685
1694
|
return null;
|
|
1686
1695
|
}
|
|
1696
|
+
if (authoritySource === "host") {
|
|
1697
|
+
// The internal installation/runtime ref retains the exact host binding.
|
|
1698
|
+
// Public capability catalogs use the existing null representation for an
|
|
1699
|
+
// enabled capability without a native OpenGeni connection, so indefinitely
|
|
1700
|
+
// open old browser bundles cannot treat a host UUID as native OAuth state.
|
|
1701
|
+
return null;
|
|
1702
|
+
}
|
|
1687
1703
|
if (subjectScope === "subject") {
|
|
1688
|
-
// Never project a personal connection UUID through workspace-visible
|
|
1704
|
+
// Never project a native personal connection UUID through workspace-visible
|
|
1689
1705
|
// capability configuration, including legacy rows that still contain one.
|
|
1690
1706
|
return { providerDomain, kind, subjectScope: "subject" };
|
|
1691
1707
|
}
|