Skip to content

Scaffold an agentlet

This command creates a working demo agentlet named my-agentlet within agentlet-core/../my-agentlet/, pre-packaged with all required external libraries.

Terminal window
# Full template (comprehensive example with all API features)
npm run scaffold:agentlet:defaults
# Minimal template (simple starter)
npm run scaffold:agentlet -- --minimal
# Interactive scaffolding (choose template and options)
npm run scaffold:agentlet

The minimal template provides a short starting point with basic structure and agentlet.Dialog API usage, while the full template includes comprehensive examples of all framework features.

The generated module declares patterns: ['localhost', '127.0.0.1', 'file://'] with matchMode: 'host', so it matches those hosts and file pages and not a page that only mentions them in its URL. matchMode is available since agentlet-core 2.4.0. An older core ignores it and matches by substring, which also matches these three patterns. Replace the patterns with the host of the site you target. See matching URLs.

The scaffolded src/index.js resolves the registry (agentlets-registry.js) and the PDF.js worker against the URL the core bundle itself was loaded from, not against the host page. The bookmarklet served by npm start on http://localhost:8080 therefore works on any origin, not only on the dev server page. The registry loads module-bundle.js and registers the module class its entry names, so src/index.js does not depend on the agentlet’s name.

Projects scaffolded before agentlet-core 2.2.0 use relative URLs resolved against the host page. To run one on another origin, make registryUrl in src/index.js and the entry url in dist/agentlets-registry.js absolute.

By default, the scaffolded project’s package.json depends on the published npm package, "agentlet-core": "^2.3.0". Pass --core=local, or answer “Local checkout” in the interactive prompt, to depend on this checkout instead, "file:../<folder>". Local checkout is for developing agentlet-core itself alongside a scaffolded agentlet.

Terminal window
npm run scaffold:agentlet -- --core=local
Terminal window
cd ../my-agentlet
npm install
npm run build
npm start