Compare commits

...

353 Commits

Author SHA1 Message Date
lobehubbot 93603ae83b 🔖 chore(release): release version v2.1.51 [skip ci] 2026-04-16 15:42:58 +00:00
CanisMinor d87094236a 🚀 release: 20260416 (#13895)
# 🚀 LobeHub v2.1.50 (20260416)

**Release Date:** April 16, 2026\
**Since v2.1.49:** 107 commits · 101 merged PRs · 13 contributors

> This weekly release focuses on improving runtime stability and gateway
execution consistency, while making Home/Recents workflows faster to
navigate and easier to manage in daily use.

---

##  Highlights

- **Server-side Human Approval Flow** — Agent runtime now supports more
reliable approve/reject/reject-continue handling in gateway mode,
reducing stalled execution paths in long-running tasks. (#13829, #13863,
#13873)

- **Message Gateway End-to-End Hardening** — Gateway message flow, queue
handling, tool callback routing, and stop interruption behavior were
strengthened for better execution continuity. (#13761, #13816, #13820,
#13815)

- **Client Tool Execution in Gateway Mode** — Client-executor tools now
run more predictably across gateway and desktop callers, with improved
executor dispatch behavior. (#13792, #13790)

- **Home / Recents / Sidebar Upgrade** — Sidebar layout, custom sort,
recents operations, and profile actions were improved to reduce
navigation friction in active sessions. (#13719, #13812, #13723, #13739,
#13878, #13734)

- **Agent Workspace and Documents Expansion** — Working panel and agent
document workflows were expanded and polished for better day-to-day
agent operations. (#13766, #13857)

- **Provider and Model Compatibility Improvements** — Added GLM-5.1
support and refined model/provider edge-case handling, including schema
and error-path fixes. (#13757, #13806, #13736, #13740)

---

## 🏗️ Core Agent & Architecture

### Agent runtime and intervention lifecycle

- Added server-side human approval and improved runtime coordination
across approve/reject decision paths. (#13829, #13863)
- Improved interrupted-task handling and operation lifecycle consistency
to reduce half-finished runtime states. (#13714)
- Refined error classification and payload propagation so downstream
surfaces receive clearer actionable errors. (#13736, #13740)

### Execution model and dispatch behavior

- Introduced executor-aware runtime behavior to better separate
client/server tool execution semantics. (#13758)
- Improved tool/plugin resolution and manifest handling to avoid runtime
failures on malformed inputs. (#13856, #13840, #13807)

---

## 📱 Gateway & Platform Integrations

- Added message gateway support and strengthened queue/error behavior
for more stable cross-channel execution. (#13761, #13816, #13820)
- Improved gateway callback pipeline with protocol and API additions for
`tool_execute` / `tool_result`. (#13762, #13764, #13765)
- Improved bot/channel reliability and DM/slash handling in
Discord-related paths. (#13805, #13724)

---

## 🖥️ CLI & User Experience

- Improved CLI reliability across message/topic operations and
build/minify-related paths. (#13731, #13888)
- Added image-to-video options and improved command behavior for
generation workflows. (#13788)
- Improved desktop runtime behavior for remote fetch and Linux
notification urgency handling. (#13789, #13782)

---

## 🔧 Tooling

- Extracted gateway stream client into `@lobechat/agent-gateway-client`
to centralize protocol usage and reduce duplication. (#13866)
- Improved built-in tool coverage and runtime support, including GTD
server runtime and missing lobe-kb tools. (#13854, #13876)
- Updated skill and frontmatter consistency in workflow tooling.
(#13730)

---

## 🔒 Security & Reliability

- **Security:** Strengthened API key WS auth behavior and safer
serverUrl forwarding in gateway-related auth paths. (#13824)
- **Reliability:** Reduced runtime stalls by improving gateway
stop/interrupt and approval-state routing behavior. (#13815, #13863,
#13873)
- **Reliability:** Added defensive guards for malformed tool manifests
and non-string content edge cases. (#13856, #13753)

---

## 👥 Contributors

**101 merged PRs** from **13 contributors** across **107 commits**.

### Community Contributors

- @arvinxx - Runtime, gateway, and execution reliability improvements
- @Innei - Navigation, workflow UX, and desktop/CLI refinements
- @rdmclin2 - Sidebar, recents, and channel behavior updates
- @ONLY-yours - Tooling/runtime fixes and model execution compatibility
- @tjx666 - Model support and release/tooling maintenance
- @nekomeowww - Memory and search-path stability fixes
- @cy948 - CLI indexing and command flow fixes
- @octo-patch - Local system runtime edge-case fixes
- @djthread - Desktop runtime request reliability improvements
- @rivertwilight - Documentation and changelog updates
- @sudongyuer - Subscription/mobile support improvements
- @Zhouguanyang - Provider/model configuration correctness fixes
- @lobehubbot - Translation and maintenance automation support

---

**Full Changelog**: v2.1.49...v2.1.50
2026-04-16 23:40:02 +08:00
CanisMinor 549735be7f 📝 docs: Update changelog docs and release skills (#13897)
* 🔨 chore: update .vscode/settings.json (#13894)

* 🐛 fix(builtin-tool-local-system): honor glob scope in local system tool (#13875)

Made-with: Cursor

* 📝 docs: Update changelog docs and release skills (#13897)

- Update changelog documentation format across all historical changelog files
- Merge release-changelog-style skill into version-release skill
- Update changelog examples with improved formatting and structure

Made-with: Cursor

---------

Co-authored-by: YuTengjing <ytj2713151713@gmail.com>
Co-authored-by: Innei <i@innei.in>
2026-04-16 22:24:48 +08:00
lobehubbot 282415b886 🔖 chore(release): release version v2.1.50 [skip ci] 2026-04-16 11:29:10 +00:00
lobehubbot 94b6827580 Merge remote-tracking branch 'origin/main' into canary 2026-04-16 11:27:19 +00:00
Innei c1174d3eb8 👷 build(database): add document history schema (#13789)
#### 💻 Change Type

- [ ]  feat
- [ ] 🐛 fix
- [ ] ♻️ refactor
- [ ] 💄 style
- [x] 👷 build
- [ ] ️ perf
- [ ]  test
- [ ] 📝 docs
- [ ] 🔨 chore

#### 🔗 Related Issue

- None

#### 🔀 Description of Change

- Extract the document history database changes from the feature branch
onto a branch based on main.
- Add the document history migration, schema, relations, model, and
database tests only.
- Exclude UI, router, and service-layer changes so the PR stays focused
on the database layer.

#### 🧪 How to Test

- Run: cd packages/database && bunx vitest run --silent=passed-only
src/models/__tests__/document.test.ts
src/models/__tests__/documentHistory.test.ts
- [x] Tested locally
- [x] Added or updated tests
- [ ] No tests needed

#### 📸 Screenshots / Videos

| Before | After |
| ------ | ----- |
| N/A | N/A |

#### 📝 Additional Information

- This PR intentionally targets main because the database migration
needs to land on the release branch first.
2026-04-16 19:26:37 +08:00
Arvin Xu cb4ad01135 🐛 fix: fix minify cli (#13888)
* update

* update

* 🔧 chore: update CLI build command in electron-builder and ensure proper newline in package.json

* Changed the CLI build command from 'npm run build' to 'npm run build:cli' in electron-builder.mjs.
* Added a newline at the end of package.json for consistency.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
Co-authored-by: Innei <tukon479@gmail.com>
2026-04-16 18:39:18 +08:00
Rdmclin2 2cfcd4a75f 🔨 chore: add ENABLE_BOT_IN_DEV swtich (#13883)
* chore: add  ENABLE_BOT_IN_DEV swtich

* chore: add explicit judge
2026-04-16 17:47:31 +08:00
LiJian 843248fb77 🐛 fix: add some lost lobe-kb builtin tools (#13876)
* feat: add some lost lobe-kb builtin tools

* feat: add the list files and get file detail

* feat: add the list files and get file detail

* fix: update the search limit
2026-04-16 17:08:22 +08:00
Arvin Xu 1476cd86ee ♻️ refactor: add backgroundColor to TaskParticipant and rename name to title (#13877)
* ♻️ refactor: add backgroundColor to TaskParticipant and rename name to title

Add backgroundColor field and rename name→title in TaskParticipant interface
to match agent avatar data. Add LobeAI fallback for inbox agent in
getAgentAvatarsByIds when avatar/title are missing.
2026-04-16 17:06:51 +08:00
Innei 7c8f721d6d 💾 chore(database): sync document history schema indexes 2026-04-16 16:48:15 +08:00
Rdmclin2 85227cf467 🐛 fix: recent delete (#13878)
* chore: update skills dir

* chore: remove unused recent fetch actions and components

* fix: recent delete functions

* chore: update comments
2026-04-16 16:42:50 +08:00
Innei d526b40b78 🐛 fix(deps): pin @react-pdf/image to 3.0.4 to avoid privatized @react-pdf/svg
Picked from canary commit 9f61b58a29.
- Bump @react-pdf/renderer from ^4.3.2 to 4.4.1
- Pin @react-pdf/image to 3.0.4 via pnpm.overrides
2026-04-16 15:01:49 +08:00
Innei a7339bea13 🌐 chore(locale): update page editor placeholder to new AI command prompt (#13872)
Update `pageEditor.editorPlaceholder` from `Start writing your page. Press / to open the command menu` to `Press "/" for AI and commands.` across all supported locales and the default locale source.
2026-04-16 14:41:07 +08:00
Arvin Xu ab05020f62 🐛 fix: default execAgent approval mode to headless (#13873)
* 🐛 fix: default execAgent approval mode to headless

Backend execAgent calls should run headlessly by default since only
frontend scenarios require manual human approval. This prevents cron
jobs and other server-side triggers from unexpectedly waiting for
human intervention.

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

*  test: add regression test for headless approval default

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:05:53 +08:00
Arvin Xu 4203e32dc7 ♻️ refactor: createAgent uses agentModel.create directly (#13871)
* ♻️ refactor: createAgent uses agentModel.create directly

The createAgent router was still going through sessionModel.create,
which is a legacy path that doesn't pass all agent fields (like
agencyConfig) to the agents table. Switch to agentModel.create
which directly inserts into the agents table with full field support.

- Add CreateAgentSchema in types package for proper input validation
- Remove dependency on insertAgentSchema from database package
- Remove sessionId from CreateAgentResult

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

* 🏷️ chore: mark session-based agent creation as deprecated

Add @deprecated JSDoc tags to the legacy session-based agent creation
path (session router, SessionService, SessionModel.create, session store,
insertAgentSchema). New code should use agent.createAgent / agentModel.create
directly.

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

* 🐛 fix: honor groupId when creating agents

Pass input.groupId as sessionGroupId to agentModel.create so that
agents created from a sidebar folder are correctly assigned to that group.

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

* 🐛 fix: resolve type errors from createAgent refactor

- Remove sessionId fallback in AddAgent.tsx and ForkAndChat.tsx
- Use z.custom<T>() for agencyConfig and tts in CreateAgentSchema
  to match agentModel.create parameter types

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:10:13 +08:00
LobeHub Bot 9583de88e3 🌐 chore: translate non-English comments to English in desktop-controller-tests (#13867)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-16 12:02:18 +08:00
LiJian 0699a0b5ce 🐛 fix: improve the skill execution error body back (#13868)
fix: improve the skill execution error body back
2026-04-16 11:43:01 +08:00
Arvin Xu dd81642d83 ♻️ refactor: extract agent-stream into @lobechat/agent-gateway-client package (#13866)
* ♻️ refactor: extract agent-stream into @lobechat/agent-gateway-client package

Move the Agent Gateway WebSocket client from src/libs/agent-stream/ into
a standalone workspace package at packages/agent-gateway-client/. This
eliminates the duplicate AgentStreamEvent type in apps/cli and provides
a single source of truth for the Gateway WS protocol types shared by
SPA, server, and CLI consumers.

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

* add agent-gateway-client

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 11:25:32 +08:00
Arvin Xu f6c70210f2 ♻️ refactor(chat): remove reject-only button, unify to rejected_continue (#13865)
* ♻️ refactor(chat): remove reject-only button, unify to rejected_continue

Server-side `decision='rejected'` and `decision='rejected_continue'`
share the exact same code path — both surface the rejection to the
LLM as user feedback. Having a separate "reject only" button added UI
complexity without behavioural difference.

- Remove the "仅拒绝" button from InterventionBar popover; the single
  "拒绝" button now calls `rejectAndContinueToolCall` directly
- `rejectToolCalling` Gateway branch sends `rejected_continue` instead
  of `rejected` so all rejection paths use one decision value

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

* Update ApprovalActions.tsx

*  feat(tool): add executors field to BuiltinToolManifest and dispatch page-agent to client

Add `executors?: ('client' | 'server')[]` to `BuiltinToolManifest` so
each builtin tool declares where it can run. The server-side dispatch
logic in `aiAgent/index.ts` now reads this field instead of hardcoding
per-identifier checks.

- `lobe-local-system`: `executors: ['client', 'server']` — runs on
  client via Electron IPC or server via Remote Device proxy
- `lobe-page-agent`: `executors: ['client']` — requires EditorRuntime,
  client-only
- Stdio MCP plugins still use the `customParams.mcp.type` heuristic
  (not manifest-driven)

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 10:45:17 +08:00
Arvin Xu 8109bbbbc3 🐛 fix(gateway): route approve/reject via lab flag (#13863)
🐛 fix(gateway): route approve/reject via lab flag, not transient server op state

After the coordinator fix for `waiting_for_human` (#13860) the paused
`execServerAgentRuntime` op is marked `completed` client-side as soon
as the server emits `agent_runtime_end`. `startOperation` then runs
`cleanupCompletedOperations(30_000)`, which deletes any op completed
more than 30 seconds ago — so by the time the user sees the
InterventionBar and clicks approve/reject, the running (or recently
completed) server op is gone.

The previous `#hasRunningServerOp` check therefore kept returning
false against a live Gateway backend, flipping approve/reject into
the client-mode `internal_execAgentRuntime` branch and stranding the
server-side paused conversation.

Switch the helper to `#shouldUseGatewayResume`, which checks the same
`isGatewayModeEnabled()` lab flag used to route the initial send. The
signal now mirrors how the conversation was dispatched and survives
the op-cleanup window.

New regression test exercises the post-coordinator-fix state: the
paused `execServerAgentRuntime` op is explicitly `completed` before
the approve call runs, and we still expect the Gateway branch to
fire with `decision='approved'`.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 09:26:22 +08:00
Arvin Xu 1005f442d6 🐛 fix(gateway): clean up paused server op after human approve/reject (#13860)
* 🐛 fix(gateway): clean up paused server op after human approve/reject

In Gateway mode with userInterventionConfig.approvalMode='ask', the
paused execServerAgentRuntime op was never released — the loading
spinner kept spinning after the user approved, rejected, or
reject-and-continued, and reject-only silently did nothing on the
server.

- ToolAction.rejectToolCall now delegates to chatStore.rejectToolCalling
  so the Gateway resume op actually fires with decision='rejected';
  previously it only mutated local intervention state and the server's
  paused op waited forever.
- AgentRuntimeCoordinator treats waiting_for_human as end-of-stream so
  the coordinator emits agent_runtime_end when request_human_approve
  flips state, letting the client close the paused op via the normal
  terminal-event path.
- conversationControl adds #completeRunningServerOps as a fallback
  guard in the approve/reject/reject-continue Gateway branches — if
  the server-side signal is delayed or missing, the client still clears
  the orphan op before starting the resume op.

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

* 🐛 fix(gateway): defer paused-op cleanup until resume starts successfully

If `executeGatewayAgent` failed (transient network/auth/server error),
the paused `execServerAgentRuntime` op was already marked completed
locally by the pre-call `#completeRunningServerOps`. Retries would
then see no running server op, miss `#hasRunningServerOp`, and fall
through to the non-Gateway client-mode path — while the backend was
still paused awaiting human input.

Snapshot the paused op IDs before the resume call and retire them
only inside the try block after `executeGatewayAgent` resolves. On
failure the running marker stays intact so a retry still lands on
the Gateway branch and can re-issue the resume.

The helper was renamed from `#completeRunningServerOps(context)` to
`#completeOpsById(ids)` to reflect the new contract: callers must
snapshot beforehand, not re-query at completion time (which would
incorrectly match the new resume op too).

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

* 🐛 fix(gateway): avoid double reject dispatch in reject-and-continue

Now that `rejectToolCall` delegates to `chatStore.rejectToolCalling`,
the chained `await get().rejectToolCall(...)` inside
`rejectAndContinueToolCall` fired a full halting reject before the
continue call. In Gateway mode that meant two resume ops on the same
tool_call_id (`decision='rejected'` followed by
`decision='rejected_continue'`) racing server-side; in client mode it
duplicated reject bookkeeping that `chatStore.rejectAndContinueToolCalling`
already handles internally.

Drop the chained call and fire `onToolRejected` inline so hook
semantics are preserved. `chatStore.rejectAndContinueToolCalling` is
now the single entry point for both the rejection persist and the
continue dispatch.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 01:43:00 +08:00
Arvin Xu 2cf65e9fb3 💄 style: agent documents (#13857)
* improve style

* improve style
2026-04-16 01:05:27 +08:00
Arvin Xu 6636b35188 🐛 fix: drop manifests missing api before feeding ToolsEngine (#13856)
🐛 fix(toolEngineering): drop manifests missing `api` before feeding ToolsEngine

`ToolsEngine.convertManifestsToTools` calls `manifest.api.map(...)`
without a null check, so any manifest that is truthy but lacks a valid
`api` array crashes the entire tools build with "Cannot read properties
of undefined (reading 'map')". This takes down anything that touches
the tools pipeline on that agent — including TokenTag in ChatInput,
which is why users see the crash on the chat page load path.

Manifests are merged from 5 sources (installed plugins, builtin tools,
Klavis, LobeHub skills, caller-supplied extras), only some of which
filter falsy entries, and none validate `api`. Guard defensively at
the merge point and log the offending source + identifier so the
underlying bad data can be traced.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 01:04:55 +08:00
Arvin Xu 8475bc11fc 🐛 fix(builtin-tool-gtd): add server runtime for GTD tool (#13854)
*  feat(builtin-tool-gtd): add server runtime for GTD tool

Implement server-side execution runtime so the GTD tool works when
agents run in a pure server context (bot platforms, async task workers,
QStash workflows). Previously only the client executor existed, which
relied on `useNotebookStore` and `notebookService` and would break on
the server.

- `packages/builtin-tool-gtd/src/ExecutionRuntime/index.ts`: pure
  `GTDExecutionRuntime` class with an injected service interface,
  covering createPlan/updatePlan/createTodos/updateTodos/clearTodos
  and execTask/execTasks. Since server runtime has no stepContext,
  todo state is read from / written back to the Plan document's
  `metadata.todos` field.
- `src/server/services/toolExecution/serverRuntimes/gtd.ts`: factory
  wiring `DocumentModel` + `TopicDocumentModel` into the runtime and
  registering under `GTDIdentifier`.

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

* ♻️ refactor(builtin-tool-gtd): share runtime logic between executor and server

Make the client executor a thin adapter over `GTDExecutionRuntime` so
all processing logic (todo reducer, plan CRUD flow, execTask state
builder, output formatting) lives in one place. Previously the server
runtime was a near-duplicate of the client executor.

- Expand `GTDRuntimeContext` with `currentTodos`, `messageId`, `signal`
  so both callers can thread their environment through:
  - client supplies `currentTodos` from stepContext / pluginState via
    `getTodosFromContext`, and `messageId` for execTask parentMessageId
  - server lets the runtime resolve todos from the plan document's
    metadata when `currentTodos` is not supplied
- Split service surface into `updatePlan` (user-facing: goal / desc /
  context — client routes through `useNotebookStore` to refresh SWR)
  vs `updatePlanMetadata` (silent todos sync — client stays on the
  raw `notebookService`)
- Runtime methods now return `BuiltinToolResult` (superset of
  `BuiltinServerRuntimeOutput`), so `stop: true` on execTask /
  execTasks is typed cleanly without `@ts-expect-error`

Net effect: `executor/index.ts` shrinks from 510 → 134 lines; the
server factory just maps models to the service interface.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 00:04:48 +08:00
LobeHub Bot 3bb4fd6046 🌐 chore: translate non-English comments to English in lambda-router-tests (#13838)
🌐 chore: translate non-English comments to English in lambda router tests

Translated all Chinese/CJK comments to English in 6 test files under
src/server/routers/lambda/__tests__/. Code logic and string literals
are unchanged; only explanatory comments were translated.

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-15 23:59:08 +08:00
Arvin Xu 9608494b0a 💄 style(chat): tighten execServerAgentRuntime loading copy (#13855)
💄 style(chat): tighten `execServerAgentRuntime` loading copy

Current text was trying to do too much in one line — status + two
separate user affordances — and read as an explanation, not a status.
Replaces it with a status-first line that mentions where the work is
happening and the single reassurance users actually need.

- EN: "Task is running in the server. You are safe to leave this page."
- zh-CN: "任务正在服务器运行,您可以放心离开此页面。"

Only en-US and zh-CN are edited; CI translates the rest from the
default file.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 23:42:37 +08:00
Innei bc7b798dbb 🐛 fix(conversation): improve workflow display when user intervention is pending (#13847)
* 🐛 fix(conversation): improve workflow display when user intervention is pending

Made-with: Cursor

* 🐛 fix(builtin-tool-activator): add ActivatedToolInfo typing to requestedTools for tsgo compat

requestedTools was inferred as `{ identifier, name }[]` which lacks the
`avatar` property required by `ActivatedToolInfo`, causing tsgo errors.
2026-04-15 23:30:34 +08:00
Arvin Xu 986bd2f7ec 🐛 fix(agent-runtime): fetch tool plugin from message_plugins for resumeApproval (#13852)
`messageModel.findById(parentMessageId)` only returns the row from the
`messages` table — the tool-call metadata (identifier / apiName /
arguments / type / toolCallId) lives in the separate `message_plugins`
table. The resumeApproval path was reading `(resumeParentMessage as any).plugin`
and `(resumeParentMessage as any).tool_call_id`, both always undefined,
which meant:

- Approved tool calls were dispatched with `identifier: undefined`,
  causing the server-side tool executor to throw
  `Builtin tool "undefined" is not implemented`. The follow-up LLM
  step could still describe success (it sees the user prompt + picks
  plausible output) but the tool message content is permanently the
  error string.
- The toolCallId mismatch guard was silently disabled because the
  stored value was always null → validation always passed regardless
  of what the client sent.

Fix: query `messagePlugins.findFirst` by message id, use the fetched
row for both the toolCallId equality check and the approvedToolCall
payload that the runtime dispatches.

Tests:
- Mock `db.query.messagePlugins.findFirst` with the plugin fields so
  existing asserts on `approvedToolCall.identifier`/`apiName` pass
  against real values.
- Move `tool_call_id` / identifier / apiName / arguments / type out of
  the mock `messages` row fixture into a separate `pendingToolPlugin`
  fixture that mirrors the actual DB layout.
- Flip the "toolCallId mismatch" guard test to mutate the plugin mock
  (not the message mock) — this is exactly the class of bug the fetch
  guards against, so the test would have masked it before.
- New guard test: throw when `messagePlugins.findFirst` returns
  undefined (stale message id, wrong user, etc.).

Discovered during E2E verification of LOBE-7152 approve flow — the
approve decision was flipping to the new op correctly but every tool
execution was failing with the "undefined" error.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 22:53:50 +08:00
Arvin Xu 843cb8f30b 🔨 chore: wire server-mode human approval through conversationControl (#13830)
 feat(chat): server-mode human approval via new Gateway op + resumeApproval

When the current agent runtime is Gateway-mode (execServerAgentRuntime),
approve / reject / reject_continue now start a **new** Gateway op carrying
a `resumeApproval` decision instead of resuming the paused op in place
over tRPC — mirroring the "interrupt + new op" pattern from LOBE-7142
(stop/interrupt). This sidesteps the stepIndex / executeStep early-exit
race that was blocking the in-place resume path and matches the Linear
spec for LOBE-7152. Client mode is unchanged.

### Client

- `conversationControl.ts`
  - `approveToolCalling` / `rejectToolCalling` / `rejectAndContinueToolCalling`:
    server-mode branch calls `executeGatewayAgent({ message: '',
    parentMessageId: toolMessageId, resumeApproval: { decision, ... } })`.
    The local runtime never spins up; the new op's `agent_runtime_end`
    clears loading.
  - `#hasRunningServerOp` replaces the old `#getServerOperationId` helper
    (we no longer need the paused op's id). Forwards scope/groupId/
    subAgentId from `ConversationContext` into the operation lookup so
    group/thread conversations correctly resolve their running server op
    — `operationsByContext` is keyed on the full `messageMapKey`.
- `gateway.ts` — `executeGatewayAgent` takes an optional `resumeApproval`
  and forwards it to `aiAgentService.execAgentTask`.
- `services/aiAgent.ts` — `ExecAgentTaskParams.resumeApproval` with new
  `ResumeApprovalParam` shape (decision + parentMessageId + toolCallId
  + optional rejectionReason).
- `gatewayEventHandler.ts` — kept the `toolMessageIds` branch that fetches
  pending tool messages on `tools_calling`.
- `services/agentRuntime/{type,index}.ts` — removed the short-lived
  `toolMessageId` / `reject_continue` additions; this flow no longer
  routes through `processHumanIntervention`.
- `store/chat/slices/operation/selectors.ts` — `getOperationsByContext` /
  `hasRunningOperationByContext` now take `MessageMapKeyInput` so scope/
  group/subAgent fields are honoured end-to-end.

### Server

- `ExecAgentSchema` / `InternalExecAgentParams.resumeApproval` — optional
  `{ decision, parentMessageId, rejectionReason?, toolCallId }`.
- `AiAgentService.execAgent`
  - `resumeApproval` implies resume semantics (skip user-message creation,
    reuse `parentMessageId` as the target tool message). Folded into a
    single `effectiveResume` flag so the existing resume branches apply.
  - Validates parent is a `role='tool'` message whose `tool_call_id`
    matches the request — guards stale / double-clicks.
  - Writes the decision to DB before `historyMessages` is fetched so the
    runtime sees the updated tool message on the first step:
    * `approved` → `intervention: { status: 'approved' }`
    * `rejected` / `rejected_continue` → tool content =
      "User reject this tool calling [with reason: X]",
      `intervention: { status: 'rejected', rejectedReason }`.
  - Branches initial runtime context:
    * `approved` → `phase: 'human_approved_tool'` + `approvedToolCall`
      payload rebuilt from the tool message plugin → runtime executes
      the tool.
    * `rejected` / `rejected_continue` → `phase: 'user_input'` with
      empty content → LLM re-reads history (now including the rejected
      tool) and responds. Both decisions share this path: the client
      split is only about optimistic writes and button UX; once the
      rejection is persisted there's nothing meaningful to differentiate
      server-side.

### Tests

- `conversationControl.test.ts` — rewrote the three server-mode blocks
  to spy `executeGatewayAgent` and assert the `resumeApproval` payload
  shape. Added a regression test covering group-scope lookup so dropping
  scope/groupId from `#hasRunningServerOp` breaks the suite.
- `execAgent.resumeApproval.test.ts` (new) — covers approved and the
  unified rejected branches (parameterized), the no-reason fallback, and
  the role/tool_call_id validation guards.

Relates to LOBE-7152.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 21:17:22 +08:00
Arvin Xu 75626de0b3 🐛 fix: forward serverUrl in WS auth for apiKey verification (#13824)
* 🐛 fix: forward serverUrl in WS auth for apiKey verification

The agent gateway verifies an apiKey by calling
\`\${serverUrl}/api/v1/users/me\` with the token, so \`serverUrl\` has to be
part of the WebSocket auth handshake. The device-gateway-client already
does this; \`lh agent run\` was missing it, producing
"Gateway auth failed: Missing serverUrl for apiKey auth".

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

* 🔨 chore: bump cli to 0.0.7

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 21:16:11 +08:00
Innei ad634daf32 🧹 chore(onboarding): remove builtin-agent-onboarding and consolidate prompts (#13825)
* 🧹 chore: remove builtin-agent-onboarding and consolidate web onboarding

- Merge agent system role into builtin-agents; colocate toolSystemPrompt in builtin-tool-web-onboarding
- Drop unused QuestionRenderer client bundle
- Gate onboarding footer switch/skip on AGENT_ONBOARDING_ENABLED for agent route

Made-with: Cursor

* 🧪 test: fix onboarding layout translation mock

* 🧪 test: align onboarding layout test with feature flag

* 🧪 test: type onboarding business const mock
2026-04-15 20:40:37 +08:00
Arvin Xu f99935e992 🐛 fix(agent-runtime): carry persisted assistant id into state.messages (#13841)
When `call_llm` pushed the assistant turn into `state.messages`, it
dropped the DB id even though the row was already persisted. The
downstream `request_human_approve` executor filters parent lookup on
`m.role === 'assistant' && m.id`, and the DB fallback query is not
reliably finding the just-written row on every topology — so when
human-approve fires on the fresh LLM turn the op errors out with
"No assistant message found as parent for pending tool messages".

Attach `assistantMessageItem.id` to the pushed message so the existing
in-memory lookup hits, and nextContext's `parentMessageId` and
`state.messages` agree on a single source of truth.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 20:02:40 +08:00
Neko 632a6383f0 feat(app): working panel, and many agent document feat (#13766) 2026-04-15 19:18:24 +08:00
LiJian 15fcce97c9 ♻️ refactor: add more tools in lobe-agent-manangerment(modify、update、delete) (#13842)
* feat: add more tools in lobe-agent-manangerment

* feat: add the ensureAgentLoaded to modify it

* feat: add the update prompt tools
2026-04-15 17:57:05 +08:00
Neko e5be1801a1 🐛 fix(userMemories,database): bm25 should escape more characters like < and > (#13843) 2026-04-15 17:30:32 +08:00
Innei 64fc6d4bbd feat(database): add document history table and update related models
- Introduced a new `document_histories` table to track changes made to documents, including fields for `editor_data`, `save_source`, and `saved_at`.
- Updated foreign key relationships to link `document_histories` with `documents` and `users`.
- Modified existing models and tests to accommodate the new document history functionality, including changes to pagination and retrieval methods.
- Removed the versioning system from documents in favor of a more flexible history tracking approach.

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-15 14:39:37 +08:00
LiJian 524e07540c 🐛 fix: update the builtin lobehub skill manifest (#13840)
* fix: update the lobehub skill manifest

* fix: remove the no use code

* fix: update the test
2026-04-15 13:24:57 +08:00
Arvin Xu 9f61b58a29 feat(agent-runtime): server-side human approval flow (#13829)
*  feat(agent-runtime): implement server-side human approval flow

Port the client-mode human approval executors (request_human_approve,
call_tool resumption, handleHumanIntervention) to the server agent
runtime so that execServerAgentRuntime can correctly pause on
waiting_for_human and resume on approve / reject / reject_continue.

- request_human_approve now creates one `role='tool'` message per pending
  tool call with `pluginIntervention: { status: 'pending' }` and ships
  the `{ toolCallId → toolMessageId }` mapping on the `tools_calling`
  stream chunk.
- call_tool gains a `skipCreateToolMessage` branch that updates the
  pre-existing tool message in-place (prevents duplicate rows / parent_id
  FK violations that show up as LOBE-7154 errors).
- AgentRuntimeService.handleHumanIntervention implements all three
  paths: approve → `phase: 'human_approved_tool'`; reject → interrupted
  with `reason: 'human_rejected'`; reject_continue → `phase: 'user_input'`.
- ProcessHumanIntervention schema carries `toolMessageId` and a new
  `reject_continue` action; schema remains permissive (handler no-ops on
  missing toolMessageId) to keep legacy callers working.

Fixes LOBE-7151

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

* 🐛 fix(agent-runtime): address LOBE-7151 review (P1 reject_continue, P2 duplicate tool msg)

P1 — reject_continue with remaining pending tools must NOT resume the LLM.
Previously `handleHumanIntervention` kept `status='waiting_for_human'` but
returned `nextContext: { phase: 'user_input' }`, which `executeStep` would
hand to `runtime.step` immediately, breaking batch semantics. Now when
other tools are still pending, the rejection is persisted but no context
is returned; the `user_input` continuation only fires when this is the
last pending tool.

P2 — request_human_approve was pushing an empty placeholder
`{ role: 'tool', tool_call_id, content: '' }` into `newState.messages`
to "reflect" the newly-created pending DB row. On resume, the `call_tool`
skip-create path appends the real tool result, leaving two entries for
the same `tool_call_id` in runtime state. The downstream short-circuit
(`phase=human_approved_tool` → `call_tool`) doesn't consult
state.messages, so the placeholder was unused cost. Removed.

Also fixes a TS 2339 in the skipCreateToolMessage test where
`nextContext.payload` is typed `{}` and needed an explicit cast.

Tests: 99 pass (82 RuntimeExecutors + 17 handleHumanIntervention), type-check clean.
Verified end-to-end via the human-approval eval — it now exercises a
multi-turn retry path (LLM calls the gated tool twice) and both
approvals resolve cleanly through to `completionReason=done`.

Relates to LOBE-7151

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

* pin @react-pdf/renderer

* 🐛 fix(deps): pin @react-pdf/image to 3.0.4 to avoid privatized @react-pdf/svg

@react-pdf/image@3.1.0 (auto-resolved via layout@4.6.0 ← renderer@4.4.1)
declares `@react-pdf/svg@^1.1.0` as a dependency, but the svg package was
unpublished/made private on npm (returns 404). CI installs blow up with
ERR_PNPM_FETCH_404.

Upstream issue: https://github.com/diegomura/react-pdf/issues/3377

Pin image to 3.0.4 (the last release before the broken svg dep was
introduced) via pnpm.overrides until react-pdf publishes a fix.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:07:06 +08:00
Arvin Xu f12cf8f2ea 🐛 fix: fail fast when tool/assistant message persist hits a missing parent (#13828)
* 🐛 fix: fail fast when tool/assistant message persist hits a missing parent

When a conversation parent was deleted mid-operation (LOBE-7154), the
runtime was silently swallowing the parent_id FK violation in three tool
persist paths and continuing with a stale parentMessageId. The next LLM
call hit the same FK without context, surfacing as a raw SQL error to
the user after burning several LLM + tool call round trips.

Changes

- packages/types: add AgentRuntimeErrorType.ConversationParentMissing
- new messagePersistErrors.ts helper: FK detection + structured error
  constructor + persist-fatal marker (keeps RuntimeExecutors smaller)
- RuntimeExecutors:
  - call_tool: publish error event + re-throw on persist failure;
    outer catch propagates when persist-fatal
  - call_tools_batch: same, mark so the per-tool outer catch doesn't
    swallow and fall back to the already-deleted parent
  - resolve_aborted_tools: same pattern
  - call_llm: preflight parent existence via findById so we fail before
    the LLM call instead of after
- tests: replace old swallow-on-fail expectations, add LOBE-7158 cases
  for each executor plus focused unit tests for the helper module

Fixes LOBE-7158

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

* 💄 chore: publish normalized ConversationParentMissing on persist failure

Review feedback on LOBE-7158: the three persist catches were emitting
the raw DB exception as a stream `error` event before normalizing it.
Clients treat `error` events as terminal and surface `event.data.error`
directly, so the raw SQL text leaked to users and ended the stream
before the typed `ConversationParentMissing` throw could propagate.

Move normalization ahead of the publish in call_tool, call_tools_batch,
and resolve_aborted_tools so the stream event always carries the
intended business error. Add a regression assertion on the
call_tool FK test that the error event's `errorType` is
`ConversationParentMissing` and no `Failed query` text leaks through.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 09:27:01 +08:00
Arvin Xu 1a98e1b5aa 💄 style(nav-panel): remove nav panel content switch animation (#13814)
Drop the `motion/react` slide + fade transition on NavPanel content
switches (e.g. navigating from `/` to `/agent`). The new content now
renders directly without the 0.28s x-translate animation.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 01:10:37 +08:00
Innei b4fc85b57b 💄 style(proxy-settings): sticky pill SaveBar + instant enable toggle (#13821)
* 🔖 chore(release): release version v2.1.49 [skip ci]

* 💄 style(proxy-settings): sticky pill SaveBar + instant enable toggle

- Split enableProxy into instant-apply (no save required)
- Floating pill SaveBar fixed bottom-center, visible only when dirty
- Test connection feedback moved to toast (@lobehub/ui)
- Refresh style guidance: prefer createStaticStyles + cssVar

Fixes LOBE-7071

* 🐛 fix(proxy-settings): rollback enable toggle on save failure, preserve in-progress edits

---------

Co-authored-by: lobehubbot <i@lobehub.com>
2026-04-15 00:05:00 +08:00
Rdmclin2 fd0d846975 feat: support layout custom sort and fix copy (#13812)
* fix: menu locale keys

* feat: support resort sidebar

* feat: add lock to middle messages

* feat: add memory menu and default hidden

* fix: lint error

* fix: legacy secion order

* chore: add test cases

* chore: remove top zone

* feat: custom sidebar reorder

* chore: fix sidebar items
2026-04-14 23:49:47 +08:00
Arvin Xu 41efd16bba 🔨 chore: update cli version (#13822)
update cli version
2026-04-14 23:37:28 +08:00
Arvin Xu f6081c9914 🔨 chore: add headless approval and apiKey WS auth to lh agent run (#13819)
 feat: add headless approval and apiKey ws auth to `lh agent run`

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>
2026-04-14 23:28:01 +08:00
Arvin Xu d6f11f80b6 🐛 fix(agent-runtime): harden classifyLLMError so it never masks the original provider error (#13774)
* 🐛 fix(agent-runtime): harden classifyLLMError so it never masks the original provider error

Production traces across multiple providers (openrouter, openai, google)
surface a single opaque error — `e.trim is not a function` with
`errorType: 'unknown'` — hiding whatever the upstream actually returned.

Root cause: `normalizeCode` / `normalizeErrorType` assumed their input is
always `string | undefined` (matching the TypeScript signature), but real
provider error objects frequently carry a numeric `code` (HTTP status) or
a structured object in `errorType`. `value?.trim()` short-circuits only
on null/undefined, so a truthy non-string turns into a TypeError that
the outer catch records as the "final" error, erasing the upstream one.

Fixes:
- Guard `normalizeCode` / `normalizeErrorType` on `typeof value ===
  'string'`, widen parameter type to `unknown`.
- Wrap the whole `classifyLLMError` in a try/catch that falls back to a
  conservative `stop` decision and preserves the best-effort message of
  the ORIGINAL error. A classifier that throws is worse than a
  classifier that's wrong — it must never shadow the real failure.
- `bestEffortMessage` swallows property-access errors (hostile Proxy
  etc.) to guarantee the fallback itself can't throw.

Regression tests cover: numeric `code`, structured `errorType`, nested
OpenAI-SDK-shaped `error.error.code`, and a hostile Proxy that throws on
every property access.

This is a forcing function for root-cause diagnosis: after this lands,
the real upstream errors behind the 'e.trim' mask will finally surface.

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

* Remove fallback warning in classifyLLMError

Removed console warning for classification failure.

* 🐛 fix(agent-runtime): treat numeric provider code as status fallback

Bare HTTP proxies sometimes surface the HTTP status ONLY as a numeric `code`
on the error object (no `status`/`statusCode`, no digits in the message).
After widening `normalizeCode` to require `typeof === 'string'`, those numeric
codes were dropped entirely and auth/permission failures fell through to
retry — wasting the full retry budget on permanent errors.

Forward numeric `raw.code` / `nested?.code` / `nestedError?.code` into the
status chain (after the real status/statusCode lookups, before the
message-digit extractor) so classifyKind still maps 401/403 → stop and
429/5xx → retry.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 23:23:21 +08:00
Rdmclin2 1c75686b70 🐛 fix: gateway typing error (#13820)
fix: gateway typing error
2026-04-14 23:15:41 +08:00
Arvin Xu 7e89fa782d 🐛 fix: detect truncated tool_calls arguments in builtin tools (#13817)
* 🐛 fix: detect truncated tool_call arguments in builtin tools

When an LLM hits max_tokens mid tool_call, the arguments JSON is
truncated. The previous flow passed `{}` to the tool, which returned a
generic "required field missing" error; the model re-tried with the same
payload and the truncation repeated — one observed trace burned 17 min
and $2.46 on 5 blind retries.

Detect structural truncation (unclosed braces/brackets/strings) in
BuiltinToolsExecutor before schema validation, and return a dedicated
TRUNCATED_ARGUMENTS error telling the model to reduce payload size or
raise max_tokens instead of retrying.

Fixes LOBE-7148

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

* 💄 chore: echo raw arguments string and reject all unparseable JSON

Two improvements based on review:

- Append the received arguments string to the error content so the model
  can verify the payload is exactly what it produced (stops it from
  blaming upstream or guessing what went wrong).
- Treat ANY unparseable non-empty argsStr as an error (new code
  INVALID_JSON_ARGUMENTS), not just truncation. The previous fallback
  of passing `{}` to the tool produced generic "missing field" errors
  that hid the real cause. Empty argsStr still falls through to `{}`
  for tools that take no parameters.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 22:50:49 +08:00
Arvin Xu 18bc2716b2 🔨 fix: wire Gateway-mode stop via direct tRPC interrupt (#13815)
*  feat: wire Gateway-mode stop button to WS interrupt

Frontend half of [LOBE-7142](https://linear.app/lobehub/issue/LOBE-7142)
— the stop button previously silently failed in Gateway mode because:

1. `stopGenerateMessage` only filtered `execAgentRuntime`, so
   `execServerAgentRuntime` ops (Gateway) were skipped.
2. Even if the local op got cancelled, nothing bridged the cancel to
   the server-side agent loop running behind the Agent Gateway WS.

## Changes

**`conversationControl.ts::stopGenerateMessage`** — extend the type
filter to include both op types so both client-side and Gateway-mode
runs are cancelled from the same entry point.

**`gateway.ts::executeGatewayAgent` + `reconnectToGatewayOperation`** —
register an `onOperationCancel` handler on the local `gatewayOpId` that
forwards the server-side operation id to `interruptGatewayAgent(...)`,
which sends `{ type: 'interrupt' }` over the Agent Gateway WS. The
closure cleanly resolves the "local op id vs server op id" mapping —
no metadata lookup needed.

**`operation/actions.ts::cancelOperation`** — `isAborting` flag was
gated on `execAgentRuntime`. Extend to `execServerAgentRuntime` too so
the UI loading state transitions out immediately on Gateway-mode stop,
without waiting for the round-trip `session_complete` from the server.

## What this doesn't do (follow-ups)

- **Backend**: new `POST /api/agent/interrupt` route + Redis LPUSH
  (LOBE-7145). Without it, the WS interrupt reaches Agent Gateway but
  never gets forwarded to cloud.
- **Agent loop**: `AgentRuntimeService.executeStep` LPOP polling of the
  interrupt key (LOBE-7146). Without it, the state never flips to
  `interrupted` server-side.
- **Agent Gateway DO** (external repo): `_forwardInterrupt` HTTP POST
  from the WS interrupt handler (LOBE-7147).

With only this PR merged, clicking stop will clear the local UI state
and send the WS frame correctly — the server-side loop keeps running
until those three are merged too.

## Tests

- `conversationControl.test.ts`: +1 — stopGenerateMessage cancels
  `execServerAgentRuntime`, invokes the onCancel handler, sets
  `isAborting: true`.
- `gateway.test.ts`: +1 — `executeGatewayAgent` registers a handler
  against the local opId, handler invokes `interruptGatewayAgent`
  with the server opId.

All 123 touched-slice tests pass; type-check clean.

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

* 🔨 chore: switch Gateway stop to direct tRPC instead of WS roundtrip

Rewiring only — no new behaviour on top of the previous commit. See
the discussion in PR #13815 for the full reasoning.

TL;DR the WS-based path (client → Agent Gateway WS → DO forwards
HTTP → cloud route → Redis LPUSH → loop LPOP) has the same end-effect
as the tRPC-direct path (client → tRPC → AgentRuntimeService
.interruptOperation → DB state flip), except:

- the tRPC path is one hop instead of three
- the tRPC path reuses infrastructure that's *already on canary* —
  `aiAgentService.interruptTask` → `AiAgentService.interruptTask` →
  `AgentRuntimeService.interruptOperation` → `coordinator.saveAgentState`
  with status='interrupted' — and the existing step-boundary polling
  in `executeStep` (AgentRuntimeService.ts:474, 565) already picks it up
- zero new server code required; zero Agent Gateway (external repo)
  coordination required

The only reason the WS path was in the original spec (LOBE-7142) was
symmetry with the Phase 6.4 tool_execute/tool_result path, but
`interrupt` is a one-shot control signal, not stream data — there's
no actual benefit to routing it through the same channel. Mid-step
abort would require threading an AbortSignal into `runtime.step(...)`,
which WS doesn't help with either.

Closes out the need for LOBE-7145 / LOBE-7146 / LOBE-7147.

Changes:
- `gateway.ts`: both `executeGatewayAgent` and
  `reconnectToGatewayOperation` register the cancel handler against
  the local op id, but the handler body now calls
  `aiAgentService.interruptTask({ operationId: serverOpId })` via
  tRPC instead of `this.interruptGatewayAgent(serverOpId)` (which sent
  the WS interrupt frame).
- `gateway.test.ts`: adjust the one new test case to verify the
  tRPC call rather than the WS-path spy; add `interruptTask` to the
  `aiAgentService` mock.

`AgentStreamClient.sendInterrupt()` and `interruptGatewayAgent()` are
kept as-is — public API, might be useful elsewhere. Just not called
from the cancel handler anymore.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 22:41:45 +08:00
Rdmclin2 636a3b77c3 🐛 fix: message gateway queue error (#13816)
* fix: gateway sync

* fix: skip  error connection

* feat: add disconnect all &  MESSAGE_GATEWAY_ENABLED env vairable

* chore: add gateway test case

* chore: clean lobehub connnections when switch to message gateway

* chore: optimize disconnect all

* chore: disconnect gateway connnections when using lobehub gateway

* chore: clean up exsiting gateway connections after reconnect and avoid gateway callback when not enabled
2026-04-14 22:10:17 +08:00
Arvin Xu c70ac84da7 feat: support run client tools in agent gateway mode (#13792)
*  feat: receive and execute executor=client tools on desktop Electron

Frontend half of LOBE-7076 (Phase 6.4). Pairs with server PR #13790,
which adds the `clientRuntime` signal + `hasClientExecutor` gate so
`local-system` and stdio MCP can enter the manifest for desktop callers.

Data flow, client side:

  Agent Gateway WS
     └─ tool_execute event ──► AgentStreamClient
            └─ 'agent_event' ──► gatewayEventHandler (case 'tool_execute')
                    └─ internal_executeClientTool (fire-and-forget)
                          ├─ parse args → params
                          ├─ mark pendingClientToolExecutions[toolCallId]
                          ├─ dispatch: builtin → invokeExecutor,
                          │            else   → mcpService.invokeMcpToolCall
                          ├─ clear pending
                          └─ AgentStreamClient.sendToolResult(...)
                                └─ WS → /api/agent/tool-result → LPUSH
                                       → server BLPOP unblocks → loop continues

Key guarantees:

- `internal_executeClientTool` never throws; ALL error paths (parse
  failure, no executor match, thrown executor, missing connection, MCP
  error) still call `sendToolResult({ success: false, error })`. The
  server's BLPOP must never hang on a silent client.
- `case 'tool_execute'` uses `void`, not `await`. A long-running tool
  must not block subsequent `stream_chunk` / `tool_end` events on the
  same WebSocket.
- UI loading state is kept separate from `toolCallingStreamIds` (the
  LLM-streaming animation) via a dedicated
  `pendingClientToolExecutions: Record<toolCallId, true>` map, so a
  renderer can show a distinct "running on device" indicator without
  entangling existing selectors.

Client → server signal:

`executeGatewayAgent` now passes `clientRuntime: isDesktop ? 'desktop' : 'web'`
so the server knows this Electron caller can receive `tool_execute`.

Tests: 39 new cases across AgentStreamClient / internal_executeClientTool
/ gatewayEventHandler covering success, error, MCP fallback, pending
state lifecycle, and fire-and-forget semantics. 148 total in affected
suites.

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

* 🐛 fix: pass server operationId to tool_result dispatch (operationId mismatch)

The gateway event handler received `tool_execute` events but the resulting
`internal_executeClientTool` call looked up `gatewayConnections` by the
*local* operation id (e.g. `op_8chrnd`) instead of the *server-side*
operation id (e.g. `op_1776171452938_...`) the WS connection is actually
keyed on. `conn` was therefore always `undefined`, the early-return in
`send(...)` swallowed the response, and the server's BLPOP waiter timed
out after 60 s.

This was reproducible on canary E2E: server logs showed
`dispatching client tool lobe-local-system/readLocalFile` followed by
`client tool ... timed out after 60027ms`, with no outbound `tool_result`
frame ever reaching the Agent Gateway.

Fix: thread a distinct `gatewayOperationId` through
`createGatewayEventHandler` and use it for the `case 'tool_execute'`
dispatch. The existing `operationId` (used for `dispatchContext` →
`internal_dispatchMessage` keying) is untouched. Both `executeGatewayAgent`
and `reconnectToGatewayOperation` now pass the server id explicitly; when
a caller omits it, it falls back to the local `operationId` for backwards
compatibility.

Verified live on canary: WS now shows
`[in] tool_execute` → `[out] tool_result success=true content=...` and
the agent returns the real local-file contents.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 21:30:13 +08:00
LiJian 116495bd1e 🐛 fix: slove the execAgents tools exec types not correct (#13807)
* fix: slove the execAgents tools exec types not correct

* fix: should inject source:discovery when tools type is lost

* fix: delete the source inject test
2026-04-14 17:51:08 +08:00
LiJian 922f7ace41 🐛 fix: fixed the when call saveCreds the bad request problem (#13809)
* fix: fixed the when call saveCreds the bad request problem

* fix: add the empty kv checked
2026-04-14 17:51:00 +08:00
YuTengjing b369c53bda 🐛 fix(model-bank): disable GLM-5.1 built-in search in LobeHub (#13806) 2026-04-14 17:05:42 +08:00
René Wang 5ecccf4b9e 📝 docs: add April 13 weekly changelog (#13808) 2026-04-14 17:02:10 +08:00
Rdmclin2 f9fbd45fee feat: discord support slash commands and DM (#13805)
* fix: slack not respond to text commands

* feat: add slack slash commands instructions

* chore: add slack validate in test connections

* chore: update slack docs

* chore: remove text commands for slack
2026-04-14 16:48:16 +08:00
LiJian 0b490a7268 🐛 fix: execAgent should get builtin discoverable tools into manifests (#13804)
* fix: execAgent should get all tools manifests

* fix: should add the tools source into payload source

* fix: add the discoverable tools into tools enginer

* fix: update the test, should include the discoverable tools
2026-04-14 16:07:49 +08:00
Innei a9c5badb80 ♻️ refactor(navigation): stable navigate hook and imperative routing (#13795)
*  fix: implement stable navigation hook and refactor navigation handling

- Introduced `useStableNavigate` hook to provide a stable `navigate` function that can be used across the application.
- Refactored components to utilize the new stable navigation approach, replacing direct access to the navigation function from the global store.
- Updated `NavigatorRegistrar` to sync the `navigate` function into a ref for consistent access.
- Removed deprecated navigation handling from various components and actions, ensuring a cleaner and more maintainable codebase.

Signed-off-by: Innei <tukon479@gmail.com>

* 🐛 fix: refactor navigation handling to prevent state mutation

- Updated navigation reference handling in the global store to use a dedicated function for creating navigation refs, ensuring that the initial state is not mutated by nested writes.
- Adjusted tests and components to utilize the new navigation ref creation method, enhancing stability and maintainability of navigation logic.

Signed-off-by: Innei <tukon479@gmail.com>

*  test: mock Electron's net.fetch in unit tests

- Added a mock for Electron's net.fetch in the AuthCtr and BackendProxyProtocolManager tests to ensure proper handling of remote server requests.
- This change allows tests to simulate network interactions without relying on the actual fetch implementation, improving test reliability.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-14 13:28:12 +08:00
LiJian cd0f65210c ♻️ refactor: update the codesandbox systemRole(preinstalled_software) (#13799)
refactor: update the codesandbox systemRole(preinstalled_software)
2026-04-14 12:11:44 +08:00
Arvin Xu 24be35fd84 🐛 fix(agent-runtime): resolve S3 image keys when refreshing messages (#13794)
messageModel.query() calls inside RuntimeExecutors were missing a
postProcessUrl callback, so imageList/videoList/fileList entries retained
raw S3 keys (e.g. `files/user_xxx/icon.png`). After the first tool batch,
the refreshed state fed those raw keys straight into the next LLM call,
and providers like Anthropic reject anything that isn't an absolute URL or
data URI ("Invalid image URL"). Wire a lazy FileService-backed
postProcessUrl into all three query sites (topic reference resolution,
compression, and post-batch refresh) so imageLists stay resolved across
multi-step operations.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:29:49 +08:00
Arvin Xu 46adf43453 🐛 fix: dispatch executor=client tools to desktop callers when DEVICE_GATEWAY is configured (#13793)
🐛 fix: dispatch executor=client tools to desktop caller even with DEVICE_GATEWAY configured

Two fixes to make Phase 6.4 (LOBE-7076) actually reach a desktop caller on
canary, where DEVICE_GATEWAY is configured and a separate remote device
may be registered.

### 1. AgentToolsEngine: suppress RemoteDevice for desktop callers

The `lobe-remote-device` tool is meant for the legacy "tunnel commands to
a separately registered desktop" flow. When the caller itself is a
desktop Electron client, that's redundant — and worse, the LLM was
picking `listOnlineDevices` + `activateDevice` *first*, then routing the
subsequent `readLocalFile` to a different registered host (a remote
Linux VM in our E2E trace, returning ENOENT for a path that only exists
on the caller).

Adds `&& !hasClientExecutor` to the RemoteDevice enable rule. Desktop
callers now see only `local-system` in their manifest.

### 2. aiAgent.execAgent: mark executor='client' for desktop callers

The existing gate was `if (!gatewayConfigured) { executorMap[...] = 'client' }`.
On canary, `gatewayConfigured === true` (DEVICE_GATEWAY set), so
`local-system` / stdio MCP stayed server-executed and were dispatched to
the Remote Device proxy instead of back to the caller's Agent Gateway WS.

Extends the gate to:
  `if (clientRuntime === 'desktop' || !gatewayConfigured)`

So a caller that explicitly signals it can receive `tool_execute` bypasses
the DEVICE_GATEWAY heuristic. Legacy behaviour unchanged for web callers
and for callers that don't send `clientRuntime`.

### Tests

- AgentToolsEngine: +1 case verifying RemoteDevice is suppressed when
  `clientRuntime === 'desktop'` even with `gatewayConfigured: true`
- execAgent.deviceToolPipeline: +3 cases
  - local-system gets executor='client' for desktop + DEVICE_GATEWAY
  - stdio MCP gets executor='client' for desktop + DEVICE_GATEWAY
  - web caller preserves legacy routing (executor unset)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 09:22:18 +08:00
Arvin Xu f0a811ef83 🐛 fix: enable executor=client tools for desktop Electron callers (#13790)
*  feat: enable executor=client tools for desktop Electron callers

Adds a `clientRuntime` signal to execAgent so the server knows the caller
itself can execute `executor: 'client'` tools (local-system, stdio MCP) over
its Agent Gateway WebSocket. This is the missing server piece for Phase 6.4
(LOBE-7076): previously `local-system` only entered the manifest when a
*separately registered* remote device was online & auto-activated, so a
desktop Electron caller sitting on the other end of the Gateway WS could
never actually be dispatched to via `tool_execute`.

The new signal is orthogonal to the legacy device-proxy `deviceContext` —
it describes the caller itself, not a third-party device. The enable rule
for LocalSystemManifest simply gets one extra OR branch:

  local && gatewayConfigured && (hasClientExecutor || legacy-device-online-activated)

`toolExecutorMap[LocalSystemManifest.identifier] = 'client'` (LOBE-7067)
then kicks in as soon as the manifest entry is present, so
`RuntimeExecutors.call_tool` (LOBE-7068) will push `tool_execute` over the
Agent Gateway WS to this caller.

Plumbing:
- packages/types: `ExecAgentParams.clientRuntime?: 'desktop' | 'web'`
- lambda router: accepts + forwards `clientRuntime`
- aiAgent service: forwards to `createServerAgentToolsEngine`
- AgentToolsEngine: +1 field, +1 OR branch in LocalSystem enable rule.
  Zero changes to `runtimeMode` / `platform` / `RemoteDeviceManifest` /
  `deviceContext` semantics.

Tests: 3 new cases in AgentToolsEngine covering desktop / web / gateway-off
branches; 3 new cases in execAgent.deviceToolPipeline verifying the
`clientRuntime` param is forwarded verbatim.

Follow-up (separate PR): frontend receives `tool_execute`, runs the tool
via Electron IPC, and sends `tool_result` back over the same WS.

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

* ♻️ refactor: untangle runtime / platform / device-proxy flags in AgentToolsEngine

Renames and separates two orthogonal concerns that used to share the
misleading `isDesktopClient` name:

- `hasClientExecutor` — caller itself can receive `tool_execute` over
  the Agent Gateway WS (Phase 6.4). Property of the caller.
- `hasDeviceProxy` — server has a device-proxy configured that tunnels
  to a separately registered device (legacy Remote Device). Property of
  the server.

`platform` is now derived from the caller (`clientRuntime`) first,
falling back to the device-proxy signal for backwards compat — it was
previously derived purely from the server's proxy config, which
conflated "server can reach a desktop" with "caller is a desktop".

LocalSystem enable rule restructured to read in natural order:
  runtimeMode === 'local'         // user opted in
  && hasDeviceProxy               // server has a Gateway path
  && (hasClientExecutor || ...)   // an execution target exists

Behavior is identical to the previous commit; this is a pure rename /
regrouping refactor. 38 existing tests still pass without changes.

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

* 🐛 fix: decouple hasClientExecutor from hasDeviceProxy in local-system gate

The previous rule required `hasDeviceProxy` as a shared prerequisite for
BOTH enable paths, which is wrong: `hasDeviceProxy` reflects the legacy
device-proxy (`deviceProxy.isConfigured`), while Phase 6.4's
`tool_execute` rides the Agent Gateway WebSocket that this request is
already on. The two systems are orthogonal — a desktop caller on the
Gateway WS can receive `tool_execute` without any device-proxy being
configured server-side.

Correct enable rule:

  runtimeMode === 'local'
  && (hasClientExecutor                              // Phase 6.4, self
      || (hasDeviceProxy && deviceOnline && autoActivated))  // legacy

Updated the `still requires gateway to be configured` test, which was
asserting the incorrect coupling, to instead verify that agent-level
`runtimeMode.desktop === 'none'` opt-out is respected for desktop
callers.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 01:12:45 +08:00
Arvin Xu 10914ff015 🐛 fix: add image-to-video options to CLI generate video command (#13788)
*  feat: add image-to-video options to CLI generate video command

Why: CLI only supported text-to-video. Backend already accepts imageUrl/endImageUrl
for image-to-video, but the CLI had no way to pass them.

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

* update cli version

* update cli version

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 01:12:10 +08:00
Innei b9c4b87a90 🩹 fix(database): enforce document history ownership and pagination 2026-04-14 00:51:13 +08:00
Adam Bellinson b857ae6c57 🐛 fix(desktop): use Electron net.fetch for remote server requests (#13400)
* use Electron's net.fetch() so system trusted certs are honored

* 🐛 fix(tests): mock netFetch in unit tests broken by net.fetch migration

Both LocalFileCtr and RemoteServerConfigCtr tests were patching
global.fetch / stubGlobal, which no longer intercepts calls now that
the controllers route through Electron's net.fetch via @/utils/net-fetch.
Hoist the fetch mock and point vi.mock('@/utils/net-fetch') at it directly.
2026-04-14 00:45:54 +08:00
Arvin Xu e11c89fc48 🐛 fix(agent-runtime): skip client-executor marking when gateway is configured (#13787)
Tools flagged as `executor: 'client'` are dispatched via `dispatchClientTool`
through the Agent Gateway WS path. In cloud deployments where the gateway is
configured but no desktop device is connected, this path 404s on
`/api/operations/tool-execute` and the tool fails with `dispatch_failed`.

Only mark local-system and stdio MCP plugins as `'client'` when the gateway
is NOT configured (standalone Electron). When deviceContext is available,
tool routing goes through the RemoteDevice proxy instead.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 00:25:19 +08:00
Innei e3eef044ca 👷 build(database): add document history schema 2026-04-14 00:05:06 +08:00
LiJian b9a136f9f1 🐛 fix: slove the execAgent not have lobehub skills & builtin tools (#13781)
fix: slove the execAgent not have lobehub skills & builtin tools
2026-04-13 18:15:54 +08:00
Rdmclin2 809e1e0716 🐛 fix: message gateway ensure running (#13780)
fix: message gateway ensure running
2026-04-13 17:43:18 +08:00
Octopus 7953cf5b5a fix(desktop): use low urgency for Linux notifications to prevent GNOME Shell freeze (#13767)
🐛 fix(desktop): use low urgency for Linux notifications to prevent GNOME Shell freeze

On Linux/GNOME Shell, desktop notifications with urgency 'normal' appear
as banner pop-ups. Clicking the dismiss (X) button on these banners can
cause the system to freeze for 30-45 seconds due to heavy gnome-shell
CPU and memory usage.

Setting urgency to 'low' on Linux routes notifications to the message
tray instead of displaying them as banners, which avoids the problematic
X button interaction. The urgency option is ignored on macOS and Windows.

Fixes #13538

Co-authored-by: octo-patch <octo-patch@github.com>
2026-04-13 16:19:44 +08:00
LobeHub Bot 012214205e 🌐 chore: translate non-English comments to English in database-tests (#13771)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 16:14:09 +08:00
Arvin Xu f0f2feb015 🔨 chore(task): add participants to task.list response (#13778)
*  feat(task): add participants array to task.list response

Return a participants array per task (id / type / avatar / name) so
clients can show avatar groups on task cards. For now participants
only contains the assignee agent; future iterations can aggregate
comment authors and topic executors.

Also extract TaskItem into @lobechat/types as an explicit type
definition so it no longer relies on drizzle schema inference.

* ♻️ refactor(task): extract NewTask to @lobechat/types

Remove the drizzle $inferInsert NewTask from schemas and define it
explicitly in @lobechat/types alongside TaskItem.

*  test(task): cover participants in task.list response
2026-04-13 16:09:53 +08:00
Innei f439fb913a 🐛 fix(editor): bump @lobehub/editor to 4.8.1 (#13756)
🐛 fix: bump @lobehub/editor to 4.8.1
2026-04-13 14:17:39 +08:00
Neko 6966d366d1 🐛 fix(userMemories): should trim way too long bm25 (#13744) 2026-04-13 13:45:37 +08:00
LiJian f89adb36b3 🐛 fix: slove the agent details pages not get the agent config always lo… (#13772)
fix: slove the agent details pages not get the agent config always loading problem
2026-04-13 12:46:10 +08:00
Arvin Xu 3c2fc7f368 🔨 chore(agent-runtime): dispatch client-executor tools via Agent Gateway WS (#13769)
 feat(agent-runtime): dispatch client-executor tools via Agent Gateway WS

Wire the block-await dispatch path for tools marked as `executor: 'client'`:

- `aiAgent/index.ts` (6.3a) — derive `toolExecutorMap` from manifests:
  * `local-system` builtin → `'client'` (requires Electron IPC)
  * MCP plugins with `customParams.mcp.type === 'stdio'` → `'client'`
    (subprocess runs on the user's machine)
  Purely manifest-driven; no new context / capability fields needed.

- `dispatchClientTool` (6.3b) — helper that:
  * Pushes a `tool_execute` event via `streamManager.sendToolExecute`
  * Block-awaits on Redis BLPOP via `ToolResultWaiter`
  * Returns a `ToolExecutionResultResponse`-shaped object (drop-in with
    the existing server path)
  * Never throws — timeouts / gateway errors / missing infra all
    produce a failed-but-structured result so the agent loop continues

- `RuntimeExecutors.call_tool` / `call_tools_batch` — route to
  `dispatchClientTool` when `payload.executor === 'client'` AND the
  stream manager exposes `sendToolExecute`. Otherwise fall through to
  the existing server path unchanged. Response API (`source: 'client'`)
  interrupt branch is untouched.

Capped at 270s per tool to match Vercel's streaming function window;
longer tools will be handled by the resumable path in Phase 6.3c.

Covered by:
- 5 unit tests on `dispatchClientTool` (gateway missing, redis missing,
  happy path, timeout, dispatch error)
- 286 existing tests still pass in adjacent suites

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:25:43 +08:00
LobeHub Bot a72ae190a3 🌐 chore: translate non-English comments to English in integration-test-utilities (#13749)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-13 11:01:34 +08:00
Arvin Xu 4feafb3fcb ♻️ refactor: migrate memory-user-memory workflows to Hono (#13768)
Replace 6 per-path Next.js `route.ts` handlers (using `@upstash/workflow/nextjs` serve) with a single Hono app mounted at `[[...route]]`. Workflow logic moves to `src/server/workflows-hono/memory-user-memory/`; all public URLs remain unchanged so existing `MemoryExtractionWorkflowService.triggerXxx` callers need no update.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:50:10 +08:00
Arvin Xu eff527de65 🔨 chore(agent-runtime): add ToolResultWaiter for BLPOP-based tool result await (#13763)
*  feat(agent-runtime): add ToolResultWaiter for Redis BLPOP-based tool result await

Introduce ToolResultWaiter — a Promise-based wrapper around Redis BLPOP
that server-side agent loops will use to block-await client-side tool
execution results delivered via the callback API (LPUSH on another
connection).

Design highlights:
- Takes two ioredis clients: a dedicated blocking connection for BLPOP
  (must not be shared with business traffic) and a normal producing
  connection for side effects (cancel sentinel).
- `waitForResult(id, timeoutMs)` returns the parsed payload or null on
  timeout / cancel, never throws for timeout (caller decides fallback).
- `waitForResults(ids[], timeoutMs)` fans out via Promise.all, aligning
  results with input order.
- `cancel(id)` LPUSHes a poison-pill sentinel to wake a pending waiter,
  used when the agent loop is terminated mid-tool.

Covered by unit tests (6 cases: push-before / push-after / timeout /
batch / cancel / malformed payload).

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

* 🐛 fix(agent-runtime): use multi-key BLPOP in waitForResults to avoid N×timeout latency

Promise.all-ing waitForResult over a shared blocking Redis connection
actually serializes: BLPOP holds the socket, so calls run back-to-back
rather than concurrently. A batch of N where some results never arrive
would take up to N × timeoutMs to resolve, stalling tool-call loops
and delaying cancellation.

Rewrite waitForResults to use Redis's multi-key BLPOP in a loop with a
shared deadline: each iteration blocks on all remaining keys with the
remaining budget, wakes when any one arrives, drops that key, and
re-enters with the rest. Total latency is bounded by one timeoutMs
regardless of N. Single-key waitForResult now delegates to this path.

Covered by a new regression test asserting that an N=3 batch of
never-arriving keys completes in ~1 timeout window, not N×.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:47:49 +08:00
Arvin Xu c60563fffc 🔨 chore(api): add POST /api/agent/tool-result callback endpoint (#13764)
 feat(api): add POST /api/agent/tool-result callback endpoint

Agent Gateway forwards client tool execution results to this endpoint;
the handler LPUSHes into a per-toolCallId Redis list with a 120s TTL so
the server-side agent loop's BLPOP can wake and continue.

- Auth via AGENT_GATEWAY_SERVICE_TOKEN bearer header
- Zod-validated body: { toolCallId, content, success, error? }
- Key: tool_result:{toolCallId}
- Idempotency not required; duplicates sit under TTL until expired

No runtime caller yet — wiring lands with the BLPOP waiter in LOBE-7068.

Covered by unit tests (6 cases: missing/wrong token, missing token env,
invalid body, Redis unavailable, happy path, Redis write error).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:35:03 +08:00
Arvin Xu b36c5a2f1b 🔨 chore: add GatewayStreamNotifier.sendToolExecute (#13765)
 feat(agent-runtime): add GatewayStreamNotifier.sendToolExecute

Expose a request-response-style push for tool_execute on top of the
existing Gateway HTTP pipe. Callers use this to delegate tool execution
to the client; failures surface back to the caller so the agent loop
can decide whether to fall back to the interrupt-resume path.

- `IStreamEventManager.sendToolExecute?` — optional interface method,
  only the Gateway-backed notifier implements it (InMemory/Redis-only
  managers intentionally leave it undefined)
- `GatewayStreamNotifier.sendToolExecute(operationId, ToolExecuteData)`
  POSTs to Gateway `/api/operations/tool-execute`
- New private `httpPostAwait` helper preserves the 5s timeout but,
  unlike the fire-and-forget `httpPost`, rejects on non-ok / network
  failure so callers can react

No runtime caller yet; the dispatch branch lands with LOBE-7068.

Covered by unit tests (3 new cases: happy path payload, non-ok
response, network error).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:29:43 +08:00
Arvin Xu 12bbc56db3 🔨 chore: add tool_execute / tool_result protocol types (#13762)
*  feat(agent-stream): add tool_execute / tool_result protocol types

Introduce the type-level scaffold for the Gateway-mediated client tool
execution flow:

- `tool_execute` server→client event with `ToolExecuteData` payload
  (toolCallId, identifier, apiName, arguments, executionTimeoutMs)
- `tool_result` client→server message with success/error and content,
  added to the `ClientMessage` union

No runtime wiring yet; this PR is pure type scaffolding so subsequent
server (Redis BLPOP waiter, Gateway notifier, RuntimeExecutors branch)
and client (gateway handler) work can land independently.

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

* Update types.ts

* 💄 style(agent-stream): reorder ToolResultMessage fields for perfectionist

Move `error?` before `state?` to satisfy `perfectionist/sort-interfaces`
after the `state?: any` field was added to align with ChatToolResult.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:09:53 +08:00
Rdmclin2 73be58ba12 feat: support message gateway (#13761)
* feat: support message gateway

* feat: sync message gateway connections

* chore: add cloudflare http v2

* fix: typing interval

* feat: add connnectionMode to gateway

* chore: add applicationId when connect

* fix: judge typing supoort by  triggerTyping implementation

* fix: skip message gateway & start connnections

* fix: qq platform hint

* chore: skip webhook mode in gateway connection

* fix: test case

* fix:  message gateway check

* chore: add failaure case post

* fix: test case

* feat: add GatewayManager for webhook-mode platforms
2026-04-13 01:27:54 +08:00
Arvin Xu 3ad124ac4f 🔨 chore: support multimodal input for server-side agent execution (#13759)
*  feat(agent): support multimodal input for server-side agent execution

Wires already-uploaded file IDs through the Gateway-mode execAgent path so
SPA-attached images / documents / videos reach the LLM when the agent runs
server-side. Resolves attachments via FileModel.findByIds, classifies by
MIME, parses documents idempotently, and persists the messages_files link
for history replay.

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

* 🐛 fix(agent): dedupe repeated fileIds before writing messages_files

messages_files has a composite PK on (file_id, message_id); a fileIds array
containing the same id twice would fail the insert and abort execAgent. Dedupe
the input while preserving caller-provided order so rendering stays stable.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:52:03 +08:00
Arvin Xu e569c8dee0 ♻️ refactor: introduce ToolExecutor field orthogonal to ToolSource (#13760)
Add ToolExecutor ('client' | 'server') as a new orthogonal dimension
alongside ToolSource to describe where a tool invocation is dispatched.
Thread executorMap through OperationToolSet / ResolvedToolSet / AgentState
and attach executor to the ChatToolPayload emitted in onToolsCalling.

Defaults remain empty (all server-side), so behavior is unchanged. This
is pure scaffolding to unblock subsequent work on client-side dispatch.

Also remove the unused 'plugin' value from ToolSource (no downstream
consumers branched on it; installed plugins now labeled 'mcp').

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 00:28:30 +08:00
YuTengjing 406cb5554b feat: add GLM-5.1 model support for Zhipu provider (#13757) 2026-04-12 22:14:52 +08:00
Arvin Xu 0486be4773 🐛 fix: guard non-string content in context-engine to prevent e.trim errors (#13753)
🐛 fix: guard non-string content in context-engine to prevent `e.trim is not a function`

Two unguarded `.trim()` / string-concatenation paths in the context-engine
could throw or produce garbage text when a message's `content` is not a
plain string (multimodal parts array, null tool turns). Both are reached
in normal chat and trigger `e.trim is not a function` in production.

- `resolveTopicReferences`: filter out non-string content in the fallback
  `lookupMessages` path before calling `.trim()`. Without this guard, the
  outer try/catch swallows the TypeError and drops the whole fallback.
- `MessageContent` processor: normalize `message.content` (string or
  parts array) before concatenating file context, instead of relying on
  implicit `toString()` coercion which emitted `[object Object]` into
  the LLM prompt.

Adds regression tests for both paths.
2026-04-12 19:27:52 +08:00
Innei f2ee67c3c5 🐛 fix(inbox): restore inbox avatar fallback after deletion (#13752) 2026-04-12 17:40:40 +08:00
Rdmclin2 16ed80701c 🐛 fix: revert anthropic base64 image (#13751)
chore: revert anthropic base64 image
2026-04-12 16:06:19 +08:00
Octopus 37bf1bd191 fix(local-system): restore loc param when calling readLocalFile IPC (#13748)
🐛 fix(local-system): restore loc param when calling readLocalFile IPC

The `denormalizeParams` method in `LocalSystemExecutionRuntime` was
missing a case for `readLocalFile`. It fell through to `default`, which
passed `{startLine, endLine, path}` as-is to the IPC layer. However,
the IPC handler (`LocalFileCtr.readFile`) expects `LocalReadFileParams`
with `loc?: [number, number]`, not `startLine`/`endLine`. As a result,
`loc` was always `undefined` on the IPC side, causing `readLocalFile`
to default to `[0, 200]` and always return content from line 0.

Fix: add an explicit `readLocalFile` case that reconstructs the `loc`
tuple from `startLine` and `endLine` before forwarding to the IPC layer.

Fixes #13735

Co-authored-by: octo-patch <octo-patch@github.com>
2026-04-12 14:34:42 +08:00
Neko e0f97c4920 🐛 fix(userMemories): missing cancel webhook api for cascading cancellation (#13742) 2026-04-12 04:35:17 +08:00
Arvin Xu 93698f76f8 🔨 chore: update cli version (#13741)
update cli
2026-04-12 02:20:08 +08:00
Arvin Xu 2c79b5ab78 🐛 fix: refine ProviderBizError classification for insufficient balance and quota limit (#13740)
* 🐛 fix: refine ProviderBizError classification for insufficient balance and quota limit errors

Extract inline "Insufficient Balance" check into a dedicated `isInsufficientQuotaError` utility with case-insensitive matching and broader patterns. Add "too many tokens" pattern to `isQuotaLimitError` for Moonshot rate-limit messages.

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

* update

* 🐛 fix: remove "account has been deactivated" from InsufficientQuota patterns

Account deactivation can be triggered by policy, security, or account review — not just billing. Classifying it as InsufficientQuota misleads users into topping up balance when the fix is usually permission or support escalation.

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

*  feat: add AccountDeactivated error type for deactivated/suspended accounts

Separate account deactivation from InsufficientQuota so users get actionable guidance (contact support) instead of misleading billing advice.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 02:14:30 +08:00
Rylan Cai 5613935b73 🐛 fix: fix cli message/topic list page indexing (#13731)
* 🐛 fix cli message/topic list page indexing

* ♻️ inline page parsing in message command
2026-04-12 00:46:31 +08:00
Arvin Xu fb7f0c3e92 🐛 fix: preserve error message in ChatCompletionErrorPayload (#13736)
* 🐛 fix: preserve error message in ChatCompletionErrorPayload for ProviderBizError

Add `message` field to `ChatCompletionErrorPayload` and extract SDK error messages in `handleOpenAIError` and `handleAnthropicError`, so downstream consumers (agent tracing, error state) receive human-readable error details instead of generic "ProviderBizError".

Closes LOBE-7019

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

* 🐛 fix: guard nullish error in handleAnthropicError

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 23:42:03 +08:00
Rdmclin2 08769e5bf1 🐛 fix: layout recent locale and support dismiss banner (#13739)
* fix: CN locale for rencents

* fix: community profile setup modal

* feat: support skill banner dismiss
2026-04-11 23:27:21 +08:00
Arvin Xu 732a3ae54a ♻️ refactor: clean up unused sessionStore selectors and slices (#13738)
Remove dead code from the legacy sessionStore:
- Delete `recent` slice (migrated to homeStore)
- Delete `homeInput` slice (migrated to homeStore)
- Remove unused selectors: currentSessionSafe, hasCustomAgents,
  defaultSessionsCount, defaultSessionsLimited, getSessionMetaById,
  currentGroupMeta, getDescription
- Update store type, initialState, and tests accordingly

Closes LOBE-7018

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 22:37:22 +08:00
Arvin Xu a8fee05c3e 🔨 chore: resolve author info for task activity list (#13732)
*  feat: resolve author info (avatar + name) for task activity list

Add `author` field to `TaskDetailActivity` with `{id, type, name, avatar}`.
Backend resolves agent/user info via batch queries in `getTaskDetail`:
- Topics: author is the task's assignee agent
- Briefs: author is the brief's agentId
- Comments: author is authorAgentId or authorUserId

Fixes LOBE-7013

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

* ♻️ refactor: move author resolution queries to model layer

Replace direct db.select() calls in TaskService with:
- AgentModel.getAgentAvatarsByIds() for agent info
- UserModel.findByIds() for user info

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 20:43:00 +08:00
Arvin Xu c255bfe97d 💄 style: show loading state for assistant message during optimistic update (#13733)
🐛 fix: show loading state for assistant message during sendMessage phase

During optimistic update, the assistant message content is "..." but the
loading indicator was not shown because isGenerating only checks
AI_RUNTIME_OPERATION_TYPES (execAgentRuntime), not sendMessage. Include
isCreating state so the loading dots appear immediately when message is sent.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 20:37:16 +08:00
Arvin Xu f7f2e063d1 💄 style: add delete action to agent profile dropdown menu (#13734)
*  feat: add delete action to agent profile dropdown menu

Add a "Delete" option to the three-dot menu in Agent Profile header,
with confirmation modal. Uses existing `removeAgent` from homeStore.

Fixes LOBE-6582

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

* 🐛 fix: navigate to home after deleting agent from profile

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 20:31:55 +08:00
Sun13138 39bca4bc1a 🐛 fix(gemini): align thinkingLevel config resolution across the stack (#13457)
* 🐛 fix(gemini): omit empty thinkingConfig and align thinkingLevel keys

- Google runtime: omit empty thinkingConfig to avoid sending thinkingConfig: {} upstream.\n- UI: ThinkingLevel2/3/4/5 sliders read/write only their own config key.\n- Resolver: map model extend params thinkingLevel* to matching chatConfig key (no fallback/priority logic).\n- Tests: add regression coverage for empty thinkingConfig omission.

* 🐛 fix(gemini): restore default thinking levels by model param

* 🐛 fix(gemini): prefer configured thinkingLevel params
2026-04-11 19:10:26 +08:00
Arvin Xu 9b765eb360 update og 2026-04-11 18:43:28 +08:00
Arvin Xu f68c45cab6 Merge remote-tracking branch 'origin/canary' into fix/task-topic-status-cascade 2026-04-11 18:42:57 +08:00
LobeHub Bot 44c569c5db 🌐 chore: translate non-English comments to English in chat store (#13728)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 18:37:00 +08:00
Arvin Xu 390d82d730 🐛 fix: complete operation and show error on gateway error event (#13714)
* 🐛 fix: complete operation and show error on gateway error event

- Error event handler writes inline error immediately via
  internal_dispatchMessage, then fetches from DB for richer detail.
  This ensures the UI always shows an error even when the server
  hasn't persisted the error into the message table.
- disconnected listener only fires onSessionComplete after a terminal
  agent event (agent_runtime_end / error), not on auth failures or
  explicit disconnect calls.
- Track terminal events via agent_event listener with dedup guard to
  prevent double-firing onSessionComplete.

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

* 🐛 fix: persist error into assistant message on agent runtime failure

When an agent runtime step fails, the error was written to error_logs
and Redis state but not to the assistant message in the DB. This caused
the frontend to show an empty message after fetchAndReplaceMessages,
since the message had no error field set.

Now dispatchCompletionHooks writes the error to the assistant message
via messageModel.update when reason is 'error', matching the pattern
used by updateAbortedAssistantMessage.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 18:22:18 +08:00
Arvin Xu 2b44cdd298 🐛 fix: add null guard for topicId to fix type error
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 18:05:41 +08:00
Arvin Xu 345f144b1e 🐛 fix: use conditional cancel and fail-fast on interrupt errors
- Add `cancelIfRunning` to TaskTopicModel: atomically cancel only if topic
  is still running, preventing overwrite of concurrent completed/timeout transitions
- Skip topic cancellation when `interruptTask` fails, keeping DB state
  consistent with the still-running remote operation
- Add test for interrupt failure scenario

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 17:52:29 +08:00
YuTengjing f780f43863 🔨 chore: fix skill frontmatter key to use kebab-case (#13730) 2026-04-11 15:53:02 +08:00
Rdmclin2 ac1abbaf8b 🐛 fix: bot error lobe 6925 (#13724)
* chore: remove unused variables

* fix: add  catch error

* chore: use url for anthropic image

* feat: add bot  process warnings to context

* feat: add thread context

* fix: rename thread name when already has one

* chore: update test cases

* fix: warning sanitize

* fix: threadName safe review
2026-04-11 02:11:33 +08:00
Innei b5f98bd745 feat(chat-input): improve mention menu skill and tool icons (#13722)
*  feat(chat-input): improve mention menu skill and tool icons

- Add MentionItemIcon with SkillAvatar, McpIcon, and Avatar fallbacks
- Strip placeholder avatars ending with _AVATAR
- Tweak mention item icon frame (overflow, border-radius)

Made-with: Cursor

* 💄 fix(chat-input): use theme-aware mention skill fallback
2026-04-11 01:35:02 +08:00
Innei 48d0a759a8 🐛 fix(chat): refine workflow collapse headline (#13717)
* 🐛 fix(chat): refine workflow collapse headline

* 🐛 fix(chat): use state machine for workflow headline

* 🐛 fix(chat): backtrack workflow headline state

* ♻️ refactor(chat): simplify workflow headline selector

* 💄 style(chat): use lucide workflow collapse arrow

* ♻️ refactor(chat): use accordion indicator layout

* Move workflow duration text beside the title

* Localize workflow tool display labels

* Update Page workflow localization labels

* fix: sort imports in toolDisplayNames.test.ts
2026-04-11 00:49:25 +08:00
Rdmclin2 5d135b3ae1 🔨 fix: layout sidebar en More (#13723)
* fix: layout sidebar en More

* chore: update i18n files
2026-04-11 00:46:53 +08:00
Tsuki 17b3acead6 feat(subscription): add cross-platform subscription support for mobile IAP (#13413)
feat(subscription): add cross-platform subscription i18n and mobile subscription router

- Add crossPlatform.title/desc/manageOnMobile translations for 18 languages
- Register mobileSubscriptionRouter in mobile tRPC router
- Add mobileSubscription business router placeholder

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 00:27:51 +08:00
Rdmclin2 2c397390b4 feat: layout sidebar impl (#13719)
* ♻️ Restructure sidebar layout: extract Lobe AI entry, move New Agent button

- Extract Lobe AI (InboxItem) from agent list to standalone top entry in sidebar body
- Move "New Agent" button from header to below Lobe AI entry
- Add "Create" to bottom menu items alongside Community and Resources
- Filter hidden items in BottomMenu component

Fixes LOBE-6938

https://claude.ai/code/session_01RtfXck3GUngoLAgP2yHArz

*  Add unified Recents section to home page

- New TRPC router `recent.getAll` aggregating topics, documents, files, and tasks
- New client service and SWR-based store integration for recents data
- Unified Recents component on home page with type-based icons
- Items sorted by updatedAt, limited to 10, mixed across all types

Fixes LOBE-6938

https://claude.ai/code/session_01RtfXck3GUngoLAgP2yHArz

*  Prefetch agent config on hover for faster page loads

- Add usePrefetchAgent hook using SWR mutate to warm cache
- Trigger prefetch on mouseEnter for sidebar agent items
- Reduces or eliminates loading screen when navigating to agent pages

Fixes LOBE-6938

https://claude.ai/code/session_01RtfXck3GUngoLAgP2yHArz

*  Redesign agent homepage with info, recent topics, and tasks

- New AgentHome feature replacing the old AgentWelcome component
- Agent info section: avatar, name, description, opening questions
- Recent Topics: horizontal scrollable cards for agent-specific topics
- Tasks section: list with status labels for agent-assigned tasks
- Preserve ToolAuthAlert for tool authorization flows

Fixes LOBE-6938

https://claude.ai/code/session_01RtfXck3GUngoLAgP2yHArz

* fix: common misstakes in layout

* chore: add fetch Recents cache

* chore: add back createagents

* chore: add back lobe ai

* feat: add display count

* feat: add create agent button

* feat: add sidebar section order

* chore: move divider

*  feat: show current page size in display items submenu

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

*  feat: add sidebar display management with customize sidebar modal

- Add "Hide section" and "Customize sidebar" to Recents/Agents dropdown menus
- Create CustomizeSidebarModal with eye toggle for section visibility
- BottomMenu (Community/Resources) also manageable via modal
- Show customize sidebar button in footer when all sections hidden
- Add hiddenSidebarSections to store with localStorage persistence
- Rename "Display Items" to "Show" in dropdown menus
- Add 12px margin between accordion sections and bottom menu
- Add i18n keys for en-US and zh-CN

Fixes LOBE-6938

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

* 💄 style: use SlidersHorizontal icon for customize sidebar

Replace Settings2/PanelLeft icon with SlidersHorizontal to avoid
confusion with the settings gear icon.

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

* 💄 style: refine sidebar customization UX

- Move Settings entry from Footer to BottomMenu alongside Community/Resources
- Add Settings to Customize sidebar modal with eye toggle
- Allow hiding all sections (remove disabled constraint)
- Move Customize sidebar button next to help button in Footer
- Merge Agent dropdown: group Create items with Category items
- Use SlidersHorizontal icon for Customize sidebar

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

*  feat: add recents item actions and "more" drawer

- Add inline rename (same as Agent Topic) and delete to Recents items
- Topic/document/file support rename + delete, task supports delete only
- Add "more" button when items exceed pageSize, opens AllRecentsDrawer
- AllRecentsDrawer shows all cached recents from store (up to 50)
- Fetch max(pageSize, 50) items to support drawer without extra request

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

*  feat: add create agent/group modal with ChatInput and examples

- Add CreateAgentModal using base-ui Modal with ChatInputProvider
- Show suggestion examples (agent/group mode) in 2-column grid
- Submit triggers sendAsAgent/sendAsGroup to auto-generate via Agent Builder
- "Create Blank" button for skipping the prompt
- Integrate modal into AgentModalProvider for shared state across sidebar
- Wire up AddButton, NewAgentButton, and dropdown menus to open modal

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

* feat: optimitic update rename

* chore: prefetch agent detail

* feat: add recent topic meta data

* feat: add recents search

*  perf: optimize recents API with single UNION query and prefetch

- Replace 3 separate DB queries with single UNION ALL query (RecentModel)
- Add optimistic updates for rename and delete actions
- Add hover prefetch for resources (usePrefetchResource)
- Add hover prefetch for agent config on topic/task items
- Change default pageSize to 5 for both Agents and Recents
- Unify delete confirmation messages per item type

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

* chore: adjust settings page

* chore: optimize side bar

* feat: recents support right click

* chore: add pin icon to Agents

* chore: add custom side bar modal

* chore: reserve rencent drawer status

* feat: add prefetch route

* feat: add LobeAI prefetch

* fix: document and task rename and delete operation lost

* fix: group route id

* fix: lint error

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-11 00:13:19 +08:00
Innei cd49e98936 chore: bump lucide-react to v1.8.0 (#13703)
* chore: bump lucide-react from ^0.577.0 to ^1.8.0

 Breaking change: Github icon was removed from lucide-react v1.x (brand icons removed).
 Replaced with Github from @lobehub/icons in 5 affected files.

* fix: use GithubIcon from @lobehub/ui/icons instead of @lobehub/icons
2026-04-10 20:17:23 +08:00
Arvin Xu 7894a0a28e 🐛 fix: cascade cancel running topics when task status transitions out of running
When a task's status changes from `running` to another state (backlog/paused/completed/canceled),
automatically cancel all associated running topics and interrupt their operations.
This prevents 409 CONFLICT errors when users try to re-run a task after manually changing its status.

Fixes LOBE-6719

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 19:37:03 +08:00
lobehubbot d47f4fec76 🔖 chore(release): release version v2.1.49 [skip ci] 2026-04-10 09:51:03 +00:00
Tsuki 9088a074e2 🚀 release: 20260410 (#13716)
## 📦 Weekly Release 20260410

This release includes **67 commits**. Key user-facing updates below.

### New Features and Enhancements

- Introduced **Prompt Rewrite & Translate** feature for assisted input
editing.
- Added **Skill Panel** with dedicated skills tab in the skill store and
fixed skill icon rendering.
- Introduced `lh notify` CLI command for external agent callbacks.
- Added `migrate openclaw` CLI command.
- Added **GraphAgent** and `agentFactory` for graph-driven agent
execution (experimental).
- New topic auto-creation every 4 hours for long-running sessions.

### Models and Provider Expansion

- Added a new provider: **StreamLake (快手万擎)**.
- Added **GLM-5.1** model support with Kimi CodingPlan fixes.
- Added **Seedance 2.0** & **Seedance 2.0 Fast** video generation models
(pricing adjusted with 20% service fee).
- Expanded AIGC parameter support for image and video generation.
- Improved model type normalization for better provider compatibility.
- Multi-media and multiple connection mode support for ComfyUI
integration.

### Desktop Improvements

- **Embedded CLI** in the desktop app with PATH installation support.
- Added Electron version display in system tools settings.
- Fixed RuntimeConfig instant-apply working directory with recent list.
- Fixed desktop locale restore — now uses stored URL parameter instead
of system locale.
- Improved remote re-auth for batched tRPC and clean OIDC on gateway
disconnect.

### Stability, Security, and UX Fixes

- **Security**: prevented path traversal in
`TempFileManager.writeTempFile`; patched IDOR in
`addFilesToKnowledgeBase`; upgraded `better-auth` with hardened
`humanIntervention` requirement in builtin-tool-activator.
- **Context engine**: added `typeof` guard before `.trim()` calls to
prevent runtime crashes.
- **Agent runtime**: preserved reasoning state across OpenAI providers;
fixed service error serialization producing `[object Object]`; surfaced
error `reasonDetail` in `agent_runtime_end` events.
- **Knowledge Base**: cleaned up vector storage when deleting knowledge
bases.
- **Templates**: allow templates to specify `policyLoad` so default docs
are fully injected.
- **Skills**: inject current agents information when `lobehub_skill` is
activated; filter current agent out of available agents list; fix
`agents_documents` overriding `systemRole`.
- **Google Tools**: use `parametersJsonSchema` for Google tool schemas.
- **Web Crawler**: prevent happy-dom CSS parsing crash in
`htmlToMarkdown`.
- **Mobile/UI**: fixed video page icon collision, missing locale keys,
model query param; hidden LocalFile actions on topic share page; allow
manual close of hidden builtin tools.
- **Auth**: `ENABLE_MOCK_DEV_USER` now supported in `checkAuth` and
openapi auth middleware.
- **Sandbox**: stopped using `sanitizeHTMLContent` to block scripts &
sandbox styles.

### Refactors

- Library/resource tree store for hierarchy and move sync.
- Removed legacy `messageLoadingIds` from chat store.
- Removed promptfoo configs and dependencies.
- `OnboardingContextInjector` wired into context engine.

### Credits

Huge thanks to these contributors (alphabetical):

@arvinxx @canisminor1990 @cy948 @hardy-one @hezhijie0327 @Innei
@MarcellGu @ONLY-yours @rdmclin2 @rivertwilight @sxjeru @tjx666
2026-04-10 17:48:33 +08:00
Arvin Xu b95720d210 🐛 fix: add typeof guard before .trim() calls in context engine (#13715)
Add `typeof !== 'string'` checks before `.trim()` calls in BaseSystemRoleProvider,
SystemRoleInjector, and BaseProcessor to prevent TypeError when a non-string truthy
value (e.g. object, array, number) is passed at runtime.
2026-04-10 14:21:18 +08:00
Marcell Gu 560ec57f75 🐛 fix: changed builtin-tool-activator's humanIntervention to require & upgraded better auth (#13682)
* fix(builtin-tool-activator): add humanIntervention required field to activateTools manifest

- Add humanIntervention: "required" to the activateTools API manifest
- Update better-auth dependency from 1.4.6 to 1.4.9 (GHSA-xg6x-h9c9-2m83, 分数: 7.4)

* Downgrade better-auth version to 1.4.6

Thanks for your correction.
2026-04-10 14:20:51 +08:00
Arvin Xu dbca232e35 feat: support regenerateUserMessage in gateway mode (#13711)
*  feat: add gateway mode branch to regenerateUserMessage

When gateway mode is enabled, regenerateUserMessage now calls
executeGatewayAgent with parentMessageId instead of running
internal_execAgentRuntime locally. The server handles branching
and agent execution.

Fixes LOBE-6934

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

* 🐛 fix: switch branch before gateway regeneration and keep operation open

- Move switchMessageBranch before the gateway/client branch so
  activeBranchIndex is advanced and the UI shows the new response
  immediately (fixes regression from client path)
- Add onComplete callback to executeGatewayAgent so callers can
  run cleanup when the gateway session finishes
- Keep regenerate operation running until onComplete fires,
  preventing duplicate concurrent regenerations via isMessageRegenerating

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 13:23:19 +08:00
Zhijie He c879629439 feat: add prompt rewrite & translate feat (#13523) 2026-04-10 12:33:50 +08:00
Zhijie He 1ecf7d2be8 💄 style(image,video): extend more AIGC params support (#13597)
* 🐛 fix(image,video): preserve prompt and image when switching model

*  feat(image): smart imageUrl ↔ imageUrls conversion on model switch

- When switching from multi-image to single-image model: use imageUrls[0] as imageUrl
- When switching from single-image to multi-image model: wrap imageUrl into [imageUrl] as imageUrls
- Preserves prompt and other compatible parameters
- Add test cases for bidirectional conversion

♻️ refactor(image): simplify preserveImageInputParams logic

- Remove intermediate variables for cleaner code readability
- Condense 9 intermediate variables to 3 core ones
- Inline condition checks for simpler if statements
- Improve code clarity without changing functionality

* 🐛 fix(image): preserve imageUrl when target imageUrls default is empty array

* chore: format imageUrl & imageUrls

* feat: support imageUrls for videoGen

fix: fix ci error

fix: fix ci error

fix: fix + button

fix: fix batch images display

fix: fix muti images upload display

fix: fix ci error

style: add Seedance 2.0 support

style: add Seedance 2.0 support

fix: fix veo imageUrls logic

* style: add watermark & prompt_extend & web_search support

style: update minimax & seedream price

style: fix fix ui error

style: update z-image

style: fix video ui

style: fix seedance & seedream params

style: fix seedance & seedream params

style: fix seedance & seedream params

fix ci error

Update createImage.ts

fix ci error

fix ci error

fix ci error

fix ci error

fix ci error

fix ci error

fix: fix optimize_prompt_options

* fix rebase issue

* fix: seedance 2.0 price missing

* fix: apply some suggestions
2026-04-10 11:50:22 +08:00
LobeHub Bot 8b5aaeebdf 🌐 chore: translate non-English comments to English in comfyui (#13712)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 11:10:11 +08:00
CanisMinor 4787bed380 💄 style: Update agent onboarding style (#13678)
* 💄 style: Update onboarding

* style: update

* 💄 style: Update i18n

* fix: test
2026-04-10 10:44:09 +08:00
Hardy 5f25efd54c feat: add GLM-5.1 model and fix KimiCodingPlan issues (#13700)
* 🐛 fix: fix Kimi K2.5 model icon display by using deploymentName

- Change model id from 'k2p5' to 'kimi-k2.5' to match Moonshot icon keywords
- Add deploymentName 'k2p5' for API calls to use original model name
- Add KimiCodingPlan to providersWithDeploymentName list

This allows the model icon to display correctly while maintaining
backward compatibility with the API using the original 'k2p5' name.

* 🐛 fix: normalize messages for KimiCodingPlan thinking models

Add message normalization for Kimi K2.5 and K2 Thinking models to ensure
every assistant message has a thinking block when thinking is enabled.

This fixes the issue where regenerating with KimiCodingPlan after using
other providers would fail with "thinking is enabled but reasoning_content
is missing" error, because historical messages from other providers don't
have reasoning fields.

The normalization adds a placeholder thinking block when:
1. Thinking is enabled for Kimi K2.5/K2 Thinking models
2. Assistant message doesn't have reasoning content

*  feat(siliconcloud): add GLM-5.1 model support

Add GLM-5.1 (Pro) model configuration with:
- 198K context window
- Function call and reasoning capabilities
- Tiered pricing (0-32k / 32k+)
- reasoningBudgetToken32k extension parameter

* 🐛 fix: use hardcoded maxOutput mapping for KimiCodingPlan models

Replace getModelPropertyWithFallback with a simple hardcoded mapping to fix
the issue where max_tokens lookup fails when using deploymentName (k2p5).

The model id is converted to deploymentName in ChatService layer before
reaching the provider, causing getModelPropertyWithFallback('k2p5', ...) to
fail since the model card uses id 'kimi-k2.5'.

By using a hardcoded mapping that supports both model id and deploymentName,
we avoid the lookup issue while keeping the code simple (KimiCodingPlan only
has a few models).

*  test(kimiCodingPlan): add tests for thinking and max_tokens handling

Add comprehensive tests for KimiCodingPlan provider covering:
- Hardcoded maxOutput mapping for k2p5, kimi-k2.5, kimi-k2-thinking
- Thinking parameter handling for kimi-k2.5 and kimi-k2-thinking models
- Message normalization with forceThinking for assistant messages
- Tool calls with reasoning content to prevent API error

*  test(kimiCodingPlan): add tests for thinking and max_tokens handling

Add comprehensive tests for KimiCodingPlan provider covering:
- Hardcoded maxOutput mapping for k2p5, kimi-k2.5, kimi-k2-thinking
- Thinking parameter handling for kimi-k2.5 and kimi-k2-thinking models
- Message normalization with forceThinking for assistant messages
- Tool calls with reasoning content to prevent API error
2026-04-10 10:41:06 +08:00
Rylan Cai c85be1265f 🐛 fix:(agent-runtime): keep reasoning state in openai providers (#13701)
* 🐛 fix: preserve assistant reasoning in runtime state

* 🐛 fix: preserve agent reasoning and cached usage conversion

* 💬 docs: move usage retention comment to helper

* ♻️ refactor: remove redundant any cast in runtime executor

* 🐛 filter non-finite OpenAI usage values
2026-04-10 10:19:08 +08:00
Innei 4f1d2d494f feat(conversation): assistant group workflow collapse and activate-tools inspector (#13696)
* refactor(workflow): rewrite WorkflowSummary with status dot and minimal flat style

* refactor(workflow): rewrite WorkflowCollapse with unified borderless container

*  feat(workflow): add WorkflowExpandedList component and fix type errors

* ♻️ refactor(workflow): add missing Workflow components with Minimal Flat design

- WorkflowReasoningLine: cssVar tokens, aligned padding
- WorkflowToolDetail: new expandable result panel with motion animation
- WorkflowToolLine: expand chevron, getToolColor, detail panel integration
- WorkflowExpandedList: flat rendering with reasoning + tool lines

* Add tool call collapse support

Made-with: Cursor

* 💄 style(workflow): align WorkflowCollapse UI with @lobehub/ui design system

- Align border-radius, gap, padding tokens across all Workflow components
- Replace chevron expand/collapse with status icons (CheckCircle2, CircleX, Loader2)
- Use @lobehub/ui Highlighter for tool detail panel with JSON auto-formatting
- Use @lobehub/ui Flexbox for WorkflowExpandedList with proper gap and padding
- Fix delete action to use removeToolFromMessage instead of deleteAssistantMessage
- Wire debug button to existing Tool/Debug panel with full tabs
- Fix auto-collapse to only trigger on incomplete→complete transition
- Single ChevronDown with rotation for WorkflowSummary (match @lobehub/ui pattern)

* 💄 style(workflow): use AccordionItem and inspectorTextStyles for WorkflowCollapse

- Replace custom WorkflowSummary with @lobehub/ui AccordionItem
- Use StatusIndicator pattern (Block outlined 24x24) for status icon
- Apply inspectorTextStyles.root for title text (colorTextSecondary)
- Remove WorkflowSummary.tsx (dead code)
- Match Tool component AccordionItem usage (paddingBlock/Inline=4, borderless)

* 💄 style(workflow): remove divider and gap from WorkflowExpandedList

* 💄 style(workflow): align WorkflowCollapse title bar with Thinking component

* 💄 style(workflow): unify inner item spacing, font size, and colors

*  feat(workflow): add streaming scroll behavior with max-height and auto-scroll

* 💄 refactor(assistant-group): refine workflow collapse UI and duration

- Use Accordion for collapse; align tool/reasoning lines with generation state
- Show workflow header duration from summed block performance, not reasoning only

Made-with: Cursor

*  feat(inspector): enhance ActivateToolsInspector to display not found tools count

- Added localization for not found tools message in English, Chinese, and default locales.
- Updated ActivateToolsInspector to show a tooltip with the count of tools not found.
- Modified StatusIndicator to support a warning state for scenarios where no tools are activated but some are not found.

Signed-off-by: Innei <tukon479@gmail.com>

* 💄 style(workflow): simplify padding in WorkflowExpandedList component

- Removed unnecessary paddingInline from Flexbox elements in WorkflowExpandedList for cleaner layout.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(assistant-group): introduce constants and utility functions for workflow management

- Added constants for workflow timing, limits, and tool display names to enhance the assistant group's functionality.
- Implemented utility functions for processing and scoring post-tool answers, improving the workflow's response handling.
- Created new components for rendering content blocks and managing scroll behavior in the assistant group.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(assistant-group): enhance ContentBlock and Group components with content handling logic

- Added logic to conditionally render message content based on content availability and tool presence in ContentBlock.
- Introduced utility functions to determine substantive content and reasoning in Group, improving block partitioning for workflow management.
- Updated partitioning logic to handle trailing reasoning candidates and streamline answer and working block separation.

Signed-off-by: Innei <tukon479@gmail.com>

* 🙈 chore(gitignore): clarify superpowers local paths

Document that `.superpowers/` and `docs/superpowers/` are plugin/local outputs
and must not be committed.

Made-with: Cursor

* 👷 chore(ci): restore auto-tag-release workflow from canary

Revert unintended workflow edits so release tagging stays on main with
sync-main-to-canary dispatch.

Made-with: Cursor

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-10 02:00:38 +08:00
Innei 3b81a94d76 🐛 fix(kb): clean up vector storage when deleting knowledge bases (#13254)
* 🐛 feat(db): add findExclusiveFileIds, deleteWithFiles, deleteAllWithFiles to KnowledgeBaseModel

Add methods to safely clean up vector storage when deleting knowledge bases:
- findExclusiveFileIds: identifies files belonging only to a specific KB
- deleteWithFiles: deletes KB and its exclusive files with chunks/embeddings
- deleteAllWithFiles: bulk version for deleting all user KBs

* 🐛 fix(kb): wire vector cleanup in TRPC router, OpenAPI service, and client

- TRPC removeKnowledgeBase: use deleteWithFiles when removeFiles=true + S3 cleanup
- TRPC removeAllKnowledgeBases: use deleteAllWithFiles + S3 cleanup
- OpenAPI deleteKnowledgeBase: use deleteWithFiles + S3 cleanup
- Client service: default removeFiles=true when deleting knowledge base

* 🐛 fix(knowledgeBase): change default behavior of deleteKnowledgeBase to not remove files and update related tests

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(knowledgeBase): add optional query parameter to deleteKnowledgeBase for file removal

- Introduced `removeFiles` query parameter to control the deletion of exclusive files and derived data when deleting a knowledge base.
- Updated `KnowledgeBaseController`, `KnowledgeBaseService`, and related schemas to support this new functionality.

This change enhances the flexibility of the delete operation, allowing users to choose whether to remove associated files.

Signed-off-by: Innei <tukon479@gmail.com>

* 🐛 fix: cascade knowledge base deletion and add orphan cleanup runbook

*  feat(knowledgeRepo): implement cascading deletion for file-backed documents

- Enhanced the `KnowledgeRepo` to ensure that when a document with an associated file is deleted, all related data (files, chunks, embeddings) are also removed.
- Introduced a new method `deleteDocumentWithRelations` to handle the cascading deletion logic.
- Updated tests to verify that all related entities are deleted when a file-backed document is removed.

This change improves data integrity by ensuring that no orphaned records remain after deletions.

Signed-off-by: Innei <tukon479@gmail.com>

* Defer DocumentService file initialization

* Fix flaky database tests and knowledge repo fixtures

* Add deletion regression tests for folders and external files

*  chore: remove kb orphan cleanup files from pr

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-10 01:56:05 +08:00
Arvin Xu a4d9967e60 🐛 fix: gateway not receiving error reasonDetail in agent_runtime_end event (#13707)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 01:51:19 +08:00
Arvin Xu 6a40eb8a3b 🐛 fix: resolve agent runtime service error serialization producing [object Object] (#13704)
 feat: add remote snapshot fetch for agent-tracing CLI and fix error serialization
2026-04-10 00:01:01 +08:00
Arvin Xu a23e159ef3 🔨 chore: extend execAgent with parentMessageId for Gateway regeneration/continue (#13699)
* 🌐 chore: update execServerAgentRuntime i18n copy

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

*  feat: extend execAgent with parentMessageId for regeneration/continue via Gateway

Add parentMessageId support to the execAgent API, enabling regeneration and continue-generation flows through the Gateway WebSocket path. When parentMessageId is provided, user message creation is skipped (resume mode) and the new assistant message branches from the specified parent.

Fixes LOBE-6933

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

* 🐛 fix: propagate parentMessageId through execAgents batch and fix test types

- Forward parentMessageId in execAgents executeTask to maintain batch parity with execAgent
- Fix ExecAgentResult mock types in gateway tests
- Fix messages table insert type cast in server router test

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 21:51:59 +08:00
Arvin Xu 1eb1fca7f2 🌐 chore: update execServerAgentRuntime i18n copy (#13698)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 18:52:07 +08:00
sxjeru 4100f2f700 🐛 fix: enhance model type normalization (#13548)
* feat(modelParse): enhance model type normalization and add tests for invalid types

* feat(modelParse): optimize imports and improve model type handling
2026-04-09 18:46:14 +08:00
Arvin Xu 23f91d044c 🐛 fix: buffer and deduplicate events during gateway resume (#13689)
* 🐛 fix: buffer and deduplicate events during resume to prevent out-of-order display

When reconnecting with empty lastEventId (page reload), live broadcast
events can arrive before resume replay completes, causing content to
appear out of order. Now AgentStreamClient enters resume mode: buffers
all events, waits for a 500ms gap (resume replay is dense, live events
are sparse), then deduplicates by event ID and emits in order.

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

* 🐛 fix: clear runningOperation on agent finish + resume timeout for completed sessions

- RuntimeExecutors.finish clears topic metadata.runningOperation when
  agent reaches terminal state, so stale entries don't trigger reconnect
- AgentStreamClient resume mode: add 3s timeout for empty buffer —
  if no events arrive after resume request, session has already completed,
  emit session_complete and disconnect

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

* 🐛 fix: eagerly fetch messages after topic switch to avoid skeleton flash

After switchTopic in Gateway mode, immediately fetch messages from DB
and replace in store, so the UI renders content right away instead of
showing a skeleton loading state while SWR re-fetches.

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

* 🐛 fix: eliminate skeleton flash on gateway topic switch

Match the client-mode pattern: fetch messages from DB and replaceMessages
BEFORE calling switchTopic with skipRefreshMessage: true. This ensures
messages are already in the store when the topic switches, preventing
a skeleton loading flash.

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

* 🐛 fix: flush resume buffer on session_complete before disconnect

session_complete is a top-level ServerMessage (not an agent_event), so
it bypassed the resume buffer. When it arrived during resume mode,
disconnect() cleared the buffer and all replayed events were lost.

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

* 🐛 fix: limit resume buffering to explicit reconnect scenarios only

Resume mode was triggered for ALL new connections (lastEventId always
empty on first connect), delaying live streaming for normal operations.

Now resume buffering requires explicit opt-in via resumeOnConnect option,
which is only set by reconnectToGatewayOperation (page-reload reconnect).
Normal executeGatewayAgent connections stream events immediately.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 16:26:21 +08:00
LiJian 06ac87dc45 🐛 fix: should inject current agnets information when actived the lobehub_skill (#13661)
* fix: should inject current agnets information when actived the lobehub skill

* fix: not inject the agent systemRole in lobehub skill inject

* fix: should use the isLobeHubSkillActive hook to judge

* fix: change the tools inject to vars replace function

* fix: add the lost topic id & agent title

* fix: later the PlaceholderVariablesProcessor

* fix: update the description
2026-04-09 16:11:18 +08:00
Zhijie He 6d731dd116 feat: add StreamLake Provider support (#13651)
*  feat: add StreamLake (快手) support

* style: add thinking support

style: add thinking support

style: add thinking support

style: add thinking support

style: add thinking support
2026-04-09 15:00:50 +08:00
LobeHub Bot f804d0fc7c 🌐 chore: translate non-English comments to English in scripts (#13690)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 14:38:29 +08:00
Arvin Xu b268f44f06 🐛 fix(server): prevent path traversal in TempFileManager.writeTempFile (#13684)
🐛 fix(server): prevent path traversal in TempFileManager.writeTempFile

Use path.basename() to strip directory components from user-supplied
filenames before writing temp files, preventing arbitrary file write
via crafted filenames like "../../app/startServer.js".

Fixes LOBE-6904

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 14:35:20 +08:00
Rdmclin2 475622a4b9 feat: support multi media and multiple connection mode (#13624)
* test: add feishu and qq test cases

* feat: support qq websocket mode

* feat: support slack websocket mode

* feat: feishu/lark support websocket connectMode

* chore: add default connection mode

* fix: discord 401 sign error

* fix: feishu websocket need verification token

* fix: heartbeate interval

* fix: get effective connnection mode

* chore: extract  getEffectiveConnectionMode utils

* chore: merge with default settings

* chore: add connectionMode fallback

* fix: file extract error

* fix: list platforms by connectionMode

* fix: qq bot gateway

* fix: support fileList

* feat: support video list

* chore: migrate local testing to references

* chore: add bot skill

* fix: telegram file serialize error

* feat: extract file extract logic to platform client

* fix: wechat file read

* feat: skip no metion in thread and set default message mode to queue

* chore: refact download resources

* fix: feishu adapter mention and dm error

* fix: feishu thread id

* fix: slack remove action

* fix: bot resovle files
2026-04-09 14:16:03 +08:00
René Wang 7b40538486 feat: add iamge (#13688) 2026-04-09 10:33:08 +08:00
Arvin Xu 5531ff7907 🔨 chore: Gateway reconnect after page reload (#13685)
*  feat: persist runningOperation to topic metadata for gateway reconnect

- Add runningOperation field to ChatTopicMetadata type
- execAgent writes { operationId, assistantMessageId } to topic metadata
  after creating the operation
- onSessionComplete clears runningOperation from metadata (best-effort)
- Extend updateTopicMetadata tRPC schema + service to support the field

Fixes LOBE-6905

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

*  feat: add refreshGatewayToken tRPC endpoint

Signs a fresh JWT for Gateway WebSocket reconnection after page reload.
The token is scoped to the authenticated user via signUserJWT.

Fixes LOBE-6906

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

*  feat: auto-reconnect to running Gateway operation on topic load

- Add reconnectToGatewayOperation to GatewayActionImpl — refreshes JWT,
  creates local operation, and connects WebSocket with event replay
- Add useGatewayReconnect hook — checks topic metadata.runningOperation
  when entering a topic and triggers reconnection
- Wire hook into ConversationArea

Fixes LOBE-6907

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

* 🐛 fix: preserve thread scope in reconnect context and subscribe to topic metadata

- Store scope + threadId in topic metadata.runningOperation
- reconnectToGatewayOperation uses stored scope/threadId instead of
  hardcoded main/null
- useGatewayReconnect subscribes to runningOperation via useChatStore
  selector so it triggers when topic data arrives from SWR (not just
  on mount when data may be empty)

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

* 🐛 fix: update device tests to allow runningOperation metadata writes

The tests asserted updateMetadata was never called, but now execAgent
persists runningOperation. Changed to assert no device-binding metadata
was written (boundDeviceId), which is the actual intent.

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

* ♻️ refactor: use SWR for gateway reconnect lifecycle

Replace useEffect + ref with useSWR keyed by operationId. SWR
naturally deduplicates (same key = no re-fetch), handles the async
reconnect, and doesn't fire when key is null (no runningOperation).

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

* 🐛 fix: validate topic has running operation before issuing gateway token

refreshGatewayToken now requires topicId, verifies the topic belongs to
the user and has a runningOperation in metadata before signing a JWT.

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

* 💄 style: break signin title into two lines

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

* Fix signin.title formatting in auth.json

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 10:23:57 +08:00
Arvin Xu 4f56868545 🐛 fix: allow templates to specify policyLoad so default docs are fully injected (#13672)
* 🐛 fix: allow templates to specify policyLoad so default docs are fully injected

All documents were hardcoded to PolicyLoad.PROGRESSIVE on creation,
causing CLAW template docs (IDENTITY, SOUL, BOOTSTRAP, AGENTS) to be
progressively disclosed instead of fully injected into context.

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

* 🐛 fix: forward policyLoad through upsertDocument and persist on update

- Add policyLoad to UpsertDocumentParams and pass it through to model
- Add policyLoad param to update() so upsert's existing-document path
  writes the value instead of silently discarding it
- Ensures re-running template init migrates pre-existing docs to ALWAYS

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

* ♻️ refactor: change update() to use named params object instead of positional args

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

* ♻️ refactor: change create() and upsert() to use named params object

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

*  test: improve agentDocuments test coverage to 99%

Add tests for uncovered branches:
- normalizeLoadRule default branch (unknown rule)
- explicit 'always' rule match
- by-time-range with NaN dates
- resolveDocumentLoadPosition fallback paths
- composeToolPolicyUpdate with existing context values
- upsert create path for new filenames
- getAgentContext empty docs path

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

* 🐛 fix: preserve policyLoad when copying documents

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

*  fix: align test assertion with refactored create() params object signature

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 10:09:05 +08:00
Arvin Xu dc1b43d86c 🐛 fix(database): prevent IDOR in addFilesToKnowledgeBase (#13683)
🐛 fix(database): add ownership check in addFilesToKnowledgeBase to prevent IDOR

Verify that the target knowledge base belongs to the authenticated user
before inserting files, preventing unauthorized file injection into
other users' knowledge bases.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 01:36:51 +08:00
Arvin Xu 4d7cbfea8e 🐛 fix: skip sendMessageInServer in Gateway mode + NavItem loading fix + i18n (#13681)
* 🐛 fix: reuse existing messages in execAgent when existingMessageIds provided

When existingMessageIds contains [userMsgId, assistantMsgId], skip
creating new messages and reuse the existing ones. This fixes duplicate
messages in Gateway mode where sendMessageInServer already created
the messages before execAgentTask is called.

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

* 🐛 fix: allow clicking NavItem while loading

Loading state should only show a visual indicator, not block onClick.
This fixes topic sidebar items being unclickable during agent execution.

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

* Revert "🐛 fix: reuse existing messages in execAgent when existingMessageIds provided"

This reverts commit 43b808024d5c4a0074b692a85083a72046ab47e0.

* 🐛 fix: skip sendMessageInServer in Gateway mode to avoid duplicate messages

Gateway mode now calls execAgentTask directly instead of going through
sendMessageInServer first. The backend creates user + assistant messages
and topic in one call. executeGatewayAgent handles topic switching
internally after receiving the server response.

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

* 🌐 chore: add i18n for execServerAgentRuntime operation

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

* 🐛 fix: move temp message cleanup after executeGatewayAgent succeeds

Keep temp messages visible during the gateway call so the UI isn't
blank. On failure, mark the operation as failed instead of silently
returning — temp messages remain so the user sees something went wrong.

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

* ♻️ refactor: remove manual temp message cleanup in gateway mode

switchTopic handles new topic navigation, and fetchAndReplaceMessages
replaces the message list from DB — no need to manually delete temp
messages.

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

* 🐛 fix: clear _new key temp messages when gateway creates new topic

Pass clearNewKey: true to switchTopic so temp messages from the
optimistic create don't persist in the _new key after switching
to the server-created topic.

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

* ♻️ refactor: import ExecAgentResult from @lobechat/types

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 01:33:54 +08:00
Innei e65e2c3628 feat(desktop): embed CLI in app and PATH install (#13669)
*  feat(desktop): embed CLI in app and PATH install

Made-with: Cursor

*  feat(desktop): add CLI command execution feature and UI integration

- Implemented `runCliCommand` method in `ElectronSystemService` to execute CLI commands.
- Added `CliTestSection` component for testing CLI commands within the app.
- Updated `SystemCtr` to include CLI command execution functionality.
- Enhanced `generateCliWrapper` to create short aliases for CLI commands.
- Integrated CLI testing UI in the system tools settings page.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: enhance working directory handling for desktop

- Updated working directory logic to prioritize topic-level settings over agent-level.
- Introduced local storage management for agent working directories.
- Modified tests to reflect changes in working directory behavior.
- Added checks to ensure working directory retrieval is only performed on desktop environments.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(desktop): implement CLI command routing and cleanup

- Introduced `CliCtr` for executing CLI commands, enhancing the desktop application with CLI capabilities.
- Updated `ShellCommandCtr` to route specific commands to `CliCtr`, improving command handling.
- Removed legacy CLI path installation methods from `SystemCtr` and related services.
- Cleaned up localization files by removing obsolete entries related to CLI path installation.

Signed-off-by: Innei <tukon479@gmail.com>

* 🚸 settings(system-tools): show CLI embedded test only in dev mode

Made-with: Cursor

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-09 00:53:49 +08:00
Arvin Xu eebf9cb056 chore: add gatewayMode translations for labs (#13680)
* 🌐 i18n: add gatewayMode translations for labs

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

* Update labs.json

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 23:49:32 +08:00
Arvin Xu 3e7ee1fbfc 🔨 chore: integrate Gateway connection management into chat store (#13636)
*  feat: integrate Gateway connection management into chat store

Add GatewayActionImpl to aiChat slice for managing Agent Gateway
WebSocket connections per operationId. Includes connect, disconnect,
interrupt, and status tracking. Also type the execAgentTask return value.

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

*  feat: add Gateway mode branch in sendMessage for server-side agent execution

When agentGatewayUrl is set in server config (enableQueueAgentRuntime),
sendMessage now triggers server-side agent execution via execAgentTask
and receives events through the Agent Gateway WebSocket, instead of
running the agent loop client-side.

Includes:
- Expose agentGatewayUrl in GlobalServerConfig when queue mode is enabled
- Gateway event handler mapping stream events to UI message updates
- Fallback to client-side agent loop when Gateway is not configured

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

* 🐛 fix: emit disconnected event on intentional disconnect

disconnect() was only calling setStatus('disconnected') but not emitting
the 'disconnected' event. This caused the store's cleanup listener to
never fire after terminal events (agent_runtime_end), leaving stale
connections in gatewayConnections.

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

*  feat: enhance Gateway event handler for multi-step agent streaming

Support multi-step agent execution display (LLM → tool calls → next LLM)
using hybrid approach: real-time streaming for current step, DB refresh at
step transitions.

Fixes LOBE-6874

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

*  feat: wire up Gateway JWT token from execAgent to connectToGateway

Pass the RS256 JWT token returned by execAgentTask to connectToGateway
for WebSocket authentication. Also use ExecAgentResult from @lobechat/types
instead of local duplicate definition.

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

* 🐛 fix: handle wss:// protocol in AgentStreamClient buildWsUrl

When gatewayUrl already uses ws:// or wss:// protocol, use it directly
instead of stripping and re-adding the protocol prefix. Previously,
wss://host would become ws://wss://host (double protocol).

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

* 🐛 fix: queue gateway events to ensure stream_chunk waits for refreshMessages

Use a sequential Promise chain to process gateway events, so that
stream_chunk dispatches only run after stream_start's refreshMessages
resolves. Previously, chunks arrived before the new assistant message
existed in dbMessagesMap, causing updates to be silently dropped.

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

* 🐛 fix: pass operationId context to internal_dispatchMessage in gateway handler

Without operationId, internal_dispatchMessage falls back to global state
to compute the messageMapKey, which may differ from the key where
refreshMessages stored the server-created messages. Passing operationId
ensures the correct conversation context is resolved.

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

* 🐛 fix: resolve gateway streaming display issues

- Use fetchAndReplaceMessages (direct DB fetch + replaceMessages) instead
  of refreshMessages which mutates an orphaned SWR key
- Create dedicated execServerAgentRuntime operation with correct topicId
  context for internal_dispatchMessage to resolve the right messageMapKey
- Complete operation on agent_runtime_end instead of relying on
  onSessionComplete callback
- Keep loading state active between steps (only clear on agent_runtime_end)
  so users don't think the session ended during tool execution gaps

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

* 🐛 fix: maintain loading state across gateway step transitions

- Create dedicated execServerAgentRuntime operation with correct topicId
- Use fetchAndReplaceMessages instead of orphaned refreshMessages SWR key
- Re-apply loading after tool_end refresh so UI stays active between steps
- Complete operation on agent_runtime_end
- Add record-app-screen.sh for automated screen recording
- Output recordings to .records/ (gitignored)

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

* 🐛 fix: show loading on assistant message immediately in stream_start

Set loading on the current assistant message BEFORE awaiting
fetchAndReplaceMessages, so the UI shows a loading indicator while
waiting for the DB response instead of appearing frozen.

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

* 🐛 fix: drive gateway loading state via operation system instead of messageLoadingIds

Associate the assistant message with the gateway operation via
associateMessageWithOperation so the Conversation store's operation-based
loading detection (isGenerating) works correctly. This shows the proper
loading skeleton on the assistant message while waiting for gateway events.

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

* ♻️ refactor: remove unused internal_toggleMessageLoading from gateway handler

Loading state is now fully driven by the operation system via
associateMessageWithOperation + completeOperation. The old
messageLoadingIds-based approach is no longer needed.

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

* 🐛 fix: rewrite record-app-screen.sh to use CDP screenshot assembly

Replace broken ffmpeg avfoundation live recording (corrupts on kill) with
agent-browser CDP screenshot capture + ffmpeg assembly on stop. This works
reliably on any screen including external monitors.

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

*  feat: add Gateway Mode lab toggle and fix CI type error

- Add enableGatewayMode to UserLabSchema as experimental feature
- Add lab selector and settings UI toggle in Advanced > Labs
- Gateway mode now requires both server config (agentGatewayUrl) AND
  user opt-in via Labs toggle
- Fix TS2322: result.token (string | undefined) → fallback to ''
- Add i18n keys for gateway mode feature

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

*  feat: hide Gateway Mode toggle when agentGatewayUrl is not configured

Only show the lab toggle when the server has AGENT_GATEWAY_URL set,
so users without gateway infrastructure don't see the option.

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

* 💄 style: move Gateway Mode toggle below Input Markdown in labs section

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

* 🐛 fix: remove default AGENT_GATEWAY_URL value and make schema optional

Without an explicit env var, the gateway URL should be undefined so the
lab toggle and gateway mode are not available.

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

* 📝 docs: update SKILL.md to reference record-app-screen.sh

Replace outdated record-gateway-demo.sh references with the renamed
record-app-screen.sh and its start/stop lifecycle documentation.

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

* 📝 docs: add record-app-screen reference doc and slim down SKILL.md

Move detailed recording documentation to references/record-app-screen.md
and keep SKILL.md concise with a link to the full reference.

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

* 🐛 fix: guard GatewayStreamNotifier with AGENT_GATEWAY_URL check

AGENT_GATEWAY_URL is now optional, so check both URL and service token
before wrapping with GatewayStreamNotifier to avoid TS2345.

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

* ♻️ refactor: extract gateway execution logic to GatewayActionImpl

Move server-side gateway execution logic from conversationLifecycle.ts
into GatewayActionImpl.startGatewayExecution(). The sendMessage flow
now does a simple early return when gateway mode is active, keeping
the existing client-mode code path untouched.

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

* ♻️ refactor: split gateway into isGatewayModeEnabled check + executeGatewayAgent

Replace fire-and-forget startGatewayExecution with explicit check/execute
pattern. Caller does: if (check) { await execute(); return; } — giving
proper error handling and clearer control flow.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 23:31:26 +08:00
renovate[bot] 84eff30be1 Update dependency lucide-react to ^0.577.0 (#13580)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-04-08 23:31:20 +08:00
Innei 50a1cc1ec2 ♻️ refactor(resource): tree store for library hierarchy and move sync (#13640)
*  feat(ResourceManager): integrate tree store for folder management and enhance file operations

- Added `useTreeStore` to manage folder structure and state, replacing previous file store dependencies.
- Updated `EmptyPlaceholder` to utilize `currentFolderId` for file uploads.
- Refactored `MoveToFolderModal` to use tree store for moving items, improving folder navigation.
- Enhanced drag-and-drop functionality in `DndContextWrapper` to support moving items between folders.
- Removed obsolete `LibraryHierarchy` state management, streamlining folder operations.
- Improved file renaming and deletion processes to ensure tree state consistency.

This update enhances the overall file management experience by leveraging a dedicated tree store for better performance and maintainability.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(TreeAction): enhance resource movement and update handling

- Updated mutation logic for moving resources to differentiate between items visible in the Explorer and those not visible, improving performance and user experience.
- Added refresh functionality for the file list after resource updates (move, update, delete) to ensure the Explorer reflects the latest state.
- Refactored mutation methods to use async/await for better readability and error handling.

This update streamlines resource management within the tree structure, ensuring a more responsive and consistent user interface.

Signed-off-by: Innei <tukon479@gmail.com>

* Fix file updates and tree move fallback regressions

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-08 23:26:58 +08:00
Arvin Xu d49aba748e 🐛 fix: hide LocalFile actions in topic share page (#12254)
🐛 fix: hide LocalFile actions (Open/Show in Folder) in share page

In topic share pages, the LocalFile component was showing 'Open' and
'Show in Folder' action buttons on hover, which are desktop-only
operations not available to share page viewers.

- Add 'readonly' prop to LocalFile component to disable interactive actions
- Detect share page context via topicShareId in LocalFile Render plugin
- Skip Popover rendering when readonly is true
2026-04-08 22:45:08 +08:00
Arvin Xu 8a0c3cb36a ♻️ refactor: remove legacy messageLoadingIds from chat store (#13662)
* ♻️ refactor: remove legacy messageLoadingIds from chat store

The messageLoadingIds state and internal_toggleMessageLoading action in the
chat store have been fully superseded by the operation system. The state was
being written to but never read by any consumer — all UI components and
selectors already use operation-based selectors (isMessageGenerating,
isMessageProcessing, etc.).

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

* 📝 chore: update skill docs to remove messageLoadingIds references

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

* 🐛 fix: replace messageLoadingIds with operationSelectors in generation action

The Conversation store's regenerateUserMessage was reading messageLoadingIds
from the chat store to check if a message is already being processed. Replace
with operationSelectors.isMessageProcessing which is the correct way to check
operation state.

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

* 🐛 fix: add operationsByMessage to test mocks for operation selector

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 21:54:11 +08:00
LiJian 26d1d6bbfb 🐛 fix: slove the agents_documents will coverd the systemRole (#13667)
fix: slove the agents_documents will coverd the systemRole
2026-04-08 20:54:20 +08:00
YuTengjing c5ec0ef2a1 💰 chore: adjust Seedance 2.0 pricing with 20% service fee (#13676) 2026-04-08 20:50:18 +08:00
YuTengjing 6d0c8d710a 🐛 fix: video page icon collision, missing locale keys, and model query param (#13671) 2026-04-08 19:44:35 +08:00
Rdmclin2 e10265fadd feat: add skill panel and fix skill icon (#13666)
* fix: custom agent skill icon

* feat: support skill detail

* chore: remove unnecessary custom tag
2026-04-08 18:51:01 +08:00
Arvin Xu c68dfa00df feat(cli): add lh notify command for external agent callbacks (#13664)
*  feat(cli): add `lh notify` command for external agent callbacks

Add a new `lh notify` CLI command and server-side TRPC endpoint that allows
external agents (e.g. Claude Code) to send callback messages to a topic and
trigger the agent loop to process them.

Fixes LOBE-6888

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

* 🔧 chore(cli): replace sessionId with agentId and threadId in notify command

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 18:03:55 +08:00
Arvin Xu b6a47debfd ♻️ refactor: remove promptfoo configs and dependencies (#13665)
♻️ refactor: remove promptfoo configs and dependencies from packages

Migrate all prompt evaluation tests to the cloud repo's agent-evals framework.
Remove promptfoo directories, configs, dependencies, and generator scripts
from @lobechat/prompts, @lobechat/memory-user-memory, and @lobechat/builtin-tool-memory.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 17:50:55 +08:00
YuTengjing 147ff3976f feat: add Seedance 2.0 & 2.0 Fast video generation models (#13663) 2026-04-08 17:39:50 +08:00
René Wang 034c7c203b feat: changelog (#13634)
* feat: changelog

* feat: edito content
2026-04-08 15:30:33 +08:00
Rdmclin2 b0b6684294 🔨 chore: optimize model and skills (#13659)
* chore: model detail default close

* fix: model detail show info in normal mode
2026-04-08 15:20:35 +08:00
Arvin Xu 36d2427947 🐛 fix: use parametersJsonSchema for Google tool schemas (#13656)
* 🐛 fix: use parametersJsonSchema for Google tool schemas to support full JSON Schema

Replace Google's restrictive Schema subset with parametersJsonSchema, which accepts
standard JSON Schema directly. This eliminates the need for resolveRefs and
sanitizeSchemaForGoogle, fixing nullable enum (LOBE-6607) and $ref (LOBE-6680) issues.

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

* 🐛 fix: update remaining tests to use parametersJsonSchema

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 15:08:59 +08:00
Innei 4d15979fab 💄 fix(RuntimeConfig): instant-apply working directory with recent list (#13641)
* 💄 fix(RuntimeConfig): instant-apply working directory with recent list

Remove Save/Cancel buttons from working directory selector.
Directories now apply immediately on click. Show recent directories
list with checkmark for active selection and "Choose a different folder"
entry at bottom.

*  feat(SystemCtr): enhance folder selection to return repository type

Updated the `selectFolder` method to return an object containing the selected folder path and its repository type (either 'git' or 'github'). Added a new private method `detectRepoType` to determine the repository type based on the presence of a `.git/config` file. Introduced a new utility for managing recent directories, allowing the application to display appropriate icons based on the repository type in the UI.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-08 14:56:18 +08:00
Arvin Xu 53786e30b6 🔨 chore: remove redundant update-status call from GatewayStreamNotifier (#13655)
* ♻️ refactor: remove redundant update-status call from GatewayStreamNotifier

Gateway now handles session completion directly in pushEvent when it
receives agent_runtime_end, so the separate update-status HTTP call
is no longer needed.

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

*  test: update GatewayStreamNotifier tests for removed update-status call

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 14:03:46 +08:00
LiJian 7300b53e99 🐛 fix: not use sanitizeHTMLContent to block the scripts & sandbox styles (#13649)
* fix: not use sanitizeHTMLContent to block the scripts & sandbox styles

* fix: clean the code & remove the allows-popups
2026-04-08 13:34:40 +08:00
Arvin Xu 6f3897a6e8 🔨 chore: generate JWT token for Gateway WebSocket auth in execAgent (#13654)
 feat: generate JWT token for Gateway WebSocket auth in execAgent

Sign a short-lived RS256 JWT via signUserJWT(userId) when creating an agent
operation, and return it in ExecAgentResult.token so the client can
authenticate with the Agent Gateway WebSocket.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 13:28:37 +08:00
Arvin Xu a6e330cfa9 🐛 fix(web-crawler): prevent happy-dom CSS parsing crash in htmlToMarkdown (#13652)
- Disable CSS file loading and JS evaluation in happy-dom Window (root cause)
- Add try-catch around Readability.parse() for defense in depth
- Add regression tests for invalid CSS selectors and external stylesheet links

Closes LOBE-6869

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 12:59:49 +08:00
LobeHub Bot accc173068 🌐 chore: translate non-English comments to English in openapi routes (#13647)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-08 12:50:17 +08:00
Arvin Xu 81ab8aa07b 🔨 chore: support nested subtask tree in task.detail (#13625)
*  feat: support nested subtask tree in task.detail

Replace flat subtask list with recursive nested tree structure.
Backend builds the complete subtask tree in one response,
eliminating the need for separate getTaskTree API calls.

Fixes LOBE-6814

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

* 🐛 fix: return empty array for root subtasks instead of undefined

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

* 📝 docs: add cli-backend-testing skill

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 12:49:26 +08:00
YuTengjing 12ee7c9e9a 🐛 fix: support ENABLE_MOCK_DEV_USER in checkAuth and openapi auth middleware (#13648) 2026-04-08 12:37:27 +08:00
LiJian 8d8b60e4f9 🐛 fix: should filiter the current agents in avaiable agents list (#13644)
* fix: should inject the current agents & remove current agent from avaiable agents list

* fix: delete the current agents blocks
2026-04-08 11:24:53 +08:00
YuTengjing 19aedcdf56 fix: skip @mention for team members in PR assign and issue triage (#13633) 2026-04-08 11:00:19 +08:00
YuTengjing 3bb09e0ef9 feat: enhance linear skill with image extraction and in-progress status (#13629) 2026-04-08 10:58:07 +08:00
Arvin Xu 13fc65faa2 update 2026-04-08 10:53:00 +08:00
Arvin Xu de8761cf29 🐛 fix: import hook types before re-exporting for tsgo compatibility
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 10:52:11 +08:00
Arvin Xu 4f2f0055e1 ♻️ refactor(agent-runtime): improve AgentInstruction types and extract hook event types
- Each instruction interface now extends AgentInstructionBase directly instead of intersection
- Group instructions by category: LLM, Tool, Task, Human Interaction, Control
- Extract AgentHookType and AgentHookEvent into agent-runtime package
- Keep AgentHook, AgentHookWebhook, SerializedHook in server layer (webhook is server-specific)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 10:45:00 +08:00
Arvin Xu 2290929255 🔨 chore: add GraphAgent and agentFactory for graph-driven agent execution (#13643)
*  feat: add GraphAgent and agentFactory for graph-driven agent execution

- Add GraphAgent: a decorator around GeneralChatAgent that drives execution via declarative ReasoningGraph
  - Agent nodes: delegate to GeneralChatAgent for tool-calling loops, then extract structured output
  - LLM nodes: single structured LLM call
  - Programmatic transition evaluation (not LLM-driven)
  - Backtracking with configurable limits
- Add AgentInstruction.stepLabel: allows any Agent to label steps for display in stream events and hooks
- Add agentFactory to AgentRuntimeServiceOptions: external injection of custom Agent implementations
- Add stepLabel propagation: stream_start/stream_end events and afterStep hooks carry the label
- Fix: sanitize null bytes in MessageModel.create content (consistent with existing plugin argument sanitization)

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

* 🐛 fix(agent-runtime): validate graph node existence and preserve transitions at backtrack limit

- Add node existence check in startNode to prevent runtime crash on invalid entry/transition targets
- Evaluate all transitions even when backtrack limit is reached; only suppress actual backtrack targets
2026-04-08 10:28:15 +08:00
Innei a2eab24536 🐛 fix(device-gateway-client): prevent uncaught WebSocket error on disconnect (#13635)
* 🐛(device-gateway-client): prevent uncaught error when closing connecting WebSocket

Detach ws event listeners safely, temporarily handle close-phase errors, and guard ws.close() so logout/token clear does not surface a main-process uncaught exception.

Made-with: Cursor

* 🧹 refactor(tests): remove unused mockProps from ComfyUIForm test

Cleaned up the ComfyUIForm test by removing the unused mockProps object, streamlining the test setup for better clarity and maintainability.

Signed-off-by: Innei <tukon479@gmail.com>

* Hide onboarding finish tool call and preserve close error listener

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-07 23:59:03 +08:00
Innei b279c108b6 🐛 fix(desktop): use stored locale from URL parameter instead of syste… (#13620)
🐛 fix(desktop): use stored locale from URL parameter instead of system language

When the desktop app restarts, the UI language was reverting to the system
language instead of respecting the user's saved language preference.

Root cause: The inline script in index.html was setting document.documentElement.lang
from navigator.language (system language) before i18n initialization could read
the stored locale from Electron store.

Fix: Check the URL's `lng` query parameter first (which is set by Electron main
process from stored settings in Browser.ts:buildUrlWithLocale()), then fall back
to navigator.language.

Fixes #13616

https://claude.ai/code/session_0128LZAbJL1a5vkGboH4U5FP

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-07 22:58:09 +08:00
Innei 7a6fd8e865 🐛 fix(desktop): remote re-auth for batched tRPC and clean OIDC on disconnect (#13614)
* 🐛 fix(desktop): remote re-auth for batched tRPC and clean OIDC on disconnect

- Notify authorization required when X-Auth-Required is set, not only on HTTP 401 (207 batch)
- Show AuthRequiredModal after remote config init; do not gate on dataSyncConfig.active
- Desktop: market 401 only silent refresh; avoid community sign-in UI (AuthRequiredModal handles cloud)
- Disconnect: clearRemoteServerConfig to wipe encrypted OIDC tokens

Made-with: Cursor

* 🐛 Reset user-data Zustand stores on remote disconnect and sync refresh

- Add ResetableStoreAction helper and batched reset via userDataStores
- Wire reset into Electron remote disconnect and refreshUserData
- Handle refreshUserData failures in data sync SWR onSuccess

Made-with: Cursor

* 🐛 fix(useUserAvatar): refactor desktop environment checks to use mockConstEnv

- Replace direct manipulation of mockIsDesktop with mockConstEnv.isDesktop for better encapsulation.
- Update all relevant test cases to utilize the new mock structure, ensuring consistent behavior across tests.

This change improves the clarity and maintainability of the test code.

Signed-off-by: Innei <tukon479@gmail.com>

* 🐛 test: update mocks for ShikiLobeTheme and refactor session/agent mocks

- Added ShikiLobeTheme mock to ComfyUIForm and AddFilesToKnowledgeBase tests for consistent theming.
- Refactored session and agent mocks to use async imports, improving test isolation and performance.

This enhances the clarity and maintainability of the test suite.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-07 22:57:49 +08:00
lobehubbot 7d599a980f 🔖 chore(release): release version v2.1.48 [skip ci] 2026-04-07 14:50:49 +00:00
lobehubbot 1206db7c12 Merge remote-tracking branch 'origin/main' into canary 2026-04-07 14:48:16 +00:00
Arvin Xu bd61b61843 🚀 release: 20260407 (#13626)
# 🚀 release: 20260407

This release includes **148 commits**. Key updates are below.

- **Response API tool execution is more capable and reliable** — Added
hosted builtin tools + client-side function tools and improved tool-call
streaming/completion behavior.
[#13406](https://github.com/lobehub/lobehub/pull/13406)
[#13414](https://github.com/lobehub/lobehub/pull/13414)
[#13506](https://github.com/lobehub/lobehub/pull/13506)
[#13555](https://github.com/lobehub/lobehub/pull/13555)
- **Input and composition UX upgraded** — Added AI input auto-completion
and multiple chat-input stability fixes.
[#13458](https://github.com/lobehub/lobehub/pull/13458)
[#13551](https://github.com/lobehub/lobehub/pull/13551)
[#13481](https://github.com/lobehub/lobehub/pull/13481)
- **Model/provider compatibility improved** — Better Gemini/Google tool
schema handling and additional model updates.
[#13429](https://github.com/lobehub/lobehub/pull/13429)
[#13465](https://github.com/lobehub/lobehub/pull/13465)
[#13613](https://github.com/lobehub/lobehub/pull/13613)
- **Desktop and CLI reliability improved** — Gateway WebSocket support
and desktop runtime upgrades.
[#13608](https://github.com/lobehub/lobehub/pull/13608)
[#13550](https://github.com/lobehub/lobehub/pull/13550)
[#13557](https://github.com/lobehub/lobehub/pull/13557)
- **Security hardening continued** — Fixed auth and sanitization risks
and upgraded vulnerable dependencies.
[#13535](https://github.com/lobehub/lobehub/pull/13535)
[#13529](https://github.com/lobehub/lobehub/pull/13529)
[#13479](https://github.com/lobehub/lobehub/pull/13479)

### Models & Providers

- Added/updated support for `glm-5v-turbo`, GLM-5.1 updates, and
qwen3.5-omni series.
[#13487](https://github.com/lobehub/lobehub/pull/13487)
[#13405](https://github.com/lobehub/lobehub/pull/13405)
[#13422](https://github.com/lobehub/lobehub/pull/13422)
- Added additional ImageGen providers/models (Wanxiang 2.7 and Keling
from Qwen). [#13478](https://github.com/lobehub/lobehub/pull/13478)
- Improved Gemini/Google tool schema and compatibility handling across
runtime paths. [#13429](https://github.com/lobehub/lobehub/pull/13429)
[#13465](https://github.com/lobehub/lobehub/pull/13465)
[#13613](https://github.com/lobehub/lobehub/pull/13613)

### Response API & Runtime

- Added hosted builtin tools in Response API and client-side function
tool execution support.
[#13406](https://github.com/lobehub/lobehub/pull/13406)
[#13414](https://github.com/lobehub/lobehub/pull/13414)
- Improved stream tool-call argument handling and `response.completed`
output correctness.
[#13506](https://github.com/lobehub/lobehub/pull/13506)
[#13555](https://github.com/lobehub/lobehub/pull/13555)
- Improved runtime error/context handling for intervention and provider
edge cases. [#13420](https://github.com/lobehub/lobehub/pull/13420)
[#13607](https://github.com/lobehub/lobehub/pull/13607)

### Desktop App

- Bumped desktop dependencies and runtime integrations (`agent-browser`,
`electron`). [#13550](https://github.com/lobehub/lobehub/pull/13550)
[#13557](https://github.com/lobehub/lobehub/pull/13557)
- Simplified desktop release channel setup by removing nightly release
flow. [#13480](https://github.com/lobehub/lobehub/pull/13480)

### CLI

- Added OpenClaw migration command.
[#13566](https://github.com/lobehub/lobehub/pull/13566)
- Added local device binding support for `lh agent run`.
[#13277](https://github.com/lobehub/lobehub/pull/13277)
- Added WebSocket gateway support and reconnect reliability
improvements. [#13608](https://github.com/lobehub/lobehub/pull/13608)
[#13418](https://github.com/lobehub/lobehub/pull/13418)

### Security

- Removed risky `apiKey` fallback behavior in webapi auth path to
prevent bypass risk.
[#13535](https://github.com/lobehub/lobehub/pull/13535)
- Sanitized HTML artifact rendering and iframe sandboxing to reduce
XSS-to-RCE risk. [#13529](https://github.com/lobehub/lobehub/pull/13529)
- Upgraded nodemailer to v8 to address SMTP command injection advisory.
[#13479](https://github.com/lobehub/lobehub/pull/13479)

### Bug Fixes

- Fixed image generation model default switch issues.
[#13587](https://github.com/lobehub/lobehub/pull/13587)
- Fixed subtopic re-fork message scope behavior and agent panel reset
edge cases. [#13606](https://github.com/lobehub/lobehub/pull/13606)
[#13556](https://github.com/lobehub/lobehub/pull/13556)
- Fixed chat-input freeze on paste and mention plugin behavior.
[#13551](https://github.com/lobehub/lobehub/pull/13551)
[#13415](https://github.com/lobehub/lobehub/pull/13415)
- Fixed auth/social sign-in and settings UX edge cases.
[#13368](https://github.com/lobehub/lobehub/pull/13368)
[#13392](https://github.com/lobehub/lobehub/pull/13392)
[#13338](https://github.com/lobehub/lobehub/pull/13338)

### Credits

Huge thanks to these contributors:

@chriszf @hardy-one @Innei @LiJian @Neko @octopusnote @rdmclin2
@rivertwilight @RylanCai @suyua9 @sxjeru @Tsuki @WangYK @WindSpiritSR
@Yizhuo @YuTengjing @hezhijie0327 @arvinxx
2026-04-07 22:45:54 +08:00
Arvin Xu 0c49b0a039 🔨 chore: add AgentStreamClient for Agent Gateway WebSocket (#13628)
* 🤖 chore(skills): add electron-dev.sh script and update local-testing skill

Add reusable electron-dev.sh script with start/stop/status/restart commands
that reliably manages all Electron processes (main + helpers + vite).
Update SKILL.md to reference the script instead of inline bash commands.

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

*  feat: add AgentStreamClient for Agent Gateway WebSocket communication

Browser-compatible WebSocket client for receiving agent execution events
from the Agent Gateway. Supports auto-reconnect with exponential backoff,
heartbeat keep-alive, and event replay via lastEventId resume.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:42:54 +08:00
Innei 1beb9d4eb6 feat(desktop): add Electron version display in system tools settings (#13630)
*  feat(desktop): add Electron version display in system tools settings

Display Electron, Chrome, and Node.js versions in the desktop app's Settings > System Tools page under a new "App Environment" section.

https://claude.ai/code/session_01C6nUdBci6A29CZCvQSUuDt

* 🐛 fix(desktop): update preload test for new version properties

https://claude.ai/code/session_01C6nUdBci6A29CZCvQSUuDt

* ♻️ refactor: remove unused i18n name keys for app environment section

Tool names (Electron, Chrome, Node.js) are proper nouns that don't need
localization, matching the existing pattern in ToolDetectorSection.

https://claude.ai/code/session_01C6nUdBci6A29CZCvQSUuDt

* 🐛 fix(desktop): handle undefined electron/chrome versions in test env

process.versions.electron and process.versions.chrome are only available
in Electron runtime, not in the Node.js test environment.

https://claude.ai/code/session_01C6nUdBci6A29CZCvQSUuDt

* 🐛 fix: use const assertion for i18n key type safety

https://claude.ai/code/session_01C6nUdBci6A29CZCvQSUuDt

* 🌐 Add app environment strings to setting locales and refine copy

Made-with: Cursor

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-07 21:53:27 +08:00
LiJian 021fd07deb 🐛 fix: can manual close the hidden builtin tools (#13631)
* fix: can manual close the hidden builtin tools

* fix: should change it into chatConfigByIdSelectors

* fix: add the always not close tools
2026-04-07 21:37:32 +08:00
LiJian 33f729cd1a 🐛 fix: add the availableAgents into the prompt inject (#13621)
* fix: add the availableAgents into the prompt inject

* fix: should auto inject the avaiable agents into context when use the auto model

* fix: update the prompt

* fix: test fixed
2026-04-07 19:45:29 +08:00
Innei 8b3c871d08 ♻️ refactor(onboarding): add OnboardingContextInjector and wire context engine (#13518)
* ♻️ refactor(onboarding): add OnboardingContextInjector and wire context engine

Made-with: Cursor

* 🔧 refactor(onboarding): update tool call references to use `lobe-user-interaction________builtin`

Modified onboarding documentation and utility functions to standardize the use of the `lobe-user-interaction________builtin` tool call for structured input collection, enhancing clarity and consistency across the codebase.

Signed-off-by: Innei <tukon479@gmail.com>

* 🔧 refactor(onboarding): standardize tool call references to `lobe-user-interaction____askUserQuestion____builtin`

Updated documentation and utility functions to replace instances of the `lobe-user-interaction________builtin` tool call with `lobe-user-interaction____askUserQuestion____builtin`, ensuring consistency in structured input collection across the onboarding process.

Signed-off-by: Innei <tukon479@gmail.com>

* ♻️ refactor(onboarding): move onboarding context before first user

* ♻️ refactor(context-engine): add virtual last user provider

* update v3

* 🐛 fix(onboarding): add early exit escape hatch for boundary cases

The `<next_actions>` directive only prompted finishOnboarding in the
summary phase, but phase transition required all fields + 5 discovery
exchanges — a condition extreme cases rarely meet. This left the model
stuck in discovery, never calling finishOnboarding.

- Add EARLY EXIT hint in discovery phase next_actions
- Add universal completion-signal REMINDER across all phases
- Add minimum-viable discovery fallback in systemRole
- Add explicit completion signal list in Early Exit section
- Add off-topic redirect limit in Boundaries
- Add CRITICAL persistence rule in toolSystemRole

*  test(context-engine): fix OnboardingContextInjector tests to match BaseFirstUserContentProvider

Remove brittle MessagesEngine onboarding test that hardcoded XML content.

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-07 19:25:16 +08:00
Arvin Xu bd8143c464 🐛 fix(prompts): enforce user perspective in input completion (#13619)
🐛 fix(prompts): enforce user perspective in input completion prompt

The autocomplete prompt was generating completions from the AI assistant's
perspective (e.g., "How can I help you?") instead of the user's perspective.
Added explicit perspective constraints with good/bad examples.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 17:31:14 +08:00
LobeHub Bot 68762fc4ae 🌐 chore: translate non-English comments to English in desktop i18nWorkflow (#13604)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 16:51:56 +08:00
Arvin Xu 1a58d530fb ♻️ refactor: add WebSocket gateway support to CLI agent run (#13608)
*  feat: add WebSocket gateway support to CLI agent run

CLI `agent run` now connects to Agent Gateway via WebSocket by default,
falling back to SSE when `--sse` is passed. After auth, sends `resume`
to fetch buffered events (covers race between exec and WS connect).

- Add `streamAgentEventsViaWebSocket` in agentStream.ts
- Add `resolveAgentGatewayUrl` in settings
- Add `OFFICIAL_AGENT_GATEWAY_URL` constant
- Support `AGENT_GATEWAY_SERVICE_TOKEN` env for gateway auth
- Add `--sse` flag for forced SSE fallback

Fixes LOBE-6800

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

*  test: add WebSocket gateway stream tests for CLI

Cover auth flow, resume, event rendering, JSON mode, auth failure,
heartbeat_ack, URL construction, and a multi-step tool-call scenario.

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

* 🐛 fix: persist agentGatewayUrl in saveSettings/loadSettings

saveSettings and loadSettings now handle agentGatewayUrl so custom
gateway configuration survives across CLI runs. Default URL is
stripped like serverUrl to keep the settings file minimal.

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

* 🐛 fix: remove AGENT_GATEWAY_SERVICE_TOKEN and fix JSON double-print in WS stream

1. Remove AGENT_GATEWAY_SERVICE_TOKEN env var — gateway auth should
   only use Oidc-Auth / X-API-Key from the existing auth flow.

2. Fix --json mode printing duplicate JSON arrays: agent_runtime_end,
   session_complete, and onclose all called console.log independently.
   Add jsonPrinted guard so only the first path outputs JSON.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 16:49:25 +08:00
Arvin Xu ca01385666 🐛 fix(model-runtime): strip additionalProperties and leftover $ref in Google tool schemas (#13613)
Google Gemini / Vertex AI rejects `additionalProperties` and `$ref` in
function declaration schemas. The previous fix (PR #13524) resolved most
`$ref` via `resolveRefs()` but missed two cases:

1. `additionalProperties` was never stripped
2. `$ref` survived when `resolveRefs` hit its depth limit (>10) on
   recursive schemas

Add both keys to UNSUPPORTED_SCHEMA_KEYS so `sanitizeSchemaForGoogle()`
strips them after ref resolution.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 16:08:15 +08:00
dependabot[bot] 5231bbbcac build(deps-dev): bump electron from 41.0.3 to 41.1.0 in /apps/desktop (#13557)
Bumps [electron](https://github.com/electron/electron) from 41.0.3 to 41.1.0.
- [Release notes](https://github.com/electron/electron/releases)
- [Commits](https://github.com/electron/electron/compare/v41.0.3...v41.1.0)

---
updated-dependencies:
- dependency-name: electron
  dependency-version: 41.1.0
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-07 14:19:46 +08:00
Octopus 496b10f5c0 fix(github-copilot): surface quota exhaustion 429 instead of retrying (#13584)
🐛 fix(github-copilot): surface quota exhaustion 429 instead of retrying

When the GitHub Copilot API returns a 429 with a Retry-After header
exceeding 5 minutes (indicating quota exhaustion rather than transient
rate limiting), throw the error immediately instead of retrying up to
MAX_RATE_LIMIT_RETRIES times with a silently capped 10s delay.

Fixes #13572
2026-04-07 14:06:52 +08:00
Arvin Xu 1800110748 🐛 fix: use main scope messages for subtopic re-fork (#13606)
* 🐛 fix: use main scope messages for thread fork to fix subtopic re-fork failure

When inside a subtopic (activeThreadId set), openThreadCreator and portalAIChats
used activeDisplayMessages which included activeThreadId in the key, returning
thread-scoped messages instead of main conversation messages. This caused
genParentMessages to fail finding the target message, resulting in empty parent
messages and a broken/loading fork UI.

Fix: use messageMapKey with only agentId/topicId to always get main scope messages.

Closes LOBE-5023

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

* 🐛 fix: include groupId in main scope key for group session support

Address Codex review: pass activeGroupId to messageMapKey so that
fork and thread selectors work correctly in group conversations
where messages are keyed by group scope instead of main scope.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 13:40:59 +08:00
YuTengjing b068c427d4 🐛 fix: preserve backend traceId in error handler (#13607) 2026-04-07 12:58:26 +08:00
Arvin Xu d5eec83a72 🔧 chore: disable input completion by default (#13605)
* 🔧 chore: disable input completion by default

The input auto-completion experience is not polished enough yet,
so disable it by default. Users can still enable it manually in
Settings > Agent.

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

* 🐛 fix: update snapshot for disabled input completion default

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 12:29:50 +08:00
Arvin Xu 6c9cbb07ee 🔨 chore: add GatewayStreamNotifier for Agent Gateway WebSocket push (#13603)
*  feat: add GatewayStreamNotifier for Agent Gateway WebSocket push

Add a decorator that wraps IStreamEventManager to additionally push
events to the Agent Gateway via HTTP (fire-and-forget). When
AGENT_GATEWAY_SERVICE_TOKEN is configured, the factory automatically
wraps the base stream manager with the gateway notifier. Redis SSE
remains the primary event channel; the gateway is an additive push
layer for WebSocket delivery.

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

*  test: add GatewayStreamNotifier and factory gateway wrapping tests

Ensure the decorator always delegates to the inner stream event manager
first, gateway failure never drops Redis events, and the factory
correctly wraps/skips based on AGENT_GATEWAY_SERVICE_TOKEN.

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

* 🐛 fix: add timeout, bounded concurrency and url-join to gateway notifier

- 5s AbortSignal timeout on every gateway POST to prevent hanging sockets
- Max 20 inflight requests; excess silently dropped with a debug log
- Use url-join for URL construction instead of string concatenation

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

* 🐛 fix: resolve TS18048 possibly undefined in test

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

* ♻️ refactor: move gateway env vars to appEnv

Read AGENT_GATEWAY_SERVICE_TOKEN and AGENT_GATEWAY_URL from the
validated appEnv config instead of raw process.env.

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

* ♻️ refactor: move gateway URL default into appEnv

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 12:16:49 +08:00
LobeHub Bot b92ee0ade5 🌐 chore: translate non-English comments to English in store/task (#13561)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 12:16:24 +08:00
Arvin Xu 3327b293d6 🔒 fix: remove apiKey fallback in webapi auth to prevent auth bypass (#13535)
* 🔒 fix: remove XOR auth header and legacy apiKey bypass (GHSA-5mwj-v5jw-5c97)

Completely remove the forgeable X-lobe-chat-auth XOR obfuscation mechanism:

- Remove apiKey fallback in checkAuthMethod (auth bypass vector)
- Rewrite checkAuth to use session/OIDC userId only, never trust client header
- Delete XOR encoding/decoding utilities and tests
- Delete dead keyVaults TRPC middleware (no consumers)
- Simplify createHeaderWithAuth (no longer sends XOR payload)
- Remove SECRET_XOR_KEY constant
- Remove authorizationHeader from TRPC lambda context
- Clean up CLI to only send Oidc-Auth header
- Update all affected tests

The LOBE_CHAT_AUTH_HEADER constant is retained for the async caller
(server-to-server) path which uses AES encryption via KeyVaultsGateKeeper.

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

* 🐛 fix: restore createPayloadWithKeyVaults for fetchOnClient path

The client-side model runtime (fetchOnClient) needs getProviderAuthPayload
and createPayloadWithKeyVaults to build provider SDK init params directly
in the browser. These functions are unrelated to XOR encoding.

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

* 🐛 fix: guard against null session before accessing user id

Add explicit null check before accessing session.user.id to prevent
TypeError when session is null (e.g. unauthenticated requests).

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

* 🐛 fix: add missing AgentRuntimeError import

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

* 🐛 fix: remove dead createRuntime code path causing type error

The createRuntime property was removed from checkAuth's RequestHandler
type but still referenced in the route handler, causing TS2339.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 11:53:07 +08:00
Innei d7e5d4645d ⬆️ chore(desktop): bump agent-browser to v0.24.0 (#13550)
* ⬆️ chore(desktop): bump agent-browser to v0.24.0

https://claude.ai/code/session_01XnRtpGn54turwVXf4MziLM

* 📝 chore: update agent-browser skill to match upstream v0.24.0

Sync the local-testing skill's agent-browser section with the upstream
SKILL.md from vercel-labs/agent-browser. Adds new commands: batch, auth
vault, semantic locators, annotated screenshots, clipboard, dialog
handling, diff, streaming, iOS simulator, dashboard, cloud providers,
and engine selection.

https://claude.ai/code/session_01XnRtpGn54turwVXf4MziLM

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-07 02:28:50 +08:00
lobehubbot 918e4a8fa1 Merge remote-tracking branch 'origin/main' into canary 2026-04-06 14:54:26 +00:00
Rdmclin2 f58015bb23 docs: clarify WeChat channel availability (#13540)
## Summary
- clarify in the channels overview that WeChat currently requires an
active subscription
- note that community edition users may not see the WeChat option in
channel settings yet
- keep the English and Chinese overview pages aligned

## Testing
- `git diff --check`

Related to #13461.
2026-04-06 22:53:44 +08:00
Zhijie He e6244aaea6 🐛 fix: fix imageGen button always switch to Nano Banaba (#13587) 2026-04-06 10:20:51 +08:00
Arvin Xu e9d43cb43f ♻️ refactor(bot): migrate Bot service to Agent Runtime Hooks framework (#13546)
* ♻️ refactor(bot): migrate Bot service to Agent Runtime Hooks framework

Migrate the last consumer (Bot/AgentBridgeService) from legacy
completionWebhook/stepWebhook/stepCallbacks dual-track pattern
to the unified hooks API. This completes LOBE-6208 Step 4.

- Enrich AgentHookEvent with step presentation + tracking data
- Enrich afterStep hook dispatch with full step context
- Merge executeWithWebhooks + executeWithInMemoryCallbacks into unified hooks
- Remove legacy triggerCompletionWebhook, triggerStepWebhook, stepCallbacks
- Remove completionWebhook/stepWebhook/webhookDelivery from params

LOBE-6675

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

* 🐛 fix(hooks): dispatch completion hooks on early-terminal return and fix totalToolCalls lag

- Add dispatchCompletionHooks in early-terminal branch of executeStep
  so onComplete hooks fire when operation is already interrupted/done/error
  between queued steps (e.g., via /stop)
- Include current step's toolsCalling in afterStep totalToolCalls so
  consumers get an accurate cumulative count instead of lagging by one step

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

*  test: update tests to match hooks-based architecture

- Rewrite executeStep tests to use hookDispatcher spies instead of
  removed registerStepCallbacks/getStepCallbacks API
- Rewrite completionWebhook tests to use hooks param and _hooks metadata
  instead of removed completionWebhook param
- Delete stepLifecycleCallbacks.test.ts (tests removed API, coverage
  now provided by HookDispatcher.test.ts + executeStep.test.ts)
- Update AgentRuntimeService.test.ts abort test to remove stepCallbacks

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

* 🐛 fix: resolve remaining CI failures from hooks migration

- Fix TS18048 errors: guard metadata access with null check in
  _stepTracking block
- Migrate remaining registerStepCallbacks usage in
  AgentRuntimeService.test.ts to hookDispatcher.dispatch spies:
  onComplete error tests and onAfterStep tool result extraction tests

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

*  test(bot): update AgentBridgeService tests for hooks-based execution

Old tests expected execAgent to NOT be called (because APP_URL check
would throw in queue mode). With hooks migration, the APP_URL check
is gone (hooks use relative URLs resolved by HookDispatcher), so
execAgent is now called. Update tests to verify hooks are passed
correctly instead.

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

*  test(bot): add hook payload compatibility tests for BotCallbackService

Add tests verifying that webhook payloads from HookDispatcher (containing
hookId/hookType fields) are correctly handled by BotCallbackService.
This validates the critical contract between the hooks framework and
the bot callback endpoint for step progress, completion, and error paths.

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

*  test: add hooks integration tests for e2e payload verification

Add integration tests that verify the full executeStep → hookDispatcher
chain produces events with all fields bot consumers depend on:

- afterStep event includes content, stepType, totalTokens, executionTimeMs
- afterStep event includes cross-step tracking (lastLLMContent, totalToolCalls)
- afterStep event includes toolsResult for tool_result phases
- onComplete fires on early-terminal states (interrupted) with lastAssistantContent
- All RenderStepParams-required fields are present and correctly typed

These tests catch payload format regressions without needing production
infrastructure (Redis, QStash, real bot platforms).

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 22:14:56 +08:00
Arvin Xu 5b03f009ee 🐛 fix(agentDocuments): add progressive disclosure PolicyLoad mode (#13571)
---------

Co-authored-by: Arvin Xu <arvinxx@ArvindeMacBook-Pro.local>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by-agent: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 01:23:32 +08:00
Neko 25cf3bfafd 🐛 fix(userMemories): i18n for purge button (#13569) 2026-04-05 00:28:10 +08:00
Rdmclin2 3cb7206d90 feat: create new topic every 4 hours (#13570)
* feat: create new topic every  4 hours

* fix: bot topic try catch

* fix: test case
2026-04-04 23:40:04 +08:00
Rdmclin2 e364b9a516 feat: skill store add skills tab (#13568)
* feat: add skill list and mcp list

* feat: support market skill detail

* fix: market skill detail render

* feat: add task emoji

* chore: lost  setting locales

* fix: build market download url
2026-04-04 22:11:17 +08:00
Arvin Xu a7e3d198df 🐛 fix(chat-input): memoize mentionOption/slashOption to prevent freeze on paste (#13551)
* 🐛 fix(chat-input): memoize mentionOption and slashOption to prevent page freeze on paste

Stabilize mentionOption and slashOption references with useMemo/useCallback to break the
infinite re-render loop that occurs when pasting text triggers autocomplete.

Fixes LOBE-6684

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

* 🐛 fix(chat-input): trim trailing newlines from autocomplete result to prevent empty lines

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

* 🐛 fix(chat-input): skip autocomplete during IME composition to prevent interrupting Chinese input

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 20:09:17 +08:00
Arvin Xu 14cd81b624 feat(cli): add migrate openclaw command (#13566)
*  feat(cli): add `migrate openclaw` command for importing OpenClaw workspace

Add a new CLI command `lh migrate openclaw` that imports all files from the
OpenClaw workspace (~/.openclaw/workspace) as agent documents into the LobeHub
inbox agent. Supports --source, --agent-id, --slug, --dry-run, and --yes options.

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

* ♻️ refactor(cli): restructure migrate as directory for future providers

Refactor `migrate` command from a single file to a directory structure
(`migrate/index.ts` + `migrate/openclaw.ts`) to support future migration
sources like ChatGPT, Claude, Codex, etc.

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

* 🐛 fix(cli): remove unnecessary `as any` casts in migrate openclaw

Use proper TrpcClient type instead of casting to any. Extract
resolveInboxAgentId helper with correct typing.

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

* ♻️ refactor(cli): migrate openclaw creates a new "OpenClaw" agent by default

Instead of importing into the inbox, the default behavior now creates a
dedicated "OpenClaw" agent and imports workspace files as its documents.
Use --agent-id to import into an existing agent instead.

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

*  feat(cli): restore --agent-id and --slug options for migrate openclaw

Support three modes: --agent-id (by ID), --slug (by slug, e.g. "inbox"),
or default (create a new "OpenClaw" agent).

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

*  feat(cli): print agent URL after migrate openclaw completes

Show a clickable link (e.g. https://app.lobehub.com/agent/<id>) at the
end of the import so users can open the agent directly.

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

*  feat(cli): check login state early in migrate openclaw

Verify authentication before scanning files so users get a clear
"Run 'lh login' first" message upfront instead of after confirmation.

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

*  feat(cli): read agent name, description, avatar from OpenClaw workspace

Parse IDENTITY.md (or SOUL.md) for Name, Creature/Vibe/Description, and
Emoji fields to populate the new agent's title, description, and avatar
instead of hardcoding "OpenClaw".

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

* 💄 style(cli): show emoji + name instead of agent ID in migrate output

Display the agent avatar emoji and title throughout the migrate flow
(confirmation, creation, importing). The agent ID only appears in the
final URL.

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

* 🐛 fix(cli): exclude .venv from openclaw workspace scan

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

* 🔧 chore(cli): expand excluded dirs/files for openclaw workspace scan

Filter out IDE configs, VCS dirs, OS artifacts, dependency dirs, Python
caches, build outputs, env files, and other common non-content items.

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

* update version

*  feat(cli): use `ignore` package for gitignore-based file filtering & improve output

- Replace hardcoded EXCLUDED_NAMES set with `ignore` package (gitignore syntax)
- Respect workspace .gitignore if present, plus comprehensive default rules
- Cover all common languages/tools: Python, Ruby, Rust, Go, Java, .NET, etc.
- Improve final output: friendlier completion message with agent name + URL

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

*  test(cli): add tests for migrate openclaw command

Cover profile parsing, file filtering (gitignore + default rules),
dry-run, agent resolution (--agent-id, --slug, default create),
confirmation flow, error handling, and output formatting.

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

*  feat(cli): filter placeholder emoji and binary/database files

- Skip avatar values like (待定), _(待定)_, TBD, N/A, etc.
- Add ignore rules for database files (*.sqlite, *.db, *.mdb, etc.),
  images, media, fonts, lock files, and compiled binaries
- Runtime binary detection: check first 8KB for null bytes and skip
  binary files that slip through the extension filter
- Add tests for placeholder emoji filtering, binary skip, and db exclusion

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

*  feat(api,cli): support optional createdAt for agent document upsert

Thread an optional `createdAt` parameter through all layers:
- Model: AgentDocumentModel.create/upsert accept optional createdAt,
  set both createdAt and updatedAt on documents + agent_documents rows
- Service: UpsertDocumentParams includes createdAt
- Router: agentDocument.upsertDocument accepts optional z.date()
- CLI: migrate openclaw passes file mtime as createdAt to preserve
  original file timestamps

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

* 💄 style(cli): add npx usage hint to auth error message

Show 'npx -y @lobehub/cli login' alongside 'lh login' so users who
haven't installed the CLI globally know how to authenticate.

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

* update version

*  feat(api,cli): support optional updatedAt for agent document upsert

Add updatedAt alongside createdAt through all layers. When both are
provided, updatedAt is used independently; when only createdAt is
given, updatedAt falls back to createdAt.

CLI now passes file birthtime as createdAt and mtime as updatedAt.

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

* 🐛 fix(cli): use os.homedir() for default source & wrap file reads in try

- Replace process.env.HOME || '~' with os.homedir() so the default
  --source path resolves correctly on Windows and when HOME is unset
- Move fs.readFileSync/statSync inside the try block so a single
  unreadable file doesn't abort the entire migration

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:45:04 +08:00
Arvin Xu bd345d35a8 🐛 fix(openapi): fix response.completed output missing message, wrong tool name & id (#13555)
* 🐛 fix(openapi): fix response.completed output missing message, wrong tool name & id

Fix three bugs in extractOutputItems for the Response API:
1. Assistant message with text+tool_calls was dropped from output
2. Function call names kept internal ____-separated format instead of identifier/apiName
3. Function call IDs were off by one due to missing message item

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

*  test(openapi): exercise real ResponsesService in regression tests

Replace local reimplementation with vi.mock stubs + real class import
so the tests fail if the production extractOutputItems regresses.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:08:58 +08:00
Neko 40d0825d79 🐛 fix(agent,topic): should reset agent side panel if agent state changes (#13556) 2026-04-04 03:46:45 +08:00
Neko ea725aca9e test(agentDocuments): incorrect assertion against agent document (#13552) 2026-04-03 23:32:39 +08:00
Innei dbdbe16da9 ♻️ refactor: move skills/tools to @ mention with direct context injection (#13419)
* ♻️ refactor: move skills/tools from slash menu to @ mention with direct context injection

Separates slash menu (/) and @ mention responsibilities:
- Slash menu: only commands (compact, newTopic)
- @ mention: agents, topics, skills, tools

Replaces fake activateSkill tool-call preload messages with direct
content injection via SelectedSkillInjector/SelectedToolInjector,
preventing models from mimicking activateSkill calls.

Fixes LOBE-6048

* ♻️ refactor: skip activateSkill when skill content already injected via selected_skill_context

Fixes LOBE-6048

* ♻️ refactor: align @-mention skills/tools with context injectors and preload

Made-with: Cursor

* 🐛 fix(chat): preserve editorData across queue and home input sends

* Update home send APIs and align related tests
2026-04-03 22:09:48 +08:00
Innei 5cd4e390e3 👷 build(model-bank): align pnpm setup with packageManager (#13545)
Remove hardcoded pnpm versions in the model-bank release workflow so CI uses the repository packageManager setting and avoids pnpm version mismatch failures. Also align release commit identity with the lobehub bot account used by other release workflows.

Made-with: Cursor
2026-04-03 21:13:43 +08:00
Rdmclin2 5c17a0d652 feat: bot related common features (#13483)
* chore: remove default platform header

* fix: clean speaker tag when copy

* fix: discord client memory leak

* feat: support tool display config

* fix: test case

* fix: lint error
2026-04-03 19:58:32 +08:00
Innei ec3dd471b1 👷 build(model-bank): add release workflow (#13384)
* 👷 build(model-bank): add release workflow

* 🐛 fix(model-bank): bundle business const for publish

* Remove ModelBank CI package rewrite before publish
2026-04-03 19:35:26 +08:00
Innei 1d7a0d6bd8 👷 build(desktop): remove nightly release channel (#13480)
* 👷 build(desktop): remove nightly release channel

* 🐛 fix(database): remove invalid tool_call_id from messages inserts in tests

* 🧪 test(desktop): fix updater channel migration mocks

* ♻️ refactor(desktop): migrate update channel in bootstrap

* ♻️ refactor(desktop): extract store migrations

* 🐛 fix(desktop): use custom store migration runner

* ♻️ refactor(desktop): split store migrations into files

* update

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
Co-authored-by: codex-514 <codex514@users.noreply.github.com>
2026-04-03 19:13:25 +08:00
Neko 71df4aa473 🐛 fix(agentDocuments): should fetch passively for agent documents (#13508) 2026-04-03 18:29:15 +08:00
renovate[bot] 48d14bfb7e chore(deps): update dependency electron to v39 [security] (#13527)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-04-03 17:53:21 +08:00
dependabot[bot] 74bcf41fe8 build(deps-dev): bump electron from 41.0.2 to 41.0.3 in /apps/desktop (#13525)
Bumps [electron](https://github.com/electron/electron) from 41.0.2 to 41.0.3.
- [Release notes](https://github.com/electron/electron/releases)
- [Commits](https://github.com/electron/electron/compare/v41.0.2...v41.0.3)

---
updated-dependencies:
- dependency-name: electron
  dependency-version: 41.0.3
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-03 17:20:15 +08:00
Zhijie He 210f020092 💄 style: add wanxiang2.7 & keling ImageGen from Qwen (#13478) 2026-04-03 17:17:21 +08:00
suyua9 306691b4d7 docs: clarify WeChat channel availability 2026-04-03 17:03:11 +08:00
WangYK f531c65fbb 🐛 fix: align message sharing modal with topic sharing (#13003) 2026-04-03 16:15:07 +08:00
YuTengjing 6d742388fa 🐛 fix: hide copy link button when share visibility is private (#13537) 2026-04-03 15:42:46 +08:00
LiJian aec2d30506 ♻️ refactor: add the cronjob tools executiors (#13536)
* fix: add the cronjob tools executiors

* fix: should use mutate to refresh the cronjob when it changes && add it into backend runtime

* fix: add the lost deps

* fix: should await the delete servers
2026-04-03 15:21:32 +08:00
Rylan Cai eb086b8456 feat: support local device binding in lh agent run (#13277)
*  support device binding in lh agent run

*  align device binding tests with current behavior
2026-04-03 13:44:12 +08:00
LiJian 3dd91a04fa 🐛 fix: slove the lobehub skill cant use activator to active (#13534)
fix: slove the lobehub skill cant use activator to active
2026-04-03 12:26:38 +08:00
Rylan Cai 9264a9c66d ♻️ refactor(eval): + resume agent run (#13412)
* ♻️ refactor: support minimal execAgent resume flow

* ♻️ refactor execAgent resume to caller-owned continuation context

* 📝 fix execAgent topic metadata comment

* 🚚 revert non-essential public execAgent resume changes

* 🚚 narrow execAgent resume changes to internal service scope

* 🚚 keep execAgent resume scoped to internal service

* 📝 restore taskId in execAgent runtime appContext

*  add agent eval trajectory resume

* ♻️ route agent eval resume through workflow

* 🩹 tighten eval resume workflow semantics

* ♻️ refine agent eval resume semantics

* ♻️ simplify resume workflow dispatch

* wip: rm redundancy interfaces

* wip: trim code

* wip: remove unuse

* wip: add eval detail resume btn

* 🐛 fix: message chains

* 🐛 fix: incorrect steps & cost count

* 🐛 fix: should allow start from non-zero step

* 🐛 fix: batch resume

* 🐛 fix: import

* ♻️ restore retry visibility guard in eval case table

* 🐛 fix: should not check run status

* 🐛 fix agent eval resume test regressions

* 🐛 fix: allow retry pass@k trajectory

* 🐛 fix eval case thread messages during run

* 🐛 fix pass@k batch resume target resolution

* 🐛 fix eval resume thread state handling

* ♻️ simplify eval resume validation

* 🚑 fix lint:ts interface order

* wip: fix lint

* 🐛 enforce max steps per resumed eval thread

* 🐛 avoid topic-level max steps check for pass@k resumes
2026-04-03 12:17:57 +08:00
Arvin Xu f9f7283fec 🐛 fix(model-runtime): resolve Vertex AI $ref schema error and toolConfig incompatibility (#13524)
* 🐛 fix(model-runtime): resolve Vertex AI $ref schema error and toolConfig incompatibility

1. Dereference $ref in JSON Schema before sending to Google/Vertex AI — the memory
   tool manifest (from neko's recent refactor) uses $ref which Vertex AI rejects.
2. Skip includeServerSideToolInvocations for Vertex AI — only Google AI supports it.

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

* 🐛 fix(model-runtime): preserve sibling schema fields when resolving $ref

When a schema node has $ref plus sibling keys (e.g. description from
allOf unwrapping), the resolved definition now merges with those siblings
instead of dropping them. This preserves argument-level descriptions for
fields like timeIntent, improving tool-call quality.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 12:06:27 +08:00
Arvin Xu 25e851b359 🔒 fix: sanitize HTML artifact content and sandbox iframe to prevent XSS-to-RCE (#13529)
* 🔒 fix: sanitize HTML artifact content and sandbox iframe to prevent XSS-to-RCE

- Add sanitizeHTMLContent() using DOMPurify to strip dangerous tags (script, embed, object, etc.) and all on* event handler attributes
- Add sandbox="" attribute to HTML artifact iframe to block all script execution and parent frame access
- Replace doc.write() with srcDoc for cleaner rendering
- Extract shared FORBID_EVENT_HANDLERS list to DRY up SVG and HTML sanitization

Ref: GHSA-xq4x-622m-q8fq

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

* 🐛 fix: correct import path from @lobehub/utils to @lobechat/utils

The package name is @lobechat/utils, not @lobehub/utils. This caused a build failure in Electron desktop app.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 12:05:54 +08:00
Tsuki f2a95f9ae6 🔨 chore: add Task store — service layer, selectors, and 4 slices (#13500)
 feat: add Task store with service layer, selectors, and 4 slices (LOBE-6597)

Implement frontend Task system state management:
- Service layer wrapping all TRPC task/brief endpoints
- List slice: SWR fetch by agent, list/kanban view mode
- Detail slice: CRUD with optimistic updates, immer reducer
- Lifecycle slice: run/pause/cancel/complete/resume, heartbeat ping
- Config slice: checkpoint, review, brief ops (model config deferred to LOBE-6634)
- Selectors: list (kanban columns, display status), detail (field accessors, operation guards), activity (sorted/filtered)
- Types derived from TRPC inference (TaskListItem, TaskStatus)
- 118 tests across 9 test files

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 11:57:46 +08:00
Chris Z 4e0bcf1c4d 📝 docs: sync contributing guide branding (#13533) 2026-04-03 11:57:06 +08:00
Arvin Xu bbcb3304dc 📝 docs: add SECURITY.md with vulnerability reporting policy (#13528)
📝 docs: add SECURITY.md with vulnerability reporting policy

Define supported versions, reporting guidelines, response timeline, scope (in/out), and disclosure policy for security vulnerabilities.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 10:48:19 +08:00
Tsuki 3b316e3a4e 🐛 fix(task): include config in getTaskDetail response (#13521) 2026-04-03 09:49:35 +08:00
Arvin Xu 251e12c7d1 feat(editor): implement AI input auto-completion (#13458)
*  feat: implement AI input auto-completion with ReactAutoCompletePlugin

Adds GitHub Copilot-style ghost text completion to the chat input,
powered by a configurable system agent (disabled by default).

Key changes:
- Add `inputCompletion` system agent config (type, default, selector, i18n)
- Create `chainInputCompletion` prompt chain (V2 few-shot, benchmarked)
- Mount `ReactAutoCompletePlugin` in InputEditor when enabled
- Wire `getMessages` through ChatInput store for conversation context
- Add settings UI in Service Model page with enable toggle

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

*  test: update systemAgent snapshot for inputCompletion

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

* 🐛 fix: restrict auto-complete context to visible user/assistant turns

Filter getMessages to use displayMessages (active visible thread)
instead of dbMessages (raw DB records including tool messages and
inactive branches). Also limit to last 10 user/assistant turns to
keep payload small and relevant.

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

*  feat: enable input completion by default

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

* ️ perf: use non-streaming for input completion requests

Autocomplete needs the full result before displaying ghost text,
so streaming adds unnecessary overhead. Setting stream: false
reduces latency by avoiding SSE chunking.

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

* 🐛 fix: revert stream:false for input completion

fetchPresetTaskResult uses fetchSSE internally which cannot handle
non-streaming JSON responses, causing the editor to freeze after
receiving the completion result.

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

* ️ perf: use non-streaming for input completion requests

Autocomplete waits for the full result before displaying ghost text.
fetchSSE handles non-streaming responses via its fallback path
(response.clone().text()), avoiding SSE chunking overhead.

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

* ️ perf: skip contextEngineering for input completion

Call getChatCompletion directly instead of fetchPresetTaskResult
to avoid triggering agentDocument.getDocuments on every autocomplete
request. Input completion only needs a simple LLM call with the
prompt chain, not the full context engineering pipeline.

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

* ♻️ refactor: revert to fetchPresetTaskResult for input completion

Use the standard contextEngineering pipeline. The agentDocument
overhead will be addressed separately.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 02:00:18 +08:00
Arvin Xu 3b13a1b6d4 🐛 fix: expose tool discovery config to context engine and inject available tools (#13417)
♻️ refactor: extract server tool discovery config builder
2026-04-03 01:54:22 +08:00
Arvin Xu 126db9612f 🐛 fix: stream tool call arguments incrementally in Response API (#13506)
* 🐛 fix: stream tool call arguments incrementally in Response API

The tool_calling stream chunks contain accumulated arguments (not
deltas), but the Response API was treating each chunk as a complete
independent output_item — creating a new lifecycle (added → delta →
done) per token and incrementing output_index to 90+.

Fix: track active tool calls by call_id and compute true incremental
deltas by slicing off previously-seen content. Each tool call now
gets a single stable output_item with proper streaming deltas,
finalized only when the stream ends or tool execution begins.

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

* 🐛 fix: clear stale tool-call state on LLM stream retry

When call_llm retries after a failed attempt, activeToolCalls may
contain entries from the failed stream that never received a
tool_end. Without clearing, finishActiveToolCalls would emit
phantom function_call done events and misalign output_index for
the successful attempt. Reset the map on stream_retry.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 01:46:14 +08:00
Arvin Xu dd7819b1be 🔨 chore(cli): register task command and add kanban board view (#13511)
*  feat(cli): register task command and add kanban board view

Register the missing `registerTaskCommand` in program.ts so `lh task` commands are accessible. Add `--board` flag to `task list` that renders a kanban-style view grouping tasks by status columns (backlog, running, paused, completed, etc.) with color-coded borders.

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

* update

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 00:54:12 +08:00
Arvin Xu 3415df3715 ♻️ refactor: remove chat-plugin-sdk (#13512)
* ♻️ refactor: remove @lobehub/chat-plugin-sdk dependency

Plugins have been deprecated. This removes the SDK entirely:

- Define built-in ToolManifest, ToolManifestSettings, ToolErrorType types
- Delete src/features/PluginsUI/ (plugin iframe rendering)
- Delete src/store/tool/slices/oldStore/ (deprecated plugin store)
- Delete src/server/services/pluginGateway/ (plugin gateway)
- Delete src/app/(backend)/webapi/plugin/gateway/ (plugin API route)
- Migrate all ~50 files from SDK imports to @lobechat/types
- Remove @lobehub/chat-plugin-sdk, @lobehub/chat-plugins-gateway deps
- Remove @swagger-api/apidom-reference override and patch

Fixes LOBE-6655

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

* 🐛 fix: add missing getInstalledPlugins mock in customPlugin test

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

* 🔧 chore: increase Vercel build memory limit to 8192MB

The 6144MB limit was causing OOM during Vite SPA chunk rendering.
Aligned with other build commands that already use 8192MB.

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

* ♻️ refactor: unify default tool type to builtin and fix CustomRender

- Remove `invokeDefaultTypePlugin` — default type now falls through to builtin in both server and client execution paths
- Fix `CustomRender` to actually render builtin tool components via `getBuiltinRender` instead of always returning null
- Increase SPA build memory limit from 7168MB to 8192MB to fix OOM

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

* ♻️ refactor: remove legacy plugin gateway and type-specific invocations

- Delete `runPluginApi`, `internal_callPluginApi`, `invokeMarkdownTypePlugin`, `invokeStandaloneTypePlugin`
- Remove plugin gateway endpoint (`/webapi/plugin/gateway`) from URL config
- Remove special `builtin → default` runtimeType mapping in plugin model
- Clean up unused imports and related tests

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

* 🐛 fix: add 'builtin' to runtimeType union to fix type error

Use ToolManifestType instead of inline union for runtimeType fields
so that 'builtin' is included as a valid type.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 00:46:19 +08:00
YuTengjing 0dc8930750 🔨 chore: update team assignment and fix prompt formatting (#13520) 2026-04-03 00:40:45 +08:00
Zhijie He 9f2d7daa17 💄 style: add more videoGen provider support (#13428)
Co-authored-by: YuTengjing <ytj2713151713@gmail.com>
2026-04-03 00:37:15 +08:00
YuTengjing 249483c3e1 🔨 chore: skip PR welcome comment for maintainer (#13519) 2026-04-02 23:42:28 +08:00
YuTengjing eb2731183f 🔨 chore(i18n): remove unused suspectedReason locale key (#13517) 2026-04-02 22:21:00 +08:00
YuTengjing d9c50b97f8 🐛 fix(database): apply injectSearchSettings consistently for unmodified builtin models (#13514) 2026-04-02 21:48:02 +08:00
Innei 8b445a1dc3 refactor: consolidate imports and add electron styling to theme/lang buttons (#13495)
🐛 fix(electron): add nodrag to userinfo dropdown menus

Add `-webkit-app-region: no-drag` to ThemeButton and LangButton
dropdown popups to prevent Electron from capturing click events
when the dropdown appears in the titlebar drag region.

https://claude.ai/code/session_01K6FLLJ4PMhKWqbRmrGEZkS

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-02 20:27:21 +08:00
Arvin Xu be99aaebd0 ♻️ refactor: unify tool content formatting with ComputerRuntime and shared UI (#13470)
* ♻️ refactor: unify tool content formatting with ComputerRuntime and shared UI components

Introduce `@lobechat/tool-runtime` with `ComputerRuntime` abstract class to ensure consistent
content formatting (via `formatCommandResult`, `formatFileContent`, etc.) across local-system,
cloud-sandbox, and skills packages. Create `@lobechat/shared-tool-ui` to share Render and
Inspector components, eliminating duplicated UI code across tool packages.

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

* 🐛 fix: address review issues — state mapping for renders and IPC param denormalization

- Add legacy state field mappings in local-system executor (listResults, fileContent,
  searchResults) for backward compatibility with existing render components
- Add denormalizeParams in LocalSystemExecutionRuntime to map ComputerRuntime params
  back to IPC-expected field names (file_path, items, shell_id, etc.)
- Fix i18n type casting for dynamic translation keys in shared-tool-ui inspectors

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

* ♻️ refactor: inject render capabilities via context, unify state shape for cross-package render reuse

- Add ToolRenderContext with injectable capabilities (openFile, openFolder,
  isLoading, displayRelativePath) to shared-tool-ui
- Update local-system render components (ReadLocalFile, ListFiles, SearchFiles,
  MoveLocalFiles, FileItem) to use context instead of direct Electron imports
- Enrich ReadFileState with render-compatible fields (filename, fileType,
  charCount, loc, totalCharCount)
- Cloud-sandbox now fully reuses local-system renders — renders degrade
  gracefully when capabilities are not provided (no open file buttons in sandbox)
- Remove executor-level state mapping hacks

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

* 🐛 fix: fix sandbox render bugs — SearchFiles, GrepContent, MoveFiles, GlobFiles

- SearchFiles: ensure results is always an array (not object passthrough)
- GrepContent: update formatGrepResults to support object matches
  `{path, content, lineNumber}` alongside string matches
- MoveFiles: render now handles both IPC format (items/oldPath/newPath) and
  ComputerRuntime format (operations/source/destination)
- GlobFiles: fallback totalCount to files.length when API returns 0

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

* 🐛 fix: unify SearchLocalFiles inspector with shared factory

SearchLocalFiles inspector now supports all keyword field variants
(keyword, keywords, query) and reads from unified state (results/totalCount).

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

* 🐛 fix: handle missing path in grep matches to avoid undefined display

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

* 🐛 fix: improve render field compatibility for sandbox

- EditLocalFile render: support both file_path (IPC) and path (sandbox) args
- SearchFiles render: support keyword/keywords/query arg variants
- FileItem: derive name from path when not provided

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

* 🐛 fix: add missing cloud-sandbox i18n key for noResults

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 19:42:45 +08:00
Arvin Xu f96edd56fb 🔨 chore(task): add task.groupList API for kanban view (#13507)
*  feat(task): add task.groupList API for kanban board view

Support querying tasks grouped by status in a single request, with per-group independent pagination. Returns array structure with hasMore/limit/offset for each group.

LOBE-6589

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

* 🐛 fix(task): bound groupList groups and statuses array size

Prevent query storms from oversized requests by capping groups to 20
and statuses per group to 10.

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

* 🔧 chore(task): reduce groupList max groups from 20 to 10

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 19:38:12 +08:00
Arvin Xu 074de037cd 🔨 chore(task): add generic updateTaskConfig for safe config merging (#13502)
*  feat(task): add generic updateTaskConfig method for safe config merging

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

*  test: add updateTaskConfig tests and use deep merge

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 18:41:23 +08:00
YuTengjing 297c884b88 🐛 fix(model-runtime): ensure before* hook errors trigger on*Error handlers (#13496) 2026-04-02 16:12:15 +08:00
Arvin Xu 04b32e3152 🔨 chore: add agent avatar data to brief list API (#13489)
*  feat: add agent avatar data to brief list API

Enrich brief list and listUnresolved endpoints with agent avatars
from the task tree. For each brief's associated task, walks up to
find the root task, then collects all agents (assignee + creator)
across the full tree.

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

*  test: add BriefService and unit tests for brief agent enrichment

Extract enrichBriefsWithAgents logic into BriefService for reuse.
Add unit tests for TaskModel.getTreeAgentIdsForTaskIds,
AgentModel.getAgentAvatarsByIds, and BriefService.

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

* 🔒 fix: scope recursive CTE to current user in getTreeAgentIdsForTaskIds

Add created_by_user_id filter to both the ancestor walk-up and
descendant walk-down recursive legs to prevent cross-tenant tree
traversal.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 15:41:08 +08:00
Zhijie He bbd09d6785 💄 style: add glm-5v-turbo support (#13487) 2026-04-02 14:39:07 +08:00
Neko 6a2ca59592 ♻️ refacor(database,userMemories): rework of user memory search (#13453) 2026-04-02 14:13:06 +08:00
LiJian 8aeb47eda3 🐛 fix: should clean up tools when the old tools is deprecated (#13492)
* fix: should clean up tools when the old tools is deprecated

* fixshould try delete incetent first
2026-04-02 12:39:51 +08:00
LiJian da1bccfd20 🐛 fix: slove the creds detail page cant modify the kv creds (#13473)
fix: slove the creds detail page cant modify the kv creds
2026-04-02 12:36:58 +08:00
LobeHub Bot 03c7a3fd42 🌐 chore: translate non-English comments to English in database messages tests (#13491)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-02 11:57:33 +08:00
Innei be8903e707 refactor: Extract web onboarding runtime to builtin package (#13446)
*  feat: add server runtime for lobe-web-onboarding tool

Implement server-side execution runtime for onboarding agent tools, enabling them to run in server environment without client-side dependencies.

https://claude.ai/code/session_01Das8jWLe5ibm6vJUFGu6Xb

* ♻️ refactor: deduplicate web onboarding utils by exporting from package

Move formatWebOnboardingStateMessage, createDocumentReadResult, createWebOnboardingToolResult, and EMPTY_DOCUMENT_MESSAGES into @lobechat/builtin-tool-web-onboarding/utils and update all consumers to import from there.

https://claude.ai/code/session_01Das8jWLe5ibm6vJUFGu6Xb

* 🔧 fix: sort imports in webOnboardingToolResult test

https://claude.ai/code/session_01Das8jWLe5ibm6vJUFGu6Xb

* 🔧 fix: sort imports with eslint --fix

https://claude.ai/code/session_01Das8jWLe5ibm6vJUFGu6Xb

* 🐛 fix: add missing properties to OnboardingStateContext interface

https://claude.ai/code/session_01Das8jWLe5ibm6vJUFGu6Xb

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-02 02:19:26 +08:00
Innei d8534c2966 🐛 fix(chat-input): preserve fullscreen editor state and send behavior (#13481)
* 🐛 fix(chat-input): preserve editor state and behavior in fullscreen

Keep chat input content and interaction consistent when toggling fullscreen by restoring editor JSON state, adjusting Enter/Cmd+Enter semantics, and rendering fullscreen input in the desktop layout container.

Made-with: Cursor

* 🐛 fix(chat-input): auto-collapse fullscreen after send

Automatically exit fullscreen after sending from chat input so users do not need a second manual collapse action, and clear saved editor snapshot to avoid stale restore.

Made-with: Cursor
2026-04-02 02:13:15 +08:00
Innei d25db6e6f8 🐛 fix(conversation): hide loading placeholder when AI generation is stopped (#13482)
🐛 fix: hide loading placeholder when AI generation is stopped

Only render ContentLoading for LOADING_FLAT messages when actively generating.
Previously, stopping AI mid-generation left the "..." placeholder visible
with a loading animation even though nothing was being generated.
2026-04-02 01:44:45 +08:00
YuTengjing df6d8f19f8 🔒 fix: upgrade nodemailer to v8 to fix SMTP command injection (#13479) 2026-04-01 21:51:32 +08:00
Arvin Xu 8af28a778b 🐛 fix(fetch-sse): stop injecting contextBody into structured provider errors (#13477)
* 🐛 fix(fetch-sse): stop injecting contextBody into structured provider errors

Structured errors (ProviderBizError etc.) already contain complete context.
Spreading contextBody into their body overwrites fields like `provider` and
pollutes the error structure that downstream renderers depend on.

Fixes #13476

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

*  test(fetch-sse): add regression test for structured error body pollution

Ensures structured provider errors (e.g. ProviderBizError) are passed through
unchanged without contextBody injection, and that contextBody is only applied
to unknown/unstructured errors.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 21:24:01 +08:00
Innei 6ecae1bbd1 ♻️ refactor: gate agent onboarding with dedicated business flag (#13472)
* ♻️ refactor: gate agent onboarding with dedicated business flag

Made-with: Cursor

* 🗑️ chore(migrations): remove agent onboarding column from users table

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): enable agent onboarding based on environment and add redirect to classic onboarding

- Updated AGENT_ONBOARDING_ENABLED to be true in development mode.
- Introduced RedirectToClassicOnboarding component to handle navigation to classic onboarding.
- Simplified ClassicOnboardingPage by removing the mode switch button for non-development environments.
- Adjusted OnBoardingContainer to conditionally render the skip onboarding button based on the current route.

This change enhances the onboarding experience by ensuring that the agent onboarding feature is only available in development, while also improving navigation for users.

Signed-off-by: Innei <tukon479@gmail.com>

* 🐛 fix(test): inline emoji-mart and @lobehub/* deps in Vitest to fix ESM JSON import error

Widen server.deps.inline to include `emoji-mart` and all `@lobehub/*`
packages so their transitive `@emoji-mart/data` import (a .json main
entry) goes through Vite's transform pipeline instead of Node's native
ESM loader, which requires `with { type: "json" }`.

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-04-01 19:38:14 +08:00
Arvin Xu 60a59e89f6 🛠 chore(fetch-sse): preserve legacy body.message and body.name keys for compatibility (#13469)
Restores the original body.message / body.name fields that downstream error
handlers rely on. The previous PR renamed them to errorMessage / errorName
which broke existing error renderers.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 15:04:37 +08:00
Arvin Xu 7fd6d67fe3 🐛 fix(model-runtime): add toolConfig for Gemini 3+ combined tools (#13465)
* 🐛 fix(model-runtime): add toolConfig for Gemini 3+ combined tools

When Gemini 3+ models combine built-in tools (googleSearch/urlContext)
with functionDeclarations, the API requires
toolConfig.includeServerSideToolInvocations to be set to true.

Without this flag, requests return 400: "Please enable
tool_config.include_server_side_tool_invocations to use Built-in tools
with Function calling."

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

*  test(google): fix incomplete grounding metadata test

The test defined grounding response data but never used it as mock
input and had no assertions. Rewrote to properly feed grounding chunks
through the stream and verify the output contains grounding events
with citations and search queries.

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

* 🐛 fix(test): use type assertion for grounding test data

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 15:03:23 +08:00
Arvin Xu 453db9f165 🔨 chore(fetch-sse): enrich error context with provider, model, and network diagnostics (#13468)
 feat(fetch-sse): enrich error context with provider, model, and network diagnostics

When a fetch error occurs (e.g. TypeError: Failed to fetch), the error body now
includes provider, model, apiMode, fetchOnClient, elapsedMs, networkStatus, and
traceId to help diagnose issues instead of only showing a useless minified stack.

Fixes LOBE-6594

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:58:14 +08:00
LiJian 19f90e3d9a ♻️ refactor: change the klavis github tools into lobehub skill & add vercel skills (#13442)
* refactor: change the klavis github tools into lobehub skill & add the vercel skill

* fix: slove the test & topicid parse
2026-04-01 14:48:16 +08:00
Arvin Xu fee0fe5699 🔨 chore: add disableTools option to execAgent (#13454)
*  feat: add disableTools option to execAgent for eval/benchmark scenarios

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

* ♻️ refactor: short-circuit tool discovery when disableTools is set

Move all tool-related fetches (plugin DB query, LobeHub/Klavis manifest
fetches, device list probing, model-bank import) inside the disableTools
guard so they are fully skipped in eval/benchmark runs.

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

*  test: add unit tests for disableTools short-circuit behavior

Verify that when disableTools=true, all expensive tool discovery
(plugin query, manifest fetches, ToolsEngine creation) is skipped.

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

* 🐛 fix: hoist variables referenced outside disableTools guard

Move lobehubSkillManifests, klavisManifests, agentPlugins, and
LOBE_DEFAULT_MODEL_LIST declarations outside the else block since
they are also used by agent management context and skill engine.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:28:59 +08:00
Arvin Xu 88246e5719 🔨 chore: support per-task model/provider override via task.config (#13466)
*  feat: support per-task model/provider override via task.config

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

* ♻️ refactor: extract agent execution types into dedicated agentExecution module

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

*  test: add unit tests for execAgent model/provider override

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:25:24 +08:00
Innei aaefe6c0d2 👷 chore(ci): unify CI package manager from bun to pnpm (#13464)
* 👷 chore(ci): unify CI package manager from bun to pnpm

Replace bun with pnpm across all GitHub Actions workflows to ensure
lockfile consistency with pnpm-lock.yaml as single source of truth.

* 👷 chore(ci): replace bun run with pnpm run in package.json scripts

Fix build failure in CI where bun is not installed. Replace bun run
references in root and e2e package.json scripts with pnpm run.

* 👷 chore(e2e): replace bunx with npx in e2e server startup

* 👷 chore(ci): create unified setup-env action, use pnpm install + bun run

- Add .github/actions/setup-env composite action (pnpm + bun + node)
- Refactor desktop-build-setup to use setup-env internally
- All workflows: pnpm install for deps, bun run for scripts
- Revert package.json/e2e scripts back to bun run
- Remove all direct pnpm/action-setup and oven-sh/setup-bun from workflows

* 🐛 fix(test): inline lexical ESM deps for vitest under pnpm

pnpm's strict node_modules layout causes vitest ESM resolution to fail
for lexical's named exports. Add lexical and @lexical/* to inline deps.
2026-04-01 14:08:37 +08:00
Arvin Xu cbc9bfccaa 💄 style: show live elapsed timer during tool execution (#13437)
*  feat: show live elapsed timer during tool execution

Display a real-time elapsed timer on tool call inspector while the tool is executing.
The timer automatically hides once execution completes.

Fixes LOBE-6331

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

* 🐛 fix: stop execution timer for rejected tool calls and reset elapsed on restart

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 11:34:54 +08:00
Rylan Cai 3e056ad37a 🔧 chore:(web-browsing): OOM debug logs (#13452)
* 🔧 add oom debug logging for web browsing search

* wip: trim

* 🔧 minimize web browsing oom debug logs

* ♻️ revert incidental crawl error check change

* 🔧 refine web browsing oom tracing

* 🔧 polish oom memory logs

* ♻️ inline crawler impl fallback in caller

* 🐛 guard memory snapshot behind debug enablement
2026-04-01 00:22:48 +08:00
Innei 46bac5b540 🐛 fix(utils): auto-reload on chunk load error (#13450)
🐛 fix: auto-reload on chunk load error instead of showing toast

When a chunk fails to load the old version is already unusable,
so reload the page automatically. Uses sessionStorage guard to
prevent infinite reload loops.

Fixes LOBE-6572
2026-03-31 23:56:20 +08:00
Innei 57ed8f8541 ♻️ refactor(tool): decouple topic-reference executor from app TRPC client (#13451)
♻️ refactor(tool): inject topic reference runtime in app layer

Move topic-reference executor to runtime injection so package code no longer imports app-level TRPC client aliases. Keep the TRPC call in store executor wiring for clear package/app boundaries.

Made-with: Cursor
2026-03-31 23:27:42 +08:00
LobeHub Bot 132893549a test: add unit tests for TaskService (#13432)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 22:14:50 +08:00
sxjeru d717d5da20 🐛 fix: update payload handling for OpenRouter image models (#10622)
*  feat: add imageAspectRatio support and update payload handling for image models

*  feat: enhance image model handling and support imageAspectRatio configuration

*  feat: add support for new image model "Nano Banana 2" and enhance image configuration handling

*  feat: add 'thinkingLevel4' to extendParams and improve image configuration handling

*  feat: add new AI models including DeepSeek V3.2 and Ministral 3 series, enhancing model capabilities and configurations

*  feat: update context window tokens and add new models in AIChatModelCard

*  feat: update Mistral model IDs and add new models; change AiHubMix base URL to API endpoint
2026-03-31 22:12:52 +08:00
Innei 58fa4f869d feat(chat): intervention fallback UI, GTD default tools, intervention guard order (#13447)
*  Improve intervention fallback UI; add GTD to default tools; defer unknown-tool guard

- Fallback intervention: show tool/action titles, collapsible parameters with i18n
- Register GTD manifest in defaultToolIds for shared tool list
- Run unknown-tool intervention only after per-tool resolver (auto-run skips early)
- TodoProgress: horizontal margin and top corner radii

Made-with: Cursor

* 🌐 chore(i18n): sync default keys and locale JSON across namespaces

Align knowledgeBase, labs, memory, notification, portal, thread, models, and chat bundles with default sources.

Made-with: Cursor
2026-03-31 22:07:58 +08:00
Rdmclin2 32e36e330a 🔨 chore: optimize message tool (#13444)
* chore: adjust electron testing to local testing

* chore: comprehence discord docs

* chore: add common capture window

* chore: default enable message tool in bot conversation

* fix: discord readMessages error

* chore: optimize readMessages prompt

* chore: optimize limit description

* chore: optimize limit size

* chore: remove limit parameter for discord

* chore: add threadRecover  Patch

* chore: optimize system role and bot context

* fix: avoid overide user config message tool

* chore: add default timeout
2026-03-31 21:28:18 +08:00
Innei ee8cab8305 🐛 fix: set context before replaceMessages in StoreUpdater layout effect (#13421)
🐛 fix: set context before replaceMessages in layout effect

replaceMessages calls onMessagesChange(messages, get().context) internally.
Without updating context first, it writes new topic's messages to the old
topic's key in ChatStore, corrupting cached data.
2026-03-31 20:47:33 +08:00
Innei 393653e20c ⬆️ chore: bump Lexical to 0.42 and align editor imports (#13440)
* ⬆️ chore: bump Lexical to 0.42 and align editor imports

- Bump lexical and @lexical/utils; pin lexical in pnpm overrides
- Return serialized nodes from ActionTag/ReferTopic XML readers (no INodeHelper require)
- Drop IEditorPlugin implements; import MenuRenderProps and IEditor from @lobehub/editor barrel

Made-with: Cursor

*  chore: add lexical dependency version 0.42.0 to package.json

Signed-off-by: Innei <tukon479@gmail.com>

*  test: enhance MCPClient Stdio Transport tests with local stdio entry

- Updated the test configuration to use a local stdio entry instead of `npx`, improving test reliability in CI environments.
- Added necessary imports for path resolution to support the new configuration.

Signed-off-by: Innei <tukon479@gmail.com>

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-03-31 20:45:32 +08:00
Hardy 560f598789 🐛 fix(glmCodingPlan): update default URL and add GLM-5.1 model (#13405)
*  feat(glmCodingPlan): update default URL and add GLM-5.1 model

- Change default URL to open.bigmodel.cn/api/coding/paas/v4
- Add GLM-5.1 model with 200K context window, 128K max output, reasoning support

* 🐛 fix: update test baseline URL for GLM Coding Plan provider
2026-03-31 18:42:40 +08:00
LobeHub Bot 993dfe1bb0 🌐 chore: translate non-English comments to English in packages (#13427)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 18:11:39 +08:00
Arvin Xu 967302269e 🐛 fix: support multiple artifacts rendering in the same message (#13436)
* 🐛 fix: support multiple artifacts rendering in the same message

When a message contains multiple `<lobeArtifact>` tags, only the first one
rendered correctly. The rest stayed in loading state or showed incorrect content.

Root causes:
- processWithArtifact used non-global regex, only removing newlines from first artifact
- artifactCode selector only extracted first artifact's content
- isArtifactTagClosed returned true if ANY artifact was closed
- Render onClick compared only messageId, closing portal instead of switching

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

*  test: add comprehensive tests for multiple artifacts rendering

- rehypePlugin: test multiple artifact tags in same tree (both p-wrapped and raw)
- action: test openArtifact switching between artifacts (same message, different messages)
- selectors: test artifactCode/isArtifactTagClosed with identifier edge cases
  (non-existent identifier, unclosed artifact, both closed)

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

* 🐛 fix: resolve type error in rehypePlugin test

Cast tree.children elements to any when accessing tagName property
to fix TS2339 error in the raw node test case.

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

* 🐛 fix: escape regex special characters in artifact identifier

Artifact identifiers interpolated directly into `new RegExp()` could cause
SyntaxError or incorrect matching when containing regex metacharacters
like (, [, +, etc. Now escapes identifiers before building regex patterns.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 17:21:15 +08:00
Arvin Xu 674c849254 feat: support client-side function tool execution in Response API (#13414)
*  feat: support client-side function tool execution in Response API

Implement LOBE-6543: when the Response API receives tools with type='function',
inject them into the LLM and pause execution when the LLM calls them, allowing
the client to provide results via function_call_output input items.

Key changes:
- Add 'client' to ToolSource type
- Inject function tools into LLM via execAgent with source='client' in sourceMap
- Pause agent loop (interrupt) when LLM calls a client function tool
- Handle function_call_output resume flow via previous_response_id
- Add response.function_call_arguments.done streaming event
- Emit response.incomplete when interrupted for client tool execution
- Use original function name for client tools instead of identifier/apiName
- Simplify response ID to use topicId directly (includes LOBE-6536 fix)

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

* 🐛 fix: remove MessageModel import, use prompt-based resume flow

MessageModel is not exported from @lobechat/database package.
Replace direct DB writes with prompt-based approach for tool result resume.

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

* 🐛 fix: use separator-safe client function identifier and add client to ToolSource

CLIENT_FN_IDENTIFIER `__fn__` caused ambiguous splits with PLUGIN_SCHEMA_SEPARATOR `____`,
breaking tool name resolution. Renamed to `lobe-client-fn` and added `client` to the
ToolSource union in @lobechat/types to match context-engine's definition.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 16:24:39 +08:00
René Wang f327e377a6 feat: update changelog (#13430)
* feat: Update changelog

* fix: changelog images missing
2026-03-31 14:58:04 +08:00
Rylan Cai e7be5b1928 🔧 chore: adjust eval qstash runtime retries (#13364)
* 🔧 tune eval qstash runtime retries

* 🔧 smooth eval qstash retry delay

* 🔧 persist eval qstash retry telemetry

* ♻️ trim hook types formatting noise

* 🗑️ remove eval retry telemetry passthrough

* 🚚 restore hook event spacing
2026-03-31 14:12:11 +08:00
Arvin Xu b54a41968d 🐛 fix(model-runtime): allow Gemini 3+ to combine search tools with function declarations (#13429)
* 🐛 fix(model-runtime): allow Gemini 3+ models to combine search tools with function declarations

Gemini 3+ models support urlContext, googleSearch, and functionDeclarations coexisting in the tools array. Previously, enabling search/urlContext would exclude function declarations (MCP tools/skills), causing them to silently fail.

Fixes LOBE-6450

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

* 🐛 fix(model-runtime): restore hasToolCalls guard for pre-Gemini 3 multi-turn tool sessions

Restores the hasToolCalls check for pre-Gemini 3 models so that when
tool_calls exist in message history, functionDeclarations are prioritized
over search tools to maintain multi-turn tool-calling sessions.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 12:34:48 +08:00
Zhijie He f39f5e9fd6 🐛 fix: fix lmstudio api key field has been hidden (#12678)
fix: fix lmstudio api key field has been hidden

env: support api key env
2026-03-31 12:17:16 +08:00
Rylan Cai 7be18092d3 ♻️ refactor: Agent Runtime stability improvement (#13257)
*  feat: add tool error kind classification and runtime retry dispatch

*  feat: add llm retry loop and stream reset event

* 🚑 stop retrying unknown tool execution errors

* ♻️ reduce runtime executor diff noise

* ♻️ restore runtime executor context comments

* ♻️ compress runtime executor retry diff

*  add llm retry backoff

* ♻️ tighten llm error classification kinds

* ♻️ tighten retry test assertions

* 🐛 stop llm retry after operation interruption

*  fix runtime executor retry stream test

* 🐛 stop retries after operation interruption

* 🐛 stop retrying provider invalid_request llm errors

* wip: reset

*  sync runAgent test with canary expectations
2026-03-31 11:18:30 +08:00
sxjeru c60c02bcfe 🐛 fix: correct extend params reasoning payloads and persist cleared model settings & add MiniMax M2.7 (#12760)
* fix: 允许单独传递 thinking.budget_tokens 参数

* fix: 添加 normalizeExtendParamsValue 函数并更新 ExtendParamsSelect 组件逻辑

* add new GPT-5.4 mini and nano models to AIChatModelCard array

* 🐛 fix: update DEFAULT_MINI_MODEL to gpt-5.4-mini

* 🐛 fix: update model references to gpt-5.4-mini in tests and snapshots

* 🐛 fix: 移除 MiniMax-M2.1 模型的定义

* feat: 添加 MiniMax M2.7 和高速度模型,更新现有模型定价和描述

* typo

* feat: 添加 MiniMax M2.7 和 MiMo V2 系列模型,更新模型能力和定价

* fix test

*  feat: update NVIDIA chat models with new entries and enhanced descriptions

* feat: 添加 Qwen3.5 Omni Plus 和 Qwen3.5 Omni Flash 模型,更新模型能力和定价
feat: 更新响应 API 模型,添加 gpt-5.4-mini 和 gpt-5.4-nano
2026-03-31 11:01:32 +08:00
Zhijie He ec3443d1db 💄 style: add qwen3.5-omni series (#13422)
style: add qwen3.5-omni series
2026-03-31 10:05:29 +08:00
Arvin Xu e76ab1f990 💄 style: mount DynamicFavicon for agent operation favicon switching (#13416)
*  feat: mount DynamicFavicon to enable favicon state switching during agent operations

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

* 🐛 fix: add favicon link tags to SPA HTML templates and handle missing links in updateFaviconDOM

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 09:25:18 +08:00
Innei c59c066330 🐛 fix(intervention): resolve InterventionBar context errors, rendering, and topic transition issues (#13420)
* 🐛 fix: resolve InterventionBar context errors and rendering issues

- Replace useMessageAggregationContext with prop drilling for assistantGroupId,
  fixing crash when ApprovalActions renders outside MessageAggregationContext
- Filter out tmp_ message IDs from pending interventions to prevent
  disabled buttons during message creation
- Portal ApprovalActions outside scroll container in InterventionBar
  so buttons are always accessible for long content
- Clear stale displayMessages synchronously on topic change to prevent
  old interventions from persisting during transitions

* 🐛 fix: use useLayoutEffect to clear stale interventions on topic switch

Replace render-phase side effect with useLayoutEffect to properly clear
displayMessages before browser paint when context changes, preventing
old topic interventions from flashing during transitions.

* 🐛 fix: synchronously reset store on context change to prevent stale data flash

Use React's "setState during render" pattern instead of useLayoutEffect.
When contextKey changes, React bails out and re-renders StoreUpdater
before rendering sibling components (ChatList/ChatInput), ensuring they
read fresh store state with no visible flash of old topic data.

* 🐛 fix: remount store on context change to eliminate stale data flash

Add key={contextKey} to zustand Provider so the store is recreated on
topic switch. Seed the new store with initialMessages in createStore to
render correct data on first mount — no intermediate skeleton or stale
flash. Remove render-phase reset hack from StoreUpdater as it's no
longer needed.

* 🐛 fix: revert Provider key approach, use useLayoutEffect for context reset

Provider key={contextKey} caused ChatHydration to remount and reset
activeTopicId from URL query, preventing topic switches entirely.

Reverted to stable Provider. Instead, use useLayoutEffect in StoreUpdater
to atomically reset displayMessages + messagesInit when contextKey changes.
This fires after commit but before paint, and React processes store updates
from layout effects synchronously, ensuring subscribers re-render with
correct state before the browser paints.
2026-03-31 02:57:56 +08:00
Innei 7097167613 🐛 fix(editor): add ReactMentionPlugin to ChatInput for mention node rendering (#13415)
🐛 fix: add ReactMentionPlugin to ChatInput so mention nodes render

The ChatInput editor plugins did not include ReactMentionPlugin, causing
mention nodes inserted via @ to be invisible. Move the plugin into
CHAT_INPUT_EMBED_PLUGINS so all ChatInput instances (including Home)
render mention nodes, and remove the now-duplicate entry from EditorCanvas.

Fixes LOBE-6270
2026-03-31 01:53:29 +08:00
Arvin Xu 2c2795e73a 🐛 fix: cli gateway auto reconnect (#13418)
* ♻️ refactor: move Marketplace below Resources in sidebar

Move the Marketplace (Community) nav item from topNavItems to bottomMenuItems,
positioning it below Resources in the sidebar navigation.

Closes LOBE-6320

* 🐛 fix(cli): auto-reconnect on auth expiry instead of exit

- Add `updateToken()` and `reconnect()` methods to GatewayClient
- On `auth_expired`, refresh JWT then reconnect automatically (no more process.exit)
- Add heartbeat ack timeout detection: force reconnect after 3 missed acks
- Reset missed heartbeat counter on `heartbeat_ack` receipt
- Add comprehensive tests for updateToken, reconnect, and missed heartbeat scenarios

Closes connection drop issue when JWT expires after long-running sessions.
2026-03-31 01:16:17 +08:00
Rdmclin2 965fc929e1 feat: add unified messaging tool for cross-platform communication (#13296)
*  feat: add cross-platform message tool for AI bot channel operations

Implement a unified message tool (`lobe-message`) that provides AI with
messaging capabilities across Discord, Telegram, Slack, Google Chat,
and IRC through a single interface with platform-specific extensions.

Core APIs: sendMessage, readMessages, editMessage, deleteMessage,
searchMessages, reactToMessage, getReactions, pin/unpin management,
channel/member info, thread operations, and polls.

Architecture follows the established builtin-tool pattern:
- Package: @lobechat/builtin-tool-message (manifest, types, executor,
  ExecutionRuntime, client components)
- Registry: registered in builtin-tools (renders, inspectors,
  interventions, streamings)
- Server runtime: stub service ready for platform adapter integration

https://claude.ai/code/session_011sHc6R7V4cSYKere9RY1QM

* feat: implement platform specific message service

* chore: add wechat platform

* chore: update wechat api service

* chore: update protocol implementation

* chore: optimize  platform api test

* fix: lark domain error

* feat: support bot message cli

* chore: refactor adapter to service

* chore: optimize bot status fetch

* fix: bot status

* fix: channel nav ignore

* feat: message tool support bot manage

* feat: add lobe-message runtime

* feat: support direct message

* feat: add history limit

* chore: update const limit

* feat: optimize  server id message history limit

* chore: optimize system role & inject platform environment info

* chore: update  readMessages vibe

* fix: form body width 50%

* chore: optimize tool prompt

* chore: update i18n files

* chore: optimize read message system role and update bot message lh

* updage readMessage api rate limit

* chore: comatible for readMessages

* fix: feishu readMessage implementation error

* fix: test case

* chore: update i18n files

* fix: lint error

* chore: add timeout for conversaction case

* fix: message test case

* fix: vite gzip error

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-31 00:26:32 +08:00
Innei 491aba4dbd ♻️ refactor(store): class-based Zustand actions with flattenActions (#13383)
♻️ refactor(store): migrate slices to class actions with flattenActions

- Video store: generationConfig/Topic/Batch/createVideo as *ActionImpl; aggregate with flattenActions
- Eval store: benchmark/dataset/run/testCase as classes; top-level flattenActions
- Tool agentSkills: AgentSkillsActionImpl + Pick typing
- groupProfile: flattenActions around ActionImpl instead of spreading instance
- agentGroup: wrap chatGroupAction with flattenActions for consistent aggregation

Made-with: Cursor
2026-03-30 23:46:35 +08:00
Innei 6402656ec7 feat: use skill-specific icons in slash menu instead of generic wrench icon (#13401)
*  feat: use skill-specific icons in slash menu instead of generic wrench icon

Each skill/tool in the slash menu now displays its own avatar (emoji or image URL)
instead of the generic 🔧 wrench icon for all items.

https://claude.ai/code/session_01KbUecMiAUDHvFtEULkSDvr

* ♻️ refactor: use SkillsIcon as default slash menu skill icon

https://claude.ai/code/session_01KbUecMiAUDHvFtEULkSDvr

*  feat: enhance slash action item rendering and mention menu styles

- Updated `useSlashActionItems.ts` to improve icon rendering for URLs, now supporting blob and data-URI images.
- Modified `MenuItem.tsx` to conditionally apply additional styles for items with extra categories.
- Added new style for `itemWithCategoryExtra` in `style.ts` to enhance layout consistency.

These changes aim to improve the visual presentation and functionality of the chat input components.

Signed-off-by: Innei <tukon479@gmail.com>

* 🐛 fix(mention-menu): satisfy cx ClassNamesArg types in MenuItem

Made-with: Cursor

---------

Signed-off-by: Innei <tukon479@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-03-30 22:36:12 +08:00
Innei f6314cc673 ♻️ refactor: serve Vite SPA static assets under /_spa (#13409)
Made-with: Cursor
2026-03-30 21:54:20 +08:00
Yizhuo cded932f1a 📝 docs: update telegram channel guide & remove wip description (#13226)
*  docs: add screenshots to Telegram channel guide

* 📝 docs: Remove "feature in development" callout and developer mode requirement from channels documentation.

* docs: Migrate Telegram channel images to local assets and update CDN cache.

* docs: Add screenshots to channel setup guides for various platforms.

* chore: Update documentation image paths from GitHub user attachments to local blog assets.

---------

Co-authored-by: Rdmclin2 <rdmclin2@gmail.com>
2026-03-30 21:42:29 +08:00
Innei e7c496352f 🐛 fix: defer scroll-to-user-message until spacer is mounted (#13378)
* 🐛 fix: defer scroll-to-user-message until spacer is mounted

The scroll that pins a user message to the top of the viewport was
racing with the conversation spacer mount. When the spacer hadn't
rendered yet, there wasn't enough scrollable height, so the scroll
had no effect.

Now `useScrollToUserMessage` accepts a `spacerActive` flag and
defers the scroll until the spacer is mounted, guaranteeing the
fill height is available before scrolling.

https://claude.ai/code/session_016GDASpf7Rh5yN7BJTdXYwT

* 🐛 fix: always scroll immediately, re-scroll when spacer mounts

The previous fix deferred scrolling entirely until spacerActive was
true. This regressed the no-spacer case (content fills viewport,
spacer height = 0, mounted stays false) — the scroll never fired.

Now the hook always scrolls immediately on message send (preserving
original behavior), and additionally fires a follow-up scroll when
spacerActive transitions to true. This covers both cases:
- Content fills viewport: immediate scroll works, no spacer needed
- Content is short: immediate scroll may under-scroll, but the
  follow-up scroll after spacer mounts corrects the position

https://claude.ai/code/session_016GDASpf7Rh5yN7BJTdXYwT

* 🐛 fix(conversation): shrink bottom spacer on scroll-up when idle

- Track scroll delta to reduce spacer height while not streaming
- Disable height transition during scroll-shrink for immediate feedback
- Reset reduction on new user/assistant pair and generation state changes

Made-with: Cursor

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-30 21:31:35 +08:00
Arvin Xu 296c6f3cb3 🔧 refactor: simplify response ID to use topicId directly (#13410)
Remove resp_ prefix and random suffix encoding from response IDs.
Response ID now equals topicId directly, simplifying multi-turn
conversation support via previous_response_id.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 21:31:09 +08:00
LiJian 53d0ee9ca5 🐛 fix: should use env.APP_URL to replace online url (#13408)
* fix: should use env.APP_URL to replace online url

* fix: fixed the double / path problem
2026-03-30 20:37:44 +08:00
Arvin Xu 689d5a51e8 feat(openapi): support hosted builtin tools in Response API (#13406)
*  feat(openapi): support hosted builtin tools in Response API

Allow declaring builtin tools via { type: 'lobe-xxx' } syntax in the
tools array of POST /api/v1/responses. Hosted tool identifiers are
extracted and passed as additionalPluginIds to execAgent, where the
existing ToolsEngine handles manifest resolution automatically.

LOBE-6535

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

*  feat(openapi): stream tool calls and results in Response API

Add full streaming support for tool execution events in the Response
API. Previously only text deltas were streamed; tool calls and results
were only visible in the final response.completed event.

Now emits:
- response.output_item.added (function_call) when LLM invokes a tool
- response.function_call_arguments.delta for tool arguments
- response.output_item.done (function_call) when tool call is complete
- response.output_item.added/done (function_call_output) when tool
  execution finishes with results
- Proper text message lifecycle (added/delta/done) across multi-step
  agent loops

LOBE-6535

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

* 🐛 fix(openapi): handle nullable tools param in extractHostedToolIds

The tools field from CreateResponseRequest uses .nullish() in zod,
so it can be null. Accept null in the parameter type.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:37:07 +08:00
Arvin Xu 23eab8769b 🐛 fix: add unread completion notification for group topic orchestration (#13407)
* 🐛 fix: add unread completion notification for group topic orchestration

Group orchestration was missing markUnreadCompleted() call after completion,
and group topic NavItem lacked the unread completion indicator UI.

Fixes LOBE-4878

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

* 💄 style: extract neon dot inline styles to createStaticStyles

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

* docs: add test screenshot 01.jpg for LOBE-4878

* docs: add test screenshot 02.jpg for LOBE-4878

* docs: add test screenshot 03.jpg for LOBE-4878

* 🔥 chore: remove temporary test screenshots

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

* 💄 style: change unread neon dot color from green to blue (colorInfo)

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

* 🐛 fix: replace remaining successColor references with infoColor in group topic item

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:33:31 +08:00
Innei 0e57fd9955 feat(onboarding): agent web onboarding, feature toggle, and lifecycle sync (#13139)
*  feat(onboarding): add agent-guided web onboarding flow

Made-with: Cursor

* Update onboarding prompts

Co-authored-by: Codex <noreply@openai.com>

* 🐛 fix web onboarding builtin tool flow

*  feat(onboarding): enhance agent onboarding flow with new dimensions and refined rules

- Updated onboarding structure to include new nodes: agentIdentity, userIdentity, workStyle, workContext, and painPoints.
- Revised system role instructions to emphasize a conversational approach and concise interactions.
- Adjusted manifest and type definitions to reflect the new onboarding schema.
- Implemented tests to ensure proper functionality of the onboarding context and flow.

This update aims to improve user experience during onboarding by making it more engaging and structured.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): enhance onboarding experience with localized welcome messages and interaction hints

- Added localized welcome messages for onboarding in English and Chinese.
- Refactored system role handling to support dynamic interaction hints based on user locale.
- Updated onboarding context to include interaction hints for improved user engagement.
- Implemented tests to validate the new interaction hint functionality.

This update aims to create a more personalized and engaging onboarding experience for users across different languages.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): overhaul onboarding flow with new question structure and refined interaction rules

- Replaced existing interaction hints with a focused question structure to enhance user engagement.
- Updated system role instructions to clarify onboarding protocols and improve conversational flow.
- Refactored type definitions and manifest to align with the new onboarding schema.
- Removed deprecated interaction hint components and tests to streamline the codebase.

This update aims to create a more structured and engaging onboarding experience for users, ensuring clarity and efficiency in interactions.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): introduce builtin agent onboarding package with structured roles and prompts

- Added a new package for agent onboarding, including a package.json configuration and initial TypeScript files.
- Implemented system role templates and tool prompts to guide the onboarding process.
- Established a client interface for rendering questions and handling user interactions.
- Updated dependencies in related packages to integrate the new onboarding functionality.

This update aims to enhance the onboarding experience by providing a structured approach for agents, ensuring clarity and efficiency in user interactions.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): enhance agent onboarding with new question renderer and refined interaction logic

- Introduced a new `QuestionRendererView` component to streamline the rendering of onboarding questions.
- Refactored the `QuestionRenderer` to utilize a runtime hook for improved state management and separation of concerns.
- Updated the onboarding context to fallback to stored questions when the current question is empty, enhancing user experience.
- Simplified the onboarding API by removing unnecessary read token requirements from various endpoints.
- Added tests to validate the new question rendering logic and ensure proper functionality.

This update aims to create a more efficient and user-friendly onboarding experience by improving the question handling and rendering process.

Signed-off-by: Innei <tukon479@gmail.com>

* Add dev history view for onboarding

* remove: prosetting

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): inline response language step in agent conversation

- Add ResponseLanguageInlineStep and wire into Conversation flow
- Extend agent onboarding context and update ResponseLanguageStep route
- Add tests and onboarding agent document design spec

Made-with: Cursor

*  feat(onboarding): enhance onboarding flow with inbox integration and schema refactor

- Updated onboarding process to migrate conversation topics to the inbox upon completion, ensuring users can revisit their onboarding discussions.
- Introduced a new schema-driven normalizer and node handler registry to streamline onboarding data handling, reducing code duplication and improving maintainability.
- Added comprehensive tests for new document builders and onboarding service methods to ensure functionality and reliability.
- Refactored existing components to support the new onboarding structure and improve user experience.

This update aims to create a more cohesive onboarding experience by integrating user identity data into the inbox and simplifying the underlying code structure.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(agent-documents): add listDocuments, readDocumentByFilename, upsertDocumentByFilename APIs

*  feat(onboarding): add generic user interaction builtin tool

*  feat(onboarding): wire generic tool interaction semantics

Register user-interaction tool in builtin-tools registry with manifest,
intervention components, client executor, and server runtime. Extend
BuiltinInterventionProps with interactionMode and onInteractionAction
to support custom (non-approval) interaction UIs. Add submit/skip/cancel
actions to conversation store with full operation lifecycle management.

* 🔧 fix: add builtin-tool-user-interaction to root workspace dependencies

* ♻️ refactor(onboarding): remove onboarding-owned question persistence

Drop askUserQuestion from the web-onboarding tool and remove
questionSurface from persisted state. Question presentation is now
delegated to the generic lobe-user-interaction tool.

* ♻️ refactor(onboarding): switch UI to generic interaction tool

Enable UserInteraction and AgentDocuments tools in web-onboarding and
inbox agent configs. Remove obsolete inline question renderers
(QuestionRenderer, QuestionRendererView, questionRendererRuntime,
questionRendererSchema, ResponseLanguageInlineStep) and simplify
Conversation component to only render summary CTA.

* 🔥 refactor(onboarding): remove identity doc and rewrite soul sync

* 🐛 fix(user-interaction): add humanIntervention to manifest and implement form UI

* 🐛 fix(onboarding): create user message on interaction submit instead of re-executing tool

* ♻️ refactor(onboarding): rebuild generic interaction flow

Align agent/tool roles and onboarding UI/runtime around the generic interaction rebuild.

Made-with: Cursor

*  feat(onboarding): implement onboarding document and persona management

Introduce a new onboarding document structure that separates agent identity and user persona data. Replace existing `readSoulDocument` and `updateSoulDocument` APIs with `readDocument` and `updateDocument` to handle both SOUL.md and user persona documents. Update related services, client executors, and localization keys to reflect these changes. Ensure document updates are driven by the agent, allowing for incremental updates and improved content management.

Signed-off-by: Innei <tukon479@gmail.com>

* refactor

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(workflow): introduce unified tool call collapse UI and supporting components

Add a new workflow collapse feature that groups tool calls and reasoning into a single collapsible unit, enhancing the user interface for tool call progress. This includes the creation of several components: `WorkflowCollapse`, `WorkflowSummary`, `WorkflowExpandedList`, `WorkflowToolLine`, and `WorkflowReasoningLine`. Update the design specifications and implementation plans to reflect this new structure, aiming for a more cohesive and user-friendly experience.

Signed-off-by: Innei <tukon479@gmail.com>

* feat(types): add discovery pacing types and constant

* feat(onboarding): add countTopicUserMessages and pacing gate to derivePhase

* feat(onboarding): capture discovery baseline and return pacing data in getState

*  feat(onboarding): add pacing hints to discovery phase tool result

* test(onboarding): add discovery pacing gate tests

* ♻️ refactor(onboarding): soften discovery pacing gate and add early exit exception

- MIN_DISCOVERY_USER_MESSAGES lowered from 4 to 2 (hard floor)
- RECOMMENDED_DISCOVERY_USER_MESSAGES = 4 (advisory hint)
- Tool protocol rule 2 now has explicit early exit exception
- Pacing hint text changed from imperative to advisory

*  feat(onboarding): update .gitignore and remove outdated onboarding plans

- Added `docs/superpowers` to .gitignore to exclude documentation files from version control.
- Deleted several outdated onboarding implementation plans, including those for onboarding inbox integration, generic interaction rebuild, and user question simplification, to streamline project documentation.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): refine agent onboarding, streaming, and AskUserQuestion

Made-with: Cursor

*  feat(store): add pending interventions selector

* 🐛 fix(store): handle standalone tool messages and structural children traversal in pending interventions selector

*  feat(conversation): create InterventionBar component

Add InterventionBar UI component with tab bar for multiple pending
interventions, reusing the existing Intervention detail component.

* 🐛 fix(conversation): use stable toolCallId for active tab state and add min-height: 0

Track active intervention by toolCallId instead of array index to prevent
stale selection when interventions are resolved. Add min-height: 0 to
scrollable content for correct overflow in flex column layout.

* feat(chatinput): show InterventionBar when pending interventions exist

* feat(tool): collapse inline intervention to one-line summary with scroll-to-bottom

* feat(i18n): add intervention bar translation keys

* 🐛 fix(chatinput): prevent infinite render loop from pendingInterventions selector

* 🐛 fix(chatinput): use equality function for pendingInterventions to break render loop

* refactor(tool): remove CollapsedIntervention, return null for pending inline

* feat(i18n): add form.other translation key

* feat(tool): add styles for select field with Other option

* feat(tool): add SelectFieldInput with Other option row

* feat(tool): wire SelectFieldInput and update validation in AskUserQuestion

* fix(tool): add keyboard handler to Other row, fix label flex

* refactor(tool): restore Select dropdown, add Other toggle row below

* refactor(tool): change Other to form-level escape hatch, restore antd Select

* refactor(tool): replace checkbox toggle with minimal text link escape hatch

* feat(tool): use lucide icons, auto-focus on escape toggle, createStaticStyles

* refactor(onboarding): update onboarding model references and improve styling in ModeSwitch component

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): add greeting entry animation keyframes and card styles

*  feat(onboarding): add LogoThree and entry animations to greeting card

*  feat(onboarding): add View Transition morph from greeting to conversation

* refactor(onboarding): simplify ModeSwitch component by removing segmentedGlass styling

Signed-off-by: Innei <tukon479@gmail.com>

*  feat(onboarding): increase maximum onboarding steps to 5 and add ProSettingsStep component

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: enhance user interaction question handling with validation schema

- Introduced Zod validation for askUserQuestion arguments to ensure correct structure.
- Updated test to reflect new question format with fields.
- Added error handling in AskUserQuestion component to log submission errors.

This improves the robustness of user interactions by enforcing schema validation and enhancing error reporting.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: enhance agent metadata handling and onboarding synchronization

- Updated `useAgentMeta` to prioritize custom titles from the database, falling back to the default Lobe AI title if none exists.
- Integrated `refreshBuiltinAgent` into the onboarding process to ensure the latest agent data is reflected during user interactions.
- Adjusted the `InboxItem` component to display the correct agent title and avatar based on the updated metadata.
- Refactored optimistic update actions to improve message handling and synchronization across components.

This improves the user experience by ensuring that the most relevant agent information is displayed and updated in real-time during onboarding and conversation flows.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: enhance conversation lifecycle and onboarding agent synchronization

- Updated `ConversationLifecycleActionImpl` to include additional context parameters (agentId, groupId, threadId, topicId) when updating message plugins for aborted interactions.
- Integrated `refreshBuiltinAgent` for the inbox during the onboarding process to ensure the latest agent data is synchronized.

These changes improve the handling of conversation lifecycle events and ensure that onboarding reflects the most current agent information, enhancing user experience during interactions.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: implement agent onboarding feature toggle and enhance ModeSwitch component

- Introduced `AGENT_ONBOARDING_ENABLED` configuration to control the visibility of the agent onboarding options.
- Updated `ModeSwitch` component to conditionally render onboarding options based on the feature toggle.
- Enhanced tests for `ModeSwitch` to cover scenarios for both enabled and disabled states of agent onboarding.
- Refactored `AgentOnboardingRoute` to navigate to the classic onboarding if the agent onboarding feature is disabled.

These changes improve the onboarding experience by allowing dynamic control over the agent onboarding feature, ensuring that users only see relevant options based on the configuration.

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: update agent onboarding feature toggle to include development mode

- Modified `AGENT_ONBOARDING_ENABLED` to also activate in development mode using `isDev`.
- This change allows for easier testing and development of the agent onboarding feature without needing to alter production configurations.

Signed-off-by: Innei <tukon479@gmail.com>

* Prevent welcome message when onboard

* 🐛 fix: satisfy ToolExecutionContext and updateMessageTools typings

Made-with: Cursor

* 🐛 fix: update tests for custom builtin agent title and discovery phase constants

* 🐛 fix: use custom inbox agent title and avatar in InboxWelcome

* 🧹 chore(onboarding): remove HistoryPanel unit test

Made-with: Cursor

* 🐛 fix: add missing onboarding/agent and onboarding/classic routes to desktop config

*  test: fix failing tests for onboarding container, document helpers, and executor

*  test: mock LogoThree to prevent Spline runtime fetch errors in CI

---------

Signed-off-by: Innei <tukon479@gmail.com>
Co-authored-by: Codex <noreply@openai.com>
2026-03-30 20:28:54 +08:00
LobeHub Bot 2f5a31fc99 test: add unit tests for LocalTaskScheduler (#13398)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 18:53:03 +08:00
Arvin Xu 143a15fdb9 💄 style: show interrupted hint when AI generation is stopped (#13397)
*  feat: show interrupted hint when AI generation is stopped

Display "Interrupted · What should I do instead?" text below the message
when user stops AI generation, replacing the infinite dotting animation.

Fixes LOBE-4462
Fixes LOBE-5726

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

*  feat: add edit button to queued messages tray

Allow users to edit queued messages by clicking the pencil icon,
which removes the message from the queue and restores its content
to the input editor.

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

* 📝 chore: move record-electron-demo.sh to electron-testing skill

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

* 🐛 fix: derive isInterrupted from latest runtime operation only

Previously isInterrupted used .some() to check if any cancelled AI
runtime operation existed for a message. In stop-then-retry flows,
the old cancelled op persisted alongside the new completed one,
causing the interrupted hint to reappear after the retry finished.

Now only the latest AI runtime operation is checked, so completed
retries correctly clear the interrupted state.

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

* 🐛 fix: read group interruption from active block ID

For assistant groups, continuation runs attach cancelled operations to
lastBlockId (contentId) rather than the group root. Check isInterrupted
on both the group root and the active block so the interrupted hint
is shown correctly for stopped group continuations.

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

*  test: update test to expect cancelled status after user stop

The test for resolving aborted tools after cancellation now correctly
expects 'cancelled' status, since completeOperation preserves the
user's intentional cancellation rather than overwriting it.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 18:46:46 +08:00
LiJian 9c08fa5cdf 🐛 fix: add the creds tools into execAgentRuntime (#13399)
fix: add the creds tools into execAgentRuntime
2026-03-30 17:20:37 +08:00
Hardy 59d8d878a2 🐛 fix: use Anthropic SDK for Kimi Coding Plan provider (#13345)
🐛 fix: use Anthropic SDK for Kimi Coding Plan provider

- Switch from OpenAI SDK to Anthropic SDK for Kimi Coding Plan
- Update baseURL from `/coding/v1` to `/coding` (Anthropic-compatible endpoint)
- Update model IDs: `kimi-k2.5` → `k2p5`, remove `kimi-k2`
- Fix max_tokens resolution to use KimiCodingPlan model list
- Rewrite tests for Anthropic SDK compatibility
2026-03-30 16:53:28 +08:00
WindSpiritSR 0439a29189 🔨 chore(docker): replace dev/prod pgsql docker image with paradedb (#13373)
🐛 fix(docker): replace dev/prod pgsql docker image with paradedb

Signed-off-by: WindSpiritSR <simon343riley@gmail.com>
2026-03-30 16:52:00 +08:00
LobeHub Bot 4a63ea3dcc 🌐 chore: translate non-English comments to English in src/routes (#13395)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-30 16:50:45 +08:00
YuTengjing 91b2653c71 🐛 fix: check error value in social sign-in result (#13392) 2026-03-30 11:38:48 +08:00
René Wang 8c8e7dd992 Update team assignments and feature responsibilities (#13393) 2026-03-30 10:44:25 +08:00
Arvin Xu a9cd2f7301 ♻️ refactor: remove DefaultAgentForm UI from settings pages (#13342)
🔥 refactor: remove DefaultAgentForm UI from settings pages

Remove the user-facing Default Agent configuration form from both
the agent settings page and the service-model settings page.
The underlying store action and selectors are preserved for
programmatic use (e.g. onboarding).

Fixes LOBE-1125

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 10:18:31 +08:00
YuTengjing b6c66dbdd7 feat: add businessElement and getFetchOptions plumbing to signin page (#13382)
*  feat: add businessElement and getFetchOptions plumbing to signin page

Add extension points to the signin flow so cloud overrides can inject
custom UI elements and modify fetch options for social sign-in requests.

- Add businessElement slot to SignInEmailStep component
- Pass getFetchOptions to signIn.social() and signIn.oauth2() calls
- Add businessElement and getFetchOptions defaults to useBusinessSignin

* 🐛 fix: resolve TS error on signIn.social result type with fetchOptions
2026-03-29 23:15:16 +08:00
Rylan Cai 5e1738ad4b ♻️ refactor(context engine): tool message normalization (#13359)
* ♻️ normalize tool call messages in context engine

* ♻️ prune tool message normalization implementation

* ♻️ prune tool message normalization diff

* ♻️ simplify tool message normalization diff

* ♻️ restore tool message reorder logging

* ♻️ restore reorder tool message shape

* ♻️ restore tool message reorder comment

* ♻️ prune tool message normalization diff

* ♻️ restore tool message reorder shape

* 🐛 fix(context-engine): keep empty tool content in reorder
2026-03-29 23:04:02 +08:00
Arvin Xu 4dc3c4ea1d 💄 style: move Marketplace below Resources in sidebar (#13381)
♻️ refactor: move Marketplace below Resources in sidebar

Move the Marketplace (Community) nav item from topNavItems to bottomMenuItems,
positioning it below Resources in the sidebar navigation.

Closes LOBE-6320
2026-03-29 22:32:30 +08:00
Arvin Xu bc9ae6b4e5 feat: support message queue (#13343)
*  feat: add message queue for agent runtime (soft interrupt)

Implement per-context message queue that allows users to send messages
while the agent is executing. Messages are queued and consumed via two
paths: injected at step boundaries during execution (Path A), or
triggering a new sendMessage after completion (Path B).

- Add QueuedMessage type and queuedMessages state in operation store
- Add enqueue/drain/remove/clear actions and selectors
- Modify sendMessage to enqueue when execAgentRuntime is running
- Add queue checkpoint in step loop (streamingExecutor)
- Add Path B: drain remaining queue after completion → new sendMessage
- Keep input enabled during agent execution (remove isInputLoading guard)
- Add QueueTray component showing "N Queued" above ChatInput
- Add electron-testing skill for agent-browser CLI automation

Fixes LOBE-6001

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

* 🐛 fix: Path B deferred execution to avoid recursive internal_execAgentRuntime

Use setTimeout(0) to break out of the current execution context when
triggering a new agent runtime for queued messages after completion.
Direct recursive calls caused issues with zustand state batching.

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

* 🐛 fix: remove premature Path A drain, fix Path B with fresh store ref

Path A (step checkpoint injection) was draining the queue before the
last LLM step, leaving nothing for Path B. For agents without tool
calls, this meant queued messages were consumed but never acted upon.

Fix: remove Path A for now (will be re-added for tool-call scenarios),
and use useChatStore.getState() in Path B setTimeout to get a fresh
store reference instead of a stale closure capture.

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

* 📝 docs: update electron-testing skill with real-world patterns

Based on lessons learned during message queue testing:
- Must cd to apps/desktop before npx electron-vite dev
- Use polling loop for startup detection
- snapshot -i -C required for contenteditable (chat input)
- Use sleep + screenshot instead of agent-browser wait for long ops
- Access store via window.__LOBE_STORES.chat()
- Add error interceptor and store inspection patterns
- Document all gotchas (HMR, daemon blocking, fill vs type)

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

*  feat: add Path A - early handoff to Path B at tool completion

When tools finish and queue has messages, break the step loop early
and let Path B create user message + start new operation. The new
LLM call sees full context including tool results + new user message.

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

* 🐛 fix: Path B use sendMessage for proper message creation

Use sendMessage instead of optimisticCreateMessage + internal_execAgentRuntime.
sendMessage handles the full lifecycle correctly: creates user message
on server, creates assistant message placeholder, and triggers
internal_execAgentRuntime — ensuring both messages are visible in UI.

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

* 💄 style: redesign QueueTray to Codex-style card layout

Each queued message shows as a card with icon, text preview,
and delete button. Uses antd CSS variables for consistent theming.

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

* 💄 style: connect QueueTray with ChatInput as unified container

QueueTray and ChatInput now share a connected border:
- QueueTray has top-rounded corners, no bottom border
- ChatInput gets bottom-only rounded corners when queue has items
- Uses cssVar for proper theme token styling
- Zero gap between tray and input

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

* ♻️ refactor: move queue check logic into GeneralChatAgent

Move the "finish early when queue has messages" decision from
streamingExecutor into GeneralChatAgent.runner(). The agent now
checks stepContext.hasQueuedMessages at tools_batch_result phase
and returns finish instruction, which is architecturally cleaner.

- Add hasQueuedMessages to RuntimeStepContext and computeStepContext
- GeneralChatAgent returns finish when tools complete + queue non-empty
- Remove Path A/B labels from comments
- streamingExecutor just passes hasQueuedMessages via stepContext

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

* 🐛 fix: forward queued files in sendMessage and drain only on success

- Forward merged file attachments when replaying queued messages
  (sendMessage now receives files from merged queue)
- Move drainQueuedMessages inside the status==='done' branch so
  queued messages are preserved on error/interrupted states
- Add queued_message_interrupt to FinishReason enum
- Add hasQueuedMessages check to tool_result and tasks_batch_result
  phases in GeneralChatAgent (not just tools_batch_result)

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

* ♻️ refactor: use full operationContext for context key indexing

- operationsByContext index now uses messageMapKey(context) with full
  context (including threadId, scope, etc.) instead of stripped key
- Fixes key mismatch where thread/scoped contexts couldn't find
  running operations, causing overlapping generations
- Move mergeQueuedMessages from services/messageQueue.ts into
  operation/types.ts alongside QueuedMessage type
- Delete services/messageQueue.ts

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 22:08:15 +08:00
YuTengjing 70091935ba 🔥 refactor(auth): remove NextAuth dead code from auth middleware (#13370)
* 🔥 refactor(auth): remove NextAuth dead code from auth middleware

* chore: shorter cookie cache duration
2026-03-29 21:17:45 +08:00
YuTengjing 50e373ad1c 🐛 fix(i18n): add missing credits.packages.charged key (#13369) 2026-03-29 02:09:57 +08:00
YuTengjing 966f943175 🐛 fix(auth): throw Unauthorized when no valid auth method found (#13368) 2026-03-29 01:56:40 +08:00
Rdmclin2 c7c2b56f3b feat: support bot manage (#13365)
* feat: support platform manage

* feat: auto connect when import config

* fix: lint error
2026-03-29 01:52:59 +08:00
Innei 841c1d2ef2 ♻️ refactor(styles): migrate remaining createStyles to createStaticStyles (#13358)
- Replace antd-style createStyles hooks with createStaticStyles and cssVar tokens
- Update MentionMenu, reactions, eval bench UI, OAuth device flow, DeviceGateway, GTD plan UI
- ModelSelect: use popupMatchSelectWidth for numeric popupWidth; narrow prop to number

Made-with: Cursor
2026-03-28 21:57:15 +08:00
Innei 26449e522a feat(resource): add select all hint and improve resource explorer selection (#13134)
*  feat(resource): add select all hint and improve resource explorer selection

Made-with: Cursor

* ♻️ refactor(resource): flatten store actions and improve type imports

Made-with: Cursor

* ♻️ refactor resource explorer list view

* refactor: engine

Signed-off-by: Innei <tukon479@gmail.com>

*  feat: checkpoint current workspace updates

* ♻️ refine resource explorer fetch ownership

* 🐛 fix: resolve resource manager ci regressions

* 🐛 fix(lambda): delete page-backed knowledge items by document id

* 🐛 fix(lambda): include knowledge-base files in remove-all

* 🐛 fix(resource): preserve cross-page select-all exclusions

* 🐛 fix(resource): retain off-screen optimistic resources

* 🐛 fix(resource): hide moved root items from current query

* 🐛 fix(resource): reset explorer selection on query change

* 🐛 fix(resource): fix select-all batchChunking and optimistic replace visibility

- batchChunking: pass through server-resolved IDs not in local resourceMap
  when selectAllState is 'all', letting server filter unsupported types
- replaceLocalResource: keep replacement visible if the optimistic item was
  already in the list, avoiding slug-vs-UUID mismatch in visibility check

* 🐛 fix(resource): reset selectAllState after batch operations and preserve off-screen optimistic items

- Reset selectAllState to 'none' after delete, removeFromKnowledgeBase,
  and batchChunking to prevent stale 'all' state causing unintended
  re-selection of remaining items
- Preserve off-screen optimistic resources in clearCurrentQueryResources
  so background uploads from other folders survive delete-all-by-query

* 🐛 fix: satisfy import-x/first in resource action test

Made-with: Cursor

* 🎨 lint: sort imports in ResourceExplorer

Made-with: Cursor

* 🐛 fix: widen searchQuery type in useResetSelectionOnQueryChange test

Made-with: Cursor

---------

Signed-off-by: Innei <tukon479@gmail.com>
2026-03-28 11:51:23 +08:00
Rdmclin2 f4c4ba7db5 🐛 fix: bot callback error (#13349)
* fix: not edit message id

* fix: error edit message

* chore: merge config & default

* chore: remove typing var

* fix: agent setting problem

* fix: test case error
2026-03-28 00:53:53 +08:00
LiJian 83f8f0319c 🐛 fix: slove the list connection always use require auth & should have trust client auth (#13344)
fix: slove the list connection always use require auth & should have trust client check
2026-03-27 21:14:03 +08:00
YuTengjing 197a0cc8f1 🌐 chore: sync i18n locale translations (#13340) 2026-03-27 18:59:54 +08:00
LiJian 6b4046eb17 🐛 fix: add the user github oauth in community home page profiles (#13222)
* fix: add the user github oauth in community home page profiles

* fix: change the oauth from social Profiles into skill connector way

* feat: add the claims user mcp and skills in community profiles

* fix: improve some claim model and skills/mcp
2026-03-27 18:04:17 +08:00
Innei 9e27bef8fa 🐛 fix(settings): remove system tools full-page loading (#13338) 2026-03-27 17:28:23 +08:00
lobehubbot 11318f8ab9 🔖 chore(release): release version v2.1.47 [skip ci] 2026-03-27 08:07:22 +00:00
lobehubbot aaff9af3b7 Merge remote-tracking branch 'origin/main' into canary 2026-03-27 08:05:35 +00:00
LiJian feb50e7007 🚀 release: 20260327 (#13330)
# 🚀 release: 20260326

This release includes **91 commits**. Key updates are below.


- **Agent can now execute background tasks** — Agents can perform
long-running operations without blocking your conversation.
[#13289](https://github.com/lobehub/lobe-chat/pull/13289)
- **Better error messages** — Redesigned error UI across chat and image
generation with clearer explanations and recovery options.
[#13302](https://github.com/lobehub/lobe-chat/pull/13302)
- **Smoother topic switching** — No more full page reloads when
switching topics while an agent is responding.
[#13309](https://github.com/lobehub/lobe-chat/pull/13309)
- **Faster image uploads** — Large images are now automatically
compressed to 1920px before upload, reducing wait times.
[#13224](https://github.com/lobehub/lobe-chat/pull/13224)
- **Improved knowledge base** — Documents are now properly parsed before
chunking, improving retrieval accuracy.
[#13221](https://github.com/lobehub/lobe-chat/pull/13221)

### Bot Platform

- **WeChat Bot support** — You can now connect LobeChat to WeChat, in
addition to Discord.
[#13191](https://github.com/lobehub/lobe-chat/pull/13191)
- **Richer bot responses** — Bots now support custom markdown rendering
and context injection.
[#13294](https://github.com/lobehub/lobe-chat/pull/13294)
- **New bot commands** — Added `/new` to start fresh conversations and
`/stop` to halt generation.
[#13194](https://github.com/lobehub/lobe-chat/pull/13194)
- **Discord stability fixes** — Fixed thread creation issues and Redis
connection drops.
[#13228](https://github.com/lobehub/lobe-chat/pull/13228)
[#13205](https://github.com/lobehub/lobe-chat/pull/13205)

### Models & Providers

- **GLM-5** is now available in the LobeHub model list.
[#13189](https://github.com/lobehub/lobe-chat/pull/13189)
- **Coding Plan providers** — Added support for code planning assistant
providers. [#13203](https://github.com/lobehub/lobe-chat/pull/13203)
- **Tencent Hunyuan 3.0 ImageGen** — New image generation model from
Tencent. [#13166](https://github.com/lobehub/lobe-chat/pull/13166)
- **Gemini content handling** — Better handling when Gemini blocks
content due to safety filters.
[#13270](https://github.com/lobehub/lobe-chat/pull/13270)
- **Claude token limits fixed** — Corrected max window tokens for
Anthropic Claude models.
[#13206](https://github.com/lobehub/lobe-chat/pull/13206)

### Skills & Tools

- **Auto credential injection** — Skills can now automatically request
and use required credentials.
[#13124](https://github.com/lobehub/lobe-chat/pull/13124)
- **Smarter tool permissions** — Built-in tools skip confirmation for
safe paths like `/tmp`.
[#13232](https://github.com/lobehub/lobe-chat/pull/13232)
- **Model switcher improvements** — Quick access to provider settings
and visual highlight for default model.
[#13220](https://github.com/lobehub/lobe-chat/pull/13220)

### Memory

- **Bulk delete memories** — You can now delete all memory entries at
once. [#13161](https://github.com/lobehub/lobe-chat/pull/13161)
- **Per-agent memory control** — Memory injection now respects
individual agent settings.
[#13265](https://github.com/lobehub/lobe-chat/pull/13265)

### Desktop App

- **Gateway connection** — Desktop app can now connect to LobeHub
Gateway for enhanced features.
[#13234](https://github.com/lobehub/lobe-chat/pull/13234)
- **Connection status indicator** — See gateway connection status in the
titlebar. [#13260](https://github.com/lobehub/lobe-chat/pull/13260)
- **Settings persistence** — Gateway toggle state now persists across
app restarts. [#13300](https://github.com/lobehub/lobe-chat/pull/13300)

### CLI

- **API key authentication** — CLI now supports API key auth for
programmatic access.
[#13190](https://github.com/lobehub/lobe-chat/pull/13190)
- **Shell completion** — Tab completion for bash/zsh/fish shells.
[#13164](https://github.com/lobehub/lobe-chat/pull/13164)
- **Man pages** — Built-in manual pages for CLI commands.
[#13200](https://github.com/lobehub/lobe-chat/pull/13200)

### Security

- **XSS protection** — Sanitized search result image titles to prevent
script injection.
[#13303](https://github.com/lobehub/lobe-chat/pull/13303)
- **Workflow hardening** — Fixed potential shell injection in release
automation. [#13319](https://github.com/lobehub/lobe-chat/pull/13319)
- **Dependency update** — Updated nodemailer to address security
advisory. [#13326](https://github.com/lobehub/lobe-chat/pull/13326)

### Bug Fixes

- Fixed skill page not redirecting correctly after import.
[#13255](https://github.com/lobehub/lobe-chat/pull/13255)
[#13261](https://github.com/lobehub/lobe-chat/pull/13261)
- Fixed token counting in group chats.
[#13247](https://github.com/lobehub/lobe-chat/pull/13247)
- Fixed editor not resetting when switching to empty pages.
[#13229](https://github.com/lobehub/lobe-chat/pull/13229)
- Fixed manual tool toggle not working.
[#13218](https://github.com/lobehub/lobe-chat/pull/13218)
- Fixed Search1API response parsing.
[#13207](https://github.com/lobehub/lobe-chat/pull/13207)
[#13208](https://github.com/lobehub/lobe-chat/pull/13208)
- Fixed mobile topic menus rendering issues.
[#12477](https://github.com/lobehub/lobe-chat/pull/12477)
- Fixed history count calculation for accurate context.
[#13051](https://github.com/lobehub/lobe-chat/pull/13051)
- Added missing Turkish translations.
[#13196](https://github.com/lobehub/lobe-chat/pull/13196)

### Credits

Huge thanks to these contributors:

@bakiburakogun @hardy-one @Zhouguanyang @sxjeru @hezhijie0327 @arvinxx
@cy948 @CanisMinor @Innei @LiJian @lobehubbot @Neko @rdmclin2
@rivertwilight @tjx666
2026-03-27 16:04:56 +08:00
Zhijie He dc9adf8f10 🐛 fix: fix some features for Github Copilot (ResponseAPI / Vision, etc) (#13279)
* 🐛 fix(github-copilot): switch codex models to responses api

* ♻️ refactor(github-copilot): simplify responses api routing

style: update model list

style: update model list

🐛 fix: align github copilot payload mapping and tests

style: update model list

style: update model list

* chore: add debug stream support

* refactor: use anthropic sdk for claude

* fix: fix ci error

* fix: fix github copilot reasoning_text chunk

* style: update Raptor mini base config, same as gpt-5-mini

style: update Raptor mini base config, same as gpt-5-mini

style: update Raptor mini base config, same as gpt-5-mini

* style: update model contextWindowTokens

* style: set default reasoning.summary to detailed, default as vscode
2026-03-27 15:13:28 +08:00
Innei 3d592ca70d ♻️ refactor: add generic SafeBoundary error boundary with tiered fallback (#13321)
Introduce a unified SafeBoundary component (silent/alert variants) to
replace scattered custom ErrorBoundary class components. Automatically
wraps Inspector, ContentBlock sub-components, MessageItem, and
EditorCanvas to prevent individual component crashes from propagating
to the entire app.
2026-03-27 15:10:00 +08:00
LobeHub Bot 8d0ac45476 🌐 chore: translate non-English comments to English in packages/openapi (#13329)
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 14:15:46 +08:00
Rdmclin2 953033355b 🔨 chore: optimize bot platform ux (#13262)
* chore: remove typing interval

* chore: optimize wechat media problem

* chore: add webhook helpers

* chore: update telegram docs

* chore: extract wechat credentials to custom render form

* feat: support wechat file upload

* feat: support concurrency mode and debounceMs

* chore: add locales

* chore: support visible then

* chore: support auto disapear save result info

* chore: default debounce mode

* chore: optimize doc position

* chore: adjust ack message logic

* fix: aes throw
2026-03-27 13:28:52 +08:00
sxjeru 48b5927024 💄 style: enhance handling of blocked content on Gemini (#13270)
*  feat: improve error messages for Google AI block reasons and enhance handling of blocked content

*  feat: add error localization for Google provider in createAgentExecutors
2026-03-27 10:51:01 +08:00
renovate[bot] 6e86912e7f Update dependency nodemailer to ^7.0.13 [SECURITY] (#13326)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-03-27 10:34:22 +08:00
Arvin Xu 4576059f4f ♻️ refactor: implement SkillResolver, BaseSystemRoleProvider, and agent document injection pipeline (#13315)
* ♻️ refactor: implement SkillResolver to replace ad-hoc skill assembly

Introduces a two-layer skill resolution architecture mirroring ToolsEngine + ToolResolver:

- SkillEngine (assembly layer): accepts raw skills + enableChecker, outputs OperationSkillSet
- SkillResolver (resolution layer): merges operation + step delta + accumulated activations

Key changes:
- Add SkillResolver, OperationSkillSet, StepSkillDelta, ActivatedStepSkill types
- Enhance SkillEngine with enableChecker and generate() method
- Wire SkillResolver into RuntimeExecutors call_llm
- Replace manual skillMetas assembly in aiAgent with SkillEngine.generate()
- Update client-side skillEngineering to use SkillEngine + enableChecker
- Add activatedStepSkills to AgentState for step-level skill accumulation

Fixes: agent-browser content injected into non-desktop scenarios (Discord bot)
due to missing filterBuiltinSkills call in aiAgent

LOBE-6410

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

* ♻️ refactor: extract agent-templates to standalone package and inject documents server-side

- Create @lobechat/agent-templates package with types, templates, and registry
- Move DocumentLoadPosition, DocumentLoadFormat, DocumentLoadRule, etc. to new package
- Move claw templates (AGENTS, BOOTSTRAP, IDENTITY, SOUL) with .md file imports
- Add BOOTSTRAP.md as new onboarding template (priority 1, system-append)
- Fix template positions: AGENTS→before-system, IDENTITY/SOUL→system-append
- Update database package to re-export from @lobechat/agent-templates
- Migrate all consumers to import directly from @lobechat/agent-templates
- Add agent documents injection in server-side RuntimeExecutors (was missing)
- Support -p CLI flag in devStartupSequence for port configuration

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

* 🐛 fix: correct import statement for non-type exports from agent-templates

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

* 📦 build: add @lobechat/agent-templates to root dependencies

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

* ♻️ refactor: remove template proxy files from database package

Stop re-exporting template/templates from database — consumers import
directly from @lobechat/agent-templates. Keep types.ts re-exports for
internal database code only.

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

* ♻️ refactor: create BaseSystemRoleProvider to unify system message append pattern

All providers that append to the system message now inherit from
BaseSystemRoleProvider and only implement buildSystemRoleContent().
The base class handles find-or-create and join logic.

Migrated providers:
- EvalContextSystemInjector
- BotPlatformContextInjector
- SystemDateProvider
- ToolSystemRoleProvider
- HistorySummaryProvider
- SkillContextProvider

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

* 🐛 fix: restore metadata tracking in BaseSystemRoleProvider via onInjected hook

Add onInjected() callback to BaseSystemRoleProvider so subclasses can
update pipeline metadata after successful injection. Also add raw-md
plugin to context-engine vitest config for .md imports.

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

*  feat: add enabled field to AgentDocumentInjector config

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

* ♻️ refactor: add enabled field to all providers, remove spread conditionals in MessagesEngine

All providers now accept an `enabled` config field. MessagesEngine
pipeline is a flat array with no spread conditionals — each provider
is always instantiated and uses `enabled` to skip internally.

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

* 💄 style: clean up MessagesEngine pipeline comments

Remove numbered prefixes, keep descriptive comments for each provider.
Only phase headers use separator blocks.

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

* ♻️ refactor: reorganize MessagesEngine pipeline phases by injection target

Phase 1: History Truncation
Phase 2: System Message Assembly (all BaseSystemRoleProvider)
Phase 3: Context Injection (before first user message, BaseFirstUserContentProvider)
Phase 4: User Message Augmentation (last user message injections)
Phase 5: Message Transformation (flatten, template, variables)
Phase 6: Content Processing & Cleanup (multimodal, tool calls, cleanup)

Moved SkillContext, ToolSystemRole, HistorySummary from Phase 3 to
Phase 2 since they append to system message, not user context.

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

* 💄 style: split Phase 6 into Content Processing (6) and Cleanup (7)

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

* ♻️ refactor: split AgentDocumentInjector into three position-based injectors

- AgentDocumentSystemInjector (Phase 2): before-system, system-append, system-replace
- AgentDocumentContextInjector (Phase 3): before-first-user
- AgentDocumentMessageInjector (Phase 4): after-first-user, context-end

Shared utilities (filterByRules, formatDocument, sortByPriority) extracted
to AgentDocumentInjector/shared.ts. Old monolithic injector removed.

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

* ♻️ refactor: split AgentDocumentSystemInjector into three separate injectors

- AgentDocumentBeforeSystemInjector: prepends as separate system message (before-system)
- AgentDocumentSystemAppendInjector: appends to system message (system-append)
- AgentDocumentSystemReplaceInjector: replaces entire system message (system-replace)

Each has distinct semantics and correct pipeline placement:
- BeforeSystem → before SystemRoleInjector
- SystemAppend → after HistorySummary (end of Phase 2)
- SystemReplace → last in Phase 2 (destructive)

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

*  feat: auto-enable agent-documents tool when agent has documents

- Add AgentDocumentsManifest to defaultToolIds
- Add hasAgentDocuments rule in server createServerAgentToolsEngine
- Query agent documents in AiAgentService.execAgent to determine flag
- Pattern matches KnowledgeBase auto-enable via enableChecker rules

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

* 🔨 chore: add agent documents status to execAgent operation log

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

* update content

* fix tests

* 🐛 fix: add raw-md plugin to database vitest configs

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 10:10:06 +08:00
Arvin Xu 9e9ba3e6c3 🐛 fix: prevent first assistant message re-animation on assistantGroup transition (#13320)
* 🐛 fix: prevent first assistant message re-animation on assistantGroup transition

When tool calls arrive during streaming, the message transitions from
assistant to assistantGroup, causing a full React remount. The first
content block's text was re-animating because isGenerating was still
true. Pass isFirstBlock prop through the render chain to disable
animation for the first block, since its text is guaranteed complete
by the time the group forms.

Fixes LOBE-6414

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

* ♻️ refactor: remove redundant isToolSingleLine animation check

isFirstBlock already covers the first block case, and subsequent blocks
should not have animation disabled just because they are single-line
with tools — they may still be streaming.

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 01:41:17 +08:00
Innei 46602be0b3 🐛 fix(workflow): prevent shell injection in auto-tag release (#13319) 2026-03-27 01:18:35 +08:00
YuTengjing 14b278fba8 💄 style: add payment upgrade i18n keys and update microcopy (#13317) 2026-03-27 00:51:28 +08:00
Arvin Xu 53c5708c9f 🔨 chore: improve start up scripts (#13318)
update scripts
2026-03-27 00:49:23 +08:00
YuTengjing edc8920703 🔨 chore: temporarily disable notification triggers (#13314) 2026-03-26 23:35:04 +08:00
Arvin Xu 926de076d9 🐛 fix: sanitize search grounding image titles to prevent XSS (#13303)
* 🐛 fix: sanitize search grounding image titles to prevent XSS

Replace dangerouslySetInnerHTML with stripHtml() for image result titles
in SearchGrounding and ImageSearchRef components to prevent stored XSS
attacks via malicious search result data.

Ref: GHSA-m5qx-g8hx-5f2p

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

* 🔒 fix: remove SystemJS plugin renderer to eliminate arbitrary JS execution risk

The old plugin render system (ui.mode === 'module') that used SystemJS
to dynamically load and execute JS from untrusted URLs has been fully
retired. Remove SystemJsRender and systemjs dependency entirely.

Ref: GHSA-46v7-wvmj-6vf7

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

* Revert "🔒 fix: remove SystemJS plugin renderer to eliminate arbitrary JS execution risk"

This reverts commit 99a7603a72.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 22:38:49 +08:00
Innei 9b7beca85e 💄 style(conversation): align user rich text line height with LexicalRenderer (#13312)
💄 style(conversation): set LexicalRenderer line height in user rich text

Made-with: Cursor
2026-03-26 21:58:24 +08:00
Arvin Xu 0724d8ca60 🐛 fix: prevent full page reload when switching topics during agent execution (#13309)
Move `e.preventDefault()` before the `disabled || loading` early return
in NavItem's onClick handler. Previously, when a NavItem was in disabled
or loading state, the early return skipped `preventDefault()`, allowing
the underlying `<a>` tag's default navigation to trigger a full browser
page load instead of SPA routing.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 21:30:08 +08:00
YuTengjing 9f36fe95ac feat: add notification system (temporarily disabled) (#13301) 2026-03-26 21:16:38 +08:00
Arvin Xu 3f148005e4 ♻️ refactor: remove langchain dependency, use direct document loaders (#13304)
* ♻️ refactor: remove langchain dependency, use direct document loaders

Replace langchain and @langchain/community with self-implemented text
splitters and direct usage of underlying libraries (pdf-parse, d3-dsv,
mammoth, officeparser, epub2). This eliminates unnecessary dependency
bloat and addresses CVE-2026-26019 in @langchain/community.

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

* 🐛 fix: add missing @types/html-to-text and @types/pdf-parse

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

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 21:13:55 +08:00
Arvin Xu 4e60d87514 🔒 refactor: remove deprecated SystemJS plugin renderer (#13305)
🔒 fix: remove SystemJS plugin renderer to eliminate arbitrary JS execution risk

The old plugin render system (ui.mode === 'module') that used SystemJS
to dynamically load and execute JS from untrusted URLs has been fully
retired. Remove SystemJsRender and systemjs dependency entirely.

Ref: GHSA-46v7-wvmj-6vf7

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 20:41:06 +08:00
YuTengjing d2a16d0714 feat: improve error UI and error handling across chat and image generation (#13302) 2026-03-26 20:09:06 +08:00
lobehubbot ac8a9ec0f8 🔖 chore(release): release version v2.1.46 [skip ci] 2026-03-26 09:07:05 +00:00
2607 changed files with 173510 additions and 38426 deletions
+298
View File
@@ -0,0 +1,298 @@
---
name: bot
description: 'Bot platform architecture (Discord, Slack, Telegram, Feishu/Lark, QQ, WeChat). Use when working on inbound webhooks, Chat SDK message routing, agent execution from chat platforms, queue-mode callbacks, gateway lifecycle (websocket/polling), bot provider CRUD/credentials, or platform-specific clients/adapters/schemas. Triggers on bot, channel, webhook, mention, Chat SDK, agent bot provider, gateway, bot-callback, qstash bot.'
---
# Bot System
> **Last updated: 2026-04-08.** Implementation evolves quickly — this doc is a map, not the source of truth. Always read the key files below to verify behavior, especially per-platform quirks. Update this doc when the architecture changes.
LobeChat agents can answer inside external chat platforms. Inbound messages flow through the Chat SDK (`chat` npm package), get routed to the right agent by `(platform, applicationId)`, executed via `AiAgentService`, and replied back through a per-platform `PlatformClient`. There are **two execution modes** (in-memory vs queue/QStash) and **three connection modes** (`webhook`, `websocket`, `polling`).
## Supported Platforms
| Platform | id | Default mode | Markdown | Edit | Notes |
| -------- | ---------- | ------------------------------- | ----------------- | ------ | -------------------------------------------------------------------------------------- |
| Discord | `discord` | `websocket` | yes | yes | Persistent gateway via Chat SDK adapter; reaction-thread quirks; native slash commands |
| Slack | `slack` | `websocket` (Socket Mode) | yes (mrkdwn) | yes | Multi-mode — user can pick `webhook` per provider |
| Telegram | `telegram` | `webhook` | yes (HTML) | yes | `setMyCommands` menu via `registerBotCommands` |
| Feishu | `feishu` | `websocket` (Lark SDK WSClient) | **no** (stripped) | yes | Multi-mode; shared client with Lark |
| Lark | `lark` | `websocket` | **no** | yes | Same client/schema as Feishu, different domain |
| QQ | `qq` | `websocket` | **no** | **no** | All replies are final-only |
| WeChat | `wechat` | `polling` (iLink long-poll) | **no** | **no** | 10-minute gateway window |
`supportsMarkdown=false` ⇒ outbound markdown is stripped to plain text via `stripMarkdown` and the AI is told not to use markdown. `supportsMessageEdit=false` ⇒ no progress edits — only the final reply is sent.
**Multi-mode connection** — Slack/Feishu/Lark/QQ shipped as websocket but support `webhook` per-provider via `settings.connectionMode`. Legacy rows without that field stay on `webhook` (see `LEGACY_WEBHOOK_PLATFORMS` in `platforms/utils.ts`) — **never add new platforms to that list**.
## Inbound Flow (one webhook → reply)
```
Platform server
│ POST /api/agent/webhooks/[platform]/[appId]
route.ts ── catch-all `[[...appId]]` route
BotMessageRouter (singleton)
│ • lazy-loads bot per `platform:applicationId`
│ • merges schema defaults + provider.settings (mergeWithDefaults)
│ • builds Chat SDK Chat<any> with createIoRedisState (if Redis available)
│ • registerHandlers: onNewMention / onSubscribedMessage / onNewMessage(/.dm)
│ • registerCommands: /new (reset topic), /stop (interrupt)
chatBot.webhooks[platform](req) ← Chat SDK parses → fires events
AgentBridgeService.handleMention / handleSubscribedMessage
│ • activeThreads guard (no duplicate runs per thread)
│ • adds 👀 reaction (eyes), startTyping
│ • merges debounced/queued skipped messages (mergeSkippedMessages)
│ • extractFiles (buffer → fetchData → url)
│ • formatPrompt (sanitize mention + speaker tag + referenced_message)
├── In-memory mode ──► AiAgentService.execAgent({ stepCallbacks })
│ → onAfterStep edits progress message live
│ → onComplete edits final reply, splits via splitMessage(charLimit)
└── Queue mode (isQueueAgentRuntimeEnabled) ──► execAgent({ stepWebhook, completionWebhook, webhookDelivery: 'qstash' })
→ returns immediately, callbacks land at /api/agent/webhooks/bot-callback
```
The router caches loaded bots in memory. Cache is **invalidated** by `BotMessageRouter.invalidateBot(platform, appId)` whenever the TRPC `update`/`delete` mutations run, so new credentials/settings take effect on the next webhook.
## Execution Modes
### In-memory (default)
`AgentBridgeService.executeWithInMemoryCallbacks` wraps `execAgent` with `stepCallbacks`. Lives in one process — Promise-based wait, 30-min timeout, edits the same `progressMessage` after every step. Topic title is summarized inline via `SystemAgentService`.
### Queue (`isQueueAgentRuntimeEnabled`)
`AgentBridgeService.executeWithWebhooks`:
1. Posts the `renderStart` placeholder, captures `progressMessageId`.
2. Calls `execAgent` with `stepWebhook` and `completionWebhook` pointing at `${INTERNAL_APP_URL ?? APP_URL}/api/agent/webhooks/bot-callback`, plus `webhookDelivery: 'qstash'`.
3. Returns immediately; the bridge `finally` block keeps the active-thread marker held until the `completion` callback fires.
`/api/agent/webhooks/bot-callback/route.ts` verifies the QStash signature and hands off to `BotCallbackService.handleCallback`:
- `type: 'step'``handleStep` re-renders `renderStepProgress`, edits `progressMessageId` (skipped if `displayToolCalls=false` or platform `supportsMessageEdit=false`).
- `type: 'completion'``handleCompletion` writes the final reply (or error/interrupted message), removes the 👀 reaction, clears active-thread tracker, fires async `summarizeTopicTitle`.
`BotCallbackService.createMessenger` reloads provider + credentials from DB and rebuilds a `PlatformClient` per call (no in-memory state).
## Commands
Defined in `BotMessageRouter.buildCommands` and registered via two paths:
- **Native slash commands** (Slack/Discord): `bot.onSlashCommand('/<name>', ...)`
- **Text-based fallback** (Telegram/Feishu/QQ/Lark/WeChat): `bot.onNewMessage(/^\/(new|stop)(\s|$|@)/, ...)` plus a per-mention `tryDispatch` so commands work even before subscribe.
Built-in commands:
- `/new` — clears `topicId` in thread state, next message starts a fresh topic.
- `/stop` — interrupts the active execution (calls `AiAgentService.interruptTask` if `operationId` is known; otherwise queues a deferred stop via `requestStop`/`pendingStopThreads`, also aborts the startup phase via `startupControllers`).
To add a command, append to `buildCommands` — it auto-registers everywhere; on Telegram it also surfaces in the `/` menu via `client.registerBotCommands``setMyCommands`.
## Active-thread State (statics on `AgentBridgeService`)
- `activeThreads: Set<threadId>` — prevents duplicate runs per thread (must guard before stale-topic check, otherwise concurrent messages can drop).
- `activeOperations: Map<threadId, operationId>` — needed by `/stop` once `execAgent` returns.
- `startupControllers: Map<threadId, AbortController>` — cancels pre-`operationId` work (topic/tool prep).
- `pendingStopThreads: Set<threadId>``/stop` arrived before `operationId` existed; consumed once available.
In **queue mode**, the bridge `finally` skips cleanup so the marker persists until `BotCallbackService.handleCompletion` calls `clearActiveThread`.
## Topic Lifecycle in Threads
- `handleMention` always treats the message as the start of a new conversation.
- `handleSubscribedMessage` reads `topicId` from `thread.state`. If the topic is stale (`> 4 hours` since `updatedAt`), state is cleared and it retries as a fresh mention.
- If `execAgent` fails with a Postgres FK violation on `topic_id` (cached topic was deleted), the bridge clears state and retries as a mention.
- `subscribe()` is gated by `client.shouldSubscribe(threadId)` — Discord top-level channels return `false` so we don't follow up there.
## Attachments
`AgentBridgeService.extractFiles` resolves attachments in priority order:
1. `att.buffer` — already downloaded by the adapter (WeChat/Feishu inbound).
2. `att.fetchData()` — adapter-provided lazy download with auth (Telegram, Slack, Feishu history). **Required** when URLs are token-protected — naive `fetch(url)` later in `ingestAttachment.ts` has no credentials.
3. `att.url` — public CDN fallback (Discord, public QQ).
`inferMimeType` / `inferName` patch Telegram-style `photo` payloads (no `mimeType`/`name` from Bot API → defaults to `image/jpeg`) so vision models actually see them. Quoted-message attachments are also pulled from `raw.referenced_message.attachments` (Discord).
## Concurrency
`settings.concurrency` is `'queue'` or `'debounce'`:
- `debounce` → Chat SDK debounces inbound messages by `debounceMs`; `mergeSkippedMessages` joins skipped texts/attachments into the current message before handing to the agent.
- `queue` → Chat SDK serializes per-thread; the bridge's own `activeThreads` set is still required because in queue mode the SDK lock releases before the agent finishes.
## Gateway (persistent platforms)
Webhook platforms run fine in serverless functions. Persistent platforms (`websocket`, `polling`) need a long-running listener — that's the **gateway**.
**`GatewayService.startClient(platform, appId, userId)`** (`src/server/services/gateway/index.ts`):
- On Vercel + persistent mode → `BotConnectQueue.push` (Redis hash) and mark runtime status `queued`. The cron picks it up.
- On Vercel + webhook mode → start the client inline (one HTTP call).
- Off-Vercel → `GatewayManager` singleton holds long-lived clients in process.
**`GET /api/agent/gateway/route.ts`** (cron, `Bearer ${CRON_SECRET}`):
- Iterates registered platforms and starts every enabled persistent provider with `durationMs = 10min`, then in `after(...)` polls `BotConnectQueue` every 30s for new connect requests, until the window expires.
- `getEffectiveConnectionMode(platform, settings)` is the only place that resolves per-provider mode — respect it everywhere.
**`POST /api/agent/gateway/start/route.ts`** is the non-Vercel `ensureRunning` entry point (`Bearer ${KEY_VAULTS_SECRET}`).
**Runtime status** is stored in Redis at `bot:runtime-status:platform:appId` with TTL ≈ `durationMs + 60s`. States: `starting | connected | disconnected | failed | queued`. Updated by each `PlatformClient.start/stop` and by the gateway service.
## Platform Definitions
Each platform exposes a `PlatformDefinition` registered in `platforms/index.ts`:
```ts
{
id: 'discord',
name: 'Discord',
connectionMode: 'websocket', // recommended default
schema: FieldSchema[], // applicationId + credentials + settings
clientFactory: new DiscordClientFactory(),
supportsMarkdown?: boolean, // default true
supportsMessageEdit?: boolean, // default true
documentation?: { portalUrl, setupGuideUrl },
}
```
`schema` drives both server validation (`mergeWithDefaults`, `extractDefaults`) **and** the auto-generated UI form. Top-level keys `applicationId` / `credentials` / `settings` map to DB columns. Common settings fields live in `platforms/const.ts` (`displayToolCallsField`, `serverIdField`, `userIdField`).
Each platform implements `PlatformClient` (see `platforms/types.ts`):
- Lifecycle: `start(opts?)`, `stop()`
- Inbound: `createAdapter()` → Chat SDK adapter map
- Outbound: `getMessenger(platformThreadId)``{ createMessage, editMessage, removeReaction, triggerTyping, updateThreadName? }`
- Formatting: `formatMarkdown?`, `formatReply?` (usage-stats footer when `showUsageStats`)
- Helpers: `extractChatId`, `parseMessageId`, `sanitizeUserInput`, `shouldSubscribe`, `resolveReactionThreadId`
- Optional patches: `applyChatPatches(chatBot)` (Discord uses this for `forwardedInteractions` + `threadRecovery`)
- Optional menu: `registerBotCommands(commands)` (Telegram `setMyCommands`)
`ClientFactory.validateCredentials` is called from the TRPC `testConnection` mutation — implement it to hit the platform API and return useful per-field errors.
## Database
**Schema** (`packages/database/src/schemas/agentBotProvider.ts`):
```ts
agent_bot_providers (
id uuid pk,
agent_id text fk agents.id (cascade),
user_id text fk users.id (cascade),
platform varchar(50), // 'discord' | 'slack' | …
application_id varchar(255),
credentials text, // KeyVaults-encrypted JSON
settings jsonb default '{}',
enabled boolean default true,
timestamps
)
unique (platform, application_id)
```
**Model** (`packages/database/src/models/agentBotProvider.ts`):
- User-scoped: `create / update / delete / query / findById / findByAgentId / findEnabledByApplicationId`. Credentials are encrypted/decrypted via the injected `KeyVaultsGateKeeper`.
- Static (system-wide): `findByPlatformAndAppId`, `findEnabledByPlatform` — used by webhook routing & gateway sync, since they don't have a user context yet.
**TRPC router** (`src/server/routers/lambda/agentBotProvider.ts`):
| Procedure | Notes | |
| -------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------ |
| `listPlatforms` | Returns `SerializedPlatformDefinition[]` (no `clientFactory`) | |
| `create` / `update` / `delete` | Calls `BotMessageRouter.invalidateBot` + `GatewayService.stopClient` so changes take effect | |
| `list` / `getByAgentId` / `getRuntimeStatus` | Decorate rows with Redis runtime status | |
| `connectBot` | Returns \`{ status: 'started' | 'queued' }\` |
| `testConnection` | Calls `clientFactory.validateCredentials` | |
| `wechatGetQrCode` / `wechatPollQrStatus` | iLink onboarding flow | |
Client service: `src/services/agentBotProvider.ts`. Store actions: `src/store/agent/slices/bot/action.ts`. UI: `src/routes/(main)/agent/channel/{list,detail}` — settings form is auto-generated from each platform's `schema`.
## Reply Templates
`src/server/services/bot/replyTemplate.ts` exports `renderStart`, `renderStepProgress`, `renderFinalReply`, `renderError`, `renderStopped`, `splitMessage`. Step progress carries elapsed time, last LLM content, last tools, totals; final reply uses `client.formatMarkdown` then `client.formatReply` (which optionally appends `formatUsageStats`). `splitMessage(text, charLimit)` chunks at paragraph → line → hard cut.
`src/server/services/bot/ackPhrases/` provides randomized ack phrases.
## Key Files
```plaintext
Webhook routes:
src/app/(backend)/api/agent/webhooks/[platform]/[[...appId]]/route.ts — inbound catch-all
src/app/(backend)/api/agent/webhooks/bot-callback/route.ts — qstash bot callback
src/app/(backend)/api/agent/gateway/route.ts — cron gateway (10min window)
src/app/(backend)/api/agent/gateway/start/route.ts — non-Vercel ensureRunning
Bot service:
src/server/services/bot/index.ts — barrel
src/server/services/bot/BotMessageRouter.ts — lazy bot loading + handler registration + commands
src/server/services/bot/AgentBridgeService.ts — Chat SDK ↔ AiAgentService bridge, both exec modes
src/server/services/bot/BotCallbackService.ts — qstash callback handler
src/server/services/bot/formatPrompt.ts — speaker tag + referenced_message + sanitize
src/server/services/bot/replyTemplate.ts — render*/splitMessage
src/server/services/bot/ackPhrases/ — randomized acks
src/server/services/bot/__tests__/ — unit tests for the above
Platform abstraction:
src/server/services/bot/platforms/index.ts — registry singleton + exports
src/server/services/bot/platforms/types.ts — PlatformClient/Definition/FieldSchema/ClientFactory
src/server/services/bot/platforms/registry.ts — PlatformRegistry class
src/server/services/bot/platforms/utils.ts — mergeWithDefaults, getEffectiveConnectionMode, formatUsageStats, runtimeKey
src/server/services/bot/platforms/const.ts — shared FieldSchema fragments (displayToolCalls, serverId, userId)
src/server/services/bot/platforms/stripMarkdown.ts — used by no-markdown platforms
Per-platform (each ships definition.ts, schema.ts, client.ts, const.ts, protocol-spec.md):
src/server/services/bot/platforms/discord/ — websocket gateway + chat patches
src/server/services/bot/platforms/slack/ — multi-mode (Socket Mode / webhook), markdownToMrkdwn
src/server/services/bot/platforms/telegram/ — webhook, markdownToHTML, registerBotCommands
src/server/services/bot/platforms/feishu/ — feishu + lark share client/schema (definitions/{feishu,lark,shared}.ts)
src/server/services/bot/platforms/qq/ — websocket, no markdown, no edit
src/server/services/bot/platforms/wechat/ — long-poll, no markdown, no edit
Gateway:
src/server/services/gateway/index.ts — GatewayService (Vercel-aware startClient/stopClient)
src/server/services/gateway/GatewayManager.ts — long-running client registry (non-Vercel)
src/server/services/gateway/botConnectQueue.ts — Redis hash queue with TTL
src/server/services/gateway/runtimeStatus.ts — Redis bot:runtime-status keys
Database:
packages/database/src/schemas/agentBotProvider.ts — agent_bot_providers table
packages/database/src/models/agentBotProvider.ts — encrypted CRUD + system-wide finders
TRPC + client:
src/server/routers/lambda/agentBotProvider.ts — TRPC router
src/services/agentBotProvider.ts — client wrapper
src/store/agent/slices/bot/action.ts — Zustand actions
UI:
src/routes/(main)/agent/channel/list.tsx — channel list
src/routes/(main)/agent/channel/detail/ — auto-generated form (Header/Body/Footer)
src/routes/(main)/agent/channel/const.ts — platform icons
Types & runtime status:
src/types/botRuntimeStatus.ts — BOT_RUNTIME_STATUSES enum + snapshot type
```
## Adding a New Platform
1. Create `src/server/services/bot/platforms/<id>/`:
- `definition.ts``PlatformDefinition` registered in `platforms/index.ts`
- `schema.ts``FieldSchema[]` (`applicationId` + `credentials` + `settings`); reuse fragments from `../const.ts`
- `client.ts``class XClientFactory extends ClientFactory` returning a `PlatformClient` (lifecycle + adapter + messenger + helpers)
- `const.ts``DEFAULT_X_CONNECTION_MODE`, history limits, etc.
- `protocol-spec.md` — protocol notes (every existing platform has one)
2. Pick the right `connectionMode` — webhook is much simpler if the platform supports it.
3. If the platform can't render markdown, set `supportsMarkdown: false` and implement `formatMarkdown` via `stripMarkdown`.
4. If it can't edit messages, set `supportsMessageEdit: false``BotCallbackService` will skip step edits and only send the final reply.
5. Implement `validateCredentials` so the UI's "Test connection" button gives useful errors.
6. Add the platform icon in `src/routes/(main)/agent/channel/const.ts` and register the platform in `src/server/services/bot/platforms/index.ts`.
7. Add i18n keys under `channel.*` in `src/locales/default/setting.ts` (or wherever the channel namespace lives) — the schema's `label`/`description`/`placeholder`/`enumLabels` are i18n keys.
+218
View File
@@ -0,0 +1,218 @@
---
name: cli-backend-testing
description: >
CLI + Backend integration testing workflow. Use when verifying backend API changes
(TRPC routers, services, models) via the LobeHub CLI against a local dev server.
Triggers on 'cli test', 'test with cli', 'verify with cli', 'local cli test',
'backend test with cli', or when needing to validate server-side changes end-to-end.
---
# CLI + Backend Integration Testing
Standard workflow for verifying backend changes using the LobeHub CLI (`lh`) against a local dev server.
## When to Use
- Verifying TRPC router / service / model changes end-to-end
- Testing new API fields or response structure changes
- Validating CLI command output after backend modifications
- Debugging data flow issues between server and CLI
## Prerequisites
| Requirement | Details |
| ------------ | ------------------------------------------------------------- |
| Dev server | `localhost:3011` (Next.js) |
| CLI source | `lobehub/apps/cli/` |
| CLI dev mode | Uses `LOBEHUB_CLI_HOME=.lobehub-dev` for isolated credentials |
| Auth | Device Code Flow login to local server |
## Quick Reference
All CLI dev commands run from `lobehub/apps/cli/`:
```bash
# Shorthand for all commands below
CLI="LOBEHUB_CLI_HOME=.lobehub-dev bun src/index.ts"
```
## Workflow
### Step 1: Ensure Dev Server is Running
Check if the dev server is already running:
```bash
curl -s -o /dev/null -w '%{http_code}' http://localhost:3011/ 2> /dev/null
```
- **If reachable** (returns any HTTP status): server is running. Skip to Step 2.
- **If unreachable**: start the server:
```bash
# From cloud repo root
pnpm run dev:next
```
To **restart** (pick up server-side code changes):
```bash
lsof -ti:3011 | xargs kill
pnpm run dev:next
```
**Important:** Server-side code changes in the submodule (`lobehub/src/server/`, `lobehub/packages/`) require a server restart. Next.js hot-reload may not pick up changes in submodule packages.
### Step 2: Check CLI Authentication
Check if dev credentials already exist:
```bash
cat lobehub/apps/cli/.lobehub-dev/settings.json 2> /dev/null
```
- **If file exists and contains `"serverUrl": "http://localhost:3011"`**: already authenticated. Skip to Step 3.
- **If file missing or points to wrong server**: login is needed. Ask the user to run:
```bash
! cd lobehub/apps/cli && LOBEHUB_CLI_HOME=.lobehub-dev bun src/index.ts login --server http://localhost:3011
```
> Login requires interactive browser authorization (OIDC Device Code Flow), so the user must run it themselves via `!` prefix. After login, credentials are saved to `lobehub/apps/cli/.lobehub-dev/` and persist across sessions.
### Step 3: Test with CLI Commands
CLI runs from source (`bun src/index.ts`), so CLI-side code changes take effect immediately without rebuilding.
```bash
cd lobehub/apps/cli
LOBEHUB_CLI_HOME=.lobehub-dev bun src/index.ts <command>
```
### Step 4: Clean Up Test Data
Delete any test data created during verification:
```bash
LOBEHUB_CLI_HOME=.lobehub-dev bun src/index.ts task delete < id > -y
LOBEHUB_CLI_HOME=.lobehub-dev bun src/index.ts agent delete < id > -y
```
## Common Testing Patterns
### Task System
```bash
# List tasks
$CLI task list
# Create test data with nesting
$CLI task create -n "Root Task" -i "Test instruction"
$CLI task create -n "Child Task" -i "Sub instruction" --parent T-1
# View task detail (tests getTaskDetail service)
$CLI task view T-1
# View task tree
$CLI task tree T-1
# Test lifecycle
$CLI task edit T-1 --status running
$CLI task comment T-1 -m "Test comment"
# Clean up
$CLI task delete T-1 -y
```
### Agent System
```bash
# List agents
$CLI agent list
# View agent detail
$CLI agent view <agent-id>
# Run agent (tests agent execution pipeline)
$CLI agent run <agent-id> -m "Test prompt"
```
### Document & Knowledge Base
```bash
# List documents
$CLI doc list
# Create and view
$CLI doc create -t "Test Doc" -c "Content here"
$CLI doc view <doc-id>
# Knowledge base
$CLI kb list
$CLI kb tree <kb-id>
```
### Model & Provider
```bash
# List models and providers
$CLI model list
$CLI provider list
# Test provider connectivity
$CLI provider test <provider-id>
```
## Dev-Test Cycle
The standard cycle for backend development:
```
1. Make code changes (service/model/router/type)
|
2. Run unit tests (fast feedback)
bunx vitest run --silent='passed-only' '<test-file>'
|
3. Restart dev server (if server-side changes)
lsof -ti:3011 | xargs kill && pnpm run dev:next
|
4. CLI verification (end-to-end)
LOBEHUB_CLI_HOME=.lobehub-dev bun src/index.ts <command>
|
5. Clean up test data
```
### When Server Restart is Needed
| Change Location | Restart? |
| ----------------------------------------- | -------- |
| `lobehub/src/server/` (routers, services) | Yes |
| `lobehub/packages/database/` (models) | Yes |
| `lobehub/packages/types/` | Yes |
| `lobehub/packages/prompts/` | Yes |
| `lobehub/apps/cli/` (CLI code) | No |
| `src/` (cloud overrides) | Yes |
### When Server Restart is NOT Needed
CLI runs from source via `bun src/index.ts`, so any changes to `lobehub/apps/cli/src/` take effect immediately on next command invocation.
## Troubleshooting
| Issue | Solution |
| --------------------------- | --------------------------------------------------------------------- |
| `No authentication found` | Run `login --server http://localhost:3011` |
| `UNAUTHORIZED` on API calls | Token expired; re-run login |
| `ECONNREFUSED` | Dev server not running; start with `pnpm run dev:next` |
| CLI shows old data/behavior | Server needs restart to pick up code changes |
| `EADDRINUSE` on port 3011 | Server already running; kill with `lsof -ti:3011 \| xargs kill` |
| Login opens wrong server | Must use `--server http://localhost:3011` flag (env var doesn't work) |
## Credential Isolation
| Mode | Credential Dir | Server |
| ---------- | -------------------------------- | ----------------- |
| Dev | `lobehub/apps/cli/.lobehub-dev/` | `localhost:3011` |
| Production | `~/.lobehub/` | `app.lobehub.com` |
The two environments are completely isolated. Dev mode credentials are gitignored.
+1 -1
View File
@@ -46,7 +46,7 @@ description: 'Code review checklist for LobeHub. Use when reviewing PRs, diffs,
- Newly written code duplicates existing utilities in `packages/utils` or shared modules?
- Copy-pasted blocks with slight variation — extract into shared function
- `antd` imports replaceable with `@lobehub/ui` wrapped components (`Input`, `Button`, `Modal`, `Avatar`, etc.)
- Use `antd-style` token system, not hardcoded colors
- Use `antd-style` token system, not hardcoded colors; prefer `createStaticStyles` + `cssVar.*` over `createStyles` + `token` unless runtime computation is required
### Database
+5 -3
View File
@@ -20,9 +20,11 @@ This is NON-NEGOTIABLE. Skipping Linear comments is a workflow violation.
## Workflow
1. **Retrieve issue details** before starting: `mcp__linear-server__get_issue`
2. **Check for sub-issues**: Use `mcp__linear-server__list_issues` with `parentId` filter
3. **Update issue status** when completing: `mcp__linear-server__update_issue`
4. **Add completion comment** (REQUIRED): `mcp__linear-server__create_comment`
2. **Read images**: If the issue description contains images, MUST use `mcp__linear-server__extract_images` to read image content for full context
3. **Check for sub-issues**: Use `mcp__linear-server__list_issues` with `parentId` filter
4. **Mark as In Progress**: When starting to plan or implement an issue, immediately update status to **"In Progress"** via `mcp__linear-server__update_issue`
5. **Update issue status** when completing: `mcp__linear-server__update_issue`
6. **Add completion comment** (REQUIRED): `mcp__linear-server__create_comment`
## Creating Issues
+516
View File
@@ -0,0 +1,516 @@
---
name: local-testing
description: >
Local app and bot testing. Uses agent-browser CLI for Electron/web app UI testing,
and osascript (AppleScript) for controlling native macOS apps (WeChat, Discord, Telegram, Slack, Lark/飞书, QQ)
to test bots. Triggers on 'local test', 'test in electron', 'test desktop', 'test bot',
'bot test', 'test in discord', 'test in telegram', 'test in slack', 'test in weixin',
'test in wechat', 'test in lark', 'test in feishu', 'test in qq',
'manual test', 'osascript', or UI/bot verification tasks.
---
# Local App & Bot Testing
Two approaches for local testing on macOS:
| Approach | Tool | Best For |
| --------------------------- | ------------------- | ---------------------------------------------------- |
| **agent-browser + CDP** | `agent-browser` CLI | Electron apps, web apps (DOM access, JS eval) |
| **osascript (AppleScript)** | `osascript -e` | Native macOS apps (WeChat, Discord, Telegram, Slack) |
---
# Part 1: agent-browser (Electron / Web Apps)
Use `agent-browser` to automate Chromium-based apps via Chrome DevTools Protocol.
Install via `npm i -g agent-browser`, `brew install agent-browser`, or `cargo install agent-browser`. Run `agent-browser install` to download Chrome. Run `agent-browser upgrade` to update.
## Core Workflow
Every browser automation follows this pattern:
1. **Navigate**: `agent-browser open <url>`
2. **Snapshot**: `agent-browser snapshot -i` (get element refs like `@e1`, `@e2`)
3. **Interact**: Use refs to click, fill, select
4. **Re-snapshot**: After navigation or DOM changes, get fresh refs
```bash
agent-browser open https://example.com/form
agent-browser snapshot -i
# Output: @e1 [input type="email"], @e2 [input type="password"], @e3 [button] "Submit"
agent-browser fill @e1 "user@example.com"
agent-browser fill @e2 "password123"
agent-browser click @e3
agent-browser wait --load networkidle
agent-browser snapshot -i # Check result
```
## Command Chaining
```bash
# Chain open + wait + snapshot in one call
agent-browser open https://example.com && agent-browser wait --load networkidle && agent-browser snapshot -i
```
Use `&&` when you don't need to read intermediate output. Run commands separately when you need to parse output first (e.g., snapshot to discover refs, then interact).
## Essential Commands
```bash
# Navigation
agent-browser open <url> # Navigate (aliases: goto, navigate)
agent-browser close # Close browser
agent-browser close --all # Close all active sessions
# Snapshot
agent-browser snapshot -i # Interactive elements with refs (recommended)
agent-browser snapshot -s "#selector" # Scope to CSS selector
# Interaction (use @refs from snapshot)
agent-browser click @e1 # Click element
agent-browser click @e1 --new-tab # Click and open in new tab
agent-browser fill @e2 "text" # Clear and type text
agent-browser type @e2 "text" # Type without clearing
agent-browser select @e1 "option" # Select dropdown option
agent-browser check @e1 # Check checkbox
agent-browser press Enter # Press key
agent-browser keyboard type "text" # Type at current focus (no selector)
agent-browser keyboard inserttext "text" # Insert without key events
agent-browser scroll down 500 # Scroll page
agent-browser scroll down 500 --selector "div.content" # Scroll within container
# Get information
agent-browser get text @e1 # Get element text
agent-browser get url # Get current URL
agent-browser get title # Get page title
agent-browser get cdp-url # Get CDP WebSocket URL
# Wait
agent-browser wait @e1 # Wait for element
agent-browser wait --load networkidle # Wait for network idle
agent-browser wait --url "**/page" # Wait for URL pattern
agent-browser wait 2000 # Wait milliseconds
agent-browser wait --text "Welcome" # Wait for text to appear
agent-browser wait --fn "!document.body.innerText.includes('Loading...')" # Wait for text to disappear
agent-browser wait "#spinner" --state hidden # Wait for element to disappear
# Downloads
agent-browser download @e1 ./file.pdf # Click element to trigger download
agent-browser wait --download ./output.zip # Wait for any download to complete
# Network
agent-browser network requests # Inspect tracked requests
agent-browser network requests --type xhr,fetch # Filter by resource type
agent-browser network requests --method POST # Filter by HTTP method
agent-browser network route "**/api/*" --abort # Block matching requests
agent-browser network har start # Start HAR recording
agent-browser network har stop ./capture.har # Stop and save HAR file
# Viewport & Device Emulation
agent-browser set viewport 1920 1080 # Set viewport size (default: 1280x720)
agent-browser set viewport 1920 1080 2 # 2x retina
agent-browser set device "iPhone 14" # Emulate device (viewport + user agent)
# Capture
agent-browser screenshot # Screenshot to temp dir
agent-browser screenshot --full # Full page screenshot
agent-browser screenshot --annotate # Annotated screenshot with numbered element labels
agent-browser pdf output.pdf # Save as PDF
# Clipboard
agent-browser clipboard read # Read text from clipboard
agent-browser clipboard write "text" # Write text to clipboard
agent-browser clipboard copy # Copy current selection
agent-browser clipboard paste # Paste from clipboard
# Dialogs (alert, confirm, prompt, beforeunload)
agent-browser dialog accept # Accept dialog
agent-browser dialog accept "input" # Accept prompt dialog with text
agent-browser dialog dismiss # Dismiss/cancel dialog
agent-browser dialog status # Check if dialog is open
# Diff (compare page states)
agent-browser diff snapshot # Compare current vs last snapshot
agent-browser diff screenshot --baseline before.png # Visual pixel diff
agent-browser diff url <url1> <url2> # Compare two pages
# Streaming
agent-browser stream enable # Start WebSocket streaming
agent-browser stream status # Inspect streaming state
agent-browser stream disable # Stop streaming
```
## Batch Execution
```bash
echo '[
["open", "https://example.com"],
["snapshot", "-i"],
["click", "@e1"],
["screenshot", "result.png"]
]' | agent-browser batch --json
```
## Authentication
```bash
# Option 1: Auth vault (credentials stored encrypted)
echo "$PASSWORD" | agent-browser auth save myapp --url https://app.example.com/login --username user --password-stdin
agent-browser auth login myapp
# Option 2: Session name (auto-save/restore cookies + localStorage)
agent-browser --session-name myapp open https://app.example.com/login
agent-browser close # State auto-saved
agent-browser --session-name myapp open https://app.example.com/dashboard # Auto-restored
# Option 3: Persistent profile
agent-browser --profile ~/.myapp open https://app.example.com/login
# Option 4: State file
agent-browser state save auth.json
agent-browser state load auth.json
```
## Semantic Locators (Alternative to Refs)
```bash
agent-browser find text "Sign In" click
agent-browser find label "Email" fill "user@test.com"
agent-browser find role button click --name "Submit"
agent-browser find placeholder "Search" type "query"
agent-browser find testid "submit-btn" click
```
## JavaScript Evaluation (eval)
```bash
# Simple expressions
agent-browser eval 'document.title'
# Complex JS: use --stdin with heredoc (RECOMMENDED)
agent-browser eval --stdin << 'EVALEOF'
JSON.stringify(
Array.from(document.querySelectorAll("img"))
.filter(i => !i.alt)
.map(i => ({ src: i.src.split("/").pop(), width: i.width }))
)
EVALEOF
# Base64 encoding (avoids all shell escaping issues)
agent-browser eval -b "$(echo -n 'document.title' | base64)"
```
## Ref Lifecycle
Refs (`@e1`, `@e2`, etc.) are invalidated when the page changes. Always re-snapshot after clicking links/buttons that navigate, form submissions, or dynamic content loading.
## Annotated Screenshots (Vision Mode)
```bash
agent-browser screenshot --annotate
# Output includes the image path and a legend:
# [1] @e1 button "Submit"
# [2] @e2 link "Home"
agent-browser click @e2 # Click using ref from annotated screenshot
```
## Parallel Sessions
```bash
agent-browser --session site1 open https://site-a.com
agent-browser --session site2 open https://site-b.com
agent-browser session list
```
## Connect to Existing Chrome
```bash
agent-browser --auto-connect snapshot # Auto-discover running Chrome
agent-browser --cdp 9222 snapshot # Explicit CDP port
```
## iOS Simulator (Mobile Safari)
```bash
agent-browser device list
agent-browser -p ios --device "iPhone 16 Pro" open https://example.com
agent-browser -p ios snapshot -i
agent-browser -p ios tap @e1
agent-browser -p ios swipe up
agent-browser -p ios screenshot mobile.png
agent-browser -p ios close
```
## Observability Dashboard
```bash
agent-browser dashboard install
agent-browser dashboard start # Background server on port 4848
agent-browser dashboard stop
```
## Cloud Providers
Use `-p <provider>` to run against cloud browsers: `agentcore`, `browserbase`, `browserless`, `browseruse`, `kernel`.
## Browser Engine Selection
```bash
agent-browser --engine lightpanda open example.com # 10x faster, 10x less memory
```
## Electron (LobeHub Desktop)
### Setup / Teardown
Use the `electron-dev.sh` script to manage the Electron dev environment. It handles process lifecycle, waits for SPA readiness, and reliably kills all child processes (main + helpers + vite).
```bash
SCRIPT=".agents/skills/local-testing/scripts/electron-dev.sh"
# Start Electron dev with CDP (idempotent — skips if already running)
$SCRIPT start
# Check if Electron is running and CDP is reachable
$SCRIPT status
# Kill all Electron-related processes (main + helper + vite)
$SCRIPT stop
# Force fresh restart
$SCRIPT restart
```
After `start` succeeds, connect with: `agent-browser --cdp 9222 snapshot -i`
**Always run `$SCRIPT stop` when done testing**`pkill -f "Electron"` alone won't catch all helper processes.
#### Environment Variables
| Variable | Default | Description |
| ----------------- | ----------------------- | ---------------------------------------- |
| `CDP_PORT` | `9222` | Chrome DevTools Protocol port |
| `ELECTRON_LOG` | `/tmp/electron-dev.log` | Electron process log |
| `ELECTRON_WAIT_S` | `60` | Max seconds to wait for Electron process |
| `RENDERER_WAIT_S` | `60` | Max seconds to wait for SPA to load |
### LobeHub-Specific Patterns
#### Access Zustand Store State
```bash
agent-browser --cdp 9222 eval --stdin << 'EVALEOF'
(function() {
var chat = window.__LOBE_STORES.chat();
var ops = Object.values(chat.operations);
return JSON.stringify({
ops: ops.map(function(o) { return { type: o.type, status: o.status }; }),
activeAgent: chat.activeAgentId,
activeTopic: chat.activeTopicId,
});
})()
EVALEOF
```
#### Find and Use the Chat Input
```bash
# The chat input is contenteditable — must use -C flag
agent-browser --cdp 9222 snapshot -i -C 2>&1 | grep "editable"
agent-browser --cdp 9222 click @e48
agent-browser --cdp 9222 type @e48 "Hello world"
agent-browser --cdp 9222 press Enter
```
#### Wait for Agent to Complete
```bash
agent-browser --cdp 9222 eval --stdin << 'EVALEOF'
(function() {
var chat = window.__LOBE_STORES.chat();
var ops = Object.values(chat.operations);
var running = ops.filter(function(o) { return o.status === 'running'; });
return running.length === 0 ? 'done' : 'running: ' + running.length;
})()
EVALEOF
```
#### Install Error Interceptor
```bash
agent-browser --cdp 9222 eval --stdin << 'EVALEOF'
(function() {
window.__CAPTURED_ERRORS = [];
var orig = console.error;
console.error = function() {
var msg = Array.from(arguments).map(function(a) {
if (a instanceof Error) return a.message;
return typeof a === 'object' ? JSON.stringify(a) : String(a);
}).join(' ');
window.__CAPTURED_ERRORS.push(msg);
orig.apply(console, arguments);
};
return 'installed';
})()
EVALEOF
# Later, check captured errors:
agent-browser --cdp 9222 eval "JSON.stringify(window.__CAPTURED_ERRORS)"
```
## Chrome / Web Apps
```bash
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--remote-debugging-port=9222 \
--user-data-dir=/tmp/chrome-test-profile \
"<URL>" &
sleep 5
agent-browser --cdp 9222 snapshot -i
# Or auto-discover running Chrome with remote debugging
agent-browser --auto-connect snapshot -i
```
---
# Part 2: osascript (Native macOS App Bot Testing)
Use AppleScript via `osascript` to control native macOS desktop apps for bot testing. Works with any app that supports macOS Accessibility, no CDP or Chromium needed.
The pattern is the same for every platform:
1. **Activate** the app (`tell application "X" to activate`)
2. **Navigate** to a channel/chat (Quick Switcher `Cmd+K` or Search `Cmd+F`)
3. **Send** a message (clipboard paste `Cmd+V` + Enter)
4. **Wait** for the bot response
5. **Screenshot** for verification (`screencapture` + `Read` tool)
## Per-Platform References
Pick the file for your target platform — each contains activation, navigation, send-message, and verification snippets specific to that app:
| Platform | Reference | Quick switcher |
| ------------- | -------------------------------------------------- | -------------- |
| Discord | [references/discord.md](./references/discord.md) | `Cmd+K` |
| Slack | [references/slack.md](./references/slack.md) | `Cmd+K` |
| Telegram | [references/telegram.md](./references/telegram.md) | `Cmd+F` |
| WeChat / 微信 | [references/wechat.md](./references/wechat.md) | `Cmd+F` |
| Lark / 飞书 | [references/lark.md](./references/lark.md) | `Cmd+K` |
| QQ | [references/qq.md](./references/qq.md) | `Cmd+F` |
For **shared osascript patterns** (activate, type, paste, screenshot, read accessibility, common workflow template, gotchas), see [references/osascript-common.md](./references/osascript-common.md). Read this first if you're new to osascript automation.
---
# Scripts
Ready-to-use scripts in `.agents/skills/local-testing/scripts/`:
| Script | Usage |
| ------------------------- | --------------------------------------------------- |
| `electron-dev.sh` | Manage Electron dev env (start/stop/status/restart) |
| `capture-app-window.sh` | Capture screenshot of a specific app window |
| `record-electron-demo.sh` | Record Electron app demo with ffmpeg |
| `record-app-screen.sh` | Record app screen (video + screenshots, start/stop) |
| `test-discord-bot.sh` | Send message to Discord bot via osascript |
| `test-slack-bot.sh` | Send message to Slack bot via osascript |
| `test-telegram-bot.sh` | Send message to Telegram bot via osascript |
| `test-wechat-bot.sh` | Send message to WeChat bot via osascript |
| `test-lark-bot.sh` | Send message to Lark / 飞书 bot via osascript |
| `test-qq-bot.sh` | Send message to QQ bot via osascript |
### Window Screenshot Utility
`capture-app-window.sh` captures a screenshot of a specific app window using `screencapture -l <windowID>`. It uses Swift + CGWindowList to find the window by process name, so screenshots work correctly even when the window is on an external monitor or behind other windows.
```bash
# Standalone usage
./.agents/skills/local-testing/scripts/capture-app-window.sh "Discord" /tmp/discord.png
./.agents/skills/local-testing/scripts/capture-app-window.sh "Slack" /tmp/slack.png
./.agents/skills/local-testing/scripts/capture-app-window.sh "WeChat" /tmp/wechat.png
```
All bot test scripts use this utility automatically for their screenshots.
### Bot Test Scripts
All bot test scripts share the same interface:
```bash
./scripts/test-<platform>-bot.sh <channel_or_contact> <message> [wait_seconds] [screenshot_path]
```
Examples:
```bash
# Discord — test a bot in #bot-testing channel
./.agents/skills/local-testing/scripts/test-discord-bot.sh "bot-testing" "!ping"
./.agents/skills/local-testing/scripts/test-discord-bot.sh "bot-testing" "/ask Tell me a joke" 30
# Slack — test a bot in #bot-testing channel
./.agents/skills/local-testing/scripts/test-slack-bot.sh "bot-testing" "@mybot hello"
./.agents/skills/local-testing/scripts/test-slack-bot.sh "bot-testing" "/ask What is 2+2?" 20
# Telegram — test a bot by username
./.agents/skills/local-testing/scripts/test-telegram-bot.sh "MyTestBot" "/start"
./.agents/skills/local-testing/scripts/test-telegram-bot.sh "GPTBot" "Hello" 60
# WeChat — test a bot or send to a contact
./.agents/skills/local-testing/scripts/test-wechat-bot.sh "文件传输助手" "test message" 5
./.agents/skills/local-testing/scripts/test-wechat-bot.sh "MyBot" "Tell me a joke" 30
# Lark/飞书 — test a bot in a group chat
./.agents/skills/local-testing/scripts/test-lark-bot.sh "bot-testing" "@MyBot hello"
./.agents/skills/local-testing/scripts/test-lark-bot.sh "bot-testing" "Help me with this" 30
# QQ — test a bot in a group or direct chat
./.agents/skills/local-testing/scripts/test-qq-bot.sh "bot-testing" "Hello bot" 15
./.agents/skills/local-testing/scripts/test-qq-bot.sh "MyBot" "/help" 10
```
Each script: activates the app, navigates to the channel/contact, pastes the message via clipboard, sends, waits, and takes a screenshot. Use the `Read` tool on the screenshot for visual verification.
---
# Screen Recording
Record automated demos using `record-app-screen.sh` (start/stop lifecycle, CDP screenshots + ffmpeg assembly). See [references/record-app-screen.md](references/record-app-screen.md) for full documentation.
```bash
./.agents/skills/local-testing/scripts/electron-dev.sh start
./.agents/skills/local-testing/scripts/record-app-screen.sh start my-demo
# ... run automation ...
./.agents/skills/local-testing/scripts/record-app-screen.sh stop
```
Outputs to `.records/` directory (gitignored): `<name>.mp4` (video) + `<name>/` (screenshots every 3s).
---
# Gotchas
### agent-browser
- **Daemon can get stuck** — if commands hang, `agent-browser close --all` or `pkill -f agent-browser` to reset
- **HMR invalidates everything** — after code changes, refs break. Re-snapshot or restart
- **`snapshot -i` doesn't find contenteditable** — use `snapshot -i -C` for rich text editors
- **`fill` doesn't work on contenteditable** — use `type` for chat inputs
- **Screenshots go to `~/.agent-browser/tmp/screenshots/`** — read them with the `Read` tool
- **Dialogs block all commands** — if commands time out, check `agent-browser dialog status`
- **Default timeout is 25s** — override with `AGENT_BROWSER_DEFAULT_TIMEOUT` (ms) or use explicit waits
- **Shell quoting corrupts eval** — use `eval --stdin <<'EVALEOF'` for complex JS
### Electron-specific
- **Always use `electron-dev.sh stop` to clean up** — `pkill -f "Electron"` only kills the main process; helper processes (GPU, renderer, network) survive. The script finds and kills all of them via PID matching against the project's electron binary path.
- **`npx electron-vite dev` must run from `apps/desktop/`** — running from project root fails silently. The `electron-dev.sh` script handles this automatically.
- **Don't resize the Electron window after load** — resizing triggers full SPA reload
- **Store is at `window.__LOBE_STORES`** not `window.__ZUSTAND_STORES__`
### osascript
See [references/osascript-common.md](./references/osascript-common.md#gotchas) for the full osascript gotchas list (accessibility permissions, `keystroke` non-ASCII issues, locale-specific app names, rate limiting, etc.).
@@ -0,0 +1,97 @@
# Discord Bot Testing
**App name:** `Discord` | **Process name:** `Discord`
See [osascript-common.md](./osascript-common.md) for shared patterns.
## Activate & Navigate
```bash
# Activate Discord
osascript -e 'tell application "Discord" to activate'
sleep 1
# Open Quick Switcher (Cmd+K) to navigate to a channel
osascript -e 'tell application "System Events" to keystroke "k" using command down'
sleep 0.5
osascript -e 'tell application "System Events" to keystroke "bot-testing"'
sleep 1
osascript -e 'tell application "System Events" to key code 36' # Enter
sleep 2
```
## Send Message to Bot
```bash
# The message input is focused after navigating to a channel
# Type a message
osascript -e 'tell application "System Events" to keystroke "/hello"'
sleep 0.5
osascript -e 'tell application "System Events" to key code 36' # Enter
```
## Send Long Message (via clipboard)
```bash
osascript -e '
tell application "Discord" to activate
delay 0.5
set the clipboard to "Write a 3000 word essay about space exploration"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter
end tell
'
```
## Verify Bot Response
```bash
# Wait for bot to respond, then screenshot
sleep 10
screencapture /tmp/discord-bot-response.png
# Read with the Read tool for visual verification
```
## Full Bot Test Example
```bash
#!/usr/bin/env bash
# test-discord-bot.sh — Send message and verify bot response
# 1. Activate Discord and navigate to channel
osascript -e '
tell application "Discord" to activate
delay 1
-- Quick Switcher
tell application "System Events" to keystroke "k" using command down
delay 0.5
tell application "System Events" to keystroke "bot-testing"
delay 1
tell application "System Events" to key code 36
delay 2
'
# 2. Send test message
osascript -e '
set the clipboard to "!ping"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36
end tell
'
# 3. Wait for response and capture
sleep 5
screencapture /tmp/discord-test-result.png
echo "Screenshot saved to /tmp/discord-test-result.png"
```
## Script
```bash
./.agents/skills/local-testing/scripts/test-discord-bot.sh "bot-testing" "!ping"
./.agents/skills/local-testing/scripts/test-discord-bot.sh "bot-testing" "/ask Tell me a joke" 30
```
@@ -0,0 +1,61 @@
# Lark / 飞书 Bot Testing
**App name:** `Lark` or `飞书` | **Process name:** `Lark` or `飞书`
See [osascript-common.md](./osascript-common.md) for shared patterns.
## Activate & Navigate
```bash
# Activate Lark (auto-detects Lark or 飞书)
osascript -e 'tell application "Lark" to activate' 2> /dev/null \
|| osascript -e 'tell application "飞书" to activate'
sleep 1
# Quick Switcher / Search (Cmd+K)
osascript -e 'tell application "System Events" to keystroke "k" using command down'
sleep 0.5
osascript -e '
set the clipboard to "bot-testing"
tell application "System Events"
keystroke "v" using command down
delay 1.5
key code 36 -- Enter
end tell
'
sleep 2
```
## Send Message to Bot
```bash
osascript -e '
set the clipboard to "@MyBot help me with this task"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter
end tell
'
```
## Verify Response
```bash
sleep 10
screencapture /tmp/lark-bot-response.png
```
## Lark-Specific Notes
- App name varies: `Lark` (international) vs `飞书` (China mainland) — the script auto-detects
- Uses `Cmd+K` for quick search (same as Discord/Slack)
- Enter sends message by default
- Always use clipboard paste for CJK characters
## Script
```bash
./.agents/skills/local-testing/scripts/test-lark-bot.sh "bot-testing" "@MyBot hello"
./.agents/skills/local-testing/scripts/test-lark-bot.sh "bot-testing" "Help me with this" 30
```
@@ -0,0 +1,217 @@
# osascript Common Patterns
Shared AppleScript / `osascript` patterns used by all platform bot tests. Read this first, then refer to the per-platform file for app-specific quirks.
## Core Patterns
### Activate an App
```bash
osascript -e 'tell application "Discord" to activate'
```
### Type Text
```bash
# Type character by character (reliable, but slow for long text)
osascript -e 'tell application "System Events" to keystroke "Hello world"'
# Press Enter
osascript -e 'tell application "System Events" to key code 36'
# Press Tab
osascript -e 'tell application "System Events" to key code 48'
# Press Escape
osascript -e 'tell application "System Events" to key code 53'
```
### Paste from Clipboard (fast, for long text)
```bash
# Set clipboard and paste — much faster than keystroke for long messages
osascript -e 'set the clipboard to "Your long message here"'
osascript -e 'tell application "System Events" to keystroke "v" using command down'
```
Or in one shot:
```bash
osascript -e '
set the clipboard to "Your long message here"
tell application "System Events" to keystroke "v" using command down
'
```
### Keyboard Shortcuts
```bash
# Cmd+K (quick switcher in Discord/Slack)
osascript -e 'tell application "System Events" to keystroke "k" using command down'
# Cmd+F (search)
osascript -e 'tell application "System Events" to keystroke "f" using command down'
# Cmd+N (new message/chat)
osascript -e 'tell application "System Events" to keystroke "n" using command down'
# Cmd+Shift+K (example: multi-modifier)
osascript -e 'tell application "System Events" to keystroke "k" using {command down, shift down}'
```
### Click at Position
```bash
# Click at absolute screen coordinates
osascript -e '
tell application "System Events"
click at {500, 300}
end tell
'
```
### Get Window Info
```bash
# Get window position and size
osascript -e '
tell application "System Events"
tell process "Discord"
get {position, size} of window 1
end tell
end tell
'
```
### Screenshot
```bash
# Full screen
screencapture /tmp/screenshot.png
# Interactive region select
screencapture -i /tmp/screenshot.png
# Specific window (by window ID from CGWindowList)
screencapture -l < WINDOW_ID > /tmp/screenshot.png
```
To get window ID for a specific app:
```bash
osascript -e '
tell application "System Events"
tell process "Discord"
get id of window 1
end tell
end tell
'
```
### Read Accessibility Elements
```bash
# Get all UI elements of the frontmost window (can be slow/large)
osascript -e '
tell application "System Events"
tell process "Discord"
entire contents of window 1
end tell
end tell
'
# Get a specific element's value
osascript -e '
tell application "System Events"
tell process "Discord"
get value of text field 1 of window 1
end tell
end tell
'
```
> **Warning:** `entire contents` can be extremely slow on complex UIs. Prefer screenshots + `Read` tool for visual verification.
### Read Screen Text via Clipboard
For reading the latest message or response from an app:
```bash
# Select all text in the focused area and copy
osascript -e '
tell application "System Events"
keystroke "a" using command down
keystroke "c" using command down
end tell
'
sleep 0.5
# Read clipboard
pbpaste
```
---
## Common Bot Testing Workflow
Regardless of platform, the pattern is:
```bash
APP_NAME="Discord" # or "Slack", "Telegram", "微信"
CHANNEL="bot-testing"
MESSAGE="Hello bot!"
WAIT_SECONDS=10
# 1. Activate
osascript -e "tell application \"$APP_NAME\" to activate"
sleep 1
# 2. Navigate to channel/chat (via Quick Switcher or Search)
osascript -e 'tell application "System Events" to keystroke "k" using command down'
sleep 0.5
osascript -e "tell application \"System Events\" to keystroke \"$CHANNEL\""
sleep 1
osascript -e 'tell application "System Events" to key code 36'
sleep 2
# 3. Send message
osascript -e "set the clipboard to \"$MESSAGE\""
osascript -e '
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36
end tell
'
# 4. Wait for bot response
sleep "$WAIT_SECONDS"
# 5. Screenshot for verification
screencapture /tmp/"${APP_NAME,,}"-bot-test.png
echo "Result saved to /tmp/${APP_NAME,,}-bot-test.png"
```
### Tips
- **Use clipboard paste** (`Cmd+V`) for messages containing special characters or long text — `keystroke` can mangle non-ASCII
- **Add `delay`** between actions — apps need time to process UI events
- **Screenshot for verification** — use `screencapture` + `Read` tool for visual checks
- **Use a dedicated test channel/chat** — avoid polluting real conversations
- **Check app name** — some apps have different names in different locales (e.g., `微信` vs `WeChat`)
- **Accessibility permissions required** — System Events automation requires granting Accessibility access in System Preferences > Privacy & Security > Accessibility
---
## Gotchas
- **Accessibility permission required** — first run will prompt for access; grant it in System Preferences > Privacy & Security > Accessibility for Terminal / iTerm / Claude Code
- **`keystroke` is slow for long text** — always use clipboard paste (`Cmd+V`) for messages over \~20 characters
- **`keystroke` can mangle non-ASCII** — use clipboard paste for Chinese, emoji, or special characters
- **`key code 36` is Enter** — this is the hardware key code, works regardless of keyboard layout
- **`entire contents` is extremely slow** — avoid for complex UIs; use screenshots instead
- **App name varies by locale** — `微信` vs `WeChat`, `企业微信` vs `WeCom`; handle both
- **WeChat Enter sends immediately** — use `Shift+Enter` for newlines within a message
- **Rate limiting** — don't send messages too fast; platforms may throttle or flag automated input
- **Lark / 飞书 app name varies** — `Lark` (international) vs `飞书` (China mainland); scripts auto-detect
- **QQ uses `Cmd+F` for search** — not `Cmd+K` like Discord/Slack/Lark
- **Bot response times vary** — AI-powered bots may take 10-60s; use generous sleep values
@@ -0,0 +1,62 @@
# QQ Bot Testing
**App name:** `QQ` | **Process name:** `QQ`
See [osascript-common.md](./osascript-common.md) for shared patterns.
## Activate & Navigate
```bash
osascript -e 'tell application "QQ" to activate'
sleep 1
# Search for contact/group (Cmd+F)
osascript -e '
tell application "System Events"
keystroke "f" using command down
delay 0.8
end tell
'
osascript -e '
set the clipboard to "bot-testing"
tell application "System Events"
keystroke "v" using command down
delay 1.5
key code 36 -- Enter
end tell
'
sleep 2
```
## Send Message to Bot
```bash
osascript -e '
set the clipboard to "Hello bot!"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter
end tell
'
```
## Verify Response
```bash
sleep 10
screencapture /tmp/qq-bot-response.png
```
## QQ-Specific Notes
- Enter sends message by default; Shift+Enter for newlines
- Uses `Cmd+F` for search (not `Cmd+K` like Discord/Slack/Lark)
- Always use clipboard paste for CJK characters
## Script
```bash
./.agents/skills/local-testing/scripts/test-qq-bot.sh "bot-testing" "Hello bot" 15
./.agents/skills/local-testing/scripts/test-qq-bot.sh "MyBot" "/help" 10
```
@@ -0,0 +1,142 @@
# record-app-screen.sh
General-purpose screen recording tool for the Electron app. Captures CDP screenshots as video frames and gallery snapshots, then assembles into an MP4 on stop.
## Why CDP Screenshots Instead of ffmpeg Screen Capture
- **Works on any screen** — CDP screenshots capture the browser viewport directly, so external monitors, Retina scaling, and window positioning are all handled automatically
- **No signal handling issues** — ffmpeg-static (npm) produces corrupt MP4 files when killed (missing moov atom). CDP screenshots avoid this entirely
- **Consistent output** — Screenshots are resolution-independent and don't require crop coordinate calculations
## Commands
```bash
# Start recording (Electron must be running with CDP)
.agents/skills/local-testing/scripts/record-app-screen.sh start [output_name]
# Stop recording and assemble video
.agents/skills/local-testing/scripts/record-app-screen.sh stop
# Check if recording is active
.agents/skills/local-testing/scripts/record-app-screen.sh status
```
### Arguments
| Argument | Default | Description |
| ------------- | --------------------------- | -------------------------- |
| `output_name` | `recording-YYYYMMDD-HHMMSS` | Base name for output files |
### Environment Variables
| Variable | Default | Description |
| ---------------------- | ------- | -------------------------------------- |
| `CDP_PORT` | `9222` | Chrome DevTools Protocol port |
| `SCREENSHOT_INTERVAL` | `3` | Seconds between gallery screenshots |
| `VIDEO_FRAME_INTERVAL` | `0.5` | Seconds between video frames (\~2 fps) |
## Output Structure
```
.records/
<name>.mp4 # Video assembled from frames (~2 fps)
<name>/ # Gallery screenshots (every 3s)
0000.png
0001.png
0002.png
...
```
The `.records/` directory is at the project root and is gitignored.
## How It Works
### Start
1. Creates two background loops:
- **Video frames** — `agent-browser screenshot` every `VIDEO_FRAME_INTERVAL` seconds into a temp directory (`/tmp/record-frames-XXXXXX/`)
- **Gallery screenshots** — `agent-browser screenshot` every `SCREENSHOT_INTERVAL` seconds into `.records/<name>/`
2. Saves PIDs and paths to `/tmp/record-app-screen.pids` and `/tmp/record-app-screen.state`
### Stop
1. Kills both background loops
2. Assembles video frames into MP4 using ffmpeg:
```
ffmpeg -framerate 2 -i frame_%06d.png -c:v libx264 -crf 23 -pix_fmt yuv420p <output>.mp4
```
3. Cleans up temp frame directory
4. Reports file sizes and paths
## Usage Examples
### Basic Test Recording
```bash
# Start Electron
.agents/skills/local-testing/scripts/electron-dev.sh start
# Start recording
.agents/skills/local-testing/scripts/record-app-screen.sh start my-test
# Run automation
agent-browser --cdp 9222 click @e61
agent-browser --cdp 9222 type @e42 "hello"
agent-browser --cdp 9222 press Enter
sleep 10
# Stop and get results
.agents/skills/local-testing/scripts/record-app-screen.sh stop
# → .records/my-test.mp4 + .records/my-test/*.png
```
### Gateway Streaming Demo
```bash
.agents/skills/local-testing/scripts/electron-dev.sh start
# Inject gateway URL
agent-browser --cdp 9222 eval --stdin << 'EOF'
(function() {
var store = window.global_serverConfigStore;
store.setState({ serverConfig: { ...store.getState().serverConfig,
agentGatewayUrl: 'https://agent-gateway.lobehub.com' } });
return 'ready';
})()
EOF
# Record
.agents/skills/local-testing/scripts/record-app-screen.sh start gateway-demo
# Navigate to agent, send message, wait for completion...
# (automation commands here)
.agents/skills/local-testing/scripts/record-app-screen.sh stop
open .records/gateway-demo.mp4
```
### Check Active Recording
```bash
.agents/skills/local-testing/scripts/record-app-screen.sh status
# [record] Active recording
# Frames: 42 captured (running: yes)
# Screenshots: 14 captured (running: yes)
# Output: .records/my-test.mp4
```
## Prerequisites
- **ffmpeg** — For video assembly. Install via `bun add -g ffmpeg-static` or `brew install ffmpeg`
- **agent-browser** — For CDP screenshots. Install via `npm i -g agent-browser`
- **Electron app running** — With CDP enabled (use `electron-dev.sh start`)
## Troubleshooting
| Problem | Solution |
| ----------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| "No active recording found" on stop | PID file was cleaned up. Check if background processes are still running with `ps aux \| grep agent-browser` |
| "A recording is already active" | Run `stop` first, or manually clean: `rm /tmp/record-app-screen.pids /tmp/record-app-screen.state` |
| Video is 0 bytes | No frames were captured. Ensure Electron is running and CDP port is correct |
| Screenshots are blank/white | SPA may not have loaded yet. Wait for `electron-dev.sh` to report "Renderer ready" |
| ffmpeg assembly fails | Check `/tmp/ffmpeg-assemble.log`. Ensure ffmpeg is installed and frames exist |
@@ -0,0 +1,73 @@
# Slack Bot Testing
**App name:** `Slack` | **Process name:** `Slack`
See [osascript-common.md](./osascript-common.md) for shared patterns.
## Activate & Navigate
```bash
# Activate Slack
osascript -e 'tell application "Slack" to activate'
sleep 1
# Quick Switcher (Cmd+K)
osascript -e 'tell application "System Events" to keystroke "k" using command down'
sleep 0.5
osascript -e 'tell application "System Events" to keystroke "bot-testing"'
sleep 1
osascript -e 'tell application "System Events" to key code 36' # Enter
sleep 2
```
## Send Message to Bot
```bash
# Direct message input (focused after channel nav)
osascript -e 'tell application "System Events" to keystroke "@mybot hello"'
sleep 0.3
osascript -e 'tell application "System Events" to key code 36'
```
## Send Long Message
```bash
osascript -e '
tell application "Slack" to activate
delay 0.5
set the clipboard to "A long test message for the bot..."
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36
end tell
'
```
## Slash Command Test
```bash
osascript -e '
tell application "Slack" to activate
delay 0.5
tell application "System Events"
keystroke "/ask What is the meaning of life?"
delay 0.5
key code 36
end tell
'
```
## Verify Response
```bash
sleep 10
screencapture /tmp/slack-bot-response.png
```
## Script
```bash
./.agents/skills/local-testing/scripts/test-slack-bot.sh "bot-testing" "@mybot hello"
./.agents/skills/local-testing/scripts/test-slack-bot.sh "bot-testing" "/ask What is 2+2?" 20
```
@@ -0,0 +1,80 @@
# Telegram Bot Testing
**App name:** `Telegram` | **Process name:** `Telegram`
See [osascript-common.md](./osascript-common.md) for shared patterns.
## Activate & Navigate
```bash
# Activate Telegram
osascript -e 'tell application "Telegram" to activate'
sleep 1
# Search for a bot (Cmd+F or click search)
osascript -e '
tell application "System Events"
keystroke "f" using command down
delay 0.5
keystroke "MyTestBot"
delay 1
key code 36 -- Enter to select
end tell
'
sleep 2
```
## Send Message to Bot
```bash
# After navigating to bot chat, input is focused
osascript -e '
tell application "System Events"
keystroke "/start"
delay 0.3
key code 36
end tell
'
```
## Send Long Message
```bash
osascript -e '
tell application "Telegram" to activate
delay 0.5
set the clipboard to "Tell me about quantum computing in detail"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36
end tell
'
```
## Verify Response
```bash
sleep 10
screencapture /tmp/telegram-bot-response.png
```
## Telegram Bot API (programmatic alternative)
For sending messages directly to the bot's chat without UI:
```bash
# Send message as the bot (for testing webhooks/responses)
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
-d "chat_id=$CHAT_ID&text=test message"
# Get recent updates
curl -s "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/getUpdates?limit=5" | jq .
```
## Script
```bash
./.agents/skills/local-testing/scripts/test-telegram-bot.sh "MyTestBot" "/start"
./.agents/skills/local-testing/scripts/test-telegram-bot.sh "GPTBot" "Hello" 60
```
@@ -0,0 +1,81 @@
# WeChat / 微信 Bot Testing
**App name:** `微信` or `WeChat` | **Process name:** `WeChat`
See [osascript-common.md](./osascript-common.md) for shared patterns.
## Activate & Navigate
```bash
# Activate WeChat
osascript -e 'tell application "微信" to activate'
sleep 1
# Search for a contact/bot (Cmd+F)
osascript -e '
tell application "System Events"
keystroke "f" using command down
delay 0.5
keystroke "TestBot"
delay 1
key code 36 -- Enter to select
end tell
'
sleep 2
```
## Send Message
```bash
# After navigating to a chat, the input is focused
osascript -e '
tell application "System Events"
keystroke "Hello bot!"
delay 0.3
key code 36
end tell
'
```
## Send Long Message (clipboard)
```bash
osascript -e '
tell application "微信" to activate
delay 0.5
set the clipboard to "Please help me with this task..."
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36
end tell
'
```
## Verify Response
```bash
sleep 10
screencapture /tmp/wechat-bot-response.png
```
## WeChat-Specific Notes
- WeChat macOS app name can be `微信` or `WeChat` depending on system language. Try both:
```bash
osascript -e 'tell application "微信" to activate' 2> /dev/null \
|| osascript -e 'tell application "WeChat" to activate'
```
- WeChat uses **Enter** to send (not Cmd+Enter by default, but configurable)
- For multi-line messages without sending, use **Shift+Enter**:
```bash
osascript -e 'tell application "System Events" to key code 36 using shift down'
```
- Always use clipboard paste for CJK characters — `keystroke` mangles non-ASCII
## Script
```bash
./.agents/skills/local-testing/scripts/test-wechat-bot.sh "文件传输助手" "test message" 5
./.agents/skills/local-testing/scripts/test-wechat-bot.sh "MyBot" "Tell me a joke" 30
```
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
#
# capture-app-window.sh — Capture a screenshot of a specific app window
#
# Uses CGWindowList via Swift to find the window by process name, then
# screencapture -l <windowID> to capture only that window.
# Falls back to full-screen capture if the window is not found.
#
# Usage:
# ./capture-app-window.sh <process_name> <output_path>
#
# Arguments:
# process_name — The process/owner name as shown in Activity Monitor
# (e.g., "Discord", "Slack", "Telegram", "WeChat", "QQ", "Lark")
# output_path — Path to save the screenshot (e.g., /tmp/screenshot.png)
#
# Examples:
# ./capture-app-window.sh "Discord" /tmp/discord.png
# ./capture-app-window.sh "Slack" /tmp/slack.png
# ./capture-app-window.sh "微信" /tmp/wechat.png
#
set -euo pipefail
PROCESS="${1:?Usage: capture-app-window.sh <process_name> <output_path>}"
OUTPUT="${2:?Usage: capture-app-window.sh <process_name> <output_path>}"
# Find the CGWindowID for the target process using Swift + CGWindowList
# Pass process name via environment variable (swift -e doesn't support -- args)
WINDOW_ID=$(TARGET_PROCESS="$PROCESS" swift -e '
import Cocoa
import Foundation
let target = ProcessInfo.processInfo.environment["TARGET_PROCESS"] ?? ""
let windowList = CGWindowListCopyWindowInfo([.optionAll], kCGNullWindowID) as! [[String: Any]]
for w in windowList {
let owner = w["kCGWindowOwnerName"] as? String ?? ""
let layer = w["kCGWindowLayer"] as? Int ?? -1
let bounds = w["kCGWindowBounds"] as? [String: Any] ?? [:]
let ww = bounds["Width"] as? Double ?? 0
let wh = bounds["Height"] as? Double ?? 0
let wid = w["kCGWindowNumber"] as? Int ?? 0
// Match process name, normal window layer (0), and reasonable size
if owner == target && layer == 0 && ww > 200 && wh > 200 {
print(wid)
break
}
}
' 2>/dev/null || true)
if [ -n "$WINDOW_ID" ]; then
screencapture -l "$WINDOW_ID" -x "$OUTPUT"
else
echo "[capture] Warning: Could not find window for '$PROCESS', falling back to full screen"
screencapture -x "$OUTPUT"
fi
+244
View File
@@ -0,0 +1,244 @@
#!/usr/bin/env bash
#
# electron-dev.sh — Manage Electron dev environment for testing
#
# Usage:
# ./electron-dev.sh start # Kill existing, start fresh, wait until ready
# ./electron-dev.sh stop # Kill all Electron-related processes
# ./electron-dev.sh status # Check if Electron is running and CDP is reachable
# ./electron-dev.sh restart # Stop then start
#
# Environment variables:
# CDP_PORT — Chrome DevTools Protocol port (default: 9222)
# ELECTRON_LOG — Log file path (default: /tmp/electron-dev.log)
# ELECTRON_WAIT_S — Max seconds to wait for Electron process (default: 60)
# RENDERER_WAIT_S — Max seconds to wait for renderer/SPA (default: 60)
#
set -euo pipefail
CDP_PORT="${CDP_PORT:-9222}"
ELECTRON_LOG="${ELECTRON_LOG:-/tmp/electron-dev.log}"
ELECTRON_WAIT_S="${ELECTRON_WAIT_S:-60}"
RENDERER_WAIT_S="${RENDERER_WAIT_S:-60}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
PIDFILE="/tmp/electron-dev-cdp-${CDP_PORT}.pid"
# ── Helpers ──────────────────────────────────────────────────────────
# Get the Electron binary path used by this project
electron_bin_pattern() {
echo "${PROJECT_ROOT}/apps/desktop/node_modules/.pnpm/electron@*/node_modules/electron/dist/Electron.app"
}
# Find all PIDs related to the project's Electron dev session
find_electron_pids() {
local pids=""
# 1. Main Electron process (launched with --remote-debugging-port)
local main_pids
main_pids=$(pgrep -f "Electron\.app.*--remote-debugging-port=${CDP_PORT}" 2>/dev/null || true)
[ -n "$main_pids" ] && pids="$pids $main_pids"
# 2. Electron Helper processes (gpu, renderer, utility) spawned from the project's electron binary
local helper_pids
helper_pids=$(pgrep -f "${PROJECT_ROOT}/apps/desktop/node_modules/.*Electron Helper" 2>/dev/null || true)
[ -n "$helper_pids" ] && pids="$pids $helper_pids"
# 3. electron-vite dev server
local vite_pids
vite_pids=$(pgrep -f "electron-vite.*dev" 2>/dev/null || true)
[ -n "$vite_pids" ] && pids="$pids $vite_pids"
# 4. PID from pidfile (fallback)
if [ -f "$PIDFILE" ]; then
local saved_pid
saved_pid=$(cat "$PIDFILE")
if kill -0 "$saved_pid" 2>/dev/null; then
pids="$pids $saved_pid"
fi
fi
# Deduplicate
echo "$pids" | tr ' ' '\n' | sort -u | grep -v '^$' | tr '\n' ' ' || true
}
do_stop() {
echo "[electron-dev] Stopping Electron dev environment..."
local pids
pids=$(find_electron_pids)
if [ -z "$pids" ]; then
echo "[electron-dev] No Electron processes found."
else
echo "[electron-dev] Killing PIDs: $pids"
for pid in $pids; do
kill "$pid" 2>/dev/null || true
done
# Wait up to 5s for graceful exit, then force-kill survivors
local waited=0
while [ $waited -lt 5 ]; do
local alive=""
for pid in $pids; do
kill -0 "$pid" 2>/dev/null && alive="$alive $pid"
done
[ -z "$alive" ] && break
sleep 1
waited=$((waited + 1))
done
# Force-kill any remaining
for pid in $pids; do
if kill -0 "$pid" 2>/dev/null; then
echo "[electron-dev] Force-killing PID $pid"
kill -9 "$pid" 2>/dev/null || true
fi
done
fi
# Also close any agent-browser sessions connected to this port
agent-browser --cdp "$CDP_PORT" close --all 2>/dev/null || true
rm -f "$PIDFILE"
echo "[electron-dev] Stopped."
}
do_status() {
local pids
pids=$(find_electron_pids)
if [ -z "$pids" ]; then
echo "[electron-dev] Electron is NOT running."
return 1
fi
echo "[electron-dev] Electron is running (PIDs: $pids)"
# Check CDP connectivity
if agent-browser --cdp "$CDP_PORT" get url >/dev/null 2>&1; then
local url
url=$(agent-browser --cdp "$CDP_PORT" get url 2>&1 | tail -1)
echo "[electron-dev] CDP port ${CDP_PORT} is reachable. URL: $url"
return 0
else
echo "[electron-dev] CDP port ${CDP_PORT} is NOT reachable (Electron may still be loading)."
return 2
fi
}
wait_for_electron() {
echo "[electron-dev] Waiting for Electron process (up to ${ELECTRON_WAIT_S}s)..."
local elapsed=0
local interval=3
while [ $elapsed -lt "$ELECTRON_WAIT_S" ]; do
if strings "$ELECTRON_LOG" 2>/dev/null | grep -q "starting electron"; then
echo "[electron-dev] Electron process started."
return 0
fi
sleep "$interval"
elapsed=$((elapsed + interval))
echo "[electron-dev] Still waiting... (${elapsed}/${ELECTRON_WAIT_S}s)"
done
echo "[electron-dev] ERROR: Electron did not start within ${ELECTRON_WAIT_S}s"
echo "[electron-dev] Last 20 lines of log:"
tail -20 "$ELECTRON_LOG" 2>/dev/null || true
return 1
}
wait_for_renderer() {
echo "[electron-dev] Waiting for renderer/SPA to load (up to ${RENDERER_WAIT_S}s)..."
# Initial delay — renderer needs time to bootstrap
sleep 10
local elapsed=10
local interval=5
while [ $elapsed -lt "$RENDERER_WAIT_S" ]; do
if agent-browser --cdp "$CDP_PORT" wait 2000 >/dev/null 2>&1; then
# Check if interactive elements are present (SPA loaded)
local snap
snap=$(agent-browser --cdp "$CDP_PORT" snapshot -i 2>&1 || true)
if echo "$snap" | grep -qE 'link |button '; then
echo "[electron-dev] Renderer ready (interactive elements found)."
return 0
fi
fi
sleep "$interval"
elapsed=$((elapsed + interval))
echo "[electron-dev] SPA still loading... (${elapsed}/${RENDERER_WAIT_S}s)"
done
echo "[electron-dev] WARNING: Timed out waiting for renderer, proceeding anyway."
return 0
}
do_start() {
# If already running and healthy, skip
local status_ok=0
do_status >/dev/null 2>&1 || status_ok=$?
if [ "$status_ok" -eq 0 ]; then
echo "[electron-dev] Electron is already running and CDP is reachable. Skipping start."
echo "[electron-dev] Use 'restart' to force a fresh session, or 'stop' to tear down."
return 0
fi
# Clean up any stale processes
do_stop
# Start fresh
echo "[electron-dev] Starting Electron dev server..."
echo "[electron-dev] Project: $PROJECT_ROOT"
echo "[electron-dev] CDP port: $CDP_PORT"
echo "[electron-dev] Log: $ELECTRON_LOG"
: > "$ELECTRON_LOG" # Truncate log
(
cd "$PROJECT_ROOT/apps/desktop" && \
ELECTRON_ENABLE_LOGGING=1 npx electron-vite dev -- --remote-debugging-port="$CDP_PORT" \
>> "$ELECTRON_LOG" 2>&1
) &
local bg_pid=$!
echo "$bg_pid" > "$PIDFILE"
echo "[electron-dev] Background PID: $bg_pid"
# Wait for Electron process to start
if ! wait_for_electron; then
echo "[electron-dev] Failed to start. Cleaning up..."
do_stop
return 1
fi
# Wait for renderer to be interactive
if ! wait_for_renderer; then
echo "[electron-dev] Renderer not ready, but Electron is running. You may need to wait more."
fi
echo "[electron-dev] Ready! Use: agent-browser --cdp $CDP_PORT snapshot -i"
}
do_restart() {
do_stop
sleep 2
do_start
}
# ── Main ─────────────────────────────────────────────────────────────
case "${1:-help}" in
start) do_start ;;
stop) do_stop ;;
status) do_status ;;
restart) do_restart ;;
*)
echo "Usage: $0 {start|stop|status|restart}"
echo ""
echo " start — Start Electron dev with CDP (idempotent, skips if already running)"
echo " stop — Kill all Electron dev processes (main + helpers + vite)"
echo " status — Check if Electron is running and CDP is reachable"
echo " restart — Stop then start"
exit 1
;;
esac
+189
View File
@@ -0,0 +1,189 @@
#!/usr/bin/env bash
#
# record-app-screen.sh — Record the Electron app window (video + screenshots)
#
# Captures screenshots via agent-browser (CDP), then assembles into video on stop.
# Works on any screen (including external monitors) since it uses CDP, not screen capture.
#
# Usage:
# ./record-app-screen.sh start [output_name] # Begin recording
# ./record-app-screen.sh stop # Stop and save
# ./record-app-screen.sh status # Check recording state
#
# Outputs to .records/ directory:
# .records/<name>.mp4 — Video assembled from screenshots (~2 fps)
# .records/<name>/ — Screenshots every SCREENSHOT_INTERVAL seconds
#
# Prerequisites:
# - ffmpeg installed (bun add -g ffmpeg-static, or brew install ffmpeg)
# - agent-browser CLI installed
# - Electron app already running with CDP enabled
#
# Environment variables:
# CDP_PORT — Chrome DevTools Protocol port (default: 9222)
# SCREENSHOT_INTERVAL — Seconds between gallery screenshots (default: 3)
# VIDEO_FRAME_INTERVAL — Seconds between video frames (default: 0.5)
#
# Examples:
# ./electron-dev.sh start
# ./record-app-screen.sh start gateway-demo
# # ... run automation via agent-browser ...
# ./record-app-screen.sh stop
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
RECORDS_DIR="$PROJECT_DIR/.records"
PID_FILE="/tmp/record-app-screen.pids"
STATE_FILE="/tmp/record-app-screen.state"
CDP_PORT="${CDP_PORT:-9222}"
SCREENSHOT_INTERVAL="${SCREENSHOT_INTERVAL:-3}"
VIDEO_FRAME_INTERVAL="${VIDEO_FRAME_INTERVAL:-0.5}"
AB="agent-browser --cdp $CDP_PORT"
# ─── Commands ───
cmd_start() {
local output_name="${1:-recording-$(date +%Y%m%d-%H%M%S)}"
local output_video="$RECORDS_DIR/${output_name}.mp4"
local screenshot_dir="$RECORDS_DIR/${output_name}"
local frames_dir
frames_dir=$(mktemp -d /tmp/record-frames-XXXXXX)
if [ -f "$PID_FILE" ]; then
echo "[record] A recording is already active. Run '$0 stop' first."
exit 1
fi
mkdir -p "$RECORDS_DIR" "$screenshot_dir"
# Video frames loop (~2 fps via agent-browser CDP screenshots)
(
local idx=0
while true; do
local fname
fname=$(printf "%s/frame_%06d.png" "$frames_dir" "$idx")
$AB screenshot "$fname" 2>/dev/null || true
idx=$((idx + 1))
sleep "$VIDEO_FRAME_INTERVAL"
done
) &
local frames_pid=$!
# Gallery screenshots loop (every N seconds for human review)
(
local idx=0
while true; do
local fname
fname=$(printf "%s/%04d.png" "$screenshot_dir" "$idx")
$AB screenshot "$fname" 2>/dev/null || true
idx=$((idx + 1))
sleep "$SCREENSHOT_INTERVAL"
done
) &
local screenshot_pid=$!
# Save state
echo "$frames_pid $screenshot_pid" > "$PID_FILE"
echo "$output_video $frames_dir $screenshot_dir" > "$STATE_FILE"
echo "[record] Started!"
echo " Video frames: every ${VIDEO_FRAME_INTERVAL}s (PID $frames_pid)"
echo " Screenshots: every ${SCREENSHOT_INTERVAL}s → $screenshot_dir/"
echo " Stop with: $0 stop"
}
cmd_stop() {
if [ ! -f "$PID_FILE" ] || [ ! -f "$STATE_FILE" ]; then
echo "[record] No active recording found."
return 0
fi
local frames_pid screenshot_pid
read -r frames_pid screenshot_pid < "$PID_FILE"
local output_video frames_dir screenshot_dir
read -r output_video frames_dir screenshot_dir < "$STATE_FILE"
# Stop both capture loops
kill "$frames_pid" 2>/dev/null || true
kill "$screenshot_pid" 2>/dev/null || true
wait "$frames_pid" 2>/dev/null || true
wait "$screenshot_pid" 2>/dev/null || true
# Assemble frames into video
local frame_count
frame_count=$(ls -1 "$frames_dir"/frame_*.png 2>/dev/null | wc -l | tr -d ' ')
if [ "$frame_count" -gt 0 ]; then
echo "[record] Assembling $frame_count frames into video..."
ffmpeg -y -framerate 2 -i "$frames_dir/frame_%06d.png" \
-c:v libx264 -crf 23 -pix_fmt yuv420p -an \
"$output_video" > /tmp/ffmpeg-assemble.log 2>&1
if [ ! -s "$output_video" ]; then
echo " [warn] Video assembly failed. Check /tmp/ffmpeg-assemble.log"
echo " Frames preserved in: $frames_dir/"
fi
else
echo " [warn] No frames captured."
fi
rm -rf "$frames_dir" 2>/dev/null
rm -f "$PID_FILE" "$STATE_FILE"
local video_size screenshot_count
video_size=$(ls -lh "$output_video" 2>/dev/null | awk '{print $5}' || echo "?")
screenshot_count=$(ls -1 "$screenshot_dir"/*.png 2>/dev/null | wc -l | tr -d ' ' || echo "0")
echo "[record] Stopped!"
echo " Video: $output_video ($video_size)"
echo " Screenshots: ${screenshot_count} files in $screenshot_dir/"
echo " Play: open $output_video"
}
cmd_status() {
if [ ! -f "$PID_FILE" ]; then
echo "[record] No active recording."
return 0
fi
local frames_pid screenshot_pid
read -r frames_pid screenshot_pid < "$PID_FILE"
local frames_ok="no" screenshot_ok="no"
kill -0 "$frames_pid" 2>/dev/null && frames_ok="yes"
kill -0 "$screenshot_pid" 2>/dev/null && screenshot_ok="yes"
if [ -f "$STATE_FILE" ]; then
local output_video frames_dir screenshot_dir
read -r output_video frames_dir screenshot_dir < "$STATE_FILE"
local frame_count ss_count
frame_count=$(ls -1 "$frames_dir"/frame_*.png 2>/dev/null | wc -l | tr -d ' ' || echo "0")
ss_count=$(ls -1 "$screenshot_dir"/*.png 2>/dev/null | wc -l | tr -d ' ' || echo "0")
echo "[record] Active recording"
echo " Frames: $frame_count captured (running: $frames_ok)"
echo " Screenshots: $ss_count captured (running: $screenshot_ok)"
echo " Output: $output_video"
fi
}
# ─── Main ───
case "${1:-}" in
start) shift; cmd_start "$@" ;;
stop) cmd_stop ;;
status) cmd_status ;;
*)
echo "Usage: $0 {start [name] | stop | status}"
echo ""
echo " start [name] Start recording (default: recording-YYYYMMDD-HHMMSS)"
echo " stop Stop recording and save outputs"
echo " status Check if recording is active"
exit 1
;;
esac
@@ -0,0 +1,353 @@
#!/usr/bin/env bash
#
# record-electron-demo.sh — Record an automated demo of the Electron app
#
# Usage:
# ./scripts/record-electron-demo.sh [script.sh] [output.mp4]
#
# script.sh — A shell script containing agent-browser commands to automate.
# It receives the CDP port as $1. Defaults to a built-in queue-edit demo.
# output.mp4 — Output file path. Defaults to /tmp/electron-demo.mp4
#
# Prerequisites:
# - agent-browser CLI installed globally
# - ffmpeg installed (brew install ffmpeg)
# - Electron app NOT already running (script manages lifecycle)
#
# Examples:
# # Run built-in demo
# ./scripts/record-electron-demo.sh
#
# # Run custom automation script
# ./scripts/record-electron-demo.sh ./my-demo.sh /tmp/my-demo.mp4
#
set -euo pipefail
CDP_PORT=9222
DEMO_SCRIPT="${1:-}"
OUTPUT="${2:-/tmp/electron-demo.mp4}"
ELECTRON_LOG="/tmp/electron-dev.log"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)"
RECORD_PID=""
# ── Helpers ──────────────────────────────────────────────────────────
cleanup() {
echo "[cleanup] Stopping all processes..."
[ -n "$RECORD_PID" ] && kill -INT "$RECORD_PID" 2>/dev/null && sleep 2
pkill -f "electron-vite" 2>/dev/null || true
pkill -f "Electron" 2>/dev/null || true
pkill -f "agent-browser" 2>/dev/null || true
echo "[cleanup] Done."
}
trap cleanup EXIT
wait_for_electron() {
echo "[wait] Waiting for Electron to start..."
for i in $(seq 1 24); do
sleep 5
if strings "$ELECTRON_LOG" 2>/dev/null | grep -q "starting electron"; then
echo "[wait] Electron process ready."
return 0
fi
echo "[wait] Still waiting... (${i}/24)"
done
echo "[error] Electron failed to start within 120s"
exit 1
}
wait_for_renderer() {
echo "[wait] Waiting for renderer to load..."
sleep 15
agent-browser --cdp "$CDP_PORT" wait 3000
# Poll until interactive elements appear (SPA may take extra time)
for i in $(seq 1 12); do
local snap
snap=$(agent-browser --cdp "$CDP_PORT" snapshot -i 2>&1)
if echo "$snap" | grep -q 'link "'; then
echo "[wait] Renderer ready (interactive elements found)."
return 0
fi
echo "[wait] SPA still loading... (${i}/12)"
sleep 5
done
echo "[warn] Timed out waiting for interactive elements, proceeding anyway."
}
get_window_and_screen_info() {
# Returns: window_x window_y window_w window_h screen_index
# Uses Swift to find the Electron window bounds and which screen it's on
swift -e '
import Cocoa
let windowList = CGWindowListCopyWindowInfo([.optionAll], kCGNullWindowID) as! [[String: Any]]
for w in windowList {
let owner = w["kCGWindowOwnerName"] as? String ?? ""
let name = w["kCGWindowName"] as? String ?? ""
let layer = w["kCGWindowLayer"] as? Int ?? -1
let bounds = w["kCGWindowBounds"] as? [String: Any] ?? [:]
let wx = bounds["X"] as? Double ?? 0
let wy = bounds["Y"] as? Double ?? 0
let ww = bounds["Width"] as? Double ?? 0
let wh = bounds["Height"] as? Double ?? 0
if (owner == "Electron" || owner == "LobeHub") && layer == 0 && name == "LobeHub" && ww > 200 && wh > 200 {
// Find which screen this window is on
let screens = NSScreen.screens
var screenIdx = 0
let windowCenter = NSPoint(x: wx + ww / 2, y: wy + wh / 2)
for (i, screen) in screens.enumerated() {
let frame = screen.frame
// Convert CG coords (top-left origin) to NSScreen coords (bottom-left origin)
let mainHeight = screens[0].frame.height
let screenTop = mainHeight - frame.origin.y - frame.height
let screenBottom = screenTop + frame.height
let screenLeft = frame.origin.x
let screenRight = screenLeft + frame.width
if windowCenter.x >= screenLeft && windowCenter.x <= screenRight &&
windowCenter.y >= screenTop && windowCenter.y <= screenBottom {
screenIdx = i
break
}
}
// Compute window position relative to the screen it is on
let screen = screens[screenIdx]
let mainHeight = screens[0].frame.height
let screenTop = mainHeight - screen.frame.origin.y - screen.frame.height
let relX = wx - screen.frame.origin.x
let relY = wy - screenTop
let scale = Int(screen.backingScaleFactor)
print("\(Int(relX)) \(Int(relY)) \(Int(ww)) \(Int(wh)) \(screenIdx) \(scale)")
break
}
}
'
}
start_recording() {
local rel_x=$1 rel_y=$2 w=$3 h=$4 screen_idx=$5 scale=$6
# ffmpeg avfoundation device index for screens
# List devices and find the one matching our screen index
local device_idx
device_idx=$(ffmpeg -f avfoundation -list_devices true -i "" 2>&1 \
| grep "Capture screen ${screen_idx}" \
| grep -oE '\[[0-9]+\]' | tr -d '[]' || true)
if [ -z "$device_idx" ]; then
echo "[warn] Could not find capture device for screen $screen_idx, trying default (3)"
device_idx=3
fi
# Scale coordinates to native resolution
local cx=$((rel_x * scale))
local cy=$((rel_y * scale))
local cw=$((w * scale))
local ch=$((h * scale))
echo "[record] Window: ${rel_x},${rel_y} ${w}x${h} on screen ${screen_idx} (scale=${scale})"
echo "[record] Crop: ${cx},${cy} ${cw}x${ch}, device: ${device_idx}"
echo "[record] Output: $OUTPUT"
ffmpeg -y \
-f avfoundation -framerate 30 -capture_cursor 1 -i "${device_idx}:" \
-vf "crop=${cw}:${ch}:${cx}:${cy},scale=${w}:${h}" \
-c:v libx264 -crf 23 -preset fast -an \
"$OUTPUT" \
> /tmp/ffmpeg-record.log 2>&1 &
RECORD_PID=$!
sleep 2
if ! kill -0 "$RECORD_PID" 2>/dev/null; then
echo "[error] ffmpeg failed to start. Log:"
cat /tmp/ffmpeg-record.log
RECORD_PID=""
return 1
fi
echo "[record] Recording started (PID=$RECORD_PID)"
}
stop_recording() {
if [ -n "$RECORD_PID" ]; then
echo "[record] Stopping recording..."
kill -INT "$RECORD_PID" 2>/dev/null || true
wait "$RECORD_PID" 2>/dev/null || true
RECORD_PID=""
echo "[record] Saved to $OUTPUT"
ls -lh "$OUTPUT"
fi
}
# ── Built-in demo: Queue Edit ────────────────────────────────────────
find_input_ref() {
local port=$1
agent-browser --cdp "$port" snapshot -i -C 2>&1 \
| grep "editable" \
| grep -oE 'ref=e[0-9]+' \
| head -1 \
| sed 's/ref=//'
}
builtin_demo() {
local port=$1
echo "[demo] Step 1: Navigate to first available agent"
local snapshot agent_ref
snapshot=$(agent-browser --cdp "$port" snapshot -i 2>&1)
# Try Lobe AI first, then fall back to any agent link in the sidebar
agent_ref=$(echo "$snapshot" | grep -oE 'link "Lobe AI" \[ref=e[0-9]+\]' | grep -oE 'e[0-9]+' || true)
if [ -z "$agent_ref" ]; then
# Pick the first agent-like link (skip nav links)
agent_ref=$(echo "$snapshot" | grep 'link "' | grep -vE '"Home"|"Pages"|"Settings"|"Search"|"Resources"|"Marketplace"' | head -1 | grep -oE 'ref=e[0-9]+' | sed 's/ref=//' || true)
fi
if [ -z "$agent_ref" ]; then
echo "[error] No agent link found in snapshot"
echo "$snapshot" | head -30
return 1
fi
echo "[demo] Clicking agent ref: @$agent_ref"
agent-browser --cdp "$port" click "@$agent_ref"
sleep 3
echo "[demo] Step 2: Send first message (triggers AI generation)"
local input_ref
input_ref=$(find_input_ref "$port")
agent-browser --cdp "$port" click "@$input_ref"
agent-browser --cdp "$port" type "@$input_ref" "Write a 3000 word essay about the complete history of space exploration from Sputnik to the James Webb Space Telescope"
sleep 1
agent-browser --cdp "$port" press Enter
sleep 3
echo "[demo] Step 3: Queue message 1"
input_ref=$(find_input_ref "$port")
agent-browser --cdp "$port" click "@$input_ref"
agent-browser --cdp "$port" type "@$input_ref" "This message should be edited"
sleep 1
agent-browser --cdp "$port" press Enter
sleep 1
echo "[demo] Step 4: Queue message 2"
input_ref=$(find_input_ref "$port")
agent-browser --cdp "$port" click "@$input_ref"
agent-browser --cdp "$port" type "@$input_ref" "Another queued message"
sleep 1
agent-browser --cdp "$port" press Enter
sleep 1
echo "[demo] Step 5: Verify queue has messages"
local queue_count
queue_count=$(agent-browser --cdp "$port" eval --stdin << 'EVALEOF'
(function() {
var chat = window.__LOBE_STORES.chat();
var total = 0;
Object.keys(chat.queuedMessages).forEach(function(k) {
total += chat.queuedMessages[k].length;
});
return String(total);
})()
EVALEOF
)
echo "[demo] Queue count: $queue_count"
if [ "$queue_count" = "0" ] || [ "$queue_count" = '"0"' ]; then
echo "[demo] Queue was already drained. Retrying..."
input_ref=$(find_input_ref "$port")
agent-browser --cdp "$port" click "@$input_ref"
agent-browser --cdp "$port" type "@$input_ref" "Now write another 3000 word essay about artificial intelligence from Turing to transformers covering every major breakthrough"
sleep 1
agent-browser --cdp "$port" press Enter
sleep 2
input_ref=$(find_input_ref "$port")
agent-browser --cdp "$port" click "@$input_ref"
agent-browser --cdp "$port" type "@$input_ref" "This message should be edited"
sleep 1
agent-browser --cdp "$port" press Enter
sleep 1
input_ref=$(find_input_ref "$port")
agent-browser --cdp "$port" click "@$input_ref"
agent-browser --cdp "$port" type "@$input_ref" "Another queued message"
sleep 1
agent-browser --cdp "$port" press Enter
sleep 1
fi
echo "[demo] Step 6: Scroll to show queue tray"
agent-browser --cdp "$port" scroll down 5000
sleep 2
echo "[demo] Step 7: Click edit button on first queued message"
agent-browser --cdp "$port" eval --stdin << 'EVALEOF'
(function() {
var chat = window.__LOBE_STORES.chat();
var keys = Object.keys(chat.queuedMessages);
for (var k = 0; k < keys.length; k++) {
var queue = chat.queuedMessages[keys[k]];
if (queue.length > 0) {
var targetText = queue[0].content;
var walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null);
while (walker.nextNode()) {
var node = walker.currentNode;
if (node.textContent.trim() === targetText) {
var row = node.parentElement.parentElement;
var buttons = row.querySelectorAll('[role="button"]');
if (buttons.length >= 1) {
buttons[0].click();
return 'clicked edit on: ' + targetText;
}
}
}
}
}
return 'edit button not found';
})()
EVALEOF
sleep 3
echo "[demo] Step 8: Show result — content restored to input"
sleep 3
echo "[demo] Complete!"
}
# ── Main ─────────────────────────────────────────────────────────────
echo "=== Electron Demo Recorder ==="
# 1. Kill existing instances
echo "[setup] Cleaning up existing processes..."
pkill -f "Electron" 2>/dev/null || true
pkill -f "electron-vite" 2>/dev/null || true
pkill -f "agent-browser" 2>/dev/null || true
sleep 3
# 2. Start Electron
echo "[setup] Starting Electron..."
cd "$PROJECT_ROOT/apps/desktop"
ELECTRON_ENABLE_LOGGING=1 npx electron-vite dev -- --remote-debugging-port="$CDP_PORT" > "$ELECTRON_LOG" 2>&1 &
wait_for_electron
wait_for_renderer
# 3. Get window position and start recording
WIN_INFO=$(get_window_and_screen_info)
if [ -z "$WIN_INFO" ]; then
echo "[error] Could not find Electron window"
exit 1
fi
read -r WIN_X WIN_Y WIN_W WIN_H SCREEN_IDX SCALE <<< "$WIN_INFO"
start_recording "$WIN_X" "$WIN_Y" "$WIN_W" "$WIN_H" "$SCREEN_IDX" "$SCALE"
# 4. Run demo script
if [ -n "$DEMO_SCRIPT" ] && [ -f "$DEMO_SCRIPT" ]; then
echo "[demo] Running custom script: $DEMO_SCRIPT"
bash "$DEMO_SCRIPT" "$CDP_PORT"
else
echo "[demo] Running built-in queue-edit demo"
builtin_demo "$CDP_PORT"
fi
# 5. Stop recording
stop_recording
echo "=== Done! Output: $OUTPUT ==="
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
#
# test-discord-bot.sh — Send a message to a Discord bot and capture the response
#
# Usage:
# ./scripts/test-discord-bot.sh <channel> <message> [wait_seconds] [screenshot_path]
#
# channel — Channel name to navigate to via Quick Switcher (Cmd+K)
# message — Message to send to the bot
# wait_seconds — Seconds to wait for bot response (default: 10)
# screenshot_path — Output screenshot path (default: /tmp/discord-bot-test.png)
#
# Prerequisites:
# - Discord desktop app installed and logged in
# - Accessibility permission granted (System Preferences > Privacy > Accessibility)
#
# Examples:
# ./scripts/test-discord-bot.sh "bot-testing" "!ping"
# ./scripts/test-discord-bot.sh "bot-testing" "/ask Tell me a joke" 30
# ./scripts/test-discord-bot.sh "general" "Hello bot" 15 /tmp/my-test.png
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CHANNEL="${1:?Usage: test-discord-bot.sh <channel> <message> [wait_seconds] [screenshot_path]}"
MESSAGE="${2:?Usage: test-discord-bot.sh <channel> <message> [wait_seconds] [screenshot_path]}"
WAIT="${3:-10}"
SCREENSHOT="${4:-/tmp/discord-bot-test.png}"
APP="Discord"
echo "[$APP] Activating..."
osascript -e "tell application \"$APP\" to activate"
sleep 1
echo "[$APP] Navigating to channel: $CHANNEL"
osascript -e '
tell application "System Events"
-- Quick Switcher
keystroke "k" using command down
delay 0.8
keystroke "'"$CHANNEL"'"
delay 1.5
key code 36 -- Enter
end tell
'
sleep 2
echo "[$APP] Sending message: $MESSAGE"
osascript -e '
set the clipboard to "'"$MESSAGE"'"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter
end tell
'
echo "[$APP] Waiting ${WAIT}s for bot response..."
sleep "$WAIT"
echo "[$APP] Capturing screenshot..."
"$SCRIPT_DIR/capture-app-window.sh" "$APP" "$SCREENSHOT"
echo "[$APP] Done! Screenshot saved to $SCREENSHOT"
+84
View File
@@ -0,0 +1,84 @@
#!/usr/bin/env bash
#
# test-lark-bot.sh — Send a message to a Lark/Feishu bot and capture the response
#
# Usage:
# ./scripts/test-lark-bot.sh <chat> <message> [wait_seconds] [screenshot_path]
#
# chat — Chat or contact name to search for
# message — Message to send to the bot
# wait_seconds — Seconds to wait for bot response (default: 10)
# screenshot_path — Output screenshot path (default: /tmp/lark-bot-test.png)
#
# Prerequisites:
# - Lark (飞书) desktop app installed and logged in
# - Accessibility permission granted (System Preferences > Privacy > Accessibility)
#
# Notes:
# - The app name may be "Lark" or "飞书" depending on version/locale
# - Uses Cmd+K to open search/quick switcher
# - Enter sends message by default
#
# Examples:
# ./scripts/test-lark-bot.sh "TestBot" "Hello"
# ./scripts/test-lark-bot.sh "bot-testing" "/ask Tell me a joke" 30
# ./scripts/test-lark-bot.sh "MyBot" "Help me summarize this" 60 /tmp/my-test.png
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CHAT="${1:?Usage: test-lark-bot.sh <chat> <message> [wait_seconds] [screenshot_path]}"
MESSAGE="${2:?Usage: test-lark-bot.sh <chat> <message> [wait_seconds] [screenshot_path]}"
WAIT="${3:-10}"
SCREENSHOT="${4:-/tmp/lark-bot-test.png}"
# Detect app name — "Lark" or "飞书"
APP=""
if osascript -e 'tell application "Lark" to name' &>/dev/null; then
APP="Lark"
elif osascript -e 'tell application "飞书" to name' &>/dev/null; then
APP="飞书"
else
echo "[error] Lark/飞书 app not found. Install Lark or 飞书."
exit 1
fi
echo "[$APP] Activating..."
osascript -e "tell application \"$APP\" to activate"
sleep 1
echo "[$APP] Searching for chat: $CHAT"
osascript -e '
tell application "System Events"
-- Quick Switcher / Search (Cmd+K)
keystroke "k" using command down
delay 0.8
end tell
'
# Use clipboard for chat name (supports CJK characters)
osascript -e '
set the clipboard to "'"$CHAT"'"
tell application "System Events"
keystroke "v" using command down
delay 1.5
key code 36 -- Enter to select first result
end tell
'
sleep 2
echo "[$APP] Sending message: $MESSAGE"
osascript -e '
set the clipboard to "'"$MESSAGE"'"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter to send
end tell
'
echo "[$APP] Waiting ${WAIT}s for bot response..."
sleep "$WAIT"
echo "[$APP] Capturing screenshot..."
"$SCRIPT_DIR/capture-app-window.sh" "$APP" "$SCREENSHOT"
echo "[$APP] Done! Screenshot saved to $SCREENSHOT"
+76
View File
@@ -0,0 +1,76 @@
#!/usr/bin/env bash
#
# test-qq-bot.sh — Send a message to a QQ bot and capture the response
#
# Usage:
# ./scripts/test-qq-bot.sh <contact> <message> [wait_seconds] [screenshot_path]
#
# contact — Contact, group, or bot name to search for
# message — Message to send
# wait_seconds — Seconds to wait for bot response (default: 10)
# screenshot_path — Output screenshot path (default: /tmp/qq-bot-test.png)
#
# Prerequisites:
# - QQ desktop app installed and logged in
# - Accessibility permission granted (System Preferences > Privacy > Accessibility)
#
# Notes:
# - The app name is "QQ"
# - Uses Cmd+F to open search
# - Enter sends message by default; Shift+Enter for newlines
# - Uses clipboard paste for CJK character support
#
# Examples:
# ./scripts/test-qq-bot.sh "TestBot" "Hello"
# ./scripts/test-qq-bot.sh "bot-testing" "Hello bot" 30
# ./scripts/test-qq-bot.sh "MyBot" "/help" 15 /tmp/my-test.png
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CONTACT="${1:?Usage: test-qq-bot.sh <contact> <message> [wait_seconds] [screenshot_path]}"
MESSAGE="${2:?Usage: test-qq-bot.sh <contact> <message> [wait_seconds] [screenshot_path]}"
WAIT="${3:-10}"
SCREENSHOT="${4:-/tmp/qq-bot-test.png}"
APP="QQ"
echo "[$APP] Activating..."
osascript -e "tell application \"$APP\" to activate"
sleep 1
echo "[$APP] Searching for contact: $CONTACT"
osascript -e '
tell application "System Events"
-- Search (Cmd+F)
keystroke "f" using command down
delay 0.8
end tell
'
# Use clipboard for contact name (supports CJK characters)
osascript -e '
set the clipboard to "'"$CONTACT"'"
tell application "System Events"
keystroke "v" using command down
delay 1.5
key code 36 -- Enter to select first result
end tell
'
sleep 2
echo "[$APP] Sending message: $MESSAGE"
osascript -e '
set the clipboard to "'"$MESSAGE"'"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter to send
end tell
'
echo "[$APP] Waiting ${WAIT}s for bot response..."
sleep "$WAIT"
echo "[$APP] Capturing screenshot..."
"$SCRIPT_DIR/capture-app-window.sh" "$APP" "$SCREENSHOT"
echo "[$APP] Done! Screenshot saved to $SCREENSHOT"
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
#
# test-slack-bot.sh — Send a message to a Slack bot and capture the response
#
# Usage:
# ./scripts/test-slack-bot.sh <channel> <message> [wait_seconds] [screenshot_path]
#
# channel — Channel name to navigate to via Quick Switcher (Cmd+K)
# message — Message to send (e.g., "@mybot hello" or "/ask question")
# wait_seconds — Seconds to wait for bot response (default: 10)
# screenshot_path — Output screenshot path (default: /tmp/slack-bot-test.png)
#
# Prerequisites:
# - Slack desktop app installed and logged in
# - Accessibility permission granted (System Preferences > Privacy > Accessibility)
#
# Examples:
# ./scripts/test-slack-bot.sh "bot-testing" "@mybot hello"
# ./scripts/test-slack-bot.sh "bot-testing" "/ask What is 2+2?" 20
# ./scripts/test-slack-bot.sh "general" "Hey bot" 15 /tmp/my-test.png
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CHANNEL="${1:?Usage: test-slack-bot.sh <channel> <message> [wait_seconds] [screenshot_path]}"
MESSAGE="${2:?Usage: test-slack-bot.sh <channel> <message> [wait_seconds] [screenshot_path]}"
WAIT="${3:-10}"
SCREENSHOT="${4:-/tmp/slack-bot-test.png}"
APP="Slack"
echo "[$APP] Activating..."
osascript -e "tell application \"$APP\" to activate"
sleep 1
echo "[$APP] Navigating to channel: $CHANNEL"
osascript -e '
tell application "System Events"
-- Quick Switcher
keystroke "k" using command down
delay 0.8
keystroke "'"$CHANNEL"'"
delay 1.5
key code 36 -- Enter
end tell
'
sleep 2
echo "[$APP] Sending message: $MESSAGE"
osascript -e '
set the clipboard to "'"$MESSAGE"'"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter
end tell
'
echo "[$APP] Waiting ${WAIT}s for bot response..."
sleep "$WAIT"
echo "[$APP] Capturing screenshot..."
"$SCRIPT_DIR/capture-app-window.sh" "$APP" "$SCREENSHOT"
echo "[$APP] Done! Screenshot saved to $SCREENSHOT"
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
#
# test-telegram-bot.sh — Send a message to a Telegram bot and capture the response
#
# Usage:
# ./scripts/test-telegram-bot.sh <bot_or_chat> <message> [wait_seconds] [screenshot_path]
#
# bot_or_chat — Bot username or chat name to search for
# message — Message to send to the bot
# wait_seconds — Seconds to wait for bot response (default: 10)
# screenshot_path — Output screenshot path (default: /tmp/telegram-bot-test.png)
#
# Prerequisites:
# - Telegram desktop app installed and logged in
# - Accessibility permission granted (System Preferences > Privacy > Accessibility)
#
# Notes:
# - The app name may be "Telegram" or "Telegram Desktop" depending on installation
# - Uses Cmd+F to search for the bot, then Enter to open the chat
#
# Examples:
# ./scripts/test-telegram-bot.sh "MyTestBot" "/start"
# ./scripts/test-telegram-bot.sh "MyTestBot" "Hello bot" 30
# ./scripts/test-telegram-bot.sh "GPTBot" "/ask What is AI?" 60 /tmp/my-test.png
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BOT="${1:?Usage: test-telegram-bot.sh <bot_or_chat> <message> [wait_seconds] [screenshot_path]}"
MESSAGE="${2:?Usage: test-telegram-bot.sh <bot_or_chat> <message> [wait_seconds] [screenshot_path]}"
WAIT="${3:-10}"
SCREENSHOT="${4:-/tmp/telegram-bot-test.png}"
# Detect app name — "Telegram" or "Telegram Desktop"
APP=""
if osascript -e 'tell application "Telegram" to name' &>/dev/null; then
APP="Telegram"
elif osascript -e 'tell application "Telegram Desktop" to name' &>/dev/null; then
APP="Telegram Desktop"
else
echo "[error] Telegram app not found. Install Telegram or Telegram Desktop."
exit 1
fi
echo "[$APP] Activating..."
osascript -e "tell application \"$APP\" to activate"
sleep 1
echo "[$APP] Searching for: $BOT"
osascript -e '
tell application "System Events"
-- Search (Escape first to clear any existing state)
key code 53 -- Escape
delay 0.3
keystroke "f" using command down
delay 0.8
keystroke "'"$BOT"'"
delay 2
key code 36 -- Enter to select first result
end tell
'
sleep 2
echo "[$APP] Sending message: $MESSAGE"
osascript -e '
set the clipboard to "'"$MESSAGE"'"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter
end tell
'
echo "[$APP] Waiting ${WAIT}s for bot response..."
sleep "$WAIT"
echo "[$APP] Capturing screenshot..."
"$SCRIPT_DIR/capture-app-window.sh" "$APP" "$SCREENSHOT"
echo "[$APP] Done! Screenshot saved to $SCREENSHOT"
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
#
# test-wechat-bot.sh — Send a message to a WeChat bot and capture the response
#
# Usage:
# ./scripts/test-wechat-bot.sh <contact> <message> [wait_seconds] [screenshot_path]
#
# contact — Contact or bot name to search for
# message — Message to send
# wait_seconds — Seconds to wait for bot response (default: 10)
# screenshot_path — Output screenshot path (default: /tmp/wechat-bot-test.png)
#
# Prerequisites:
# - WeChat (微信) desktop app installed and logged in
# - Accessibility permission granted (System Preferences > Privacy > Accessibility)
#
# Notes:
# - The app name may be "微信" or "WeChat" depending on system language
# - WeChat sends on Enter by default; use Shift+Enter for newlines
# - For Chinese text, always uses clipboard paste (keystroke can't handle CJK)
#
# Examples:
# ./scripts/test-wechat-bot.sh "TestBot" "Hello"
# ./scripts/test-wechat-bot.sh "文件传输助手" "test message" 5
# ./scripts/test-wechat-bot.sh "MyBot" "Tell me a joke" 30 /tmp/my-test.png
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CONTACT="${1:?Usage: test-wechat-bot.sh <contact> <message> [wait_seconds] [screenshot_path]}"
MESSAGE="${2:?Usage: test-wechat-bot.sh <contact> <message> [wait_seconds] [screenshot_path]}"
WAIT="${3:-10}"
SCREENSHOT="${4:-/tmp/wechat-bot-test.png}"
# Detect app name — "微信" or "WeChat"
APP=""
if osascript -e 'tell application "微信" to name' &>/dev/null; then
APP="微信"
elif osascript -e 'tell application "WeChat" to name' &>/dev/null; then
APP="WeChat"
else
echo "[error] WeChat app not found. Install 微信 (WeChat)."
exit 1
fi
echo "[$APP] Activating..."
osascript -e "tell application \"$APP\" to activate"
sleep 1
echo "[$APP] Searching for contact: $CONTACT"
osascript -e '
tell application "System Events"
-- Search (Cmd+F)
keystroke "f" using command down
delay 0.8
end tell
'
# Use clipboard for contact name (supports CJK characters)
osascript -e '
set the clipboard to "'"$CONTACT"'"
tell application "System Events"
keystroke "v" using command down
delay 1.5
key code 36 -- Enter to select first result
end tell
'
sleep 2
echo "[$APP] Sending message: $MESSAGE"
# Always use clipboard paste — keystroke can't handle CJK or special characters
osascript -e '
set the clipboard to "'"$MESSAGE"'"
tell application "System Events"
keystroke "v" using command down
delay 0.3
key code 36 -- Enter to send
end tell
'
echo "[$APP] Waiting ${WAIT}s for bot response..."
sleep "$WAIT"
echo "[$APP] Capturing screenshot..."
"$SCRIPT_DIR/capture-app-window.sh" "$APP" "$SCREENSHOT"
echo "[$APP] Done! Screenshot saved to $SCREENSHOT"
+1 -1
View File
@@ -1,7 +1,7 @@
---
name: pr
description: "Create a PR for the current branch. Use when the user asks to create a pull request, submit PR, or says 'pr'."
user_invocable: true
user-invocable: true
---
# Create Pull Request
+13 -7
View File
@@ -6,8 +6,14 @@ description: React component development guide. Use when working with React comp
# React Component Writing Guide
- Use antd-style for complex styles; for simple cases, use inline `style` attribute
- **Prefer `createStaticStyles` with `cssVar.*`** (zero-runtime) — module-level, no hook call required
- Only fall back to `createStyles` + `token` when styles genuinely need runtime computation (dynamic props, JS color fns like `readableColor`/`chroma`)
- See `.cursor/docs/createStaticStyles_migration_guide.md` for full pattern
- Use `Flexbox` and `Center` from `@lobehub/ui` for layouts (see `references/layout-kit.md`)
- Component priority: `src/components` > installed packages > `@lobehub/ui` > antd
- Component priority: `src/components` > `@lobehub/ui/base-ui` > `@lobehub/ui` > custom implementation
- Always prefer `@lobehub/ui/base-ui` primitives (Select, Modal, DropdownMenu, Popover, Switch, ScrollArea…) over antd equivalents
- Fall back to `@lobehub/ui` higher-level components when base-ui has no match
- Only implement a custom component as a last resort — never reach for antd directly
- Use selectors to access zustand store data
## @lobehub/ui Components
@@ -29,9 +35,9 @@ Reference: `node_modules/@lobehub/ui/es/index.mjs` for all available components.
Hybrid routing: Next.js App Router (static pages) + React Router DOM (main SPA).
| Route Type | Use Case | Implementation |
| ------------------ | --------------------------------- | ---------------------------- |
| Next.js App Router | Auth pages (login, signup, oauth) | `src/app/[variants]/(auth)/` |
| Route Type | Use Case | Implementation |
| ------------------ | --------------------------------- | ---------------------------------------------------------------------------- |
| Next.js App Router | Auth pages (login, signup, oauth) | `src/app/[variants]/(auth)/` |
| React Router DOM | Main SPA (chat, settings) | `desktopRouter.config.tsx` + `desktopRouter.config.desktop.tsx` (must match) |
### Key Files
@@ -47,9 +53,9 @@ Hybrid routing: Next.js App Router (static pages) + React Router DOM (main SPA).
Known pairs that must stay in sync:
| Base file (web, dynamic imports) | Desktop file (Electron, sync imports) |
| --- | --- |
| `src/spa/router/desktopRouter.config.tsx` | `src/spa/router/desktopRouter.config.desktop.tsx` |
| Base file (web, dynamic imports) | Desktop file (Electron, sync imports) |
| ----------------------------------------------------- | ------------------------------------------------------------- |
| `src/spa/router/desktopRouter.config.tsx` | `src/spa/router/desktopRouter.config.desktop.tsx` |
| `src/routes/(main)/settings/features/componentMap.ts` | `src/routes/(main)/settings/features/componentMap.desktop.ts` |
**How to check**: After editing any `.ts` / `.tsx` file, run `Glob` for `<filename>.desktop.{ts,tsx}` in the same directory. If a match exists, update it with the equivalent sync-import change.
-114
View File
@@ -1,114 +0,0 @@
---
name: recent-data
description: Guide for using Recent Data (topics, resources, pages). Use when working with recently accessed items, implementing recent lists, or accessing session store recent data. Triggers on recent data usage or implementation tasks.
user-invocable: false
---
# Recent Data Usage Guide
Recent data (recentTopics, recentResources, recentPages) is stored in session store.
## Initialization
In app top-level (e.g., `RecentHydration.tsx`):
```tsx
import { useInitRecentTopic } from '@/hooks/useInitRecentTopic';
import { useInitRecentResource } from '@/hooks/useInitRecentResource';
import { useInitRecentPage } from '@/hooks/useInitRecentPage';
const App = () => {
useInitRecentTopic();
useInitRecentResource();
useInitRecentPage();
return <YourComponents />;
};
```
## Usage
### Method 1: Read from Store (Recommended)
```tsx
import { useSessionStore } from '@/store/session';
import { recentSelectors } from '@/store/session/selectors';
const Component = () => {
const recentTopics = useSessionStore(recentSelectors.recentTopics);
const isInit = useSessionStore(recentSelectors.isRecentTopicsInit);
if (!isInit) return <div>Loading...</div>;
return (
<div>
{recentTopics.map((topic) => (
<div key={topic.id}>{topic.title}</div>
))}
</div>
);
};
```
### Method 2: Use Hook Return (Single component)
```tsx
const { data: recentTopics, isLoading } = useInitRecentTopic();
```
## Available Selectors
### Recent Topics
```tsx
const recentTopics = useSessionStore(recentSelectors.recentTopics);
// Type: RecentTopic[]
const isInit = useSessionStore(recentSelectors.isRecentTopicsInit);
// Type: boolean
```
**RecentTopic type:**
```typescript
interface RecentTopic {
agent: {
avatar: string | null;
backgroundColor: string | null;
id: string;
title: string | null;
} | null;
id: string;
title: string | null;
updatedAt: Date;
}
```
### Recent Resources
```tsx
const recentResources = useSessionStore(recentSelectors.recentResources);
// Type: FileListItem[]
const isInit = useSessionStore(recentSelectors.isRecentResourcesInit);
```
### Recent Pages
```tsx
const recentPages = useSessionStore(recentSelectors.recentPages);
const isInit = useSessionStore(recentSelectors.isRecentPagesInit);
```
## Features
1. **Auto login detection**: Only loads when user is logged in
2. **Data caching**: Stored in store, no repeated loading
3. **Auto refresh**: SWR refreshes on focus (5-minute interval)
4. **Type safe**: Full TypeScript types
## Best Practices
1. Initialize all recent data at app top-level
2. Use selectors to read from store
3. For multi-component use, prefer Method 1
4. Use selectors for render optimization
+185
View File
@@ -5,6 +5,14 @@ description: "Version release workflow. Use when the user mentions 'release', 'h
# Version Release Workflow
## Mandatory Companion Skill
For every `/version-release` execution, you MUST load and apply:
- `../microcopy/SKILL.md`
Changelog style guidance is now fully embedded in this skill. Keep release facts unchanged, and only improve structure, readability, and tone.
## Overview
The primary development branch is **canary**. All day-to-day development happens on canary. When releasing, canary is merged into main. After merge, `auto-tag-release.yml` automatically handles tagging, version bumping, creating a GitHub Release, and syncing back to the canary branch.
@@ -150,6 +158,166 @@ All release PR bodies (both Minor and Patch) must include a user-facing changelo
- Weekly Release: See `reference/changelog-example/weekly-release.md`
- DB Migration: See `reference/changelog-example/db-migration.md`
### Mandatory Inputs Before Writing
1. Release diff context (`git log main..canary` and/or `git diff main...canary --stat`)
2. Existing release template constraints (title, credits, trigger rules)
3. `../microcopy/SKILL.md` terminology constraints
### Output Constraints (Hard Rules)
1. Keep all factual claims accurate to merged changes.
2. Do not invent numbers, scope, timelines, or availability tiers.
3. Keep release title and trigger-sensitive format unchanged.
4. Keep `Credits` section intact (format required by project conventions).
5. Prefer fewer headings and more natural narrative paragraphs.
6. EN/ZH versions must cover the same facts in the same order.
7. Prefer storytelling over feature enumeration.
8. Avoid `Key Updates` sections that are only bullet dumps unless explicitly requested.
### Editorial Voice (Notion/Linear-Inspired)
Target a changelog voice that is calm, confident, and human:
- Start from user reality, not internal implementation.
- Explain why this change matters before listing mechanics.
- Keep tone practical and grounded, but allow a little product warmth.
- Favor concrete workflow examples over abstract claims.
- Write like an update from a thoughtful product team, not a marketing launch page.
### Writing Model (3-Pass Rewrite)
#### Pass 1: Remove AI Vocabulary and Filler
- Replace inflated words with simple alternatives.
- Remove transition padding like "furthermore", "notably", "it is worth noting that".
- Cut generic importance inflation ("pivotal", "testament", "game-changer").
- Prefer direct verbs like `run`, `customize`, `manage`, `capture`, `improve`, `fix`.
#### Pass 2: Break AI Sentence Patterns
Avoid these structures:
- Parallel negation: "Not X, but Y"
- Tricolon overload: "A, B, and C" used repeatedly
- Rhetorical Q + answer: "What does this mean? It means..."
- Dramatic reveal openers: "Here's the thing", "The result?"
- Mirror symmetry in consecutive lines
- Overuse of em dashes
- Every paragraph ending in tidy "lesson learned" phrasing
#### Pass 3: Add Human Product Texture
- Lead with user-visible outcome, then explain mechanism.
- Mix sentence lengths naturally.
- Prefer straightforward phrasing over polished-but-empty language.
- Keep confidence, but avoid launch-ad hype.
- Write like a product team update, not a marketing page.
### Recommended Structure Blueprint
Use this shape unless the user asks otherwise:
1. `# 🚀 release: ...`
2. One opening paragraph (2-4 sentences) that explains overall user impact.
3. 2-4 narrative capability blocks (short headings optional):
- each block = user value + key capability
4. `Improvements and fixes` / `体验优化与修复` with concise bullets
5. `Credits` with required mention format
### Length and Reading Density (Important)
Avoid overly short release notes when the diff is substantial.
- Weekly release PR body:
- Usually target 350-700 English words (or equivalent Chinese length)
- Keep 2-4 narrative sections, each with at least one real paragraph
- Minor release PR body:
- Usually target 500-1000 English words (or equivalent Chinese length)
- Allow richer context and more concrete usage scenarios
- DB migration release PR body:
- Keep concise, but still include context + impact + operator notes
- If there are many commits, increase narrative depth before adding more bullets.
- If there are few commits, stay concise and do not pad content.
### Storytelling Contract (Major Capabilities)
For each major capability, write in this order:
1. Prior context/problem (briefly)
2. What changed in this release
3. Practical impact on user workflow
Do not collapse major capability sections into one-line bullets.
### Section Anatomy (Preferred)
Each major section should follow this internal rhythm:
1. Lead sentence: what changed and who benefits.
2. Context sentence: what was painful, slow, or fragmented before.
3. Mechanism paragraph: how the new behavior works in practice.
4. Optional utility list (`Use X to:`) for actionable workflows.
5. Optional availability closer when plan/platform constraints matter.
This pattern increases readability and makes changelogs more enjoyable to read without sacrificing precision.
### Section and Heading Heuristics
- Keep heading count low (typically 3-5).
- Weekly release PR body target:
- 1 opening paragraph
- 2-4 major narrative sections
- 1 improvements/fixes section
- 1 credits section
- Never produce heading-per-bullet layout.
- If a section has 4+ bullets, convert into 2-3 short narrative paragraphs when possible.
### Linear-Style Block Pattern
Use this pattern when writing major sections:
```md
## <Capability name>
<One sentence: what users can do now and why it matters.>
<One short paragraph: how this works in practice, in plain language.>
<Optional list for workflows>
Use <feature> to:
- <practical action 1>
- <practical action 2>
- <practical action 3>
<Optional availability sentence>
```
### Notion-Style Readability Moves
Apply these moves when appropriate:
- Use one clear "scene" sentence to ground context (for example, what a team is doing when the feature helps).
- Alternate paragraph lengths: one compact paragraph followed by a denser explanatory one.
- Prefer specific nouns (`triage inbox`, `topic switch`, `mobile session`) over broad terms like "experience" or "workflow improvements".
- Keep transitions natural (`Previously`, `Now`, `In practice`, `This means`) and avoid ornate writing.
- End key sections with a practical takeaway sentence, not a slogan.
### Anti-Pattern Red Flags (Rewrite Required)
- "Key Updates" followed by only bullets and no narrative context
- One bullet per feature with no prior context or user impact
- Repeated template like "Feature X: did Y"
- Heading-per-feature with no explanatory paragraph
- Mechanical transitions with no causal flow
### EN/ZH Synchronization Rules
- Keep section order aligned.
- Keep facts and scope aligned.
- Localize naturally; avoid literal sentence mirroring.
- If one language uses bullets for a section, the other should match style intent.
### Writing Tips
- **User-facing**: Describe changes that users can perceive, not internal implementation details
@@ -157,3 +325,20 @@ All release PR bodies (both Minor and Patch) must include a user-facing changelo
- **Highlight key items**: Use `**bold**` for important feature names
- **Credit contributors**: Collect all committers via `git log` and list alphabetically
- **Flexible categories**: Choose categories based on actual changes — no need to force-fit all categories
- **Terminology enforcement**: Ensure wording follows `microcopy` skill terminology and tone constraints
- **Linear narrative enforcement**: Follow capability -> explanation -> optional "Use X to" list
- **Storytelling enforcement**: For major updates, write in "before -> now -> impact" order
- **Depth enforcement**: If the diff is non-trivial, prefer complete paragraphs over compressed bullet-only summaries
- **Pleasure-to-read enforcement**: Include concrete examples and practical scenarios so readers can imagine using the capability
### Quick Checklist
- [ ] First paragraph explains user-visible release outcome
- [ ] Heading count is minimal and meaningful
- [ ] Major capabilities are short narrative paragraphs, not only bullets
- [ ] Includes "before -> now -> impact" for major sections
- [ ] No obvious AI patterns (parallel negation, rhetorical Q/A, dramatic reveal)
- [ ] Vocabulary is plain, direct, and product-credible
- [ ] Improvements/fixes remain concise and scannable
- [ ] Credits format is preserved exactly
- [ ] EN/ZH versions align in facts and order
@@ -4,16 +4,27 @@ A changelog reference for database migration release PR bodies.
---
This release includes a **database schema migration** involving **5 new tables** for the Agent Evaluation Benchmark system.
This release includes a **database schema migration** for Agent Evaluation Benchmark. We are adding **5 new tables** so benchmark setup, runs, and run-topic records can be stored in a complete and queryable structure.
### Migration: Add Agent Evaluation Benchmark Tables
## Migration overview
- Added 5 new tables: `agent_eval_benchmarks`, `agent_eval_datasets`, `agent_eval_records`, `agent_eval_runs`, `agent_eval_run_topics`
Previously, benchmark-related data lacked a full lifecycle model, which made it harder to track evaluation flow from dataset to run results. This migration introduces the missing relational layer so benchmark configuration, execution, and analysis records stay connected.
### Notes for Self-hosted Users
In practical terms, this reduces ambiguity for downstream features and gives operators a cleaner foundation for troubleshooting and reporting.
- The migration runs automatically on application startup
- No manual intervention required
Added tables:
- `agent_eval_benchmarks`
- `agent_eval_datasets`
- `agent_eval_records`
- `agent_eval_runs`
- `agent_eval_run_topics`
## Notes for self-hosted users
- Migration runs automatically during app startup.
- No manual SQL action is required in standard deployments.
- As with any schema release, we still recommend database backup and rollout during a low-traffic window.
The migration owner: @{pr-author} — responsible for this database schema change, reach out for any migration-related issues.
@@ -4,42 +4,47 @@ A real-world changelog reference for weekly patch release PR bodies.
---
This release includes **82 commits** , Key updates are below.
This weekly release includes **82 commits**. The throughline is simple: less friction when moving from idea to execution. Across agent workflows, model coverage, and desktop polish, this release removes several small blockers that used to interrupt momentum.
### New Features and Enhancements
The result is not one headline feature, but a noticeably smoother week-to-week experience. Teams can evaluate agents with clearer structure, ship richer media flows, and spend less time debugging provider and platform edge cases.
- Added **Agent Benchmark** support for more systematic agent performance evaluation.
- Introduced the **video generation** feature end-to-end, including entry points, sidebar "new" badge support, and skeleton loading for topic switching.
- Expanded memory capabilities: support for memory effort/tool permission configuration and improved timeout calculation for memory analysis tasks.
- Added desktop editor support for image upload via file picker.
## Agent workflows and media generation
### Models and Provider Expansion
Previously, some agent evaluation and media generation flows still felt fragmented: setup was manual, discoverability was uneven, and switching between topics could interrupt context. This release adds **Agent Benchmark** support and lands the **video generation** path end-to-end, from entry point to generation feedback.
- Added a new provider: **Straico**.
- Added/updated support for:
- Claude Sonnet 4.6
- Gemini 3.1 Pro Preview
- Qwen3.5 series
- Grok Imagine (`grok-imagine-image`)
- MiniMax 2.5
- Added related i18n copy and model parameter adaptations.
In practice, this means users can discover and run these workflows with fewer detours. Sidebar "new" indicators improve visibility, skeleton loading makes topic switches feel less abrupt, and memory-related controls now behave more predictably under real workload pressure.
### Desktop Improvements
We also expanded memory controls with effort and tool-permission configuration, and improved timeout calculation for memory analysis tasks so longer runs fail less often in production-like usage.
- Integrated `electron-liquid-glass` (macOS Tahoe).
- Improved DMG background assets and desktop release workflow.
## Models and provider coverage
### Stability, Security, and UX Fixes
Provider diversity matters most when teams can adopt new models without rewriting glue code every sprint. This release adds **Straico** and updates support for Claude Sonnet 4.6, Gemini 3.1 Pro Preview, Qwen3.5, Grok Imagine (`grok-imagine-image`), and MiniMax 2.5.
- Fixed multiple video generation pipeline issues: precharge refund handling, webhook token verification, pricing parameter usage, asset cleanup, and type safety.
- Fixed `sanitizeFileName` path traversal risks and added unit tests.
- Fixed MCP media URL generation with duplicated `APP_URL` prefix.
Use these updates to:
- route requests to newly available providers
- test newer model families without custom patching
- keep model parameters and related i18n copy aligned across providers
This keeps model exploration practical: faster evaluation loops, fewer adaptation surprises, and cleaner cross-provider behavior.
## Desktop and platform polish
Desktop receives a set of quality-of-life upgrades that reduce "death by a thousand cuts" moments. We integrated `electron-liquid-glass` for macOS Tahoe and improved DMG background assets and packaging flow for more consistent release output.
The desktop editor now supports image upload from the file picker, which shortens everyday authoring steps and removes one more reason to switch tools mid-task.
## Improvements and fixes
- Fixed multiple video pipeline issues across precharge refund handling, webhook token verification, pricing parameter usage, asset cleanup, and type safety.
- Fixed path traversal risk in `sanitizeFileName` and added corresponding unit tests.
- Fixed MCP media URL generation when `APP_URL` was duplicated in output paths.
- Fixed Qwen3 embedding failures caused by batch-size limits.
- Fixed multiple UI/interaction issues, including mobile header agent selector/topic count, ChatInput scrolling behavior, and tooltip stacking context.
- Fixed several UI interaction issues, including mobile header agent selector/topic count, ChatInput scrolling behavior, and tooltip stacking context.
- Fixed missing `@napi-rs/canvas` native bindings in Docker standalone builds.
- Improved GitHub Copilot authentication retry behavior and response error handling in edge cases.
### Credits
## Credits
Huge thanks to these contributors (alphabetical):
+6 -3
View File
@@ -71,15 +71,18 @@ internal_createTopic: async (params) => {
**Actions:**
- Public: `createTopic`, `sendMessage`
- Internal: `internal_createTopic`, `internal_updateMessageContent`
- Dispatch: `internal_dispatchTopic`
- Toggle: `internal_toggleMessageLoading`
**State:**
**State:**
- ID arrays: `topicEditingIds`
- ID arrays: `messageLoadingIds`, `topicEditingIds`
- Maps: `topicMaps`, `messagesMap`
- Active: `activeTopicId`
- Init flags: `topicsInit`
## Detailed Guides
@@ -30,16 +30,13 @@ internal_createMessage: async (message, context) => {
let tempId = context?.tempMessageId;
if (!tempId) {
tempId = internal_createTmpMessage(message);
internal_toggleMessageLoading(true, tempId);
}
try {
const id = await messageService.createMessage(message);
await refreshMessages();
internal_toggleMessageLoading(false, tempId);
return id;
} catch (e) {
internal_toggleMessageLoading(false, tempId);
internal_dispatchMessage({
id: tempId,
type: 'updateMessage',
+5
View File
@@ -162,11 +162,15 @@ describe('ModuleName', () => {
### 5. Create Pull Request
- Create a new branch: `automatic/add-tests-[module-name]-[date]`
- Commit changes with message format:
```
✅ test: add unit tests for [module-name]
```
- Push the branch
- Create a PR with:
- Title: `✅ test: add unit tests for [module-name]`
@@ -198,6 +202,7 @@ describe('ModuleName', () => {
- Test approach: [brief description]
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
```
+12 -4
View File
@@ -77,20 +77,24 @@ Create `e2e/src/features/{module-name}/README.md` with:
# {Module} 模块 E2E 测试覆盖
## 模块概述
**路由**: `/module`, `/module/[id]`
## 功能清单与测试覆盖
### 1. 功能分组名称
| 功能点 | 描述 | 优先级 | 状态 | 测试文件 |
| ------ | ---- | ------ | ---- | -------- |
| 功能点 | 描述 | 优先级 | 状态 | 测试文件 |
| ------ | ---- | ------ | ---- | ------------- |
| 功能A | xxx | P0 | ✅ | `xxx.feature` |
| 功能B | xxx | P1 | ⏳ | |
| 功能B | xxx | P1 | ⏳ | |
## 测试文件结构
## 测试执行
## 已知问题
## 更新记录
```
@@ -228,7 +232,7 @@ const testId = pickle.tags.find(
tag.name.startsWith('@COMMUNITY-') ||
tag.name.startsWith('@AGENT-') ||
tag.name.startsWith('@HOME-') ||
tag.name.startsWith('@PAGE-') || // Add new prefix
tag.name.startsWith('@PAGE-') || // Add new prefix
tag.name.startsWith('@ROUTES-'),
);
```
@@ -300,11 +304,15 @@ HEADLESS=true BASE_URL=http://localhost:3006 \
### 10. Create Pull Request
- Branch name: `test/e2e-{module-name}`
- Commit message format:
```
✅ test: add E2E tests for {module-name}
```
- PR title: `✅ test: add E2E tests for {module-name}`
- PR body template:
````markdown
+8
View File
@@ -36,6 +36,7 @@ If you detect any leaked secrets, respond IMMEDIATELY with:
⚠️ **Security Warning**: Your comment appears to contain sensitive information (API keys, secrets, or credentials).
**Please delete your comment immediately** to protect your account security, then:
1. Rotate/regenerate any exposed credentials
2. Re-post your question with secrets redacted (e.g., `AUTH_SECRET=***`)
@@ -73,12 +74,17 @@ Look for the "Troubleshooting" or "FAQ" section in the migration docs and match
## Response Guidelines
1. **Be helpful and friendly** - Users are often frustrated when migration doesn't work
2. **Be specific** - Provide exact commands or configuration examples
3. **Reference documentation** - Point users to relevant docs sections
4. **Ask for logs** - If the issue is unclear, ask for Docker logs:
```bash
docker logs <container_name> 2>&1 | tail -100
```
5. **One issue at a time** - Focus on solving one problem before moving to the next
## Response Format
@@ -90,6 +96,7 @@ Use this format for your responses:
[If missing information]
To help you effectively, please provide:
- [List missing items]
[If you can help]
@@ -102,6 +109,7 @@ Based on your description, here's what I suggest:
[If the issue is complex or unknown]
This issue needs further investigation. I've notified the team. In the meantime, please:
1. [Any immediate steps they can try]
2. Share your Docker logs if you haven't already
```
+16 -13
View File
@@ -2,15 +2,15 @@
## Quick Reference by Name
- **@arvinxx**: Last resort only, mention for priority:high issues, tool calling , mcp
- **@arvinxx**: Last resort only, mention for priority:high issues, tool calling, mcp, database
- **@canisminor1990**: Design, UI components, editor, markdown rendering
- **@tjx666**: Image/video generation, vision, cloud version, documentation, TTS, auth, login/register
- **@ONLY-yours**: Performance, streaming, settings, general bugs, web platform, marketplace
- **@RiverTwilight**: Knowledge base, files (KB-related), group chat
- **@nekomeowww**: Memory, backend, deployment, DevOps
- **@tjx666**: Image/video generation, vision, cloud version, documentation, TTS, auth, login/register, database
- **@ONLY-yours**: Performance, streaming, settings, general bugs, web platform, marketplace, agent builder, schedule task
- **@Innei**: Knowledge base, files (KB-related), group chat, Electron, desktop client, build system
- **@nekomeowww**: Memory, backend, deployment, DevOps, database
- **@sudongyuer**: Mobile app (React Native)
- **@sxjeru**: Model providers and configuration
- **@rdmclin2**: Team workspace
- **@rdmclin2**: Team workspace, IM and bot integration
- **@tcmonster**: Subscription, refund, recharge, business cooperation
Quick reference for assigning issues based on labels.
@@ -28,7 +28,7 @@ Quick reference for assigning issues based on labels.
| Label | Owner | Notes |
| ------------------ | ----------- | -------------------------------------- |
| `platform:mobile` | @sudongyuer | React Native mobile app |
| `platform:desktop` | @ONLY-yours | Electron desktop client (general) |
| `platform:desktop` | @Innei | Electron desktop client, build system |
| `platform:web` | @ONLY-yours | Web platform (unless specific feature) |
### Feature Labels (feature:\*)
@@ -38,8 +38,8 @@ Quick reference for assigning issues based on labels.
| `feature:image` | @tjx666 | AI image generation |
| `feature:dalle` | @tjx666 | DALL-E related |
| `feature:vision` | @tjx666 | Vision/multimodal generation |
| `feature:knowledge-base` | @RiverTwilight | Knowledge base and RAG |
| `feature:files` | @RiverTwilight | File upload/management (when KB-related)<br>@ONLY-yours (general files) |
| `feature:knowledge-base` | @Innei | Knowledge base and RAG |
| `feature:files` | @Innei | File upload/management (when KB-related)<br>@ONLY-yours (general files) |
| `feature:editor` | @canisminor1990 | Lobe Editor |
| `feature:markdown` | @canisminor1990 | Markdown rendering |
| `feature:auth` | @tjx666 | Authentication/authorization |
@@ -57,9 +57,12 @@ Quick reference for assigning issues based on labels.
| `feature:search` | @ONLY-yours | Search functionality |
| `feature:tts` | @tjx666 | Text-to-speech |
| `feature:export` | @ONLY-yours | Export functionality |
| `feature:group-chat` | @RiverTwilight | Group chat functionality |
| `feature:group-chat` | @arvinxx | Group chat functionality |
| `feature:memory` | @nekomeowww | Memory feature |
| `feature:team-workspace` | @rdmclin2 | Team workspace application |
| `feature:im-integration` | @rdmclin2 | IM and bot integration (Slack, Discord, etc.) |
| `feature:agent-builder` | @ONLY-yours | Agent builder |
| `feature:schedule-task` | @ONLY-yours | Schedule task |
| `feature:subscription` | @tcmonster | Subscription and billing |
| `feature:refund` | @tcmonster | Refund requests |
| `feature:recharge` | @tcmonster | Recharge and payment |
@@ -125,18 +128,18 @@ Quick reference for assigning issues based on labels.
**Single owner:**
```
```plaintext
@username - This is a [feature/component] issue. Please take a look.
```
**Multiple owners:**
```
```plaintext
@primary @secondary - This involves [features]. Please coordinate.
```
**High priority:**
```
```plaintext
@owner @arvinxx - High priority [feature] issue.
```
+5
View File
@@ -72,11 +72,15 @@ Module granularity examples:
### 5. Create Pull Request
- Create a new branch: `automatic/translate-comments-[module-name]-[date]`
- Commit changes with message format:
```
🌐 chore: translate non-English comments to English in [module-name]
```
- Push the branch
- Create a PR with:
- Title: `🌐 chore: translate non-English comments to English in [module-name]`
@@ -100,6 +104,7 @@ Module granularity examples:
`[module-path]`
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
```
+11
View File
@@ -408,3 +408,14 @@ OPENAI_API_KEY=sk-xxxxxxxxx
# IMPORTANT: This key is stored server-side only and NEVER exposed to the client
# When this key is set, Klavis integration will be automatically enabled
# KLAVIS_API_KEY=your_klavis_api_key_here
# #######################################
# #### Message Gateway (IM Integration) ##
# #######################################
# External message-gateway for unified IM platform connection management.
# Set ENABLED=1 to activate. To migrate away, remove ENABLED first (keep URL/TOKEN)
# so LobeHub can automatically disconnect leftover gateway connections.
# MESSAGE_GATEWAY_ENABLED=1
# MESSAGE_GATEWAY_URL=https://message-gateway.lobehub.com
# MESSAGE_GATEWAY_SERVICE_TOKEN=your_service_token_here
@@ -9,16 +9,10 @@ inputs:
runs:
using: composite
steps:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ inputs.node-version }}
package-manager-cache: false
- name: Install dependencies
shell: bash
+29
View File
@@ -0,0 +1,29 @@
name: Setup Environment
description: Setup Node.js, pnpm (install) and Bun (script runner) for workflows
inputs:
node-version:
description: Node.js version
required: false
default: '24.11.1'
package-manager-cache:
description: Pass-through to actions/setup-node package-manager-cache
required: false
default: 'false'
runs:
using: composite
steps:
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false
- name: Install bun
uses: oven-sh/setup-bun@v2
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.node-version }}
package-manager-cache: ${{ inputs.package-manager-cache }}
+13
View File
@@ -0,0 +1,13 @@
AmAzing129
arvinxx
canisminor1990
ilimei
Innei
lobehubbot
nekomeowww
ONLY-yours
rdmclin2
rivertwilight
sudongyuer
tcmonster
tjx666
+4 -6
View File
@@ -3,7 +3,7 @@ name: Daily i18n Update
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
workflow_dispatch: {}
# Add permissions configuration
permissions:
@@ -25,13 +25,11 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ secrets.BUN_VERSION }}
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
- name: Update i18n
run: bun run i18n
+8 -15
View File
@@ -26,8 +26,9 @@ jobs:
- name: Detect release PR (version from title)
id: release
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
PR_TITLE="${{ github.event.pull_request.title }}"
echo "PR Title: $PR_TITLE"
# Match "🚀 release: v{x.x.x}" format (strict semver: x.y.z with optional -prerelease or +build)
@@ -44,9 +45,10 @@ jobs:
- name: Detect patch PR (branch first, title fallback)
id: patch
if: steps.release.outputs.should_tag != 'true'
env:
HEAD_REF: ${{ github.event.pull_request.head.ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
HEAD_REF="${{ github.event.pull_request.head.ref }}"
PR_TITLE="${{ github.event.pull_request.title }}"
echo "Head ref: $HEAD_REF"
echo "PR Title: $PR_TITLE"
@@ -72,22 +74,13 @@ jobs:
git checkout main
git pull --rebase origin main
- name: Setup Node.js
- name: Setup environment
if: steps.release.outputs.should_tag == 'true' || steps.patch.outputs.should_tag == 'true'
uses: actions/setup-node@v6
with:
node-version: 24.11.1
package-manager-cache: false
- name: Install bun
if: steps.release.outputs.should_tag == 'true' || steps.patch.outputs.should_tag == 'true'
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
uses: ./.github/actions/setup-env
- name: Install deps
if: steps.release.outputs.should_tag == 'true' || steps.patch.outputs.should_tag == 'true'
run: bun i
run: pnpm install
- name: Resolve patch version (patch bump)
id: patch-version
+3 -12
View File
@@ -1,7 +1,7 @@
name: Bundle Analyzer
on:
workflow_dispatch:
workflow_dispatch: {}
permissions:
contents: read
@@ -9,7 +9,6 @@ permissions:
env:
NODE_VERSION: 24.11.1
BUN_VERSION: 1.2.23
jobs:
bundle-analyzer:
@@ -20,19 +19,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install dependencies
run: pnpm i
@@ -51,11 +51,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install dependencies
run: bun install --frozen-lockfile
run: pnpm install --frozen-lockfile
- name: Install Playwright browsers (with system deps)
run: bunx playwright install --with-deps chromium
+3 -3
View File
@@ -29,11 +29,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install dependencies
run: bun install --frozen-lockfile
run: pnpm install --frozen-lockfile
- name: Configure Git
run: |
+11 -1
View File
@@ -18,6 +18,16 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Check if author is a team member
id: check-team
run: |
ISSUE_AUTHOR="${{ github.event.issue.user.login }}"
if grep -iq "^${ISSUE_AUTHOR}$" .github/maintainers.txt; then
echo "is_team=true" >> "$GITHUB_OUTPUT"
else
echo "is_team=false" >> "$GITHUB_OUTPUT"
fi
- name: Copy triage prompts
run: |
mkdir -p /tmp/claude-prompts
@@ -62,7 +72,7 @@ jobs:
**IMPORTANT**:
- Follow ALL steps in the issue-triage.md guide
- Apply labels according to the guide's rules
- Post a mention comment to the appropriate team member(s) based on team-assignment.md
- ${{ steps.check-team.outputs.is_team == 'true' && 'The issue author is a team member. Do NOT post any @mention comment.' || 'Post a mention comment to the appropriate team member(s) based on team-assignment.md' }}
- Replace [ISSUE_NUMBER] with: ${{ github.event.issue.number }}
**Start the triage process now.**
+12
View File
@@ -21,7 +21,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Check if author is a team member
id: check-team
run: |
PR_AUTHOR="${{ github.event.pull_request.user.login }}"
if grep -iq "^${PR_AUTHOR}$" .github/maintainers.txt; then
echo "is_team=true" >> "$GITHUB_OUTPUT"
else
echo "is_team=false" >> "$GITHUB_OUTPUT"
fi
- name: Copy prompts
if: steps.check-team.outputs.is_team == 'false'
run: |
mkdir -p /tmp/claude-prompts
cp .claude/prompts/pr-assign.md /tmp/claude-prompts/
@@ -29,6 +40,7 @@ jobs:
cp .claude/prompts/security-rules.md /tmp/claude-prompts/
- name: Run Claude Code for PR Reviewer Assignment
if: steps.check-team.outputs.is_team == 'false'
uses: anthropics/claude-code-action@v1
with:
github_token: ${{ secrets.GH_TOKEN }}
+1 -1
View File
@@ -55,5 +55,5 @@ jobs:
# Security: Allow only specific safe commands - no gh commands to prevent token exfiltration
# These tools are restricted to code analysis and build operations only
claude_args: |
--allowedTools "Bash(git:*),Bash(gh:*),Bash(bun run:*),Bash(pnpm run:*),Bash(npm run:*),Bash(npx:*),Bash(bunx:*),Bash(vitest:*),Bash(rg:*),Bash(find:*),Bash(sed:*),Bash(grep:*),Bash(awk:*),Bash(wc:*),Bash(xargs:*)"
--allowedTools "Bash(git:*),Bash(gh:*),Bash(bun run:*),Bash(bunx:*),Bash(pnpm:*),Bash(npm run:*),Bash(npx:*),Bash(vitest:*),Bash(rg:*),Bash(find:*),Bash(sed:*),Bash(grep:*),Bash(awk:*),Bash(wc:*),Bash(xargs:*)"
--append-system-prompt "$(cat /tmp/claude-prompts/security-rules.md)"
+4 -6
View File
@@ -61,13 +61,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install dependencies (bun)
run: bun install
- name: Install dependencies
run: pnpm install
- name: Install Playwright browsers (with system deps)
run: bunx playwright install --with-deps chromium
@@ -3,7 +3,7 @@ description: Auto-closes issues that are duplicates of existing issues
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
workflow_dispatch: {}
jobs:
auto-close-duplicates:
@@ -17,10 +17,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install dependencies
run: pnpm install
- name: Auto-close duplicate issues
run: bun run .github/scripts/auto-close-duplicates.ts
+13 -1
View File
@@ -28,9 +28,21 @@ jobs:
✅ @{{ author }}
This issue is closed, If you have any questions, you can comment and reply.
- name: Checkout repository
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == true
uses: actions/checkout@v4
- name: Check if PR author is maintainer
if: github.event.pull_request.merged == true
id: maintainer-check
run: |
if [ -f .github/maintainers.txt ] && grep -qx "${{ github.event.pull_request.user.login }}" .github/maintainers.txt; then
echo "skip=true" >> $GITHUB_OUTPUT
fi
- name: Auto Comment on Pull Request Merged
uses: actions-cool/pr-welcome@main
if: github.event.pull_request.merged == true
if: github.event.pull_request.merged == true && steps.maintainer-check.outputs.skip != 'true'
with:
token: ${{ secrets.GH_TOKEN }}
comment: |
+14 -32
View File
@@ -6,10 +6,10 @@ on:
channel:
description: 'Release channel for desktop build (affects version suffix and workflow:set-desktop-version)'
required: true
default: nightly
default: canary
type: choice
options:
- nightly
- canary
- beta
- stable
build_macos:
@@ -41,7 +41,6 @@ permissions:
env:
NODE_VERSION: 24.11.1
BUN_VERSION: 1.2.23
jobs:
version:
@@ -102,18 +101,10 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node & pnpm
uses: ./.github/actions/setup-node-pnpm
- name: Setup build environment
uses: ./.github/actions/desktop-build-setup
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: 'false'
# node-linker=hoisted 模式将可以确保 asar 压缩可用
- name: Install dependencies
run: |
pnpm install --node-linker=hoisted &
npm run install-isolated --prefix=./apps/desktop &
wait
- name: Set package version
run: npm run workflow:set-desktop-version ${{ needs.version.outputs.version }} ${{ inputs.channel }}
@@ -127,8 +118,8 @@ jobs:
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
CSC_LINK: ${{ secrets.APPLE_CERTIFICATE_BASE64 }}
CSC_KEY_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ inputs.channel == 'beta' && secrets.UMAMI_BETA_DESKTOP_PROJECT_ID || secrets.UMAMI_NIGHTLY_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ inputs.channel == 'beta' && secrets.UMAMI_BETA_DESKTOP_BASE_URL || secrets.UMAMI_NIGHTLY_DESKTOP_BASE_URL }}
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ inputs.channel == 'stable' && secrets.UMAMI_STABLE_DESKTOP_PROJECT_ID || secrets.UMAMI_BETA_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ inputs.channel == 'stable' && secrets.UMAMI_STABLE_DESKTOP_BASE_URL || secrets.UMAMI_BETA_DESKTOP_BASE_URL }}
CSC_FOR_PULL_REQUEST: true
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
@@ -193,8 +184,8 @@ jobs:
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ inputs.channel == 'beta' && secrets.UMAMI_BETA_DESKTOP_PROJECT_ID || secrets.UMAMI_NIGHTLY_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ inputs.channel == 'beta' && secrets.UMAMI_BETA_DESKTOP_BASE_URL || secrets.UMAMI_NIGHTLY_DESKTOP_BASE_URL }}
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ inputs.channel == 'stable' && secrets.UMAMI_STABLE_DESKTOP_PROJECT_ID || secrets.UMAMI_BETA_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ inputs.channel == 'stable' && secrets.UMAMI_STABLE_DESKTOP_BASE_URL || secrets.UMAMI_BETA_DESKTOP_BASE_URL }}
TEMP: C:\temp
TMP: C:\temp
@@ -222,17 +213,10 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node & pnpm
uses: ./.github/actions/setup-node-pnpm
- name: Setup build environment
uses: ./.github/actions/desktop-build-setup
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: 'false'
- name: Install dependencies
run: |
pnpm install --node-linker=hoisted &
npm run install-isolated --prefix=./apps/desktop &
wait
- name: Set package version
run: npm run workflow:set-desktop-version ${{ needs.version.outputs.version }} ${{ inputs.channel }}
@@ -244,8 +228,8 @@ jobs:
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ inputs.channel == 'beta' && secrets.UMAMI_BETA_DESKTOP_PROJECT_ID || secrets.UMAMI_NIGHTLY_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ inputs.channel == 'beta' && secrets.UMAMI_BETA_DESKTOP_BASE_URL || secrets.UMAMI_NIGHTLY_DESKTOP_BASE_URL }}
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ inputs.channel == 'stable' && secrets.UMAMI_STABLE_DESKTOP_PROJECT_ID || secrets.UMAMI_BETA_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ inputs.channel == 'stable' && secrets.UMAMI_STABLE_DESKTOP_BASE_URL || secrets.UMAMI_BETA_DESKTOP_BASE_URL }}
- name: Upload artifact
uses: actions/upload-artifact@v6
@@ -274,12 +258,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node & Bun
uses: ./.github/actions/setup-node-bun
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
bun-version: ${{ env.BUN_VERSION }}
package-manager-cache: 'false'
- name: Download artifacts
uses: actions/download-artifact@v7
+7 -36
View File
@@ -27,15 +27,11 @@ jobs:
- name: Checkout base
uses: actions/checkout@v6
- name: Setup Node & Bun
uses: ./.github/actions/setup-node-bun
with:
node-version: 24.11.1
bun-version: latest
package-manager-cache: 'false'
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
env:
NODE_OPTIONS: --max-old-space-size=8192
@@ -93,29 +89,10 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node & pnpm
uses: ./.github/actions/setup-node-pnpm
- name: Setup build environment
uses: ./.github/actions/desktop-build-setup
with:
node-version: 24.11.1
package-manager-cache: 'false'
# node-linker=hoisted 模式将可以确保 asar 压缩可用
- name: Install dependencies
run: pnpm install --node-linker=hoisted
# 移除国内 electron 镜像配置,GitHub Actions 使用官方源更快
- name: Remove China electron mirror from .npmrc
shell: bash
run: |
NPMRC_FILE="./apps/desktop/.npmrc"
if [ -f "$NPMRC_FILE" ]; then
sed -i.bak '/^electron_mirror=/d; /^electron_builder_binaries_mirror=/d' "$NPMRC_FILE"
rm -f "${NPMRC_FILE}.bak"
echo "✅ Removed electron mirror config from .npmrc"
fi
- name: Install deps on Desktop
run: npm run install-isolated --prefix=./apps/desktop
# 设置 package.json 的版本号
- name: Set package version
@@ -228,12 +205,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node & Bun
uses: ./.github/actions/setup-node-bun
with:
node-version: 24.11.1
bun-version: latest
package-manager-cache: 'false'
- name: Setup environment
uses: ./.github/actions/setup-env
# 下载所有平台的构建产物
- name: Download artifacts
@@ -251,13 +224,11 @@ jobs:
- name: Install yaml only for merge step
run: |
cd scripts/electronWorkflow
# 在脚本目录创建最小 package.json,防止 bun 向上寻找根 package.json
if [ ! -f package.json ]; then
echo '{"name":"merge-mac-release","private":true}' > package.json
fi
bun add --no-save yaml@2.8.1
# 合并 macOS YAML 文件 (使用 bun 运行 JavaScript)
- name: Merge latest-mac.yml files
run: bun run scripts/electronWorkflow/mergeMacReleaseFiles.js
+8 -22
View File
@@ -7,7 +7,7 @@ name: Release Desktop Beta
# 如: v2.0.0-beta.1, v2.0.0-alpha.1, v2.0.0-rc.1
#
# 注意: Stable 版本 (如 v2.0.0) 由 release-desktop-stable.yml 处理
# 注意: Nightly 版本 (如 v2.1.0-nightly.xxx) 由 release-desktop-nightly.yml 处理
# 注意: Nightly 版本已停用,不再参与 Desktop 发布流程
# ============================================
on:
@@ -41,10 +41,10 @@ jobs:
version="${version#v}"
echo "version=${version}" >> $GITHUB_OUTPUT
# Beta 版本包含 beta/alpha/rc (nightly 由 release-desktop-nightly.yml 处理)
# Beta 版本包含 beta/alpha/rcnightly 标签已停用
if [[ "$version" == *"nightly"* ]]; then
echo "is_beta=false" >> $GITHUB_OUTPUT
echo "⏭️ Skipping: $version is a nightly release (handled by release-desktop-nightly.yml)"
echo "⏭️ Skipping: $version is a disabled nightly release tag"
elif [[ "$version" == *"beta"* ]] || [[ "$version" == *"alpha"* ]] || [[ "$version" == *"rc"* ]]; then
echo "is_beta=true" >> $GITHUB_OUTPUT
echo "✅ Beta release detected: $version"
@@ -62,19 +62,13 @@ jobs:
- name: Checkout base
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install deps
run: bun i
run: pnpm install
- name: Lint
run: bun run lint
@@ -168,16 +162,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
# 下载所有平台的构建产物
- name: Download artifacts
@@ -195,13 +183,11 @@ jobs:
- name: Install yaml only for merge step
run: |
cd scripts/electronWorkflow
# 在脚本目录创建最小 package.json,防止 bun 向上寻找根 package.json
if [ ! -f package.json ]; then
echo '{"name":"merge-mac-release","private":true}' > package.json
fi
bun add --no-save yaml@2.8.1
# 合并 macOS YAML 文件 (使用 bun 运行 JavaScript)
- name: Merge latest-mac.yml files
run: bun run scripts/electronWorkflow/mergeMacReleaseFiles.js
+70 -39
View File
@@ -45,6 +45,7 @@ jobs:
name: Calculate Canary Version
runs-on: ubuntu-latest
outputs:
release_notes: ${{ steps.release-notes.outputs.release_notes }}
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
should_build: ${{ steps.check.outputs.should_build }}
@@ -121,6 +122,66 @@ jobs:
echo "✅ Canary version: ${version}"
echo "🏷️ Tag: ${tag}"
- name: Generate canary release notes
if: steps.check.outputs.should_build == 'true'
id: release-notes
env:
TAG: ${{ steps.version.outputs.tag }}
run: |
previous_canary=$(git tag --sort=-creatordate | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-canary\.[0-9]+$' | head -n 1)
latest_stable=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -n "$previous_canary" ]; then
compare_from="$previous_canary"
compare_range="${previous_canary}..HEAD"
elif [ -n "$latest_stable" ]; then
compare_from="$latest_stable"
compare_range="${latest_stable}..HEAD"
else
compare_from="initial commit"
compare_range="HEAD"
fi
commit_count=$(git rev-list --count "$compare_range")
commits=$(git log --no-merges --pretty='- `%h` %s (%an)' "$compare_range")
if [ -z "$commits" ]; then
commits='- No new commits recorded.'
fi
{
echo "release_notes<<EOF"
echo "## 🐤 Canary Build — ${TAG}"
echo
echo "> Automated canary build from \`canary\` branch."
echo
echo "### Commit Information"
echo
echo "- Based on changes since \`${compare_from}\`"
echo "- Commit count: ${commit_count}"
echo
printf '%s\n' "$commits"
echo
echo "### ⚠️ Important Notes"
echo
echo "- **This is an automated canary build and is NOT intended for production use.**"
echo "- Canary builds are triggered by \`build\`/\`fix\`/\`style\` commits on the \`canary\` branch."
echo "- May contain **unstable or incomplete changes**. **Use at your own risk.**"
echo "- It is strongly recommended to **back up your data** before using a canary build."
echo
echo "### 📦 Installation"
echo
echo "Download the appropriate installer for your platform from the assets below."
echo
echo "| Platform | File |"
echo "|----------|------|"
echo "| macOS (Apple Silicon) | \`.dmg\` (arm64) |"
echo "| macOS (Intel) | \`.dmg\` (x64) |"
echo "| Windows | \`.exe\` |"
echo "| Linux | \`.AppImage\` / \`.deb\` |"
echo "EOF"
} >> $GITHUB_OUTPUT
# ============================================
# 代码质量检查
# ============================================
@@ -133,19 +194,13 @@ jobs:
- name: Checkout base
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install deps
run: bun i
run: pnpm install
- name: Lint
run: bun run lint
@@ -188,6 +243,7 @@ jobs:
env:
UPDATE_CHANNEL: canary
UPDATE_SERVER_URL: ${{ secrets.UPDATE_SERVER_URL }}
RELEASE_NOTES: ${{ needs.calculate-version.outputs.release_notes }}
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
@@ -207,6 +263,7 @@ jobs:
env:
UPDATE_CHANNEL: canary
UPDATE_SERVER_URL: ${{ secrets.UPDATE_SERVER_URL }}
RELEASE_NOTES: ${{ needs.calculate-version.outputs.release_notes }}
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
@@ -222,6 +279,7 @@ jobs:
env:
UPDATE_CHANNEL: canary
UPDATE_SERVER_URL: ${{ secrets.UPDATE_SERVER_URL }}
RELEASE_NOTES: ${{ needs.calculate-version.outputs.release_notes }}
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
@@ -247,16 +305,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Download artifacts
uses: actions/download-artifact@v7
@@ -311,28 +363,7 @@ jobs:
tag_name: ${{ needs.calculate-version.outputs.tag }}
name: 'Desktop Canary ${{ needs.calculate-version.outputs.tag }}'
prerelease: true
body: |
## 🐤 Canary Build — ${{ needs.calculate-version.outputs.tag }}
> Automated canary build from `canary` branch.
### ⚠️ Important Notes
- **This is an automated canary build and is NOT intended for production use.**
- Canary builds are triggered by `build`/`fix`/`style` commits on the `canary` branch.
- May contain **unstable or incomplete changes**. **Use at your own risk.**
- It is strongly recommended to **back up your data** before using a canary build.
### 📦 Installation
Download the appropriate installer for your platform from the assets below.
| Platform | File |
|----------|------|
| macOS (Apple Silicon) | `.dmg` (arm64) |
| macOS (Intel) | `.dmg` (x64) |
| Windows | `.exe` |
| Linux | `.AppImage` / `.deb` |
body: ${{ needs.calculate-version.outputs.release_notes }}
files: |
release/latest*
release/*.dmg*
@@ -1,427 +0,0 @@
name: Release Desktop Nightly
# ============================================
# Nightly 自动发版工作流
# ============================================
# 触发条件:
# 1. 定时: 每天 UTC+8 14:00 (UTC 06:00)
# 2. 手动触发 (workflow_dispatch)
#
# 版本策略:
# 基于最新 tag 的 minor+1, 格式: X.(Y+1).0-nightly.YYYYMMDDHHMM
# 例: 当前 tag v2.0.12 → v2.1.0-nightly.202502091400
# 使用精确到分钟的时间戳避免同一天多次触发时 tag 冲突
# ============================================
on:
schedule:
- cron: '0 6 * * *'
workflow_dispatch:
inputs:
force:
description: 'Force build (skip diff check)'
required: false
type: boolean
default: false
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
permissions: read-all
env:
NODE_VERSION: '24.11.1'
jobs:
# ============================================
# 计算 Nightly 版本号
# ============================================
calculate-version:
name: Calculate Nightly Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
has_changes: ${{ steps.changes.outputs.has_changes }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Check for code changes since last nightly
id: changes
run: |
# 手动触发 + force 时跳过 diff 检查
if [ "${{ inputs.force }}" == "true" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "🔧 Force build requested, skipping diff check"
exit 0
fi
# 查找上一个 nightly tag
last_nightly=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+-nightly\.' | head -n 1)
if [ -z "$last_nightly" ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "📦 No previous nightly tag found, proceeding with first nightly build"
exit 0
fi
echo "📌 Last nightly tag: $last_nightly"
# 对比指定目录是否有变更
changes=$(git diff --name-only "$last_nightly"..HEAD -- package.json src/ packages/ apps/desktop/)
if [ -z "$changes" ]; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "⏭️ No code changes since $last_nightly, skipping nightly build"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
change_count=$(echo "$changes" | wc -l | tr -d ' ')
echo "✅ ${change_count} file(s) changed since $last_nightly:"
echo "$changes" | head -20
[ "$change_count" -gt 20 ] && echo " ... and $((change_count - 20)) more"
fi
- name: Calculate nightly version
if: steps.changes.outputs.has_changes == 'true'
id: version
run: |
# 获取最新的 tag (排除 nightly tag)
latest_tag=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
if [ -z "$latest_tag" ]; then
echo "❌ No stable tag found"
exit 1
fi
echo "📌 Latest stable tag: $latest_tag"
# 去掉 v 前缀
base_version="${latest_tag#v}"
# 解析 major.minor.patch
IFS='.' read -r major minor patch <<< "$base_version"
# minor + 1, patch 归零
new_minor=$((minor + 1))
timestamp=$(date -u +"%Y%m%d%H%M")
version="${major}.${new_minor}.0-nightly.${timestamp}"
tag="v${version}"
echo "version=${version}" >> $GITHUB_OUTPUT
echo "tag=${tag}" >> $GITHUB_OUTPUT
echo "✅ Nightly version: ${version}"
echo "🏷️ Tag: ${tag}"
# ============================================
# 代码质量检查
# ============================================
test:
name: Code quality check
needs: [calculate-version]
if: needs.calculate-version.outputs.has_changes == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout base
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install deps
run: bun i
- name: Lint
run: bun run lint
# ============================================
# 多平台构建
# ============================================
build:
needs: [calculate-version, test]
if: needs.calculate-version.outputs.has_changes == 'true'
name: Build Desktop App
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-15, macos-15-intel, windows-2025, ubuntu-latest]
steps:
- uses: actions/checkout@v6
- name: Setup build environment
uses: ./.github/actions/desktop-build-setup
with:
node-version: ${{ env.NODE_VERSION }}
- name: Set package version
run: npm run workflow:set-desktop-version ${{ needs.calculate-version.outputs.version }} nightly
# macOS 构建前清理 (修复 hdiutil 问题 https://github.com/electron-userland/electron-builder/issues/8415)
- name: Clean previous build artifacts (macOS)
if: runner.os == 'macOS'
run: |
sudo rm -rf apps/desktop/release || true
sudo rm -rf apps/desktop/dist || true
sudo rm -rf /tmp/electron-builder* || true
# macOS 构建
- name: Build artifact on macOS
if: runner.os == 'macOS'
run: npm run desktop:package:app
env:
UPDATE_CHANNEL: nightly
UPDATE_SERVER_URL: ${{ secrets.UPDATE_SERVER_URL }}
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
CSC_LINK: ${{ secrets.APPLE_CERTIFICATE_BASE64 }}
CSC_KEY_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
CSC_FOR_PULL_REQUEST: true
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ secrets.UMAMI_BETA_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ secrets.UMAMI_BETA_DESKTOP_BASE_URL }}
# Windows 构建
- name: Build artifact on Windows
if: runner.os == 'Windows'
run: npm run desktop:package:app
env:
UPDATE_CHANNEL: nightly
UPDATE_SERVER_URL: ${{ secrets.UPDATE_SERVER_URL }}
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ secrets.UMAMI_BETA_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ secrets.UMAMI_BETA_DESKTOP_BASE_URL }}
TEMP: C:\temp
TMP: C:\temp
# Linux 构建
- name: Build artifact on Linux
if: runner.os == 'Linux'
run: npm run desktop:package:app
env:
UPDATE_CHANNEL: nightly
UPDATE_SERVER_URL: ${{ secrets.UPDATE_SERVER_URL }}
APP_URL: http://localhost:3015
DATABASE_URL: 'postgresql://postgres@localhost:5432/postgres'
KEY_VAULTS_SECRET: 'oLXWIiR/AKF+rWaqy9lHkrYgzpATbW3CtJp3UfkVgpE='
NEXT_PUBLIC_DESKTOP_PROJECT_ID: ${{ secrets.UMAMI_BETA_DESKTOP_PROJECT_ID }}
NEXT_PUBLIC_DESKTOP_UMAMI_BASE_URL: ${{ secrets.UMAMI_BETA_DESKTOP_BASE_URL }}
- name: Upload artifacts
uses: ./.github/actions/desktop-upload-artifacts
with:
artifact-name: release-${{ matrix.os }}
retention-days: 3
# ============================================
# 合并 macOS 多架构 latest-mac.yml 文件
# ============================================
merge-mac-files:
needs: [build]
name: Merge macOS Release Files
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Download artifacts
uses: actions/download-artifact@v7
with:
path: release
pattern: release-*
merge-multiple: true
- name: List downloaded artifacts
run: ls -R release
- name: Install yaml only for merge step
run: |
cd scripts/electronWorkflow
if [ ! -f package.json ]; then
echo '{"name":"merge-mac-release","private":true}' > package.json
fi
bun add --no-save yaml@2.8.1
- name: Merge latest-mac.yml files
run: bun run scripts/electronWorkflow/mergeMacReleaseFiles.js
- name: Upload artifacts with merged macOS files
uses: actions/upload-artifact@v6
with:
name: merged-release
path: release/
retention-days: 1
# ============================================
# 创建 Nightly Release
# ============================================
publish-release:
needs: [merge-mac-files, calculate-version]
name: Publish Nightly Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download merged artifacts
uses: actions/download-artifact@v7
with:
name: merged-release
path: release
- name: List final artifacts
run: ls -R release
- name: Create Nightly Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.calculate-version.outputs.tag }}
name: 'Desktop Nightly ${{ needs.calculate-version.outputs.tag }}'
prerelease: true
body: |
## 🌙 Nightly Build — ${{ needs.calculate-version.outputs.tag }}
> Automated nightly build from `main` branch.
### ⚠️ Important Notes
- **This is an automated nightly build and is NOT intended for production use.**
- Nightly builds are generated from the latest `main` branch and may contain **unstable, untested, or incomplete features**.
- **No guarantees** are made regarding stability, data integrity, or backward compatibility.
- Bugs, crashes, and breaking changes are expected. **Use at your own risk.**
- **Do NOT report bugs** from nightly builds unless you can reproduce them on the latest beta or stable release.
- Nightly builds may have **different update channels** — they will not auto-update to/from stable or beta versions.
- It is strongly recommended to **back up your data** before using a nightly build.
### 📦 Installation
Download the appropriate installer for your platform from the assets below.
| Platform | File |
|----------|------|
| macOS (Apple Silicon) | `.dmg` (arm64) |
| macOS (Intel) | `.dmg` (x64) |
| Windows | `.exe` |
| Linux | `.AppImage` / `.deb` |
files: |
release/latest*
release/*.dmg*
release/*.zip*
release/*.exe*
release/*.AppImage
release/*.deb*
release/*.snap*
release/*.rpm*
release/*.tar.gz*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ============================================
# 发布到 S3 更新服务器
# ============================================
publish-s3:
needs: [merge-mac-files, calculate-version]
name: Publish to S3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/desktop-publish-s3
with:
channel: nightly
version: ${{ needs.calculate-version.outputs.version }}
aws-access-key-id: ${{ secrets.UPDATE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.UPDATE_AWS_SECRET_ACCESS_KEY }}
s3-bucket: ${{ secrets.UPDATE_S3_BUCKET }}
s3-region: ${{ secrets.UPDATE_S3_REGION }}
s3-endpoint: ${{ secrets.UPDATE_S3_ENDPOINT }}
# ============================================
# 清理旧的 Nightly Releases (保留最近 7 个)
# ============================================
cleanup-old-nightlies:
needs: [publish-release, publish-s3]
name: Cleanup Old Nightly Releases
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v6
- name: Delete old nightly GitHub releases
uses: actions/github-script@v7
with:
script: |
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const nightlyReleases = releases
.filter(r => r.tag_name.includes('-nightly.'))
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
const toDelete = nightlyReleases.slice(7);
for (const release of toDelete) {
console.log(`🗑️ Deleting old nightly release: ${release.tag_name}`);
// Delete the release
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.id,
});
// Delete the tag
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${release.tag_name}`,
});
} catch (e) {
console.log(`⚠️ Could not delete tag ${release.tag_name}: ${e.message}`);
}
}
console.log(`✅ Cleanup complete. Kept ${Math.min(nightlyReleases.length, 7)} nightly releases, deleted ${toDelete.length}.`);
- name: Cleanup old S3 versions
uses: ./.github/actions/desktop-cleanup-s3
with:
channel: nightly
keep-count: '15'
aws-access-key-id: ${{ secrets.UPDATE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.UPDATE_AWS_SECRET_ACCESS_KEY }}
s3-bucket: ${{ secrets.UPDATE_S3_BUCKET }}
s3-region: ${{ secrets.UPDATE_S3_REGION }}
s3-endpoint: ${{ secrets.UPDATE_S3_ENDPOINT }}
+2 -8
View File
@@ -266,16 +266,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
- name: Setup environment
uses: ./.github/actions/setup-env
with:
node-version: ${{ env.NODE_VERSION }}
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Download artifacts
uses: actions/download-artifact@v7
+89
View File
@@ -0,0 +1,89 @@
name: Release ModelBank
permissions:
contents: write
id-token: write
on:
push:
branches:
- canary
paths:
- packages/model-bank/**
workflow_dispatch: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build ModelBank
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install dependencies
run: pnpm install
- name: Build package
run: pnpm --filter model-bank build
publish:
name: Publish ModelBank
if: ${{ github.event_name == 'workflow_dispatch' }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
registry-url: https://registry.npmjs.org
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install dependencies
run: pnpm install
- name: Bump patch version
id: version
run: |
npm version patch --no-git-tag-version --prefix packages/model-bank
echo "version=$(node -p 'require(\"./packages/model-bank/package.json\").version')" >> "$GITHUB_OUTPUT"
- name: Build package
run: pnpm --filter model-bank build
- name: Publish to npm
run: npm publish --provenance
working-directory: packages/model-bank
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Commit version bump
env:
MODEL_BANK_VERSION: ${{ steps.version.outputs.version }}
run: |
git config user.name "lobehubbot"
git config user.email "i@lobehub.com"
git add packages/model-bank/package.json
git commit -m "🔖 chore(model-bank): release v${MODEL_BANK_VERSION}"
git push
+3 -11
View File
@@ -37,19 +37,11 @@ jobs:
with:
token: ${{ secrets.GH_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
- name: Lint
run: bun run lint
+4 -6
View File
@@ -15,15 +15,13 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ secrets.BUN_VERSION }}
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
- name: sync database schema to dbdocs
env:
DBDOCS_TOKEN: ${{ secrets.DBDOCS_TOKEN }}
run: npm run db:visualize
run: bun run db:visualize
+14 -46
View File
@@ -37,19 +37,11 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ secrets.BUN_VERSION }}
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
- name: Test packages with coverage
run: |
@@ -111,19 +103,11 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
package-manager-cache: false
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
- name: Run tests
run: bunx vitest --coverage --silent='passed-only' --reporter=default --reporter=blob --shard=${{ matrix.shard }}/2
@@ -146,13 +130,11 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: bun i
run: pnpm install
- name: Download blob reports
uses: actions/download-artifact@v7
@@ -181,16 +163,8 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
package-manager-cache: false
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: pnpm install
@@ -235,20 +209,14 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.11.1
package-manager-cache: false
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Install deps
run: pnpm i
- name: Lint
run: npm run lint
run: bun run lint
- name: Test Coverage
run: pnpm --filter @lobechat/database test:coverage
+13 -1
View File
@@ -25,6 +25,9 @@ Desktop.ini
*.code-workspace
.vscode/sessions.json
prd
# Recordings
.records/
# Temporary files
.temp/
temp/
@@ -52,6 +55,7 @@ bun.lockb
# Build outputs
dist/
public/_spa/
public/spa/
es/
lib/
@@ -134,4 +138,12 @@ i18n-unused-keys-report.json
pnpm-lock.yaml
.turbo
spaHtmlTemplates.ts
spaHtmlTemplates.ts
# Embedded CLI bundle (built at pack time)
apps/desktop/resources/bin/lobe-cli.js
apps/desktop/resources/cli-package.json
# Superpowers plugin brainstorm/spec outputs (local only; do not commit)
.superpowers/
docs/superpowers/
+4 -4
View File
@@ -1,6 +1,6 @@
const { defineConfig } = require('@lobehub/i18n-cli');
const fs = require('fs');
const path = require('path');
const fs = require('node:fs');
const path = require('node:path');
module.exports = defineConfig({
entry: 'locales/en-US',
@@ -27,14 +27,14 @@ module.exports = defineConfig({
],
temperature: 0,
saveImmediately: true,
modelName: 'chatgpt-4o-latest',
modelName: 'gpt-5.1-chat-latest',
experimental: {
jsonMode: true,
},
markdown: {
reference:
'You need to maintain the component format of the mdx file; the output text does not need to be wrapped in any code block syntax on the outermost layer.\n' +
fs.readFileSync(path.join(__dirname, 'docs/glossary.md'), 'utf-8'),
fs.readFileSync(path.join(__dirname, 'docs/glossary.md'), 'utf8'),
entry: ['./README.md', './docs/**/*.md', './docs/**/*.mdx'],
entryLocale: 'en-US',
outputLocales: ['zh-CN'],
+6 -4
View File
@@ -6,7 +6,11 @@
},
"editor.formatOnSave": true,
// don't show errors, but fix when save and git pre commit
"eslint.rules.customizations": [],
"eslint.rules.customizations": [
{ "rule": "simple-import-sort/exports", "severity": "off" },
{ "rule": "perfectionist/sort-interfaces", "severity": "off" },
{ "rule": "simple-import-sort/imports", "severity": "off" }
],
"eslint.validate": [
"json",
"javascript",
@@ -16,7 +20,7 @@
// support mdx
"mdx"
],
"mdx.server.enable": false,
"js/ts.tsdk.path": "node_modules/typescript/lib",
"npm.packageManager": "pnpm",
"search.exclude": {
"**/node_modules": true,
@@ -44,9 +48,7 @@
// make stylelint work with tsx antd-style css template string
"typescriptreact"
],
"typescript.tsdk": "node_modules/typescript/lib",
"vitest.disableWorkspaceWarning": true,
"vitest.maximumConfigs": 10,
"workbench.editor.customLabels.patterns": {
"**/app/**/[[]*[]]/[[]*[]]/page.tsx": "${dirname(2)}/${dirname(1)}/${dirname} • page component",
"**/app/**/[[]*[]]/page.tsx": "${dirname(1)}/${dirname} • page component",
+3 -1
View File
@@ -47,6 +47,7 @@ lobehub/
- Git commit messages should prefix with gitmoji
- Git branch name format: `feat/feature-name`
- Use `.github/PULL_REQUEST_TEMPLATE.md` for PR descriptions
- **Protection of local changes**: Never use `git restore`, `git checkout --`, `git reset --hard`, or any other command or workflow that can forcibly overwrite, discard, or silently replace user-owned uncommitted changes. Before any revert or restoration affecting existing files, inspect the working tree carefully and obtain explicit user confirmation.
### Package Management
@@ -89,7 +90,8 @@ cd packages/[package-name] && bunx vitest run --silent='passed-only' '[file-path
- **`src/routes/`** holds only page segments (`_layout/index.tsx`, `index.tsx`, `[id]/index.tsx`). Keep route files **thin** — import from `@/features/*` and compose, no business logic.
- **`src/features/`** holds business components by **domain** (e.g. `Pages`, `PageEditor`, `Home`). Layout pieces, hooks, and domain UI go here.
- See the **spa-routes** skill for the full convention and file-division rules.
- **Desktop router parity:** When changing the main SPA route tree, update **both** `src/spa/router/desktopRouter.config.tsx` (dynamic imports) and `src/spa/router/desktopRouter.config.desktop.tsx` (sync imports) so paths and nesting match. Changing only one can leave routes unregistered and cause **blank screens**.
- See the **spa-routes** skill (`.agents/skills/spa-routes/SKILL.md`) for the full convention and file-division rules.
## Skills (Auto-loaded)
+94
View File
@@ -2,6 +2,100 @@
# Changelog
## [Version 2.1.51](https://github.com/lobehub/lobe-chat/compare/v0.0.0-nightly.pr13850.8503...v2.1.51)
<sup>Released on **2026-04-16**</sup>
#### 👷 Build System
- **database**: add document history schema.
- **database**: add document history schema.
#### 🐛 Bug Fixes
- **misc**: fix minify cli.
- **misc**: recent delete.
- **deps**: pin @react-pdf/image to 3.0.4 to avoid privatized @react-pdf/svg.
- **database**: enforce document history ownership and pagination.
#### ✨ Features
- **database**: add document history table and update related models.
<br/>
<details>
<summary><kbd>Improvements and Fixes</kbd></summary>
#### Build System
- **database**: add document history schema, closes [#13789](https://github.com/lobehub/lobe-chat/issues/13789) ([c1174d3](https://github.com/lobehub/lobe-chat/commit/c1174d3))
- **database**: add document history schema ([e3eef04](https://github.com/lobehub/lobe-chat/commit/e3eef04))
#### What's fixed
- **misc**: fix minify cli, closes [#13888](https://github.com/lobehub/lobe-chat/issues/13888) ([cb4ad01](https://github.com/lobehub/lobe-chat/commit/cb4ad01))
- **misc**: recent delete, closes [#13878](https://github.com/lobehub/lobe-chat/issues/13878) ([85227cf](https://github.com/lobehub/lobe-chat/commit/85227cf))
- **deps**: pin @react-pdf/image to 3.0.4 to avoid privatized @react-pdf/svg ([d526b40](https://github.com/lobehub/lobe-chat/commit/d526b40))
- **database**: enforce document history ownership and pagination ([b9c4b87](https://github.com/lobehub/lobe-chat/commit/b9c4b87))
#### What's improved
- **database**: add document history table and update related models ([64fc6d4](https://github.com/lobehub/lobe-chat/commit/64fc6d4))
</details>
<div align="right">
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
</div>
## [Version 2.1.50](https://github.com/lobehub/lobe-chat/compare/v2.1.49...v2.1.50)
<sup>Released on **2026-04-16**</sup>
#### 👷 Build System
- **database**: add document history schema.
- **database**: add document history schema.
#### 🐛 Bug Fixes
- **deps**: pin @react-pdf/image to 3.0.4 to avoid privatized @react-pdf/svg.
- **database**: enforce document history ownership and pagination.
#### ✨ Features
- **database**: add document history table and update related models.
<br/>
<details>
<summary><kbd>Improvements and Fixes</kbd></summary>
#### Build System
- **database**: add document history schema, closes [#13789](https://github.com/lobehub/lobe-chat/issues/13789) ([c1174d3](https://github.com/lobehub/lobe-chat/commit/c1174d3))
- **database**: add document history schema ([e3eef04](https://github.com/lobehub/lobe-chat/commit/e3eef04))
#### What's fixed
- **deps**: pin @react-pdf/image to 3.0.4 to avoid privatized @react-pdf/svg ([d526b40](https://github.com/lobehub/lobe-chat/commit/d526b40))
- **database**: enforce document history ownership and pagination ([b9c4b87](https://github.com/lobehub/lobe-chat/commit/b9c4b87))
#### What's improved
- **database**: add document history table and update related models ([64fc6d4](https://github.com/lobehub/lobe-chat/commit/64fc6d4))
</details>
<div align="right">
[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
</div>
### [Version 2.1.45](https://github.com/lobehub/lobe-chat/compare/v2.1.44...v2.1.45)
<sup>Released on **2026-03-26**</sup>
+2 -1
View File
@@ -6,7 +6,7 @@ Guidelines for using Claude Code in this LobeHub repository.
- Next.js 16 + React 19 + TypeScript
- SPA inside Next.js with `react-router-dom`
- `@lobehub/ui`, antd for components; antd-style for CSS-in-JS
- `@lobehub/ui`, antd for components; antd-style for CSS-in-JS**prefer `createStaticStyles` with `cssVar.*`** (zero-runtime); only fall back to `createStyles` + `token` when styles genuinely need runtime computation. See `.cursor/docs/createStaticStyles_migration_guide.md`.
- react-i18next for i18n; zustand for state management
- SWR for data fetching; TRPC for type-safe backend
- Drizzle ORM with PostgreSQL; Vitest for testing
@@ -60,6 +60,7 @@ When adding or changing SPA routes:
1. In `src/routes/`, add only the route segment files (layout + page) that delegate to features.
2. Implement layout and page content under `src/features/<Domain>/` and export from there.
3. In route files, use `import { X } from '@/features/<Domain>'` (or `import Y from '@/features/<Domain>/...'`). Do not add new `features/` folders inside `src/routes/`.
4. **Register the desktop route tree in both configs:** `src/spa/router/desktopRouter.config.tsx` and `src/spa/router/desktopRouter.config.desktop.tsx` must stay in sync (same paths and nesting). Updating only one can cause **blank screens** if the other build path expects the route.
See the **spa-routes** skill (`.agents/skills/spa-routes/SKILL.md`) for the full convention and file-division rules.
+7 -7
View File
@@ -1,8 +1,8 @@
# Lobe Chat - Contributing Guide 🌟
# LobeHub - Contributing Guide 🌟
We're thrilled that you want to contribute to Lobe Chat, the future of communication! 😄
We're thrilled that you want to contribute to LobeHub, the future of communication! 😄
Lobe Chat is an open-source project, and we welcome your collaboration. Before you jump in, let's make sure you're all set to contribute effectively and have loads of fun along the way!
LobeHub is an open-source project, and we welcome your collaboration. Before you jump in, let's make sure you're all set to contribute effectively and have loads of fun along the way!
## Table of Contents
@@ -69,11 +69,11 @@ git fetch upstream
git merge upstream/main
```
This ensures you're working on the most current version of Lobe Chat. Stay fresh! 💨
This ensures you're working on the most current version of LobeHub. Stay fresh! 💨
## Open a Pull Request
🚀 Time to share your contribution! Head over to the original Lobe Chat repository and open a Pull Request (PR). Our maintainers will review your work.
🚀 Time to share your contribution! Head over to the original LobeHub repository and open a Pull Request (PR). Our maintainers will review your work.
## Review and Collaboration
@@ -81,8 +81,8 @@ This ensures you're working on the most current version of Lobe Chat. Stay fresh
## Celebrate 🎉
🎈 Congratulations! Your contribution is now part of Lobe Chat. 🥳
🎈 Congratulations! Your contribution is now part of LobeHub. 🥳
Thank you for making Lobe Chat even more magical. We can't wait to see what you create! 🌠
Thank you for making LobeHub even more magical. We can't wait to see what you create! 🌠
Happy Coding! 🚀🦄
+1 -1
View File
@@ -111,7 +111,7 @@ COPY --from=base /distroless/ /
COPY --from=builder /app/.next/standalone /app/
COPY --from=builder /app/.next/static /app/.next/static
# Copy SPA assets (Vite build output)
COPY --from=builder /app/public/spa /app/public/spa
COPY --from=builder /app/public/_spa /app/public/_spa
# Copy database migrations
COPY --from=builder /app/packages/database/migrations /app/migrations
COPY --from=builder /app/scripts/migrateServerDB/docker.cjs /app/docker.cjs
+81
View File
@@ -0,0 +1,81 @@
# Security Policy
## Supported Versions
We only provide security fixes for the **latest 2.x release**. Older versions (including all 1.x releases) are end-of-life and will not receive patches.
| Version | Supported |
| ------------ | --------- |
| 2.x (latest) | ✅ |
| 1.x | ❌ |
| 0.x | ❌ |
If you are running a 1.x deployment, we strongly recommend upgrading to the latest 2.x release.
## Reporting a Vulnerability
Please report security vulnerabilities through the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/lobehub/lobehub/security/advisories/new) tab.
**Please do not report security vulnerabilities through public GitHub issues.**
### Response Timeline
- **Acknowledgement**: We aim to respond to all reports within **7 days**.
- **Fix**: Confirmed vulnerabilities will be addressed within **30 days**.
- **Urgent issues**: If you believe the vulnerability is critical and actively exploitable, you can reach out directly on Discord (`arvinxu`) for faster coordination.
### What to Include
A good vulnerability report should include:
- A clear description of the issue and its potential impact
- The affected version (must be the latest 2.x release)
- Step-by-step reproduction instructions or a working PoC
- Any relevant logs, screenshots, or code references
## Scope
### In Scope
- Security issues affecting the **latest 2.x release** of LobeHub
- Vulnerabilities in the **server-side deployment** (LobeHub Cloud or self-hosted server mode)
- Issues that can be exploited **without requiring admin/owner access** to the deployment
### Out of Scope (Not a Vulnerability)
The following are considered **by design** or **out of scope** and will not be accepted as vulnerability reports:
#### 1. End-of-Life Versions
Any issue that only affects 1.x or earlier versions. This includes but is not limited to the `X-lobe-chat-auth` header mechanism, `webapi` route authentication, and other 1.x-specific architectures that have been completely removed in 2.x.
#### 2. File Proxy Public Access (`/f/:id`)
The file proxy endpoint `/f/:id` uses randomly generated, non-enumerable IDs as [capability URLs](https://www.w3.org/TR/capability-urls/). This is a deliberate design choice, similar to how S3 presigned URLs or Google Docs sharing links work. Knowing the URL grants access — this is by design, not an authorization bypass.
#### 3. User Enumeration on Login Flows
Endpoints such as `check-user` that indicate whether an account exists are part of the standard login UX. This is a common and intentional pattern used by most modern authentication flows.
#### 4. Self-Hosted Client-Side API Key Storage
In self-hosted client-side mode, users configure their own API keys which are stored in the browser's local storage. This is the expected behavior for client-side deployments where the user is both the operator and the consumer.
#### 5. Issues Requiring Admin or Owner Privileges
Actions that require administrative access to the deployment (e.g., environment variable configuration, server-side settings) are not considered security vulnerabilities, as the admin is already a trusted party.
#### 6. Theoretical Attacks Without Practical Impact
Reports based on theoretical attack scenarios without a working proof of concept against a realistic deployment, or issues that require unlikely preconditions (e.g., physical access to the server, pre-existing compromise of the host system).
## Disclosure Policy
- We follow [coordinated vulnerability disclosure](https://en.wikipedia.org/wiki/Coordinated_vulnerability_disclosure).
- We will credit reporters in the security advisory unless they prefer to remain anonymous.
- Please allow us reasonable time to address the issue before any public disclosure.
## Contact
- **Primary**: [GitHub Security Advisories](https://github.com/lobehub/lobehub/security/advisories/new)
- **Urgent**: Discord — `arvinxu`
+11
View File
@@ -15,6 +15,17 @@ LobeHub command-line interface.
- To make `lh` available in your shell, run `bun run cli:link`.
- After linking, if your shell still cannot find `lh`, run `rehash` in `zsh`.
## Custom Server URL
By default the CLI connects to `https://app.lobehub.com`. To point it at a different server (e.g. a local instance):
| Method | Command | Persistence |
| -------------------- | --------------------------------------------------------------- | ----------------------------------- |
| Environment variable | `LOBEHUB_SERVER=http://localhost:4000 bun run dev -- <command>` | Current command only |
| Login flag | `lh login --server http://localhost:4000` | Saved to `~/.lobehub/settings.json` |
Priority: `LOBEHUB_SERVER` env var > `settings.json` > default official URL.
## Shell Completion
### Install completion for a linked CLI
+11 -2
View File
@@ -1,6 +1,6 @@
.\" Code generated by `npm run man:generate`; DO NOT EDIT.
.\" Manual command details come from the Commander command tree.
.TH LH 1 "" "@lobehub/cli 0.0.1\-canary.12" "User Commands"
.TH LH 1 "" "@lobehub/cli 0.0.8" "User Commands"
.SH NAME
lh \- LobeHub CLI \- manage and connect to LobeHub services
.SH SYNOPSIS
@@ -27,7 +27,7 @@ For command-specific manuals, use the built-in manual command:
.SH COMMANDS
.TP
.B login
Log in to LobeHub via browser (Device Code Flow)
Log in to LobeHub via browser (Device Code Flow) or configure API key server
.TP
.B logout
Log out and remove stored credentials
@@ -83,6 +83,9 @@ Manage agent skills
.B session\-group
Manage agent session groups
.TP
.B task
Manage agent tasks
.TP
.B thread
Manage message threads
.TP
@@ -95,6 +98,9 @@ Manage messages
.B model
Manage AI models
.TP
.B notify
Send a callback message to a topic and trigger the agent to process it
.TP
.B provider
Manage AI providers
.TP
@@ -112,6 +118,9 @@ View usage statistics
.TP
.B eval
Manage evaluation workflows
.TP
.B migrate
Migrate data from external tools (OpenClaw, ChatGPT, Claude, etc.)
.SH OPTIONS
.TP
.B \-V, \-\-version
+3 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@lobehub/cli",
"version": "0.0.1-canary.14",
"version": "0.0.8",
"type": "module",
"bin": {
"lh": "./dist/index.js",
@@ -28,6 +28,7 @@
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@lobechat/agent-gateway-client": "workspace:*",
"@lobechat/device-gateway-client": "workspace:*",
"@lobechat/local-file-shell": "workspace:*",
"@trpc/client": "^11.8.1",
@@ -37,6 +38,7 @@
"debug": "^4.4.0",
"diff": "^8.0.3",
"fast-glob": "^3.3.3",
"ignore": "^7.0.5",
"picocolors": "^1.1.1",
"superjson": "^2.2.6",
"tsdown": "^0.21.4",
+1
View File
@@ -1,4 +1,5 @@
packages:
- '../../packages/agent-gateway-client'
- '../../packages/device-gateway-client'
- '../../packages/local-file-shell'
- '../../packages/file-loaders'
+3 -1
View File
@@ -39,7 +39,9 @@ async function getAuthAndServer() {
const result = await getValidToken();
if (!result) {
log.error(`No authentication found. Run 'lh login' first, or set ${CLI_API_KEY_ENV}.`);
log.error(
`No authentication found. Run 'lh login' (or 'npx -y @lobehub/cli login') first, or set ${CLI_API_KEY_ENV}.`,
);
process.exit(1);
}
+63 -22
View File
@@ -3,29 +3,9 @@ import { CLI_API_KEY_ENV } from '../constants/auth';
import { resolveServerUrl } from '../settings';
import { log } from '../utils/logger';
// Must match the server's SECRET_XOR_KEY (src/envs/auth.ts)
const SECRET_XOR_KEY = 'LobeHub · LobeHub';
/**
* XOR-obfuscate a payload and encode as Base64.
* The /webapi/* routes require `X-lobe-chat-auth` with this encoding.
*/
function obfuscatePayloadWithXOR(payload: Record<string, any>): string {
const jsonString = JSON.stringify(payload);
const dataBytes = new TextEncoder().encode(jsonString);
const keyBytes = new TextEncoder().encode(SECRET_XOR_KEY);
const result = new Uint8Array(dataBytes.length);
for (let i = 0; i < dataBytes.length; i++) {
result[i] = dataBytes[i] ^ keyBytes[i % keyBytes.length];
}
return btoa(String.fromCharCode(...result));
}
export interface AuthInfo {
accessToken: string;
/** Headers required for /webapi/* endpoints (includes both X-lobe-chat-auth and Oidc-Auth) */
/** Headers required for /webapi/* endpoints (Oidc-Auth for authentication) */
headers: Record<string, string>;
serverUrl: string;
}
@@ -52,8 +32,69 @@ export async function getAuthInfo(): Promise<AuthInfo> {
headers: {
'Content-Type': 'application/json',
'Oidc-Auth': accessToken,
'X-lobe-chat-auth': obfuscatePayloadWithXOR({}),
},
serverUrl,
};
}
export type AgentStreamTokenType = 'jwt' | 'apiKey';
export interface AgentStreamAuthInfo {
headers: Record<string, string>;
serverUrl: string;
/**
* Raw token value (without header prefix). Used for WebSocket auth messages
* where header-based auth is not available.
*/
token: string;
/**
* How the token should be verified by downstream services (agent gateway WS).
* jwt → validate with JWKS
* apiKey → validate by calling /api/v1/users/me
*/
tokenType: AgentStreamTokenType;
}
export async function getAgentStreamAuthInfo(): Promise<AgentStreamAuthInfo> {
const serverUrl = resolveServerUrl();
const envJwt = process.env.LOBEHUB_JWT;
if (envJwt) {
return {
headers: { 'Oidc-Auth': envJwt },
serverUrl,
token: envJwt,
tokenType: 'jwt',
};
}
const envApiKey = process.env[CLI_API_KEY_ENV];
if (envApiKey) {
return {
headers: { 'X-API-Key': envApiKey },
serverUrl,
token: envApiKey,
tokenType: 'apiKey',
};
}
const result = await getValidToken();
if (!result) {
log.error(`No authentication found. Run 'lh login' first, or set ${CLI_API_KEY_ENV}.`);
process.exit(1);
return {
headers: {},
serverUrl,
token: '',
tokenType: 'jwt',
};
}
return {
headers: { 'Oidc-Auth': result.credentials.accessToken },
serverUrl,
token: result.credentials.accessToken,
tokenType: 'jwt',
};
}
+199 -7
View File
@@ -27,6 +27,9 @@ const { mockTrpcClient } = vi.hoisted(() => ({
execAgent: { mutate: vi.fn() },
getOperationStatus: { query: vi.fn() },
},
device: {
listDevices: { query: vi.fn() },
},
},
}));
@@ -38,13 +41,18 @@ const { mockStreamAgentEvents } = vi.hoisted(() => ({
mockStreamAgentEvents: vi.fn(),
}));
const { mockGetAuthInfo } = vi.hoisted(() => ({
mockGetAuthInfo: vi.fn(),
const { mockGetAgentStreamAuthInfo } = vi.hoisted(() => ({
mockGetAgentStreamAuthInfo: vi.fn(),
}));
const { mockResolveLocalDeviceId } = vi.hoisted(() => ({
mockResolveLocalDeviceId: vi.fn(),
}));
vi.mock('../api/client', () => ({ getTrpcClient: mockGetTrpcClient }));
vi.mock('../api/http', () => ({ getAuthInfo: mockGetAuthInfo }));
vi.mock('../api/http', () => ({ getAgentStreamAuthInfo: mockGetAgentStreamAuthInfo }));
vi.mock('../utils/agentStream', () => ({ streamAgentEvents: mockStreamAgentEvents }));
vi.mock('../utils/device', () => ({ resolveLocalDeviceId: mockResolveLocalDeviceId }));
vi.mock('../utils/logger', () => ({
log: { debug: vi.fn(), error: vi.fn(), heartbeat: vi.fn(), info: vi.fn(), warn: vi.fn() },
setVerbose: vi.fn(),
@@ -58,12 +66,12 @@ describe('agent command', () => {
exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => {}) as any);
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
mockGetTrpcClient.mockResolvedValue(mockTrpcClient);
mockGetAuthInfo.mockResolvedValue({
accessToken: 'test-token',
headers: { 'Content-Type': 'application/json', 'Oidc-Auth': 'test-token' },
mockGetAgentStreamAuthInfo.mockResolvedValue({
headers: { 'Oidc-Auth': 'test-token' },
serverUrl: 'https://example.com',
});
mockStreamAgentEvents.mockResolvedValue(undefined);
mockResolveLocalDeviceId.mockReset();
for (const method of Object.values(mockTrpcClient.agent)) {
for (const fn of Object.values(method)) {
(fn as ReturnType<typeof vi.fn>).mockReset();
@@ -74,6 +82,11 @@ describe('agent command', () => {
(fn as ReturnType<typeof vi.fn>).mockReset();
}
}
for (const method of Object.values(mockTrpcClient.device)) {
for (const fn of Object.values(method)) {
(fn as ReturnType<typeof vi.fn>).mockReset();
}
}
});
afterEach(() => {
@@ -297,7 +310,6 @@ describe('agent command', () => {
expect.objectContaining({ json: undefined, verbose: undefined }),
);
});
it('should support --slug option', async () => {
mockTrpcClient.aiAgent.execAgent.mutate.mockResolvedValue({
operationId: 'op-456',
@@ -384,6 +396,186 @@ describe('agent command', () => {
);
});
it('should pass --device local as deviceId', async () => {
mockResolveLocalDeviceId.mockReturnValue('local-device-1');
mockTrpcClient.device.listDevices.query.mockResolvedValue([
{ deviceId: 'local-device-1', online: true },
]);
mockTrpcClient.aiAgent.execAgent.mutate.mockResolvedValue({
operationId: 'op-device',
success: true,
});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--device',
'local',
]);
expect(mockTrpcClient.aiAgent.execAgent.mutate).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'a1', deviceId: 'local-device-1', prompt: 'Hi' }),
);
});
it('should pass --topic-id and --device local together', async () => {
mockResolveLocalDeviceId.mockReturnValue('local-device-1');
mockTrpcClient.device.listDevices.query.mockResolvedValue([
{ deviceId: 'local-device-1', online: true },
]);
mockTrpcClient.aiAgent.execAgent.mutate.mockResolvedValue({
operationId: 'op-topic-device',
success: true,
});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--topic-id',
't1',
'--device',
'local',
]);
expect(mockTrpcClient.aiAgent.execAgent.mutate).toHaveBeenCalledWith(
expect.objectContaining({ appContext: { topicId: 't1' }, deviceId: 'local-device-1' }),
);
});
it('should pass explicit --device id as deviceId', async () => {
mockTrpcClient.device.listDevices.query.mockResolvedValue([
{ deviceId: 'device-remote-1', online: true },
]);
mockTrpcClient.aiAgent.execAgent.mutate.mockResolvedValue({
operationId: 'op-explicit-device',
success: true,
});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--device',
'device-remote-1',
]);
expect(mockResolveLocalDeviceId).not.toHaveBeenCalled();
expect(mockTrpcClient.aiAgent.execAgent.mutate).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'a1', deviceId: 'device-remote-1', prompt: 'Hi' }),
);
});
it('should exit when explicit device is not found', async () => {
mockTrpcClient.device.listDevices.query.mockResolvedValue([
{ deviceId: 'other-device', online: true },
]);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--device',
'device-remote-1',
]);
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('was not found'));
expect(exitSpy).toHaveBeenCalledWith(1);
});
it('should exit when local device cannot be resolved', async () => {
mockResolveLocalDeviceId.mockReturnValue(undefined);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--device',
'local',
]);
expect(log.error).toHaveBeenCalledWith(expect.stringContaining("Run 'lh connect' first"));
expect(exitSpy).toHaveBeenCalledWith(1);
});
it('should exit when local device is offline', async () => {
mockResolveLocalDeviceId.mockReturnValue('local-device-1');
mockTrpcClient.device.listDevices.query.mockResolvedValue([
{ deviceId: 'local-device-1', online: false },
]);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--device',
'local',
]);
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('is not online'));
expect(exitSpy).toHaveBeenCalledWith(1);
});
it('should exit when explicit device is offline', async () => {
mockTrpcClient.device.listDevices.query.mockResolvedValue([
{ deviceId: 'device-remote-1', online: false },
]);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'agent',
'run',
'--agent-id',
'a1',
'--prompt',
'Hi',
'--device',
'device-remote-1',
]);
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('Bring it online'));
expect(exitSpy).toHaveBeenCalledWith(1);
});
it('should pass --json to stream options', async () => {
mockTrpcClient.aiAgent.execAgent.mutate.mockResolvedValue({
operationId: 'op-j',
+81 -9
View File
@@ -4,8 +4,14 @@ import type { Command } from 'commander';
import pc from 'picocolors';
import { getTrpcClient } from '../api/client';
import { getAuthInfo } from '../api/http';
import { replayAgentEvents, streamAgentEvents } from '../utils/agentStream';
import { getAgentStreamAuthInfo } from '../api/http';
import { resolveAgentGatewayUrl } from '../settings';
import {
replayAgentEvents,
streamAgentEvents,
streamAgentEventsViaWebSocket,
} from '../utils/agentStream';
import { resolveLocalDeviceId } from '../utils/device';
import { confirm, outputJson, printTable, truncate } from '../utils/format';
import { log, setVerbose } from '../utils/logger';
@@ -248,17 +254,29 @@ export function registerAgentCommand(program: Command) {
.option('-p, --prompt <text>', 'User prompt')
.option('-t, --topic-id <id>', 'Reuse an existing topic')
.option('--no-auto-start', 'Do not auto-start the agent')
.option(
'--device <target>',
'Target device ID, or use "local" for the current connected device',
)
.option(
'--no-headless',
"Disable headless mode and wait for human approval on tool calls (default: headless — tools auto-run, matching the CLI's non-interactive nature)",
)
.option('--json', 'Output full JSON event stream')
.option('-v, --verbose', 'Show detailed tool call info')
.option('--replay <file>', 'Replay events from a saved JSON file (offline)')
.option('--sse', 'Force SSE stream instead of WebSocket gateway')
.action(
async (options: {
agentId?: string;
autoStart?: boolean;
device?: string;
headless?: boolean;
json?: boolean;
prompt?: string;
replay?: string;
slug?: string;
sse?: boolean;
topicId?: string;
verbose?: boolean;
}) => {
@@ -285,12 +303,53 @@ export function registerAgentCommand(program: Command) {
const client = await getTrpcClient();
let deviceId: string | undefined;
if (options.device !== undefined) {
if (options.device === 'local') {
deviceId = resolveLocalDeviceId();
if (!deviceId) {
log.error(
"No local device found. Run 'lh connect' first, then retry with --device local.",
);
process.exit(1);
return;
}
} else {
deviceId = options.device;
}
const devices = await client.device.listDevices.query();
const matchedDevice = devices.find(
(device: { deviceId?: string; online?: boolean }) => device.deviceId === deviceId,
);
if (!matchedDevice) {
log.error(`Device "${deviceId}" was not found. Check 'lh device list' and try again.`);
process.exit(1);
return;
}
if (!matchedDevice.online) {
log.error(
options.device === 'local'
? `Local device "${deviceId}" is not online. Reconnect with 'lh connect' and try again.`
: `Device "${deviceId}" is not online. Bring it online and try again.`,
);
process.exit(1);
return;
}
}
// 1. Exec agent to get operationId
const input: Record<string, any> = { prompt: options.prompt };
if (options.agentId) input.agentId = options.agentId;
if (deviceId) input.deviceId = deviceId;
if (options.slug) input.slug = options.slug;
if (options.topicId) input.appContext = { topicId: options.topicId };
if (options.autoStart === false) input.autoStart = false;
// commander's --no-headless sets `headless` to false. Anything else
// (undefined, true) → headless mode is on and tool calls auto-execute.
if (options.headless !== false) {
input.userInterventionConfig = { approvalMode: 'headless' };
}
const result = await client.aiAgent.execAgent.mutate(input as any);
const r = result as any;
@@ -305,14 +364,27 @@ export function registerAgentCommand(program: Command) {
log.info(`Operation: ${pc.dim(operationId)} · Topic: ${pc.dim(r.topicId || 'n/a')}`);
}
// 2. Connect to SSE stream
const { serverUrl, headers } = await getAuthInfo();
const streamUrl = `${serverUrl}/api/agent/stream?operationId=${encodeURIComponent(operationId)}`;
// 2. Connect to stream (WebSocket via Gateway, or fallback to SSE)
const { serverUrl, headers, token, tokenType } = await getAgentStreamAuthInfo();
const agentGatewayUrl = options.sse ? undefined : resolveAgentGatewayUrl();
await streamAgentEvents(streamUrl, headers, {
json: options.json,
verbose: options.verbose,
});
if (agentGatewayUrl) {
await streamAgentEventsViaWebSocket({
gatewayUrl: agentGatewayUrl,
json: options.json,
operationId,
serverUrl,
token,
tokenType,
verbose: options.verbose,
});
} else {
const streamUrl = `${serverUrl}/api/agent/stream?operationId=${encodeURIComponent(operationId)}`;
await streamAgentEvents(streamUrl, headers, {
json: options.json,
verbose: options.verbose,
});
}
},
);
+242 -99
View File
@@ -1,39 +1,130 @@
import type { Command } from 'commander';
import pc from 'picocolors';
import type { TrpcClient } from '../api/client';
import { getTrpcClient } from '../api/client';
import { confirm, outputJson, printTable } from '../utils/format';
import { confirm, outputJson, printBoxTable, printTable, timeAgo } from '../utils/format';
import { log } from '../utils/logger';
import { registerBotMessageCommands } from './botMessage';
const SUPPORTED_PLATFORMS = ['discord', 'slack', 'telegram', 'lark', 'feishu', 'wechat'];
// ── Helpers ──────────────────────────────────────────────
const PLATFORM_CREDENTIAL_FIELDS: Record<string, string[]> = {
discord: ['botToken', 'publicKey'],
feishu: ['appSecret'],
lark: ['appSecret'],
slack: ['botToken', 'signingSecret'],
telegram: ['botToken'],
wechat: ['botToken', 'botId'],
function maskValue(val: string): string {
if (val.length > 8) return val.slice(0, 4) + '****' + val.slice(-4);
return '****';
}
function camelToFlag(name: string): string {
return '--' + name.replaceAll(/([A-Z])/g, '-$1').toLowerCase();
}
/** Extract credential field definitions from a platform schema. */
function getCredentialFields(platformDef: any): any[] {
const credSchema = (platformDef.schema ?? []).find(
(f: any) => f.key === 'credentials' && f.properties,
);
return credSchema?.properties ?? [];
}
/** Extract credential values from CLI options based on platform schema. */
function extractCredentials(
platformDef: any,
options: Record<string, any>,
): { credentials: Record<string, string>; missing: any[] } {
const fields = getCredentialFields(platformDef);
const credentials: Record<string, string> = {};
for (const field of fields) {
const value = options[field.key];
if (typeof value === 'string') {
credentials[field.key] = value;
}
}
const missing = fields.filter((f: any) => f.required && !credentials[f.key]);
return { credentials, missing };
}
/** Find a bot by ID from the user's bot list. */
async function findBot(client: TrpcClient, botId: string) {
const bots = await client.agentBotProvider.list.query();
const bot = (bots as any[]).find((b: any) => b.id === botId);
if (!bot) {
log.error(`Bot integration not found: ${botId}`);
process.exit(1);
}
return bot;
}
const STATUS_COLORS: Record<string, (s: string) => string> = {
connected: pc.green,
disconnected: pc.dim,
failed: pc.red,
queued: pc.yellow,
starting: pc.yellow,
unknown: pc.dim,
};
function parseCredentials(
platform: string,
options: Record<string, string | undefined>,
): Record<string, string> {
const creds: Record<string, string> = {};
if (options.botToken) creds.botToken = options.botToken;
if (options.botId) creds.botId = options.botId;
if (options.publicKey) creds.publicKey = options.publicKey;
if (options.signingSecret) creds.signingSecret = options.signingSecret;
if (options.appSecret) creds.appSecret = options.appSecret;
return creds;
/** Validate a platform ID and return its definition. */
async function resolvePlatform(client: TrpcClient, platformId: string) {
const platforms = await client.agentBotProvider.listPlatforms.query();
const def = (platforms as any[]).find((p: any) => p.id === platformId);
if (!def) {
const ids = (platforms as any[]).map((p: any) => p.id).join(', ');
log.error(`Invalid platform "${platformId}". Must be one of: ${ids}`);
log.info('Run `lh bot platforms` to see required credentials for each platform.');
process.exit(1);
}
return def;
}
// ── Command Registration ─────────────────────────────────
export function registerBotCommand(program: Command) {
const bot = program.command('bot').description('Manage bot integrations');
// Register message subcommand group
registerBotMessageCommands(bot);
// ── platforms ───────────────────────────────────────────
bot
.command('platforms')
.description('List supported platforms and their required credentials')
.option('--json', 'Output JSON')
.action(async (options: { json?: boolean }) => {
const client = await getTrpcClient();
const platforms = await client.agentBotProvider.listPlatforms.query();
if (options.json) {
outputJson(platforms);
return;
}
console.log(pc.bold('Supported platforms:\n'));
for (const p of platforms as any[]) {
console.log(` ${pc.bold(pc.cyan(p.id))}`);
if (p.name) console.log(` Name: ${p.name}`);
const fields = getCredentialFields(p);
const required = fields.filter((f: any) => f.required);
const optional = fields.filter((f: any) => !f.required);
if (required.length > 0) {
console.log(
` Required: ${required.map((f: any) => pc.yellow(camelToFlag(f.key))).join(', ')}`,
);
}
if (optional.length > 0) {
console.log(
` Optional: ${optional.map((f: any) => pc.dim(camelToFlag(f.key))).join(', ')}`,
);
}
console.log();
}
});
// ── list ──────────────────────────────────────────────
bot
@@ -63,15 +154,20 @@ export function registerBotCommand(program: Command) {
return;
}
const rows = items.map((b: any) => [
b.id || '',
b.platform || '',
b.applicationId || '',
b.agentId || '',
b.enabled ? pc.green('enabled') : pc.dim('disabled'),
]);
const rows = items.map((b: any) => {
const status = b.enabled ? (b.runtimeStatus ?? 'disconnected') : 'disabled';
const colorFn = STATUS_COLORS[status] ?? pc.dim;
return [
b.id || '',
b.platform || '',
b.applicationId || '',
b.agentId || '',
colorFn(status),
b.updatedAt ? timeAgo(b.updatedAt) : pc.dim('-'),
];
});
printTable(rows, ['ID', 'PLATFORM', 'APP ID', 'AGENT', 'STATUS']);
printTable(rows, ['ID', 'PLATFORM', 'APP ID', 'AGENT', 'STATUS', 'UPDATED']);
});
// ── view ──────────────────────────────────────────────
@@ -79,44 +175,62 @@ export function registerBotCommand(program: Command) {
bot
.command('view <botId>')
.description('View bot integration details')
.requiredOption('-a, --agent <agentId>', 'Agent ID')
.option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
.action(async (botId: string, options: { agent: string; json?: string | boolean }) => {
const client = await getTrpcClient();
const result = await client.agentBotProvider.getByAgentId.query({
agentId: options.agent,
});
const items = Array.isArray(result) ? result : [];
const item = items.find((b: any) => b.id === botId);
.option('--show-credentials', 'Show full credential values (unmasked)')
.action(
async (botId: string, options: { json?: string | boolean; showCredentials?: boolean }) => {
const client = await getTrpcClient();
const b = await findBot(client, botId);
if (!item) {
log.error(`Bot integration not found: ${botId}`);
process.exit(1);
return;
}
if (options.json !== undefined) {
const fields = typeof options.json === 'string' ? options.json : undefined;
outputJson(item, fields);
return;
}
const b = item as any;
console.log(pc.bold(`${b.platform} bot`));
console.log(pc.dim(`ID: ${b.id}`));
console.log(`Application ID: ${b.applicationId}`);
console.log(`Status: ${b.enabled ? pc.green('enabled') : pc.dim('disabled')}`);
if (b.credentials && typeof b.credentials === 'object') {
console.log();
console.log(pc.bold('Credentials:'));
for (const [key, value] of Object.entries(b.credentials)) {
const val = String(value);
const masked = val.length > 8 ? val.slice(0, 4) + '****' + val.slice(-4) : '****';
console.log(` ${key}: ${masked}`);
if (options.json !== undefined) {
const fields = typeof options.json === 'string' ? options.json : undefined;
outputJson(b, fields);
return;
}
}
});
const status = b.enabled ? (b.runtimeStatus ?? 'disconnected') : 'disabled';
const statusColorFn = STATUS_COLORS[status] ?? pc.dim;
const credentialLines: string[] = [];
if (b.credentials && typeof b.credentials === 'object') {
for (const [key, value] of Object.entries(b.credentials)) {
const val = String(value);
const display = options.showCredentials ? val : maskValue(val);
credentialLines.push(`${pc.dim(key)}: ${display}`);
}
}
const settingsLines: string[] = [];
if (b.settings && typeof b.settings === 'object') {
for (const [key, value] of Object.entries(b.settings)) {
settingsLines.push(`${pc.dim(key)}: ${JSON.stringify(value)}`);
}
}
printBoxTable(
[
{ header: 'Field', key: 'field' },
{ header: 'Value', key: 'value' },
],
[
{ field: 'ID', value: b.id || '' },
{ field: 'Platform', value: pc.cyan(b.platform || '') },
{ field: 'Application ID', value: b.applicationId || '' },
{ field: 'Agent ID', value: b.agentId || '' },
{ field: 'Status', value: statusColorFn(status) },
...(credentialLines.length > 0
? [{ field: 'Credentials', value: credentialLines }]
: []),
...(settingsLines.length > 0 ? [{ field: 'Settings', value: settingsLines }] : []),
...(b.createdAt
? [{ field: 'Created', value: new Date(b.createdAt).toLocaleString() }]
: []),
...(b.updatedAt ? [{ field: 'Updated', value: timeAgo(b.updatedAt) }] : []),
],
`${b.platform} bot`,
);
},
);
// ── add ───────────────────────────────────────────────
@@ -124,13 +238,18 @@ export function registerBotCommand(program: Command) {
.command('add')
.description('Add a bot integration to an agent')
.requiredOption('-a, --agent <agentId>', 'Agent ID')
.requiredOption('--platform <platform>', `Platform: ${SUPPORTED_PLATFORMS.join(', ')}`)
.requiredOption('--platform <platform>', 'Platform (run `lh bot platforms` to see options)')
.requiredOption('--app-id <appId>', 'Application ID for webhook routing')
.option('--bot-token <token>', 'Bot token')
.option('--bot-token <token>', 'Bot token (Discord, Slack, Telegram)')
.option('--bot-id <id>', 'Bot ID (WeChat)')
.option('--public-key <key>', 'Public key (Discord)')
.option('--signing-secret <secret>', 'Signing secret (Slack)')
.option('--app-secret <secret>', 'App secret (Lark/Feishu)')
.option('--app-secret <secret>', 'App secret (Lark, Feishu, QQ)')
.option('--secret-token <token>', 'Secret token (Telegram)')
.option('--webhook-proxy-url <url>', 'Webhook proxy URL (Telegram)')
.option('--encrypt-key <key>', 'Encrypt key (Feishu)')
.option('--verification-token <token>', 'Verification token (Feishu)')
.option('--json', 'Output created bot as JSON')
.action(
async (options: {
agent: string;
@@ -138,34 +257,39 @@ export function registerBotCommand(program: Command) {
appSecret?: string;
botId?: string;
botToken?: string;
encryptKey?: string;
json?: boolean;
platform: string;
publicKey?: string;
secretToken?: string;
signingSecret?: string;
verificationToken?: string;
webhookProxyUrl?: string;
}) => {
if (!SUPPORTED_PLATFORMS.includes(options.platform)) {
log.error(`Invalid platform. Must be one of: ${SUPPORTED_PLATFORMS.join(', ')}`);
process.exit(1);
return;
}
const client = await getTrpcClient();
const platformDef = await resolvePlatform(client, options.platform);
const credentials = parseCredentials(options.platform, options);
const requiredFields = PLATFORM_CREDENTIAL_FIELDS[options.platform] || [];
const missing = requiredFields.filter((f) => !credentials[f]);
const { credentials, missing } = extractCredentials(platformDef, options);
if (missing.length > 0) {
log.error(
`Missing required credentials for ${options.platform}: ${missing.map((f) => '--' + f.replaceAll(/([A-Z])/g, '-$1').toLowerCase()).join(', ')}`,
`Missing required credentials for ${options.platform}: ${missing.map((f: any) => camelToFlag(f.key)).join(', ')}`,
);
process.exit(1);
return;
}
const client = await getTrpcClient();
const result = await client.agentBotProvider.create.mutate({
agentId: options.agent,
applicationId: options.appId,
credentials,
platform: options.platform,
});
if (options.json) {
outputJson(result);
return;
}
const r = result as any;
console.log(
`${pc.green('✓')} Added ${pc.bold(options.platform)} bot ${pc.bold(r.id || '')}`,
@@ -183,6 +307,10 @@ export function registerBotCommand(program: Command) {
.option('--public-key <key>', 'New public key')
.option('--signing-secret <secret>', 'New signing secret')
.option('--app-secret <secret>', 'New app secret')
.option('--secret-token <token>', 'New secret token')
.option('--webhook-proxy-url <url>', 'New webhook proxy URL')
.option('--encrypt-key <key>', 'New encrypt key')
.option('--verification-token <token>', 'New verification token')
.option('--app-id <appId>', 'New application ID')
.option('--platform <platform>', 'New platform')
.action(
@@ -193,20 +321,23 @@ export function registerBotCommand(program: Command) {
appSecret?: string;
botId?: string;
botToken?: string;
encryptKey?: string;
platform?: string;
publicKey?: string;
secretToken?: string;
signingSecret?: string;
verificationToken?: string;
webhookProxyUrl?: string;
},
) => {
const client = await getTrpcClient();
const input: Record<string, any> = { id: botId };
const credentials: Record<string, string> = {};
if (options.botToken) credentials.botToken = options.botToken;
if (options.botId) credentials.botId = options.botId;
if (options.publicKey) credentials.publicKey = options.publicKey;
if (options.signingSecret) credentials.signingSecret = options.signingSecret;
if (options.appSecret) credentials.appSecret = options.appSecret;
const existing = await findBot(client, botId);
const platform = options.platform ?? existing.platform;
const platformDef = await resolvePlatform(client, platform);
const { credentials } = extractCredentials(platformDef, options);
if (Object.keys(credentials).length > 0) input.credentials = credentials;
if (options.appId) input.applicationId = options.appId;
if (options.platform) input.platform = options.platform;
@@ -217,7 +348,6 @@ export function registerBotCommand(program: Command) {
return;
}
const client = await getTrpcClient();
await client.agentBotProvider.update.mutate(input as any);
console.log(`${pc.green('✓')} Updated bot ${pc.bold(botId)}`);
},
@@ -263,28 +393,41 @@ export function registerBotCommand(program: Command) {
console.log(`${pc.green('✓')} Disabled bot ${pc.bold(botId)}`);
});
// ── test ───────────────────────────────────────────────
bot
.command('test <botId>')
.description('Test bot credentials against the platform API')
.action(async (botId: string) => {
const client = await getTrpcClient();
const b = await findBot(client, botId);
log.status(`Testing ${b.platform} credentials for ${b.applicationId}...`);
try {
await client.agentBotProvider.testConnection.mutate({
applicationId: b.applicationId,
platform: b.platform,
});
console.log(`${pc.green('✓')} Credentials are valid for ${pc.bold(b.platform)} bot`);
} catch (err: any) {
const message = err?.message || 'Connection test failed';
log.error(`Credential test failed: ${message}`);
process.exit(1);
}
});
// ── connect ───────────────────────────────────────────
bot
.command('connect <botId>')
.description('Connect and start a bot')
.requiredOption('-a, --agent <agentId>', 'Agent ID')
.action(async (botId: string, options: { agent: string }) => {
// First fetch the bot to get platform and applicationId
.action(async (botId: string) => {
const client = await getTrpcClient();
const result = await client.agentBotProvider.getByAgentId.query({
agentId: options.agent,
});
const items = Array.isArray(result) ? result : [];
const item = items.find((b: any) => b.id === botId);
const b = await findBot(client, botId);
if (!item) {
log.error(`Bot integration not found: ${botId}`);
process.exit(1);
return;
}
log.status(`Connecting ${b.platform} bot ${b.applicationId}...`);
const b = item as any;
const connectResult = await client.agentBotProvider.connectBot.mutate({
applicationId: b.applicationId,
platform: b.platform,
+564
View File
@@ -0,0 +1,564 @@
import { DEFAULT_BOT_HISTORY_LIMIT } from '@lobechat/const';
import type { Command } from 'commander';
import pc from 'picocolors';
import { getTrpcClient } from '../api/client';
import { confirm, outputJson, printTable, truncate } from '../utils/format';
import { log } from '../utils/logger';
export function registerBotMessageCommands(bot: Command) {
const message = bot
.command('message')
.description('Send and manage messages on connected platforms');
// ── send ────────────────────────────────────────────────
message
.command('send <botId>')
.description('Send a message to a channel')
.requiredOption('--target <channelId>', 'Target channel / conversation ID')
.requiredOption('--message <text>', 'Message content')
.option('--reply-to <messageId>', 'Reply to a specific message')
.option('--json', 'Output JSON')
.action(
async (
botId: string,
options: { json?: boolean; message: string; replyTo?: string; target: string },
) => {
const client = await getTrpcClient();
const result = await client.botMessage.sendMessage.mutate({
botId,
channelId: options.target,
content: options.message,
replyTo: options.replyTo,
});
if (options.json) {
outputJson(result);
return;
}
const r = result as any;
console.log(
`${pc.green('✓')} Message sent${r.messageId ? ` (${pc.dim(r.messageId)})` : ''}`,
);
},
);
// ── read ────────────────────────────────────────────────
message
.command('read <botId>')
.description('Read messages from a channel')
.requiredOption('--target <channelId>', 'Target channel / conversation ID')
.option('--limit <n>', 'Max messages to fetch', String(DEFAULT_BOT_HISTORY_LIMIT))
.option('--before <messageId>', 'Read messages before this ID')
.option('--after <messageId>', 'Read messages after this ID')
.option('--start-time <timestamp>', 'Start time as Unix seconds (Feishu/Lark)')
.option('--end-time <timestamp>', 'End time as Unix seconds (Feishu/Lark)')
.option('--cursor <token>', 'Pagination cursor from a previous response (Feishu/Lark)')
.option('--json', 'Output JSON')
.action(
async (
botId: string,
options: {
after?: string;
before?: string;
cursor?: string;
endTime?: string;
json?: boolean;
limit?: string;
startTime?: string;
target: string;
},
) => {
const client = await getTrpcClient();
const result = await client.botMessage.readMessages.query({
after: options.after,
before: options.before,
botId,
channelId: options.target,
cursor: options.cursor,
endTime: options.endTime,
limit: options.limit ? Number.parseInt(options.limit, 10) : undefined,
startTime: options.startTime,
});
if (options.json) {
outputJson(result);
return;
}
const messages = (result as any).messages ?? [];
if (messages.length === 0) {
console.log('No messages found.');
return;
}
const rows = messages.map((m: any) => [
m.id || '',
m.author?.name || '',
truncate(m.content || '', 60),
m.timestamp || '',
]);
printTable(rows, ['ID', 'AUTHOR', 'CONTENT', 'TIME']);
const r = result as any;
if (r.hasMore && r.nextCursor) {
console.log(
`\nMore messages available. Use ${pc.dim(`--cursor ${r.nextCursor}`)} to fetch next page.`,
);
}
},
);
// ── edit ────────────────────────────────────────────────
message
.command('edit <botId>')
.description('Edit a message')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--message-id <id>', 'Message ID to edit')
.requiredOption('--message <text>', 'New message content')
.action(
async (botId: string, options: { message: string; messageId: string; target: string }) => {
const client = await getTrpcClient();
await client.botMessage.editMessage.mutate({
botId,
channelId: options.target,
content: options.message,
messageId: options.messageId,
});
console.log(`${pc.green('✓')} Message ${pc.bold(options.messageId)} edited`);
},
);
// ── delete ──────────────────────────────────────────────
message
.command('delete <botId>')
.description('Delete a message')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--message-id <id>', 'Message ID to delete')
.option('--yes', 'Skip confirmation prompt')
.action(
async (botId: string, options: { messageId: string; target: string; yes?: boolean }) => {
if (!options.yes) {
const confirmed = await confirm('Are you sure you want to delete this message?');
if (!confirmed) {
console.log('Cancelled.');
return;
}
}
const client = await getTrpcClient();
await client.botMessage.deleteMessage.mutate({
botId,
channelId: options.target,
messageId: options.messageId,
});
console.log(`${pc.green('✓')} Message ${pc.bold(options.messageId)} deleted`);
},
);
// ── search ──────────────────────────────────────────────
message
.command('search <botId>')
.description('Search messages in a channel')
.requiredOption('--target <channelId>', 'Channel ID to search in')
.requiredOption('--query <text>', 'Search query')
.option('--author-id <id>', 'Filter by author ID')
.option('--limit <n>', 'Max results')
.option('--json', 'Output JSON')
.action(
async (
botId: string,
options: {
authorId?: string;
json?: boolean;
limit?: string;
query: string;
target: string;
},
) => {
const client = await getTrpcClient();
const result = await client.botMessage.searchMessages.query({
authorId: options.authorId,
botId,
channelId: options.target,
limit: options.limit ? Number.parseInt(options.limit, 10) : undefined,
query: options.query,
});
if (options.json) {
outputJson(result);
return;
}
const messages = (result as any).messages ?? [];
if (messages.length === 0) {
console.log('No messages found.');
return;
}
const rows = messages.map((m: any) => [
m.id || '',
m.author?.name || '',
truncate(m.content || '', 60),
]);
printTable(rows, ['ID', 'AUTHOR', 'CONTENT']);
},
);
// ── react ───────────────────────────────────────────────
message
.command('react <botId>')
.description('Add an emoji reaction to a message')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--message-id <id>', 'Message ID to react to')
.requiredOption('--emoji <emoji>', 'Emoji to react with')
.action(
async (botId: string, options: { emoji: string; messageId: string; target: string }) => {
const client = await getTrpcClient();
await client.botMessage.reactToMessage.mutate({
botId,
channelId: options.target,
emoji: options.emoji,
messageId: options.messageId,
});
console.log(
`${pc.green('✓')} Reacted with ${options.emoji} to message ${pc.bold(options.messageId)}`,
);
},
);
// ── reactions ───────────────────────────────────────────
message
.command('reactions <botId>')
.description('List reactions on a message')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--message-id <id>', 'Message ID')
.option('--json', 'Output JSON')
.action(
async (botId: string, options: { json?: boolean; messageId: string; target: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.getReactions.query({
botId,
channelId: options.target,
messageId: options.messageId,
});
if (options.json) {
outputJson(result);
return;
}
const reactions = (result as any).reactions ?? [];
if (reactions.length === 0) {
console.log('No reactions found.');
return;
}
const rows = reactions.map((r: any) => [r.emoji || '', String(r.count || 0)]);
printTable(rows, ['EMOJI', 'COUNT']);
},
);
// ── pin ─────────────────────────────────────────────────
message
.command('pin <botId>')
.description('Pin a message')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--message-id <id>', 'Message ID to pin')
.action(async (botId: string, options: { messageId: string; target: string }) => {
const client = await getTrpcClient();
await client.botMessage.pinMessage.mutate({
botId,
channelId: options.target,
messageId: options.messageId,
});
console.log(`${pc.green('✓')} Pinned message ${pc.bold(options.messageId)}`);
});
// ── unpin ───────────────────────────────────────────────
message
.command('unpin <botId>')
.description('Unpin a message')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--message-id <id>', 'Message ID to unpin')
.action(async (botId: string, options: { messageId: string; target: string }) => {
const client = await getTrpcClient();
await client.botMessage.unpinMessage.mutate({
botId,
channelId: options.target,
messageId: options.messageId,
});
console.log(`${pc.green('✓')} Unpinned message ${pc.bold(options.messageId)}`);
});
// ── pins ────────────────────────────────────────────────
message
.command('pins <botId>')
.description('List pinned messages')
.requiredOption('--target <channelId>', 'Channel ID')
.option('--json', 'Output JSON')
.action(async (botId: string, options: { json?: boolean; target: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.listPins.query({
botId,
channelId: options.target,
});
if (options.json) {
outputJson(result);
return;
}
const messages = (result as any).messages ?? [];
if (messages.length === 0) {
console.log('No pinned messages.');
return;
}
const rows = messages.map((m: any) => [
m.id || '',
m.author?.name || '',
truncate(m.content || '', 60),
]);
printTable(rows, ['ID', 'AUTHOR', 'CONTENT']);
});
// ── poll ────────────────────────────────────────────────
message
.command('poll <botId>')
.description('Create a poll')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--poll-question <text>', 'Poll question')
.requiredOption('--poll-option <option>', 'Poll option (repeatable)', collectOptions, [])
.option('--poll-multi', 'Allow multiple answers')
.option('--poll-duration-hours <n>', 'Poll duration in hours')
.action(
async (
botId: string,
options: {
pollDurationHours?: string;
pollMulti?: boolean;
pollOption: string[];
pollQuestion: string;
target: string;
},
) => {
if (options.pollOption.length < 2) {
log.error('At least 2 poll options are required.');
process.exit(1);
}
const client = await getTrpcClient();
const result = await client.botMessage.createPoll.mutate({
botId,
channelId: options.target,
duration: options.pollDurationHours
? Number.parseInt(options.pollDurationHours, 10)
: undefined,
multipleAnswers: options.pollMulti,
options: options.pollOption,
question: options.pollQuestion,
});
const r = result as any;
console.log(`${pc.green('✓')} Poll created${r.pollId ? ` (${pc.dim(r.pollId)})` : ''}`);
},
);
// ── thread (subcommand group) ───────────────────────────
const thread = message.command('thread').description('Manage threads');
thread
.command('create <botId>')
.description('Create a new thread')
.requiredOption('--target <channelId>', 'Channel ID')
.requiredOption('--thread-name <name>', 'Thread name')
.option('--message <text>', 'Initial message content')
.option('--message-id <id>', 'Create thread from a message')
.action(
async (
botId: string,
options: { message?: string; messageId?: string; target: string; threadName: string },
) => {
const client = await getTrpcClient();
const result = await client.botMessage.createThread.mutate({
botId,
channelId: options.target,
content: options.message,
messageId: options.messageId,
name: options.threadName,
});
const r = result as any;
console.log(
`${pc.green('✓')} Thread created${r.threadId ? ` (${pc.dim(r.threadId)})` : ''}`,
);
},
);
thread
.command('list <botId>')
.description('List threads in a channel')
.requiredOption('--target <channelId>', 'Channel ID')
.option('--json', 'Output JSON')
.action(async (botId: string, options: { json?: boolean; target: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.listThreads.query({
botId,
channelId: options.target,
});
if (options.json) {
outputJson(result);
return;
}
const threads = (result as any).threads ?? [];
if (threads.length === 0) {
console.log('No threads found.');
return;
}
const rows = threads.map((t: any) => [
t.id || '',
t.name || '',
String(t.messageCount ?? ''),
]);
printTable(rows, ['ID', 'NAME', 'MESSAGES']);
});
thread
.command('reply <botId>')
.description('Reply to a thread')
.requiredOption('--thread-id <id>', 'Thread ID')
.requiredOption('--message <text>', 'Reply content')
.action(async (botId: string, options: { message: string; threadId: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.replyToThread.mutate({
botId,
content: options.message,
threadId: options.threadId,
});
const r = result as any;
console.log(`${pc.green('✓')} Reply sent${r.messageId ? ` (${pc.dim(r.messageId)})` : ''}`);
});
// ── channel (subcommand group) ──────────────────────────
const channel = message.command('channel').description('Manage channels');
channel
.command('list <botId>')
.description('List channels')
.option('--server-id <id>', 'Server / workspace ID')
.option('--filter <type>', 'Filter by type')
.option('--json', 'Output JSON')
.action(
async (botId: string, options: { filter?: string; json?: boolean; serverId?: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.listChannels.query({
botId,
filter: options.filter,
serverId: options.serverId,
});
if (options.json) {
outputJson(result);
return;
}
const channels = (result as any).channels ?? [];
if (channels.length === 0) {
console.log('No channels found.');
return;
}
const rows = channels.map((c: any) => [c.id || '', c.name || '', c.type || '']);
printTable(rows, ['ID', 'NAME', 'TYPE']);
},
);
channel
.command('info <botId>')
.description('Get channel details')
.requiredOption('--target <channelId>', 'Channel ID')
.option('--json', 'Output JSON')
.action(async (botId: string, options: { json?: boolean; target: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.getChannelInfo.query({
botId,
channelId: options.target,
});
if (options.json) {
outputJson(result);
return;
}
const r = result as any;
console.log(`Channel: ${pc.bold(r.name || options.target)}`);
if (r.type) console.log(` Type: ${r.type}`);
if (r.memberCount != null) console.log(` Members: ${r.memberCount}`);
if (r.description) console.log(` Description: ${r.description}`);
});
// ── member ──────────────────────────────────────────────
const member = message.command('member').description('Member information');
member
.command('info <botId>')
.description('Get member details')
.requiredOption('--member-id <id>', 'Member / user ID')
.option('--server-id <id>', 'Server / workspace ID')
.option('--json', 'Output JSON')
.action(
async (botId: string, options: { json?: boolean; memberId: string; serverId?: string }) => {
const client = await getTrpcClient();
const result = await client.botMessage.getMemberInfo.query({
botId,
memberId: options.memberId,
serverId: options.serverId,
});
if (options.json) {
outputJson(result);
return;
}
const r = result as any;
console.log(`Member: ${pc.bold(r.displayName || r.username || options.memberId)}`);
if (r.status) console.log(` Status: ${r.status}`);
if (r.roles?.length) console.log(` Roles: ${r.roles.join(', ')}`);
},
);
}
// ── Helpers ──────────────────────────────────────────────
function collectOptions(value: string, previous: string[]): string[] {
return [...previous, value];
}
+32 -1
View File
@@ -96,7 +96,7 @@ vi.mock('@lobechat/device-gateway-client', () => ({
// eslint-disable-next-line import-x/first
import { resolveToken } from '../auth/resolveToken';
// eslint-disable-next-line import-x/first
import { spawnDaemon, stopDaemon } from '../daemon/manager';
import { removeStatus, spawnDaemon, stopDaemon, writeStatus } from '../daemon/manager';
// eslint-disable-next-line import-x/first
import { loadSettings, saveSettings } from '../settings';
// eslint-disable-next-line import-x/first
@@ -130,6 +130,36 @@ describe('connect command', () => {
return program;
}
it('should persist deviceId in status for foreground connections', async () => {
const program = createProgram();
await program.parseAsync(['node', 'test', 'connect']);
expect(writeStatus).toHaveBeenCalledWith(
expect.objectContaining({ connectionStatus: 'connecting', deviceId: 'mock-device-id' }),
);
clientEventHandlers.connected?.();
expect(writeStatus).toHaveBeenLastCalledWith(
expect.objectContaining({ connectionStatus: 'connected', deviceId: 'mock-device-id' }),
);
});
it('should persist deviceId in status for daemon child connections', async () => {
const program = createProgram();
await program.parseAsync(['node', 'test', 'connect', '--daemon-child']);
expect(writeStatus).toHaveBeenCalledWith(
expect.objectContaining({ connectionStatus: 'connecting', deviceId: 'mock-device-id' }),
);
clientEventHandlers.connected?.();
expect(writeStatus).toHaveBeenLastCalledWith(
expect.objectContaining({ connectionStatus: 'connected', deviceId: 'mock-device-id' }),
);
});
it('should connect to gateway', async () => {
const program = createProgram();
await program.parseAsync(['node', 'test', 'connect']);
@@ -288,6 +318,7 @@ describe('connect command', () => {
}
expect(cleanupAllProcesses).toHaveBeenCalled();
expect(removeStatus).toHaveBeenCalled();
});
it('should handle auth_expired when refresh fails', async () => {
+28 -18
View File
@@ -173,7 +173,7 @@ function buildDaemonArgs(options: ConnectOptions): string[] {
}
async function runConnect(options: ConnectOptions, isDaemonChild: boolean) {
const auth = await resolveToken(options);
let auth = await resolveToken(options);
const settings = loadSettings();
const gatewayUrl = normalizeUrl(options.gateway) || settings?.gatewayUrl;
@@ -221,16 +221,15 @@ async function runConnect(options: ConnectOptions, isDaemonChild: boolean) {
info(` Mode : ${isDaemonChild ? 'daemon' : 'foreground'}`);
info('───────────────────');
// Update status file for daemon mode
// Update local connection status so other CLI commands can resolve the current device
const updateStatus = (connectionStatus: string) => {
if (isDaemonChild) {
writeStatus({
connectionStatus,
gatewayUrl: resolvedGatewayUrl,
pid: process.pid,
startedAt: startedAt.toISOString(),
});
}
writeStatus({
connectionStatus,
deviceId: client.currentDeviceId,
gatewayUrl: resolvedGatewayUrl,
pid: process.pid,
startedAt: startedAt.toISOString(),
});
};
const startedAt = new Date();
@@ -295,19 +294,30 @@ async function runConnect(options: ConnectOptions, isDaemonChild: boolean) {
process.exit(1);
});
// Handle auth expired
// Handle auth expired — refresh token and reconnect automatically
client.on('auth_expired', async () => {
if (auth.tokenType === 'apiKey') {
// API keys don't expire; ignore stale auth_expired signals
return;
}
error('Authentication expired. Attempting to refresh...');
const refreshed = await resolveToken({});
if (refreshed) {
info('Token refreshed. Please reconnect.');
} else {
error("Could not refresh token. Run 'lh login' to re-authenticate.");
info('Authentication expired. Attempting to refresh token...');
try {
const refreshed = await resolveToken({});
if (refreshed) {
info('Token refreshed successfully. Reconnecting...');
client.updateToken(refreshed.token);
// Update cached auth so subsequent refreshes use the latest token
auth = refreshed;
await client.reconnect();
return;
}
} catch {
// refresh failed — fall through
}
error("Could not refresh token. Run 'lh login' to re-authenticate.");
cleanup();
process.exit(1);
});
@@ -322,8 +332,8 @@ async function runConnect(options: ConnectOptions, isDaemonChild: boolean) {
info('Shutting down...');
cleanupAllProcesses();
client.disconnect();
removeStatus();
if (isDaemonChild) {
removeStatus();
removePid();
}
};
+42 -1
View File
@@ -61,7 +61,6 @@ describe('generate command', () => {
headers: {
'Content-Type': 'application/json',
'Oidc-Auth': 'test-token',
'X-lobe-chat-auth': 'test-xor-token',
},
serverUrl: 'https://app.lobehub.com',
});
@@ -271,6 +270,48 @@ describe('generate command', () => {
);
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Video generation started'));
});
it('should pass image-to-video params', async () => {
mockTrpcClient.generationTopic.createTopic.mutate.mockResolvedValue('topic-3');
mockTrpcClient.video.createVideo.mutate.mockResolvedValue({
data: { generationId: 'gen-v2' },
success: true,
});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'generate',
'video',
'a cat waving',
'--model',
'cogvideox',
'--provider',
'zhipu',
'--image',
'https://example.com/first.png',
'--end-image',
'https://example.com/last.png',
'--images',
'https://example.com/a.png',
'https://example.com/b.png',
]);
expect(mockTrpcClient.video.createVideo.mutate).toHaveBeenCalledWith(
expect.objectContaining({
generationTopicId: 'topic-3',
model: 'cogvideox',
params: {
endImageUrl: 'https://example.com/last.png',
imageUrl: 'https://example.com/first.png',
imageUrls: ['https://example.com/a.png', 'https://example.com/b.png'],
prompt: 'a cat waving',
},
provider: 'zhipu',
}),
);
});
});
describe('tts', () => {
+10 -1
View File
@@ -6,13 +6,16 @@ import { getTrpcClient } from '../../api/client';
export function registerVideoCommand(parent: Command) {
parent
.command('video <prompt>')
.description('Generate a video from text')
.description('Generate a video from text or image(s)')
.requiredOption('-m, --model <model>', 'Model ID')
.requiredOption('-p, --provider <provider>', 'Provider name')
.option('--aspect-ratio <ratio>', 'Aspect ratio (e.g. 16:9)')
.option('--duration <sec>', 'Duration in seconds')
.option('--resolution <res>', 'Resolution (e.g. 720p, 1080p)')
.option('--seed <n>', 'Random seed')
.option('--image <url>', 'First-frame image URL (image-to-video)')
.option('--images <urls...>', 'Multiple reference image URLs')
.option('--end-image <url>', 'Last-frame image URL')
.option('--json', 'Output raw JSON')
.action(
async (
@@ -20,6 +23,9 @@ export function registerVideoCommand(parent: Command) {
options: {
aspectRatio?: string;
duration?: string;
endImage?: string;
image?: string;
images?: string[];
json?: boolean;
model: string;
provider: string;
@@ -35,6 +41,9 @@ export function registerVideoCommand(parent: Command) {
if (options.duration) params.duration = Number.parseInt(options.duration, 10);
if (options.resolution) params.resolution = options.resolution;
if (options.seed) params.seed = Number.parseInt(options.seed, 10);
if (options.image) params.imageUrl = options.image;
if (options.images && options.images.length > 0) params.imageUrls = options.images;
if (options.endImage) params.endImageUrl = options.endImage;
const result = await client.video.createVideo.mutate({
generationTopicId: topicId as string,
+51
View File
@@ -79,6 +79,57 @@ describe('message command', () => {
);
expect(mockTrpcClient.message.listAll.query).not.toHaveBeenCalled();
});
it('should keep first page on the backend default offset for filtered queries', async () => {
mockTrpcClient.message.getMessages.query.mockResolvedValue([]);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'message',
'list',
'--topic-id',
't1',
'-L',
'200',
]);
expect(mockTrpcClient.message.getMessages.query).toHaveBeenCalledWith(
expect.objectContaining({ pageSize: 200, topicId: 't1' }),
);
});
it('should convert page 2 to current 1 for filtered queries', async () => {
mockTrpcClient.message.getMessages.query.mockResolvedValue([]);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'message',
'list',
'--topic-id',
't1',
'--page',
'2',
]);
expect(mockTrpcClient.message.getMessages.query).toHaveBeenCalledWith(
expect.objectContaining({ current: 1, topicId: 't1' }),
);
});
it('should support the short page flag for filtered queries', async () => {
mockTrpcClient.message.getMessages.query.mockResolvedValue([]);
const program = createProgram();
await program.parseAsync(['node', 'test', 'message', 'list', '--topic-id', 't1', '-P', '2']);
expect(mockTrpcClient.message.getMessages.query).toHaveBeenCalledWith(
expect.objectContaining({ current: 1, topicId: 't1' }),
);
});
});
describe('search', () => {
+4 -2
View File
@@ -16,7 +16,7 @@ export function registerMessageCommand(program: Command) {
.option('--topic-id <id>', 'Filter by topic ID')
.option('--agent-id <id>', 'Filter by agent ID')
.option('-L, --limit <n>', 'Page size', '30')
.option('--page <n>', 'Page number', '1')
.option('-P, --page <n>', 'Page number', '1')
.option('--user', 'Only show user messages')
.option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
.action(
@@ -32,7 +32,9 @@ export function registerMessageCommand(program: Command) {
const hasFilter = options.topicId || options.agentId;
const pageSize = options.limit ? Number.parseInt(options.limit, 10) : undefined;
const current = options.page ? Number.parseInt(options.page, 10) : undefined;
const current = options.page
? Math.max(Number.parseInt(options.page, 10) - 1, 0)
: undefined;
let items: any[];
+11
View File
@@ -0,0 +1,11 @@
import type { Command } from 'commander';
import { registerOpenClawMigration } from './openclaw';
export function registerMigrateCommand(program: Command) {
const migrate = program
.command('migrate')
.description('Migrate data from external tools (OpenClaw, ChatGPT, Claude, etc.)');
registerOpenClawMigration(migrate);
}
@@ -0,0 +1,588 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { Command } from 'commander';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
// ── Mocks ──────────────────────────────────────────────
const { mockTrpcClient } = vi.hoisted(() => ({
mockTrpcClient: {
agent: {
createAgent: { mutate: vi.fn() },
getBuiltinAgent: { query: vi.fn() },
},
agentDocument: {
upsertDocument: { mutate: vi.fn() },
},
},
}));
const { getTrpcClient: mockGetTrpcClient } = vi.hoisted(() => ({
getTrpcClient: vi.fn(),
}));
const { mockConfirm } = vi.hoisted(() => ({
mockConfirm: vi.fn(),
}));
vi.mock('../../api/client', () => ({
getTrpcClient: mockGetTrpcClient,
}));
vi.mock('../../settings', () => ({
resolveServerUrl: () => 'https://app.lobehub.com',
}));
vi.mock('../../utils/format', async (importOriginal) => {
const actual = await importOriginal<Record<string, unknown>>();
return { ...actual, confirm: mockConfirm };
});
vi.mock('../../utils/logger', () => ({
log: {
debug: vi.fn(),
error: vi.fn(),
info: vi.fn(),
warn: vi.fn(),
},
setVerbose: vi.fn(),
}));
// eslint-disable-next-line import-x/first
import { log } from '../../utils/logger';
// eslint-disable-next-line import-x/first
import { registerOpenClawMigration } from './openclaw';
// ── Helpers ────────────────────────────────────────────
let tmpDir: string;
function createProgram() {
const program = new Command();
program.exitOverride();
const migrate = program.command('migrate');
registerOpenClawMigration(migrate);
return program;
}
function writeFile(relativePath: string, content: string) {
const fullPath = path.join(tmpDir, relativePath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, content);
}
// ── Setup / teardown ───────────────────────────────────
let exitSpy: ReturnType<typeof vi.spyOn>;
let consoleSpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
vi.clearAllMocks();
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'openclaw-test-'));
exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => {
throw new Error('process.exit');
}) as any);
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
mockGetTrpcClient.mockResolvedValue(mockTrpcClient);
mockConfirm.mockResolvedValue(true);
});
afterEach(() => {
exitSpy.mockRestore();
consoleSpy.mockRestore();
fs.rmSync(tmpDir, { recursive: true, force: true });
});
// ── Tests ──────────────────────────────────────────────
describe('migrate openclaw', () => {
// ── Profile parsing ────────────────────────────────
describe('agent profile from workspace', () => {
it('should read name, description, and emoji from IDENTITY.md', async () => {
writeFile(
'IDENTITY.md',
['# IDENTITY.md', '- **Name:** 龙虾', '- **Creature:** AI 助手', '- **Emoji:** 🦞'].join(
'\n',
),
);
writeFile('hello.md', 'hello');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agent.createAgent.mutate).toHaveBeenCalledWith({
config: {
avatar: '🦞',
description: 'AI 助手',
title: '龙虾',
},
});
});
it('should filter out placeholder emoji like (待定)', async () => {
writeFile(
'IDENTITY.md',
['# IDENTITY.md', '- **Name:** TestBot', '- **Emoji:**', ' _(待定)_'].join('\n'),
);
writeFile('hello.md', 'hello');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agent.createAgent.mutate).toHaveBeenCalledWith({
config: {
avatar: undefined,
description: undefined,
title: 'TestBot',
},
});
});
it('should fall back to "OpenClaw" when no identity files exist', async () => {
writeFile('doc.md', 'content');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agent.createAgent.mutate).toHaveBeenCalledWith({
config: {
avatar: undefined,
description: undefined,
title: 'OpenClaw',
},
});
});
});
// ── File filtering ─────────────────────────────────
describe('file collection and filtering', () => {
it('should exclude common directories like node_modules and .git', async () => {
writeFile('README.md', 'readme');
writeFile('node_modules/pkg/index.js', 'module');
writeFile('.git/config', 'git');
writeFile('.idea/workspace.xml', 'ide');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledTimes(1);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ filename: 'README.md' }),
);
});
it('should exclude files matching glob patterns like *.pyc and *.log', async () => {
writeFile('main.py', 'print("hi")');
writeFile('main.pyc', 'bytecode');
writeFile('app.log', 'log data');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledTimes(1);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ filename: 'main.py' }),
);
});
it('should respect workspace .gitignore', async () => {
writeFile('.gitignore', 'secret.txt\ndata/\n');
writeFile('README.md', 'readme');
writeFile('secret.txt', 'password');
writeFile('data/dump.sql', 'sql');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
const filenames = mockTrpcClient.agentDocument.upsertDocument.mutate.mock.calls.map(
(c: any[]) => c[0].filename,
);
expect(filenames).toContain('README.md');
expect(filenames).not.toContain('secret.txt');
expect(filenames).not.toContain('data/dump.sql');
});
it('should skip binary files during import', async () => {
writeFile('readme.md', 'text content');
// Write a file with null bytes (binary)
const binPath = path.join(tmpDir, 'image.dat');
fs.writeFileSync(binPath, Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x00, 0x00, 0x01]));
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
// Only the text file should be upserted
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledTimes(1);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ filename: 'readme.md' }),
);
// Binary file should show as skipped in output
const allOutput = consoleSpy.mock.calls.map((c: any[]) => c[0]).join('\n');
expect(allOutput).toContain('skipped');
});
it('should exclude database files by extension', async () => {
writeFile('data.md', 'notes');
writeFile('local.sqlite', 'fake-sqlite');
writeFile('app.db', 'fake-db');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledTimes(1);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ filename: 'data.md' }),
);
});
it('should collect files in subdirectories', async () => {
writeFile('docs/guide.md', 'guide');
writeFile('docs/api.md', 'api');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
const filenames = mockTrpcClient.agentDocument.upsertDocument.mutate.mock.calls
.map((c: any[]) => c[0].filename)
.sort();
expect(filenames).toEqual(['docs/api.md', 'docs/guide.md']);
});
});
// ── Dry run ────────────────────────────────────────
describe('--dry-run', () => {
it('should list files without calling API', async () => {
writeFile('file.md', 'content');
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--dry-run',
]);
expect(mockGetTrpcClient).not.toHaveBeenCalled();
expect(mockTrpcClient.agent.createAgent.mutate).not.toHaveBeenCalled();
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).not.toHaveBeenCalled();
expect(log.info).toHaveBeenCalledWith(expect.stringContaining('Dry run'));
});
});
// ── Agent resolution ───────────────────────────────
describe('agent resolution', () => {
it('should use --agent-id directly when provided', async () => {
writeFile('file.md', 'content');
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--agent-id',
'agt_existing',
'--yes',
]);
expect(mockTrpcClient.agent.createAgent.mutate).not.toHaveBeenCalled();
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'agt_existing' }),
);
});
it('should resolve agent by --slug', async () => {
writeFile('file.md', 'content');
mockTrpcClient.agent.getBuiltinAgent.query.mockResolvedValue({ id: 'agt_inbox' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--slug',
'inbox',
'--yes',
]);
expect(mockTrpcClient.agent.getBuiltinAgent.query).toHaveBeenCalledWith({ slug: 'inbox' });
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'agt_inbox' }),
);
});
it('should create a new agent by default', async () => {
writeFile('file.md', 'content');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_new' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agent.createAgent.mutate).toHaveBeenCalledTimes(1);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'agt_new' }),
);
});
});
// ── Confirmation ───────────────────────────────────
describe('confirmation', () => {
it('should cancel when user declines', async () => {
writeFile('file.md', 'content');
mockConfirm.mockResolvedValue(false);
const program = createProgram();
await program.parseAsync(['node', 'test', 'migrate', 'openclaw', '--source', tmpDir]);
expect(mockTrpcClient.agent.createAgent.mutate).not.toHaveBeenCalled();
expect(consoleSpy).toHaveBeenCalledWith('Cancelled.');
});
it('should skip confirmation with --yes', async () => {
writeFile('file.md', 'content');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockConfirm).not.toHaveBeenCalled();
});
});
// ── Error handling ─────────────────────────────────
describe('error handling', () => {
it('should exit when source path does not exist', async () => {
const program = createProgram();
await program
.parseAsync(['node', 'test', 'migrate', 'openclaw', '--source', '/nonexistent/path'])
.catch(() => {}); // process.exit throws
expect(exitSpy).toHaveBeenCalledWith(1);
expect(log.error).toHaveBeenCalledWith(expect.stringContaining('not found'));
});
it('should report failed files without aborting', async () => {
writeFile('a.md', 'ok');
writeFile('b.md', 'fail');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
// Files are iterated in readdir order; mock first success then failure
mockTrpcClient.agentDocument.upsertDocument.mutate
.mockResolvedValueOnce({})
.mockRejectedValueOnce(new Error('upload error'));
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
expect(mockTrpcClient.agentDocument.upsertDocument.mutate).toHaveBeenCalledTimes(2);
const allOutput = consoleSpy.mock.calls.map((c: any[]) => c[0]).join('\n');
expect(allOutput).toContain('1 imported');
expect(allOutput).toContain('1 failed');
});
it('should show no files message for empty workspace', async () => {
// Only excluded items
writeFile('.git/config', 'git');
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--dry-run',
]);
expect(log.info).toHaveBeenCalledWith('No files found in workspace.');
});
});
// ── Output ─────────────────────────────────────────
describe('output', () => {
it('should print agent URL on completion', async () => {
writeFile('file.md', 'content');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_abc123' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
const allOutput = consoleSpy.mock.calls.map((c: any[]) => c[0]).join('\n');
expect(allOutput).toContain('https://app.lobehub.com/agent/agt_abc123');
});
it('should show friendly completion message on success', async () => {
writeFile('file.md', 'content');
mockTrpcClient.agent.createAgent.mutate.mockResolvedValue({ agentId: 'agt_test' });
mockTrpcClient.agentDocument.upsertDocument.mutate.mockResolvedValue({});
const program = createProgram();
await program.parseAsync([
'node',
'test',
'migrate',
'openclaw',
'--source',
tmpDir,
'--yes',
]);
const allOutput = consoleSpy.mock.calls.map((c: any[]) => c[0]).join('\n');
expect(allOutput).toContain('Migration complete');
});
});
});
+466
View File
@@ -0,0 +1,466 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import type { Command } from 'commander';
import ignore from 'ignore';
import pc from 'picocolors';
import type { TrpcClient } from '../../api/client';
import { getTrpcClient } from '../../api/client';
import { resolveServerUrl } from '../../settings';
import { confirm } from '../../utils/format';
import { log } from '../../utils/logger';
const DEFAULT_AGENT_NAME = 'OpenClaw';
// Files to look for agent identity (tried in order)
const IDENTITY_FILES = ['IDENTITY.md', 'SOUL.md'];
// Default ignore rules (gitignore syntax) applied when no .gitignore is found
const DEFAULT_IGNORE_RULES = [
// VCS
'.git',
'.svn',
'.hg',
// OpenClaw internal
'.openclaw',
// OS artifacts
'.DS_Store',
'Thumbs.db',
'desktop.ini',
// IDE / editor
'.idea',
'.vscode',
'.fleet',
'.cursor',
'.zed',
'*.swp',
'*.swo',
'*~',
// Dependencies
'node_modules',
'.pnp',
'.yarn',
'bower_components',
'vendor',
'jspm_packages',
// Python
'.venv',
'venv',
'env',
'__pycache__',
'*.pyc',
'*.pyo',
'.mypy_cache',
'.ruff_cache',
'.pytest_cache',
'.tox',
'.eggs',
'*.egg-info',
// Ruby
'.bundle',
// Rust
'target',
// Go
'go.sum',
// Java / JVM
'.gradle',
'.m2',
// .NET
'bin',
'obj',
'packages',
// Build / cache / output
'.cache',
'.parcel-cache',
'.next',
'.nuxt',
'.turbo',
'.output',
'dist',
'build',
'out',
'.sass-cache',
// Env / secrets
'.env',
'.env.*',
// Test / coverage
'coverage',
'.nyc_output',
// Infra
'.terraform',
// Temp
'tmp',
'.tmp',
// Logs
'*.log',
'logs',
// Databases
'*.sqlite',
'*.sqlite3',
'*.db',
'*.db-shm',
'*.db-wal',
'*.ldb',
'*.mdb',
'*.accdb',
// Archives / binaries
'*.zip',
'*.tar',
'*.tar.gz',
'*.tgz',
'*.gz',
'*.bz2',
'*.xz',
'*.rar',
'*.7z',
'*.jar',
'*.war',
'*.dll',
'*.so',
'*.dylib',
'*.exe',
'*.bin',
'*.o',
'*.a',
'*.lib',
'*.class',
// Images / media / fonts
'*.png',
'*.jpg',
'*.jpeg',
'*.gif',
'*.bmp',
'*.ico',
'*.webp',
'*.svg',
'*.mp3',
'*.mp4',
'*.wav',
'*.avi',
'*.mov',
'*.mkv',
'*.flac',
'*.ogg',
'*.pdf',
'*.woff',
'*.woff2',
'*.ttf',
'*.otf',
'*.eot',
// Lock files
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml',
'Gemfile.lock',
'Cargo.lock',
'poetry.lock',
'composer.lock',
];
interface AgentProfile {
avatar?: string;
description?: string;
title: string;
}
/**
* Try to extract the agent name, description, and avatar emoji from
* IDENTITY.md or SOUL.md. Falls back to "OpenClaw" if neither file
* exists or parsing fails.
*/
function readAgentProfile(workspacePath: string): AgentProfile {
for (const filename of IDENTITY_FILES) {
const filePath = path.join(workspacePath, filename);
if (!fs.existsSync(filePath)) continue;
const content = fs.readFileSync(filePath, 'utf8');
// Try to extract **Name:** value
const nameMatch = content.match(/\*{0,2}Name:?\*{0,2}\s*(.+)/i);
const title = nameMatch ? nameMatch[1].trim() : DEFAULT_AGENT_NAME;
// Try to extract **Creature:** or **Vibe:** or **Description:** as description
const descMatch = content.match(/\*{0,2}(?:Creature|Vibe|Description):?\*{0,2}\s*(.+)/i);
const description = descMatch ? descMatch[1].trim() : undefined;
// Try to extract **Emoji:** value (single emoji)
const emojiMatch = content.match(/\*{0,2}Emoji:?\*{0,2}\s*(.+)/i);
const rawAvatar = emojiMatch ? emojiMatch[1].trim() : undefined;
// Filter out placeholder text like (待定)(Chinese TBD), _(待定)_, (TBD), N/A, etc.
const isPlaceholder =
rawAvatar && /^[_*(].*[)_*]$|^(?:tbd|todo|n\/?a|none|待定|未定)$/i.test(rawAvatar);
const avatar = rawAvatar && !isPlaceholder ? rawAvatar : undefined;
return { avatar, description, title };
}
return { title: DEFAULT_AGENT_NAME };
}
/**
* Build an ignore filter for the workspace. Uses .gitignore if present,
* otherwise falls back to a comprehensive default rule set.
*/
function buildIgnoreFilter(workspacePath: string) {
const ig = ignore();
const gitignorePath = path.join(workspacePath, '.gitignore');
if (fs.existsSync(gitignorePath)) {
ig.add(fs.readFileSync(gitignorePath, 'utf8'));
}
// Always apply default rules on top
ig.add(DEFAULT_IGNORE_RULES);
return ig;
}
/**
* Recursively collect all files under `dir`, filtered by ignore rules.
* Returns paths relative to `baseDir`.
*/
function collectFiles(dir: string, baseDir: string, ig: ReturnType<typeof ignore>): string[] {
const results: string[] = [];
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const relativePath = path.relative(baseDir, path.join(dir, entry.name));
// Directories need a trailing slash for ignore to match correctly
const testPath = entry.isDirectory() ? `${relativePath}/` : relativePath;
if (ig.ignores(testPath)) continue;
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
results.push(...collectFiles(fullPath, baseDir, ig));
} else if (entry.isFile()) {
results.push(relativePath);
}
}
return results;
}
/**
* Quick check: read the first 8KB and look for null bytes.
* If found, the file is likely binary and should be skipped.
*/
function isBinaryFile(filePath: string): boolean {
const fd = fs.openSync(filePath, 'r');
try {
const buf = Buffer.alloc(8192);
const bytesRead = fs.readSync(fd, buf, 0, 8192, 0);
for (let i = 0; i < bytesRead; i++) {
if (buf[i] === 0) return true;
}
return false;
} finally {
fs.closeSync(fd);
}
}
function formatAgentLabel(profile: AgentProfile): string {
return profile.avatar ? `${profile.avatar} ${profile.title}` : profile.title;
}
/**
* Resolve the target agent ID.
* Priority: --agent-id > --slug > create new agent from workspace profile.
*/
async function resolveAgentId(
client: TrpcClient,
opts: { agentId?: string; slug?: string },
profile: AgentProfile,
): Promise<string> {
if (opts.agentId) return opts.agentId;
if (opts.slug) {
const agent = await client.agent.getBuiltinAgent.query({ slug: opts.slug });
if (!agent) {
log.error(`Agent not found for slug: ${opts.slug}`);
process.exit(1);
}
return agent.id;
}
const label = formatAgentLabel(profile);
log.info(`Creating new agent ${pc.bold(label)}...`);
const result = await client.agent.createAgent.mutate({
config: {
avatar: profile.avatar,
description: profile.description,
title: profile.title,
},
});
const id = result.agentId;
if (!id) {
log.error('Failed to create agent — no agentId returned.');
process.exit(1);
}
console.log(`${pc.green('✓')} Agent created: ${pc.bold(label)}`);
return id;
}
export function registerOpenClawMigration(migrate: Command) {
migrate
.command('openclaw')
.description('Import OpenClaw workspace files as agent documents')
.option(
'--source <path>',
'Path to OpenClaw workspace',
path.join(os.homedir(), '.openclaw', 'workspace'),
)
.option('--agent-id <id>', 'Import into an existing agent by ID')
.option('--slug <slug>', 'Import into an existing agent by slug (e.g. "inbox")')
.option('--dry-run', 'Preview files without importing')
.option('--yes', 'Skip confirmation prompt')
.action(
async (options: {
agentId?: string;
dryRun?: boolean;
slug?: string;
source: string;
yes?: boolean;
}) => {
// Check auth early so users don't scan files only to find out they're not logged in
if (!options.dryRun) {
await getTrpcClient();
}
const workspacePath = path.resolve(options.source);
// Validate source directory
if (!fs.existsSync(workspacePath)) {
log.error(`OpenClaw workspace not found: ${workspacePath}`);
process.exit(1);
}
if (!fs.statSync(workspacePath).isDirectory()) {
log.error(`Not a directory: ${workspacePath}`);
process.exit(1);
}
// Read agent profile from workspace identity files
const profile = readAgentProfile(workspacePath);
const label = formatAgentLabel(profile);
// Collect files (respects .gitignore + default rules)
const ig = buildIgnoreFilter(workspacePath);
const files = collectFiles(workspacePath, workspacePath, ig);
if (files.length === 0) {
log.info('No files found in workspace.');
return;
}
console.log(
`Found ${pc.bold(String(files.length))} file(s) in ${pc.dim(workspacePath)}:\n`,
);
for (const f of files) {
console.log(` ${pc.dim('•')} ${f}`);
}
console.log();
if (options.dryRun) {
log.info('Dry run — no changes made.');
return;
}
// Confirm
if (!options.yes) {
const target = options.agentId
? `agent ${pc.bold(options.agentId)}`
: options.slug
? `agent slug "${pc.bold(options.slug)}"`
: `a new ${pc.bold(label)} agent`;
const confirmed = await confirm(
`Import ${files.length} file(s) as agent documents into ${target}?`,
);
if (!confirmed) {
console.log('Cancelled.');
return;
}
}
const client = await getTrpcClient();
// Create or reuse agent
const agentId = await resolveAgentId(client, options, profile);
console.log(`\nImporting to ${pc.bold(label)}...\n`);
let success = 0;
let failed = 0;
let skipped = 0;
for (const relativePath of files) {
const fullPath = path.join(workspacePath, relativePath);
try {
// Skip binary files that slipped through the extension filter
if (isBinaryFile(fullPath)) {
console.log(` ${pc.dim('○')} ${relativePath} ${pc.dim('(binary, skipped)')}`);
skipped++;
continue;
}
const content = fs.readFileSync(fullPath, 'utf8');
const stat = fs.statSync(fullPath);
await client.agentDocument.upsertDocument.mutate({
agentId,
content,
createdAt: stat.birthtime,
filename: relativePath,
updatedAt: stat.mtime,
});
console.log(` ${pc.green('✓')} ${relativePath}`);
success++;
} catch (err: any) {
console.log(` ${pc.red('✗')} ${relativePath}${err.message || err}`);
failed++;
}
}
const agentUrl = `${resolveServerUrl()}/agent/${agentId}`;
const skippedInfo = skipped > 0 ? `, ${skipped} skipped` : '';
console.log();
if (failed === 0) {
console.log(
`${pc.green('✓')} Migration complete! ${pc.bold(String(success))} file(s) imported to ${pc.bold(label)}.${skippedInfo}`,
);
} else {
console.log(
`${pc.yellow('⚠')} Migration finished with issues: ${pc.bold(String(success))} imported, ${pc.red(String(failed))} failed${skippedInfo}.`,
);
}
console.log(`\n ${pc.dim('→')} ${pc.underline(agentUrl)}`);
console.log();
},
);
}
+51
View File
@@ -0,0 +1,51 @@
import type { Command } from 'commander';
import pc from 'picocolors';
import { getTrpcClient } from '../api/client';
import { log } from '../utils/logger';
export function registerNotifyCommand(program: Command) {
program
.command('notify')
.description('Send a callback message to a topic and trigger the agent to process it')
.requiredOption('--topic <topicId>', 'Target topic ID')
.requiredOption('-c, --content <content>', 'Message content')
.option('--agent-id <agentId>', 'Agent ID (overrides topic default)')
.option('--thread-id <threadId>', 'Thread ID for threaded conversations')
.option('--json', 'Output JSON')
.action(
async (options: {
agentId?: string;
content: string;
json?: boolean;
threadId?: string;
topic: string;
}) => {
log.debug('notify: topic=%s, agentId=%s', options.topic, options.agentId);
const client = await getTrpcClient();
try {
const result = await client.agentNotify.notify.mutate({
agentId: options.agentId,
content: options.content,
threadId: options.threadId,
topicId: options.topic,
});
if (options.json) {
console.log(JSON.stringify(result, null, 2));
return;
}
console.log(`${pc.green('✓')} Message sent to topic ${pc.bold(result.topicId)}`);
if (result.operationId) {
console.log(` Operation ID: ${result.operationId}`);
}
} catch (error: any) {
console.error(`${pc.red('✗')} Failed to send notification: ${error.message}`);
process.exit(1);
}
},
);
}
+83 -16
View File
@@ -2,10 +2,12 @@ import type { Command } from 'commander';
import pc from 'picocolors';
import { getTrpcClient } from '../../api/client';
import type { KanbanColumn } from '../../utils/format';
import {
confirm,
displayWidth,
outputJson,
printKanban,
printTable,
timeAgo,
truncate,
@@ -37,10 +39,12 @@ export function registerTaskCommand(program: Command) {
.option('-L, --limit <n>', 'Page size', '50')
.option('--offset <n>', 'Offset', '0')
.option('--tree', 'Display as tree structure')
.option('--board', 'Display as kanban board grouped by status')
.option('--json [fields]', 'Output JSON')
.action(
async (options: {
agent?: string;
board?: boolean;
json?: string | boolean;
limit?: string;
offset?: string;
@@ -59,8 +63,8 @@ export function registerTaskCommand(program: Command) {
if (options.limit) input.limit = Number.parseInt(options.limit, 10);
if (options.offset) input.offset = Number.parseInt(options.offset, 10);
// For tree mode, fetch all tasks (no pagination limit)
if (options.tree) {
// For tree/board mode, fetch all tasks (no pagination limit)
if (options.tree || options.board) {
input.limit = 100;
delete input.offset;
}
@@ -77,6 +81,58 @@ export function registerTaskCommand(program: Command) {
return;
}
if (options.board) {
// Kanban board grouped by status
const statusOrder = [
'backlog',
'blocked',
'running',
'paused',
'completed',
'failed',
'timeout',
'canceled',
];
const statusColors: Record<string, (s: string) => string> = {
backlog: pc.dim,
blocked: pc.red,
canceled: pc.dim,
completed: pc.green,
failed: pc.red,
paused: pc.yellow,
running: pc.blue,
timeout: pc.red,
};
// Group tasks by status
const grouped = new Map<string, any[]>();
for (const t of result.data) {
const status = t.status || 'backlog';
const list = grouped.get(status) || [];
list.push(t);
grouped.set(status, list);
}
const kanbanColumns: KanbanColumn[] = statusOrder
.filter((s) => grouped.has(s))
.map((status) => ({
color: statusColors[status],
items: grouped.get(status)!.map((t: any) => ({
badge: pc.dim(t.identifier),
meta: t.assigneeAgentId ? `agent: ${t.assigneeAgentId}` : undefined,
title: t.name || t.instruction,
})),
title: status.toUpperCase(),
}));
console.log();
printKanban(kanbanColumns);
console.log();
log.info(`Total: ${result.total}`);
return;
}
if (options.tree) {
// Build tree display
const taskMap = new Map<string, any>();
@@ -240,23 +296,34 @@ export function registerTaskCommand(program: Command) {
}
if (t.error) console.log(`${pc.red('Error:')} ${t.error}`);
// ── Subtasks ──
// ── Subtasks (nested tree) ──
if (t.subtasks && t.subtasks.length > 0) {
// Build lookup: which subtasks are completed
const completedIdentifiers = new Set(
t.subtasks.filter((s) => s.status === 'completed').map((s) => s.identifier),
);
// Build lookup: which subtasks are completed (flatten tree)
const collectCompleted = (nodes: typeof t.subtasks, set: Set<string>): Set<string> => {
for (const s of nodes!) {
if (s.status === 'completed') set.add(s.identifier);
if (s.children) collectCompleted(s.children, set);
}
return set;
};
const completedIdentifiers = collectCompleted(t.subtasks, new Set());
const renderSubtasks = (nodes: typeof t.subtasks, indent: string) => {
for (const s of nodes!) {
const depInfo = s.blockedBy ? pc.dim(` ← blocks: ${s.blockedBy}`) : '';
const isBlocked = s.blockedBy && !completedIdentifiers.has(s.blockedBy);
const displayStatus = s.status === 'backlog' && isBlocked ? 'blocked' : s.status;
console.log(
`${indent}${pc.dim(s.identifier)} ${statusBadge(displayStatus)} ${s.name || '(unnamed)'}${depInfo}`,
);
if (s.children && s.children.length > 0) {
renderSubtasks(s.children, indent + ' ');
}
}
};
console.log(`\n${pc.bold('Subtasks:')}`);
for (const s of t.subtasks) {
const depInfo = s.blockedBy ? pc.dim(` ← blocks: ${s.blockedBy}`) : '';
// Show 'blocked' instead of 'backlog' if task has unresolved dependencies
const isBlocked = s.blockedBy && !completedIdentifiers.has(s.blockedBy);
const displayStatus = s.status === 'backlog' && isBlocked ? 'blocked' : s.status;
console.log(
` ${pc.dim(s.identifier)} ${statusBadge(displayStatus)} ${s.name || '(unnamed)'}${depInfo}`,
);
}
renderSubtasks(t.subtasks, ' ');
}
// ── Dependencies ──
+42
View File
@@ -77,6 +77,48 @@ describe('topic command', () => {
expect.objectContaining({ agentId: 'a1' }),
);
});
it('should keep first page on the backend default offset', async () => {
mockTrpcClient.topic.getTopics.query.mockResolvedValue([]);
const program = createProgram();
await program.parseAsync(['node', 'test', 'topic', 'list', '--agent-id', 'a1', '-L', '200']);
expect(mockTrpcClient.topic.getTopics.query).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'a1', pageSize: 200 }),
);
});
it('should convert page 2 to current 1', async () => {
mockTrpcClient.topic.getTopics.query.mockResolvedValue([]);
const program = createProgram();
await program.parseAsync([
'node',
'test',
'topic',
'list',
'--agent-id',
'a1',
'--page',
'2',
]);
expect(mockTrpcClient.topic.getTopics.query).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'a1', current: 1 }),
);
});
it('should support the short page flag', async () => {
mockTrpcClient.topic.getTopics.query.mockResolvedValue([]);
const program = createProgram();
await program.parseAsync(['node', 'test', 'topic', 'list', '--agent-id', 'a1', '-P', '2']);
expect(mockTrpcClient.topic.getTopics.query).toHaveBeenCalledWith(
expect.objectContaining({ agentId: 'a1', current: 1 }),
);
});
});
describe('search', () => {
+3 -2
View File
@@ -17,7 +17,7 @@ export function registerTopicCommand(program: Command) {
.description('List topics')
.option('--agent-id <id>', 'Filter by agent ID')
.option('-L, --limit <n>', 'Page size', '30')
.option('--page <n>', 'Page number', '1')
.option('-P, --page <n>', 'Page number', '1')
.option('--json [fields]', 'Output JSON, optionally specify fields (comma-separated)')
.action(
async (options: {
@@ -31,7 +31,8 @@ export function registerTopicCommand(program: Command) {
const input: Record<string, any> = {};
if (options.agentId) input.agentId = options.agentId;
if (options.limit) input.pageSize = Number.parseInt(options.limit, 10);
if (options.page) input.current = Number.parseInt(options.page, 10);
const page = options.page ? Number.parseInt(options.page, 10) : undefined;
if (page !== undefined && page > 1) input.current = page - 1;
const result = await client.topic.getTopics.query(input as any);
const items = Array.isArray(result) ? result : ((result as any).items ?? []);
+1
View File
@@ -1,2 +1,3 @@
export const OFFICIAL_AGENT_GATEWAY_URL = 'https://agent-gateway.lobehub.com';
export const OFFICIAL_SERVER_URL = 'https://app.lobehub.com';
export const OFFICIAL_GATEWAY_URL = 'https://device-gateway.lobehub.com';
+2 -1
View File
@@ -23,6 +23,7 @@ function getLogFilePath() {
export interface DaemonStatus {
connectionStatus: string;
deviceId?: string;
gatewayUrl: string;
pid: number;
startedAt: string;
@@ -159,7 +160,7 @@ export function spawnDaemon(args: string[]): number {
// Re-run the same entry with --daemon-child (internal flag)
const child = spawn(process.execPath, [...process.execArgv, ...args, '--daemon-child'], {
detached: true,
env: { ...process.env, LOBEHUB_DAEMON: '1' },
env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', LOBEHUB_DAEMON: '1' },
stdio: ['ignore', logFd, logFd],
});
+1 -1
View File
@@ -1,3 +1,3 @@
import { createProgram } from './program';
createProgram().parse();
createProgram().parse(process.argv, { from: 'node' });
+6
View File
@@ -20,13 +20,16 @@ import { registerLogoutCommand } from './commands/logout';
import { registerManCommand } from './commands/man';
import { registerMemoryCommand } from './commands/memory';
import { registerMessageCommand } from './commands/message';
import { registerMigrateCommand } from './commands/migrate';
import { registerModelCommand } from './commands/model';
import { registerNotifyCommand } from './commands/notify';
import { registerPluginCommand } from './commands/plugin';
import { registerProviderCommand } from './commands/provider';
import { registerSearchCommand } from './commands/search';
import { registerSessionGroupCommand } from './commands/session-group';
import { registerSkillCommand } from './commands/skill';
import { registerStatusCommand } from './commands/status';
import { registerTaskCommand } from './commands/task';
import { registerThreadCommand } from './commands/thread';
import { registerTopicCommand } from './commands/topic';
import { registerUserCommand } from './commands/user';
@@ -61,15 +64,18 @@ export function createProgram() {
registerFileCommand(program);
registerSkillCommand(program);
registerSessionGroupCommand(program);
registerTaskCommand(program);
registerThreadCommand(program);
registerTopicCommand(program);
registerMessageCommand(program);
registerModelCommand(program);
registerNotifyCommand(program);
registerProviderCommand(program);
registerPluginCommand(program);
registerUserCommand(program);
registerConfigCommand(program);
registerEvalCommand(program);
registerMigrateCommand(program);
return program;
}
+16 -4
View File
@@ -2,10 +2,11 @@ import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { OFFICIAL_SERVER_URL } from '../constants/urls';
import { OFFICIAL_AGENT_GATEWAY_URL, OFFICIAL_SERVER_URL } from '../constants/urls';
import { log } from '../utils/logger';
export interface StoredSettings {
agentGatewayUrl?: string;
gatewayUrl?: string;
serverUrl?: string;
}
@@ -25,15 +26,24 @@ export function resolveServerUrl(): string {
return envServerUrl || settingsServerUrl || OFFICIAL_SERVER_URL;
}
export function resolveAgentGatewayUrl(): string | undefined {
const envUrl = normalizeUrl(process.env.AGENT_GATEWAY_URL);
const settingsUrl = normalizeUrl(loadSettings()?.agentGatewayUrl);
return envUrl || settingsUrl || OFFICIAL_AGENT_GATEWAY_URL;
}
export function saveSettings(settings: StoredSettings): void {
const serverUrl = normalizeUrl(settings.serverUrl);
const agentGatewayUrl = normalizeUrl(settings.agentGatewayUrl);
const gatewayUrl = normalizeUrl(settings.gatewayUrl);
const serverUrl = normalizeUrl(settings.serverUrl);
const normalized: StoredSettings = {
agentGatewayUrl: agentGatewayUrl === OFFICIAL_AGENT_GATEWAY_URL ? undefined : agentGatewayUrl,
gatewayUrl,
serverUrl: serverUrl === OFFICIAL_SERVER_URL ? undefined : serverUrl,
};
if (!normalized.serverUrl && !normalized.gatewayUrl) {
if (!normalized.serverUrl && !normalized.gatewayUrl && !normalized.agentGatewayUrl) {
try {
fs.unlinkSync(SETTINGS_FILE);
} catch {}
@@ -50,14 +60,16 @@ export function loadSettings(): StoredSettings | null {
try {
const data = fs.readFileSync(SETTINGS_FILE, 'utf8');
const parsed = JSON.parse(data) as StoredSettings;
const agentGatewayUrl = normalizeUrl(parsed.agentGatewayUrl);
const gatewayUrl = normalizeUrl(parsed.gatewayUrl);
const serverUrl = normalizeUrl(parsed.serverUrl);
const normalized: StoredSettings = {
agentGatewayUrl: agentGatewayUrl === OFFICIAL_AGENT_GATEWAY_URL ? undefined : agentGatewayUrl,
gatewayUrl,
serverUrl: serverUrl === OFFICIAL_SERVER_URL ? undefined : serverUrl,
};
if (!normalized.serverUrl && !normalized.gatewayUrl) return null;
if (!normalized.serverUrl && !normalized.gatewayUrl && !normalized.agentGatewayUrl) return null;
return normalized;
} catch {
+417 -1
View File
@@ -1,9 +1,10 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { streamAgentEvents } from './agentStream';
import { streamAgentEvents, streamAgentEventsViaWebSocket } from './agentStream';
vi.mock('./logger', () => ({
log: {
debug: vi.fn(),
error: vi.fn(),
heartbeat: vi.fn(),
info: vi.fn(),
@@ -193,3 +194,418 @@ describe('streamAgentEvents', () => {
exitSpy.mockRestore();
});
});
// ── WebSocket stream tests ──────────────────────────────
let capturedWs: MockWebSocket | undefined;
class MockWebSocket {
static OPEN = 1;
static CONNECTING = 0;
static CLOSED = 3;
readyState = MockWebSocket.CONNECTING;
onopen: ((ev: any) => void) | null = null;
onmessage: ((ev: any) => void) | null = null;
onerror: ((ev: any) => void) | null = null;
onclose: ((ev: any) => void) | null = null;
sent: string[] = [];
private autoAuthSuccess = true;
constructor(
public url: string,
autoAuth = true,
) {
this.autoAuthSuccess = autoAuth;
capturedWs = this; // eslint-disable-line @typescript-eslint/no-this-alias
// Trigger onopen on next microtask (after handlers are assigned)
queueMicrotask(() => {
this.readyState = MockWebSocket.OPEN;
this.onopen?.({ type: 'open' });
});
}
send(data: string) {
this.sent.push(data);
const msg = JSON.parse(data);
if (msg.type === 'auth' && this.autoAuthSuccess) {
queueMicrotask(() => {
this.onmessage?.({ data: JSON.stringify({ type: 'auth_success' }) });
});
}
}
close() {
this.readyState = MockWebSocket.CLOSED;
// Async like real WebSocket — fires after current microtask
queueMicrotask(() => this.onclose?.({ code: 1000, reason: '' }));
}
simulateMessage(msg: Record<string, unknown>) {
this.onmessage?.({ data: JSON.stringify(msg) });
}
}
describe('streamAgentEventsViaWebSocket', () => {
let stdoutSpy: ReturnType<typeof vi.spyOn>;
let consoleSpy: ReturnType<typeof vi.spyOn>;
const originalWebSocket = globalThis.WebSocket;
beforeEach(() => {
capturedWs = undefined;
stdoutSpy = vi.spyOn(process.stdout, 'write').mockImplementation(() => true);
consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
(globalThis as any).WebSocket = MockWebSocket;
});
afterEach(() => {
stdoutSpy.mockRestore();
consoleSpy.mockRestore();
globalThis.WebSocket = originalWebSocket;
});
/** Wait for microtasks + short delay so WS open/auth cycle completes */
const flush = () => new Promise((r) => setTimeout(r, 20));
it('should connect, authenticate, and send resume', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
token: 'test-token',
});
await flush();
const ws = capturedWs!;
// Note: serverUrl is not set here, and JSON.stringify drops undefined keys,
// so the parsed auth message will not contain a `serverUrl` field.
expect(ws.sent.map((s) => JSON.parse(s))).toEqual([
{ token: 'test-token', tokenType: 'jwt', type: 'auth' },
{ lastEventId: '', type: 'resume' },
]);
ws.simulateMessage({ id: '1', type: 'session_complete' });
await promise;
});
it('should send tokenType=apiKey and serverUrl when the caller uses an API key', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
serverUrl: 'https://app.lobehub.com',
token: 'lh_sk_abc',
tokenType: 'apiKey',
});
await flush();
const ws = capturedWs!;
// serverUrl is forwarded so the gateway can call back to /api/v1/users/me
// to verify the API key.
expect(ws.sent.map((s) => JSON.parse(s))[0]).toEqual({
serverUrl: 'https://app.lobehub.com',
token: 'lh_sk_abc',
tokenType: 'apiKey',
type: 'auth',
});
ws.simulateMessage({ id: '1', type: 'session_complete' });
await promise;
});
it('should render agent_event messages using existing renderEvent', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
token: 'test-token',
});
await flush();
const ws = capturedWs!;
ws.simulateMessage({
event: { data: null, operationId: 'op-1', stepIndex: 0, timestamp: 1, type: 'step_start' },
id: '1',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { chunkType: 'text', content: 'Hello WS!' },
operationId: 'op-1',
stepIndex: 0,
timestamp: 2,
type: 'stream_chunk',
},
id: '2',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { stepCount: 1 },
operationId: 'op-1',
stepIndex: 0,
timestamp: 3,
type: 'agent_runtime_end',
},
id: '3',
type: 'agent_event',
});
await promise;
expect(stdoutSpy).toHaveBeenCalledWith('Hello WS!');
});
it('should output JSON when json option is set', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
json: true,
operationId: 'op-1',
token: 'test-token',
});
await flush();
const ws = capturedWs!;
ws.simulateMessage({
event: {
data: null,
operationId: 'op-1',
stepIndex: 0,
timestamp: 1,
type: 'agent_runtime_init',
},
id: '1',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { stepCount: 1 },
operationId: 'op-1',
stepIndex: 0,
timestamp: 2,
type: 'agent_runtime_end',
},
id: '2',
type: 'agent_event',
});
await promise;
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('"agent_runtime_init"'));
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('"agent_runtime_end"'));
});
it('should reject on auth failure', async () => {
// Override mock to return auth_failed instead of auth_success
(globalThis as any).WebSocket = class extends MockWebSocket {
constructor(url: string) {
super(url, false); // disable auto auth_success
capturedWs = this; // eslint-disable-line @typescript-eslint/no-this-alias
}
override send(data: string) {
this.sent.push(data);
const msg = JSON.parse(data);
if (msg.type === 'auth') {
queueMicrotask(() => {
this.onmessage?.({
data: JSON.stringify({ reason: 'invalid token', type: 'auth_failed' }),
});
});
}
}
};
await expect(
streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
token: 'bad-token',
}),
).rejects.toThrow('Gateway auth failed');
});
it('should resolve on session_complete', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
token: 'test-token',
});
await flush();
capturedWs!.simulateMessage({ id: '1', summary: 'All done', type: 'session_complete' });
await expect(promise).resolves.toBeUndefined();
});
it('should ignore heartbeat_ack messages', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
token: 'test-token',
});
await flush();
const ws = capturedWs!;
ws.simulateMessage({ type: 'heartbeat_ack' });
expect(stdoutSpy).not.toHaveBeenCalled();
ws.simulateMessage({ id: '1', type: 'session_complete' });
await promise;
});
it('should construct correct WebSocket URL from HTTPS gateway URL', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://agent-gateway.lobehub.com',
operationId: 'op-123',
token: 'tok',
});
await flush();
expect(capturedWs!.url).toBe('wss://agent-gateway.lobehub.com/ws?operationId=op-123');
capturedWs!.simulateMessage({ id: '1', type: 'session_complete' });
await promise;
});
it('should render a multi-step agent run with tool calls', async () => {
const promise = streamAgentEventsViaWebSocket({
gatewayUrl: 'https://gw.test.com',
operationId: 'op-1',
token: 'tok',
verbose: true,
});
await flush();
const ws = capturedWs!;
const { log } = await import('./logger');
// Step 1: thinking + text + tool call
ws.simulateMessage({
event: {
data: null,
operationId: 'op-1',
stepIndex: 0,
timestamp: 1,
type: 'agent_runtime_init',
},
id: '1',
type: 'agent_event',
});
ws.simulateMessage({
event: { data: null, operationId: 'op-1', stepIndex: 0, timestamp: 2, type: 'step_start' },
id: '2',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { chunkType: 'reasoning', reasoning: 'Let me search...' },
operationId: 'op-1',
stepIndex: 0,
timestamp: 3,
type: 'stream_chunk',
},
id: '3',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { chunkType: 'text', content: 'Searching for news.' },
operationId: 'op-1',
stepIndex: 0,
timestamp: 4,
type: 'stream_chunk',
},
id: '4',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { toolCalling: { apiName: 'search', id: 'tc-1' } },
operationId: 'op-1',
stepIndex: 0,
timestamp: 5,
type: 'tool_start',
},
id: '5',
type: 'agent_event',
});
ws.simulateMessage({
event: { data: null, operationId: 'op-1', stepIndex: 0, timestamp: 6, type: 'stream_end' },
id: '6',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { stepIndex: 0 },
operationId: 'op-1',
stepIndex: 0,
timestamp: 7,
type: 'step_complete',
},
id: '7',
type: 'agent_event',
});
// Step 2: tool result + final text
ws.simulateMessage({
event: { data: null, operationId: 'op-1', stepIndex: 1, timestamp: 8, type: 'step_start' },
id: '8',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: {
isSuccess: true,
payload: { toolCalling: { id: 'tc-1' } },
result: { content: 'Results...' },
},
operationId: 'op-1',
stepIndex: 1,
timestamp: 9,
type: 'tool_end',
},
id: '9',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { chunkType: 'text', content: 'Here are the results.' },
operationId: 'op-1',
stepIndex: 1,
timestamp: 10,
type: 'stream_chunk',
},
id: '10',
type: 'agent_event',
});
ws.simulateMessage({
event: {
data: { cost: { total: 0.05 }, stepCount: 2, usage: { total_tokens: 500 } },
operationId: 'op-1',
stepIndex: 1,
timestamp: 11,
type: 'agent_runtime_end',
},
id: '11',
type: 'agent_event',
});
await promise;
// Verify reasoning was rendered (dim)
expect(stdoutSpy).toHaveBeenCalledWith(expect.stringContaining('Let me search...'));
// Verify text chunks
expect(stdoutSpy).toHaveBeenCalledWith('Searching for news.');
expect(stdoutSpy).toHaveBeenCalledWith('Here are the results.');
// Verify tool call was logged
expect(log.toolCall).toHaveBeenCalledWith('search', 'tc-1', undefined);
// Verify tool result was logged
expect(log.toolResult).toHaveBeenCalled();
// Verify finish line
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Agent finished'));
});
});
+143 -8
View File
@@ -1,21 +1,33 @@
import type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
import pc from 'picocolors';
import urlJoin from 'url-join';
import { log } from './logger';
export interface AgentStreamEvent {
data: any;
id?: string;
operationId: string;
stepIndex: number;
timestamp: number;
type: string;
}
export type { AgentStreamEvent } from '@lobechat/agent-gateway-client';
interface StreamOptions {
json?: boolean;
verbose?: boolean;
}
interface WebSocketStreamOptions extends StreamOptions {
gatewayUrl: string;
operationId: string;
/**
* LobeHub server URL the gateway should call back to when verifying
* an apiKey token (via `/api/v1/users/me`). Required when
* `tokenType === 'apiKey'`; ignored for JWT.
*/
serverUrl?: string;
token: string;
/**
* How the gateway should verify `token`. `jwt` is the default for
* backwards compatibility with existing callers.
*/
tokenType?: 'jwt' | 'apiKey';
}
/**
* Connect to the agent SSE stream and render events to the terminal.
* Resolves when the stream ends (agent_runtime_end or connection close).
@@ -152,6 +164,129 @@ export function replayAgentEvents(events: AgentStreamEvent[], options: StreamOpt
}
}
const HEARTBEAT_INTERVAL = 30_000;
/**
* Connect to the Agent Gateway via WebSocket and render events to the terminal.
* Resolves when the session completes or the connection closes.
*/
export async function streamAgentEventsViaWebSocket(
options: WebSocketStreamOptions,
): Promise<void> {
const { gatewayUrl, operationId, serverUrl, token, tokenType = 'jwt', ...streamOpts } = options;
const wsUrl = urlJoin(
gatewayUrl.replace(/^http/, 'ws'),
`/ws?operationId=${encodeURIComponent(operationId)}`,
);
log.debug(`Connecting to gateway: ${wsUrl} (auth: ${tokenType})`);
return new Promise<void>((resolve, reject) => {
const ws = new WebSocket(wsUrl);
const jsonEvents: AgentStreamEvent[] = [];
const ctx = createRenderContext();
let lastEventId = '';
let heartbeatTimer: ReturnType<typeof setInterval> | undefined;
let jsonPrinted = false;
const cleanup = () => {
if (heartbeatTimer) clearInterval(heartbeatTimer);
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
ws.close();
}
};
ws.onopen = () => {
// `serverUrl` is required so the gateway can call back to verify an
// apiKey token. Harmless (but unused) for JWT, so we always include it
// when available to match the device-gateway-client contract.
ws.send(JSON.stringify({ serverUrl, token, tokenType, type: 'auth' }));
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data as string);
if (msg.type === 'auth_success') {
log.debug('Gateway authenticated');
// Request all buffered events (covers events pushed before WS connected)
ws.send(JSON.stringify({ lastEventId: '', type: 'resume' }));
heartbeatTimer = setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'heartbeat' }));
}
}, HEARTBEAT_INTERVAL);
return;
}
if (msg.type === 'auth_failed') {
cleanup();
reject(new Error(`Gateway auth failed: ${msg.reason}`));
return;
}
if (msg.type === 'heartbeat_ack') return;
if (msg.type === 'agent_event') {
const agentEvent: AgentStreamEvent = msg.event;
if (msg.id) lastEventId = msg.id;
if (streamOpts.json) {
jsonEvents.push(agentEvent);
} else {
renderEvent(agentEvent, ctx, streamOpts);
}
if (agentEvent.type === 'agent_runtime_end') {
if (streamOpts.json && !jsonPrinted) {
jsonPrinted = true;
console.log(JSON.stringify(jsonEvents, null, 2));
} else if (!streamOpts.json) {
renderEnd(agentEvent);
}
cleanup();
resolve();
return;
}
if (agentEvent.type === 'error') {
if (streamOpts.json && !jsonPrinted) {
jsonPrinted = true;
console.log(JSON.stringify(jsonEvents, null, 2));
}
log.error(
`Agent error: ${agentEvent.data?.message || agentEvent.data?.error || 'Unknown error'}`,
);
cleanup();
process.exit(1);
}
}
if (msg.type === 'session_complete') {
if (streamOpts.json && jsonEvents.length > 0 && !jsonPrinted) {
jsonPrinted = true;
console.log(JSON.stringify(jsonEvents, null, 2));
}
cleanup();
resolve();
}
};
ws.onerror = (err) => {
cleanup();
reject(err);
};
ws.onclose = () => {
if (heartbeatTimer) clearInterval(heartbeatTimer);
if (streamOpts.json && jsonEvents.length > 0 && !jsonPrinted) {
jsonPrinted = true;
console.log(JSON.stringify(jsonEvents, null, 2));
}
resolve();
};
});
}
// ── Render helpers ──────────────────────────────────────
interface RenderContext {

Some files were not shown because too many files have changed in this diff Show More