Auto-derive session cookie domain; AI prompt page = formula builder hub

Session (no env needed):
- SESSION_COOKIE_DOMAIN env removed. Config.SessionCookieParentDomain()
  derives the cookie Domain from WEB_ORIGIN + PUBLIC_API_URL, which the
  API already requires: sibling hosts of one parent (descrybe.io +
  api.descrybe.io) share the parent domain so SvelteKit SSR (/admin
  gate, user switching) receives the session cookie; localhost, IPs,
  same-host, and unrelated hosts stay host-only. Deploying the new build
  is the whole fix — nothing to configure.

AI generation prompt page:
- Each section now embeds its formula editor next to the per-language
  prompt instructions: Title = full title formula builder (preview,
  elements, separator, variable selector, custom variables), Description
  = description formula sections editor (type + instructions + export
  id, drag reorder), Meta = meta title / meta description formula
  fields. One Save writes categories.prompt + title_template +
  description_template together; Assign copies all three to the
  selected categories.
- New $lib/categories/formula-variables.ts loads every usable field for
  the builder: custom variables (/api/variables), company attributes
  (/api/attributes — attribute_key, name, unit, example), and standard
  fields (/api/standard-fields). Used by both the prompt page and the
  title-formula page (which previously ignored attributes).

Verified locally: svelte-check clean for changed files, unit tests pass,
and the full save contract exercised over HTTP as the page does it
(login → load variables/attributes/standard-fields → PATCH prompt +
title-formula + description-formula → round-trip read), then the test
category restored via repair-category-prompts.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
greeneclipseandClaude Fable 5 committed 2026-08-18 01:12:23 +02:00
1 parent 9a839d6d13
commit d03c2a5c57
7 files changed
+657 -62

No files matched your search

@@ -0,0 +1,58 @@
import { api } from "$lib/api";
import { mapApiVariable } from "./formula";
import type { FormulaVariable } from "./types";
/**
* Load every field usable as a formula variable for this company:
* custom variables (/api/variables), company attributes (/api/attributes),
* and standard fields (/api/standard-fields). First definition of a name wins
* (custom variables can override attribute labels/examples).
*/
export async function loadFormulaVariables(): Promise<FormulaVariable[]> {
const [varsRes, attrsRes, fieldsRes] = await Promise.all([
api<{ variables: Record<string, unknown>[] }>("/api/variables?limit=2000").catch(() => ({
variables: [] as Record<string, unknown>[]
})),
api<{ attributes?: Record<string, unknown>[] }>("/api/attributes?limit=2000").catch(() => ({
attributes: [] as Record<string, unknown>[]
})),
api<{ fields?: Record<string, unknown>[] }>("/api/standard-fields?limit=2000").catch(() => ({
fields: [] as Record<string, unknown>[]
}))
]);
const out = (varsRes.variables ?? []).map(mapApiVariable);
const seen = new Set(out.map((v) => v.name));
for (const row of attrsRes.attributes ?? []) {
const name = String(row.attribute_key ?? "").trim();
if (!name || seen.has(name)) continue;
seen.add(name);
const label = String(row.name ?? name);
const unit = row.unit != null ? String(row.unit).trim() : "";
out.push({
id: `attr-${name}`,
name,
label: unit ? `${label} (${unit})` : label,
description: row.description != null ? String(row.description) : undefined,
example: row.example != null ? String(row.example) : undefined,
value: label
});
}
for (const row of fieldsRes.fields ?? []) {
const name = String(row.key ?? "").trim();
if (!name || seen.has(name)) continue;
seen.add(name);
out.push({
id: `sf-${name}`,
name,
label: String(row.name ?? name),
description: row.description != null ? String(row.description) : undefined,
example: undefined,
value: String(row.name ?? name)
});
}
return out;
}