@opengeni/core 2.6.4 → 2.7.2-canary.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.
@@ -54,6 +54,7 @@ import {
54
54
  } from "../session-authorization";
55
55
  import type { SessionWorkflowClient } from "../dependencies";
56
56
  import type { ObjectStorageDependency } from "../dependencies";
57
+ import { lockActiveCustomModelForAdmission, workspaceCustomModelReference } from "../model-catalog";
57
58
  import { settingsWithEnabledCapabilityMcpServers } from "./capabilities";
58
59
  import { validateVariableSetAttachment } from "./environments";
59
60
  import {
@@ -99,6 +100,28 @@ export function scheduledTaskToolsProvided(rawPayload: unknown): boolean {
99
100
  );
100
101
  }
101
102
 
103
+ function workspaceCustomModelCommitGuard(input: {
104
+ settings: Settings;
105
+ accountId: string;
106
+ workspaceId: string;
107
+ modelId: string;
108
+ }): ((tx: Database) => Promise<void>) | undefined {
109
+ const reference = workspaceCustomModelReference(input.settings, input.modelId);
110
+ if (!reference) return undefined;
111
+ return async (tx: Database): Promise<void> => {
112
+ const active = await lockActiveCustomModelForAdmission(tx, {
113
+ accountId: input.accountId,
114
+ workspaceId: input.workspaceId,
115
+ reference,
116
+ });
117
+ if (!active) {
118
+ throw new HTTPException(422, {
119
+ message: `model is not available: ${input.modelId}`,
120
+ });
121
+ }
122
+ };
123
+ }
124
+
102
125
  export function scheduledConnectionSurfaceEligibility(
103
126
  settings: Settings,
104
127
  target: Pick<Session, "firstPartyMcpTools" | "firstPartyMcpPermissions"> | null,
@@ -146,7 +169,7 @@ export async function createValidatedScheduledTask(input: {
146
169
  action: knowledgeAction,
147
170
  });
148
171
  }
149
- const agentConfig = knowledgeAction
172
+ const agentConfig: ScheduledTaskAgentConfig = knowledgeAction
150
173
  ? input.payload.agentConfig
151
174
  : await validateScheduledTaskAgentConfig({
152
175
  ...input,
@@ -235,6 +258,15 @@ export async function createValidatedScheduledTask(input: {
235
258
  workspaceId: input.grant.workspaceId,
236
259
  subjectId: input.grant.subjectId,
237
260
  });
261
+ const beforeCreateCommit =
262
+ !knowledgeAction && input.payload.runMode !== "existing_session"
263
+ ? workspaceCustomModelCommitGuard({
264
+ settings: input.settings,
265
+ accountId: input.grant.accountId,
266
+ workspaceId: input.grant.workspaceId,
267
+ modelId: agentConfig.model ?? input.settings.openaiModel,
268
+ })
269
+ : undefined;
238
270
  return await withScheduledTaskAuthorityWriteErrors(() =>
239
271
  createScheduledTask(input.db, {
240
272
  id,
@@ -257,6 +289,7 @@ export async function createValidatedScheduledTask(input: {
257
289
  variableSetId: input.payload.variableSetId ?? null,
258
290
  rigId: input.payload.rigId ?? null,
259
291
  metadata: input.payload.metadata,
292
+ ...(beforeCreateCommit ? { beforeCreateCommit } : {}),
260
293
  }),
261
294
  );
262
295
  }
@@ -734,6 +767,15 @@ export async function validatedScheduledTaskUpdate(input: {
734
767
  (input.payload.metadata !== undefined &&
735
768
  !isDeepStrictEqual(input.payload.metadata, input.existing.metadata)) ||
736
769
  (input.existing.status === "paused" && input.payload.status === "active");
770
+ if (materialExecutionChange && nextRunMode !== "existing_session") {
771
+ const beforeUpdateCommit = workspaceCustomModelCommitGuard({
772
+ settings: input.settings,
773
+ accountId: input.existing.accountId,
774
+ workspaceId: input.existing.workspaceId,
775
+ modelId: nextAgentConfig.model ?? input.settings.openaiModel,
776
+ });
777
+ if (beforeUpdateCommit) update.beforeUpdateCommit = beforeUpdateCommit;
778
+ }
737
779
  const existingXaiAuthority = await getScheduledTaskXaiProviderAccountAuthoritySnapshot(
738
780
  input.db,
739
781
  input.existing.workspaceId,