Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@kody/skills

Store, retrieve, edit, version, and revert reusable agent skill documents via skill_list then skill_get.

FollowFork

Files

music-attribution.ts

112 lines · 3.3 KB · TypeScript
export type MusicAttributionInput = {
	title: string
	creator: string
	sourceUrl: string
	licenseName: string
	licenseUrl: string
	contentId?: string | null
	commercialUseAllowed?: boolean | null
	verifiedAt?: string | null
	notes?: string | null
}

export type MusicAttributionResult = {
	markdown: string
	rightsVerified: false
	recommendFreshRightsCheck: true
}

function requireText(name: string, value: unknown) {
	if (typeof value !== 'string' || !value.trim()) {
		throw new Error(`${name} must be a non-empty string`)
	}
	return value.trim()
}

/**
 * Build a rights-note Markdown stub from caller-supplied music metadata.
 * Use when recording title/creator/source/license for a promo track.
 * Does not assert copyright ownership or clearance — verify rights fresh.
 *
 * @param input - title, creator, sourceUrl, licenseName, licenseUrl, optional flags
 * @returns Markdown note plus reminder flags
 *
 * @example
 * import musicAttribution from 'kody:@kody/skills/music-attribution'
 *
 * const note = await musicAttribution({
 *   title: 'Example Cue',
 *   creator: 'Example Artist',
 *   sourceUrl: 'https://example.com/track',
 *   licenseName: 'Example License',
 *   licenseUrl: 'https://example.com/license',
 * })
 */
export default function musicAttribution(
	input: MusicAttributionInput,
): MusicAttributionResult {
	if (!input || typeof input !== 'object') {
		throw new Error('input object is required')
	}
	const allowed = new Set([
		'title',
		'creator',
		'sourceUrl',
		'licenseName',
		'licenseUrl',
		'contentId',
		'commercialUseAllowed',
		'verifiedAt',
		'notes',
	])
	const unknown = Object.keys(input).filter((key) => !allowed.has(key))
	if (unknown.length) {
		throw new Error(`unknown input key(s): ${unknown.join(', ')}`)
	}
	const title = requireText('title', input.title)
	const creator = requireText('creator', input.creator)
	const sourceUrl = requireText('sourceUrl', input.sourceUrl)
	const licenseName = requireText('licenseName', input.licenseName)
	const licenseUrl = requireText('licenseUrl', input.licenseUrl)

	const lines = [
		'# Music attribution',
		'',
		`- Title: ${title}`,
		`- Creator: ${creator}`,
		`- Source: ${sourceUrl}`,
		`- License: ${licenseName} (${licenseUrl})`,
	]
	if (input.contentId !== undefined && input.contentId !== null) {
		lines.push(`- Content ID / fingerprint note: ${String(input.contentId)}`)
	} else {
		lines.push('- Content ID / fingerprint note: (not recorded)')
	}
	if (input.commercialUseAllowed === true) {
		lines.push('- Commercial use flag (caller-supplied): reported allowed')
	} else if (input.commercialUseAllowed === false) {
		lines.push('- Commercial use flag (caller-supplied): reported not allowed')
	} else {
		lines.push('- Commercial use flag (caller-supplied): unset')
	}
	if (input.verifiedAt) {
		lines.push(`- Caller verification timestamp: ${input.verifiedAt}`)
	} else {
		lines.push('- Caller verification timestamp: unset')
	}
	if (input.notes) {
		lines.push(`- Notes: ${input.notes}`)
	}
	lines.push(
		'',
		'This note records caller-supplied metadata only. It is not a copyright',
		'clearance, license grant, or proof of commercial rights. Re-check the',
		'license and Content ID status before any public upload or paid placement.',
	)

	return {
		markdown: lines.join('\n') + '\n',
		rightsVerified: false,
		recommendFreshRightsCheck: true,
	}
}