Tutorial: Extract URLs
A practical custom node: paste messy agent output in, get a clean URL list out. Matches the extract-urls demo under examples/nodes/ in the threadle repo. (Smaller starter: import examples/nodes/hello-world first. See Custom nodes. For JSON extraction from agent replies, prefer the stdlib extract-json node.)
Prerequisites: threadle running, and five minutes. For the full descriptor reference see Custom nodes.
1. Create the folder
Section titled “1. Create the folder”Settings → custom nodes → + Create node. Name it extract-urls.
Or by hand:
mkdir -p ~/.config/threadle/nodes/extract-urls2. Descriptor
Section titled “2. Descriptor”{ "id": "extract-urls", "label": "Extract URLs", "glyph": "⛓", "description": "pulls every http(s) URL out of the input, one per line, deduplicated", "entry": "node.ts", "input": "text", "output": "text"}3. Logic
Section titled “3. Logic”export default class ExtractUrls { async run(input: string): Promise<string> { const urls = input.match(/https?:\/\/[^\s)\]}>"']+/g) ?? []; return [...new Set(urls)].join("\n"); }}No threadle imports. Return a string. That becomes the outbound text lane.
4. Try it
Section titled “4. Try it”- Reload threadle (or wait for the nodes watcher).
- Palette → nodes → custom → drag Extract URLs.
- Wire
prompt → Extract URLs → output. - Put this in the prompt:
See https://example.com/a and also https://example.com/a again —plus https://threadle.sh/docs.- Press ▶ Run. The output node should show:
https://example.com/ahttps://threadle.sh/docsWhy this pattern
Section titled “Why this pattern”| Piece | Lesson |
|---|---|
| One text in / one text out | Default contract. No ports or params yet |
| Pure function | Easy to test mentally. No filesystem, no network |
Dedup with Set | Nodes are great for boring munging agents forget |
Next steps: wrap lines with a param (prefix), or fan into named ports. Or jump to a command node that shells out to sort -u.
Related
Section titled “Related”- Custom nodes
- Stdlib pack.
extract-jsonand other utilities - Tutorial: Command node
- Tutorial: Typed chain
- Params & named ports