Skip to content

🔨 chore: add headless approval and apiKey WS auth to lh agent run#13819

Merged
arvinxx merged 1 commit into
canaryfrom
feat/agent-run-headless-apikey
Apr 14, 2026
Merged

🔨 chore: add headless approval and apiKey WS auth to lh agent run#13819
arvinxx merged 1 commit into
canaryfrom
feat/agent-run-headless-apikey

Conversation

@arvinxx

@arvinxx arvinxx commented Apr 14, 2026

Copy link
Copy Markdown
Member

Summary

Two independent issues that together block lh agent run when auth'd via LOBEHUB_CLI_API_KEY:

  1. CLI didn't request headless mode — without userInterventionConfig: { approvalMode: 'headless' }, the runtime waits for human tool-call approval that never arrives in a non-interactive CLI context, so commands like Run ls ~ | grep dev in my device hang forever.
  2. WebSocket auth dropped tokenType — the auth handshake was { token, type: 'auth' }, missing the tokenType field. The agent gateway defaulted to JWT verification and rejected API keys.

Changes

  • src/server/routers/lambda/aiAgent.tsExecAgentSchema now accepts userInterventionConfig (UserInterventionConfigSchema), and the router passes it through to aiAgentService.execAgent. Same shape the web/cron paths already use (e.g. task.ts:884, AgentBridgeService.ts:731).
  • apps/cli/src/commands/agent.ts — new --no-headless opt-out flag (default is headless). Sends userInterventionConfig: { approvalMode: 'headless' } unless disabled. Reads token and tokenType from getAgentStreamAuthInfo() and forwards them to the WS stream.
  • apps/cli/src/api/http.tsgetAgentStreamAuthInfo() now also returns { token, tokenType: 'jwt' | 'apiKey' } so callers don't have to re-derive the type from header names.
  • apps/cli/src/utils/agentStream.tsWebSocketStreamOptions accepts tokenType (defaults to 'jwt'), and the auth message now includes it: { token, tokenType, type: 'auth' }. This matches what @lobechat/device-gateway-client already sends on the device-gateway WS.
  • Tests: updated existing expectation for the auth message, added a new test covering the tokenType: 'apiKey' path.

Scope notes

  • --no-headless opt-out is included for completeness. Default stays headless because an interactive CLI prompt doesn't exist yet and a missing flag was the bug in the first place.
  • Backend schema is additive and optional — older CLI clients continue to work, newer clients enable headless.
  • The agent gateway server side already knows how to verify an API key (same resolveSocketAuth pattern as device-gateway); this PR just wires up the CLI side.

Test plan

  • bunx vitest run apps/cli/src/utils/agentStream.test.ts — 14/14 green (includes new apiKey auth test)
  • bunx vitest run src/server/routers/lambda/__tests__/aiAgent.test.ts — 10/10 green
  • bun run type-check — no new errors attributable to this PR
  • Manual repro from the issue:
    lh logout
    export LOBEHUB_CLI_API_KEY='***'
    lh login --server http://localhost:3010
    lh connect --daemon --gateway http://localhost:8787
    lh agent run --slug inbox --device local --prompt 'Run ls ~ | grep dev in my device'

Fixes LOBE-6939

🤖 Generated with Claude Code

Two fixes so `lh agent run` works end-to-end against the WebSocket agent
gateway when the user is authenticated via LOBEHUB_CLI_API_KEY.

- Default to `userInterventionConfig: { approvalMode: 'headless' }` when
  running the agent from the CLI. Without this flag the runtime waits
  for human tool-call approval and local-device commands hang forever.
  Users who want interactive approval can pass `--no-headless`.
- Pass `tokenType` (`jwt` | `apiKey`) in the WebSocket auth handshake so
  the gateway knows how to verify the token. Previously the CLI sent
  only the raw token value and the gateway assumed JWT, rejecting valid
  API keys.

Fixes LOBE-6939

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Apr 14, 2026 3:14pm

Request Review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@codecov

codecov Bot commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.67%. Comparing base (7e89fa7) to head (ca839e2).
⚠️ Report is 3 commits behind head on canary.

Additional details and impacted files
@@            Coverage Diff            @@
##           canary   #13819     +/-   ##
=========================================
  Coverage   66.67%   66.67%             
=========================================
  Files        2029     2029             
  Lines      172332   172335      +3     
  Branches    17621    20153   +2532     
=========================================
+ Hits       114895   114900      +5     
+ Misses      57313    57311      -2     
  Partials      124      124             
Flag Coverage Δ
app 58.82% <100.00%> (+<0.01%) ⬆️
database 92.46% <ø> (ø)
packages/agent-runtime 79.72% <ø> (ø)
packages/context-engine 83.38% <ø> (ø)
packages/conversation-flow 92.36% <ø> (ø)
packages/file-loaders 87.02% <ø> (ø)
packages/memory-user-memory 74.74% <ø> (ø)
packages/model-bank 99.86% <ø> (ø)
packages/model-runtime 84.20% <ø> (ø)
packages/prompts 69.24% <ø> (ø)
packages/python-interpreter 92.90% <ø> (ø)
packages/ssrf-safe-fetch 0.00% <ø> (ø)
packages/utils 90.34% <ø> (ø)
packages/web-crawler 88.66% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Store 65.90% <ø> (ø)
Services 52.19% <ø> (ø)
Server 66.51% <100.00%> (+<0.01%) ⬆️
Libs 52.89% <ø> (ø)
Utils 91.12% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arvinxx arvinxx changed the title ✨ feat: add headless approval and apiKey WS auth to lh agent run 🔨 chore: add headless approval and apiKey WS auth to lh agent run Apr 14, 2026
@arvinxx arvinxx merged commit f6081c9 into canary Apr 14, 2026
30 checks passed
@arvinxx arvinxx deleted the feat/agent-run-headless-apikey branch April 14, 2026 15:28
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