create-freeholder 0.2.0-beta.5 → 0.2.0-beta.6
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/template/.changeset/blog-playground-content.md +4 -0
- package/dist/template/.changeset/blog-wordpress-structure.md +6 -0
- package/dist/template/.changeset/managed-preview-assistant.md +4 -0
- package/dist/template/.changeset/public-beta-6.md +4 -0
- package/dist/template/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
- package/dist/template/MASTER.md +81 -8
- package/dist/template/README.md +1 -1
- package/dist/template/app/(admin)/admin/assistant/page.tsx +9 -1
- package/dist/template/app/(admin)/admin/blog/PostSettings.tsx +26 -0
- package/dist/template/app/(admin)/admin/blog/[kind]/page.tsx +53 -0
- package/dist/template/app/(admin)/admin/blog/actions.ts +186 -6
- package/dist/template/app/(admin)/admin/blog/comments/page.tsx +25 -0
- package/dist/template/app/(admin)/admin/blog/page.tsx +21 -5
- package/dist/template/app/(admin)/admin/imports/[id]/page.tsx +2 -0
- package/dist/template/app/(admin)/admin/pages/[id]/page.tsx +3 -0
- package/dist/template/app/(admin)/assistant-actions.ts +13 -6
- package/dist/template/app/(public)/[[...slug]]/ReaderComments.tsx +25 -0
- package/dist/template/app/(public)/[[...slug]]/blog-parts.tsx +153 -0
- package/dist/template/app/(public)/[[...slug]]/comment-actions.ts +16 -0
- package/dist/template/app/(public)/[[...slug]]/page.tsx +182 -18
- package/dist/template/app/api/chat/assistant/call/route.ts +35 -0
- package/dist/template/db/migrations/0061_blog_structure.sql +89 -0
- package/dist/template/db/migrations/0062_blog_reader_comments.sql +24 -0
- package/dist/template/db/migrations/meta/_journal.json +14 -0
- package/dist/template/deploy/blog-wordpress-2026-11-07.md +146 -0
- package/dist/template/deploy/docker-selfhost/.env.example +1 -1
- package/dist/template/deploy/docker-selfhost/README.md +3 -2
- package/dist/template/deploy/docker-selfhost/infra/compose.https.yml +1 -1
- package/dist/template/deploy/docker-selfhost/infra/compose.yml +1 -1
- package/dist/template/deploy/f-criteria-matrix.md +74 -0
- package/dist/template/deploy/linux/README.md +1 -1
- package/dist/template/deploy/linux/install.sh +1 -1
- package/dist/template/deploy/managed-preview-assistant.md +99 -0
- package/dist/template/eslint.config.mjs +3 -1
- package/dist/template/locales/ar.json +85 -6
- package/dist/template/locales/en.json +83 -4
- package/dist/template/locales/es.json +83 -4
- package/dist/template/locales/fr.json +85 -6
- package/dist/template/next.config.ts +2 -0
- package/dist/template/package.json +1 -1
- package/dist/template/packages/cli/package.json +1 -1
- package/dist/template/packages/create-freeholder/package.json +1 -1
- package/dist/template/packages/freeholder-app/package.json +1 -1
- package/dist/template/packages/mobile-app/package.json +1 -1
- package/dist/template/packages/plugin-kit/package.json +1 -1
- package/dist/template/packages/sdk/package.json +1 -1
- package/dist/template/packages/sdk/src/generated.ts +177 -9
- package/dist/template/packages/sdk/src/version.ts +1 -1
- package/dist/template/packages/templates/package.json +1 -1
- package/dist/template/proxy.ts +18 -1
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/NOTICE.txt +117 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/audio-output-processor.js +267 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.js +847 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/decoderWorker.min.wasm +0 -0
- package/dist/template/public/managed-assistant/0.1.10/duplex-codec/encoderWorker.min.js +1 -0
- package/dist/template/public/managed-assistant/0.1.10/manifest.json +12 -0
- package/dist/template/public/managed-assistant/0.1.10/pm-ai-duplex-client.js +1376 -0
- package/dist/template/scripts/license-headers.mjs +3 -0
- package/dist/template/scripts/verify-wordpress-migration.d.mts +8 -0
- package/dist/template/scripts/verify-wordpress-migration.mjs +105 -0
- package/dist/template/security/adversarial-audit-2026-10-08.md +1 -1
- package/dist/template/src/adapters/ai/types.ts +5 -0
- package/dist/template/src/adapters/paradise/assistant.ts +37 -0
- package/dist/template/src/adapters/paradise/http.ts +4 -3
- package/dist/template/src/core/contract/json-schema.ts +8 -0
- package/dist/template/src/core/demo/playground-inserts.ts +29 -0
- package/dist/template/src/core/demo/playground-policy.ts +9 -0
- package/dist/template/src/core/env.ts +2 -0
- package/dist/template/src/core/http/csp.ts +10 -2
- package/dist/template/src/core/http/csrf-client.ts +10 -0
- package/dist/template/src/core/import/service.ts +217 -12
- package/dist/template/src/core/import/wordpress.ts +80 -15
- package/dist/template/src/core/notifications/service.ts +1 -0
- package/dist/template/src/core/retention/registry.ts +2 -0
- package/dist/template/src/core/search/registry.ts +2 -0
- package/dist/template/src/core/seo/feeds.ts +2 -0
- package/dist/template/src/core/seo/jsonld.ts +46 -2
- package/dist/template/src/core/seo/legacy-proxy.ts +53 -0
- package/dist/template/src/core/seo/meta.ts +10 -7
- package/dist/template/src/core/seo/service.ts +14 -1
- package/dist/template/src/core/update/release-declaration.json +1 -1
- package/dist/template/src/modules/assistant/contract.ts +1 -1
- package/dist/template/src/modules/assistant/limits.ts +3 -0
- package/dist/template/src/modules/assistant/preview.ts +124 -0
- package/dist/template/src/modules/assistant/provider.ts +7 -0
- package/dist/template/src/modules/assistant/service.ts +21 -5
- package/dist/template/src/modules/cms/blocks/PreviewAssistantCall.tsx +176 -0
- package/dist/template/src/modules/cms/blocks/SiteChatClient.tsx +10 -4
- package/dist/template/src/modules/cms/blocks/surfaces.tsx +10 -0
- package/dist/template/src/modules/cms/blog-comments-schema.ts +27 -0
- package/dist/template/src/modules/cms/blog-comments.ts +111 -0
- package/dist/template/src/modules/cms/blog-schema.ts +146 -0
- package/dist/template/src/modules/cms/blog-service.ts +999 -0
- package/dist/template/src/modules/cms/blog.tsx +245 -25
- package/dist/template/src/modules/cms/manifest.ts +7 -1
- package/dist/template/src/modules/cms/read.ts +18 -0
- package/dist/template/src/modules/cms/service.ts +22 -4
- package/dist/template/src/modules/cms/tables.ts +2 -0
- package/dist/template/src/modules/seed/launch.ts +31 -3
- package/dist/template/tests/browser/blog-structure.spec.ts +69 -0
- package/dist/template/tests/core/analytics-consent.test.ts +1 -1
- package/dist/template/tests/core/blog-playground.test.ts +106 -0
- package/dist/template/tests/core/blog-structure-comments.test.ts +166 -0
- package/dist/template/tests/core/csp.test.ts +1 -1
- package/dist/template/tests/core/internal-services.test.ts +4 -0
- package/dist/template/tests/core/legacy-redirect-proxy.test.ts +59 -0
- package/dist/template/tests/core/locale-routing.test.ts +1 -1
- package/dist/template/tests/core/playground-cache.test.ts +1 -1
- package/dist/template/tests/core/playground.test.ts +3 -3
- package/dist/template/tests/core/preview-assistant-call.test.ts +88 -0
- package/dist/template/tests/core/private-preview-webhooks.test.ts +1 -1
- package/dist/template/tests/core/private-preview.test.ts +1 -1
- package/dist/template/tests/core/proxy-locale.test.ts +1 -1
- package/dist/template/tests/core/sdk-schema.test.ts +20 -0
- package/dist/template/tests/core/seo.test.ts +1 -1
- package/dist/template/tests/core/site-chat-client.test.ts +50 -0
- package/dist/template/tests/core/wordpress-import-flow.test.ts +81 -18
- package/dist/template/tests/core/wordpress-import.test.ts +25 -12
- package/dist/template/tests/core/wordpress-migration-verification.test.ts +37 -0
- package/dist/template/tests/modules/preview-assistant.test.ts +164 -0
- package/dist/template-manifest.json +349 -139
- package/package.json +1 -1
|
@@ -21,6 +21,9 @@ const fix = process.argv.includes("--fix");
|
|
|
21
21
|
// rewrites migrations wholesale, and any dependency change rewrites the
|
|
22
22
|
// lockfile. JSON has no comment syntax at all.
|
|
23
23
|
const EXEMPT = [
|
|
24
|
+
// Redistributed, byte-pinned Opus/MIT/BSD codecs. Their original licenses
|
|
25
|
+
// live beside them in NOTICE.txt; never relabel these as Freeholder code.
|
|
26
|
+
/^public\/managed-assistant\/0\.1\.10\/duplex-codec\//,
|
|
24
27
|
/^db\/migrations\//,
|
|
25
28
|
/\.json$/,
|
|
26
29
|
/^next-env\.d\.ts$/,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export interface HtmlMetadata { title: string; canonical: string; description: string; robots: string; ogTitle: string; ogDescription: string; ogImage: string; hreflang: Record<string, string> }
|
|
4
|
+
export interface MigrationCheck { sourceUrl: string; requestPath: string; destinationPath: string; redirect: boolean; expected: Record<string, unknown> }
|
|
5
|
+
export interface MigrationPlan { sourceOrigin: string; status: string; warnings: string[]; checks: MigrationCheck[] }
|
|
6
|
+
export interface MigrationReport { verifiedAt: string; destinationOrigin: string; status: string; accepted: boolean; unresolved: string[]; rows: Array<MigrationCheck & { errors: string[]; warnings: string[]; sourceMeta?: HtmlMetadata; destinationMeta?: HtmlMetadata }> }
|
|
7
|
+
export function htmlMetadata(html: string): HtmlMetadata;
|
|
8
|
+
export function verifyMigration(plan: MigrationPlan, destinationOrigin: string): Promise<MigrationReport>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Read-only acceptance: export imports.wordpressVerificationPlan to JSON, then
|
|
4
|
+
// compare the source crawl and the destination over real HTTP before cutover.
|
|
5
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { parse } from "parse5";
|
|
8
|
+
|
|
9
|
+
export function htmlMetadata(html) {
|
|
10
|
+
const result = { title: "", canonical: "", description: "", robots: "", ogTitle: "", ogDescription: "", ogImage: "", hreflang: {} };
|
|
11
|
+
const text = node => node.nodeName === "#text" ? node.value : (node.childNodes ?? []).map(text).join("");
|
|
12
|
+
const visit = node => {
|
|
13
|
+
const attrs = Object.fromEntries((node.attrs ?? []).map(attr => [attr.name, attr.value]));
|
|
14
|
+
if (node.tagName === "title") result.title = text(node).trim();
|
|
15
|
+
if (node.tagName === "link" && attrs.rel?.split(/\s+/).includes("canonical")) result.canonical = attrs.href ?? "";
|
|
16
|
+
if (node.tagName === "link" && attrs.rel?.split(/\s+/).includes("alternate") && attrs.hreflang) result.hreflang[attrs.hreflang] = attrs.href ?? "";
|
|
17
|
+
if (node.tagName === "meta") {
|
|
18
|
+
const key = { description: "description", robots: "robots", "og:title": "ogTitle", "og:description": "ogDescription", "og:image": "ogImage" }[attrs.name ?? attrs.property];
|
|
19
|
+
if (key) result[key] = attrs.content ?? "";
|
|
20
|
+
}
|
|
21
|
+
for (const child of node.childNodes ?? []) visit(child);
|
|
22
|
+
};
|
|
23
|
+
visit(parse(html)); return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function read(url) {
|
|
27
|
+
const response = await fetch(url, { redirect: "manual", signal: AbortSignal.timeout(15000), headers: { "user-agent": "Freeholder-Migration-Verification/1.0" } });
|
|
28
|
+
return { status: response.status, location: response.headers.get("location"), type: response.headers.get("content-type") ?? "", body: await response.text() };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function verifyMigration(plan, destinationOrigin) {
|
|
32
|
+
const origin = new URL(destinationOrigin);
|
|
33
|
+
if (!["http:", "https:"].includes(origin.protocol) || origin.username || origin.password) throw new Error("Use an HTTP(S) destination without credentials.");
|
|
34
|
+
const source = new URL(plan.sourceOrigin);
|
|
35
|
+
if (!["http:", "https:"].includes(source.protocol) || source.username || source.password) throw new Error("Use an HTTP(S) source without credentials.");
|
|
36
|
+
const sourceMap = new Map(plan.checks.map(check => { const url = new URL(check.sourceUrl); return [`${url.pathname.replace(/\/+$/, "") || "/"}${url.search}`, check.destinationPath]; }));
|
|
37
|
+
const normalize = value => {
|
|
38
|
+
const parsed = new URL(value, origin);
|
|
39
|
+
if (parsed.origin === source.origin) {
|
|
40
|
+
const mapped = sourceMap.get(`${parsed.pathname.replace(/\/+$/, "") || "/"}${parsed.search}`);
|
|
41
|
+
if (mapped) { const destination = new URL(mapped, origin); parsed.pathname = destination.pathname; parsed.search = destination.search; }
|
|
42
|
+
parsed.host = origin.host; parsed.protocol = origin.protocol;
|
|
43
|
+
}
|
|
44
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/, "") || "/";
|
|
45
|
+
parsed.searchParams.sort(); return parsed.href;
|
|
46
|
+
};
|
|
47
|
+
const rows = [];
|
|
48
|
+
for (const check of plan.checks) {
|
|
49
|
+
const request = new URL(check.requestPath, origin);
|
|
50
|
+
const wanted = new URL(check.destinationPath, origin);
|
|
51
|
+
if (request.origin !== origin.origin || wanted.origin !== origin.origin) throw new Error("A destination path escaped the configured origin.");
|
|
52
|
+
const errors = [], warnings = [];
|
|
53
|
+
let response, sourceMeta, destinationMeta;
|
|
54
|
+
try {
|
|
55
|
+
response = await read(request);
|
|
56
|
+
if (check.redirect && response.status !== 301) errors.push(`Expected one 301, received ${response.status}.`);
|
|
57
|
+
if (response.status >= 300 && response.status < 400) {
|
|
58
|
+
const target = new URL(response.location ?? "", request);
|
|
59
|
+
if (normalize(target) !== normalize(wanted)) errors.push(`Unexpected redirect target: ${target.href}`);
|
|
60
|
+
if (target.origin !== origin.origin) throw new Error("Redirect escaped the destination origin.");
|
|
61
|
+
response = await read(target);
|
|
62
|
+
}
|
|
63
|
+
if (response.status !== 200) errors.push(`Final response was ${response.status}; required 200 after at most one redirect.`);
|
|
64
|
+
if (response.type.includes("text/html")) {
|
|
65
|
+
destinationMeta = htmlMetadata(response.body);
|
|
66
|
+
const expected = check.expected ?? {};
|
|
67
|
+
for (const key of ["title", "description", "ogTitle", "ogDescription"]) if (expected[key] && destinationMeta[key] !== expected[key]) errors.push(`${key} differs from the imported value.`);
|
|
68
|
+
const canonical = expected.canonical ? new URL(expected.canonical, origin) : wanted;
|
|
69
|
+
if (!destinationMeta.canonical || normalize(destinationMeta.canonical) !== normalize(canonical)) errors.push("Canonical differs from the intended destination.");
|
|
70
|
+
if (expected.noindex && !/\bnoindex\b/i.test(destinationMeta.robots)) errors.push("Imported noindex was lost.");
|
|
71
|
+
if (expected.nofollow && !/\bnofollow\b/i.test(destinationMeta.robots)) errors.push("Imported nofollow was lost.");
|
|
72
|
+
if (!check.redirect) {
|
|
73
|
+
try {
|
|
74
|
+
if (new URL(check.sourceUrl).origin !== source.origin) throw new Error("Source URL is outside the configured source origin.");
|
|
75
|
+
let old = await read(check.sourceUrl);
|
|
76
|
+
if (old.status >= 300 && old.status < 400 && old.location) {
|
|
77
|
+
const next = new URL(old.location, check.sourceUrl);
|
|
78
|
+
if (next.origin === source.origin) old = await read(next);
|
|
79
|
+
}
|
|
80
|
+
if (old.status !== 200 || !old.type.includes("text/html")) warnings.push(`Source metadata unavailable (${old.status}).`);
|
|
81
|
+
else {
|
|
82
|
+
sourceMeta = htmlMetadata(old.body);
|
|
83
|
+
for (const key of ["title", "description", "ogTitle", "ogDescription"]) if (sourceMeta[key] && sourceMeta[key] !== destinationMeta[key]) errors.push(`${key} changed from the rendered source.`);
|
|
84
|
+
if (sourceMeta.canonical && normalize(new URL(sourceMeta.canonical, source)) !== normalize(destinationMeta.canonical)) errors.push("Canonical changed from the rendered source.");
|
|
85
|
+
for (const directive of ["noindex", "nofollow"]) if (new RegExp(`\\b${directive}\\b`, "i").test(sourceMeta.robots) !== new RegExp(`\\b${directive}\\b`, "i").test(destinationMeta.robots)) errors.push(`${directive} changed from the source.`);
|
|
86
|
+
for (const [locale, href] of Object.entries(sourceMeta.hreflang)) if (!destinationMeta.hreflang[locale] || normalize(href) !== normalize(destinationMeta.hreflang[locale])) errors.push(`hreflang ${locale} changed or disappeared.`);
|
|
87
|
+
if (sourceMeta.ogImage && !destinationMeta.ogImage) errors.push("Open Graph image disappeared.");
|
|
88
|
+
}
|
|
89
|
+
} catch (error) { warnings.push(`Source comparison unavailable: ${error.message}`); }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} catch (error) { errors.push(error.message); }
|
|
93
|
+
rows.push({ ...check, errors, warnings, sourceMeta, destinationMeta });
|
|
94
|
+
}
|
|
95
|
+
return { verifiedAt: new Date().toISOString(), destinationOrigin: origin.origin, status: plan.status, accepted: plan.status === "published" && !plan.warnings.length && rows.every(row => !row.errors.length && !row.warnings.length), unresolved: plan.warnings, rows };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? "").href) {
|
|
99
|
+
const [planPath, destination, outputPath] = process.argv.slice(2);
|
|
100
|
+
if (!planPath || !destination || !outputPath) throw new Error("Usage: node scripts/verify-wordpress-migration.mjs PLAN.json https://destination.example REPORT.json");
|
|
101
|
+
const report = await verifyMigration(JSON.parse(await readFile(planPath, "utf8")), destination);
|
|
102
|
+
await writeFile(outputPath, JSON.stringify(report, null, 2) + "\n");
|
|
103
|
+
console.log(`${report.rows.length} URL checks; ${report.rows.filter(row => row.errors.length).length} failed; ${report.unresolved.length} unresolved source features. Report: ${outputPath}`);
|
|
104
|
+
if (!report.accepted) process.exitCode = 1;
|
|
105
|
+
}
|
|
@@ -5,7 +5,7 @@ independent security sign-off. Three adversarial agents reviewed separate
|
|
|
5
5
|
customer, security and platform worktrees based on main
|
|
6
6
|
`4ba5daac5eeea6a2202b1b3972defed13cb325a1`; the integrating agent reviewed
|
|
7
7
|
public CMS delivery and editor concurrency. C11.10 remains unchecked, and
|
|
8
|
-
Freeholder remains `0.2.0-beta.
|
|
8
|
+
Freeholder remains `0.2.0-beta.6` in active development.
|
|
9
9
|
|
|
10
10
|
## Findings and repairs
|
|
11
11
|
|
|
@@ -11,6 +11,9 @@ export interface AiGenerationRequest {
|
|
|
11
11
|
maxOutputTokens: number;
|
|
12
12
|
responseSchema?: Record<string, unknown>;
|
|
13
13
|
idempotencyKey: string;
|
|
14
|
+
/** Server-derived visitor binding and a reservation held by the consumer. */
|
|
15
|
+
visitorRef?: string;
|
|
16
|
+
maxChargeCents?: number;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
export interface AiGenerationResult {
|
|
@@ -19,6 +22,8 @@ export interface AiGenerationResult {
|
|
|
19
22
|
provider: string;
|
|
20
23
|
model: string;
|
|
21
24
|
usage: { inputTokens: number; outputTokens: number; totalTokens: number };
|
|
25
|
+
/** A managed adapter's authoritative list-price receipt, already bounded at admission. */
|
|
26
|
+
meteredCents?: number;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export interface AiAdapter {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// Managed text uses the same transcript, guardrails and audited turn as other
|
|
4
|
+
// assistant providers. PM owns the quote, allowance, exact talent and SFW rules.
|
|
5
|
+
import type { AiAdapter } from "@/adapters/ai/types";
|
|
6
|
+
import { paradiseRequest } from "./http";
|
|
7
|
+
|
|
8
|
+
export function createParadiseAssistantAi(): AiAdapter {
|
|
9
|
+
return {
|
|
10
|
+
id: "paradise-assistant",
|
|
11
|
+
status: { family: "ai", id: "paradise-assistant", available: true, message: "Managed site assistant" },
|
|
12
|
+
async generate(request) {
|
|
13
|
+
if (!request.visitorRef || !request.maxChargeCents || request.purpose !== "site-assistant") {
|
|
14
|
+
throw new Error("The managed assistant requires a visitor and a reserved budget.");
|
|
15
|
+
}
|
|
16
|
+
const result = await paradiseRequest<{
|
|
17
|
+
text: string; model: string; metered_list_usd: number; content_mode: string;
|
|
18
|
+
}>("/v1/ai/assistant/text", { body: {
|
|
19
|
+
visitor_ref: request.visitorRef,
|
|
20
|
+
request_id: request.idempotencyKey,
|
|
21
|
+
system: request.system,
|
|
22
|
+
input: request.input,
|
|
23
|
+
max_output_tokens: Math.min(600, request.maxOutputTokens),
|
|
24
|
+
max_charge_usd: request.maxChargeCents / 100,
|
|
25
|
+
}, timeoutMs: 45000 });
|
|
26
|
+
const reply = result.body;
|
|
27
|
+
if (typeof reply.text !== "string" || !reply.text.trim() || reply.content_mode !== "sfw"
|
|
28
|
+
|| !Number.isFinite(reply.metered_list_usd) || reply.metered_list_usd < 0
|
|
29
|
+
|| reply.metered_list_usd > request.maxChargeCents / 100 + 1e-9) {
|
|
30
|
+
throw new Error("The managed assistant did not return a valid billing receipt.");
|
|
31
|
+
}
|
|
32
|
+
return { text: reply.text, provider: "paradise", model: reply.model,
|
|
33
|
+
usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 },
|
|
34
|
+
meteredCents: Math.ceil(reply.metered_list_usd * 100) };
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -141,7 +141,7 @@ function machineCode(body: unknown): string | undefined {
|
|
|
141
141
|
*/
|
|
142
142
|
export async function paradiseRequest<T>(
|
|
143
143
|
path: string,
|
|
144
|
-
init: { method?: "GET" | "POST"; body?: unknown; timeoutMs?: number } = {},
|
|
144
|
+
init: { method?: "GET" | "POST" | "PATCH"; body?: unknown; timeoutMs?: number; query?: Record<string, string> } = {},
|
|
145
145
|
): Promise<ParadiseResponse<T>> {
|
|
146
146
|
if (playgroundBlocksExternalDelivery(env())) {
|
|
147
147
|
// Matches mail, SMS and webhooks: a public playground fails closed.
|
|
@@ -156,10 +156,11 @@ export async function paradiseRequest<T>(
|
|
|
156
156
|
if (!site.apiKey) {
|
|
157
157
|
throw new ParadiseRequestError("PARADISEMODERN_API_KEY is not set.", 0, false, "not_configured");
|
|
158
158
|
}
|
|
159
|
-
const url = paradiseUrl(site.baseUrl, path);
|
|
159
|
+
const url = new URL(paradiseUrl(site.baseUrl, path));
|
|
160
|
+
for (const [key, value] of Object.entries(init.query ?? {})) url.searchParams.set(key, value);
|
|
160
161
|
let response: Response;
|
|
161
162
|
try {
|
|
162
|
-
response = await (fetchOverride ?? fetch)(url, {
|
|
163
|
+
response = await (fetchOverride ?? fetch)(url.href, {
|
|
163
164
|
method: init.method ?? "POST",
|
|
164
165
|
headers: {
|
|
165
166
|
accept: "application/json",
|
|
@@ -31,6 +31,14 @@ export function toContractJsonSchema(
|
|
|
31
31
|
},
|
|
32
32
|
});
|
|
33
33
|
const { $schema: _ignored, ...rest } = json as Record<string, unknown>;
|
|
34
|
+
// An object-only action union is still an object input. Preserve the
|
|
35
|
+
// canonical alternatives while giving object-only transports (MCP) an
|
|
36
|
+
// explicit root type; otherwise they erase every branch as non-object.
|
|
37
|
+
const alternatives = rest.oneOf ?? rest.anyOf;
|
|
38
|
+
if (!rest.type && Array.isArray(alternatives) && alternatives.length > 0
|
|
39
|
+
&& alternatives.every(value => value && typeof value === "object" && (value as { type?: unknown }).type === "object")) {
|
|
40
|
+
return { type: "object", ...rest };
|
|
41
|
+
}
|
|
34
42
|
return rest;
|
|
35
43
|
} catch (error) {
|
|
36
44
|
console.warn(`[contract] could not describe a ${io} schema`, error);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { sql } from "drizzle-orm";
|
|
4
|
+
import { env } from "@/core/env";
|
|
5
|
+
import { ServiceError, type Actor, type Tx } from "@/core/service";
|
|
6
|
+
import { PLAYGROUND_BASELINE_MODULE, PLAYGROUND_ROW_CAPS } from "./playground-policy";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check each new row inside its owning transaction. The service kernel's
|
|
10
|
+
* preflight cannot see inserts already staged by another call in that same
|
|
11
|
+
* transaction; bulk inline creation must count them before the next insert.
|
|
12
|
+
* The advisory lock serializes concurrent creators without locking real sites.
|
|
13
|
+
*/
|
|
14
|
+
export async function checkPlaygroundInsert(tx: Tx, actor: Actor, serviceName: string): Promise<void> {
|
|
15
|
+
if (env().FREEHOLDER_PLAYGROUND !== "1" || actor.kind === "system") return;
|
|
16
|
+
const cap = PLAYGROUND_ROW_CAPS[serviceName];
|
|
17
|
+
if (!cap) return;
|
|
18
|
+
await tx.execute(sql`select pg_advisory_xact_lock(hashtext(${`playground-cap:${cap.table}`}))`);
|
|
19
|
+
const [stored] = await tx.execute<{ baseline: Record<string, number> | null }>(sql`
|
|
20
|
+
select config->'baseline' as baseline from module_settings
|
|
21
|
+
where module = ${PLAYGROUND_BASELINE_MODULE}
|
|
22
|
+
`);
|
|
23
|
+
const [current] = await tx.execute<{ count: number }>(sql`
|
|
24
|
+
select count(*)::int as count from ${sql.identifier(cap.table)}
|
|
25
|
+
`);
|
|
26
|
+
if (Number(current?.count ?? 0) - Number(stored?.baseline?.[cap.table] ?? 0) >= cap.limit) {
|
|
27
|
+
throw new ServiceError("rate_limited", "This playground surface is full. Try again after the hourly reset.");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -36,6 +36,8 @@ const MUTATIONS = new Set([
|
|
|
36
36
|
"cms.updateSection", "cms.createSectionLocale", "cms.restoreRevision",
|
|
37
37
|
"cms.attachLayout", "cms.detachLayout", "cms.rejoinLayout", "cms.createSection",
|
|
38
38
|
"cms.saveAsSection", "cms.detachSection", "cms.deleteSection", "cms.createFromTemplate",
|
|
39
|
+
"cms.createPost", "cms.setPostMeta", "cms.saveTerm", "cms.deleteTerm",
|
|
40
|
+
"cms.saveAuthor", "cms.deleteAuthor", "cms.updateBlogSettings", "cms.moderateReaderComment",
|
|
39
41
|
"forms.create", "forms.update", "forms.delete", "forms.reviewSubmission",
|
|
40
42
|
"contacts.create", "contacts.update", "contacts.merge", "contacts.undoMerge",
|
|
41
43
|
"catalog.createProduct", "catalog.updateProduct", "catalog.updateProductDescription",
|
|
@@ -70,6 +72,7 @@ export const PLAYGROUND_PUBLIC = [
|
|
|
70
72
|
"catalog.applyCouponToCart", "catalog.subscribeBackInStock", "catalog.shopperCheckout", "catalog.checkoutCart",
|
|
71
73
|
"messaging.startSiteChat", "messaging.postSiteChat", "messaging.endSiteChat",
|
|
72
74
|
"cms.submitSiteChat", "cms.submitQuoteRequest", "cms.submitTipIntent", "cms.rateHelpArticle",
|
|
75
|
+
"cms.submitReaderComment",
|
|
73
76
|
"share.shareVia",
|
|
74
77
|
"linkinbio.follow",
|
|
75
78
|
"popups.record", "popups.capture",
|
|
@@ -136,6 +139,8 @@ export const PLAYGROUND_PUBLIC_REFUSED: Readonly<Record<string, string>> = {
|
|
|
136
139
|
"media.claimCaptureOriginal": "Uploads are refused on the bounded playground disk.",
|
|
137
140
|
"media.applyCaptureOriginal": "Uploads are refused on the bounded playground disk.",
|
|
138
141
|
"agents.proposeWriteGate": "Agent workers authenticate with keys the playground never issues.",
|
|
142
|
+
"assistant.previewCall": "Managed provider call controls are unavailable in the playground; no owner-issued preview key or media session is created.",
|
|
143
|
+
"assistant.saveCallCaption": "Private phase of a provider call the playground never admits.",
|
|
139
144
|
"assistant.prepareAnswer": "Phase of the model-backed answer the playground refuses.",
|
|
140
145
|
"assistant.applyAnswer": "Phase of the model-backed answer the playground refuses.",
|
|
141
146
|
"media.upload": "Uploads are refused on the bounded playground disk.",
|
|
@@ -256,6 +261,9 @@ export interface PlaygroundRowCap {
|
|
|
256
261
|
|
|
257
262
|
export const PLAYGROUND_ROW_CAPS: Readonly<Record<string, PlaygroundRowCap>> = {
|
|
258
263
|
"cms.createPage": { table: "pages", limit: 50 },
|
|
264
|
+
"cms.createPost": { table: "pages", limit: 50 },
|
|
265
|
+
"cms.saveAuthor": { table: "blog_authors", limit: 50 },
|
|
266
|
+
"cms.saveTerm": { table: "blog_terms", limit: 100 },
|
|
259
267
|
"cms.createFromTemplate": { table: "pages", limit: 50 },
|
|
260
268
|
"linkinbio.setup": { table: "pages", limit: 50 },
|
|
261
269
|
"cms.createSection": { table: "sections", limit: 100 },
|
|
@@ -281,6 +289,7 @@ export const PLAYGROUND_ROW_CAPS: Readonly<Record<string, PlaygroundRowCap>> = {
|
|
|
281
289
|
"cms.submitSiteChat": { table: "site_chat_sessions", limit: 200 },
|
|
282
290
|
"cms.submitQuoteRequest": { table: "conversations", limit: 500 },
|
|
283
291
|
"cms.submitTipIntent": { table: "conversations", limit: 500 },
|
|
292
|
+
"cms.submitReaderComment": { table: "blog_reader_comments", limit: 200 },
|
|
284
293
|
"share.shareVia": { table: "shared_links", limit: 1000 },
|
|
285
294
|
"popups.record": { table: "popup_events", limit: 2000 },
|
|
286
295
|
"popups.capture": { table: "popup_events", limit: 2000 },
|
|
@@ -334,6 +334,8 @@ const envSchema = z.object({
|
|
|
334
334
|
AGENT_GATEWAY_MODEL: z.string().trim().min(1).max(200).optional(),
|
|
335
335
|
/** `paradise`: purpose-bound Paradise Modern site credential (optional provider). */
|
|
336
336
|
PARADISEMODERN_API_KEY: z.string().trim().min(1).optional(),
|
|
337
|
+
/** Exact HTTPS voice/face worker origins for managed preview calls; no wildcard. */
|
|
338
|
+
PARADISEMODERN_ASSISTANT_ORIGINS: z.string().optional(),
|
|
337
339
|
/** `https://` only, or `http://` on a loopback host for tests and local work. */
|
|
338
340
|
PARADISEMODERN_URL: z
|
|
339
341
|
.string()
|
|
@@ -53,6 +53,7 @@ export interface ContentSecurityPolicyOptions {
|
|
|
53
53
|
thirdPartyCreativeConsent?: boolean;
|
|
54
54
|
/** C12.24: the site's own SFU, reachable only from group call pages. */
|
|
55
55
|
callOrigins?: string[];
|
|
56
|
+
assistantOrigins?: string[];
|
|
56
57
|
/**
|
|
57
58
|
* C3.32: the chosen measurement provider's edge. The caller passes it only
|
|
58
59
|
* for a visitor who explicitly allowed measurement; it is never implied by
|
|
@@ -69,6 +70,11 @@ export interface ContentSecurityPolicyOptions {
|
|
|
69
70
|
* inline style elements: React uses bounded style attributes for bar widths
|
|
70
71
|
* and image crop anchors, while every `<style>` element still needs the nonce.
|
|
71
72
|
*/
|
|
73
|
+
/** Calls are offered on Contact only, including the original path before locale rewrite. */
|
|
74
|
+
export function isPreviewAssistantContactPath(path: string): boolean {
|
|
75
|
+
return /^\/(?:[a-z]{2,3}(?:-[a-z0-9]{2,8})*\/)?contact\/?$/i.test(path);
|
|
76
|
+
}
|
|
77
|
+
|
|
72
78
|
export function contentSecurityPolicy(options: ContentSecurityPolicyOptions): string {
|
|
73
79
|
const media = [...new Set(options.mediaOrigins ?? [])].sort();
|
|
74
80
|
const upload = options.path.startsWith("/admin")
|
|
@@ -78,6 +84,8 @@ export function contentSecurityPolicy(options: ContentSecurityPolicyOptions): st
|
|
|
78
84
|
? [...new Set(options.creativeOrigins ?? [])].sort()
|
|
79
85
|
: [];
|
|
80
86
|
const call = options.path.startsWith("/call/group/") ? [...new Set(options.callOrigins ?? [])].sort() : [];
|
|
87
|
+
const assistant = isPreviewAssistantContactPath(options.path) ? [...new Set(options.assistantOrigins ?? [])].sort() : [];
|
|
88
|
+
const assistantWasm = isPreviewAssistantContactPath(options.path) || options.path.startsWith("/managed-assistant/");
|
|
81
89
|
const measurement = options.path.startsWith("/admin")
|
|
82
90
|
? []
|
|
83
91
|
: [...new Set(options.measurementOrigins ?? [])].sort();
|
|
@@ -88,14 +96,14 @@ export function contentSecurityPolicy(options: ContentSecurityPolicyOptions): st
|
|
|
88
96
|
: " 'unsafe-eval'";
|
|
89
97
|
const policy = [
|
|
90
98
|
"default-src 'self'",
|
|
91
|
-
`script-src 'nonce-${options.nonce}' 'strict-dynamic' 'self'${development}${sources([...creative, ...measurement])}`,
|
|
99
|
+
`script-src 'nonce-${options.nonce}' 'strict-dynamic' 'self'${assistantWasm ? " 'wasm-unsafe-eval'" : ""}${development}${sources([...creative, ...measurement])}`,
|
|
92
100
|
"script-src-attr 'none'",
|
|
93
101
|
`style-src 'self' 'nonce-${options.nonce}'${sources(creative)}`,
|
|
94
102
|
"style-src-attr 'unsafe-inline'",
|
|
95
103
|
`img-src 'self' data: blob:${sources([...media, ...creative, ...measurement])}`,
|
|
96
104
|
`font-src 'self' data:${sources(creative)}`,
|
|
97
105
|
`media-src 'self' blob:${sources([...media, ...creative])}`,
|
|
98
|
-
`connect-src 'self'${sources([...upload, ...creative, ...call, ...measurement])}`,
|
|
106
|
+
`connect-src 'self'${sources([...upload, ...creative, ...call, ...assistant, ...measurement])}`,
|
|
99
107
|
`frame-src 'self'${sources(creative)}`,
|
|
100
108
|
"worker-src 'self' blob:",
|
|
101
109
|
"manifest-src 'self'",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright (C) 2026 Tony Aly
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/** Copy only the readable double-submit token, never an authentication cookie. */
|
|
5
|
+
export function browserCsrfHeaders(): Record<string, string> {
|
|
6
|
+
const raw = document.cookie.split(/;\s*/).find(cookie => cookie.startsWith("freeholder_csrf="))?.slice("freeholder_csrf=".length);
|
|
7
|
+
if (!raw) return {};
|
|
8
|
+
try { return { "x-csrf-token": decodeURIComponent(raw) }; }
|
|
9
|
+
catch { return {}; }
|
|
10
|
+
}
|