@tansy/ai 0.0.0-stage → 0.1.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE +21 -0
  3. package/README.md +12 -2
  4. package/admin.d.ts +2 -0
  5. package/admin.js +17 -0
  6. package/ai.css +280 -0
  7. package/api.d.ts +91 -0
  8. package/api.js +79 -0
  9. package/assistant.d.ts +3 -0
  10. package/assistant.js +290 -0
  11. package/attach.d.ts +48 -0
  12. package/attach.js +141 -0
  13. package/attachments.d.ts +34 -0
  14. package/attachments.js +66 -0
  15. package/chats.d.ts +35 -0
  16. package/chats.js +78 -0
  17. package/client.d.ts +3 -0
  18. package/client.js +88 -0
  19. package/composer.d.ts +38 -0
  20. package/composer.js +155 -0
  21. package/errors.d.ts +5 -0
  22. package/errors.js +25 -0
  23. package/history.d.ts +15 -0
  24. package/history.js +47 -0
  25. package/icons.generated.d.ts +5 -0
  26. package/icons.generated.js +66 -0
  27. package/images.d.ts +21 -0
  28. package/images.js +23 -0
  29. package/index.d.ts +26 -0
  30. package/index.js +701 -0
  31. package/logic.d.ts +77 -0
  32. package/logic.js +166 -0
  33. package/markdown.d.ts +38 -0
  34. package/markdown.js +142 -0
  35. package/media.d.ts +24 -0
  36. package/media.js +64 -0
  37. package/messages.d.ts +891 -0
  38. package/messages.js +689 -0
  39. package/models.d.ts +7 -0
  40. package/models.js +47 -0
  41. package/package.json +46 -4
  42. package/parts.d.ts +59 -0
  43. package/parts.js +110 -0
  44. package/provider.d.ts +134 -0
  45. package/provider.js +117 -0
  46. package/role.d.ts +24 -0
  47. package/role.js +25 -0
  48. package/workflow/check.d.ts +46 -0
  49. package/workflow/check.js +63 -0
  50. package/workflow/client.d.ts +90 -0
  51. package/workflow/client.js +51 -0
  52. package/workflow/editor.d.ts +13 -0
  53. package/workflow/editor.js +133 -0
  54. package/workflow/engine.d.ts +232 -0
  55. package/workflow/engine.js +779 -0
  56. package/workflow/icons.d.ts +26 -0
  57. package/workflow/icons.js +67 -0
  58. package/workflow/model-picker.d.ts +22 -0
  59. package/workflow/model-picker.js +69 -0
  60. package/workflow/page.d.ts +3 -0
  61. package/workflow/page.js +118 -0
  62. package/workflow/routes.d.ts +12 -0
  63. package/workflow/routes.js +418 -0
  64. package/workflow/run.d.ts +8 -0
  65. package/workflow/run.js +162 -0
  66. package/workflow/schema.d.ts +183 -0
  67. package/workflow/schema.js +143 -0
  68. package/workflow/templates.d.ts +9 -0
  69. package/workflow/templates.js +81 -0
  70. package/workflow/workflow.css +241 -0
@@ -0,0 +1,183 @@
1
+ import { z } from "zod";
2
+ export declare const WORKFLOW_ID: RegExp;
3
+ export declare const REASONING: readonly ["provider-default", "none", "low", "medium", "high"];
4
+ /** One model on the team, with the part it plays. */
5
+ export declare const agentSchema: z.ZodObject<{
6
+ id: z.ZodString;
7
+ name: z.ZodString;
8
+ role: z.ZodDefault<z.ZodString>;
9
+ provider: z.ZodString;
10
+ model: z.ZodString;
11
+ reasoning: z.ZodDefault<z.ZodEnum<{
12
+ medium: "medium";
13
+ none: "none";
14
+ high: "high";
15
+ low: "low";
16
+ "provider-default": "provider-default";
17
+ }>>;
18
+ temperature: z.ZodOptional<z.ZodNumber>;
19
+ }, z.core.$strip>;
20
+ /** How several writers on one step share the work. */
21
+ export declare const STRATEGIES: readonly ["rotate", "compete", "fallback"];
22
+ export type Strategy = (typeof STRATEGIES)[number];
23
+ export declare const judgeSchema: z.ZodObject<{
24
+ agent: z.ZodString;
25
+ criteria: z.ZodDefault<z.ZodString>;
26
+ minScore: z.ZodDefault<z.ZodNumber>;
27
+ revisions: z.ZodDefault<z.ZodNumber>;
28
+ }, z.core.$strip>;
29
+ export declare const imageTaskSchema: z.ZodObject<{
30
+ field: z.ZodString;
31
+ artists: z.ZodArray<z.ZodString>;
32
+ style: z.ZodDefault<z.ZodString>;
33
+ aspectRatio: z.ZodDefault<z.ZodEnum<{
34
+ "1:1": "1:1";
35
+ "16:9": "16:9";
36
+ "4:3": "4:3";
37
+ "3:2": "3:2";
38
+ "2:3": "2:3";
39
+ "9:16": "9:16";
40
+ }>>;
41
+ }, z.core.$strip>;
42
+ export declare const stepSchema: z.ZodObject<{
43
+ id: z.ZodString;
44
+ name: z.ZodString;
45
+ collection: z.ZodString;
46
+ parent: z.ZodOptional<z.ZodString>;
47
+ link: z.ZodOptional<z.ZodString>;
48
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
49
+ field: z.ZodString;
50
+ step: z.ZodString;
51
+ }, z.core.$strip>>>;
52
+ orderField: z.ZodOptional<z.ZodString>;
53
+ count: z.ZodObject<{
54
+ min: z.ZodNumber;
55
+ max: z.ZodNumber;
56
+ }, z.core.$strip>;
57
+ fields: z.ZodDefault<z.ZodArray<z.ZodString>>;
58
+ instructions: z.ZodDefault<z.ZodString>;
59
+ writers: z.ZodArray<z.ZodString>;
60
+ strategy: z.ZodDefault<z.ZodEnum<{
61
+ fallback: "fallback";
62
+ rotate: "rotate";
63
+ compete: "compete";
64
+ }>>;
65
+ judge: z.ZodOptional<z.ZodObject<{
66
+ agent: z.ZodString;
67
+ criteria: z.ZodDefault<z.ZodString>;
68
+ minScore: z.ZodDefault<z.ZodNumber>;
69
+ revisions: z.ZodDefault<z.ZodNumber>;
70
+ }, z.core.$strip>>;
71
+ images: z.ZodDefault<z.ZodArray<z.ZodObject<{
72
+ field: z.ZodString;
73
+ artists: z.ZodArray<z.ZodString>;
74
+ style: z.ZodDefault<z.ZodString>;
75
+ aspectRatio: z.ZodDefault<z.ZodEnum<{
76
+ "1:1": "1:1";
77
+ "16:9": "16:9";
78
+ "4:3": "4:3";
79
+ "3:2": "3:2";
80
+ "2:3": "2:3";
81
+ "9:16": "9:16";
82
+ }>>;
83
+ }, z.core.$strip>>>;
84
+ }, z.core.$strip>;
85
+ export declare const inputSchema: z.ZodObject<{
86
+ name: z.ZodString;
87
+ label: z.ZodString;
88
+ multiline: z.ZodDefault<z.ZodBoolean>;
89
+ required: z.ZodDefault<z.ZodBoolean>;
90
+ }, z.core.$strip>;
91
+ export declare const workflowSchema: z.ZodObject<{
92
+ id: z.ZodString;
93
+ name: z.ZodString;
94
+ description: z.ZodDefault<z.ZodString>;
95
+ brief: z.ZodString;
96
+ inputs: z.ZodDefault<z.ZodArray<z.ZodObject<{
97
+ name: z.ZodString;
98
+ label: z.ZodString;
99
+ multiline: z.ZodDefault<z.ZodBoolean>;
100
+ required: z.ZodDefault<z.ZodBoolean>;
101
+ }, z.core.$strip>>>;
102
+ agents: z.ZodArray<z.ZodObject<{
103
+ id: z.ZodString;
104
+ name: z.ZodString;
105
+ role: z.ZodDefault<z.ZodString>;
106
+ provider: z.ZodString;
107
+ model: z.ZodString;
108
+ reasoning: z.ZodDefault<z.ZodEnum<{
109
+ medium: "medium";
110
+ none: "none";
111
+ high: "high";
112
+ low: "low";
113
+ "provider-default": "provider-default";
114
+ }>>;
115
+ temperature: z.ZodOptional<z.ZodNumber>;
116
+ }, z.core.$strip>>;
117
+ planner: z.ZodOptional<z.ZodObject<{
118
+ agent: z.ZodString;
119
+ }, z.core.$strip>>;
120
+ steps: z.ZodArray<z.ZodObject<{
121
+ id: z.ZodString;
122
+ name: z.ZodString;
123
+ collection: z.ZodString;
124
+ parent: z.ZodOptional<z.ZodString>;
125
+ link: z.ZodOptional<z.ZodString>;
126
+ links: z.ZodDefault<z.ZodArray<z.ZodObject<{
127
+ field: z.ZodString;
128
+ step: z.ZodString;
129
+ }, z.core.$strip>>>;
130
+ orderField: z.ZodOptional<z.ZodString>;
131
+ count: z.ZodObject<{
132
+ min: z.ZodNumber;
133
+ max: z.ZodNumber;
134
+ }, z.core.$strip>;
135
+ fields: z.ZodDefault<z.ZodArray<z.ZodString>>;
136
+ instructions: z.ZodDefault<z.ZodString>;
137
+ writers: z.ZodArray<z.ZodString>;
138
+ strategy: z.ZodDefault<z.ZodEnum<{
139
+ fallback: "fallback";
140
+ rotate: "rotate";
141
+ compete: "compete";
142
+ }>>;
143
+ judge: z.ZodOptional<z.ZodObject<{
144
+ agent: z.ZodString;
145
+ criteria: z.ZodDefault<z.ZodString>;
146
+ minScore: z.ZodDefault<z.ZodNumber>;
147
+ revisions: z.ZodDefault<z.ZodNumber>;
148
+ }, z.core.$strip>>;
149
+ images: z.ZodDefault<z.ZodArray<z.ZodObject<{
150
+ field: z.ZodString;
151
+ artists: z.ZodArray<z.ZodString>;
152
+ style: z.ZodDefault<z.ZodString>;
153
+ aspectRatio: z.ZodDefault<z.ZodEnum<{
154
+ "1:1": "1:1";
155
+ "16:9": "16:9";
156
+ "4:3": "4:3";
157
+ "3:2": "3:2";
158
+ "2:3": "2:3";
159
+ "9:16": "9:16";
160
+ }>>;
161
+ }, z.core.$strip>>>;
162
+ }, z.core.$strip>>;
163
+ retry: z.ZodDefault<z.ZodObject<{
164
+ attempts: z.ZodDefault<z.ZodNumber>;
165
+ backoffSeconds: z.ZodDefault<z.ZodNumber>;
166
+ }, z.core.$strip>>;
167
+ concurrency: z.ZodDefault<z.ZodNumber>;
168
+ status: z.ZodDefault<z.ZodEnum<{
169
+ draft: "draft";
170
+ published: "published";
171
+ }>>;
172
+ actsAs: z.ZodOptional<z.ZodString>;
173
+ }, z.core.$strip>;
174
+ export type Agent = z.output<typeof agentSchema>;
175
+ export type Step = z.output<typeof stepSchema>;
176
+ export type Judge = z.output<typeof judgeSchema>;
177
+ export type ImageTask = z.output<typeof imageTaskSchema>;
178
+ export type Workflow = z.output<typeof workflowSchema>;
179
+ export type WorkflowInput = z.input<typeof workflowSchema>;
180
+ /** The parts of a model's abilities a task needs. */
181
+ export type Task = "write" | "judge" | "plan" | "image";
182
+ /** Fills {{name}} with the run's inputs. Unknown names stay as written. */
183
+ export declare const fill: (template: string, inputs: Record<string, string>) => string;
@@ -0,0 +1,143 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * A workflow: a team of AI agents that writes records into one or more collections, such as
4
+ * a course with its sections and lessons. Plain data, saved in the plugin's store and
5
+ * edited in the dashboard. The engine in ./engine.ts runs it, and nothing is saved as a
6
+ * record until a person reviews what it wrote and creates the records.
7
+ */
8
+ const ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
9
+ export const WORKFLOW_ID = ID;
10
+ const id = z.string().regex(ID, "Use lowercase letters, digits and dashes.");
11
+ const name = z.string().trim().min(1).max(80);
12
+ const prompt = (max) => z.string().max(max).default("");
13
+ export const REASONING = ["provider-default", "none", "low", "medium", "high"];
14
+ /** One model on the team, with the part it plays. */
15
+ export const agentSchema = z.object({
16
+ id,
17
+ name,
18
+ /** Who it is and how it works, such as "A senior instructional designer who writes in plain English". */
19
+ role: prompt(2000),
20
+ provider: z.string().min(1).max(20),
21
+ model: z.string().regex(/^[A-Za-z0-9][\w.:/@+-]{0,199}$/, "That isn't a model id."),
22
+ reasoning: z.enum(REASONING).default("provider-default"),
23
+ /** 0 to 2. Empty uses the model's default. */
24
+ temperature: z.number().min(0).max(2).optional(),
25
+ });
26
+ /** How several writers on one step share the work. */
27
+ export const STRATEGIES = ["rotate", "compete", "fallback"];
28
+ export const judgeSchema = z.object({
29
+ agent: id,
30
+ /** What a good answer is. Empty lets the planner write it from the brief. */
31
+ criteria: prompt(2000),
32
+ /** 1 to 10. A draft scoring less goes back to its writer with the judge's notes. */
33
+ minScore: z.number().int().min(1).max(10).default(7),
34
+ /** How many times a draft may be sent back. */
35
+ revisions: z.number().int().min(0).max(3).default(1),
36
+ });
37
+ export const imageTaskSchema = z.object({
38
+ /** The image field it fills. */
39
+ field: z.string().min(1).max(63),
40
+ /** Agents that draw. The first that succeeds is used; the rest are fallbacks. */
41
+ artists: z.array(id).min(1).max(5),
42
+ /** The look, such as "flat vector illustration, warm palette, no text". The record's own content is added. */
43
+ style: prompt(1000),
44
+ aspectRatio: z.enum(["1:1", "16:9", "4:3", "3:2", "2:3", "9:16"]).default("16:9"),
45
+ });
46
+ export const stepSchema = z.object({
47
+ id,
48
+ name,
49
+ collection: z.string().min(1).max(63),
50
+ /** A step whose records this one's belong to: each of its records gets its own set of these. */
51
+ parent: id.optional(),
52
+ /** The field on this collection that points at the parent's record, filled when records are created. */
53
+ link: z.string().max(63).optional(),
54
+ /** More fields that point at records further up, such as a lesson's course beside its section. */
55
+ links: z.array(z.object({ field: z.string().min(1).max(63), step: id })).max(4).default([]),
56
+ /** A number field filled with each record's place among its siblings: 1, 2, 3. */
57
+ orderField: z.string().max(63).optional(),
58
+ /** How many records: exactly `min`, or as many between `min` and `max` as the content needs. */
59
+ count: z.object({ min: z.number().int().min(1).max(50), max: z.number().int().min(1).max(50) }).refine((count) => count.max >= count.min, "The most can't be fewer than the least."),
60
+ /** The fields to write. Empty writes every field AI can fill. */
61
+ fields: z.array(z.string().max(63)).max(100).default([]),
62
+ /** What this step writes, on top of the brief. May use {{input}} names. */
63
+ instructions: prompt(4000),
64
+ writers: z.array(id).min(1).max(8),
65
+ strategy: z.enum(STRATEGIES).default("rotate"),
66
+ judge: judgeSchema.optional(),
67
+ images: z.array(imageTaskSchema).max(5).default([]),
68
+ });
69
+ export const inputSchema = z.object({
70
+ name: z.string().regex(/^[a-z][a-zA-Z0-9_]{0,39}$/, "Start with a lowercase letter; letters, digits and _ after."),
71
+ label: name,
72
+ multiline: z.boolean().default(false),
73
+ required: z.boolean().default(true),
74
+ });
75
+ export const workflowSchema = z.object({
76
+ id,
77
+ name,
78
+ description: z.string().max(500).default(""),
79
+ /** The master prompt: what to make and for whom. May use {{input}} names. */
80
+ brief: z.string().trim().min(1, "Write the brief: what the team should make.").max(8000),
81
+ inputs: z.array(inputSchema).max(12).default([]),
82
+ agents: z.array(agentSchema).min(1, "Add at least one agent.").max(16),
83
+ /** An agent that reads the brief first and writes each agent its own prompt, as a lead does for a team. */
84
+ planner: z.object({ agent: id }).optional(),
85
+ steps: z.array(stepSchema).min(1, "Add at least one step.").max(12),
86
+ /** Calls to a provider that fail are tried again, waiting longer each time. */
87
+ retry: z.object({ attempts: z.number().int().min(1).max(6).default(3), backoffSeconds: z.number().min(0).max(120).default(4) }).default({ attempts: 3, backoffSeconds: 4 }),
88
+ /** How many tasks run at once. */
89
+ concurrency: z.number().int().min(1).max(6).default(2),
90
+ /** What the records are saved as. */
91
+ status: z.enum(["draft", "published"]).default("draft"),
92
+ /**
93
+ * The role the records are created with, beside the access of the person who creates them:
94
+ * never more than either. Empty uses the role chosen under AI → Settings.
95
+ */
96
+ actsAs: z.string().regex(/^[a-z][a-z0-9_-]{1,39}$/, "That isn't a role's name.").optional(),
97
+ }).superRefine((workflow, issues) => {
98
+ const twice = (values) => values.find((value, index) => values.indexOf(value) !== index);
99
+ const agents = new Set(workflow.agents.map((agent) => agent.id));
100
+ const steps = new Map(workflow.steps.map((step, index) => [step.id, index]));
101
+ const agentTwice = twice(workflow.agents.map((agent) => agent.id));
102
+ if (agentTwice)
103
+ issues.addIssue({ code: "custom", path: ["agents"], message: `The agent "${agentTwice}" is listed twice.` });
104
+ const stepTwice = twice(workflow.steps.map((step) => step.id));
105
+ if (stepTwice)
106
+ issues.addIssue({ code: "custom", path: ["steps"], message: `The step "${stepTwice}" is listed twice.` });
107
+ const inputTwice = twice(workflow.inputs.map((input) => input.name));
108
+ if (inputTwice)
109
+ issues.addIssue({ code: "custom", path: ["inputs"], message: `The input "${inputTwice}" is listed twice.` });
110
+ if (workflow.planner && !agents.has(workflow.planner.agent))
111
+ issues.addIssue({ code: "custom", path: ["planner", "agent"], message: "The planner isn't on the team." });
112
+ workflow.steps.forEach((step, index) => {
113
+ const at = (path, message) => issues.addIssue({ code: "custom", path: ["steps", index, ...path], message });
114
+ for (const writer of step.writers)
115
+ if (!agents.has(writer))
116
+ at(["writers"], `"${writer}" isn't on the team.`);
117
+ if (step.judge && !agents.has(step.judge.agent))
118
+ at(["judge", "agent"], "The judge isn't on the team.");
119
+ if (step.strategy === "compete" && !step.judge)
120
+ at(["judge"], "Writers that compete need a judge to choose between them.");
121
+ step.images.forEach((image, imageIndex) => { for (const artist of image.artists)
122
+ if (!agents.has(artist))
123
+ at(["images", imageIndex, "artists"], `"${artist}" isn't on the team.`); });
124
+ if (step.parent) {
125
+ // Parents come first, so a step's records always have theirs to belong to.
126
+ const parent = steps.get(step.parent);
127
+ if (parent === undefined)
128
+ at(["parent"], "There's no such step.");
129
+ else if (parent >= index)
130
+ at(["parent"], "A step's parent must come before it.");
131
+ if (!step.link)
132
+ at(["link"], "Choose the field that links each record to its parent.");
133
+ }
134
+ // A link further up must name a step this one is under.
135
+ const ancestors = new Set();
136
+ for (let parent = step.parent; parent && !ancestors.has(parent); parent = workflow.steps.find((other) => other.id === parent)?.parent)
137
+ ancestors.add(parent);
138
+ step.links.forEach((link, linkIndex) => { if (!ancestors.has(link.step))
139
+ at(["links", linkIndex, "step"], "Link only to a step this one is under."); });
140
+ });
141
+ });
142
+ /** Fills {{name}} with the run's inputs. Unknown names stay as written. */
143
+ export const fill = (template, inputs) => template.replace(/\{\{\s*([a-zA-Z][a-zA-Z0-9_]*)\s*\}\}/g, (whole, key) => (key in inputs ? inputs[key] : whole));
@@ -0,0 +1,9 @@
1
+ import { type Catalog } from "./check";
2
+ import type { WorkflowInput } from "./schema";
3
+ /**
4
+ * Starting points for a new workflow, filled in with models the site can use and
5
+ * collections it has. Everything stays editable.
6
+ */
7
+ export type TemplateId = "course" | "articles" | "catalog" | "blank";
8
+ export declare const TEMPLATES: TemplateId[];
9
+ export declare function fromTemplate(template: TemplateId, catalog: Catalog, collections: string[], name: string): WorkflowInput;
@@ -0,0 +1,81 @@
1
+ import { supports } from "./check";
2
+ export const TEMPLATES = ["course", "articles", "catalog", "blank"];
3
+ /** The first ready model that can do a task, preferring the provider's own default. */
4
+ function pick(catalog, task) {
5
+ for (const entry of catalog.providers.filter((item) => item.ready)) {
6
+ const models = entry.models ?? [];
7
+ const fallback = models.find((model) => model.value === entry.defaultModel) ?? models[0];
8
+ const found = task === "write"
9
+ ? (supports(fallback?.capabilities, "write") !== "no" ? fallback : models.find((model) => supports(model.capabilities, "write") === "yes"))
10
+ : models.find((model) => supports(model.capabilities, "image") === "yes");
11
+ if (found)
12
+ return { provider: entry.id, model: found.value };
13
+ if (task === "write" && !entry.models && entry.defaultModel)
14
+ return { provider: entry.id, model: entry.defaultModel };
15
+ }
16
+ return null;
17
+ }
18
+ const slugOf = (name) => name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 40) || "workflow";
19
+ export function fromTemplate(template, catalog, collections, name) {
20
+ const writer = pick(catalog, "write") ?? { provider: catalog.providers[0]?.id ?? "openai", model: catalog.providers[0]?.defaultModel ?? "" };
21
+ const artist = pick(catalog, "image");
22
+ const has = (slug) => collections.includes(slug);
23
+ const id = `${slugOf(name)}-${Math.random().toString(36).slice(2, 6)}`;
24
+ const agent = (agentId, agentName, role, model = writer) => ({ id: agentId, name: agentName, role, provider: model.provider, model: model.model, reasoning: "provider-default" });
25
+ const lead = agent("lead", "Lead editor", "A managing editor who plans the work, sets the voice and writes each writer a sharp brief.");
26
+ const writerA = agent("writer", "Writer", "A clear, warm writer who explains with concrete examples.");
27
+ const writerB = agent("writer-2", "Second writer", "A precise writer who favours structure, short sentences and checklists.");
28
+ const judge = agent("judge", "Judge", "A demanding reviewer who checks accuracy, completeness and fit with the brief, and says exactly what to fix.");
29
+ const illustrator = artist ? agent("illustrator", "Illustrator", "Draws clean editorial illustrations.", artist) : null;
30
+ const base = { id, name, retry: { attempts: 3, backoffSeconds: 4 }, concurrency: 2, status: "draft" };
31
+ if (template === "course") {
32
+ const lms = has("lms-courses") && has("lms-sections") && has("lms-lessons");
33
+ return {
34
+ ...base,
35
+ description: "A course with its sections and lessons, planned by a lead, written by two writers in turn and checked by a judge.",
36
+ brief: "Create a complete online course about {{topic}} for {{audience}}. Lessons build on each other, teach by example and end with a short recap.",
37
+ inputs: [{ name: "topic", label: "Topic", multiline: false, required: true }, { name: "audience", label: "Audience", multiline: false, required: true }],
38
+ agents: [lead, writerA, writerB, judge],
39
+ planner: { agent: "lead" },
40
+ steps: [
41
+ { id: "course", name: "Course", collection: lms ? "lms-courses" : collections[0] ?? "", count: { min: 1, max: 1 }, fields: [], instructions: "The course page: a title, a summary that sells it, and what learners will be able to do.", writers: ["writer"], strategy: "rotate", judge: { agent: "judge", criteria: "", minScore: 7, revisions: 1 }, images: [], links: [] },
42
+ { id: "sections", name: "Sections", collection: lms ? "lms-sections" : "", parent: "course", link: lms ? "course" : undefined, orderField: lms ? "position" : undefined, count: { min: 3, max: 6 }, fields: [], instructions: "Modules that take the learner from first steps to confident use.", writers: ["writer"], strategy: "rotate", images: [], links: [] },
43
+ { id: "lessons", name: "Lessons", collection: lms ? "lms-lessons" : "", parent: "sections", link: lms ? "section" : undefined, links: lms ? [{ field: "course", step: "course" }] : [], orderField: lms ? "position" : undefined, count: { min: 2, max: 5 }, fields: [], instructions: "Each lesson teaches one idea with a worked example, then a short exercise.", writers: ["writer", "writer-2"], strategy: "rotate", judge: { agent: "judge", criteria: "", minScore: 7, revisions: 2 }, images: [] },
44
+ ],
45
+ };
46
+ }
47
+ if (template === "articles") {
48
+ const posts = ["posts", "blog-posts", "articles"].find(has) ?? collections[0] ?? "";
49
+ return {
50
+ ...base,
51
+ description: "A batch of articles: two writers compete on each, a judge keeps the better one and sends it back until it's good enough.",
52
+ brief: "Write articles about {{topic}} for the site's readers. Each takes its own angle, opens with a strong hook and ends with a takeaway.",
53
+ inputs: [{ name: "topic", label: "Topic", multiline: true, required: true }],
54
+ agents: [writerA, writerB, judge, ...(illustrator ? [illustrator] : [])],
55
+ steps: [
56
+ { id: "articles", name: "Articles", collection: posts, count: { min: 3, max: 6 }, fields: [], instructions: "", writers: ["writer", "writer-2"], strategy: "compete", judge: { agent: "judge", criteria: "", minScore: 8, revisions: 1 }, images: [], links: [] },
57
+ ],
58
+ };
59
+ }
60
+ if (template === "catalog") {
61
+ const products = ["shop-products", "products"].find(has) ?? collections[0] ?? "";
62
+ return {
63
+ ...base,
64
+ description: "Product descriptions in the site's voice, from a list of product names.",
65
+ brief: "Write product pages for these products, in a confident, friendly voice: {{products}}",
66
+ inputs: [{ name: "products", label: "Products, one per line", multiline: true, required: true }],
67
+ agents: [writerA, judge],
68
+ steps: [
69
+ { id: "products", name: "Products", collection: products, count: { min: 1, max: 20 }, fields: [], instructions: "One record per product listed, in the order given.", writers: ["writer"], strategy: "fallback", judge: { agent: "judge", criteria: "Accurate to the name, benefit-led, no invented specifications or prices.", minScore: 7, revisions: 1 }, images: [], links: [] },
70
+ ],
71
+ };
72
+ }
73
+ return {
74
+ ...base,
75
+ description: "",
76
+ brief: "",
77
+ inputs: [],
78
+ agents: [writerA],
79
+ steps: [{ id: "records", name: "Records", collection: collections[0] ?? "", count: { min: 1, max: 3 }, fields: [], instructions: "", writers: ["writer"], strategy: "rotate", images: [], links: [] }],
80
+ };
81
+ }