gencow 0.1.299 → 0.2.1
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/bin/gencow.mjs +0 -6
- package/core/package.json +1 -1
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-dev-runtime.mjs +1 -0
- package/lib/cli-project-runtime.mjs +26 -14
- package/lib/codegen-command.mjs +16 -0
- package/lib/coding-guardrails.mjs +2 -0
- package/lib/dashboard-artifact.mjs +65 -0
- package/lib/dashboard-assets.mjs +20 -0
- package/lib/db-command.mjs +121 -80
- package/lib/db-migration-command-steps.mjs +19 -16
- package/lib/db-push-command.mjs +1 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- package/lib/local-dashboard-plan.mjs +60 -0
- package/lib/local-database-commands.mjs +127 -0
- package/lib/local-development-migrations.mjs +157 -0
- package/lib/local-drizzle-database.config.mjs +10 -0
- package/lib/local-runtime-features.mjs +12 -0
- package/lib/rag-selection.mjs +7 -0
- package/lib/runtime-local-worker.mjs +116 -0
- package/lib/runtime-mode.mjs +3 -0
- package/lib/standalone-codegen-adapter.mjs +91 -0
- package/lib/ts-codegen-import-extension.mjs +228 -19
- package/package.json +15 -8
- package/runtime/config.mjs +218 -2
- package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
- package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
- package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
- package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
- package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
- package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
- package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
- package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
- package/runtime/engine/chunk-5575APCJ.mjs +215 -0
- package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
- package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
- package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
- package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
- package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
- package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
- package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
- package/runtime/engine/chunk-6W653LXI.mjs +13 -0
- package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
- package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
- package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
- package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
- package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
- package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
- package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
- package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
- package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
- package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
- package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
- package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
- package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
- package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
- package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
- package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
- package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
- package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
- package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
- package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
- package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
- package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
- package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
- package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
- package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
- package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
- package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
- package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
- package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
- package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
- package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
- package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
- package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
- package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
- package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
- package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
- package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
- package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
- package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
- package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
- package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
- package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
- package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
- package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
- package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
- package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
- package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
- package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
- package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
- package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
- package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
- package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
- package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
- package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
- package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
- package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
- package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
- package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
- package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
- package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
- package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
- package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
- package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
- package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
- package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
- package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
- package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
- package/runtime/engine/chunk-YRHM272W.mjs +528 -0
- package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
- package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
- package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
- package/runtime/engine/composition.mjs +325 -0
- package/runtime/engine/document-local.mjs +504 -0
- package/runtime/engine/graph.json +4134 -0
- package/runtime/engine/index.mjs +265 -0
- package/runtime/engine/local-postgres-support.mjs +69 -0
- package/runtime/engine/local.mjs +3275 -0
- package/runtime/engine/pglite-directory-lock.mjs +8 -0
- package/runtime/engine/rag.mjs +11 -0
- package/runtime/engine/search.mjs +18 -0
- package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
- package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
- package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
- package/runtime/framework-migrations/manifest.json +56 -0
- package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
- package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
- package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
- package/runtime/runtime-metadata.json +27 -0
- package/runtime/tooling.mjs +10399 -8951
- package/scripts/bundle-runtime-config.mjs +23 -0
- package/scripts/bundle-runtime.mjs +100 -0
- package/scripts/bundle-runtime.test.mjs +33 -0
- package/scripts/bundle-shared.mjs +3 -0
- package/scripts/copy-dashboard.mjs +16 -0
- package/scripts/pre-publish-check.mjs +23 -11
- package/templateFeature/ai/ai-facade.ts +38 -15
- package/templateFeature/ai/manifest.json +1 -0
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +5 -2
- package/templateFeature/tools/tools.ts +3 -3
- package/runtime/server.mjs +0 -14389
- package/scripts/bundle-server.mjs +0 -223
- package/server/config.js +0 -1
- package/server/index.js +0 -1
- package/server/package.json +0 -6
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ragOperationError,
|
|
3
|
+
snapshotRagScopeInput
|
|
4
|
+
} from "./chunk-5TACQ2US.mjs";
|
|
5
|
+
import {
|
|
6
|
+
RuntimeDiagnosticError
|
|
7
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
8
|
+
|
|
9
|
+
// ../runtime/dist/rag/operations-diagnostic.js
|
|
10
|
+
var actions = {
|
|
11
|
+
RAG_OPERATIONS_INPUT_INVALID: "Correct the operation filters or fixtures. Supply a valid scope, finite limit, known mode/operation and required source IDs/full-rebuild confirmation. No provider or RAG write was admitted.",
|
|
12
|
+
RAG_OPERATIONS_STATE_INVALID: "Inspect the same corpus and selected database readiness. Preserve existing sources, jobs and metrics; do not edit internal rows or start replacement provider work.",
|
|
13
|
+
RAG_OPERATIONS_OBSERVATION_UNAVAILABLE: "Restore selected database readiness and read access, then inspect the same corpus. This read changed no data; do not recreate framework tables.",
|
|
14
|
+
RAG_OPERATIONS_SIZE_LIMIT_EXCEEDED: "Reduce fixtures, queries, claims or source IDs; filter summary by corpus or plan smaller explicit source sets. Inputs are limited to 128 fixtures/1 MiB, 8192 plan sources and 1024 summary scopes. No new provider work was admitted for input rejection.",
|
|
15
|
+
RAG_EVALUATION_CAPABILITY_UNAVAILABLE: "Select and restore the required search/grounding capability before evaluating. Summary, metrics and reindex planning remain available; do not enable a paid provider implicitly.",
|
|
16
|
+
RAG_EVALUATION_OUTCOME_UNKNOWN: "Inspect rag_operations.metrics with operation evaluate for the same evaluation receipt before another explicit evaluation. Provider work or metrics may have committed; do not blindly repeat calls or infer exactly-once charging."
|
|
17
|
+
};
|
|
18
|
+
function ragOperationsError(code, dataImpact = "none", evaluationId) {
|
|
19
|
+
return new RuntimeDiagnosticError({
|
|
20
|
+
code,
|
|
21
|
+
stage: "request",
|
|
22
|
+
capability: code === "RAG_OPERATIONS_OBSERVATION_UNAVAILABLE" ? "database" : "application",
|
|
23
|
+
servingStarted: "unchanged",
|
|
24
|
+
dataImpact,
|
|
25
|
+
retryable: false,
|
|
26
|
+
retryPrecondition: code === "RAG_EVALUATION_OUTCOME_UNKNOWN" ? "Establish the prior provider/metric outcome for this same evaluation before a new action." : "Correct the named input, scope, state or selected capability before resubmitting this operation.",
|
|
27
|
+
nextAction: `${actions[code]}${evaluationId && /^[a-f0-9-]{36}$/u.test(evaluationId) ? ` Evaluation receipt: ${evaluationId}.` : ""}`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ../runtime/dist/rag/operations-scope.js
|
|
32
|
+
function createRagOperationsScope(requireIdentity) {
|
|
33
|
+
let owner;
|
|
34
|
+
function active() {
|
|
35
|
+
const identity = requireIdentity();
|
|
36
|
+
if (!identity)
|
|
37
|
+
throw new RuntimeDiagnosticError({
|
|
38
|
+
code: "RUNTIME_AUTHENTICATION_REQUIRED",
|
|
39
|
+
stage: "request",
|
|
40
|
+
capability: "auth",
|
|
41
|
+
servingStarted: "unchanged",
|
|
42
|
+
dataImpact: "none",
|
|
43
|
+
retryable: false,
|
|
44
|
+
retryPrecondition: "Authenticate before using RAG operations.",
|
|
45
|
+
nextAction: "Sign in as the intended corpus owner. No operation was admitted."
|
|
46
|
+
});
|
|
47
|
+
owner ??= identity.id;
|
|
48
|
+
if (owner !== identity.id)
|
|
49
|
+
throw ragOperationError("RAG_SCOPE_FORBIDDEN");
|
|
50
|
+
return owner;
|
|
51
|
+
}
|
|
52
|
+
function scope(input) {
|
|
53
|
+
const user = active();
|
|
54
|
+
let captured;
|
|
55
|
+
try {
|
|
56
|
+
captured = snapshotRagScopeInput(input);
|
|
57
|
+
} catch {
|
|
58
|
+
throw ragOperationsError("RAG_OPERATIONS_INPUT_INVALID");
|
|
59
|
+
}
|
|
60
|
+
const ownerUserId = captured.ownerUserId ?? (captured.visibility === "private" ? user : null);
|
|
61
|
+
if (ownerUserId !== null && ownerUserId !== user)
|
|
62
|
+
throw ragOperationError("RAG_SCOPE_FORBIDDEN");
|
|
63
|
+
return Object.freeze({
|
|
64
|
+
corpus: captured.corpus,
|
|
65
|
+
visibility: captured.visibility,
|
|
66
|
+
ownerUserId
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return Object.freeze({ active, scope });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// ../runtime/dist/adapters/rag/pgvector/operations-scope.js
|
|
73
|
+
import { sql } from "drizzle-orm";
|
|
74
|
+
function ragOperationsPredicate(alias, scope) {
|
|
75
|
+
const prefix = sql.raw(alias);
|
|
76
|
+
return sql`${prefix}.corpus=${scope.corpus} AND ${prefix}.visibility_scope=${scope.visibility} AND ${prefix}.owner_user_id IS NOT DISTINCT FROM ${scope.ownerUserId}`;
|
|
77
|
+
}
|
|
78
|
+
var ragMetricKinds = ["ingest", "retrieve", "answer", "reindex", "evaluate"];
|
|
79
|
+
var validRagMetric = sql`m.visibility_scope IN ('private','shared','public') AND (m.owner_user_id IS NOT NULL OR m.visibility_scope IN ('shared','public'))
|
|
80
|
+
AND m.operation IN ('ingest','retrieve','answer','reindex','evaluate') AND m.metric_value NOT IN ('NaN'::float8,'Infinity'::float8,'-Infinity'::float8)
|
|
81
|
+
AND isfinite(m.recorded_at) AND octet_length(m.metadata::text)<=65536 AND octet_length(m.metric_name)<=256
|
|
82
|
+
AND (m.unit IS NULL OR m.unit IN ('ms','count','tokens','usd'))`;
|
|
83
|
+
|
|
84
|
+
export {
|
|
85
|
+
ragOperationsError,
|
|
86
|
+
createRagOperationsScope,
|
|
87
|
+
ragOperationsPredicate,
|
|
88
|
+
ragMetricKinds,
|
|
89
|
+
validRagMetric
|
|
90
|
+
};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import {
|
|
2
|
+
administrationMetadata,
|
|
3
|
+
captureAzureNamespaceOption,
|
|
4
|
+
resolveRuntimeUploadLimits,
|
|
5
|
+
storageAdministrationMetadataInvalid,
|
|
6
|
+
storageAdministrationReadLimit
|
|
7
|
+
} from "./chunk-N4LTCKJP.mjs";
|
|
8
|
+
import {
|
|
9
|
+
runtimeStartupError
|
|
10
|
+
} from "./chunk-IFMOTJNU.mjs";
|
|
11
|
+
import {
|
|
12
|
+
RUNTIME_REQUEST_CORRELATION_HEADER,
|
|
13
|
+
RuntimeDiagnosticError,
|
|
14
|
+
runtimeRequestCorrelation
|
|
15
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
16
|
+
|
|
17
|
+
// ../runtime/dist/adapters/storage/config.js
|
|
18
|
+
function parseRuntimeStorageConfig(input, environment = {}) {
|
|
19
|
+
const namespace = input.adapter === "azure-blob" ? captureAzureNamespaceOption(input) : void 0;
|
|
20
|
+
const limits = resolveRuntimeUploadLimits(input);
|
|
21
|
+
const required = environment.GENCOW_STORAGE_REQUIRE_READ_GRANT === "1";
|
|
22
|
+
const appName = environment.GENCOW_APP_NAME;
|
|
23
|
+
const readGrantSecret = environment.GENCOW_INTERNAL_TOKEN;
|
|
24
|
+
if (required && (!appName || !readGrantSecret))
|
|
25
|
+
throw runtimeStartupError("RUNTIME_STORAGE_READ_POLICY_MISSING", "Supply the captured storage app/signing binding before starting grant-protected storage; retain existing keys and namespace.", "none", "storage");
|
|
26
|
+
const readPolicy = appName || readGrantSecret || required ? Object.freeze({
|
|
27
|
+
appName,
|
|
28
|
+
readGrantSecret,
|
|
29
|
+
requireReadGrant: required,
|
|
30
|
+
maxFileSizeBytes: limits.maxFileSizeBytes
|
|
31
|
+
}) : void 0;
|
|
32
|
+
if (input.adapter === "filesystem" && input.directory)
|
|
33
|
+
return Object.freeze({
|
|
34
|
+
adapter: "filesystem",
|
|
35
|
+
directory: input.directory,
|
|
36
|
+
image: resolveRuntimeFilesystemImagePolicy(input.image),
|
|
37
|
+
...limits,
|
|
38
|
+
...readPolicy ? { readPolicy } : {}
|
|
39
|
+
});
|
|
40
|
+
if (input.adapter === "azure-blob" && isAzureAccountUrl(input.accountUrl) && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/u.test(input.container)) {
|
|
41
|
+
const tenantId = environment.AZURE_TENANT_ID;
|
|
42
|
+
const clientId = environment.AZURE_CLIENT_ID;
|
|
43
|
+
const clientSecret = environment.AZURE_CLIENT_SECRET;
|
|
44
|
+
if (!tenantId || !clientId || !clientSecret)
|
|
45
|
+
throw runtimeStartupError("RUNTIME_STORAGE_CREDENTIALS_MISSING", "Supply the selected Azure service-principal credentials through the trusted launcher configuration before restarting.", "none", "storage");
|
|
46
|
+
return Object.freeze({
|
|
47
|
+
...limits,
|
|
48
|
+
adapter: input.adapter,
|
|
49
|
+
accountUrl: input.accountUrl,
|
|
50
|
+
container: input.container,
|
|
51
|
+
namespace,
|
|
52
|
+
credential: Object.freeze({ tenantId, clientId, clientSecret }),
|
|
53
|
+
...readPolicy ? { readPolicy } : {}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
throw runtimeStartupError("RUNTIME_STORAGE_CONFIG_INVALID", "Configure a supported Runtime storage adapter and restart.", "none", "storage");
|
|
57
|
+
}
|
|
58
|
+
function resolveRuntimeFilesystemImagePolicy(value) {
|
|
59
|
+
if (value === void 0)
|
|
60
|
+
return Object.freeze({ enabled: true });
|
|
61
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
62
|
+
throw runtimeStartupError("RUNTIME_STORAGE_CONFIG_INVALID", "Set only the optional filesystem image enabled flag in trusted Runtime storage configuration, then restart.");
|
|
63
|
+
let enabled = true;
|
|
64
|
+
try {
|
|
65
|
+
const prototype = Object.getPrototypeOf(value);
|
|
66
|
+
const keys = Reflect.ownKeys(value);
|
|
67
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, "enabled");
|
|
68
|
+
if (prototype !== Object.prototype && prototype !== null || keys.some((key) => key !== "enabled") || descriptor !== void 0 && (!Object.hasOwn(descriptor, "value") || typeof descriptor.value !== "boolean"))
|
|
69
|
+
throw new Error("Invalid filesystem image selection");
|
|
70
|
+
if (descriptor)
|
|
71
|
+
enabled = descriptor.value;
|
|
72
|
+
} catch {
|
|
73
|
+
throw runtimeStartupError("RUNTIME_STORAGE_CONFIG_INVALID", "Set only the optional filesystem image enabled flag in trusted Runtime storage configuration, then restart.");
|
|
74
|
+
}
|
|
75
|
+
return Object.freeze({ enabled });
|
|
76
|
+
}
|
|
77
|
+
function isAzureAccountUrl(value) {
|
|
78
|
+
try {
|
|
79
|
+
const url = new URL(value);
|
|
80
|
+
return url.protocol === "https:" && !url.username && !url.password && url.pathname === "/" && !url.search && !url.hash;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ../runtime/dist/adapters/storage/content-response.js
|
|
87
|
+
function safeStorageContentMetadata(file) {
|
|
88
|
+
return administrationMetadata(file, file.createdAt === void 0 ? void 0 : new Date(file.createdAt), file.source);
|
|
89
|
+
}
|
|
90
|
+
var storageObjectNotFoundFields = {
|
|
91
|
+
code: "RUNTIME_STORAGE_OBJECT_NOT_FOUND",
|
|
92
|
+
stage: "request",
|
|
93
|
+
capability: "storage",
|
|
94
|
+
servingStarted: "unchanged",
|
|
95
|
+
dataImpact: "none",
|
|
96
|
+
retryable: false
|
|
97
|
+
};
|
|
98
|
+
function publicStorageObjectNotFound() {
|
|
99
|
+
return new RuntimeDiagnosticError({
|
|
100
|
+
...storageObjectNotFoundFields,
|
|
101
|
+
retryPrecondition: "For private storage, obtain a current short-lived grant from the selected app's trusted Storage API; for public storage, ask the app owner to confirm public access is intended.",
|
|
102
|
+
nextAction: "If authorized in the app, call ctx.storage.createReadGrant for the intended object and share the short-lived URL only with its recipient. Otherwise ask the app owner for an authorized grant. Do not make private storage public just to bypass a missing, expired, or invalid grant; no bytes were returned."
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function publicStorageObjectNotFoundResponse(request, status = 404) {
|
|
106
|
+
const correlationId = runtimeRequestCorrelation(request);
|
|
107
|
+
const headers = {
|
|
108
|
+
"cache-control": "no-store",
|
|
109
|
+
"content-type": "application/json",
|
|
110
|
+
[RUNTIME_REQUEST_CORRELATION_HEADER]: correlationId
|
|
111
|
+
};
|
|
112
|
+
if (request.method === "HEAD")
|
|
113
|
+
return new Response(null, { status, headers });
|
|
114
|
+
return Response.json({
|
|
115
|
+
error: "The storage object was not found.",
|
|
116
|
+
...storageObjectNotFoundFields,
|
|
117
|
+
retryPrecondition: "Do not retry this link. For private storage, first open the file through the app from an active authorized session to request a fresh short-lived link; for public storage, ask the app owner to verify intended access.",
|
|
118
|
+
nextAction: "Open the file through the app while signed into an active authorized session to get a fresh link. If the file should be public, ask the app owner to verify that setting. No bytes were returned, and file data and metadata were unchanged; do not make private storage public to bypass a missing, expired, or invalid link.",
|
|
119
|
+
correlationId
|
|
120
|
+
}, { status, headers });
|
|
121
|
+
}
|
|
122
|
+
async function storageContentResponse(port, id, request, publicOnly = false, notFound = publicStorageObjectNotFound) {
|
|
123
|
+
if (publicOnly && (!isSupportedReadRequest(request) || (await port.inspect(id))?.visibility !== "public"))
|
|
124
|
+
throw notFound();
|
|
125
|
+
const content = await port.content(id);
|
|
126
|
+
if (!content)
|
|
127
|
+
throw notFound();
|
|
128
|
+
const metadata = safeStorageContentMetadata(content.metadata);
|
|
129
|
+
if (metadata.id !== id || !(content.bytes instanceof Uint8Array) || content.bytes.byteLength !== metadata.size)
|
|
130
|
+
throw storageAdministrationMetadataInvalid();
|
|
131
|
+
if (metadata.size > port.limits.maxFileSizeBytes)
|
|
132
|
+
throw storageAdministrationReadLimit(port.limits.maxFileSizeBytes);
|
|
133
|
+
if (publicOnly) {
|
|
134
|
+
const currentValue = await port.inspect(id);
|
|
135
|
+
if (!currentValue || metadata.visibility !== "public" || currentValue.visibility !== "public")
|
|
136
|
+
throw notFound();
|
|
137
|
+
const current = safeStorageContentMetadata(currentValue);
|
|
138
|
+
if (JSON.stringify(current) !== JSON.stringify(metadata))
|
|
139
|
+
throw notFound();
|
|
140
|
+
}
|
|
141
|
+
return formatStorageContentResponse(metadata, content.bytes, request);
|
|
142
|
+
}
|
|
143
|
+
function isSupportedReadRequest(request) {
|
|
144
|
+
return (request.method === "GET" || request.method === "HEAD") && request.body === null;
|
|
145
|
+
}
|
|
146
|
+
function formatStorageContentResponse(metadata, bytes, request, disposition, varyAccept = false) {
|
|
147
|
+
const type = metadata.type.split(";", 1)[0].trim().toLowerCase();
|
|
148
|
+
const safeType = /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/u.test(type) ? type : "application/octet-stream";
|
|
149
|
+
const inline = disposition === "attachment" ? false : disposition === "inline" ? true : /^(?:image\/(?:png|jpeg|gif|webp|avif)|audio\/(?:mpeg|wav|ogg)|video\/(?:mp4|webm))$/u.test(safeType);
|
|
150
|
+
const filename = Array.from(Buffer.from(metadata.name, "utf8").toString("utf8")).slice(0, 160).join("");
|
|
151
|
+
const ascii = filename.replace(/[^a-zA-Z0-9._ -]/gu, "_").slice(0, 160) || "download";
|
|
152
|
+
const encoded = encodeURIComponent(filename).replace(/['()*]/gu, (char) => "%" + char.charCodeAt(0).toString(16).toUpperCase());
|
|
153
|
+
const headers = {
|
|
154
|
+
"content-type": safeType,
|
|
155
|
+
"content-length": String(metadata.size),
|
|
156
|
+
"cache-control": "no-store",
|
|
157
|
+
"content-disposition": `${inline ? "inline" : "attachment"}; filename="${ascii}"; filename*=UTF-8''${encoded}`,
|
|
158
|
+
"x-content-type-options": "nosniff",
|
|
159
|
+
"x-frame-options": "DENY",
|
|
160
|
+
"content-security-policy": "sandbox; default-src 'none'; base-uri 'none'; frame-ancestors 'none'"
|
|
161
|
+
};
|
|
162
|
+
if (varyAccept)
|
|
163
|
+
headers.vary = "Accept";
|
|
164
|
+
return new Response(request.method === "HEAD" ? null : bytes, { headers });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ../runtime/dist/adapters/storage/image-transform-policy.js
|
|
168
|
+
var runtimeFilesystemImagePolicy = Object.freeze({
|
|
169
|
+
maxInputBytes: 16 * 1024 * 1024,
|
|
170
|
+
maxOutputBytes: 16 * 1024 * 1024,
|
|
171
|
+
maxDecodedPixels: 4096 * 4096,
|
|
172
|
+
maxDimension: 4096,
|
|
173
|
+
maxCacheBytes: 128 * 1024 * 1024,
|
|
174
|
+
maxCacheEntries: 1e3,
|
|
175
|
+
maxActive: 1,
|
|
176
|
+
maxQueued: 8,
|
|
177
|
+
queueWaitMs: 750,
|
|
178
|
+
workTimeoutMs: 3e3,
|
|
179
|
+
autoQuality: 80
|
|
180
|
+
});
|
|
181
|
+
var transformNames = ["w", "h", "q", "f", "fit"];
|
|
182
|
+
var formats = /* @__PURE__ */ new Set(["webp", "avif", "jpeg", "png"]);
|
|
183
|
+
var fits = /* @__PURE__ */ new Set(["cover", "contain", "fill", "inside"]);
|
|
184
|
+
function integerValue(value, minimum, maximum) {
|
|
185
|
+
if (!/^[0-9]+$/u.test(value))
|
|
186
|
+
return void 0;
|
|
187
|
+
const parsed = Number(value);
|
|
188
|
+
return Number.isSafeInteger(parsed) && parsed >= minimum && parsed <= maximum ? parsed : void 0;
|
|
189
|
+
}
|
|
190
|
+
function parseExplicitTransform(url) {
|
|
191
|
+
const values = /* @__PURE__ */ new Map();
|
|
192
|
+
for (const name of transformNames) {
|
|
193
|
+
const found = url.searchParams.getAll(name);
|
|
194
|
+
if (found.length > 1)
|
|
195
|
+
return "invalid";
|
|
196
|
+
if (found.length === 1)
|
|
197
|
+
values.set(name, found[0]);
|
|
198
|
+
}
|
|
199
|
+
if (values.size === 0)
|
|
200
|
+
return "none";
|
|
201
|
+
const width = values.has("w") ? integerValue(values.get("w"), 1, runtimeFilesystemImagePolicy.maxDimension) : void 0;
|
|
202
|
+
const height = values.has("h") ? integerValue(values.get("h"), 1, runtimeFilesystemImagePolicy.maxDimension) : void 0;
|
|
203
|
+
const quality = values.has("q") ? integerValue(values.get("q"), 1, 100) : runtimeFilesystemImagePolicy.autoQuality;
|
|
204
|
+
const rawFormat = values.get("f");
|
|
205
|
+
const format = rawFormat === void 0 ? "webp" : rawFormat;
|
|
206
|
+
const rawFit = values.get("fit");
|
|
207
|
+
const fit = rawFit === void 0 ? "cover" : rawFit;
|
|
208
|
+
if (values.has("w") && width === void 0 || values.has("h") && height === void 0 || quality === void 0 || !formats.has(format) || !fits.has(fit))
|
|
209
|
+
return "invalid";
|
|
210
|
+
return Object.freeze({
|
|
211
|
+
format,
|
|
212
|
+
...width !== void 0 ? { width } : {},
|
|
213
|
+
...height !== void 0 ? { height } : {},
|
|
214
|
+
quality,
|
|
215
|
+
fit
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function parseAccept(value) {
|
|
219
|
+
if (!value)
|
|
220
|
+
return [];
|
|
221
|
+
const output = [];
|
|
222
|
+
for (const entry of value.split(",")) {
|
|
223
|
+
const [media = "", ...parameters] = entry.trim().split(";");
|
|
224
|
+
const [type = "", subtype = ""] = media.trim().toLowerCase().split("/", 2);
|
|
225
|
+
if (!/^(?:[a-z0-9!#$&^_.+-]+|\*)$/u.test(type) || !/^(?:[a-z0-9!#$&^_.+-]+|\*)$/u.test(subtype) || type === "*" && subtype !== "*")
|
|
226
|
+
continue;
|
|
227
|
+
let quality = 1;
|
|
228
|
+
for (const parameter of parameters) {
|
|
229
|
+
const [rawName, ...rawValue] = parameter.trim().split("=");
|
|
230
|
+
if (rawName?.trim().toLowerCase() !== "q")
|
|
231
|
+
continue;
|
|
232
|
+
const rawQuality = rawValue.join("=").trim().replace(/^"|"$/gu, "");
|
|
233
|
+
if (!/^(?:0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/u.test(rawQuality)) {
|
|
234
|
+
quality = 0;
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
quality = Number(rawQuality);
|
|
238
|
+
}
|
|
239
|
+
output.push({ type, subtype, quality });
|
|
240
|
+
}
|
|
241
|
+
return output;
|
|
242
|
+
}
|
|
243
|
+
function acceptedQuality(ranges, mime) {
|
|
244
|
+
const [wantedType, wantedSubtype] = mime.split("/", 2);
|
|
245
|
+
let specificity = -1;
|
|
246
|
+
let quality = 0;
|
|
247
|
+
for (const range of ranges) {
|
|
248
|
+
if (range.type !== "*" && range.type !== wantedType)
|
|
249
|
+
continue;
|
|
250
|
+
if (range.subtype !== "*" && range.subtype !== wantedSubtype)
|
|
251
|
+
continue;
|
|
252
|
+
const candidateSpecificity = range.type === "*" ? 0 : range.subtype === "*" ? 1 : 2;
|
|
253
|
+
if (candidateSpecificity > specificity) {
|
|
254
|
+
specificity = candidateSpecificity;
|
|
255
|
+
quality = range.quality;
|
|
256
|
+
} else if (candidateSpecificity === specificity) {
|
|
257
|
+
quality = Math.max(quality, range.quality);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return quality;
|
|
261
|
+
}
|
|
262
|
+
function acceptsWebpInsteadOf(request, normalizedType) {
|
|
263
|
+
const ranges = parseAccept(request.headers.get("accept"));
|
|
264
|
+
const webpQuality = acceptedQuality(ranges, "image/webp");
|
|
265
|
+
const originalQuality = acceptedQuality(ranges, normalizedType === "image/jpg" ? "image/jpeg" : normalizedType);
|
|
266
|
+
return webpQuality > 0 && webpQuality >= originalQuality;
|
|
267
|
+
}
|
|
268
|
+
function selectRuntimeImageTransform(request, sourceType) {
|
|
269
|
+
const explicit = parseExplicitTransform(new URL(request.url));
|
|
270
|
+
if (explicit === "invalid")
|
|
271
|
+
return { kind: "invalid", varyAccept: false };
|
|
272
|
+
const normalizedType = sourceType.split(";", 1)[0].trim().toLowerCase();
|
|
273
|
+
if (explicit !== "none") {
|
|
274
|
+
if (!/^image\/(?:png|jpeg|jpg|webp)$/u.test(normalizedType))
|
|
275
|
+
return { kind: "original", varyAccept: false };
|
|
276
|
+
return { kind: "transform", transform: explicit, varyAccept: false };
|
|
277
|
+
}
|
|
278
|
+
if (!/^image\/(?:png|jpeg|jpg)$/u.test(normalizedType))
|
|
279
|
+
return { kind: "original", varyAccept: false };
|
|
280
|
+
if (acceptsWebpInsteadOf(request, normalizedType)) {
|
|
281
|
+
return {
|
|
282
|
+
kind: "transform",
|
|
283
|
+
transform: Object.freeze({
|
|
284
|
+
format: "webp",
|
|
285
|
+
quality: runtimeFilesystemImagePolicy.autoQuality,
|
|
286
|
+
fit: "inside"
|
|
287
|
+
}),
|
|
288
|
+
varyAccept: true
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return { kind: "original", varyAccept: true };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export {
|
|
295
|
+
safeStorageContentMetadata,
|
|
296
|
+
publicStorageObjectNotFound,
|
|
297
|
+
publicStorageObjectNotFoundResponse,
|
|
298
|
+
storageContentResponse,
|
|
299
|
+
formatStorageContentResponse,
|
|
300
|
+
runtimeFilesystemImagePolicy,
|
|
301
|
+
acceptsWebpInsteadOf,
|
|
302
|
+
selectRuntimeImageTransform,
|
|
303
|
+
parseRuntimeStorageConfig,
|
|
304
|
+
resolveRuntimeFilesystemImagePolicy
|
|
305
|
+
};
|