Skip to content

Print button that hands labels to a local print agent - #1626

Draft
francisrath wants to merge 5 commits into
Part-DB:masterfrom
francisrath:feat/print-agent-button
Draft

francisrath wants to merge 5 commits into
Part-DB:masterfrom
francisrath:feat/print-agent-button

Conversation

@francisrath

@francisrath francisrath commented Oct 29, 2026 •

Copy link
Copy Markdown

Draft, not ready to merge. This hasn't been tested enough yet: one developer, one Brother QL, the Docker dev setup. I'm opening it to get your feedback on the approach before polishing it.

Part of #1625. This is the smallest of three alternative PRs; each one builds on the previous:

  1. This PR: a "Print" button that hands the label to a print agent on the user's computer. No database changes.
  2. Print jobs for print agents (server-side queue) #1627: Part-DB keeps a job queue that agents fetch from. Printing then works from any device, phones included.
  3. Instant print job delivery via Mercure (+ FrankenPHP Mercure 1.x fix) #1628: jobs reach the agent instantly through Mercure instead of at its next poll.

Pick whichever level you're comfortable with, or none.

What it does

  • A new page under Tools → Print agent (/label/agent) connects the current browser to a print agent. The agent's settings page links there with #url=<agent>&key=<pairing key>. The fragment never reaches the server, and the connection is kept only in this browser's local storage.
  • Once connected:
    • A Print button appears next to Download in the label generator, for saved profiles.
    • A printer icon appears next to each profile in the label menus of parts, part lots and storage locations.
  • Clicking either opens a signed URL on the agent in a new window (/v1/handoff?src&type&ids&profile&ts&sig, HMAC-SHA256 with the pairing key). The agent then fetches the PDF itself through the existing POST /api/labels/generate with its own read-only API token.

This is a top-level navigation, so it needs no CSP change and isn't affected by Chrome's local-network fetch rules. Part-DB never talks to the agent itself and stores nothing on the server.

The agent contract is documented in docs/usage/labels.md ("Printing with a print agent"). It isn't tied to one agent: any program that implements the handoff URL works. I wrote one for Brother QL printers, pdb-print (MIT).

Limitations

  • Only saved profiles can be printed; unsaved changes in the label generator are not printed.
  • If the browser blocks the popup, the Part-DB tab itself navigates to the agent.

Tests

  • tests/Controller/LabelControllerTest.php: the connect page, and the buttons with and without a profile.
  • /label/agent is added to the availability test.
  • The JS helper (id normalisation, signing) was only tested with throwaway node tests, which are not part of this PR.
  • Tested by hand: connecting the agent, and printing from the label dialog and the menu icons (Chrome, macOS, against the Docker dev setup).

Screenshots

connect connected dialog menu

🤖 Generated with Claude Code

francisrath and others added 5 commits October 28, 2026 21:47
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds a Tools entry for the print agent page and documents the agent contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bulk lot action and hand-typed ids can contain spaces, ';' or empty entries,
which agents don't have to accept. Also: lowercase pairing key, popup without
opener, per-profile labels on the menu icons, and the docs now say which bytes
form the HMAC key and how agents should check ts, replays and src.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant