@void/platform 1.10.0 → 1.12.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.
@@ -0,0 +1,140 @@
1
+ // src/security-local-check.ts
2
+ const LOCKFILES = /* @__PURE__ */ new Set([
3
+ "package-lock.json",
4
+ "npm-shrinkwrap.json",
5
+ "pnpm-lock.yaml",
6
+ "yarn.lock",
7
+ "bun.lock",
8
+ "bun.lockb",
9
+ "deno.lock"
10
+ ]);
11
+ const SKIPPED_EXTENSIONS = new Set([
12
+ "wasm exe dll so dylib node bin dat zip gz tgz br zst tar 7z pdf",
13
+ "png jpg jpeg gif webp avif ico bmp tif tiff heic",
14
+ "woff woff2 ttf otf eot",
15
+ "mp3 mp4 webm ogg wav mov"
16
+ ].join(" ").split(" "));
17
+ const SECRET_EXTENSIONS = /* @__PURE__ */ new Set([
18
+ "pem",
19
+ "key",
20
+ "p12",
21
+ "pfx"
22
+ ]);
23
+ function extension(name) {
24
+ const dot = name.lastIndexOf(".");
25
+ return dot <= 0 ? "" : name.slice(dot + 1).toLowerCase();
26
+ }
27
+ /**
28
+ * `id_*` names an SSH key file (`id_rsa`, `id_ed25519.pub`), not code: it matches
29
+ * only with no extension or `.pub`, so `id_utils.ts` stays.
30
+ */
31
+ function isKeyFileName(name) {
32
+ if (!name.startsWith("id_")) return false;
33
+ const dot = name.indexOf(".");
34
+ return dot === -1 || name.slice(dot) === ".pub";
35
+ }
36
+ function securityInputFilter(path) {
37
+ const segments = path.split("/");
38
+ const lower = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
39
+ if (segments.some((segment) => segment.startsWith(".git")) || lower.startsWith(".env") || lower === ".npmrc" || SECRET_EXTENSIONS.has(extension(lower)) || isKeyFileName(lower)) return "secret";
40
+ return segments.includes(".void") || LOCKFILES.has(lower) || [
41
+ ".d.ts",
42
+ ".d.mts",
43
+ ".d.cts"
44
+ ].some((suffix) => lower.endsWith(suffix)) || SKIPPED_EXTENSIONS.has(extension(lower)) ? "skipped" : null;
45
+ }
46
+ /** What one local check may send; the CLI checks before upload, the API again when it reads. */
47
+ const SECURITY_LOCAL_CHECK_LIMITS = {
48
+ /** Files in the tree. */
49
+ maxFiles: 1e4,
50
+ /** Their bytes, uncompressed (what one scan input can hold). */
51
+ maxBytes: 33554432,
52
+ /** The gzip archive. */
53
+ maxArchiveBytes: 33554432
54
+ };
55
+ /** The archive's top folder; the reader cuts it off, as for a GitHub tarball. */
56
+ const SECURITY_LOCAL_TREE_ROOT = "tree";
57
+ /**
58
+ * Whether `path` (relative to the project folder) can go in the archive: no empty,
59
+ * `.` or `..` part, no leading `/`, no control character or backslash.
60
+ */
61
+ function isSecurityLocalTreePath(path) {
62
+ if (path.length === 0 || path.startsWith("/")) return false;
63
+ if (path.split("/").some((segment) => segment === "" || segment === "." || segment === "..")) return false;
64
+ return Array.from(path).every((char) => {
65
+ const code = char.charCodeAt(0);
66
+ return code >= 32 && code !== 127 && code !== 92;
67
+ });
68
+ }
69
+ const BLOCK = 512;
70
+ const encoder = new TextEncoder();
71
+ function writeString(block, offset, length, text) {
72
+ block.set(encoder.encode(text).subarray(0, length), offset);
73
+ }
74
+ function writeOctal(block, offset, length, value) {
75
+ writeString(block, offset, length, `${value.toString(8).padStart(length - 1, "0")}\0`);
76
+ }
77
+ function header(name, size, type) {
78
+ const block = new Uint8Array(BLOCK);
79
+ writeString(block, 0, 100, name);
80
+ writeOctal(block, 100, 8, 420);
81
+ writeOctal(block, 108, 8, 0);
82
+ writeOctal(block, 116, 8, 0);
83
+ writeOctal(block, 124, 12, size);
84
+ writeOctal(block, 136, 12, 0);
85
+ block.fill(32, 148, 156);
86
+ block[156] = type.charCodeAt(0);
87
+ writeString(block, 257, 6, "ustar\0");
88
+ writeString(block, 263, 2, "00");
89
+ let sum = 0;
90
+ for (const byte of block) sum += byte;
91
+ writeString(block, 148, 8, `${sum.toString(8).padStart(6, "0")}\0 `);
92
+ return block;
93
+ }
94
+ /** `<length> path=<value>\n`, where length counts the whole record. */
95
+ function paxPathRecord(path) {
96
+ const body = ` path=${path}\n`;
97
+ const bodyLength = encoder.encode(body).length;
98
+ let length = bodyLength + 1;
99
+ while (String(length).length + bodyLength !== length) length = String(length).length + bodyLength;
100
+ return encoder.encode(`${length}${body}`);
101
+ }
102
+ /**
103
+ * The tree as one uncompressed ustar archive under `tree/`. A long or non-ASCII name
104
+ * gets a pax `path` record. Throws on a path `isSecurityLocalTreePath` refuses.
105
+ */
106
+ function securityLocalTreeTar(files) {
107
+ const chunks = [];
108
+ let total = 0;
109
+ const push = (chunk) => {
110
+ chunks.push(chunk);
111
+ total += chunk.length;
112
+ };
113
+ const pad = (size) => {
114
+ const rest = size % BLOCK;
115
+ if (rest !== 0) push(new Uint8Array(BLOCK - rest));
116
+ };
117
+ for (const file of files) {
118
+ if (!isSecurityLocalTreePath(file.path)) throw new Error(`security check: ${JSON.stringify(file.path)} is not a usable path`);
119
+ let name = `${SECURITY_LOCAL_TREE_ROOT}/${file.path}`;
120
+ if (encoder.encode(name).length > 99 || Array.from(name).some((char) => char.charCodeAt(0) > 126)) {
121
+ const record = paxPathRecord(name);
122
+ push(header("PaxHeader", record.length, "x"));
123
+ push(record);
124
+ pad(record.length);
125
+ name = `${SECURITY_LOCAL_TREE_ROOT}/pax-entry`;
126
+ }
127
+ push(header(name, file.data.length, "0"));
128
+ push(file.data);
129
+ pad(file.data.length);
130
+ }
131
+ push(new Uint8Array(BLOCK * 2));
132
+ const out = new Uint8Array(total);
133
+ let at = 0;
134
+ for (const chunk of chunks) {
135
+ out.set(chunk, at);
136
+ at += chunk.length;
137
+ }
138
+ return out;
139
+ }
140
+ export { SECURITY_LOCAL_CHECK_LIMITS, SECURITY_LOCAL_TREE_ROOT, isSecurityLocalTreePath, securityInputFilter, securityLocalTreeTar };
@@ -0,0 +1,34 @@
1
+ export type SecurityPackageSource = "registry" | "local";
2
+ /** Package name → where the lockfile says it comes from. */
3
+ export type SecurityLockfileIndex = ReadonlyMap<string, SecurityPackageSource>;
4
+ /** Lockfiles the readers understand, in the order a directory is searched. */
5
+ export declare const SECURITY_LOCKFILE_NAMES: ReadonlyArray<string>;
6
+ /** Package names one deploy may claim, at most (the deploy body stays small). */
7
+ export declare const SECURITY_PACKAGE_CLAIMS_MAX = 5e3;
8
+ /**
9
+ * What a deploy sends (`securityPackages`): the packages its Worker bundle's source maps
10
+ * name, as the project's lockfile resolves them. Names it cannot place are left out.
11
+ */
12
+ export type SecurityPackageClaims = Readonly<{
13
+ registry: ReadonlyArray<string>;
14
+ local: ReadonlyArray<string>;
15
+ }>;
16
+ /** The package a path sits in: the part after its last `node_modules/`. */
17
+ export declare function packageNameOfPath(path: string): string | null;
18
+ /** `package-lock.json` v2/v3: `packages["node_modules/x"]` with `resolved` or `link`. */
19
+ export declare function parsePackageLock(text: string): SecurityLockfileIndex | null;
20
+ /**
21
+ * `pnpm-lock.yaml` (v6–v9), read line by line from its indentation: `importers` give each
22
+ * direct dependency's `version:`, `packages` each resolved package's `resolution`.
23
+ * Workspace packages are importers, never `packages` entries, so they stay local.
24
+ */
25
+ export declare function parsePnpmLock(text: string): SecurityLockfileIndex | null;
26
+ /** Reads a lockfile by its file name; `null` for a name or text it does not understand. */
27
+ export declare function parseSecurityLockfile(fileName: string, text: string): SecurityLockfileIndex | null;
28
+ /** The claims a deploy sends for `names` (the packages its source maps name). */
29
+ export declare function securityPackageClaims(index: SecurityLockfileIndex, names: Iterable<string>): SecurityPackageClaims;
30
+ /**
31
+ * The server reads a deploy's `securityPackages` back into an index; `null` for anything
32
+ * malformed or too long (the scan then keeps third-party code, ranked last).
33
+ */
34
+ export declare function parseSecurityPackageClaims(value: unknown): SecurityLockfileIndex | null;
@@ -0,0 +1,181 @@
1
+ import { r as isRecord } from "./validate-CTKcW3Vp.mjs";
2
+ // src/security-lockfile.ts
3
+ /**
4
+ * Third-party code by package identity (design doc 0095 M10), shared by the CLI at deploy
5
+ * and the API that drops registry packages from a scan input. A package seen as both
6
+ * local and registry is local: code that may be the owner's is never dropped.
7
+ */
8
+ /** Lockfiles the readers understand, in the order a directory is searched. */
9
+ const SECURITY_LOCKFILE_NAMES = [
10
+ "pnpm-lock.yaml",
11
+ "package-lock.json",
12
+ "npm-shrinkwrap.json"
13
+ ];
14
+ /** Package names one deploy may claim, at most (the deploy body stays small). */
15
+ const SECURITY_PACKAGE_CLAIMS_MAX = 5e3;
16
+ /** npm's own limit on a package name. */
17
+ const MAX_PACKAGE_NAME = 214;
18
+ /** The package a path sits in: the part after its last `node_modules/`. */
19
+ function packageNameOfPath(path) {
20
+ const segments = path.split("/");
21
+ const last = segments.lastIndexOf("node_modules");
22
+ if (last === -1) return null;
23
+ const first = segments[last + 1];
24
+ if (!first || first.startsWith(".")) return null;
25
+ if (first.startsWith("@")) {
26
+ const second = segments[last + 2];
27
+ return second ? `${first}/${second}` : null;
28
+ }
29
+ return first;
30
+ }
31
+ function sourceOfSpecifier(version) {
32
+ return [
33
+ "link:",
34
+ "file:",
35
+ "workspace:",
36
+ "git"
37
+ ].some((prefix) => version.startsWith(prefix)) || version.includes("://") ? "local" : "registry";
38
+ }
39
+ function record(index, name, source) {
40
+ if (index.get(name) !== "local") index.set(name, source);
41
+ }
42
+ /** `package-lock.json` v2/v3: `packages["node_modules/x"]` with `resolved` or `link`. */
43
+ function parsePackageLock(text) {
44
+ let value;
45
+ try {
46
+ value = JSON.parse(text);
47
+ } catch {
48
+ return null;
49
+ }
50
+ if (!isRecord(value) || !isRecord(value.packages)) return null;
51
+ const index = /* @__PURE__ */ new Map();
52
+ for (const [key, entry] of Object.entries(value.packages)) {
53
+ const name = packageNameOfPath(key);
54
+ if (name === null || !isRecord(entry)) continue;
55
+ const { link, resolved } = entry;
56
+ record(index, name, link === true || typeof resolved !== "string" || resolved.startsWith("file:") || resolved.startsWith("git") ? "local" : "registry");
57
+ }
58
+ return index;
59
+ }
60
+ function unquote(text) {
61
+ if (text.length >= 2 && (text[0] === "'" || text[0] === "\"") && text.at(-1) === text[0]) return text.slice(1, -1);
62
+ return text;
63
+ }
64
+ /**
65
+ * The name in a `packages:` key: `hono@4.0.0` (v9), `/hono@4.0.0` (v6–v8),
66
+ * `'@acme/x@1.0.0(react@18.3.1)'`. `null` when there is no version part.
67
+ */
68
+ function nameOfPnpmPackageKey(key) {
69
+ let text = unquote(key);
70
+ if (text.startsWith("/")) text = text.slice(1);
71
+ const at = text.indexOf("@", 1);
72
+ if (at <= 0) return null;
73
+ return text.slice(0, at);
74
+ }
75
+ /** A `resolution` that is not a registry tarball: a local folder, a `file:` tarball or git. */
76
+ function localResolution(text) {
77
+ return text.includes("directory:") || text.includes("tarball: file:") || text.includes("type: git") || text.includes("repo:");
78
+ }
79
+ /**
80
+ * `pnpm-lock.yaml` (v6–v9), read line by line from its indentation: `importers` give each
81
+ * direct dependency's `version:`, `packages` each resolved package's `resolution`.
82
+ * Workspace packages are importers, never `packages` entries, so they stay local.
83
+ */
84
+ function parsePnpmLock(text) {
85
+ const index = /* @__PURE__ */ new Map();
86
+ let top = null;
87
+ let section = false;
88
+ let current = null;
89
+ let entry = null;
90
+ let resolution = null;
91
+ let nested = false;
92
+ const closeEntry = () => {
93
+ if (entry !== null && resolution !== null) record(index, entry, localResolution(resolution) ? "local" : "registry");
94
+ entry = null;
95
+ resolution = null;
96
+ nested = false;
97
+ };
98
+ for (const raw of text.split("\n")) {
99
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
100
+ if (line.trim() === "" || line.trimStart().startsWith("#")) continue;
101
+ const indent = line.length - line.trimStart().length;
102
+ const content = line.trim();
103
+ if (indent === 0) {
104
+ closeEntry();
105
+ top = content === "importers:" ? "importers" : content === "packages:" ? "packages" : null;
106
+ section = false;
107
+ current = null;
108
+ continue;
109
+ }
110
+ if (top === "packages") {
111
+ if (indent === 2) {
112
+ closeEntry();
113
+ if (content.endsWith(":")) entry = nameOfPnpmPackageKey(content.slice(0, -1));
114
+ continue;
115
+ }
116
+ if (entry === null) continue;
117
+ if (indent === 4) {
118
+ nested = false;
119
+ if (content.startsWith("resolution:")) {
120
+ resolution = content.slice(11).trim();
121
+ nested = resolution === "";
122
+ }
123
+ continue;
124
+ }
125
+ if (nested && resolution !== null) resolution += ` ${content}`;
126
+ continue;
127
+ }
128
+ if (top !== "importers") continue;
129
+ if (indent === 4) {
130
+ section = content === "dependencies:" || content === "devDependencies:" || content === "optionalDependencies:";
131
+ current = null;
132
+ continue;
133
+ }
134
+ if (!section) continue;
135
+ if (indent === 6 && content.endsWith(":")) {
136
+ current = unquote(content.slice(0, -1));
137
+ continue;
138
+ }
139
+ if (indent === 8 && current !== null && content.startsWith("version:")) record(index, current, sourceOfSpecifier(unquote(content.slice(8).trim())));
140
+ }
141
+ closeEntry();
142
+ return index.size > 0 ? index : null;
143
+ }
144
+ /** Reads a lockfile by its file name; `null` for a name or text it does not understand. */
145
+ function parseSecurityLockfile(fileName, text) {
146
+ const base = fileName.slice(fileName.lastIndexOf("/") + 1);
147
+ if (base === "pnpm-lock.yaml") return parsePnpmLock(text);
148
+ if (base === "package-lock.json" || base === "npm-shrinkwrap.json") return parsePackageLock(text);
149
+ return null;
150
+ }
151
+ /** The claims a deploy sends for `names` (the packages its source maps name). */
152
+ function securityPackageClaims(index, names) {
153
+ const registry = [];
154
+ const local = [];
155
+ for (const name of new Set(names)) {
156
+ const source = index.get(name);
157
+ if (source === "registry") registry.push(name);
158
+ else if (source === "local") local.push(name);
159
+ }
160
+ return {
161
+ registry: registry.sort(),
162
+ local: local.sort()
163
+ };
164
+ }
165
+ function validName(value) {
166
+ return typeof value === "string" && value.length > 0 && value.length <= MAX_PACKAGE_NAME && packageNameOfPath(`node_modules/${value}/x`) === value;
167
+ }
168
+ /**
169
+ * The server reads a deploy's `securityPackages` back into an index; `null` for anything
170
+ * malformed or too long (the scan then keeps third-party code, ranked last).
171
+ */
172
+ function parseSecurityPackageClaims(value) {
173
+ if (!isRecord(value)) return null;
174
+ const { registry, local } = value;
175
+ if (!Array.isArray(registry) || !Array.isArray(local) || registry.length + local.length > 5e3 || !registry.every(validName) || !local.every(validName)) return null;
176
+ const index = /* @__PURE__ */ new Map();
177
+ for (const name of registry) record(index, name, "registry");
178
+ for (const name of local) record(index, name, "local");
179
+ return index;
180
+ }
181
+ export { SECURITY_LOCKFILE_NAMES, SECURITY_PACKAGE_CLAIMS_MAX, packageNameOfPath, parsePackageLock, parsePnpmLock, parseSecurityLockfile, parseSecurityPackageClaims, securityPackageClaims };
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The only list of models a security scan can run on, shared by the platform API and the
3
+ * CLI. Prices are list prices in USD per million tokens; an unpriced model cannot be picked.
4
+ */
5
+ /** How the scanner runs a model (spec §8.1). Stored on `security_scans.engine`. */
6
+ export type SecurityEngine = "void_loop" | "agent_sdk" | "codex_sdk";
7
+ /** Who runs the model. `workers-ai` is Cloudflare; the others are reached through AI Gateway. */
8
+ export type SecurityModelHost = "workers-ai" | "openai" | "anthropic";
9
+ /** Hosts checked one by one by probe check 5 and named in the provider notice. */
10
+ export type SecurityThirdPartyHost = "openai" | "anthropic";
11
+ export type SecurityRefusalRisk = "low" | "medium" | "medium-high";
12
+ export declare const SECURITY_MODEL_IDS: readonly ["@cf/deepseek-ai/deepseek-v4.1-flash-1017", "@cf/zai-org/glm-5.3", "openai/gpt-6.1-terra", "openai/gpt-6.1-sol", "anthropic/claude-sonnet-5.5", "anthropic/claude-opus-5.5"];
13
+ export type SecurityModelId = (typeof SECURITY_MODEL_IDS)[number];
14
+ /** The installation default when the policy names none. */
15
+ export declare const DEFAULT_SECURITY_MODEL: SecurityModelId;
16
+ export type SecurityModelPrice = Readonly<{
17
+ /** USD per million input tokens. */
18
+ inputUsdPerMillion: number;
19
+ /** USD per million output tokens. */
20
+ outputUsdPerMillion: number;
21
+ /**
22
+ * USD per million input tokens read from the prompt cache, when the model lists a
23
+ * cached-input price. Without it, cached input costs the plain input price.
24
+ */
25
+ cachedInputUsdPerMillion?: number;
26
+ }>;
27
+ export type SecurityModel = Readonly<{
28
+ id: SecurityModelId;
29
+ host: SecurityModelHost;
30
+ engine: SecurityEngine;
31
+ /** Zero data retention listed in the AI Gateway catalog. */
32
+ zeroDataRetention: boolean;
33
+ refusalRisk: SecurityRefusalRisk;
34
+ /** `null` until the list price is known; the model cannot be picked without it. */
35
+ price: SecurityModelPrice | null;
36
+ }>;
37
+ /** In `SECURITY_MODEL_IDS` order, so the first `@cf/*` entry is the fallback model. */
38
+ export declare const SECURITY_MODELS: ReadonlyArray<SecurityModel>;
39
+ /** Display names used in the provider notice and in copy. */
40
+ export declare const SECURITY_PROVIDER_NAMES: Readonly<Record<SecurityModelHost, string>>;
41
+ /**
42
+ * Version of the provider notice text below. Bump it when the text changes: a stored
43
+ * acceptance with an older version no longer counts, so admins and projects are asked again.
44
+ */
45
+ export declare const SECURITY_PROVIDER_NOTICE_VERSION = 1;
46
+ /** Token counts a scan reserve is computed from when no limits are given (spec §16.1). */
47
+ export declare const SECURITY_RESERVE_INPUT_TOKENS = 12e5;
48
+ export declare const SECURITY_RESERVE_OUTPUT_TOKENS = 12e4;
49
+ export declare function isSecurityModelId(value: unknown): value is SecurityModelId;
50
+ export declare function getSecurityModel(id: SecurityModelId): SecurityModel;
51
+ /** Third-party host of a model, or `null` for Cloudflare-hosted models. */
52
+ export declare function securityModelThirdPartyHost(id: SecurityModelId): SecurityThirdPartyHost | null;
53
+ export declare function isThirdPartySecurityModel(id: SecurityModelId): boolean;
54
+ /**
55
+ * A model is listed but not pickable while its price is unknown: the spend meter and
56
+ * the caps need a price for every model that can run.
57
+ */
58
+ export declare function isSecurityModelPriced(id: SecurityModelId): boolean;
59
+ /**
60
+ * Up to three badges for the picker (spec §8.2); the refusal badge only when refusal
61
+ * risk is not low.
62
+ */
63
+ export declare function securityModelBadges(id: SecurityModelId): ReadonlyArray<string>;
64
+ /**
65
+ * Cost at the model's list price in whole nano-dollars; `cachedInputTokens` is the part of
66
+ * `inputTokens` read from the prompt cache. `null` when the model has no price.
67
+ */
68
+ export declare function securityModelCostNanoUsd(id: SecurityModelId, inputTokens: number, outputTokens: number, cachedInputTokens?: number): number | null;
69
+ /** The same cost in USD. `null` when the model has no price. */
70
+ export declare function securityModelCostUsd(id: SecurityModelId, inputTokens: number, outputTokens: number): number | null;
71
+ /** Worst-case cost of one scan, reserved against the caps at start (spec §16.1). */
72
+ export declare function securityScanReserveUsd(id: SecurityModelId, limits?: Readonly<{
73
+ maxInputTokens: number;
74
+ maxOutputTokens: number;
75
+ }>): number | null;
76
+ /**
77
+ * The provider notice (spec §8.3), shown before a third-party model is used. The same
78
+ * text goes to the admin panel, the CLI and the project page. Changing it needs a
79
+ * `SECURITY_PROVIDER_NOTICE_VERSION` bump.
80
+ */
81
+ export declare function securityProviderNotice(host: SecurityThirdPartyHost): ReadonlyArray<string>;
82
+ /** Why a scan does not run on the project's own pick (the platform API sends it as `pickProblem`). */
83
+ export type SecurityPickProblem = "blocked" | "unknown" | "notice" | "unavailable";
84
+ /**
85
+ * The model line note when the project's pick does not run (spec §8.2), shared by the
86
+ * project page and the CLI: `your pick openai/gpt-6.1-sol is blocked by the platform admin`.
87
+ */
88
+ export declare function securityPickProblemNote(pick: string, problem: SecurityPickProblem): string;
@@ -0,0 +1,186 @@
1
+ // src/security-models.ts
2
+ const SECURITY_MODEL_IDS = [
3
+ "@cf/deepseek-ai/deepseek-v4.1-flash-1017",
4
+ "@cf/zai-org/glm-5.3",
5
+ "openai/gpt-6.1-terra",
6
+ "openai/gpt-6.1-sol",
7
+ "anthropic/claude-sonnet-5.5",
8
+ "anthropic/claude-opus-5.5"
9
+ ];
10
+ /** The installation default when the policy names none. */
11
+ const DEFAULT_SECURITY_MODEL = "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
12
+ /** In `SECURITY_MODEL_IDS` order, so the first `@cf/*` entry is the fallback model. */
13
+ const SECURITY_MODELS = [
14
+ {
15
+ id: "@cf/deepseek-ai/deepseek-v4.1-flash-1017",
16
+ host: "workers-ai",
17
+ engine: "void_loop",
18
+ zeroDataRetention: true,
19
+ refusalRisk: "low",
20
+ price: {
21
+ inputUsdPerMillion: .3,
22
+ outputUsdPerMillion: 1.2,
23
+ cachedInputUsdPerMillion: .006
24
+ }
25
+ },
26
+ {
27
+ id: "@cf/zai-org/glm-5.3",
28
+ host: "workers-ai",
29
+ engine: "void_loop",
30
+ zeroDataRetention: true,
31
+ refusalRisk: "low",
32
+ price: {
33
+ inputUsdPerMillion: 1.4,
34
+ outputUsdPerMillion: 4.4,
35
+ cachedInputUsdPerMillion: .26
36
+ }
37
+ },
38
+ {
39
+ id: "openai/gpt-6.1-terra",
40
+ host: "openai",
41
+ engine: "codex_sdk",
42
+ zeroDataRetention: true,
43
+ refusalRisk: "medium-high",
44
+ price: {
45
+ inputUsdPerMillion: 1,
46
+ outputUsdPerMillion: 5
47
+ }
48
+ },
49
+ {
50
+ id: "openai/gpt-6.1-sol",
51
+ host: "openai",
52
+ engine: "codex_sdk",
53
+ zeroDataRetention: true,
54
+ refusalRisk: "medium-high",
55
+ price: {
56
+ inputUsdPerMillion: 2,
57
+ outputUsdPerMillion: 10
58
+ }
59
+ },
60
+ {
61
+ id: "anthropic/claude-sonnet-5.5",
62
+ host: "anthropic",
63
+ engine: "agent_sdk",
64
+ zeroDataRetention: false,
65
+ refusalRisk: "medium",
66
+ price: null
67
+ },
68
+ {
69
+ id: "anthropic/claude-opus-5.5",
70
+ host: "anthropic",
71
+ engine: "agent_sdk",
72
+ zeroDataRetention: true,
73
+ refusalRisk: "medium",
74
+ price: {
75
+ inputUsdPerMillion: 4,
76
+ outputUsdPerMillion: 20
77
+ }
78
+ }
79
+ ];
80
+ /** Display names used in the provider notice and in copy. */
81
+ const SECURITY_PROVIDER_NAMES = {
82
+ "workers-ai": "Cloudflare",
83
+ openai: "OpenAI",
84
+ anthropic: "Anthropic"
85
+ };
86
+ /**
87
+ * Version of the provider notice text below. Bump it when the text changes: a stored
88
+ * acceptance with an older version no longer counts, so admins and projects are asked again.
89
+ */
90
+ const SECURITY_PROVIDER_NOTICE_VERSION = 1;
91
+ /** Token counts a scan reserve is computed from when no limits are given (spec §16.1). */
92
+ const SECURITY_RESERVE_INPUT_TOKENS = 12e5;
93
+ const SECURITY_RESERVE_OUTPUT_TOKENS = 12e4;
94
+ function isSecurityModelId(value) {
95
+ return SECURITY_MODEL_IDS.some((id) => id === value);
96
+ }
97
+ function getSecurityModel(id) {
98
+ const model = SECURITY_MODELS.find((entry) => entry.id === id);
99
+ if (!model) throw new Error(`Unknown security model: ${id}.`);
100
+ return model;
101
+ }
102
+ /** Third-party host of a model, or `null` for Cloudflare-hosted models. */
103
+ function securityModelThirdPartyHost(id) {
104
+ const host = getSecurityModel(id).host;
105
+ return host === "workers-ai" ? null : host;
106
+ }
107
+ function isThirdPartySecurityModel(id) {
108
+ return securityModelThirdPartyHost(id) !== null;
109
+ }
110
+ /**
111
+ * A model is listed but not pickable while its price is unknown: the spend meter and
112
+ * the caps need a price for every model that can run.
113
+ */
114
+ function isSecurityModelPriced(id) {
115
+ return getSecurityModel(id).price !== null;
116
+ }
117
+ /**
118
+ * Up to three badges for the picker (spec §8.2); the refusal badge only when refusal
119
+ * risk is not low.
120
+ */
121
+ function securityModelBadges(id) {
122
+ const model = getSecurityModel(id);
123
+ const badges = [model.host === "workers-ai" ? "Cloudflare-hosted" : "Third-party", model.zeroDataRetention ? "Zero data retention" : "No ZDR listed"];
124
+ if (model.refusalRisk !== "low") badges.push("May refuse security reviews");
125
+ return badges;
126
+ }
127
+ function nanoUsdPerToken(usdPerMillion) {
128
+ return Math.round(usdPerMillion * 1e3);
129
+ }
130
+ function assertTokenCount(value, label) {
131
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${label} must be a nonnegative safe integer.`);
132
+ }
133
+ /**
134
+ * Cost at the model's list price in whole nano-dollars; `cachedInputTokens` is the part of
135
+ * `inputTokens` read from the prompt cache. `null` when the model has no price.
136
+ */
137
+ function securityModelCostNanoUsd(id, inputTokens, outputTokens, cachedInputTokens = 0) {
138
+ assertTokenCount(inputTokens, "inputTokens");
139
+ assertTokenCount(outputTokens, "outputTokens");
140
+ assertTokenCount(cachedInputTokens, "cachedInputTokens");
141
+ const price = getSecurityModel(id).price;
142
+ if (!price) return null;
143
+ const cached = Math.min(cachedInputTokens, inputTokens);
144
+ return (inputTokens - cached) * nanoUsdPerToken(price.inputUsdPerMillion) + cached * nanoUsdPerToken(price.cachedInputUsdPerMillion ?? price.inputUsdPerMillion) + outputTokens * nanoUsdPerToken(price.outputUsdPerMillion);
145
+ }
146
+ /** The same cost in USD. `null` when the model has no price. */
147
+ function securityModelCostUsd(id, inputTokens, outputTokens) {
148
+ const nano = securityModelCostNanoUsd(id, inputTokens, outputTokens);
149
+ return nano === null ? null : nano / 1e9;
150
+ }
151
+ /** Worst-case cost of one scan, reserved against the caps at start (spec §16.1). */
152
+ function securityScanReserveUsd(id, limits = {
153
+ maxInputTokens: SECURITY_RESERVE_INPUT_TOKENS,
154
+ maxOutputTokens: SECURITY_RESERVE_OUTPUT_TOKENS
155
+ }) {
156
+ return securityModelCostUsd(id, limits.maxInputTokens, limits.maxOutputTokens);
157
+ }
158
+ /**
159
+ * The provider notice (spec §8.3), shown before a third-party model is used. The same
160
+ * text goes to the admin panel, the CLI and the project page. Changing it needs a
161
+ * `SECURITY_PROVIDER_NOTICE_VERSION` bump.
162
+ */
163
+ function securityProviderNotice(host) {
164
+ const provider = SECURITY_PROVIDER_NAMES[host];
165
+ return [
166
+ `This model is run by ${provider}, not by Cloudflare.`,
167
+ `Scans with this model send this project's changed code, the files it uses from this project, past findings and comments to ${provider} through Cloudflare AI Gateway. ${provider}'s own usage policy and safety filters apply.`,
168
+ `${provider} may refuse to review code that looks security-related, even when the review is harmless. A refused scan shows as Refused, never as passed, and records no findings. The next deploy's scan covers the same changes.`,
169
+ `${provider} may keep request data for a limited time, for example for abuse checks. Cloudflare-hosted models (@cf/…) do not keep or train on your code.`,
170
+ "Scans run only on code this project deploys. Pick this model only if you own the code or may have it reviewed.",
171
+ "Policies: anthropic.com/legal/aup · openai.com/policies/usage-policies · developers.cloudflare.com/workers-ai/platform/data-usage"
172
+ ];
173
+ }
174
+ /**
175
+ * The model line note when the project's pick does not run (spec §8.2), shared by the
176
+ * project page and the CLI: `your pick openai/gpt-6.1-sol is blocked by the platform admin`.
177
+ */
178
+ function securityPickProblemNote(pick, problem) {
179
+ switch (problem) {
180
+ case "blocked": return `your pick ${pick} is blocked by the platform admin`;
181
+ case "unknown": return `your pick ${pick} is not offered on this platform any more`;
182
+ case "notice": return `your pick ${pick} waits for the provider notice: void project security model ${pick} --accept-provider-notice`;
183
+ case "unavailable": return `your pick ${pick} cannot run on this platform now`;
184
+ }
185
+ }
186
+ export { DEFAULT_SECURITY_MODEL, SECURITY_MODELS, SECURITY_MODEL_IDS, SECURITY_PROVIDER_NAMES, SECURITY_PROVIDER_NOTICE_VERSION, SECURITY_RESERVE_INPUT_TOKENS, SECURITY_RESERVE_OUTPUT_TOKENS, getSecurityModel, isSecurityModelId, isSecurityModelPriced, isThirdPartySecurityModel, securityModelBadges, securityModelCostNanoUsd, securityModelCostUsd, securityModelThirdPartyHost, securityPickProblemNote, securityProviderNotice, securityScanReserveUsd };