@sandboxrouter/sdk 0.8.3 → 0.10.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.
package/dist/validate.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { CATALOG } from "./catalog.js";
2
2
  import { RouterError } from "./types.js";
3
3
  /** Every key a SandboxSpec can have. Anything else in a request is a mistake (e.g. "memory" for "memoryGb"). */
4
- export const SPEC_KEYS = ["vcpu", "memoryGb", "gpu", "env", "timeoutMinutes", "expectedSeconds", "image", "metadata"];
4
+ export const SPEC_KEYS = ["vcpu", "memoryGb", "gpu", "env", "timeoutMinutes", "expectedSeconds", "cpuUtilization", "image", "metadata"];
5
5
  /** Every key RouteOptions can have. */
6
- export const ROUTE_KEYS = ["provider", "strategy", "fallback", "require", "createTimeoutSeconds", "deadlineSeconds"];
6
+ export const ROUTE_KEYS = ["provider", "strategy", "fallback", "require", "createTimeoutSeconds", "deadlineSeconds", "maxHourlyUsd"];
7
7
  export const STRATEGIES = ["default", "balanced", "verified", "cheapest", "fastest"];
8
8
  const bad = (msg) => new RouterError(msg, [], "bad_request");
9
9
  const positive = (v) => typeof v === "number" && Number.isFinite(v) && v > 0;
@@ -20,6 +20,9 @@ export function validate(spec = {}, route = {}) {
20
20
  if (spec[k] !== undefined && !positive(spec[k]))
21
21
  throw bad(`${k} must be a positive number, got ${show(spec[k])}`);
22
22
  }
23
+ if (spec.cpuUtilization !== undefined && !(positive(spec.cpuUtilization) && spec.cpuUtilization <= 1)) {
24
+ throw bad(`cpuUtilization must be more than 0 and at most 1, got ${show(spec.cpuUtilization)}`);
25
+ }
23
26
  if (spec.gpu !== undefined && (typeof spec.gpu !== "string" || !spec.gpu))
24
27
  throw bad(`gpu must be a GPU type such as "T4", got ${JSON.stringify(spec.gpu)}`);
25
28
  for (const k of ["env", "image", "metadata"]) {
@@ -32,7 +35,7 @@ export function validate(spec = {}, route = {}) {
32
35
  if (route.fallback !== undefined && route.fallback !== true && route.fallback !== false && route.fallback !== "any") {
33
36
  throw bad(`fallback must be true, false or "any", got ${JSON.stringify(route.fallback)}`);
34
37
  }
35
- for (const k of ["createTimeoutSeconds", "deadlineSeconds"]) {
38
+ for (const k of ["createTimeoutSeconds", "deadlineSeconds", "maxHourlyUsd"]) {
36
39
  if (route[k] !== undefined && !positive(route[k]))
37
40
  throw bad(`${k} must be a positive number, got ${show(route[k])}`);
38
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sandboxrouter/sdk",
3
- "version": "0.8.3",
3
+ "version": "0.10.0",
4
4
  "description": "One API for every sandbox provider: route AI agents' code by price, speed or capability, with automatic fallback. Free and open source.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",