Skip to content

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.


Settings → custom nodes → + Create node. Name it extract-urls.

Or by hand:

Terminal window
mkdir -p ~/.config/threadle/nodes/extract-urls

~/.config/threadle/nodes/extract-urls/node.json
{
"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"
}

~/.config/threadle/nodes/extract-urls/node.ts
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.


  1. Reload threadle (or wait for the nodes watcher).
  2. Palette → nodes → custom → drag Extract URLs.
  3. Wire prompt → Extract URLs → output.
  4. Put this in the prompt:
See https://example.com/a and also https://example.com/a again —
plus https://threadle.sh/docs.
  1. Press ▶ Run. The output node should show:
https://example.com/a
https://threadle.sh/docs

PieceLesson
One text in / one text outDefault contract. No ports or params yet
Pure functionEasy to test mentally. No filesystem, no network
Dedup with SetNodes 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.