lp

package
v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package lp provides web page reading via lightpanda browser with CDP.

Architecture

url(req) +------------+   wss    +---------------+ http  +-------------+
-------->|  Web       +--------->|               +------>|             |
         |  chromedp  |          |  Lightpanda   |       |  WebServer  |
<--------+            |<---------+               |<------+             |
markdown +------------+ markdown +---------------+  rep  +-------------+

The package replaces the previous approach of using Go's net/http client directly. Lightpanda provides a headless browser with CDP support, solving these problems:

  1. JavaScript-rendered pages that return empty content via HTTP
  2. Geo-restricted sites (e.g. google.com) inaccessible from local network
  3. Better HTML-to-markdown conversion via LP.getMarkdown CDP command

Remote vs Local

Lightpanda runs in two modes:

  • Local: ws://127.2.2.9:9227 (no auth, user runs lightpanda serve)
  • Remote: wss://euwest.cloud.lightpanda.io/ws (token auth, 8h/month limit)

Routing decision: if the target host is in the remoteHosts list (geo-restricted sites), use remote; otherwise use local.

Auto-start

When local lightpanda is not running, Get automatically starts it:

  1. Preferred: user service via internal/userservice - Linux: systemd user service (dscli-lightpanda.service) - macOS: LaunchAgent (dscli-lightpanda.plist) - Lifecycle independent of dscli — survives dscli process exit - Allows multiple dscli instances to share one lightpanda
  2. Fallback: child process (if user service is unavailable) - Lifecycle tied to dscli — exits when dscli exits

Config keys (~/.dscli/config.dscli):

lightpanda-local-url   = ws://127.2.2.9:9227
lightpanda-remote-url  = wss://euwest.cloud.lightpanda.io/ws
lightpanda-remote-token = <token>

Usage

import "github.com/dscli/dscli/internal/lp"

markdown, err := lp.Get(ctx, "https://example.com")

Future work

  • Web writer support (e.g. interacting with chat.deepseek.com)

Index

Constants

This section is empty.

Variables

View Source
var ErrLoginRequired = errors.New("login required — open visible browser to complete login")

ErrLoginRequired is returned when the browser is not logged in to DeepSeek. Callers should trigger a visible login flow and retry.

View Source
var ErrNoConversation = errors.New("no previous conversation — start a new one first")

ErrNoConversation is returned by WebChatContinue when no previous conversation exists to continue.

Functions

func DeepSeekLoginChrome

func DeepSeekLoginChrome(ctx context.Context, phone string, codeReader func() (string, error)) error

DeepSeekLoginChrome performs login to chat.deepseek.com using a local Chrome/Chromium browser. This is preferred over the Lightpanda-native login because Chrome properly renders the Shumei captcha widget.

func DeepSeekLoginChromeOpts

func DeepSeekLoginChromeOpts(ctx context.Context, phone string, codeReader func() (string, error), visible bool) error

DeepSeekLoginChromeOpts is like DeepSeekLoginChrome but allows disabling headless mode via the visible parameter (useful for manual captcha solving).

func DefaultCookiePath

func DefaultCookiePath() string

DefaultCookiePath returns the default path for the DeepSeek cookie file.

func Get

func Get(ctx context.Context, rawURL string) (string, error)

Get fetches a web page via lightpanda CDP and returns its markdown content.

It automatically routes to remote lightpanda for geo-restricted hosts (listed in remoteHosts), and uses local lightpanda for all other URLs. If remote is not configured, even remoteHosts fall back to local.

If local lightpanda is not running but the lightpanda command is available, Get will auto-start lightpanda serve in the background before fetching.

Config keys used (from ~/.dscli/config.dscli):

  • lightpanda-local-url (default: ws://127.2.2.9:9227)
  • lightpanda-remote-url (default: "")
  • lightpanda-remote-token (default: "")

Get fetches a web page via lightpanda CDP and returns its markdown content.

It automatically routes to remote lightpanda for geo-restricted hosts (listed in remoteHosts), and uses local lightpanda for all other URLs. If remote is not configured, even remoteHosts fall back to local.

If local lightpanda is not running but the lightpanda command is available, Get will auto-start lightpanda serve in the background before fetching.

Config keys used (from ~/.dscli/config.dscli):

  • lightpanda-local-url (default: ws://127.2.2.9:9227)
  • lightpanda-remote-url (default: "")
  • lightpanda-remote-token (default: "")

func GetRemote

func GetRemote(ctx context.Context, rawURL string) (string, error)

GetRemote fetches a web page via remote lightpanda CDP regardless of the target host. Returns an error if remote is not configured.

Unlike Get, GetRemote skips the host-based routing and local lightpanda auto-start — it always uses the configured remote endpoint.

Config keys used:

  • lightpanda-remote-url (required)
  • lightpanda-remote-token (optional)

func ReadCodeFromStdin

func ReadCodeFromStdin() (string, error)

ReadCodeFromStdin reads a verification code from stdin with a prompt. In non-interactive environments (stdin not a terminal), it falls back to polling codeFilePath every 2 seconds for up to 5 minutes.

func WebChat

func WebChat(ctx context.Context, message string) (string, error)

WebChat sends a message to chat.deepseek.com via a visible Chrome browser and returns the assistant's text response. Each call starts a **new** conversation; the conversation state is saved so it can be continued later via WebChatContinue.

It uses the same Chrome user data directory as DeepSeekLoginChromeOpts, so cookies from a prior login are automatically available. If not logged in, a visible login flow is triggered automatically in the same browser session — no separate WebChatLogin call needed.

New conversations automatically enable expert mode (V4 Pro).

Usage:

response, err := lp.WebChat(ctx, "hello")

func WebChatContinue

func WebChatContinue(ctx context.Context, message string) (string, error)

WebChatContinue sends a message continuing the last conversation saved by a previous WebChat call. The conversation state is loaded from the shared Chrome profile directory.

Returns ErrNoConversation if no previous conversation exists.

func WebChatLogin

func WebChatLogin(ctx context.Context) error

WebChatLogin opens a visible Chrome browser for manual DeepSeek login. The user completes captcha/SMS in the browser window; cookies are saved to the shared Chrome profile for subsequent WebChat calls.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL