11import { v } from 'convex/values'
22import { internal } from './_generated/api'
3+ import type { ActionCtx } from './_generated/server'
34import { internalAction , internalMutation } from './_generated/server'
45import { EMBEDDING_DIMENSIONS } from './lib/embeddings'
56import { parseClawdisMetadata , parseFrontmatter } from './lib/skills'
@@ -13,6 +14,17 @@ type SeedSkillSpec = {
1314 rawSkillMd : string
1415}
1516
17+ type SeedActionArgs = {
18+ reset ?: boolean
19+ }
20+
21+ type SeedActionResult = {
22+ ok : true
23+ results : Array < Record < string , unknown > & { slug : string } >
24+ }
25+
26+ type SeedMutationResult = Record < string , unknown >
27+
1628const SEED_SKILLS : SeedSkillSpec [ ] = [
1729 {
1830 slug : 'padel' ,
@@ -237,53 +249,19 @@ function injectMetadata(rawSkillMd: string, metadata: Record<string, unknown>) {
237249 ) } ${ rawSkillMd . slice ( frontmatterEnd ) } `
238250}
239251
240- export const seedNixSkills = internalAction ( {
241- args : {
242- reset : v . optional ( v . boolean ( ) ) ,
243- } ,
244- handler : async ( ctx , args ) => {
245- const results = [ ]
246-
247- for ( const spec of SEED_SKILLS ) {
248- const skillMd = injectMetadata ( spec . rawSkillMd , spec . metadata )
249- const frontmatter = parseFrontmatter ( skillMd )
250- const clawdis = parseClawdisMetadata ( frontmatter )
251- const storageId = await ctx . storage . store ( new Blob ( [ skillMd ] , { type : 'text/markdown' } ) )
252-
253- const result = await ctx . runMutation ( internal . devSeed . seedSkillMutation , {
254- reset : args . reset ,
255- storageId,
256- metadata : spec . metadata ,
257- frontmatter,
258- clawdis,
259- skillMd,
260- slug : spec . slug ,
261- displayName : spec . displayName ,
262- summary : spec . summary ,
263- version : spec . version ,
264- } )
265-
266- results . push ( { slug : spec . slug , ...result } )
267- }
268-
269- return { ok : true , results }
270- } ,
271- } )
272-
273- export const seedPadelSkill = internalAction ( {
274- args : {
275- reset : v . optional ( v . boolean ( ) ) ,
276- } ,
277- handler : async ( ctx , args ) => {
278- const spec = SEED_SKILLS . find ( ( entry ) => entry . slug === 'padel' )
279- if ( ! spec ) throw new Error ( 'padel seed spec missing' )
252+ async function seedNixSkillsHandler (
253+ ctx : ActionCtx ,
254+ args : SeedActionArgs ,
255+ ) : Promise < SeedActionResult > {
256+ const results : Array < Record < string , unknown > & { slug : string } > = [ ]
280257
258+ for ( const spec of SEED_SKILLS ) {
281259 const skillMd = injectMetadata ( spec . rawSkillMd , spec . metadata )
282260 const frontmatter = parseFrontmatter ( skillMd )
283261 const clawdis = parseClawdisMetadata ( frontmatter )
284262 const storageId = await ctx . storage . store ( new Blob ( [ skillMd ] , { type : 'text/markdown' } ) )
285263
286- return ctx . runMutation ( internal . devSeed . seedSkillMutation , {
264+ const result : SeedMutationResult = await ctx . runMutation ( internal . devSeed . seedSkillMutation , {
287265 reset : args . reset ,
288266 storageId,
289267 metadata : spec . metadata ,
@@ -295,7 +273,51 @@ export const seedPadelSkill = internalAction({
295273 summary : spec . summary ,
296274 version : spec . version ,
297275 } )
276+
277+ results . push ( { slug : spec . slug , ...result } )
278+ }
279+
280+ return { ok : true , results }
281+ }
282+
283+ export const seedNixSkills : ReturnType < typeof internalAction > = internalAction ( {
284+ args : {
285+ reset : v . optional ( v . boolean ( ) ) ,
286+ } ,
287+ handler : seedNixSkillsHandler ,
288+ } )
289+
290+ async function seedPadelSkillHandler (
291+ ctx : ActionCtx ,
292+ args : SeedActionArgs ,
293+ ) : Promise < SeedMutationResult > {
294+ const spec = SEED_SKILLS . find ( ( entry ) => entry . slug === 'padel' )
295+ if ( ! spec ) throw new Error ( 'padel seed spec missing' )
296+
297+ const skillMd = injectMetadata ( spec . rawSkillMd , spec . metadata )
298+ const frontmatter = parseFrontmatter ( skillMd )
299+ const clawdis = parseClawdisMetadata ( frontmatter )
300+ const storageId = await ctx . storage . store ( new Blob ( [ skillMd ] , { type : 'text/markdown' } ) )
301+
302+ return ( await ctx . runMutation ( internal . devSeed . seedSkillMutation , {
303+ reset : args . reset ,
304+ storageId,
305+ metadata : spec . metadata ,
306+ frontmatter,
307+ clawdis,
308+ skillMd,
309+ slug : spec . slug ,
310+ displayName : spec . displayName ,
311+ summary : spec . summary ,
312+ version : spec . version ,
313+ } ) ) as SeedMutationResult
314+ }
315+
316+ export const seedPadelSkill : ReturnType < typeof internalAction > = internalAction ( {
317+ args : {
318+ reset : v . optional ( v . boolean ( ) ) ,
298319 } ,
320+ handler : seedPadelSkillHandler ,
299321} )
300322
301323export const seedSkillMutation = internalMutation ( {
0 commit comments