@opengeni/core 6.5.2-canary.41607687019001 → 6.7.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.
@@ -2,6 +2,12 @@ import { fetchCodexModels } from "@opengeni/codex";
2
2
  import { type Settings } from "@opengeni/config";
3
3
  import { listSubscriptionCoreCodexServingConnections, recordSubscriptionCoreCodexModelCatalog, type CodexCredentialTokenSnapshot, type Database } from "@opengeni/db";
4
4
  import type { ModelAvailabilityObservation } from "./model-catalog.js";
5
+ /**
6
+ * How long a display read (picker, page load) waits for a live account list
7
+ * before it uses the last known one. The live read keeps going and records
8
+ * its result, so the next read is fresh.
9
+ */
10
+ export declare const CODEX_CATALOG_DISPLAY_WAIT_MS = 300;
5
11
  /** The workspace, organization and acting subject of a Codex catalog read. */
6
12
  export type WorkspaceCodexCatalogContext = {
7
13
  accountId: string;
package/dist/index.js CHANGED
@@ -8126,6 +8126,7 @@ import {
8126
8126
  getSessionLineage,
8127
8127
  getSessionTurn,
8128
8128
  getSessionTurnInitiatingHumanSubjectId,
8129
+ sameTurnSender,
8129
8130
  readTurnBillingOrigin as readTurnBillingOrigin2,
8130
8131
  getSessionTurnForAttempt as getSessionTurnForAttempt2,
8131
8132
  getSessionTurnPersonalConnectionDelegations as getSessionTurnPersonalConnectionDelegations2,
@@ -13030,8 +13031,10 @@ import {
13030
13031
  SUBSCRIPTION_MODEL_CATALOG_TTL_MS
13031
13032
  } from "@opengeni/db";
13032
13033
  import { modelServiceTierCatalogEntry } from "@opengeni/contracts";
13034
+ import { startChildSpan } from "@opengeni/observability";
13033
13035
  var CATALOG_CACHE_MS = SUBSCRIPTION_MODEL_CATALOG_TTL_MS;
13034
13036
  var CATALOG_ERROR_CACHE_MS = 5e3;
13037
+ var CODEX_CATALOG_DISPLAY_WAIT_MS = 300;
13035
13038
  var catalogs = /* @__PURE__ */ new Map();
13036
13039
  var CATALOG_SERVICE_SUBJECT = "service:subscription-core";
13037
13040
  var defaultCatalogDependencies = () => ({
@@ -13161,6 +13164,60 @@ async function loadCoreConnectionCatalog(db, settings, context, connection, deps
13161
13164
  };
13162
13165
  }
13163
13166
  }
13167
+ async function readCoreConnectionCatalogForDisplay(db, settings, context, connection, deps, waitMs = CODEX_CATALOG_DISPLAY_WAIT_MS) {
13168
+ const observed = connection.modelCatalog;
13169
+ const now = Date.now();
13170
+ if (observed && observed.observedAt <= now && observed.expiresAt > now) {
13171
+ return {
13172
+ ok: true,
13173
+ slugs: observed.slugs,
13174
+ checkedAt: new Date(observed.observedAt).toISOString(),
13175
+ expiresAt: observed.expiresAt
13176
+ };
13177
+ }
13178
+ const previous = observed && observed.observedAt <= now ? observed : null;
13179
+ const span = startChildSpan(
13180
+ "codex.model_catalog.refresh",
13181
+ { "opengeni.model_catalog.previous": previous ? "expired" : "none" },
13182
+ "internal"
13183
+ );
13184
+ const live = loadCoreConnectionCatalog(db, settings, context, connection, deps);
13185
+ let timer;
13186
+ const settled = await Promise.race([
13187
+ live,
13188
+ new Promise((resolve) => {
13189
+ timer = setTimeout(() => resolve(null), waitMs);
13190
+ })
13191
+ ]);
13192
+ if (timer !== void 0) clearTimeout(timer);
13193
+ if (settled) {
13194
+ span?.end({
13195
+ attributes: {
13196
+ "opengeni.model_catalog.outcome": settled.ok ? "refreshed" : "unavailable"
13197
+ }
13198
+ });
13199
+ return settled;
13200
+ }
13201
+ span?.end({
13202
+ attributes: {
13203
+ "opengeni.model_catalog.outcome": previous ? "served_expired" : "served_unknown"
13204
+ }
13205
+ });
13206
+ if (previous) {
13207
+ return {
13208
+ ok: true,
13209
+ slugs: previous.slugs,
13210
+ checkedAt: new Date(previous.observedAt).toISOString(),
13211
+ expiresAt: previous.expiresAt
13212
+ };
13213
+ }
13214
+ return {
13215
+ ok: false,
13216
+ slugs: [],
13217
+ checkedAt: new Date(now).toISOString(),
13218
+ expiresAt: now + CATALOG_ERROR_CACHE_MS
13219
+ };
13220
+ }
13164
13221
  async function refreshCoreCodexModelEntitlements(db, settings, context, deps = defaultCatalogDependencies(), options = {}) {
13165
13222
  const idleExpiry = Date.now() + CATALOG_CACHE_MS;
13166
13223
  const connections = await deps.listServing(db, context);
@@ -13191,7 +13248,7 @@ async function loadWorkspaceCodexCatalogReadiness(db, settings, context, options
13191
13248
  const live = await Promise.all(
13192
13249
  shared.map(async (connection) => ({
13193
13250
  connection,
13194
- ...await loadCoreConnectionCatalog(db, settings, context, connection, deps)
13251
+ ...await readCoreConnectionCatalogForDisplay(db, settings, context, connection, deps)
13195
13252
  }))
13196
13253
  );
13197
13254
  const observations = {};
@@ -17835,7 +17892,7 @@ async function acceptSessionUserMessageInFileScope(deps, grant, workspaceId, ses
17835
17892
  if (draft2?.revision === input.expectedDraftRevision && draft2.sourceTurnId) {
17836
17893
  const sourceTurn = await getSessionTurn(db, workspaceId, draft2.sourceTurnId);
17837
17894
  if (sourceTurn?.sessionId === sessionId) {
17838
- frozenAdmissionInitiator = {
17895
+ const sourceInitiator = {
17839
17896
  initiator: sourceTurn.initiator,
17840
17897
  context: sourceTurn.initiatorContext,
17841
17898
  initiatingHumanSubjectId: await getSessionTurnInitiatingHumanSubjectId(
@@ -17844,6 +17901,9 @@ async function acceptSessionUserMessageInFileScope(deps, grant, workspaceId, ses
17844
17901
  sourceTurn.id
17845
17902
  )
17846
17903
  };
17904
+ if (sameTurnSender(sourceInitiator, frozenAdmissionInitiator)) {
17905
+ frozenAdmissionInitiator = sourceInitiator;
17906
+ }
17847
17907
  }
17848
17908
  }
17849
17909
  }
@@ -40800,6 +40860,7 @@ export {
40800
40860
  AZURE_SPEECH_PROVIDER_ID,
40801
40861
  ArchivedSessionImportError2 as ArchivedSessionImportError,
40802
40862
  BYOK_FALLBACK_LIST_RATE,
40863
+ CODEX_CATALOG_DISPLAY_WAIT_MS,
40803
40864
  CONNECTED_MACHINE_CAPABILITY_ID,
40804
40865
  CONVERSATION_ATTACHMENT_MAX_COUNT,
40805
40866
  CONVERSATION_ATTACHMENT_MEDIA_TYPE_MAX_UTF8_BYTES,