opencode-magpie-plugin 0.2.1 → 0.2.2

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 CHANGED
@@ -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: 'http.request', callback: (event: {
68
- sessionID: string;
69
- request: Request;
70
- }) => Promise<void>) => Promise<Registration>;
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 = [];
@@ -642,6 +653,12 @@ const setupPlugin = async (ctx) => {
642
653
  editor.add(entry);
643
654
  });
644
655
  }));
656
+ for (const name of [
657
+ "context",
658
+ "compaction",
659
+ "generate",
660
+ "title"
661
+ ]) await track(ctx.session.hook(name, normalizeOpenAICallIDs, { providerID: "openai" }));
645
662
  await track(ctx.session.hook("http.request", async (event) => {
646
663
  const url = new URL(event.request.url);
647
664
  if (url.origin !== baseURL || !url.pathname.startsWith("/v1/")) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-magpie-plugin",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Discover Magpie providers and models in OpenCode V2 with built-in pricing and automatic local gateway startup",
5
5
  "type": "module",
6
6
  "main": "./dist/index.mjs",