Your first plugin
Build a plugin that adds a clip source to clip search, from an empty folder to a section in the running app.
This builds a plugin like the built-in Clip.Cafe one: a service with an API key, and a section of clips under the Movies & TV clips page’s search. It is about 40 lines.
Create the package
{
"name": "@playactor-plugin/quotes",
"version": "0.0.0",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts",
"./manifest": "./src/manifest.ts"
},
"dependencies": {
"@playactor/plugin": "workspace:*"
}
}
plugins/* is already a pnpm workspace glob, so pnpm install picks it up.
Write the manifest
The manifest is data only. Keep it in its own module so components can import it without a cycle through index.ts.
import type { PluginApi } from '@playactor/plugin'
import { defineManifest, field } from '@playactor/plugin/manifest'
export const manifest = defineManifest({
id: 'quotes',
name: 'Quotes',
services: {
quotes: {
title: 'Quotes API',
hosts: ['api.quotes.example'],
// Until this password preference is filled, the service reads as not set up.
credential: 'apiKey',
},
},
preferences: {
apiKey: field.password({ title: 'API key' }),
},
})
export type QuotesApi = PluginApi<typeof manifest>
defineManifest validates at load: ids are lowercase with dashes, keys are camelCase identifiers, hosts are DNS names, and a credential must name a password preference.
Declare the clip source
import { definePlugin, type ClipPage } from '@playactor/plugin'
import { manifest } from './manifest'
const PAGE_SIZE = 24
export default definePlugin(manifest, {
clipSources: {
clips: {
label: 'Quotes',
service: 'quotes',
pageSize: PAGE_SIZE,
async search(query, { offset, signal }, api): Promise<ClipPage> {
const { apiKey } = api.data.preferences.get()
const url = new URL('https://api.quotes.example/search')
url.searchParams.set('q', query.text)
url.searchParams.set('from', String(offset))
const res = await api.services.quotes.fetch(url, {
headers: { 'x-api-key': apiKey ?? '' },
signal,
})
const body: { hits: QuoteHit[]; total: number } = await res.json()
return {
total: body.total,
hits: body.hits.map(hit => ({
id: hit.slug,
title: hit.title,
quote: hit.text,
durationMs: hit.durationMs,
thumbnailUrl: hit.thumb,
pageUrl: null,
movie: { imdbId: hit.imdbId, title: hit.movie, year: hit.year },
bytes: async signal => {
const mp4 = await api.services.quotes.fetch(hit.mp4Url, { signal })
return new Uint8Array(await mp4.arrayBuffer())
},
})),
}
},
},
},
})
interface QuoteHit {
slug: string
title: string
text: string
durationMs: number | null
thumb: string | null
imdbId: string | null
movie: string | null
year: number | null
mp4Url: string
}
The key, clips, is the source’s id. api comes last in every contribution function. The host debounces the page’s query, pages by offset, and renders loading, empty and failure. While the API key is unset it shows the section as not set up, with a link to the plugin’s settings.
api.services.quotes.fetch refuses any host not in the manifest, over HTTPS only, on every redirect hop. Its outcomes feed the service’s health chip.
Register it
import quotes from '@playactor-plugin/quotes'
export const builtinPlugins: readonly PluginDefinition[] = [
podcasts,
quotes,
// …
]
Add "@playactor-plugin/quotes": "workspace:*" to apps/desktop/package.json, then pnpm install.
Run it
Start the desktop app (pnpm desktop:dev). Settings › Plugins › Quotes shows the enable switch and an API key field, built from the manifest. Fill it in, open the Library, and search.
Next
- Manifest: accounts with sign-in forms or OAuth, pages, synced collections.
- Contributions: title tabs, links, ⌘K search, song actions, album sources.