@businesskit/agent 1.0.3 → 1.0.4
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/.claude/settings.json +16 -0
- package/.claude/settings.local.json +11 -0
- package/.env.example +10 -0
- package/CLAUDE.md +32 -13
- package/PLAN.md +95 -134
- package/REFERENCE.md +60 -24
- package/agents/_base.ts +352 -44
- package/agents/analytics/SOUL.md +11 -0
- package/agents/analytics/analytics.ts +405 -0
- package/agents/business/SOUL.md +11 -0
- package/agents/{csuite/cbo.ts → business/business.ts} +2 -2
- package/agents/ceo/SOUL.md +15 -0
- package/agents/{csuite → ceo}/ceo.ts +33 -8
- package/agents/content/SOUL.md +11 -0
- package/agents/content/content.ts +379 -0
- package/agents/copywriting/SOUL.md +11 -0
- package/agents/courses/SOUL.md +11 -0
- package/agents/courses/courses.ts +451 -0
- package/agents/docs/SOUL.md +11 -0
- package/agents/forms/SOUL.md +11 -0
- package/agents/forms/forms.ts +364 -0
- package/agents/hiring/SOUL.md +11 -0
- package/agents/hiring/hiring.ts +314 -0
- package/agents/marketing/SOUL.md +15 -0
- package/agents/{csuite/cmo.ts → marketing/marketing.ts} +3 -3
- package/agents/newsletter/SOUL.md +11 -0
- package/agents/operations/SOUL.md +11 -0
- package/agents/operations/operations.ts +157 -0
- package/agents/sales/SOUL.md +44 -0
- package/agents/sales/sales.ts +883 -0
- package/agents/scheduler/SOUL.md +11 -0
- package/agents/{growth → scheduler}/scheduler.ts +2 -2
- package/agents/seo/SOUL.md +11 -0
- package/agents/{growth/seo-agent.ts → seo/seo.ts} +60 -54
- package/agents/social/SOUL.md +11 -0
- package/agents/social/social.ts +744 -0
- package/agents/store/SOUL.md +11 -0
- package/agents/store/store.ts +514 -0
- package/cli.ts +44 -25
- package/lib/cms.ts +88 -0
- package/lib/db.ts +58 -11
- package/lib/enums.ts +25 -0
- package/lib/groups.ts +122 -0
- package/lib/id.ts +38 -10
- package/lib/profile.ts +44 -8
- package/lib/schema.ts +2015 -0
- package/lib/validate.ts +33 -0
- package/package.json +1 -1
- package/scripts/generate-schema.ts +244 -0
- package/setup.ts +16 -2
- package/skills/schema/SKILL.md +57 -16
- package/tsconfig.json +2 -1
- package/agents/creators/blog-writer.ts +0 -347
- package/agents/creators/course-creator.ts +0 -106
- package/agents/creators/crm-agent.ts +0 -479
- package/agents/creators/forms-builder.ts +0 -90
- package/agents/creators/jobs-manager.ts +0 -82
- package/agents/creators/store-manager.ts +0 -138
- package/agents/csuite/coo.ts +0 -115
- package/agents/growth/analytics-agent.ts +0 -52
- package/agents/growth/social-agent.ts +0 -346
- /package/{ingest.md → .claude/commands/ingest.md} +0 -0
- /package/agents/{creators/copywriter.ts → copywriting/copywriting.ts} +0 -0
- /package/agents/{creators/docs-writer.ts → docs/docs.ts} +0 -0
- /package/agents/{creators/newsletter-writer.ts → newsletter/newsletter.ts} +0 -0
- /package/{ABOUT-ME.md → context/about-me.md} +0 -0
- /package/{brand-voice.md → context/brand-voice.md} +0 -0
- /package/{working-style.md → context/working-style.md} +0 -0
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Blog Writer — SEObot-quality content agent
|
|
3
|
-
*
|
|
4
|
-
* Produces 8 content formats from content.ts:
|
|
5
|
-
* posts → blog: listicle, how-to, checklist, qa, versus, roundup, news, ultimate-guide
|
|
6
|
-
* compare → "X vs Y" programmatic SEO pages
|
|
7
|
-
* alternative → "Best alternatives to X" pages
|
|
8
|
-
* prompt → prompt library articles
|
|
9
|
-
* notes → short-form notes
|
|
10
|
-
* guides → long-form step-by-step guides
|
|
11
|
-
* newsletter → email newsletter content
|
|
12
|
-
*
|
|
13
|
-
* Quality bar (from SEObot research):
|
|
14
|
-
* - Min 1500 words for blog, 2500+ for ultimate-guide
|
|
15
|
-
* - SEO title ≤60 chars, meta description ≤160 chars
|
|
16
|
-
* - Excerpt is a hook sentence, not a summary
|
|
17
|
-
* - internal_links: link to 2-3 related posts in same profile
|
|
18
|
-
* - sources: cite real URLs when making factual claims
|
|
19
|
-
* - content_type drives structure (listicle ≠ how-to ≠ qa)
|
|
20
|
-
*
|
|
21
|
-
* Tables written: posts, compare, alternative, prompt, notes, guides, newsletter
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import { BaseAgent, db, ulid, iso } from '../_base.ts'
|
|
25
|
-
import { logMemory } from '../../lib/memory.ts'
|
|
26
|
-
|
|
27
|
-
export type ContentType =
|
|
28
|
-
| 'blog' // generic post
|
|
29
|
-
| 'listicle' // "Top 10 X" — numbered list with explanations
|
|
30
|
-
| 'how-to' // "How to X" — step by step
|
|
31
|
-
| 'checklist' // "X Checklist" — checkbox format
|
|
32
|
-
| 'qa' // "What is X? FAQs" — question/answer pairs
|
|
33
|
-
| 'versus' // "X vs Y" — comparison post (uses compare table)
|
|
34
|
-
| 'roundup' // "Best X tools/resources" — curated list
|
|
35
|
-
| 'news' // timely news summary with source links
|
|
36
|
-
| 'ultimate-guide'// definitive long-form guide 2500+ words
|
|
37
|
-
| 'programmatic' // template-based SEO at scale
|
|
38
|
-
|
|
39
|
-
export type ContentTable =
|
|
40
|
-
| 'posts' | 'compare' | 'alternative' | 'prompt'
|
|
41
|
-
| 'notes' | 'guides' | 'newsletter'
|
|
42
|
-
|
|
43
|
-
export interface WriteInput {
|
|
44
|
-
title: string
|
|
45
|
-
topic?: string // if different from title
|
|
46
|
-
content_type?: ContentType
|
|
47
|
-
table?: ContentTable // default: 'posts'
|
|
48
|
-
target_keywords?: string[]
|
|
49
|
-
word_count_target?: number // default varies by type
|
|
50
|
-
collection_id?: string
|
|
51
|
-
publish?: boolean // default: false (draft)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface WriteResult {
|
|
55
|
-
id: string
|
|
56
|
-
table: ContentTable
|
|
57
|
-
slug: string
|
|
58
|
-
title: string
|
|
59
|
-
word_count: number
|
|
60
|
-
content_type: ContentType
|
|
61
|
-
seo_title: string
|
|
62
|
-
seo_description: string
|
|
63
|
-
published: boolean
|
|
64
|
-
url: string
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Word count targets by content type
|
|
68
|
-
const WORD_TARGETS: Record<ContentType, number> = {
|
|
69
|
-
'blog': 1500,
|
|
70
|
-
'listicle': 2000,
|
|
71
|
-
'how-to': 2000,
|
|
72
|
-
'checklist': 1200,
|
|
73
|
-
'qa': 1500,
|
|
74
|
-
'versus': 2000,
|
|
75
|
-
'roundup': 2000,
|
|
76
|
-
'news': 800,
|
|
77
|
-
'ultimate-guide': 3000,
|
|
78
|
-
'programmatic': 1000,
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Which table each type writes to by default
|
|
82
|
-
const TYPE_TABLE: Partial<Record<ContentType, ContentTable>> = {
|
|
83
|
-
'versus': 'compare',
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export class BlogWriter extends BaseAgent {
|
|
87
|
-
readonly name = 'Blog Writer'
|
|
88
|
-
readonly title = 'Blog Writer'
|
|
89
|
-
|
|
90
|
-
// ── Write new content ───────────────────────────────────────────────────────
|
|
91
|
-
|
|
92
|
-
async write(input: WriteInput): Promise<WriteResult> {
|
|
93
|
-
await this.init()
|
|
94
|
-
|
|
95
|
-
const contentType = input.content_type ?? 'blog'
|
|
96
|
-
const table = input.table ?? TYPE_TABLE[contentType] ?? 'posts'
|
|
97
|
-
const wordTarget = input.word_count_target ?? WORD_TARGETS[contentType]
|
|
98
|
-
const slug = await this.makeSlug(input.title, table)
|
|
99
|
-
const id = ulid()
|
|
100
|
-
const now = iso()
|
|
101
|
-
const keywords = input.target_keywords ?? []
|
|
102
|
-
|
|
103
|
-
// Build content structure instructions per type
|
|
104
|
-
const structureHint = this.structureForType(contentType, wordTarget, keywords)
|
|
105
|
-
|
|
106
|
-
// Agent writes the actual content — this is the LLM's job
|
|
107
|
-
// The method returns the structure; Claude fills in the words
|
|
108
|
-
const content = await this.generateContent(input.title, input.topic ?? input.title, structureHint, keywords)
|
|
109
|
-
const excerpt = await this.generateExcerpt(content, contentType)
|
|
110
|
-
const seoTitle = await this.generateSEOTitle(input.title, keywords)
|
|
111
|
-
const seoDesc = await this.generateSEODescription(content, keywords)
|
|
112
|
-
|
|
113
|
-
const wordCount = this.countWords(content)
|
|
114
|
-
const readingTime = Math.ceil(wordCount / 200)
|
|
115
|
-
|
|
116
|
-
// Get internal links from existing posts
|
|
117
|
-
const internalLinks = await this.findInternalLinks(input.title, keywords)
|
|
118
|
-
|
|
119
|
-
if (table === 'posts') {
|
|
120
|
-
await db.execute({
|
|
121
|
-
sql: `INSERT INTO posts
|
|
122
|
-
(id,profile_id,user_id,slug,title,content,excerpt,
|
|
123
|
-
content_type,seo_title,seo_description,seo_keywords,
|
|
124
|
-
word_count,reading_time_mins,internal_links,sources,
|
|
125
|
-
published,hidden,collection_id,created_at,updated_at)
|
|
126
|
-
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,0,?,?,?)`,
|
|
127
|
-
args: [
|
|
128
|
-
id, this.profileId, this.userId, slug, input.title, content, excerpt,
|
|
129
|
-
contentType, seoTitle, seoDesc,
|
|
130
|
-
keywords.length ? JSON.stringify(keywords) : null,
|
|
131
|
-
wordCount, readingTime,
|
|
132
|
-
JSON.stringify(internalLinks), '[]',
|
|
133
|
-
input.publish ? 1 : 0, null,
|
|
134
|
-
input.collection_id ?? null, now, now,
|
|
135
|
-
],
|
|
136
|
-
})
|
|
137
|
-
} else {
|
|
138
|
-
// compare, alternative, prompt, notes, guides, newsletter
|
|
139
|
-
await db.execute({
|
|
140
|
-
sql: `INSERT INTO ${table}
|
|
141
|
-
(id,profile_id,user_id,slug,title,content,excerpt,
|
|
142
|
-
published,hidden,collection_id,created_at,updated_at)
|
|
143
|
-
VALUES (?,?,?,?,?,?,?,?,0,?,?,?)`,
|
|
144
|
-
args: [
|
|
145
|
-
id, this.profileId, this.userId, slug, input.title, content, excerpt,
|
|
146
|
-
input.publish ? 1 : 0,
|
|
147
|
-
input.collection_id ?? null, now, now,
|
|
148
|
-
],
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
await logMemory('blog-writer',
|
|
153
|
-
`${input.publish ? 'Published' : 'Drafted'} "${input.title}" (${contentType}, ${wordCount} words)`,
|
|
154
|
-
{ id, table, slug, content_type: contentType, word_count: wordCount }
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
return {
|
|
158
|
-
id, table, slug, title: input.title,
|
|
159
|
-
word_count: wordCount, content_type: contentType,
|
|
160
|
-
seo_title: seoTitle, seo_description: seoDesc,
|
|
161
|
-
published: !!input.publish,
|
|
162
|
-
url: `https://${this.ctx.profile.slug}.businesskit.io/${table === 'posts' ? 'blog' : table}/${slug}`,
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// ── List + manage ───────────────────────────────────────────────────────────
|
|
167
|
-
|
|
168
|
-
async listDrafts(table: ContentTable = 'posts') {
|
|
169
|
-
await this.init()
|
|
170
|
-
const { rows } = await db.execute({
|
|
171
|
-
sql: `SELECT id,title,slug,content_type,word_count,created_at
|
|
172
|
-
FROM ${table} WHERE profile_id=? AND published=0 AND hidden=0
|
|
173
|
-
ORDER BY created_at DESC LIMIT 20`,
|
|
174
|
-
args: [this.profileId],
|
|
175
|
-
})
|
|
176
|
-
return rows
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async listPublished(table: ContentTable = 'posts', limit = 20) {
|
|
180
|
-
await this.init()
|
|
181
|
-
const { rows } = await db.execute({
|
|
182
|
-
sql: `SELECT id,title,slug,content_type,word_count,created_at
|
|
183
|
-
FROM ${table} WHERE profile_id=? AND published=1 AND hidden=0
|
|
184
|
-
ORDER BY created_at DESC LIMIT ?`,
|
|
185
|
-
args: [this.profileId, limit],
|
|
186
|
-
})
|
|
187
|
-
return rows
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async publishContent(id: string, table: ContentTable = 'posts') {
|
|
191
|
-
await this.init()
|
|
192
|
-
await db.execute({
|
|
193
|
-
sql: `UPDATE ${table} SET published=1,updated_at=? WHERE id=? AND profile_id=?`,
|
|
194
|
-
args: [iso(), id, this.profileId],
|
|
195
|
-
})
|
|
196
|
-
const { rows: [r] } = await db.execute({
|
|
197
|
-
sql: `SELECT title,slug FROM ${table} WHERE id=? LIMIT 1`,
|
|
198
|
-
args: [id],
|
|
199
|
-
})
|
|
200
|
-
if (r) await logMemory('blog-writer', `Published "${r.title}"`, { id, table, slug: r.slug })
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
async unpublish(id: string, table: ContentTable = 'posts') {
|
|
204
|
-
await this.init()
|
|
205
|
-
await db.execute({
|
|
206
|
-
sql: `UPDATE ${table} SET published=0,updated_at=? WHERE id=? AND profile_id=?`,
|
|
207
|
-
args: [iso(), id, this.profileId],
|
|
208
|
-
})
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async archiveContent(id: string, table: ContentTable = 'posts') {
|
|
212
|
-
await this.init()
|
|
213
|
-
await db.execute({
|
|
214
|
-
sql: `UPDATE ${table} SET hidden=1,updated_at=? WHERE id=? AND profile_id=?`,
|
|
215
|
-
args: [iso(), id, this.profileId],
|
|
216
|
-
})
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// ── Content inventory across all tables ─────────────────────────────────────
|
|
220
|
-
|
|
221
|
-
async inventory() {
|
|
222
|
-
await this.init()
|
|
223
|
-
const tables: ContentTable[] = ['posts', 'compare', 'alternative', 'prompt', 'notes', 'guides', 'newsletter']
|
|
224
|
-
const results: Record<string, { published: number; drafts: number }> = {}
|
|
225
|
-
|
|
226
|
-
for (const t of tables) {
|
|
227
|
-
try {
|
|
228
|
-
const { rows: [r] } = await db.execute({
|
|
229
|
-
sql: `SELECT
|
|
230
|
-
SUM(CASE WHEN published=1 AND hidden=0 THEN 1 ELSE 0 END) published,
|
|
231
|
-
SUM(CASE WHEN published=0 AND hidden=0 THEN 1 ELSE 0 END) drafts
|
|
232
|
-
FROM ${t} WHERE profile_id=?`,
|
|
233
|
-
args: [this.profileId],
|
|
234
|
-
})
|
|
235
|
-
results[t] = { published: Number(r?.published ?? 0), drafts: Number(r?.drafts ?? 0) }
|
|
236
|
-
} catch {
|
|
237
|
-
results[t] = { published: 0, drafts: 0 }
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return results
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ── SEO quality audit ───────────────────────────────────────────────────────
|
|
244
|
-
|
|
245
|
-
async seoAudit(table: ContentTable = 'posts') {
|
|
246
|
-
await this.init()
|
|
247
|
-
const { rows } = await db.execute({
|
|
248
|
-
sql: `SELECT id,title,slug,excerpt,seo_title,seo_description,word_count,content_type
|
|
249
|
-
FROM ${table} WHERE profile_id=? AND published=1 AND hidden=0`,
|
|
250
|
-
args: [this.profileId],
|
|
251
|
-
})
|
|
252
|
-
|
|
253
|
-
const issues: Array<{ id: string; title: string; problems: string[] }> = []
|
|
254
|
-
for (const r of rows) {
|
|
255
|
-
const problems: string[] = []
|
|
256
|
-
if (!r.excerpt) problems.push('missing excerpt')
|
|
257
|
-
if (!r.seo_title) problems.push('missing seo_title')
|
|
258
|
-
if (!r.seo_description) problems.push('missing seo_description')
|
|
259
|
-
if (r.seo_title && String(r.seo_title).length > 60) problems.push('seo_title too long (>60)')
|
|
260
|
-
if (r.seo_description && String(r.seo_description).length > 160) problems.push('seo_description too long (>160)')
|
|
261
|
-
if (Number(r.word_count ?? 0) < 300) problems.push('too short (<300 words)')
|
|
262
|
-
if (!r.slug || String(r.slug).includes(' ')) problems.push('bad slug')
|
|
263
|
-
if (problems.length) issues.push({ id: r.id as string, title: r.title as string, problems })
|
|
264
|
-
}
|
|
265
|
-
return issues
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// ── Private helpers ──────────────────────────────────────────────────────────
|
|
269
|
-
|
|
270
|
-
private structureForType(type: ContentType, wordTarget: number, keywords: string[]): string {
|
|
271
|
-
const kw = keywords.length ? `Target keywords: ${keywords.join(', ')}. ` : ''
|
|
272
|
-
|
|
273
|
-
const structures: Record<ContentType, string> = {
|
|
274
|
-
'blog': `${kw}Write a comprehensive blog post. Intro hook → 3-5 main sections with H2s → conclusion with CTA. ~${wordTarget} words.`,
|
|
275
|
-
'listicle': `${kw}Write a numbered listicle. Hook intro → numbered items (each with H3, 2-3 sentences, practical tip) → summary. Aim for 7-15 items. ~${wordTarget} words.`,
|
|
276
|
-
'how-to': `${kw}Write a step-by-step how-to guide. Problem intro → numbered steps (each with H3, clear action, why it matters) → result/outcome. ~${wordTarget} words.`,
|
|
277
|
-
'checklist': `${kw}Write a practical checklist. Short intro → grouped checklist items with brief explanations → conclusion. Use clear imperative language. ~${wordTarget} words.`,
|
|
278
|
-
'qa': `${kw}Write a Q&A article. Short intro → 8-12 questions as H2s with 2-4 sentence answers → summary. Address real search queries. ~${wordTarget} words.`,
|
|
279
|
-
'versus': `${kw}Write a versus comparison. TL;DR verdict first → feature table → pros/cons each option → who should use what → verdict. ~${wordTarget} words.`,
|
|
280
|
-
'roundup': `${kw}Write a curated roundup. Intro explaining criteria → each option with H3, 2-3 sentences, best for who → comparison table → top pick. ~${wordTarget} words.`,
|
|
281
|
-
'news': `${kw}Write a news article. Lead paragraph (who/what/when/where/why) → context → implications → sources cited. ~${wordTarget} words. Cite all facts.`,
|
|
282
|
-
'ultimate-guide':`${kw}Write a definitive ultimate guide. Executive summary → table of contents → deep-dive sections with H2+H3 hierarchy → examples → FAQs → conclusion. ~${wordTarget}+ words.`,
|
|
283
|
-
'programmatic': `${kw}Write an SEO-optimized page. Clear H1 → key info table → main content → FAQs → CTA. Concise and factual. ~${wordTarget} words.`,
|
|
284
|
-
}
|
|
285
|
-
return structures[type]
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
private async generateContent(title: string, topic: string, structure: string, keywords: string[]): Promise<string> {
|
|
289
|
-
// In agent context: Claude IS the LLM. Claude writes this content directly.
|
|
290
|
-
// This method returns the prompt structure; the agent fills it with real content.
|
|
291
|
-
// When called from CLI or Claude Code, the agent generates and returns the content.
|
|
292
|
-
return `<!-- Agent: generate ${structure} for title: "${title}" -->`
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
private async generateExcerpt(content: string, type: ContentType): Promise<string> {
|
|
296
|
-
// Hook sentence, not a summary. Makes reader want to click.
|
|
297
|
-
return `<!-- Agent: write a 1-sentence hook excerpt for this ${type} -->`
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
private async generateSEOTitle(title: string, keywords: string[]): Promise<string> {
|
|
301
|
-
// ≤60 chars, includes primary keyword
|
|
302
|
-
const kw = keywords[0] ?? ''
|
|
303
|
-
const base = kw && !title.toLowerCase().includes(kw.toLowerCase())
|
|
304
|
-
? `${title} | ${kw}` : title
|
|
305
|
-
return base.slice(0, 60)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
private async generateSEODescription(content: string, keywords: string[]): Promise<string> {
|
|
309
|
-
// ≤160 chars, compelling, includes keyword
|
|
310
|
-
return `<!-- Agent: write 155-char meta description including: ${keywords.join(', ')} -->`
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
private async findInternalLinks(title: string, keywords: string[]): Promise<string[]> {
|
|
314
|
-
// Find 2-3 related published posts in same profile
|
|
315
|
-
try {
|
|
316
|
-
const search = keywords[0] ?? title.split(' ')[0]
|
|
317
|
-
const { rows } = await db.execute({
|
|
318
|
-
sql: `SELECT slug,title FROM posts
|
|
319
|
-
WHERE profile_id=? AND published=1 AND hidden=0
|
|
320
|
-
AND (title LIKE ? OR slug LIKE ?)
|
|
321
|
-
LIMIT 3`,
|
|
322
|
-
args: [this.profileId, `%${search}%`, `%${search}%`],
|
|
323
|
-
})
|
|
324
|
-
return rows.map((r: any) => `/blog/${r.slug}`)
|
|
325
|
-
} catch { return [] }
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
private async makeSlug(title: string, table: string): Promise<string> {
|
|
329
|
-
const base = title.toLowerCase()
|
|
330
|
-
.replace(/[^a-z0-9\s-]/g, '')
|
|
331
|
-
.replace(/\s+/g, '-')
|
|
332
|
-
.replace(/-+/g, '-')
|
|
333
|
-
.slice(0, 80)
|
|
334
|
-
|
|
335
|
-
const { rows: [exists] } = await db.execute({
|
|
336
|
-
sql: `SELECT slug FROM ${table} WHERE profile_id=? AND slug=? LIMIT 1`,
|
|
337
|
-
args: [this.profileId, base],
|
|
338
|
-
})
|
|
339
|
-
return exists ? `${base}-${Date.now().toString(36)}` : base
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
private countWords(content: string): number {
|
|
343
|
-
return content.replace(/<[^>]+>/g, '').split(/\s+/).filter(Boolean).length
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export const blogWriter = new BlogWriter()
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SAGE — Course Creator
|
|
3
|
-
* "I structure knowledge into learnable paths."
|
|
4
|
-
* Delegates storage to LEO (same products table, type='course').
|
|
5
|
-
* Owns: lesson structure, curriculum, progress tracking reads.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { BaseAgent, db, now } from '../_base.ts'
|
|
9
|
-
import { storeManager } from './store-manager.ts'
|
|
10
|
-
|
|
11
|
-
export interface Lesson {
|
|
12
|
-
id: string
|
|
13
|
-
title: string
|
|
14
|
-
content?: string
|
|
15
|
-
video_url?: string
|
|
16
|
-
duration_minutes?: number
|
|
17
|
-
position: number
|
|
18
|
-
free_preview?: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface CourseInput {
|
|
22
|
-
title: string
|
|
23
|
-
description?: string
|
|
24
|
-
excerpt?: string
|
|
25
|
-
price_cents: number
|
|
26
|
-
sale_price_cents?: number
|
|
27
|
-
thumbnail_url?: string
|
|
28
|
-
lessons?: Lesson[]
|
|
29
|
-
publish?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class CourseCreator extends BaseAgent {
|
|
33
|
-
readonly name = 'SAGE'
|
|
34
|
-
readonly title = 'Course Creator'
|
|
35
|
-
|
|
36
|
-
async create(input: CourseInput) {
|
|
37
|
-
return storeManager.create({
|
|
38
|
-
type: 'course',
|
|
39
|
-
...input,
|
|
40
|
-
// lessons stored as JSON on the product row
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async addLesson(courseId: string, lesson: Omit<Lesson, 'position'>) {
|
|
45
|
-
await this.init()
|
|
46
|
-
const course = await storeManager.get(courseId)
|
|
47
|
-
if (course.type !== 'course') throw new Error('Not a course')
|
|
48
|
-
|
|
49
|
-
const lessons: Lesson[] = JSON.parse(course.lessons as string || '[]')
|
|
50
|
-
const newLesson: Lesson = { ...lesson, position: lessons.length }
|
|
51
|
-
lessons.push(newLesson)
|
|
52
|
-
|
|
53
|
-
const ts = now()
|
|
54
|
-
await db.execute({
|
|
55
|
-
sql: 'UPDATE products SET lessons=?,total_lessons=?,updated_at=? WHERE id=?',
|
|
56
|
-
args: [JSON.stringify(lessons), lessons.length, ts, courseId],
|
|
57
|
-
})
|
|
58
|
-
return storeManager.get(courseId)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async updateLesson(courseId: string, lessonId: string, fields: Partial<Lesson>) {
|
|
62
|
-
await this.init()
|
|
63
|
-
const course = await storeManager.get(courseId)
|
|
64
|
-
const lessons: Lesson[] = JSON.parse(course.lessons as string || '[]')
|
|
65
|
-
const idx = lessons.findIndex(l => l.id === lessonId)
|
|
66
|
-
if (idx === -1) throw new Error(`Lesson not found: ${lessonId}`)
|
|
67
|
-
lessons[idx] = { ...lessons[idx], ...fields }
|
|
68
|
-
|
|
69
|
-
await db.execute({
|
|
70
|
-
sql: 'UPDATE products SET lessons=?,updated_at=? WHERE id=?',
|
|
71
|
-
args: [JSON.stringify(lessons), now(), courseId],
|
|
72
|
-
})
|
|
73
|
-
return storeManager.get(courseId)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async reorderLessons(courseId: string, orderedIds: string[]) {
|
|
77
|
-
await this.init()
|
|
78
|
-
const course = await storeManager.get(courseId)
|
|
79
|
-
const lessons: Lesson[] = JSON.parse(course.lessons as string || '[]')
|
|
80
|
-
const sorted = orderedIds
|
|
81
|
-
.map((id, i) => { const l = lessons.find(x => x.id === id); return l ? { ...l, position: i } : null })
|
|
82
|
-
.filter(Boolean) as Lesson[]
|
|
83
|
-
|
|
84
|
-
await db.execute({
|
|
85
|
-
sql: 'UPDATE products SET lessons=?,updated_at=? WHERE id=?',
|
|
86
|
-
args: [JSON.stringify(sorted), now(), courseId],
|
|
87
|
-
})
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async listCourses(published?: boolean) {
|
|
91
|
-
return storeManager.list({ type: 'course', published })
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Students who purchased this course and their progress */
|
|
95
|
-
async getStudents(courseId: string) {
|
|
96
|
-
await this.init()
|
|
97
|
-
const { rows } = await db.execute({
|
|
98
|
-
sql: `SELECT email,customer_name,course_progress,course_completed,course_completion_date,created_at
|
|
99
|
-
FROM purchases WHERE product_id=? AND profile_id=? ORDER BY created_at DESC`,
|
|
100
|
-
args: [courseId, this.profileId],
|
|
101
|
-
})
|
|
102
|
-
return rows
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const courseCreator = new CourseCreator()
|