@opengeni/db 4.0.0-canary.2 → 4.0.0-canary.3
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/canonical-human-identities.js +3 -3
- package/dist/{chunk-B5Y3TCSP.js → chunk-3JGOYOWD.js} +2 -2
- package/dist/{chunk-NPKBYGAK.js → chunk-CZXYNVEU.js} +2 -2
- package/dist/{chunk-L2QFSPFP.js → chunk-DIFDLF2C.js} +2 -2
- package/dist/{chunk-XIYAXH47.js → chunk-GPKHEPVX.js} +2 -2
- package/dist/{chunk-CQF6G4IF.js → chunk-HUCU5BDD.js} +3 -3
- package/dist/{chunk-VU2IK37Y.js → chunk-OWZ36ST7.js} +2 -2
- package/dist/{chunk-DUB3LUVM.js → chunk-R6LIJYG6.js} +140 -8
- package/dist/chunk-R6LIJYG6.js.map +1 -0
- package/dist/{chunk-PWJJKCTF.js → chunk-WU3MSPZS.js} +19 -2
- package/dist/chunk-WU3MSPZS.js.map +1 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/schema.d.ts +85 -0
- package/dist/schema.js +1 -1
- package/dist/session-background-commands.js +4 -4
- package/dist/session-command-output.js +4 -4
- package/dist/session-control.d.ts +26 -1
- package/dist/session-event-slices.js +2 -2
- package/dist/session-tenancy.js +3 -3
- package/dist/video-generation.js +3 -3
- package/drizzle/0420_workspace_pause_timers.sql +53 -0
- package/package.json +6 -6
- package/src/index.ts +21 -0
- package/src/schema.ts +20 -1
- package/src/session-control.ts +177 -4
- package/dist/chunk-DUB3LUVM.js.map +0 -1
- package/dist/chunk-PWJJKCTF.js.map +0 -1
- /package/dist/{chunk-B5Y3TCSP.js.map → chunk-3JGOYOWD.js.map} +0 -0
- /package/dist/{chunk-NPKBYGAK.js.map → chunk-CZXYNVEU.js.map} +0 -0
- /package/dist/{chunk-L2QFSPFP.js.map → chunk-DIFDLF2C.js.map} +0 -0
- /package/dist/{chunk-XIYAXH47.js.map → chunk-GPKHEPVX.js.map} +0 -0
- /package/dist/{chunk-CQF6G4IF.js.map → chunk-HUCU5BDD.js.map} +0 -0
- /package/dist/{chunk-VU2IK37Y.js.map → chunk-OWZ36ST7.js.map} +0 -0
|
@@ -11,9 +11,9 @@ import {
|
|
|
11
11
|
getCanonicalHumanIdentityProjection,
|
|
12
12
|
synchronizeCanonicalHumanLoginBindings,
|
|
13
13
|
validateCanonicalHumanSession
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-CZXYNVEU.js";
|
|
15
|
+
import "./chunk-GPKHEPVX.js";
|
|
16
|
+
import "./chunk-WU3MSPZS.js";
|
|
17
17
|
import "./chunk-PZ5AY32C.js";
|
|
18
18
|
export {
|
|
19
19
|
CanonicalHumanIdentityAuthorityError,
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
withWorkspaceRls,
|
|
6
6
|
withWorkspaceSubjectRls,
|
|
7
7
|
withWorkspaceSubjectSessionActivityRls
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GPKHEPVX.js";
|
|
9
9
|
|
|
10
10
|
// src/session-tenancy.ts
|
|
11
11
|
import { createHash } from "crypto";
|
|
@@ -481,4 +481,4 @@ export {
|
|
|
481
481
|
forkSessionContent,
|
|
482
482
|
replayAppliedSessionFork
|
|
483
483
|
};
|
|
484
|
-
//# sourceMappingURL=chunk-
|
|
484
|
+
//# sourceMappingURL=chunk-3JGOYOWD.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nestedPostgresSqlState,
|
|
3
3
|
rawRows
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GPKHEPVX.js";
|
|
5
5
|
|
|
6
6
|
// src/canonical-human-identities.ts
|
|
7
7
|
import { createHash } from "crypto";
|
|
@@ -309,4 +309,4 @@ export {
|
|
|
309
309
|
getCanonicalHumanIdentityProjection,
|
|
310
310
|
applyCanonicalHumanIdentityOperation
|
|
311
311
|
};
|
|
312
|
-
//# sourceMappingURL=chunk-
|
|
312
|
+
//# sourceMappingURL=chunk-CZXYNVEU.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
rawRows,
|
|
3
3
|
withRlsContext
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GPKHEPVX.js";
|
|
5
5
|
|
|
6
6
|
// src/editable-artifacts.ts
|
|
7
7
|
import { createHash } from "crypto";
|
|
@@ -3540,4 +3540,4 @@ export {
|
|
|
3540
3540
|
PostgresEditableArtifactStore,
|
|
3541
3541
|
PostgresEditableArtifactLiveReadStore
|
|
3542
3542
|
};
|
|
3543
|
-
//# sourceMappingURL=chunk-
|
|
3543
|
+
//# sourceMappingURL=chunk-DIFDLF2C.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
sessions,
|
|
5
5
|
workspaceSessionActivityRevisions,
|
|
6
6
|
workspaces
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-WU3MSPZS.js";
|
|
8
8
|
|
|
9
9
|
// src/persistence-errors.ts
|
|
10
10
|
var SQLSTATE_KEYS = ["sqlState", "sqlstate", "code"];
|
|
@@ -755,4 +755,4 @@ export {
|
|
|
755
755
|
withAccountRls,
|
|
756
756
|
dbBindingFor
|
|
757
757
|
};
|
|
758
|
-
//# sourceMappingURL=chunk-
|
|
758
|
+
//# sourceMappingURL=chunk-GPKHEPVX.js.map
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
rawRows,
|
|
3
3
|
withRlsContext,
|
|
4
4
|
withWorkspaceRls
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-GPKHEPVX.js";
|
|
6
6
|
import {
|
|
7
7
|
connections,
|
|
8
8
|
creditLedgerEntries,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
workspaceVideoGenerationPolicies,
|
|
15
15
|
workspaceVideoGenerationQuotas,
|
|
16
16
|
workspaces
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-WU3MSPZS.js";
|
|
18
18
|
|
|
19
19
|
// src/video-generation.ts
|
|
20
20
|
import {
|
|
@@ -992,4 +992,4 @@ export {
|
|
|
992
992
|
mediaGenerationResultForStoredOperation,
|
|
993
993
|
getVideoGenerationOperationSummary
|
|
994
994
|
};
|
|
995
|
-
//# sourceMappingURL=chunk-
|
|
995
|
+
//# sourceMappingURL=chunk-HUCU5BDD.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
nestedPostgresSqlState,
|
|
3
3
|
rawRows
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GPKHEPVX.js";
|
|
5
5
|
|
|
6
6
|
// src/managed-auth-session-sets.ts
|
|
7
7
|
import {
|
|
@@ -296,4 +296,4 @@ export {
|
|
|
296
296
|
reapManagedAuthIsolatedSessions,
|
|
297
297
|
reapExpiredManagedAuthSessionSets
|
|
298
298
|
};
|
|
299
|
-
//# sourceMappingURL=chunk-
|
|
299
|
+
//# sourceMappingURL=chunk-OWZ36ST7.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
cancelUnacceptedVideoGenerationsForToolCallsInTransaction
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HUCU5BDD.js";
|
|
4
4
|
import {
|
|
5
5
|
nestedPostgresSqlState,
|
|
6
6
|
withRlsContext,
|
|
7
7
|
withSessionActivityRlsContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GPKHEPVX.js";
|
|
9
9
|
import {
|
|
10
10
|
LOSSLESS_CONTENT_CODEC_VERSION,
|
|
11
11
|
auditEvents,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
workspaceControlEvents,
|
|
33
33
|
workspaceInferenceControls,
|
|
34
34
|
workspaces
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-WU3MSPZS.js";
|
|
36
36
|
|
|
37
37
|
// src/session-background-commands.ts
|
|
38
38
|
import { SessionCommandFailure } from "@opengeni/contracts";
|
|
@@ -866,6 +866,9 @@ async function lockWorkspaceInferenceControl(db, workspaceId, mode, options = {}
|
|
|
866
866
|
revision,
|
|
867
867
|
workspace_state as "workspaceState",
|
|
868
868
|
workspace_pause_revision as "workspacePauseRevision",
|
|
869
|
+
timer_id as "timerId", timer_action as "timerAction",
|
|
870
|
+
timer_due_at as "timerDueAt", timer_pause_for_seconds as "timerPauseForSeconds",
|
|
871
|
+
timer_pause_revision as "timerPauseRevision",
|
|
869
872
|
reason,
|
|
870
873
|
changed_by as "changedBy",
|
|
871
874
|
changed_at as "changedAt"
|
|
@@ -3181,13 +3184,13 @@ async function mutateWorkspaceControlInTransaction(db, input) {
|
|
|
3181
3184
|
workspace.workspacePauseRevision,
|
|
3182
3185
|
"workspace pause revision"
|
|
3183
3186
|
);
|
|
3184
|
-
const changed = input.action === "pause" ? workspace.workspaceState !== "paused" || workspacePauseRevision === null || await workspacePauseEffectsNeeded(db, {
|
|
3187
|
+
const changed = !input.timerExecution && workspace.timerId != null || (input.action === "pause" ? workspace.workspaceState !== "paused" || workspacePauseRevision === null || await workspacePauseEffectsNeeded(db, {
|
|
3185
3188
|
workspaceId: input.workspaceId,
|
|
3186
3189
|
workspacePauseRevision
|
|
3187
3190
|
}) : workspace.workspaceState !== "active" || await continuableWakeRepairNeeded(db, {
|
|
3188
3191
|
workspaceId: input.workspaceId,
|
|
3189
3192
|
rootSessionId: null
|
|
3190
|
-
});
|
|
3193
|
+
}));
|
|
3191
3194
|
if (!changed) {
|
|
3192
3195
|
const receipt2 = await updateSessionCommandReceiptResult(db, reserved.receipt.id, {
|
|
3193
3196
|
result: {
|
|
@@ -3216,6 +3219,7 @@ async function mutateWorkspaceControlInTransaction(db, input) {
|
|
|
3216
3219
|
subjectId: actor
|
|
3217
3220
|
}) : 0;
|
|
3218
3221
|
const [updated] = await db.update(workspaceInferenceControls).set({
|
|
3222
|
+
...!input.timerExecution ? clearWorkspaceTimerFields : {},
|
|
3219
3223
|
revision,
|
|
3220
3224
|
workspaceState: input.action === "pause" ? "paused" : "active",
|
|
3221
3225
|
workspacePauseRevision: input.action === "pause" ? revision : null,
|
|
@@ -3239,7 +3243,7 @@ async function mutateWorkspaceControlInTransaction(db, input) {
|
|
|
3239
3243
|
scope: "workspace",
|
|
3240
3244
|
rootSessionId: null,
|
|
3241
3245
|
action: input.action,
|
|
3242
|
-
automatic:
|
|
3246
|
+
automatic: input.timerExecution === true,
|
|
3243
3247
|
reason: input.reason ?? null,
|
|
3244
3248
|
actor
|
|
3245
3249
|
});
|
|
@@ -3308,6 +3312,131 @@ async function insertWorkspaceControlEventInTransaction(db, input) {
|
|
|
3308
3312
|
}
|
|
3309
3313
|
return event.id;
|
|
3310
3314
|
}
|
|
3315
|
+
var WorkspacePauseTimerInputError = class extends Error {
|
|
3316
|
+
};
|
|
3317
|
+
var clearWorkspaceTimerFields = {
|
|
3318
|
+
timerId: null,
|
|
3319
|
+
timerAction: null,
|
|
3320
|
+
timerDueAt: null,
|
|
3321
|
+
timerPauseForSeconds: null,
|
|
3322
|
+
timerPauseRevision: null
|
|
3323
|
+
};
|
|
3324
|
+
async function setWorkspacePauseTimerInTransaction(db, input) {
|
|
3325
|
+
let workspace = await lockWorkspaceInferenceControl(db, input.workspaceId, "update", {
|
|
3326
|
+
lockTimeoutMs: workspaceControlRequestLockTimeoutMs()
|
|
3327
|
+
});
|
|
3328
|
+
const reserved = await reserveSessionCommandReceipt(db, {
|
|
3329
|
+
accountId: input.accountId,
|
|
3330
|
+
workspaceId: input.workspaceId,
|
|
3331
|
+
actor: { type: "human", subjectId: input.subjectId },
|
|
3332
|
+
action: `workspace.timer.${input.action}`,
|
|
3333
|
+
targetSessionId: null,
|
|
3334
|
+
targetTurnId: null,
|
|
3335
|
+
operationKey: input.clientEventId,
|
|
3336
|
+
canonicalRequestHash: canonicalSessionCommandHash({
|
|
3337
|
+
action: input.action,
|
|
3338
|
+
pauseInSeconds: input.pauseInSeconds ?? 0,
|
|
3339
|
+
pauseForSeconds: input.pauseForSeconds ?? null,
|
|
3340
|
+
expectedRevision: input.expectedRevision
|
|
3341
|
+
})
|
|
3342
|
+
});
|
|
3343
|
+
if (reserved.replay)
|
|
3344
|
+
return {
|
|
3345
|
+
workspaceControlEventId: reserved.receipt.result.workspaceControlEventId ?? null
|
|
3346
|
+
};
|
|
3347
|
+
if (Number(workspace.revision) !== input.expectedRevision)
|
|
3348
|
+
throw new SessionControlConflictError();
|
|
3349
|
+
let action = "pause";
|
|
3350
|
+
let delay = input.pauseInSeconds ?? 0;
|
|
3351
|
+
let pauseRevision = null;
|
|
3352
|
+
if (input.action === "set") {
|
|
3353
|
+
if (workspace.workspaceState === "paused") {
|
|
3354
|
+
if (delay !== 0 || input.pauseForSeconds == null) {
|
|
3355
|
+
throw new WorkspacePauseTimerInputError("A paused workspace requires a resume duration");
|
|
3356
|
+
}
|
|
3357
|
+
action = "resume";
|
|
3358
|
+
delay = input.pauseForSeconds;
|
|
3359
|
+
pauseRevision = Number(workspace.workspacePauseRevision);
|
|
3360
|
+
} else if (delay === 0) {
|
|
3361
|
+
await mutateWorkspaceControlInTransaction(db, {
|
|
3362
|
+
accountId: input.accountId,
|
|
3363
|
+
workspaceId: input.workspaceId,
|
|
3364
|
+
actor: { type: "human", subjectId: input.subjectId },
|
|
3365
|
+
operationKey: `timer-pause:${reserved.receipt.id}`,
|
|
3366
|
+
action: "pause"
|
|
3367
|
+
});
|
|
3368
|
+
workspace = await lockWorkspaceInferenceControl(db, input.workspaceId, "update");
|
|
3369
|
+
action = "resume";
|
|
3370
|
+
delay = input.pauseForSeconds ?? 0;
|
|
3371
|
+
pauseRevision = Number(workspace.workspacePauseRevision);
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
const hasTimer = input.action === "set" && delay > 0;
|
|
3375
|
+
const [clock] = await db.execute(sql3`select clock_timestamp() as now`);
|
|
3376
|
+
const revision = nextRevision(workspace);
|
|
3377
|
+
await db.update(workspaceInferenceControls).set({
|
|
3378
|
+
...clearWorkspaceTimerFields,
|
|
3379
|
+
...hasTimer ? {
|
|
3380
|
+
timerId: reserved.receipt.id,
|
|
3381
|
+
timerAction: action,
|
|
3382
|
+
timerDueAt: new Date(new Date(clock.now).getTime() + delay * 1e3),
|
|
3383
|
+
timerPauseForSeconds: action === "pause" ? input.pauseForSeconds ?? null : null,
|
|
3384
|
+
timerPauseRevision: pauseRevision
|
|
3385
|
+
} : {},
|
|
3386
|
+
revision,
|
|
3387
|
+
updatedAt: new Date(clock.now)
|
|
3388
|
+
}).where(eq3(workspaceInferenceControls.workspaceId, input.workspaceId));
|
|
3389
|
+
const workspaceControlEventId = await insertWorkspaceControlEventInTransaction(db, {
|
|
3390
|
+
accountId: input.accountId,
|
|
3391
|
+
workspaceId: input.workspaceId,
|
|
3392
|
+
revision,
|
|
3393
|
+
scope: "workspace",
|
|
3394
|
+
rootSessionId: null,
|
|
3395
|
+
action: hasTimer ? "timer_set" : "timer_cancelled",
|
|
3396
|
+
automatic: false,
|
|
3397
|
+
reason: null,
|
|
3398
|
+
actor: input.subjectId
|
|
3399
|
+
});
|
|
3400
|
+
await updateSessionCommandReceiptResult(db, reserved.receipt.id, {
|
|
3401
|
+
controlRevision: revision,
|
|
3402
|
+
result: { workspaceControlEventId }
|
|
3403
|
+
});
|
|
3404
|
+
return { workspaceControlEventId };
|
|
3405
|
+
}
|
|
3406
|
+
async function fireWorkspacePauseTimerInTransaction(db, input) {
|
|
3407
|
+
const workspace = await lockWorkspaceInferenceControl(db, input.workspaceId, "update", {
|
|
3408
|
+
lockTimeoutMs: 1e3
|
|
3409
|
+
});
|
|
3410
|
+
const [clock] = await db.execute(sql3`select clock_timestamp() as now`);
|
|
3411
|
+
if (workspace.timerId !== input.timerId || !workspace.timerDueAt || new Date(workspace.timerDueAt).getTime() > new Date(clock.now).getTime())
|
|
3412
|
+
return null;
|
|
3413
|
+
const action = workspace.timerAction;
|
|
3414
|
+
if (action === "resume" && (workspace.workspaceState !== "paused" || Number(workspace.workspacePauseRevision) !== Number(workspace.timerPauseRevision))) {
|
|
3415
|
+
await db.update(workspaceInferenceControls).set(clearWorkspaceTimerFields).where(eq3(workspaceInferenceControls.workspaceId, input.workspaceId));
|
|
3416
|
+
return null;
|
|
3417
|
+
}
|
|
3418
|
+
const result = await mutateWorkspaceControlInTransaction(db, {
|
|
3419
|
+
accountId: workspace.accountId,
|
|
3420
|
+
workspaceId: input.workspaceId,
|
|
3421
|
+
actor: { type: "service", subjectId: "service:workspace-pause-timer" },
|
|
3422
|
+
operationKey: `timer:${input.timerId}:${action}`,
|
|
3423
|
+
action,
|
|
3424
|
+
timerExecution: true
|
|
3425
|
+
});
|
|
3426
|
+
const [applied] = await db.execute(sql3`select clock_timestamp() as now`);
|
|
3427
|
+
await db.update(workspaceInferenceControls).set({
|
|
3428
|
+
...clearWorkspaceTimerFields,
|
|
3429
|
+
...action === "pause" && workspace.timerPauseForSeconds !== null ? {
|
|
3430
|
+
timerId: input.timerId,
|
|
3431
|
+
timerAction: "resume",
|
|
3432
|
+
timerDueAt: new Date(
|
|
3433
|
+
new Date(applied.now).getTime() + workspace.timerPauseForSeconds * 1e3
|
|
3434
|
+
),
|
|
3435
|
+
timerPauseRevision: result.revision
|
|
3436
|
+
} : {}
|
|
3437
|
+
}).where(eq3(workspaceInferenceControls.workspaceId, input.workspaceId));
|
|
3438
|
+
return result;
|
|
3439
|
+
}
|
|
3311
3440
|
|
|
3312
3441
|
// src/session-background-commands.ts
|
|
3313
3442
|
var SESSION_BACKGROUND_COMMAND_REASON_MAX_BYTES = 512;
|
|
@@ -4140,6 +4269,9 @@ export {
|
|
|
4140
4269
|
updateSessionCommandReceiptResult,
|
|
4141
4270
|
mutateSessionControlInTransaction,
|
|
4142
4271
|
autoResumeSessionBranchInTransaction,
|
|
4143
|
-
mutateWorkspaceControlInTransaction
|
|
4272
|
+
mutateWorkspaceControlInTransaction,
|
|
4273
|
+
WorkspacePauseTimerInputError,
|
|
4274
|
+
setWorkspacePauseTimerInTransaction,
|
|
4275
|
+
fireWorkspacePauseTimerInTransaction
|
|
4144
4276
|
};
|
|
4145
|
-
//# sourceMappingURL=chunk-
|
|
4277
|
+
//# sourceMappingURL=chunk-R6LIJYG6.js.map
|