@finalai/sandbox-router-final 0.2.2 → 0.2.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.
|
@@ -13,7 +13,7 @@ const lifecycleFields = (lifecycle, defaultWallClockS = DEFAULT_WALL_CLOCK_S) =>
|
|
|
13
13
|
idlePolicy: idle == null ? void 0 : IDLE_POLICIES[idle.action],
|
|
14
14
|
autoResume: lifecycle.autoResume,
|
|
15
15
|
wallClockLimitS: max === void 0 ? defaultWallClockS : max === null ? null : void 0,
|
|
16
|
-
maxLifetime: max == null ? null : { after_s: max.afterS, action: max.action, from: MaxLifetimeFrom.
|
|
16
|
+
maxLifetime: max == null ? null : { after_s: max.afterS, action: max.action, from: MaxLifetimeFrom.Create }
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
const IDLE_ACTIONS = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lifecycle.ts"],
|
|
4
|
-
"sourcesContent": ["import { IdleAction, MaxAction, type LifecycleIface } from '@finalai/sandbox-router/provider';\nimport { IdlePolicy, MaxLifetimeFrom, type MaxLifetimeBodyIface } from \"./vm/resources.mjs\";\n\n// A lifecycle in the platform's terms. The idle policy answers to idleness. A max lifetime stops\n// or deletes the sandbox a time after its
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY,iBAAsC;AAC3D,SAAS,YAAY,uBAAkD;AAUhE,MAAM,uBAAuB,MAAM,KAAK,KAAK;AAEpD,MAAM,gBAAgD;AAAA,EACpD,CAAC,WAAW,KAAK,GAAG,WAAW;AAAA,EAC/B,CAAC,WAAW,IAAI,GAAG,WAAW;AAAA,EAC9B,CAAC,WAAW,MAAM,GAAG,WAAW;AAClC;AAgBO,MAAM,kBAAkB,CAC7B,WACA,oBAA4B,yBACH;AACzB,QAAM,EAAE,MAAM,IAAI,IAAI;AACtB,SAAO;AAAA,IACL,cAAc,MAAM,UAAU;AAAA,IAC9B,YAAY,QAAQ,OAAO,SAAY,cAAc,KAAK,MAAM;AAAA,IAChE,YAAY,UAAU;AAAA,IACtB,iBAAiB,QAAQ,SAAY,oBAAoB,QAAQ,OAAO,OAAO;AAAA,IAC/E,aACE,OAAO,
|
|
4
|
+
"sourcesContent": ["import { IdleAction, MaxAction, type LifecycleIface } from '@finalai/sandbox-router/provider';\nimport { IdlePolicy, MaxLifetimeFrom, type MaxLifetimeBodyIface } from \"./vm/resources.mjs\";\n\n// A lifecycle in the platform's terms. The idle policy answers to idleness. A max lifetime stops\n// or deletes the sandbox a time after its create, in any state,\n// and replaces the wall-clock limit; without one, the wall-clock limit applies the idle policy to\n// a sandbox that has run that long since it last started or resumed.\n\n// This adapter's default for a lifecycle that leaves `max` out: a wall-clock limit of one year,\n// which create caps at the plan's maximum (30 days by default). The platform's own default is a\n// day.\nexport const DEFAULT_WALL_CLOCK_S = 365 * 24 * 60 * 60;\n\nconst IDLE_POLICIES: Record<IdleAction, IdlePolicy> = {\n [IdleAction.Pause]: IdlePolicy.Pause,\n [IdleAction.Stop]: IdlePolicy.Stop,\n [IdleAction.Delete]: IdlePolicy.Delete,\n};\n\nexport interface LifecycleFieldsIface {\n // Null: no idle timeout. This adapter has none by default (the platform's is five minutes).\n idleTimeoutS: number | null;\n // Undefined: the platform's default (pause).\n idlePolicy: IdlePolicy | undefined;\n // Undefined: the platform's default (wakes).\n autoResume: boolean | undefined;\n // Null: none, for organizations entitled to run without one. Undefined: a max lifetime\n // replaces it.\n wallClockLimitS: number | null | undefined;\n // Undefined: none to set (create) or keep; null removes one.\n maxLifetime: MaxLifetimeBodyIface | null;\n}\n\nexport const lifecycleFields = (\n lifecycle: LifecycleIface,\n defaultWallClockS: number = DEFAULT_WALL_CLOCK_S,\n): LifecycleFieldsIface => {\n const { idle, max } = lifecycle;\n return {\n idleTimeoutS: idle?.afterS ?? null,\n idlePolicy: idle == null ? undefined : IDLE_POLICIES[idle.action],\n autoResume: lifecycle.autoResume,\n wallClockLimitS: max === undefined ? defaultWallClockS : max === null ? null : undefined,\n maxLifetime:\n max == null\n ? null\n : { after_s: max.afterS, action: max.action, from: MaxLifetimeFrom.Create },\n };\n};\n\nconst IDLE_ACTIONS: Record<IdlePolicy, IdleAction> = {\n [IdlePolicy.Pause]: IdleAction.Pause,\n [IdlePolicy.Stop]: IdleAction.Stop,\n [IdlePolicy.Delete]: IdleAction.Delete,\n};\n\nconst MAX_ACTIONS: Partial<Record<IdlePolicy, MaxAction>> = {\n [IdlePolicy.Stop]: MaxAction.Stop,\n [IdlePolicy.Delete]: MaxAction.Delete,\n};\n\nexport interface LifecycleStateIface {\n // As set; null when the platform's default applies or the timer is off.\n idleTimeoutS: number | null;\n idleTimeoutDisabled: boolean;\n idlePolicy: IdlePolicy;\n autoResume: boolean;\n // Its own lifetime (a create's time to live reads as a delete from create).\n maxLifetime: { afterS: number; action: 'stop' | 'delete' } | null;\n wallClockLimitS: number | null;\n // Set while running unless the wall-clock limit is off or replaced.\n wallClockDeadlineAt: Date | null;\n running: boolean;\n}\n\n// The lifecycle in force, as far as the API shows it. A field at the platform's default is left\n// out (the API does not say what the default is), and so is a wall-clock limit that pauses,\n// which has no router equivalent. A lifetime counted from create is reported as a maximum like\n// one counted from the latest start. The wall-clock limit is reported as kept, capped at the\n// plan's maximum.\nexport const lifecycleOf = (state: LifecycleStateIface): LifecycleIface => {\n const idle = state.idleTimeoutDisabled\n ? null\n : state.idleTimeoutS == null\n ? undefined\n : { afterS: state.idleTimeoutS, action: IDLE_ACTIONS[state.idlePolicy] };\n const wallClockAction = MAX_ACTIONS[state.idlePolicy];\n const max =\n state.maxLifetime != null\n ? {\n afterS: state.maxLifetime.afterS,\n action: state.maxLifetime.action === 'stop' ? MaxAction.Stop : MaxAction.Delete,\n }\n : state.wallClockLimitS != null\n ? wallClockAction == null\n ? undefined\n : { afterS: state.wallClockLimitS, action: wallClockAction }\n : state.running && state.wallClockDeadlineAt == null\n ? null\n : undefined;\n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