@opengeni/api-router 6.7.0 → 6.8.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/app.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  withDefaultEnabledCapabilityMcpTools,
30
30
  workflowIdForSession,
31
31
  workspaceActorContextExempt
32
- } from "./chunk-WXI5VFFM.js";
32
+ } from "./chunk-A2VKA7K3.js";
33
33
  import "./chunk-OGQDXVXY.js";
34
34
  export {
35
35
  API_MAX_REQUEST_BODY_BYTES,
@@ -15,6 +15,7 @@ import {
15
15
  UPGRADE_PLAN_ACTION,
16
16
  byokRefusalAction,
17
17
  AllowanceExhaustedRefusal,
18
+ ModelPolicyRefusedError,
18
19
  ModelUnavailableError,
19
20
  ScheduledTaskTargetAccessChange
20
21
  } from "@opengeni/contracts";
@@ -241,6 +242,17 @@ function modelUnavailableHttpError(error) {
241
242
  details: { code: cause.code, modelId: cause.modelId }
242
243
  });
243
244
  }
245
+ function modelPolicyRefusedHttpError(error) {
246
+ const cause = error instanceof ModelPolicyRefusedError ? error : error instanceof HTTPException && error.cause instanceof ModelPolicyRefusedError ? error.cause : null;
247
+ if (!cause) return null;
248
+ return new ApiHttpError(422, {
249
+ code: "validation_failed",
250
+ message: cause.message,
251
+ retryable: false,
252
+ outcomeUnknown: false,
253
+ details: { code: cause.code, modelId: cause.modelId, reason: cause.reason }
254
+ });
255
+ }
244
256
  function connectionAccountSelectionHttpError(error) {
245
257
  if (!(error instanceof ConnectionAccountSelectionError)) return null;
246
258
  return new ApiHttpError(422, {
@@ -420,20 +432,51 @@ function codexOverviewProviderCall(owner2, organizationId2) {
420
432
  };
421
433
  }
422
434
 
435
+ // src/routes/codex-connect-models.ts
436
+ import {
437
+ CODEX_CLIENT_VERSION,
438
+ CODEX_PROVIDER_ID,
439
+ fetchCodexModels
440
+ } from "@opengeni/codex";
441
+ import { configuredModels, withCodexCatalogProvider } from "@opengeni/config";
442
+ function codexCatalogModels(settings, supportedSlugs) {
443
+ return configuredModels(withCodexCatalogProvider(settings)).filter(
444
+ (model) => model.providerId === CODEX_PROVIDER_ID && (supportedSlugs === void 0 || supportedSlugs.includes(model.upstreamModelId))
445
+ );
446
+ }
447
+ async function codexConnectOfferedModels(input) {
448
+ try {
449
+ const read = await fetchCodexModels(
450
+ {
451
+ accessToken: input.accessToken,
452
+ chatgptAccountId: input.chatgptAccountId,
453
+ isFedramp: input.isFedramp,
454
+ clientVersion: CODEX_CLIENT_VERSION
455
+ },
456
+ input.fetchImpl
457
+ );
458
+ if (!read.ok) return null;
459
+ return codexCatalogModels(input.settings, read.slugs).map((model) => ({
460
+ id: model.id,
461
+ label: model.label
462
+ }));
463
+ } catch {
464
+ return null;
465
+ }
466
+ }
467
+
423
468
  // src/routes/codex.ts
424
469
  import {
425
470
  environmentsEncryptionKeyBytes as environmentsEncryptionKeyBytes6,
426
- configuredModels,
427
471
  getSettings,
428
- productLabelForModelId,
429
- withCodexCatalogProvider
472
+ productLabelForModelId
430
473
  } from "@opengeni/config";
431
474
  import {
432
475
  accessTokenExpiry,
433
476
  buildCodexUsageWindowFromCache,
434
- CODEX_CLIENT_VERSION,
477
+ CODEX_CLIENT_VERSION as CODEX_CLIENT_VERSION2,
435
478
  CODEX_FIVE_HOUR_WINDOW_SECONDS,
436
- CODEX_PROVIDER_ID,
479
+ CODEX_PROVIDER_ID as CODEX_PROVIDER_ID2,
437
480
  CODEX_WEEKLY_WINDOW_SECONDS,
438
481
  CodexDeviceError,
439
482
  CodexReloginRequired,
@@ -755,11 +798,13 @@ async function coreCodexConnected(c, deps, input) {
755
798
  organizationId: input.accountId,
756
799
  subjectId: input.subjectId
757
800
  })).rotation.activeCredentialId : (await projection(deps, input.accountId, input.workspaceId, input.subjectId)).rotation.activeCredentialId;
801
+ const models = input.offeredModels ? await input.offeredModels().catch(() => null) : null;
758
802
  return c.json({
759
803
  status: "connected",
760
804
  plan: input.credential.planType,
761
805
  accountId: result2.id,
762
- isActive: activeCredentialId === result2.id
806
+ isActive: activeCredentialId === result2.id,
807
+ ...models ? { models } : {}
763
808
  });
764
809
  }
765
810
  function disconnectRefused(outcome) {
@@ -24307,7 +24352,7 @@ function registerSecretTools(server, deps, grant, sessionId, options = {}) {
24307
24352
  server.registerTool(
24308
24353
  "secret_save",
24309
24354
  {
24310
- description: 'Save or update a secret item (login, API key, note) and get its references back. For a new password use a field with `generate` (for example {name: "password", generate: {length: 24}}) and save it before typing it anywhere; copy an existing secret with `fromReference`. Put a username in `username`. saveTo picks the vault: user (Only me), task (this task) or workspace; it defaults to Only me when a person started this work, otherwise the workspace. Values are never echoed; avoid putting a literal `value` here unless the task gave you that exact value.',
24355
+ description: 'Save or update a secret item (login, API key, note) and get its references back. For a new password use a field with `generate` (for example {name: "password", generate: {length: 24}}) and save it before typing it anywhere; copy an existing secret with `fromReference`. Put a username in `username`; keys, tokens and passwords belong in concealed fields (a new plain field whose value looks like one is saved as concealed, reported in `fieldNotes`). saveTo picks the vault: user (Only me), task (this task) or workspace; it defaults to Only me when a person started this work, otherwise the workspace. Values are never echoed; avoid putting a literal `value` here unless the task gave you that exact value.',
24311
24356
  inputSchema: SecretSaveInput.shape
24312
24357
  },
24313
24358
  (input) => run2(
@@ -88320,12 +88365,10 @@ function codexUsageJson(payload) {
88320
88365
  return { status: payload.status, usage: payload };
88321
88366
  }
88322
88367
  function codexModelsForPicker(settings = getSettings(), supportedSlugs) {
88323
- return configuredModels(withCodexCatalogProvider(settings)).filter(
88324
- (model) => model.providerId === CODEX_PROVIDER_ID && (supportedSlugs === void 0 || supportedSlugs.includes(model.upstreamModelId))
88325
- ).map((model) => ({
88368
+ return codexCatalogModels(settings, supportedSlugs).map((model) => ({
88326
88369
  id: model.id,
88327
88370
  label: model.label,
88328
- provider: CODEX_PROVIDER_ID,
88371
+ provider: CODEX_PROVIDER_ID2,
88329
88372
  providerLabel: CODEX_PROVIDER_LABEL,
88330
88373
  api: "responses"
88331
88374
  }));
@@ -88819,7 +88862,14 @@ function registerCodexRoutes(app, deps) {
88819
88862
  accountEmail: id2.email ?? null,
88820
88863
  label: id2.email ?? id2.chatgptAccountId ?? null,
88821
88864
  connectedBySubjectId: (await managedCookieHuman2(c, deps))?.subjectId ?? null
88822
- }
88865
+ },
88866
+ offeredModels: async () => await codexConnectOfferedModels({
88867
+ settings: (await resolveCatalogSettings(db, settings)).settings,
88868
+ accessToken: tokens.accessToken,
88869
+ chatgptAccountId: id2.chatgptAccountId,
88870
+ isFedramp: id2.isFedramp,
88871
+ fetchImpl: deps.codexFetch
88872
+ })
88823
88873
  });
88824
88874
  });
88825
88875
  app.post("/v1/organizations/:organizationId/codex/accounts/:accountId/activate", async (c) => {
@@ -89032,7 +89082,14 @@ function registerCodexRoutes(app, deps) {
89032
89082
  accountEmail: id2.email ?? null,
89033
89083
  label: id2.email ?? id2.chatgptAccountId ?? null,
89034
89084
  connectedBySubjectId: connectingHuman?.subjectId ?? null
89035
- }
89085
+ },
89086
+ offeredModels: async () => await codexConnectOfferedModels({
89087
+ settings: (await resolveCatalogSettings(db, settings)).settings,
89088
+ accessToken: tokens.accessToken,
89089
+ chatgptAccountId: id2.chatgptAccountId,
89090
+ isFedramp: id2.isFedramp,
89091
+ fetchImpl: deps.codexFetch
89092
+ })
89036
89093
  });
89037
89094
  });
89038
89095
  app.get("/v1/workspaces/:workspaceId/codex/status", async (c) => {
@@ -89368,7 +89425,7 @@ async function coreOrganizationCodexOverview(c, deps, organizationId2, human, ra
89368
89425
  accessToken: token.accessToken,
89369
89426
  chatgptAccountId: token.chatgptAccountId,
89370
89427
  isFedramp: token.isFedramp,
89371
- clientVersion: CODEX_CLIENT_VERSION
89428
+ clientVersion: CODEX_CLIENT_VERSION2
89372
89429
  },
89373
89430
  provider.fetch
89374
89431
  );
@@ -89575,7 +89632,7 @@ async function coreCodexResetRedeem(c, deps, input, resolveTarget = () => worksp
89575
89632
  accessToken: token.accessToken,
89576
89633
  chatgptAccountId: token.chatgptAccountId,
89577
89634
  isFedramp: token.isFedramp,
89578
- clientVersion: CODEX_CLIENT_VERSION
89635
+ clientVersion: CODEX_CLIENT_VERSION2
89579
89636
  };
89580
89637
  const requestFetch = provider.fetch;
89581
89638
  if (attempt.status === "processing") {
@@ -89703,7 +89760,7 @@ async function coreCodexOverview(c, deps, grant, workspaceId) {
89703
89760
  accessToken: token.accessToken,
89704
89761
  chatgptAccountId: token.chatgptAccountId,
89705
89762
  isFedramp: token.isFedramp,
89706
- clientVersion: CODEX_CLIENT_VERSION
89763
+ clientVersion: CODEX_CLIENT_VERSION2
89707
89764
  },
89708
89765
  buildSubscriptionCoreCodexOperationFetch(deps.db, scope, null, connectionId, fetchImpl)
89709
89766
  );
@@ -94850,7 +94907,7 @@ import {
94850
94907
 
94851
94908
  // src/codex-realtime.ts
94852
94909
  import {
94853
- CODEX_CLIENT_VERSION as CODEX_CLIENT_VERSION2,
94910
+ CODEX_CLIENT_VERSION as CODEX_CLIENT_VERSION3,
94854
94911
  CodexRealtimeError,
94855
94912
  CodexReloginRequired as CodexReloginRequired2,
94856
94913
  createCodexRealtimeCall,
@@ -95121,7 +95178,7 @@ async function brokerSessionCodexRealtime(deps, input) {
95121
95178
  instructions: openGeniRealtimeInstructions(input.request.instructions)
95122
95179
  };
95123
95180
  try {
95124
- return await deps.createCall({ ...token, clientVersion: CODEX_CLIENT_VERSION2 }, callInput, {
95181
+ return await deps.createCall({ ...token, clientVersion: CODEX_CLIENT_VERSION3 }, callInput, {
95125
95182
  signal: input.signal
95126
95183
  });
95127
95184
  } catch (error) {
@@ -95135,7 +95192,7 @@ async function brokerSessionCodexRealtime(deps, input) {
95135
95192
  throw credentialError(error);
95136
95193
  }
95137
95194
  try {
95138
- return await deps.createCall({ ...token, clientVersion: CODEX_CLIENT_VERSION2 }, callInput, {
95195
+ return await deps.createCall({ ...token, clientVersion: CODEX_CLIENT_VERSION3 }, callInput, {
95139
95196
  signal: input.signal
95140
95197
  });
95141
95198
  } catch (error) {
@@ -95400,6 +95457,7 @@ import { isVaultError as isVaultError4, vaultErrorFromDatabase as vaultErrorFrom
95400
95457
  import { listSessionEventSlices } from "@opengeni/db/session-event-slices";
95401
95458
  import * as sessionPreviewSchema from "@opengeni/db/schema";
95402
95459
  import { SessionMessageSearchRequest as SessionMessageSearchRequest2 } from "@opengeni/contracts";
95460
+ import { ModelPolicyRefusedError as ModelPolicyRefusedError2, ModelUnavailableError as ModelUnavailableError2 } from "@opengeni/contracts";
95403
95461
  import { ContinueAfterCapabilitySetupRequest as ContinueAfterCapabilitySetupRequest2 } from "@opengeni/contracts";
95404
95462
  import {
95405
95463
  enqueueCapabilitySetupContinuation,
@@ -103511,6 +103569,30 @@ function sessionCreateErrorResponse(c, error) {
103511
103569
  422
103512
103570
  );
103513
103571
  }
103572
+ if (error instanceof HTTPException68 && error.status === 422 && error.cause instanceof ModelUnavailableError2) {
103573
+ return c.json(
103574
+ {
103575
+ code: "SESSION_CREATE_REJECTED",
103576
+ message: error.message,
103577
+ details: { code: error.cause.code, modelId: error.cause.modelId }
103578
+ },
103579
+ 422
103580
+ );
103581
+ }
103582
+ if (error instanceof HTTPException68 && error.status === 422 && error.cause instanceof ModelPolicyRefusedError2) {
103583
+ return c.json(
103584
+ {
103585
+ code: "SESSION_CREATE_REJECTED",
103586
+ message: error.message,
103587
+ details: {
103588
+ code: error.cause.code,
103589
+ modelId: error.cause.modelId,
103590
+ reason: error.cause.reason
103591
+ }
103592
+ },
103593
+ 422
103594
+ );
103595
+ }
103514
103596
  if (error instanceof HTTPException68 && error.status === 422) {
103515
103597
  return c.json(
103516
103598
  {
@@ -103657,6 +103739,7 @@ var PERMISSIONS = new Set(Permission4.options);
103657
103739
  var DETAIL_CODE = /^[A-Za-z][A-Za-z0-9_.-]{0,63}$/;
103658
103740
  var MISSING_PERMISSION = /^missing (?:literal )?permission: ([a-z][a-z0-9-]*:[a-z][a-z0-9-]*)/;
103659
103741
  var CONTROL_CODE = /^[a-z][a-z0-9_]{0,31}$/;
103742
+ var ROUTE_CODE = /^[A-Z][A-Z0-9_]{2,63}$/;
103660
103743
  var MAX_ENVELOPE_BYTES = 32 * 1024;
103661
103744
  var UNCLASSIFIED_REJECTION_REASON = "unclassified";
103662
103745
  function rejectionFingerprint(message) {
@@ -103673,16 +103756,19 @@ function permissionReason(permission) {
103673
103756
  return typeof permission === "string" && PERMISSIONS.has(permission) ? `permission:${permission}` : null;
103674
103757
  }
103675
103758
  function httpRejectionFactsFromEnvelope(envelope, fallbackCode) {
103676
- const error = envelope && typeof envelope === "object" && "error" in envelope ? envelope.error : void 0;
103759
+ const body6 = envelope && typeof envelope === "object" ? envelope : void 0;
103760
+ const routeShaped = body6 !== void 0 && !("error" in body6) && typeof body6.code === "string" && ROUTE_CODE.test(body6.code);
103761
+ const error = routeShaped ? body6 : body6?.error;
103677
103762
  const record11 = error && typeof error === "object" ? error : {};
103678
103763
  const code = typeof record11.code === "string" && ERROR_CODES.has(record11.code) ? record11.code : fallbackCode;
103679
103764
  const message = typeof record11.message === "string" ? record11.message : void 0;
103680
103765
  const details = record11.details && typeof record11.details === "object" ? record11.details : void 0;
103681
103766
  const detailCode = typeof details?.code === "string" && DETAIL_CODE.test(details.code) ? details.code : null;
103682
103767
  const controlCode = typeof details?.controlFailureCode === "string" && CONTROL_CODE.test(details.controlFailureCode) ? `control:${details.controlFailureCode}` : null;
103768
+ const routeCode = routeShaped && typeof record11.code === "string" && !ERROR_CODES.has(record11.code) ? record11.code : null;
103683
103769
  return {
103684
103770
  code,
103685
- reason: permissionReason(details?.permission) ?? rejectionReasonFromMessage(message) ?? detailCode ?? controlCode ?? UNCLASSIFIED_REJECTION_REASON,
103771
+ reason: permissionReason(details?.permission) ?? rejectionReasonFromMessage(message) ?? detailCode ?? controlCode ?? routeCode ?? UNCLASSIFIED_REJECTION_REASON,
103686
103772
  ...message ? { fingerprint: rejectionFingerprint(message) } : {}
103687
103773
  };
103688
103774
  }
@@ -147268,7 +147354,7 @@ function chatCompletionError(error) {
147268
147354
  // src/model-calls/service.ts
147269
147355
  import {
147270
147356
  buildModelResolver,
147271
- CODEX_CLIENT_VERSION as CODEX_CLIENT_VERSION3,
147357
+ CODEX_CLIENT_VERSION as CODEX_CLIENT_VERSION4,
147272
147358
  CodexReloginRequired as CodexReloginRequired3,
147273
147359
  codexRequestStorage
147274
147360
  } from "@opengeni/codex";
@@ -147791,7 +147877,7 @@ async function withCodexOperation(deps, settings, input, model, run2) {
147791
147877
  let pending2 = null;
147792
147878
  let sequence = 0;
147793
147879
  const context = {
147794
- clientVersion: CODEX_CLIENT_VERSION3,
147880
+ clientVersion: CODEX_CLIENT_VERSION4,
147795
147881
  getToken: () => resolver.getToken(),
147796
147882
  refresh: () => resolver.refresh(),
147797
147883
  resolveModel,
@@ -155835,7 +155921,7 @@ function createAppComposition(deps) {
155835
155921
  retryable: false,
155836
155922
  outcomeUnknown: false,
155837
155923
  details: { code: rawError.code }
155838
- }) : missingPermissionHttpError(rawError) ?? sessionUsageLimitHttpError(rawError) ?? allowanceExhaustedHttpError(rawError) ?? insufficientCreditsHttpError(rawError) ?? subscriptionSettingsLockedHttpError(rawError) ?? workspaceControlBusyHttpError(rawError) ?? regionRestrictedHttpError(rawError) ?? scheduledTaskTargetAccessHttpError(rawError) ?? agentConfigHttpError(rawError) ?? modelUnavailableHttpError(rawError) ?? connectionAccountSelectionHttpError(rawError) ?? (rawError instanceof UnsupportedLatencyModeError2 ? new ApiHttpError(422, {
155924
+ }) : missingPermissionHttpError(rawError) ?? sessionUsageLimitHttpError(rawError) ?? allowanceExhaustedHttpError(rawError) ?? insufficientCreditsHttpError(rawError) ?? subscriptionSettingsLockedHttpError(rawError) ?? workspaceControlBusyHttpError(rawError) ?? regionRestrictedHttpError(rawError) ?? scheduledTaskTargetAccessHttpError(rawError) ?? agentConfigHttpError(rawError) ?? modelUnavailableHttpError(rawError) ?? modelPolicyRefusedHttpError(rawError) ?? connectionAccountSelectionHttpError(rawError) ?? (rawError instanceof UnsupportedLatencyModeError2 ? new ApiHttpError(422, {
155839
155925
  code: "validation_failed",
155840
155926
  message: rawError.message,
155841
155927
  retryable: false,
@@ -157345,4 +157431,4 @@ export {
157345
157431
  withDefaultEnabledCapabilityMcpTools,
157346
157432
  workflowIdForSession4 as workflowIdForSession
157347
157433
  };
157348
- //# sourceMappingURL=chunk-WXI5VFFM.js.map
157434
+ //# sourceMappingURL=chunk-A2VKA7K3.js.map