@opengeni/db 0.22.1 → 0.22.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeni/db",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "description": "OpenGeni persistence: Drizzle schema, RLS-scoped query layer, the SQL migration runner, and role provisioning.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@opengeni/codex": "^0.2.9",
54
- "@opengeni/config": "^0.10.0",
55
- "@opengeni/contracts": "^0.31.0",
54
+ "@opengeni/config": "^0.10.1",
55
+ "@opengeni/contracts": "^0.31.1",
56
56
  "@opengeni/network": "^0.1.1",
57
57
  "drizzle-orm": "^0.45.2",
58
58
  "postgres": "^3.4.7"
package/src/index.ts CHANGED
@@ -146,7 +146,12 @@ import {
146
146
  SubmitHumanInputResponseRequest,
147
147
  TurnExecutionPolicyV1,
148
148
  } from "@opengeni/contracts";
149
- import { environmentsEncryptionKeyBytes, type Settings } from "@opengeni/config";
149
+ import {
150
+ environmentsEncryptionKeyBytes,
151
+ VERCEL_AI_GATEWAY_CONNECTION_DOMAIN,
152
+ VERCEL_AI_GATEWAY_CONNECTION_ROLE,
153
+ type Settings,
154
+ } from "@opengeni/config";
150
155
  import { boundModelToolOutputItem, isCodexBilledModel } from "@opengeni/codex";
151
156
  // Re-exported so consumers get the whole codex-billed detection surface (the pure
152
157
  // prefix test + the credential-aware predicates below) from a single import.
@@ -7237,6 +7242,56 @@ export async function loadConnectionCredentialForBroker(
7237
7242
  );
7238
7243
  }
7239
7244
 
7245
+ export async function workspaceVercelAiGatewayConnectionActive(
7246
+ db: Database,
7247
+ workspaceId: string,
7248
+ ): Promise<boolean> {
7249
+ const connections = await listConnectionsMetadata(db, workspaceId, null);
7250
+ return connections.some(
7251
+ (connection) =>
7252
+ connection.subjectId === null &&
7253
+ connection.providerDomain === VERCEL_AI_GATEWAY_CONNECTION_DOMAIN &&
7254
+ connection.kind === "api_key" &&
7255
+ connection.status === "active" &&
7256
+ connection.metadata.credentialRole === VERCEL_AI_GATEWAY_CONNECTION_ROLE,
7257
+ );
7258
+ }
7259
+
7260
+ /** Resolve only the reviewed workspace-shared AI Gateway credential shape. */
7261
+ export async function loadWorkspaceVercelAiGatewayApiKey(
7262
+ db: Database,
7263
+ settings: Settings,
7264
+ workspaceId: string,
7265
+ ): Promise<string | null> {
7266
+ const metadata = (await listConnectionsMetadata(db, workspaceId, null)).find(
7267
+ (connection) =>
7268
+ connection.subjectId === null &&
7269
+ connection.providerDomain === VERCEL_AI_GATEWAY_CONNECTION_DOMAIN &&
7270
+ connection.kind === "api_key" &&
7271
+ connection.status === "active" &&
7272
+ connection.metadata.credentialRole === VERCEL_AI_GATEWAY_CONNECTION_ROLE,
7273
+ );
7274
+ if (!metadata) {
7275
+ return null;
7276
+ }
7277
+ const connection = await loadConnectionCredentialForBroker(db, settings, {
7278
+ workspaceId,
7279
+ connectionId: metadata.id,
7280
+ providerDomain: VERCEL_AI_GATEWAY_CONNECTION_DOMAIN,
7281
+ kind: "api_key",
7282
+ allowSubjectOwned: false,
7283
+ });
7284
+ if (
7285
+ !connection ||
7286
+ connection.status !== "active" ||
7287
+ connection.metadata.credentialRole !== VERCEL_AI_GATEWAY_CONNECTION_ROLE
7288
+ ) {
7289
+ return null;
7290
+ }
7291
+ const apiKey = connection.credential.apiKey;
7292
+ return typeof apiKey === "string" && apiKey.trim().length > 0 ? apiKey : null;
7293
+ }
7294
+
7240
7295
  export async function recordConnectionTokenRefresh(
7241
7296
  db: Database,
7242
7297
  input: {