@@ -130,9 +130,25 @@ export type SponsoredSkillLayer2Verify = z.infer<typeof layer2Verify>
130130
131131export const sponsoredSkillLayer2Schema = z
132132 . object ( {
133- /** Stable slug, `<advertiser>-<goal>`; one id has many versions. */
133+ /**
134+ * Stable slug, `<product>-<goal>` (or `<advertiser>-<goal>` when the
135+ * campaign is for the advertiser's own product). One id has many versions.
136+ */
134137 id : slug ,
135138 advertiser : slug ,
139+ /**
140+ * The product this campaign sells, when it is not the advertiser.
141+ * Omitted for a single-product advertiser, which keeps the advertiser
142+ * label. Step headings and the skill id use it; `advertiser` stays the
143+ * company.
144+ */
145+ product : z
146+ . string ( )
147+ . trim ( )
148+ . min ( 1 )
149+ . max ( 40 )
150+ . refine ( ( value ) => ! / [ \r \n ] / . test ( value ) , 'Use a single line.' )
151+ . optional ( ) ,
136152 /** One sentence: what the agent builds in the user's project. */
137153 goal : z . string ( ) . trim ( ) . min ( 10 ) . max ( 300 ) ,
138154 docsUrl : httpsUrl ,
@@ -189,18 +205,69 @@ export type Layer2BuildResult =
189205 }
190206 | { ok : false ; errors : SponsoredSkillParseError [ ] }
191207
208+ /** `PostHog, Inc.` → `posthog-inc`. Shared with the draft so ids match headings. */
209+ export function layer2Slug ( text : string ) : string {
210+ return text
211+ . normalize ( 'NFKD' )
212+ . replace ( / [ ̀ - ͯ ] / g, '' )
213+ . toLowerCase ( )
214+ . replace ( / [ ^ a - z 0 - 9 ] + / g, '-' )
215+ . replace ( / ^ - + | - + $ / g, '' )
216+ . slice ( 0 , 40 )
217+ . replace ( / - + $ / g, '' )
218+ }
219+
192220/** `posthog` → `Posthog`, `open-router` → `Open Router`: a label, never parsed. */
193- function advertiserLabel ( advertiser : string ) : string {
221+ export function layer2AdvertiserLabel ( advertiser : string ) : string {
194222 return advertiser
195223 . split ( '-' )
196224 . map ( ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . slice ( 1 ) )
197225 . join ( ' ' )
198226}
199227
228+ /**
229+ * The product field as stored. Blank, or the advertiser's own label, means
230+ * there is no distinct product, so a save does not rename a single-product skill.
231+ */
232+ export function layer2StoredProduct (
233+ value : string ,
234+ advertiser : string ,
235+ ) : string | undefined {
236+ const trimmed = value . trim ( )
237+ if ( ! trimmed || trimmed === layer2AdvertiserLabel ( advertiser ) )
238+ return undefined
239+ return trimmed
240+ }
241+
242+ /** The name step headings use: the product, else the advertiser label. */
243+ function brandLabel (
244+ source : Pick < SponsoredSkillLayer2 , 'advertiser' | 'product' > ,
245+ ) : string {
246+ return source . product ?. trim ( ) || layer2AdvertiserLabel ( source . advertiser )
247+ }
248+
249+ /** Product slug first, then the advertiser, so `SERPIE_API_KEY` and `GRIFFIN_KEY` both strip. */
250+ function brandPrefixes (
251+ source : Pick < SponsoredSkillLayer2 , 'advertiser' | 'product' > ,
252+ ) : string [ ] {
253+ const prefixes : string [ ] = [ ]
254+ for ( const value of [ source . product , source . advertiser ] ) {
255+ const slug = value ? layer2Slug ( value ) : ''
256+ if ( slug && ! prefixes . includes ( slug ) ) prefixes . push ( slug )
257+ }
258+ return prefixes
259+ }
260+
200261/** `POSTHOG_PROJECT_TOKEN` → `project token`, `EXA_API_KEY` → `API key`. */
201- function keyLabel ( env : string , advertiser : string ) : string {
202- const prefix = `${ advertiser . replace ( / - / g, '_' ) . toUpperCase ( ) } _`
203- const rest = env . startsWith ( prefix ) ? env . slice ( prefix . length ) : env
262+ function keyLabel ( env : string , prefixes : readonly string [ ] ) : string {
263+ let rest = env
264+ for ( const prefix of prefixes ) {
265+ const needle = `${ prefix . replace ( / - / g, '_' ) . toUpperCase ( ) } _`
266+ if ( rest . startsWith ( needle ) ) {
267+ rest = rest . slice ( needle . length )
268+ break
269+ }
270+ }
204271 return rest
205272 . split ( '_' )
206273 . map ( ( word ) => ( word === 'API' ? word : word . toLowerCase ( ) ) )
@@ -234,7 +301,8 @@ export function compileLayer2Skill(
234301 const npm = source . packages . filter ( ( pkg ) => pkg . ecosystem === 'npm' )
235302 const pypi = source . packages . filter ( ( pkg ) => pkg . ecosystem === 'pypi' )
236303 const envKeys = source . envKeys ?? [ ]
237- const label = advertiserLabel ( source . advertiser )
304+ const label = brandLabel ( source )
305+ const prefixes = brandPrefixes ( source )
238306
239307 // Format 1 has no fit block, so `frameworks` must be non-empty even for a
240308 // Python-only skill; it is informational there, like the archil skill's.
@@ -302,13 +370,21 @@ export function compileLayer2Skill(
302370 envKeys . length === 1 ? 'it' : 'each'
303371 } empty in the example env file.`
304372 : ''
373+ const docsLine = `Docs: ${ source . docsUrl } `
374+ const scaffold = 'In an empty folder, scaffold a minimal project first.'
375+ // A credential's get_url is already the first link in the rendered skill,
376+ // so that step text stays as it was. A signup-only skill has to lead with
377+ // the tracked URL: otherwise the docs link is first and review flags it.
378+ const instructions = envKeys . length
379+ ? `${ source . goal } \n${ docsLine } \n${ scaffold } ${ envLine } `
380+ : `${ source . goal } \nAccount: ${ source . signupUrl } \n${ docsLine } \n${ scaffold } `
305381 const integrate : SponsoredSkillStep = {
306382 id : 'integrate' ,
307383 kind : 'agent' ,
308384 title : `Build the ${ label } integration in this project` ,
309385 // Layer 1 already says fit the project, fewest changes, read the docs;
310386 // the renderer says a step is done when its checks pass.
311- instructions : ` ${ source . goal } \nDocs: ${ source . docsUrl } \nIn an empty folder, scaffold a minimal project first. ${ envLine } ` ,
387+ instructions,
312388 checks : [
313389 ...verifyChecks ,
314390 ...packageChecks ,
@@ -324,21 +400,22 @@ export function compileLayer2Skill(
324400
325401 const userSteps : SponsoredSkillStep [ ] = envKeys . length
326402 ? envKeys . map ( ( env , index ) => {
403+ const key = keyLabel ( env , prefixes )
327404 const credential : SponsoredRunCredential = {
328405 env,
329- label : `${ label } ${ keyLabel ( env , source . advertiser ) } ` . slice ( 0 , 60 ) ,
406+ label : `${ label } ${ key } ` . slice ( 0 , 60 ) ,
330407 getUrl : source . signupUrl ,
331408 }
332409 return {
333410 id : `connect-${ index + 1 } ` ,
334411 kind : 'user' ,
335- title : `Ask the user to create ${ withArticle ( `${ label } ${ keyLabel ( env , source . advertiser ) } ` ) } and paste it` ,
412+ title : `Ask the user to create ${ withArticle ( `${ label } ${ key } ` ) } and paste it` ,
336413 instructions : `The harness saves the value; never read, write or print it or an env file. Once ${ env } is set, run the feature once and report whether ${ label } answered.` ,
337414 checks : [
338415 {
339416 id : `credential-${ index + 1 } ` ,
340417 kind : 'credential_provided' ,
341- label : `the ${ label } ${ keyLabel ( env , source . advertiser ) } was provided` ,
418+ label : `the ${ label } ${ key } was provided` ,
342419 envKey : env ,
343420 } ,
344421 ] ,
0 commit comments