@opengeni/core 4.0.1 → 4.0.3-canary.36199476632001

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.
@@ -25,8 +25,10 @@ import {
25
25
  WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
26
26
  WORKSPACE_OPENROUTER_MODEL_ID_PREFIX,
27
27
  XAI_SUBSCRIPTION_MODEL_ID_PREFIX,
28
+ codeSearchDeploymentPolicy,
28
29
  type Settings,
29
30
  } from "@opengeni/config";
31
+ import type { CodeSearchDeploymentPolicy } from "@opengeni/contracts/code-search";
30
32
  import {
31
33
  AUTOMATIC_SESSION_TITLE_FALLBACK,
32
34
  CreateSessionRequest,
@@ -181,6 +183,7 @@ import {
181
183
  resolveWorkspaceCatalogSettings,
182
184
  workspaceCustomModelReference,
183
185
  } from "../model-catalog";
186
+ import { resolveDefaultSessionModel } from "../default-session-model";
184
187
  import { settingsWithEnabledCapabilityMcpServers } from "./capabilities";
185
188
  import {
186
189
  resolveSessionToolPolicy,
@@ -874,6 +877,9 @@ export async function createAndStartSessionWithOutcome(input: {
874
877
  // on the creating grant); null for direct API creates and scheduled runs.
875
878
  // When set, the worker's terminal-for-now transitions wake this parent.
876
879
  parentSessionId?: string | null;
880
+ // Deployment code_search policy for freezing a new root session's decision.
881
+ // Omitted falls back to the policy the process installed at boot.
882
+ codeSearchDeploymentPolicy?: CodeSearchDeploymentPolicy;
877
883
  // Workspace-scoped CREATE idempotency key. When present, a double-fire with
878
884
  // the same key (sequential retry OR concurrent race) collapses to a single
879
885
  // session. Every caller repairs or re-delivers the winner's one atomic start;
@@ -1181,6 +1187,9 @@ export async function createAndStartSessionWithOutcome(input: {
1181
1187
  ...(input.scopeSubjectId !== undefined ? { scopeSubjectId: input.scopeSubjectId } : {}),
1182
1188
  ...(input.memoryScope ? { memoryScope: input.memoryScope } : {}),
1183
1189
  parentSessionId: input.parentSessionId ?? null,
1190
+ ...(input.codeSearchDeploymentPolicy
1191
+ ? { codeSearchDeploymentPolicy: input.codeSearchDeploymentPolicy }
1192
+ : {}),
1184
1193
  sandboxGroupId: input.sandboxGroupId ?? null,
1185
1194
  ...(input.sandboxOs ? { sandboxOs: input.sandboxOs } : {}),
1186
1195
  mcpServers: input.mcpServers ?? [],
@@ -1409,8 +1418,9 @@ export function workflowIdForSession(sessionId: string): string {
1409
1418
  * the API edge with 422 rather than enqueuing a turn the worker can't honor.
1410
1419
  *
1411
1420
  * `model` is the effective value selected by the caller's boundary. Top-level
1412
- * omission defaults to `settings.openaiModel`; child-session omission inherits
1413
- * the worker-signed calling turn before reaching this helper. Centralized here
1421
+ * omission resolves the new-chat default (`resolveDefaultSessionModel`);
1422
+ * child-session omission inherits the worker-signed calling turn before
1423
+ * reaching this helper. Centralized here
1414
1424
  * so every model-carrying choke point
1415
1425
  * (create-session, user-message/turn-accept, queued-turn update, and
1416
1426
  * scheduled-task agentConfig — a scheduled task is a session the worker runs
@@ -1502,10 +1512,10 @@ export function assertSessionAllowsProductModel(
1502
1512
  * worker's authoritative post-resolution gate would fail. `model` is the
1503
1513
  * EFFECTIVE value the caller is about to persist: pass the explicit value at
1504
1514
  * message/turn-update/scheduled-task edges (omitted inherits an
1505
- * already-validated stored default), but at session CREATION pass
1506
- * `payload.model ?? settings.openaiModel` — an omitted model stamps the
1507
- * deployment default onto the session, and under a restricted policy that
1508
- * default may be exactly the provider the policy exists to block.
1515
+ * already-validated stored default), but at session CREATION pass the
1516
+ * effective model: an omitted model stamps the resolved default onto the
1517
+ * session, and under a restricted policy that default may be exactly the
1518
+ * provider the policy exists to block.
1509
1519
  */
1510
1520
  export async function assertWorkspaceModelPolicyAllows(
1511
1521
  db: Database,
@@ -2316,6 +2326,7 @@ async function createSessionForRequestInFileScope(
2316
2326
  ? grant.subjectId
2317
2327
  : null;
2318
2328
  let retainedKeyedShellModel: string | null = null;
2329
+ let retainedKeyedShellReasoningEffort: Session["reasoningEffort"] | null = null;
2319
2330
  if (
2320
2331
  payload.idempotencyKey &&
2321
2332
  (effectiveVisibility !== "user_private" || replayManagedHumanSubjectId !== null)
@@ -2346,6 +2357,7 @@ async function createSessionForRequestInFileScope(
2346
2357
  }
2347
2358
  if (initializedReplay.outcome === "pending") {
2348
2359
  retainedKeyedShellModel = initializedReplay.session.model;
2360
+ retainedKeyedShellReasoningEffort = initializedReplay.session.reasoningEffort;
2349
2361
  } else {
2350
2362
  if (initializedReplay.workflowWakeRevision !== null) {
2351
2363
  await unresolvedDeps.workflowClient.wakeSessionWorkflow({
@@ -2406,7 +2418,28 @@ async function createSessionForRequestInFileScope(
2406
2418
  payload.personalResourceAttachment,
2407
2419
  false,
2408
2420
  );
2409
- const inheritedModel = parentCallingTurn?.model ?? parentSession?.model ?? settings.openaiModel;
2421
+ // A top-level create that names no model gets the resolved new-chat default
2422
+ // (saved workspace default, then a usable connected subscription, then the
2423
+ // credits default while the organization holds credits, then the deployment
2424
+ // default). Children still inherit their calling turn, never this default.
2425
+ // A keyed retry of a still-uninitialized shell keeps the default that shell
2426
+ // already persisted instead of resolving again.
2427
+ const resolvedDefault =
2428
+ parentSession || payload.model !== undefined
2429
+ ? null
2430
+ : retainedKeyedShellModel !== null && retainedKeyedShellReasoningEffort !== null
2431
+ ? { model: retainedKeyedShellModel, reasoningEffort: retainedKeyedShellReasoningEffort }
2432
+ : await resolveDefaultSessionModel(db, settings, {
2433
+ accountId: grant.accountId,
2434
+ workspaceId,
2435
+ subjectId: grant.subjectId,
2436
+ workspaceSettings: workspace.settings,
2437
+ });
2438
+ const inheritedModel =
2439
+ parentCallingTurn?.model ??
2440
+ parentSession?.model ??
2441
+ resolvedDefault?.model ??
2442
+ settings.openaiModel;
2410
2443
  const effectiveModelId = payload.model ?? inheritedModel;
2411
2444
  const effectiveCatalogSettings = await resolveWorkspaceModelBoundarySettings(
2412
2445
  deps,
@@ -2737,6 +2770,7 @@ async function createSessionForRequestInFileScope(
2737
2770
  const inheritedReasoningEffort =
2738
2771
  parentCallingTurn?.reasoningEffort ??
2739
2772
  parentSession?.reasoningEffort ??
2773
+ resolvedDefault?.reasoningEffort ??
2740
2774
  settings.openaiReasoningEffort;
2741
2775
  const inheritedLatencyMode =
2742
2776
  parentCallingTurn?.latencyMode ?? parentSession?.latencyMode ?? "standard";
@@ -3268,6 +3302,7 @@ async function createSessionForRequestInFileScope(
3268
3302
  db,
3269
3303
  bus,
3270
3304
  workflowClient,
3305
+ codeSearchDeploymentPolicy: codeSearchDeploymentPolicy(deps.settings),
3271
3306
  accountId: grant.accountId,
3272
3307
  workspaceId,
3273
3308
  visibility: effectiveVisibility,
package/src/index.ts CHANGED
@@ -56,6 +56,7 @@ export {
56
56
  } from "./managed-session";
57
57
  export * from "./transcription";
58
58
  export * from "./model-catalog";
59
+ export * from "./default-session-model";
59
60
 
60
61
  // Sandbox fleet/routing service — the closure of `domain/sessions.ts`
61
62
  // (`swapActiveSandbox` + `FleetContext`). apps/api re-imports these for its MCP