@opengeni/core 0.20.11 → 0.20.13
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/domain/capabilities.d.ts +1 -0
- package/dist/domain/personal-connection-delegations.d.ts +10 -1
- package/dist/index.js +87 -11
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/domain/capabilities.ts +5 -4
- package/src/domain/personal-connection-delegations.ts +96 -5
- package/src/domain/scheduled-tasks.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { McpServerConfig, Settings } from "@opengeni/config";
|
|
2
|
-
import type { AccessGrant, ConnectionMetadata, McpPersonalConnectionDelegation, SessionTurn, ToolRef } from "@opengeni/contracts";
|
|
2
|
+
import type { AccessGrant, ConnectionMetadata, McpPersonalConnectionDelegation, SessionTurn, SocialConnection, ToolRef } from "@opengeni/contracts";
|
|
3
3
|
import { type Database, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult } from "@opengeni/db";
|
|
4
4
|
export type PersonalConnectionDelegationSource = {
|
|
5
5
|
kind: "subject";
|
|
@@ -11,8 +11,17 @@ export type PersonalConnectionDelegationSource = {
|
|
|
11
11
|
} | {
|
|
12
12
|
kind: "none";
|
|
13
13
|
};
|
|
14
|
+
export type AuthorizedSocialConnection = {
|
|
15
|
+
connection: SocialConnection;
|
|
16
|
+
subjectId: string | null;
|
|
17
|
+
};
|
|
14
18
|
export declare function directPersonalConnectionSubjectId(turn: Pick<SessionTurn, "source" | "initiator" | "initiatorContext">): string | undefined;
|
|
15
19
|
export declare function personalConnectionDelegationSourceForGrant(grant: AccessGrant): PersonalConnectionDelegationSource;
|
|
20
|
+
export declare function authorizedSocialConnectionsForGrant(input: {
|
|
21
|
+
db: Database;
|
|
22
|
+
grant: AccessGrant;
|
|
23
|
+
limit?: number;
|
|
24
|
+
}): Promise<AuthorizedSocialConnection[]>;
|
|
16
25
|
export declare function selectedPersonalConnectionServers(settings: Pick<Settings, "mcpServers">, tools: ToolRef[]): McpServerConfig[];
|
|
17
26
|
export declare function personalConnectionDelegationsFromVisibleConnections(input: {
|
|
18
27
|
servers: McpServerConfig[];
|
package/dist/index.js
CHANGED
|
@@ -1752,7 +1752,7 @@ async function buildCapabilityCatalog(input) {
|
|
|
1752
1752
|
listCapabilityInstallations(input.db, input.workspaceId),
|
|
1753
1753
|
listPackInstallations2(input.db, input.workspaceId),
|
|
1754
1754
|
listWorkspaceCapabilityPacks(input.db, input.workspaceId),
|
|
1755
|
-
listSocialConnections(input.db, input.workspaceId, 500),
|
|
1755
|
+
listSocialConnections(input.db, input.workspaceId, 500, input.subjectId),
|
|
1756
1756
|
discoverBundledSkills(),
|
|
1757
1757
|
discoverCuratedSkillLibraryItems()
|
|
1758
1758
|
]);
|
|
@@ -2456,11 +2456,11 @@ function platformApiCatalogItems(socialConnections) {
|
|
|
2456
2456
|
notes: "Account access is provided through OpenGeni's first-party social tools."
|
|
2457
2457
|
},
|
|
2458
2458
|
enabled: xEnabled,
|
|
2459
|
-
enabledReason: xEnabled ? xConnection.status === "connected" ?
|
|
2459
|
+
enabledReason: xEnabled ? xConnection.status === "connected" ? `${xConnection.ownership} social account connected` : `${xConnection.ownership} social account needs reconnection` : null,
|
|
2460
2460
|
metadata: {
|
|
2461
2461
|
connectorMode: "first_party_social",
|
|
2462
2462
|
provider: "x",
|
|
2463
|
-
ownership: "workspace",
|
|
2463
|
+
ownership: xConnection?.ownership ?? "workspace",
|
|
2464
2464
|
firstPartyMcpTools: [
|
|
2465
2465
|
"social_connections_list",
|
|
2466
2466
|
"social_posts_recent",
|
|
@@ -3228,8 +3228,10 @@ async function listRigChangesForApi(deps, workspaceId, rigId, limit) {
|
|
|
3228
3228
|
// src/domain/personal-connection-delegations.ts
|
|
3229
3229
|
import {
|
|
3230
3230
|
getSessionTurnPersonalConnectionDelegations,
|
|
3231
|
+
getSocialConnection,
|
|
3231
3232
|
getWorkspaceGrant as getWorkspaceGrant2,
|
|
3232
|
-
listConnectionsMetadata as listConnectionsMetadata2
|
|
3233
|
+
listConnectionsMetadata as listConnectionsMetadata2,
|
|
3234
|
+
listSocialConnections as listSocialConnections2
|
|
3233
3235
|
} from "@opengeni/db";
|
|
3234
3236
|
function directPersonalConnectionSubjectId(turn) {
|
|
3235
3237
|
if (turn.source !== "user" && turn.source !== "api" || turn.initiator.kind !== "subject") {
|
|
@@ -3250,6 +3252,51 @@ function personalConnectionDelegationSourceForGrant(grant) {
|
|
|
3250
3252
|
}
|
|
3251
3253
|
return { kind: "subject", subjectId: grant.subjectId };
|
|
3252
3254
|
}
|
|
3255
|
+
async function authorizedSocialConnectionsForGrant(input) {
|
|
3256
|
+
const workspace = await listSocialConnections2(
|
|
3257
|
+
input.db,
|
|
3258
|
+
input.grant.workspaceId,
|
|
3259
|
+
input.limit ?? 500,
|
|
3260
|
+
null
|
|
3261
|
+
);
|
|
3262
|
+
const source = personalConnectionDelegationSourceForGrant(input.grant);
|
|
3263
|
+
if (source.kind === "none")
|
|
3264
|
+
return workspace.map((connection) => ({ connection, subjectId: null }));
|
|
3265
|
+
if (source.kind === "subject") {
|
|
3266
|
+
const visible = await listSocialConnections2(
|
|
3267
|
+
input.db,
|
|
3268
|
+
input.grant.workspaceId,
|
|
3269
|
+
input.limit ?? 500,
|
|
3270
|
+
source.subjectId
|
|
3271
|
+
);
|
|
3272
|
+
return visible.map((connection) => ({
|
|
3273
|
+
connection,
|
|
3274
|
+
subjectId: connection.ownership === "personal" ? source.subjectId : null
|
|
3275
|
+
}));
|
|
3276
|
+
}
|
|
3277
|
+
const delegations = (await getSessionTurnPersonalConnectionDelegations(
|
|
3278
|
+
input.db,
|
|
3279
|
+
input.grant.workspaceId,
|
|
3280
|
+
source.sessionId,
|
|
3281
|
+
source.turnId
|
|
3282
|
+
)).filter((item) => item.connectionType === "social");
|
|
3283
|
+
const personal = [];
|
|
3284
|
+
for (const delegation of delegations) {
|
|
3285
|
+
if (!await getWorkspaceGrant2(input.db, delegation.ownerSubjectId, input.grant.workspaceId))
|
|
3286
|
+
continue;
|
|
3287
|
+
const connection = await getSocialConnection(
|
|
3288
|
+
input.db,
|
|
3289
|
+
input.grant.workspaceId,
|
|
3290
|
+
delegation.connectionId,
|
|
3291
|
+
delegation.ownerSubjectId
|
|
3292
|
+
);
|
|
3293
|
+
if (!connection || connection.ownership !== "personal") continue;
|
|
3294
|
+
const domain = connection.provider === "x" ? "x.com" : `${connection.provider}.com`;
|
|
3295
|
+
if (!sameProviderDomain(domain, delegation.providerDomain)) continue;
|
|
3296
|
+
personal.push({ connection, subjectId: delegation.ownerSubjectId });
|
|
3297
|
+
}
|
|
3298
|
+
return [...workspace.map((connection) => ({ connection, subjectId: null })), ...personal];
|
|
3299
|
+
}
|
|
3253
3300
|
function selectedPersonalConnectionServers(settings, tools) {
|
|
3254
3301
|
const selected = new Set(tools.map((tool) => tool.id));
|
|
3255
3302
|
return settings.mcpServers.filter(
|
|
@@ -3291,7 +3338,7 @@ function personalConnectionDelegationsFromVisibleConnections(input) {
|
|
|
3291
3338
|
return delegations;
|
|
3292
3339
|
}
|
|
3293
3340
|
function personalConnectionDelegationsFromParent(input) {
|
|
3294
|
-
|
|
3341
|
+
const mcp = input.servers.flatMap((server) => {
|
|
3295
3342
|
const ref = server.connectionRef;
|
|
3296
3343
|
if (!ref || ref.subjectScope !== "subject") return [];
|
|
3297
3344
|
const delegation = input.parentDelegations.find(
|
|
@@ -3299,13 +3346,17 @@ function personalConnectionDelegationsFromParent(input) {
|
|
|
3299
3346
|
);
|
|
3300
3347
|
return delegation ? [{ ...delegation }] : [];
|
|
3301
3348
|
});
|
|
3349
|
+
return [
|
|
3350
|
+
...mcp,
|
|
3351
|
+
...input.parentDelegations.filter((item) => item.connectionType === "social").map((item) => ({ ...item }))
|
|
3352
|
+
];
|
|
3302
3353
|
}
|
|
3303
3354
|
function personalConnectionDelegationsEqual(left, right) {
|
|
3304
3355
|
if (left.length !== right.length) return false;
|
|
3305
3356
|
const byServer = new Map(right.map((delegation) => [delegation.serverId, delegation]));
|
|
3306
3357
|
return left.every((delegation) => {
|
|
3307
3358
|
const other = byServer.get(delegation.serverId);
|
|
3308
|
-
return other?.connectionId === delegation.connectionId && other.ownerSubjectId === delegation.ownerSubjectId && sameProviderDomain(other.providerDomain, delegation.providerDomain) && other.kind === delegation.kind;
|
|
3359
|
+
return other?.connectionId === delegation.connectionId && other.ownerSubjectId === delegation.ownerSubjectId && sameProviderDomain(other.providerDomain, delegation.providerDomain) && other.kind === delegation.kind && other.connectionType === delegation.connectionType;
|
|
3309
3360
|
});
|
|
3310
3361
|
}
|
|
3311
3362
|
function personalConnectionDelegationForServer(delegations, server) {
|
|
@@ -3356,9 +3407,10 @@ function withFrozenPersonalConnectionDelegations(input) {
|
|
|
3356
3407
|
}
|
|
3357
3408
|
async function freezePersonalConnectionDelegations(input) {
|
|
3358
3409
|
const servers = selectedPersonalConnectionServers(input.settings, input.tools);
|
|
3359
|
-
|
|
3410
|
+
const includeSocial = input.tools.some((tool) => tool.id === "opengeni");
|
|
3411
|
+
if (servers.length === 0 && !includeSocial || input.source.kind === "none") return [];
|
|
3360
3412
|
if (input.source.kind === "turn") {
|
|
3361
|
-
|
|
3413
|
+
const inherited = personalConnectionDelegationsFromParent({
|
|
3362
3414
|
servers,
|
|
3363
3415
|
parentDelegations: await getSessionTurnPersonalConnectionDelegations(
|
|
3364
3416
|
input.db,
|
|
@@ -3367,14 +3419,37 @@ async function freezePersonalConnectionDelegations(input) {
|
|
|
3367
3419
|
input.source.turnId
|
|
3368
3420
|
)
|
|
3369
3421
|
});
|
|
3422
|
+
return includeSocial ? inherited : inherited.filter((item) => item.connectionType !== "social");
|
|
3370
3423
|
}
|
|
3371
3424
|
const membership = await getWorkspaceGrant2(input.db, input.source.subjectId, input.workspaceId);
|
|
3372
3425
|
if (!membership) return [];
|
|
3373
|
-
|
|
3426
|
+
const mcp = personalConnectionDelegationsFromVisibleConnections({
|
|
3374
3427
|
servers,
|
|
3375
3428
|
subjectId: input.source.subjectId,
|
|
3376
3429
|
connections: await listConnectionsMetadata2(input.db, input.workspaceId, input.source.subjectId)
|
|
3377
3430
|
});
|
|
3431
|
+
if (!includeSocial) return mcp;
|
|
3432
|
+
const ownerSubjectId = input.source.subjectId;
|
|
3433
|
+
const visible = await listSocialConnections2(input.db, input.workspaceId, 500, ownerSubjectId);
|
|
3434
|
+
const latest = /* @__PURE__ */ new Map();
|
|
3435
|
+
for (const connection of visible) {
|
|
3436
|
+
if (connection.ownership !== "personal" || connection.status !== "connected" || connection.provider !== "x" && connection.provider !== "reddit")
|
|
3437
|
+
continue;
|
|
3438
|
+
const prior = latest.get(connection.provider);
|
|
3439
|
+
if (!prior || connection.updatedAt > prior.updatedAt)
|
|
3440
|
+
latest.set(connection.provider, connection);
|
|
3441
|
+
}
|
|
3442
|
+
return [
|
|
3443
|
+
...mcp,
|
|
3444
|
+
...[...latest.values()].map((connection) => ({
|
|
3445
|
+
serverId: `social:${connection.provider}`,
|
|
3446
|
+
connectionId: connection.id,
|
|
3447
|
+
ownerSubjectId,
|
|
3448
|
+
providerDomain: connection.provider === "x" ? "x.com" : `${connection.provider}.com`,
|
|
3449
|
+
kind: "oauth2",
|
|
3450
|
+
connectionType: "social"
|
|
3451
|
+
}))
|
|
3452
|
+
];
|
|
3378
3453
|
}
|
|
3379
3454
|
|
|
3380
3455
|
// src/domain/resources.ts
|
|
@@ -5371,7 +5446,7 @@ async function createValidatedScheduledTask(input) {
|
|
|
5371
5446
|
db: input.db,
|
|
5372
5447
|
workspaceId: input.grant.workspaceId,
|
|
5373
5448
|
settings: runtimeSettings,
|
|
5374
|
-
tools: agentConfig.tools,
|
|
5449
|
+
tools: [...agentConfig.tools, { kind: "mcp", id: "opengeni" }],
|
|
5375
5450
|
source: personalConnectionDelegationSourceForGrant(input.grant)
|
|
5376
5451
|
});
|
|
5377
5452
|
const creationInitiator = creationInitiatorForGrant(input.grant);
|
|
@@ -5479,7 +5554,7 @@ async function validatedScheduledTaskUpdate(input) {
|
|
|
5479
5554
|
db: input.db,
|
|
5480
5555
|
workspaceId: input.existing.workspaceId,
|
|
5481
5556
|
settings: runtimeSettings,
|
|
5482
|
-
tools: nextAgentConfig.tools,
|
|
5557
|
+
tools: [...nextAgentConfig.tools, { kind: "mcp", id: "opengeni" }],
|
|
5483
5558
|
source: personalConnectionDelegationSourceForGrant(input.grant)
|
|
5484
5559
|
});
|
|
5485
5560
|
if (input.existing.reusableSessionId && input.existing.runMode === "reusable_session") {
|
|
@@ -7036,6 +7111,7 @@ export {
|
|
|
7036
7111
|
assertWorkspaceDeletable,
|
|
7037
7112
|
assertWorkspaceMemberRemovable,
|
|
7038
7113
|
assertWorkspaceModelPolicyAllows,
|
|
7114
|
+
authorizedSocialConnectionsForGrant,
|
|
7039
7115
|
availableToolRefs,
|
|
7040
7116
|
buildCapabilityCatalog,
|
|
7041
7117
|
buildFleetContextForSession,
|