@aeratic/pagetailor 0.5.0 → 0.6.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aeratic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @aeratic/pagetailor
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/@aeratic/pagetailor)](https://www.npmjs.com/package/@aeratic/pagetailor) [![test](https://github.com/aeratic/pagetailor/actions/workflows/test.yml/badge.svg)](https://github.com/aeratic/pagetailor/actions/workflows/test.yml) [![license](https://img.shields.io/npm/l/@aeratic/pagetailor)](LICENSE)
4
+
3
5
  Pages as data. Define your app's pages in YAML, bind them to a typed catalog of components and data sources, tailor them per role and per person with small patches, and let an AI agent compose them through a validation gate. Rendering is done by [json-render](https://github.com/vercel-labs/json-render).
4
6
 
5
7
  ## Start here
@@ -18,8 +20,10 @@ npx pagetailor dev
18
20
  # http://localhost:4747/?role=magazzino the same page for the warehouse role
19
21
  # http://localhost:4747/?view=studio visual editor of the whole project
20
22
 
21
- # 4. Enable the AI agent
23
+ # 4. Enable the AI agent with any provider: Anthropic, OpenAI, Gemini, Groq, Mistral, DeepSeek, xAI, OpenRouter, Ollama…
22
24
  ANTHROPIC_API_KEY=sk-... npx pagetailor dev
25
+ OPENAI_API_KEY=sk-... npx pagetailor dev
26
+ PAGETAILOR_PROVIDER=ollama PAGETAILOR_MODEL=llama3.3 npx pagetailor dev
23
27
 
24
28
  # 5. After editing components/registry.yaml, regenerate the component index
25
29
  npx pagetailor registry
@@ -169,9 +173,17 @@ A user asks in natural language ("put the KPI at the top"); the agent turns it i
169
173
  3. `runAgent(root, { page, user, role, request, complete })` appends the patches to the user's existing override for that page (same merge rule as the editor) and calls `propose` as `user-<user>`: applied at once for the own user, pending otherwise.
170
174
  4. If the gate rejects, the gate errors are sent back once ("The previous patch was rejected: ... Fix it.") and the result is proposed again. The result reports `attempts`.
171
175
 
172
- `complete` is any `async ({ system, user }) => text`, so any model or SDK works; pagetailor depends on none. `anthropicComplete({ apiKey, model })` is a built-in fetch call to the Anthropic Messages API (`claude-sonnet-5-5` by default).
176
+ `complete` is any `async ({ system, user }) => text`, so any model or SDK works; pagetailor depends on none. Built-in adapters over plain `fetch`: `anthropicComplete`, `openaiComplete` (OpenAI and every provider speaking its chat-completions format), `googleComplete` (Gemini). `createComplete({ provider, model, apiKey, baseUrl })` picks one by name: `anthropic`, `openai`, `google`, `groq`, `mistral`, `deepseek`, `xai`, `openrouter`, `ollama` (local, no key) or `compatible` (any URL). `completeFromEnv()` reads the same from the environment and is what `pagetailor dev` uses:
177
+
178
+ | Variable | Meaning |
179
+ | --- | --- |
180
+ | `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `GROQ_API_KEY`, `MISTRAL_API_KEY`, `DEEPSEEK_API_KEY`, `XAI_API_KEY`, `OPENROUTER_API_KEY` | the key of the provider to use; with one key set nothing else is needed |
181
+ | `PAGETAILOR_PROVIDER` | force a provider when several keys are set, or choose `ollama` / `compatible` |
182
+ | `PAGETAILOR_MODEL` | the model; defaults exist for anthropic, openai, google, mistral, deepseek, required for the others |
183
+ | `PAGETAILOR_LLM_URL` | base URL for `compatible`, or to override a provider's URL (a proxy, an Ollama on another host) |
184
+ | `PAGETAILOR_LLM_KEY` | the key for `compatible` |
173
185
 
174
- In `pagetailor dev`, set `ANTHROPIC_API_KEY` (and optionally `PAGETAILOR_MODEL`) and use the "Change this page…" box in the header: `POST /api/agent` with `{ page, user, role, request }` (503 without the key). `GET /api/agent/prompt?page=&user=&role=&request=` returns the built prompt for debugging.
186
+ In `pagetailor dev`, set one of the variables above and use the "Change this page…" box in the header: `POST /api/agent` with `{ page, user, role, request }` (503 when no provider is configured). `GET /api/agent/prompt?page=&user=&role=&request=` returns the built prompt for debugging.
175
187
 
176
188
  ## Pages as answers
177
189
 
@@ -182,7 +194,7 @@ A user asks a question ("how did sales go this week?") and the agent composes a
182
194
  3. Keep as page: `keepAnswer(root, { user, role, title, tree, why })` writes `pages/<slug>.yaml` with `owner: <user>` and adds the slug to `manifest.pages` (slugs are made unique with `-2`, `-3`).
183
195
  4. Pin to home: `pinAnswer(root, { user, role, title, tree, why })` proposes, as `user-<user>`, an `insert` of a `layout/card` with the answer's widgets into the home's main container; on a grid it gets its own full-width row at the bottom. Same gate and proposal rules as any override.
184
196
 
185
- Both go through the gate with the user's role first. In `pagetailor dev` use the "Ask…" box: `POST /api/ask` `{ user, role, request }` (503 without `ANTHROPIC_API_KEY`), `POST /api/ask/keep` and `POST /api/ask/pin` with `{ user, role, title, tree, why }`.
197
+ Both go through the gate with the user's role first. In `pagetailor dev` use the "Ask…" box: `POST /api/ask` `{ user, role, request }` (503 when no provider is configured), `POST /api/ask/keep` and `POST /api/ask/pin` with `{ user, role, title, tree, why }`.
186
198
 
187
199
  ## Studio
188
200
 
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@aeratic/pagetailor",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "Pages as data: declarative YAML pages, typed data catalog, per-user overrides, validated for AI agents. Renders with json-render.",
5
5
  "license": "MIT",
6
+ "author": "Aeratic <info@aeratic.com>",
6
7
  "type": "module",
7
8
  "bin": {
8
9
  "pagetailor": "bin/cli.js"
@@ -16,7 +17,8 @@
16
17
  "bin",
17
18
  "src",
18
19
  "templates",
19
- "README.md"
20
+ "README.md",
21
+ "LICENSE"
20
22
  ],
21
23
  "engines": {
22
24
  "node": ">=20"
@@ -53,6 +55,10 @@
53
55
  "react-dom": "19.2.3"
54
56
  },
55
57
  "scripts": {
56
- "test": "node --no-deprecation --import ./test/jsx-loader.mjs --test test/"
58
+ "test": "node --no-deprecation --import ./test/jsx-loader.mjs --test test/*.test.js"
59
+ },
60
+ "homepage": "https://github.com/aeratic/pagetailor#readme",
61
+ "bugs": {
62
+ "url": "https://github.com/aeratic/pagetailor/issues"
57
63
  }
58
64
  }
package/src/dev.js CHANGED
@@ -10,7 +10,7 @@ import { commitOverride, listHistory, rollback } from "./history.js";
10
10
  import { propose, listPending, approve, reject } from "./proposals.js";
11
11
  import { tokensToCss } from "./tokens.js";
12
12
  import { buildAgentPrompt, runAgent, runAsk, keepAnswer, pinAnswer } from "./agent.js";
13
- import { anthropicComplete } from "./llm.js";
13
+ import { completeFromEnv, LLM_HELP } from "./llm.js";
14
14
  import { isProjectFile, readProjectFile, writeProjectFile, deleteProjectFile, listFileHistory, undoFile, readProject, scaffoldSource, scaffoldComponent } from "./files.js";
15
15
 
16
16
  const here = dirname(fileURLToPath(import.meta.url));
@@ -101,16 +101,16 @@ export async function dev(cwd, { port = 4747, host = "127.0.0.1" } = {}) {
101
101
  return json(res, 200, await buildAgentPrompt(root, { page: q.page || "home", user: q.user || undefined, role: q.role || undefined, request: q.request ?? "" }));
102
102
  }
103
103
  if (url.pathname === "/api/agent" && req.method === "POST") {
104
- if (!process.env.ANTHROPIC_API_KEY) return json(res, 503, { error: "set ANTHROPIC_API_KEY to use the agent" });
104
+ const complete = completeFromEnv();
105
+ if (!complete) return json(res, 503, { error: LLM_HELP });
105
106
  const b = await body(req);
106
- const complete = anthropicComplete({ apiKey: process.env.ANTHROPIC_API_KEY, ...(process.env.PAGETAILOR_MODEL ? { model: process.env.PAGETAILOR_MODEL } : {}) });
107
107
  const r = await runAgent(root, { page: b.page, user: b.user, role: b.role || undefined, request: b.request, complete });
108
108
  return json(res, r.ok ? 200 : 400, r);
109
109
  }
110
110
  if (url.pathname === "/api/ask" && req.method === "POST") {
111
- if (!process.env.ANTHROPIC_API_KEY) return json(res, 503, { error: "set ANTHROPIC_API_KEY to use the agent" });
111
+ const complete = completeFromEnv();
112
+ if (!complete) return json(res, 503, { error: LLM_HELP });
112
113
  const b = await body(req);
113
- const complete = anthropicComplete({ apiKey: process.env.ANTHROPIC_API_KEY, ...(process.env.PAGETAILOR_MODEL ? { model: process.env.PAGETAILOR_MODEL } : {}) });
114
114
  const r = await runAsk(root, { user: b.user || undefined, role: b.role || undefined, request: b.request, complete });
115
115
  return json(res, r.ok ? 200 : 400, r);
116
116
  }
package/src/index.js CHANGED
@@ -15,5 +15,5 @@ export async function dev(...args) {
15
15
  export { writeRegistryFile } from "./registry-file.js";
16
16
  export { tokensToCss } from "./tokens.js";
17
17
  export { describeCatalog, describePage, buildAgentPrompt, parseAgentReply, runAgent, buildAskPrompt, runAsk, keepAnswer, pinAnswer } from "./agent.js";
18
- export { anthropicComplete } from "./llm.js";
18
+ export { anthropicComplete, openaiComplete, googleComplete, createComplete, completeFromEnv, PROVIDERS } from "./llm.js";
19
19
  export { readProjectFile, writeProjectFile, deleteProjectFile, listFileHistory, undoFile, scaffoldSource, scaffoldComponent, readProject } from "./files.js";
package/src/llm.js CHANGED
@@ -1,14 +1,74 @@
1
- // Minimal Messages API call over global fetch; returns a `complete({ system, user })` for runAgent.
2
- export function anthropicComplete({ apiKey, model = "claude-sonnet-5-5" } = {}) {
3
- if (!apiKey) throw new Error("anthropicComplete: apiKey is required");
1
+ // Model adapters: each returns a `complete({ system, user }) => text` for runAgent / runAsk, over global fetch.
2
+ // Any provider works with the same shape; pagetailor depends on no SDK.
3
+
4
+ const post = async (url, headers, body) => {
5
+ const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json", ...headers }, body: JSON.stringify(body) });
6
+ const text = await res.text();
7
+ if (!res.ok) throw new Error(`${new URL(url).host} ${res.status}: ${text.slice(0, 500)}`);
8
+ return JSON.parse(text);
9
+ };
10
+ const need = (apiKey, name) => { if (!apiKey) throw new Error(`${name}: apiKey is required`); };
11
+
12
+ export function anthropicComplete({ apiKey, model = "claude-sonnet-5-5", baseUrl = "https://api.anthropic.com", maxTokens = 2048 } = {}) {
13
+ need(apiKey, "anthropicComplete");
4
14
  return async ({ system, user }) => {
5
- const res = await fetch("https://api.anthropic.com/v1/messages", {
6
- method: "POST",
7
- headers: { "content-type": "application/json", "x-api-key": apiKey, "anthropic-version": "2023-06-01" },
8
- body: JSON.stringify({ model, max_tokens: 1024, system, messages: [{ role: "user", content: user }] }),
9
- });
10
- const text = await res.text();
11
- if (!res.ok) throw new Error(`Anthropic API ${res.status}: ${text}`);
12
- return (JSON.parse(text).content ?? []).filter(b => b.type === "text").map(b => b.text).join("");
15
+ const r = await post(`${baseUrl}/v1/messages`, { "x-api-key": apiKey, "anthropic-version": "2023-06-01" }, { model, max_tokens: maxTokens, system, messages: [{ role: "user", content: user }] });
16
+ return (r.content ?? []).filter(b => b.type === "text").map(b => b.text).join("");
13
17
  };
14
18
  }
19
+
20
+ // OpenAI chat completions; also the wire format of Groq, Mistral, DeepSeek, xAI, OpenRouter, Ollama and many others.
21
+ export function openaiComplete({ apiKey, model = "gpt-5.5", baseUrl = "https://api.openai.com/v1", maxTokens = 2048, headers = {} } = {}) {
22
+ if (baseUrl.includes("api.openai.com")) need(apiKey, "openaiComplete");
23
+ return async ({ system, user }) => {
24
+ const r = await post(`${baseUrl.replace(/\/$/, "")}/chat/completions`, { ...(apiKey ? { authorization: `Bearer ${apiKey}` } : {}), ...headers },
25
+ { model, max_tokens: maxTokens, messages: [{ role: "system", content: system }, { role: "user", content: user }] });
26
+ const c = r.choices?.[0]?.message?.content;
27
+ return Array.isArray(c) ? c.filter(p => p.type === "text").map(p => p.text).join("") : c ?? "";
28
+ };
29
+ }
30
+
31
+ export function googleComplete({ apiKey, model = "gemini-3.8-flash", baseUrl = "https://generativelanguage.googleapis.com/v1beta", maxTokens = 2048 } = {}) {
32
+ need(apiKey, "googleComplete");
33
+ return async ({ system, user }) => {
34
+ const r = await post(`${baseUrl}/models/${model}:generateContent`, { "x-goog-api-key": apiKey },
35
+ { system_instruction: { parts: [{ text: system }] }, contents: [{ role: "user", parts: [{ text: user }] }], generationConfig: { maxOutputTokens: maxTokens } });
36
+ return (r.candidates?.[0]?.content?.parts ?? []).map(p => p.text ?? "").join("");
37
+ };
38
+ }
39
+
40
+ // Known providers: env var holding the key, base URL and default model (null = PAGETAILOR_MODEL required).
41
+ export const PROVIDERS = {
42
+ anthropic: { key: "ANTHROPIC_API_KEY", make: anthropicComplete },
43
+ openai: { key: "OPENAI_API_KEY", make: openaiComplete },
44
+ google: { key: ["GEMINI_API_KEY", "GOOGLE_API_KEY"], make: googleComplete },
45
+ groq: { key: "GROQ_API_KEY", make: openaiComplete, baseUrl: "https://api.groq.com/openai/v1", model: null },
46
+ mistral: { key: "MISTRAL_API_KEY", make: openaiComplete, baseUrl: "https://api.mistral.ai/v1", model: "mistral-large-latest" },
47
+ deepseek: { key: "DEEPSEEK_API_KEY", make: openaiComplete, baseUrl: "https://api.deepseek.com/v1", model: "deepseek-chat" },
48
+ xai: { key: "XAI_API_KEY", make: openaiComplete, baseUrl: "https://api.x.ai/v1", model: null },
49
+ openrouter: { key: "OPENROUTER_API_KEY", make: openaiComplete, baseUrl: "https://openrouter.ai/api/v1", model: null },
50
+ ollama: { key: null, make: openaiComplete, baseUrl: "http://localhost:11434/v1", model: null },
51
+ compatible: { key: "PAGETAILOR_LLM_KEY", make: openaiComplete, baseUrl: null, model: null },
52
+ };
53
+
54
+ // createComplete({ provider, model?, apiKey?, baseUrl? }): one call for every provider above.
55
+ export function createComplete({ provider, model, apiKey, baseUrl, ...rest } = {}) {
56
+ const p = PROVIDERS[provider];
57
+ if (!p) throw new Error(`unknown LLM provider "${provider}" (known: ${Object.keys(PROVIDERS).join(", ")})`);
58
+ const url = baseUrl ?? p.baseUrl;
59
+ if (provider === "compatible" && !url) throw new Error("provider compatible: baseUrl is required (PAGETAILOR_LLM_URL)");
60
+ const m = model ?? ("model" in p ? p.model : undefined);
61
+ if (m === null) throw new Error(`provider ${provider}: model is required (PAGETAILOR_MODEL)`);
62
+ return p.make({ apiKey, ...(m ? { model: m } : {}), ...(url ? { baseUrl: url } : {}), ...rest });
63
+ }
64
+
65
+ // Reads the provider from the environment: PAGETAILOR_PROVIDER, or the first provider whose key is set.
66
+ // PAGETAILOR_MODEL overrides the model, PAGETAILOR_LLM_URL the base URL. Returns null when nothing is configured.
67
+ export function completeFromEnv(env = process.env) {
68
+ const keyOf = p => [].concat(PROVIDERS[p].key ?? []).map(k => env[k]).find(Boolean);
69
+ const provider = env.PAGETAILOR_PROVIDER || Object.keys(PROVIDERS).find(p => PROVIDERS[p].key && keyOf(p));
70
+ if (!provider) return null;
71
+ if (!PROVIDERS[provider]) throw new Error(`unknown LLM provider "${provider}" (known: ${Object.keys(PROVIDERS).join(", ")})`);
72
+ return createComplete({ provider, apiKey: keyOf(provider), model: env.PAGETAILOR_MODEL || undefined, baseUrl: env.PAGETAILOR_LLM_URL || undefined });
73
+ }
74
+ export const LLM_HELP = "set an LLM key (ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, GROQ_API_KEY, MISTRAL_API_KEY, DEEPSEEK_API_KEY, XAI_API_KEY, OPENROUTER_API_KEY) or PAGETAILOR_PROVIDER=ollama|compatible, plus PAGETAILOR_MODEL";