opencode-magpie-plugin 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/index.d.mts +23 -4
- package/dist/index.mjs +21 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ opencode service restart
|
|
|
71
71
|
|
|
72
72
|
### Provider 名称与模型 ID
|
|
73
73
|
|
|
74
|
-
显示名与 Magpie
|
|
74
|
+
显示名与 Magpie 保持一致,只去掉上下文窗口前的空格(`Claude Opus 5.5 @ 1m` 显示为 `Claude Opus 5.5 @1m`)。模型 ID 不变。内部 ID 使用命名空间,避免覆盖另一个 Cursor / WorkBuddy 插件:
|
|
75
75
|
|
|
76
76
|
| OpenCode 中的显示名 | 内部 provider ID | 示例模型引用 | 发给 Magpie 的 model |
|
|
77
77
|
| --- | --- | --- | --- |
|
|
@@ -139,6 +139,8 @@ Fast 模型优先采用内置表中明确登记的 Fast 费率及上下文档位
|
|
|
139
139
|
|
|
140
140
|
消息、工具调用和工具结果由 OpenCode 原生 runtime 编码,再由 Magpie 转接。插件传递 `X-Magpie-Session` 保持会话标识,并指定 HTTP 传输。模型上游支持的完整能力仍取决于 Magpie 和相应服务。
|
|
141
141
|
|
|
142
|
+
切换到 `openai` provider 时,插件会在请求编码前,将历史中超过 64 字符的工具调用 ID 稳定映射为 48 字符,并同步替换对应工具结果的 ID。这适用于 HTTP、WebSocket 及压缩请求,不修改持久化历史、工具参数或输出。实测范围见 [工具调用 ID 兼容性验证](docs/call-id-compatibility.md)。
|
|
143
|
+
|
|
142
144
|
思考档位按所选协议编码:Chat 使用 `reasoning_effort`,Responses 使用 `reasoning.effort`,Anthropic 使用 `thinking.type=adaptive` 配合 `output_config.effort`;Anthropic 的 `none` 关闭 thinking。
|
|
143
145
|
|
|
144
146
|
刷新成功时替换完整目录;刷新失败保留最近一次成功的目录。首次发现失败会报告初始化错误,不生成虚假的可用模型。
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
//#region src/call-ids.d.ts
|
|
2
|
+
type ModelMessages = {
|
|
3
|
+
messages: {
|
|
4
|
+
content: {
|
|
5
|
+
type: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
}[];
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
1
11
|
//#region src/opencode.d.ts
|
|
2
12
|
/** Structural subset of the OpenCode V2 plugin API; the host supplies the runtime. */
|
|
3
13
|
type Registration = {
|
|
@@ -64,11 +74,20 @@ type PluginContext = {
|
|
|
64
74
|
reload: () => Promise<void>;
|
|
65
75
|
};
|
|
66
76
|
session: {
|
|
67
|
-
hook: (name:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
77
|
+
hook: <Name extends keyof SessionHookEvents>(name: Name, callback: (event: SessionHookEvents[Name]) => Promise<void> | void, options?: {
|
|
78
|
+
providerID?: string;
|
|
79
|
+
}) => Promise<Registration>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
type SessionHookEvents = {
|
|
83
|
+
'http.request': {
|
|
84
|
+
sessionID: string;
|
|
85
|
+
request: Request;
|
|
71
86
|
};
|
|
87
|
+
context: ModelMessages;
|
|
88
|
+
compaction: ModelMessages;
|
|
89
|
+
generate: ModelMessages;
|
|
90
|
+
title: ModelMessages;
|
|
72
91
|
};
|
|
73
92
|
type Plugin2 = {
|
|
74
93
|
id: string;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as resolveModelPricingKey, n as getModelPricing } from "./model-pricing-BbteicIQ.mjs";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
3
3
|
import { access, mkdir, readFile, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { delimiter, dirname, join } from "node:path";
|
|
@@ -7,6 +7,17 @@ import { spawn } from "node:child_process";
|
|
|
7
7
|
import { constants } from "node:fs";
|
|
8
8
|
import { setTimeout } from "node:timers/promises";
|
|
9
9
|
|
|
10
|
+
//#region src/call-ids.ts
|
|
11
|
+
/** Normalize the outgoing semantic transcript before encoding, compression, or WS delta selection. */
|
|
12
|
+
const normalizeOpenAICallIDs = ({ messages }) => {
|
|
13
|
+
for (const message of messages) for (const part of message.content) {
|
|
14
|
+
if (part.type !== "tool-call" && part.type !== "tool-result") continue;
|
|
15
|
+
if (typeof part.id !== "string" || part.id.length <= 64) continue;
|
|
16
|
+
part.id = `call_${createHash("sha256").update(part.id).digest("base64url")}`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
10
21
|
//#region src/opencode.ts
|
|
11
22
|
const createTrackedSetup = () => {
|
|
12
23
|
const registrations = [];
|
|
@@ -302,6 +313,8 @@ const providerName = (model) => {
|
|
|
302
313
|
workbuddy: "WorkBuddy"
|
|
303
314
|
}[model.owned_by] ?? model.owned_by;
|
|
304
315
|
};
|
|
316
|
+
/** Magpie writes context windows as `Claude Opus 5.5 @ 1m`. The picker shows `@1m`. */
|
|
317
|
+
const displayName = (name) => name.replace(/@\s+(\d+(?:k|m))/gi, "@$1");
|
|
305
318
|
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
306
319
|
const invalidOptions = (path, reason) => /* @__PURE__ */ new Error(`Magpie 插件的 options 无效(opencode.jsonc → plugins → ${path}):${reason}。`);
|
|
307
320
|
const requiredString = (value, path) => {
|
|
@@ -391,7 +404,7 @@ const buildInventory = (rows, baseURL, options = {}) => {
|
|
|
391
404
|
const { cost } = modelCost(row, group, options.catalog);
|
|
392
405
|
const model = toClassicModelInfo(providerID, modelID, {
|
|
393
406
|
id: row.id,
|
|
394
|
-
name: row.display_name ?? modelID,
|
|
407
|
+
name: displayName(row.display_name ?? modelID),
|
|
395
408
|
cost,
|
|
396
409
|
limit: {
|
|
397
410
|
context: row.context_window || 128e3,
|
|
@@ -642,6 +655,12 @@ const setupPlugin = async (ctx) => {
|
|
|
642
655
|
editor.add(entry);
|
|
643
656
|
});
|
|
644
657
|
}));
|
|
658
|
+
for (const name of [
|
|
659
|
+
"context",
|
|
660
|
+
"compaction",
|
|
661
|
+
"generate",
|
|
662
|
+
"title"
|
|
663
|
+
]) await track(ctx.session.hook(name, normalizeOpenAICallIDs, { providerID: "openai" }));
|
|
645
664
|
await track(ctx.session.hook("http.request", async (event) => {
|
|
646
665
|
const url = new URL(event.request.url);
|
|
647
666
|
if (url.origin !== baseURL || !url.pathname.startsWith("/v1/")) return;
|
package/package.json
CHANGED