@rynfar/meridian 1.24.1 → 1.25.1

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.
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Meridian OpenCode plugin.
3
+ *
4
+ * Injects headers into every Anthropic API request so the proxy can:
5
+ * 1. Track sessions reliably (x-opencode-session / x-opencode-request)
6
+ * 2. Select the right model tier per agent (x-opencode-agent-mode)
7
+ * — primary agents get sonnet[1m] / opus[1m] (full 1M context)
8
+ * — subagents get sonnet / opus (200k, preserves rate-limit budget)
9
+ *
10
+ * Install once globally:
11
+ * meridian setup
12
+ *
13
+ * Or manually add to ~/.config/opencode/opencode.json:
14
+ * { "plugin": ["/absolute/path/to/plugin/meridian.ts"] }
15
+ */
16
+
17
+ type Plugin = (input: any) => Promise<{
18
+ "chat.headers"?: (
19
+ input: {
20
+ sessionID: string
21
+ // Typed as string in the SDK types but is actually the full agent
22
+ // object at runtime: { name: string; mode: "primary" | "subagent" | "all" }
23
+ agent: string | { name?: string; mode?: string }
24
+ model: { providerID: string }
25
+ message: { id: string }
26
+ },
27
+ output: { headers: Record<string, string> }
28
+ ) => Promise<void>
29
+ }>
30
+
31
+ const MeridianPlugin: Plugin = async () => {
32
+ return {
33
+ "chat.headers": async (incoming, output) => {
34
+ // Only inject headers for Anthropic provider requests
35
+ if (incoming.model.providerID !== "anthropic") return
36
+
37
+ // Session tracking
38
+ output.headers["x-opencode-session"] = incoming.sessionID
39
+ output.headers["x-opencode-request"] = incoming.message.id
40
+
41
+ // Agent mode — runtime value is the full agent object even though
42
+ // the TypeScript type says string. Read .mode directly.
43
+ const agent = incoming.agent as { name?: string; mode?: string } | string
44
+ output.headers["x-opencode-agent-mode"] = typeof agent === "object"
45
+ ? (agent.mode ?? "primary")
46
+ : "primary"
47
+ output.headers["x-opencode-agent-name"] = typeof agent === "object"
48
+ ? (agent.name ?? "unknown")
49
+ : String(agent)
50
+ },
51
+ }
52
+ }
53
+
54
+ export default MeridianPlugin