@opengeni/core 0.20.13 → 0.20.16

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.
@@ -45,12 +45,17 @@ export declare function disableCapability(input: {
45
45
  }): Promise<CapabilityInstallation>;
46
46
  export declare function settingsWithEnabledCapabilityMcpServers(db: Database, workspaceId: string, settings: Settings): Promise<Settings>;
47
47
  /**
48
- * Register Codex Apps as an optional runtime MCP when the deployment enables
49
- * it. Registration only makes the server selectable; the session tool policy
50
- * decides whether the model sees it, and Codex credential resolution
51
- * independently decides whether calls can authenticate.
48
+ * Resolve executable Apps authority. The connector must remain active and its
49
+ * exact owner must still hold workspace connection-management permission.
52
50
  */
53
- export declare function settingsWithCodexAppsMcpServer(settings: Settings): Settings;
51
+ export declare function resolveCodexAppsCredentialIdForRun(db: Database, workspaceId: string): Promise<string | null>;
52
+ /**
53
+ * Register Codex Apps as an optional runtime MCP only when the deployment is
54
+ * enabled and this workspace has an active explicit Apps designation.
55
+ * Registration only makes the server selectable; session policy decides
56
+ * whether the model sees it.
57
+ */
58
+ export declare function settingsWithCodexAppsMcpServer(settings: Settings, credentialAvailable: boolean): Settings;
54
59
  export declare function settingsWithMcpCapabilityServers(settings: Settings, enabled: EnabledMcpCapabilityServer[]): Settings;
55
60
  export declare function discoverMcpRegistryCapabilities(input: {
56
61
  query?: string;
package/dist/index.js CHANGED
@@ -1383,6 +1383,8 @@ import {
1383
1383
  getCapabilityCatalogItem,
1384
1384
  getCapabilityInstallation,
1385
1385
  getConnectionMetadata,
1386
+ getCodexAppsCredentialAuthorizationForRun,
1387
+ getWorkspaceGrant as getWorkspaceGrant2,
1386
1388
  getPackInstallation,
1387
1389
  getStoredCapabilityHeaderCiphertext,
1388
1390
  getVariableSet as getVariableSet2,
@@ -1792,6 +1794,11 @@ async function createCatalogItem(input) {
1792
1794
  message: "skill ids are managed by the OpenGeni skill library or runtime adapters"
1793
1795
  });
1794
1796
  }
1797
+ if (input.payload.kind === "mcp" && typeof input.payload.metadata.mcpServerId === "string" && input.payload.metadata.mcpServerId.trim() === CODEX_APPS_MCP_SERVER_ID) {
1798
+ throw new HTTPException6(422, {
1799
+ message: `${CODEX_APPS_MCP_SERVER_ID} is reserved for the canonical Codex Apps service`
1800
+ });
1801
+ }
1795
1802
  const source = input.payload.source === "built_in" || input.payload.source === "library" || input.payload.source === "configured" || input.payload.source === "registry" ? "manual" : input.payload.source;
1796
1803
  const metadata = {
1797
1804
  ...input.payload.metadata,
@@ -2236,26 +2243,45 @@ async function disableCapability(input) {
2236
2243
  return await disableCapabilityInstallation(input.db, input.workspaceId, item.id);
2237
2244
  }
2238
2245
  async function settingsWithEnabledCapabilityMcpServers(db, workspaceId, settings) {
2239
- const enabled = await listEnabledMcpCapabilityServers(db, workspaceId);
2240
- return settingsWithCodexAppsMcpServer(settingsWithMcpCapabilityServers(settings, enabled));
2246
+ const [enabled, codexAppsCredentialId] = await Promise.all([
2247
+ listEnabledMcpCapabilityServers(db, workspaceId),
2248
+ resolveCodexAppsCredentialIdForRun(db, workspaceId)
2249
+ ]);
2250
+ return settingsWithCodexAppsMcpServer(
2251
+ settingsWithMcpCapabilityServers(settings, enabled),
2252
+ codexAppsCredentialId !== null
2253
+ );
2241
2254
  }
2242
- function settingsWithCodexAppsMcpServer(settings) {
2243
- if (!settings.codexConnectedAppsEnabled || settings.mcpServers.some((server) => server.id === CODEX_APPS_MCP_SERVER_ID)) {
2255
+ async function resolveCodexAppsCredentialIdForRun(db, workspaceId) {
2256
+ const authorization = await getCodexAppsCredentialAuthorizationForRun(db, workspaceId);
2257
+ if (!authorization) return null;
2258
+ const grant = await getWorkspaceGrant2(db, authorization.ownerSubjectId, workspaceId);
2259
+ return grant && hasPermission(grant.permissions, "connections:write") ? authorization.credentialId : null;
2260
+ }
2261
+ function settingsWithCodexAppsMcpServer(settings, credentialAvailable) {
2262
+ const canonicalServer = {
2263
+ id: CODEX_APPS_MCP_SERVER_ID,
2264
+ name: CODEX_APPS_MCP_SERVER_NAME,
2265
+ url: CODEX_APPS_MCP_URL,
2266
+ timeoutMs: CODEX_APPS_STARTUP_TIMEOUT_MS,
2267
+ // Availability is credential-specific, so discover on every run.
2268
+ cacheToolsList: false
2269
+ };
2270
+ const withoutReservedId = settings.mcpServers.filter(
2271
+ (server) => server.id !== CODEX_APPS_MCP_SERVER_ID
2272
+ );
2273
+ if (!settings.codexConnectedAppsEnabled || !credentialAvailable) {
2274
+ return withoutReservedId.length === settings.mcpServers.length ? settings : { ...settings, mcpServers: withoutReservedId };
2275
+ }
2276
+ const existing = settings.mcpServers.at(-1);
2277
+ if (withoutReservedId.length === settings.mcpServers.length - 1 && existing !== void 0 && Object.keys(existing).length === Object.keys(canonicalServer).length && Object.entries(canonicalServer).every(
2278
+ ([key, value]) => existing[key] === value
2279
+ )) {
2244
2280
  return settings;
2245
2281
  }
2246
2282
  return {
2247
2283
  ...settings,
2248
- mcpServers: [
2249
- ...settings.mcpServers,
2250
- {
2251
- id: CODEX_APPS_MCP_SERVER_ID,
2252
- name: CODEX_APPS_MCP_SERVER_NAME,
2253
- url: CODEX_APPS_MCP_URL,
2254
- timeoutMs: CODEX_APPS_STARTUP_TIMEOUT_MS,
2255
- // Availability is credential-specific, so discover on every run.
2256
- cacheToolsList: false
2257
- }
2258
- ]
2284
+ mcpServers: [...withoutReservedId, canonicalServer]
2259
2285
  };
2260
2286
  }
2261
2287
  function settingsWithMcpCapabilityServers(settings, enabled) {
@@ -3229,7 +3255,7 @@ async function listRigChangesForApi(deps, workspaceId, rigId, limit) {
3229
3255
  import {
3230
3256
  getSessionTurnPersonalConnectionDelegations,
3231
3257
  getSocialConnection,
3232
- getWorkspaceGrant as getWorkspaceGrant2,
3258
+ getWorkspaceGrant as getWorkspaceGrant3,
3233
3259
  listConnectionsMetadata as listConnectionsMetadata2,
3234
3260
  listSocialConnections as listSocialConnections2
3235
3261
  } from "@opengeni/db";
@@ -3282,7 +3308,7 @@ async function authorizedSocialConnectionsForGrant(input) {
3282
3308
  )).filter((item) => item.connectionType === "social");
3283
3309
  const personal = [];
3284
3310
  for (const delegation of delegations) {
3285
- if (!await getWorkspaceGrant2(input.db, delegation.ownerSubjectId, input.grant.workspaceId))
3311
+ if (!await getWorkspaceGrant3(input.db, delegation.ownerSubjectId, input.grant.workspaceId))
3286
3312
  continue;
3287
3313
  const connection = await getSocialConnection(
3288
3314
  input.db,
@@ -3421,7 +3447,7 @@ async function freezePersonalConnectionDelegations(input) {
3421
3447
  });
3422
3448
  return includeSocial ? inherited : inherited.filter((item) => item.connectionType !== "social");
3423
3449
  }
3424
- const membership = await getWorkspaceGrant2(input.db, input.source.subjectId, input.workspaceId);
3450
+ const membership = await getWorkspaceGrant3(input.db, input.source.subjectId, input.workspaceId);
3425
3451
  if (!membership) return [];
3426
3452
  const mcp = personalConnectionDelegationsFromVisibleConnections({
3427
3453
  servers,
@@ -7205,6 +7231,7 @@ export {
7205
7231
  requireVariableSetEncryption,
7206
7232
  requireVariableSetForApi,
7207
7233
  resolveCapabilityPack,
7234
+ resolveCodexAppsCredentialIdForRun,
7208
7235
  resolveFirstPartyMcpToolsForCreate,
7209
7236
  resolveMemberSubjectId,
7210
7237
  resolveSessionToolPolicy,