feishu-sidebar 0.1.0: a page that opens Magpie Web in Feishu's sidebar (#1212)

A page plugin that turns a Magpie Web address into Feishu's
client/web_url/open AppLink (mode=appCenter), so Magpie Web opens in
Feishu desktop's left sidebar. No permissions, no request: the page only
builds the link. Addresses with credentials, a query or a fragment are
refused (keeps ?k= keys out of a shared link), and plain HTTP only on
loopback. By zhaiqiming.

Run at the reviewed head f3164eb2 (mica, temp HOME):
- bun test packages/feishu-sidebar: 3 pass, 0 fail.
- bun scripts/check.mjs feishu-sidebar: ok. bun test scripts: 39 pass.
- The page itself, with a stub bridge, in Playwright Chromium and
  WebKit at 400px, en and zh-CN: the title is translated, Enter on a
  loopback address shows the link, a ?k= address shows the error and
  hides the link, nothing scrolls sideways.

Not tried: Feishu desktop itself (the author verified it on macOS).
The package's first npm version waits for the owner; dist serves it.
This commit is contained in:
Qiming Zhai
2026-11-16 16:39:37 +08:00
committed by GitHub
parent 0c685fe902
commit fe19854bd7
9 changed files with 209 additions and 0 deletions
+1
View File
@@ -185,6 +185,7 @@ These add a page to magpie's window, in the app and in `magpie web`, under Plugi
| Package | Page | Reads |
|---|---|---|
| [feishu-sidebar](packages/feishu-sidebar) | Generate an AppLink to open Magpie Web in Feishu desktop’s left sidebar | none |
| [usage](packages/usage) | Usage glance: calls, errors, tokens and cost for today, 7 or 30 days, and the models behind them | `usage:summary` |
| [free-tokens](packages/free-tokens) | AIHOT's Token freebies in three tiers (already configured and usable / needs one more plugin / no plugin yet), with the plugin to install or the exact login step for each | none; its host part reads magpie's folder (providers/checkin) and fetches aihot.news/free-tokens.data once each time the plugin host starts |
| [amp-usage](packages/amp-usage) | Amp usage: requests, input/output tokens, cache reads and writes and cache hit rate from Amp's cloud exports and legacy local threads, synced in the background into Magpie's usage ledger for its usage pages and Day card | none; its host part runs the Amp CLI, reads Amp's local thread files and reports usage to the local Magpie |
+20
View File
@@ -0,0 +1,20 @@
# Feishu sidebar
Open Magpie Web in the left sidebar of the Feishu desktop client. This page
generates Feishu's `client/web_url/open` AppLink with `mode=appCenter`.
1. Enable **Settings → Network and sharing → Browser access** in Magpie, or
start `magpie web`.
2. In **Plugins → Feishu sidebar**, enter the Web address, for example
`http://127.0.0.1:3430` on the same computer. Use a reachable HTTPS
address for Magpie on another computer. Leave out the `?k=...` sign-in
parameter from the URL printed by `magpie web`.
3. Generate the link and copy the selected text to your own Feishu chat.
Open it in Feishu desktop. If Magpie asks for its Web access key, enter
the key on Magpie's sign-in screen. To keep the tab, right-click it in
the left sidebar and pin it.
The plugin generates the link locally in a sandboxed page. It doesn't read
Magpie data, store the address, or send a request. The link includes the
destination address, so share it only where you intend to disclose that
address. Magpie Web still handles authentication.
+35
View File
@@ -0,0 +1,35 @@
import { expect, test } from "bun:test"
import { readFileSync } from "node:fs"
const source = readFileSync(new URL("./page/applink.js", import.meta.url), "utf8")
const buildLink = new Function(source + "\nreturn buildFeishuLink")()
test("opens a Magpie Web URL with a path as an appCenter AppLink", () => {
const { link } = buildLink(" https://magpie.example.test/panels/magpie%20web/ ")
const url = new URL(link)
expect(url.origin + url.pathname).toBe("https://applink.feishu.cn/client/web_url/open")
expect(Object.fromEntries(url.searchParams)).toEqual({
mode: "appCenter",
url: "https://magpie.example.test/panels/magpie%20web/",
})
})
test("allows Magpie Web on the desktop computer over loopback HTTP", () => {
for (const host of ["127.0.0.1", "localhost", "[::1]"]) {
const address = `http://${host}:3430`
expect(new URL(buildLink(address).link).searchParams.get("url")).toBe(address + "/")
}
})
test("does not generate a shareable link from a sign-in URL or an unencrypted remote console", () => {
for (const address of [
"https://magpie.example.test/?k=example-access-key",
"https://user:secret@magpie.example.test/",
"https://magpie.example.test/#token",
]) expect(buildLink(address)).toEqual({ error: "plainAddress" })
expect(buildLink("http://magpie.example.test:3430")).toEqual({ error: "https" })
for (const address of ["javascript:alert(1)", "https:///example.test", "magpie.example.test", ""]) {
expect(buildLink(address)).toEqual({ error: "invalid" })
}
})
+17
View File
@@ -0,0 +1,17 @@
{
"name": "@magpie-community/page-feishu-sidebar",
"version": "0.1.0",
"description": "Open Magpie Web in the Feishu desktop sidebar with an AppLink",
"files": ["page", "README.md"],
"keywords": ["magpie", "magpie-page", "feishu"],
"license": "MIT",
"repository": { "type": "git", "url": "git+https://github.com/magpie-community/plugins.git", "directory": "packages/feishu-sidebar" },
"magpie": {
"page": {
"title": "Feishu sidebar",
"titles": { "zh": "飞书侧边栏" },
"file": "page/index.html"
},
"permissions": []
}
}
+71
View File
@@ -0,0 +1,71 @@
(() => {
const en = {
title: "Feishu sidebar",
setup: "Enable Browser access in Magpie, or run magpie web.",
address: "Magpie Web address",
hint: "Use the address without the sign-in key. Use HTTPS for another computer.",
generate: "Generate Feishu link",
link: "Feishu link",
select: "Select link",
steps: "Copy the link to your own Feishu chat and open it in Feishu desktop. Sign in on Magpie’s page, then right-click the sidebar tab to pin it.",
invalid: "Enter a full Magpie Web address starting with http:// or https://.",
plainAddress: "Remove credentials, query parameters and fragments from the address before sharing it.",
https: "Use an HTTPS address for Magpie Web on another computer.",
}
const zh = {
title: "飞书侧边栏",
setup: "在 Magpie 设置里开启浏览器访问,或运行 magpie web。",
address: "Magpie Web 地址",
hint: "请填写不含登录密钥的网址。访问其他电脑上的 Magpie 时请用 HTTPS。",
generate: "生成飞书链接",
link: "飞书链接",
select: "选中链接",
steps: "复制链接,粘贴到飞书里发给自己,再用飞书桌面端打开。在 Magpie 页面登录后,可以右键点击左侧标签页将它固定。",
invalid: "请输入以 http:// 或 https:// 开头的完整 Magpie Web 地址。",
plainAddress: "请先从地址中移除身份凭据、查询参数和片段。",
https: "访问其他电脑上的 Magpie Web 时请用 HTTPS 地址。",
}
const address = document.getElementById("web-url")
const error = document.getElementById("error")
const result = document.getElementById("result")
const link = document.getElementById("applink")
const text = document.querySelectorAll("[data-t]")
let words = en
let problem = ""
function translate(theme) {
words = theme?.lang?.startsWith("zh") ? zh : en
for (const element of text) element.textContent = words[element.dataset.t]
error.textContent = words[problem] ?? ""
}
function show(output) {
problem = output.error ?? ""
error.textContent = words[problem] ?? ""
address.setAttribute("aria-invalid", String(Boolean(problem)))
link.value = output.link ?? ""
result.hidden = !output.link
}
function selectLink() {
link.focus()
link.select()
}
function generate() {
const output = buildFeishuLink(address.value)
show(output)
if (output.link) selectLink()
else address.focus()
}
address.addEventListener("input", () => show({}))
address.addEventListener("keydown", (event) => {
if (event.key === "Enter" && !event.isComposing) generate()
})
document.getElementById("generate").addEventListener("click", generate)
document.getElementById("select").addEventListener("click", selectLink)
magpie.onTheme(translate)
magpie.ready.then(translate)
})()
+20
View File
@@ -0,0 +1,20 @@
// The inner address is a single AppLink query value. Keep sign-in material out of it.
function buildFeishuLink(address) {
const text = address.trim()
if (!/^https?:\/\/[^/]/i.test(text) || /\s|\\/.test(text)) return { error: "invalid" }
let url
try {
url = new URL(text)
} catch {
return { error: "invalid" }
}
if (url.username || url.password || /[?#]/.test(text)) return { error: "plainAddress" }
const loopback = ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname)
if (url.protocol === "http:" && !loopback) return { error: "https" }
return {
link: "https://applink.feishu.cn/client/web_url/open?mode=appCenter&url=" + encodeURIComponent(url.href),
}
}
+32
View File
@@ -0,0 +1,32 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Feishu sidebar</title>
<link rel="stylesheet" href="style.css">
<script src="_magpie/bridge.js"></script>
<script src="applink.js" defer></script>
<script src="app.js" defer></script>
</head>
<body>
<main>
<h1 data-t="title">Feishu sidebar</h1>
<p data-t="setup">Enable Browser access in Magpie, or run magpie web.</p>
<label for="web-url" data-t="address">Magpie Web address</label>
<input id="web-url" type="text" inputmode="url" spellcheck="false" autocomplete="off"
placeholder="http://127.0.0.1:3430" aria-describedby="hint error">
<p id="hint" data-t="hint">Use the address without the sign-in key. Use HTTPS for another computer.</p>
<button id="generate" type="button" data-t="generate">Generate Feishu link</button>
<p id="error" role="alert"></p>
<section id="result" hidden>
<label for="applink" data-t="link">Feishu link</label>
<div class="link-row">
<input id="applink" type="text" readonly aria-describedby="steps">
<button id="select" type="button" data-t="select">Select link</button>
</div>
<p id="steps" data-t="steps">Copy the link to your own Feishu chat and open it in Feishu desktop. Sign in on Magpie’s page, then right-click the sidebar tab to pin it.</p>
</section>
</main>
</body>
</html>
+11
View File
@@ -0,0 +1,11 @@
body { margin: 0; padding: 20px 24px 32px; }
main { max-width: 36rem; }
label { display: block; font-weight: 600; margin: 1rem 0 .35rem; }
input { box-sizing: border-box; width: 100%; }
p { color: var(--magpie-muted, #6e6e73); }
#hint, #steps { margin: .5rem 0 .75rem; }
#error { color: var(--magpie-red, #d70015); }
#error:empty { margin: 0; }
.link-row { display: flex; gap: .5rem; }
.link-row input { min-width: 0; }
.link-row button { white-space: nowrap; }
+2
View File
@@ -160,6 +160,8 @@
"summary": { "en": "A day of your AI usage printed as a receipt: its cost, requests and streak, the day against your average day, each agent and its models, and its tokens. Copy it as a picture or save it as a PNG. Reads only your usage by day.", "zh": "把一天的 AI 用量打印成一张小票:费用、请求数、连续使用天数、与日均的倍数、每个 Agent 和它用的模型,以及 token 用量。可复制为图片或保存为 PNG。只读取按天的用量。" } },
{ "package": "@magpie-community/page-fingerprint", "name": "Fingerprint", "kind": "page", "community": true,
"summary": { "en": "Check for suspected model substitution by comparing response fingerprints across Magpie providers. Uses lm-detector with shared challenges, local evidence history and JSON export; sampling uses provider quota. Reference data is downloaded on demand from lm.ikale.io, falling back to cdn.jsdmirror.com.", "zh": "在 Magpie 内检测响应指纹,为疑似模型替换提供核查线索。基于 lm-detector,支持跨渠道共享挑战、保留本地证据与 JSON 导出;采样会消耗模型额度。参考库按需从 lm.ikale.io 下载,备用源为 cdn.jsdmirror.com。" } },
{ "package": "@magpie-community/page-feishu-sidebar", "name": "Feishu sidebar", "kind": "page", "community": true,
"summary": { "en": "Generate an AppLink to open Magpie Web in the Feishu desktop sidebar. The page uses the Web address you enter and reads no Magpie data.", "zh": "生成飞书链接,在飞书桌面端左侧导航打开 Magpie Web。页面使用你填写的 Web 地址,不读取 Magpie 数据。" } },
{ "package": "@magpie-community/page-chat", "name": "Chat", "kind": "page", "community": true,
"summary": { "en": "A chat page in magpie's window by Magic_zero: talk to magpie's own models with your MCP servers, instructions and skills, images and LaTeX. Runs a local service on 127.0.0.1 that only its own page can use.", "zh": "Magic_zero 做的 magpie 窗口内「对话」页面:用 magpie 自己的模型聊天,带上你的 MCP 服务器、指令和技能,支持图片与 LaTeX。本地服务只在 127.0.0.1,只给自己的页面用。" } },
{ "package": "@magpie-community/page-agent-office", "name": "Agent Office", "kind": "page", "community": true,