agent-lorca 0.1.0: Lorca as a Magpie agent (#1230)

Lorca's plugin returns its provider as one merged object (custom.custom:magpie), with no changed_at, so unwire leaves the user's credentials.json as it was. Needs magpie v0.1.4336 (8a017b583), which writes a connect-only plugin's merged-only keys.

Run at 883ea48: bun test packages/lorca 2 pass; scripts/check.mjs lorca ok; a magpie sandbox test loading this lorca.agent.js connected and unwired with no file, {"anthropic":"k"}, and a file with custom:gemini and a changed_at map: "{}" and the two files back as they were.
Not tried: the real Lorca app (author tested Desktop 0.1.22 / CLI 0.1.26).
This commit is contained in:
Ethan Chen
2026-11-17 02:15:04 +08:00
committed by GitHub
parent f10738917f
commit ffc98f640a
7 changed files with 395 additions and 0 deletions
+1
View File
@@ -299,6 +299,7 @@ it off puts the config back.
| [rhino9-ai](packages/rhino9-ai) | [Magpie-Rhino](https://github.com/mikidaren/Magpie-Rhino) for Rhino 9 on Windows, with Magpie models, custom groups and routing strategies through Rhino MCP. Install the companion `.yak`, restart Rhino once, then open its AI panel and choose **Magpie**; no command required |
| [zycode](packages/zycode) | [zycode](https://github.com/zy1233/pi-python) (`zypi`, the VS Code extension, the ACP agent): Magpie's model in the `[model]` table of `~/.pi-python/agent.toml`, set by a host part that follows `local.env` and puts the file back byte for byte; restart zycode after choosing a model |
| [meowcode](packages/meowcode) | [MeowCode](https://github.com/MuLiuSaMa/MeowCode): magpie's models in MeowCode's own model list, written to an overlay file beside its settings that MeowCode reads at start-up; restart MeowCode after choosing a model |
| [lorca](packages/lorca) | [Lorca](https://lorca.app): `~/.lorca/credentials.json` as a custom provider, mirroring Magpie's models with thinking levels and MCP support via `~/.lorca/mcp.json` |
```sh
magpie plugin add @magpie-community/agent-<name>
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Magpie Community
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+162
View File
@@ -0,0 +1,162 @@
# @magpie-community/agent-lorca
Magpie 官方规范 Agent 插件:将 Magpie 统一网关、模型目录与共享 MCP 工具库无缝接入 [Lorca](https://lorca.app)。
通过本插件,Lorca 客户端中的「Magpie」自定义 Provider 将自动跟随 Magpie 统一路由走,无需手动配置接口地址、API Key 或繁琐的模型上下文参数;同时支持将 Magpie Library 的 MCP 工具直接同步给 Lorca。
---
## 核心特性
- **网关与模型同步**:自动将 Magpie 网关地址(`gateway.v1`)与 API Key 写入 Lorca 的凭据配置,并自动镜像 Magpie 当前的全部可用模型。
- **思维链 / 思考档位完整映射**:全面支持 Lorca 内核认可的全部 Thinking Levels(`off`、`minimal`、`low`、`medium`、`high`、`xhigh`、`max`),并将 Magpie 的 `none` 自动映射为 `off`。
- **崩溃防护(对抗式枚举过滤)**:严格校验并过滤非法思考档位。由于 Lorca 遇到未知 level 时会直接抛弃整个 `custom` 配置段(导致所有自定义 Provider 消失),插件内置硬核过滤守卫,确保配置百分之百安全有效。
- **MCP 工具库打通(Magpie Library)**:支持 Lorca 的 Claude 格式 MCP 规范(`~/.lorca/mcp.json`),可通过 `magpie library sync` 一键将全局 MCP Server 分发给 Lorca。
- **流量精准归因(UA 识别)**:声明 `ua: ["lorca"]`,使 Lorca 发出的推理请求在 Magpie 监控面板与审计日志(`usage.jsonl`)中清晰归因,方便统计与调试。
- **原子级合并与纯净卸载**:采用 `merge: ["custom.custom:magpie"]` 对象级管理。连接时精准合并,断开或切换时整段彻底清理,绝不残留 `{}` 空壳对象,亦不破坏用户自建的其他 Provider。
---
## 快速上手
### 1. 安装插件
```sh
# 本地目录开发测试安装
magpie plugin add /path/to/magpie-plugin-lorca
# 或从 npm / Magpie 官方插件市场安装(发布后)
magpie plugin add @magpie-community/agent-lorca
```
### 2. 启用连接
```sh
# 将 Magpie 网关写入 Lorca 的 Provider 配置
magpie lorca provider magpie
```
> **注意**:Lorca 本地后台服务仅在启动初始化时读取一次 `~/.lorca/credentials.json`。配置写入后,请**彻底退出 Lorca 并重新打开**(若后台常驻,需确保完整重启应用),新 Provider 即可在界面中显示。
### 3. 断开连接
```sh
# 恢复默认状态,彻底卸载 Magpie Provider
magpie lorca default
```
Magpie 会自动执行原子卸载:如果该 Provider 是本次接管生成的,则完整移除;如果是接管前用户手建的同名配置,则逐字节还原,完全不干扰其他配置。
---
## MCP 工具库同步(Magpie Library)
插件声明了对 Lorca 原生 MCP 配置的托管支持:
```javascript
library: {
mcp: "~/.lorca/mcp.json",
mcpFormat: "claude"
}
```
你可以直接利用 Magpie 的 Library 能力,统一管理并分发 MCP 工具给 Lorca:
```sh
# 将指定的 MCP 服务分配给 Lorca
magpie library mcp agents <mcp-name> lorca
# 或者一键同步所有已分配的 MCP 服务到 ~/.lorca/mcp.json
magpie library sync
```
Lorca 读取 `~/.lorca/mcp.json`(标准 Claude Desktop 格式 `{"mcpServers": { ... }}`),即可在 Agent 会话与自动化流程中直接调用这些工具。
---
## 机制解析与写入格式
Lorca 的 Provider 凭证保存在 `~/.lorca/credentials.json`,自定义项置于 `custom` 字段下:
```json
{
"custom": {
"custom:magpie": {
"name": "Magpie",
"api": "chat-completions",
"base_url": "http://127.0.0.1:3425/v1",
"api_key": "magpie-lorca",
"models": [
{
"id": "deepseek-v4.1-flash",
"name": "DeepSeek V4.1 Flash",
"context_window": 131072,
"max_output": 8192,
"images": true,
"levels": ["off", "low", "medium", "high", "xhigh", "max"]
}
],
"created_at": 1794836955
}
}
}
```
### 字段转换规则
| Magpie 模型字段 | Lorca 模型字段 | 说明 |
| :--- | :--- | :--- |
| `id` | `id` | 模型标识(必填,缺失或非法的项自动跳过) |
| `name` | `name` | 模型显示名称 |
| `context` | `context_window` | 上下文窗口 Token 数(正数时写入) |
| `output` | `max_output` | 单次最大输出 Token 数(正数时写入) |
| `images` | `images` | 是否支持图片输入(布尔值) |
| `efforts` | `levels` | 思考档位映射(`none` 映射为 `off`,支持 `minimal/low/medium/high/xhigh/max`) |
> **关键技术内幕**:Lorca 采用强类型的反序列化机制。一旦 `levels` 数组中出现任意一个 Lorca 无法识别的字符串,或者 `models` 键缺失,Lorca 将拒绝加载整个 `custom` 对象,导致界面中所有自定义 Provider 同时失踪。本插件实现了严格的白名单校验与类型防御,杜绝此类隐患。
---
## 默认模型说明
- Lorca 将 `models` 列表中的**第一项**作为默认模型。
- 本插件写入时按照 Magpie 模型目录的推荐顺序排列。
- 如需在 Lorca 中切换默认模型,可直接在 Lorca 界面下拉菜单中选择,Lorca 会自动将所选模型调整到首位。
---
## 边界与注意事项
1. **配置重启生效**:Lorca 启动后会将 Provider 驻留内存,目前无动态热重载机制。更改配置后请务必重启 Lorca 应用。
2. **多模型管理隔离**:`custom:magpie` 下的模型列表由 Magpie 自动镜像。如果您希望在 Lorca 中使用完全自定义的模型列表且不被 Magpie 刷新,建议在 Lorca 界面中另建一个独立 Provider(同样填入 Magpie 网关地址 `http://127.0.0.1:3425/v1`),该条目将受到 Magpie 的永久避让保护。
3. **权限说明**:若首次由插件自动创建 `~/.lorca/credentials.json`,文件权限将遵循系统的 umask 规则(通常为 644 或 600)。
---
## 开发者调试
可以在隔离的临时沙箱中验证插件行为,不影响本机真实配置:
```sh
# 构造独立沙箱环境
sb=$(mktemp -d)
alias m="env HOME=$sb XDG_CONFIG_HOME=$sb/.config XDG_CACHE_HOME=$sb/.cache magpie"
# 添加本地插件并测试连接
m plugin add .
m lorca provider magpie
cat "$sb/.lorca/credentials.json"
# 测试断开并验证清理效果
m lorca default
cat "$sb/.lorca/credentials.json"
# 清理沙箱
rm -rf "$sb"
```
---
## 许可证
本项目遵循 [MIT License](./LICENSE)。
File diff suppressed because one or more lines are too long
+62
View File
@@ -0,0 +1,62 @@
import { expect, test } from "bun:test"
import { agent, connect } from "./lorca.agent.js"
const gateway = { url: "http://127.0.0.1:3425", v1: "http://127.0.0.1:3425/v1", key: "magpie-lorca" }
test("exports agent metadata for Lorca", () => {
expect(agent).toMatchObject({
id: "lorca",
name: "Lorca",
config: "~/.lorca/credentials.json",
format: "json",
dir: "~/.lorca",
ua: ["lorca"],
library: {
mcp: "~/.lorca/mcp.json",
mcpFormat: "claude",
},
merge: ["custom.custom:magpie"],
})
})
test("connect maps models, gateway and thinking levels correctly", () => {
const models = [
{
id: "deepseek/pro",
name: "DeepSeek Pro",
context: 128000,
output: 8192,
images: true,
efforts: ["none", "minimal", "low", "high", "unknown_level"],
},
{
id: "plain-model",
efforts: [],
},
null,
{},
]
const out = connect({ gateway, models })
const provider = out["custom.custom:magpie"]
expect(provider).toBeDefined()
expect(provider.name).toBe("Magpie")
expect(provider.api).toBe("chat-completions")
expect(provider.base_url).toBe("http://127.0.0.1:3425/v1")
expect(provider.api_key).toBe("magpie-lorca")
expect(typeof provider.created_at).toBe("number")
expect(provider.models).toHaveLength(2)
expect(provider.models[0]).toEqual({
id: "deepseek/pro",
name: "DeepSeek Pro",
context_window: 128000,
max_output: 8192,
images: true,
levels: ["off", "minimal", "low", "high"],
})
expect(provider.models[1]).toEqual({
id: "plain-model",
images: false,
})
})
+31
View File
@@ -0,0 +1,31 @@
{
"name": "@magpie-community/agent-lorca",
"version": "0.1.0",
"description": "Lorca (lorca.app) as a magpie agent: writes Magpie's gateway, models and MCP servers into Lorca's credentials",
"type": "module",
"files": [
"lorca.agent.js",
"README.md",
"LICENSE"
],
"keywords": [
"magpie",
"magpie-agent",
"lorca",
"llm-gateway"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/magpie-community/plugins.git",
"directory": "packages/lorca"
},
"scripts": {
"test": "bun test"
},
"magpie": {
"agent": "./lorca.agent.js",
"name": "Lorca",
"icon": "https://lorca.app/icon.png"
}
}
+1
View File
@@ -299,6 +299,7 @@
{ "package": "@magpie-community/agent-wave", "name": "Wave", "kind": "agent", "community": true, "icon": "https://github.com/wavetermdev.png", "summary": {"en": "Wave Terminal (waveterm) on magpie's Agents page: pick one of magpie's models for it, and switch it off to put its config back.", "zh": "把 Wave Terminal(waveterm)加到 magpie 的 Agent 页:给它选 magpie 的模型,关掉即恢复它原来的配置。"}},
{ "package": "@magpie-community/agent-zycode", "name": "zycode", "kind": "agent", "community": true, "summary": {"en": "zycode (zypi, the VS Code extension, the ACP agent) on magpie's Agents page: pick one of magpie's models for it, and switch it off to put agent.toml back. A host part copies the model into the [model] table of agent.toml, because magpie cannot edit TOML. Restart zycode after a change.", "zh": "把 zycode(zypi、VS Code 扩展、ACP agent)加到 magpie 的 Agent 页:给它选 magpie 的模型,关掉即恢复 agent.toml。magpie 不能编辑 TOML,所以由宿主部分把模型写进 agent.toml 的 [model] 表。切换后需重启 zycode。"}},
{ "package": "@magpie-community/agent-meowcode", "name": "MeowCode", "kind": "agent", "community": true, "summary": {"en": "MeowCode on magpie's Agents page: magpie's models appear in MeowCode's own model list, written to an overlay file MeowCode reads at start-up. Restart MeowCode after choosing a model.", "zh": "把 MeowCode 加到 magpie 的 Agent 页:magpie 的模型出现在 MeowCode 自己的模型列表里(启动时读取的覆盖层文件)。选择模型后需重启 MeowCode。"}},
{ "package": "@magpie-community/agent-lorca", "name": "Lorca", "kind": "agent", "community": true, "icon": "https://lorca.app/icon.png", "summary": {"en": "Lorca on magpie's Agents page: writes Magpie's gateway, models and MCP servers into Lorca's credentials (~/.lorca/credentials.json). Restart Lorca after connecting.", "zh": "把 Lorca 加到 magpie 的 Agent 页:将 Magpie 的网关、模型目录与 MCP 工具库写入 Lorca 的凭据配置(~/.lorca/credentials.json)。连接后需重启 Lorca。"}},
{ "package": "magpie-dafeiyu", "name": "DaFeiYu Desktop Pet", "kind": "page",
"summary": { "en": "A guide page for DaFeiYu, a desktop pet that lights a bulb per request and shows quota percentages and API balances. The pet is a separate Windows/macOS app you download yourself; this page does not install or start it. Artwork from PC2005-cloud/dsh-pet, non-commercial use only.", "zh": "蓝色大肥鱼桌宠的使用指南页:几个请求亮几盏灯,订阅显示额度百分比,API 钱包显示余额。桌宠是需要另外下载的 Windows/macOS 独立 App,本页不会安装或启动它。角色素材来自 PC2005-cloud/dsh-pet,仅限非商用。" } }
]