opencode-claude-max-proxy 1.11.2 → 1.12.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.
- package/README.md +26 -24
- package/dist/cli-s4sk7eks.js +13102 -0
- package/dist/cli.js +30 -0
- package/dist/server.js +10 -0
- package/package.json +20 -17
- package/bin/claude-proxy-supervisor.sh +0 -62
- package/bin/claude-proxy.ts +0 -33
- package/bin/docker-auth.sh +0 -77
- package/bin/docker-entrypoint.sh +0 -24
- package/bin/oc.sh +0 -62
- package/src/logger.ts +0 -72
- package/src/mcpTools.ts +0 -185
- package/src/plugin/claude-max-headers.ts +0 -52
- package/src/proxy/agentDefs.ts +0 -102
- package/src/proxy/agentMatch.ts +0 -93
- package/src/proxy/passthroughTools.ts +0 -108
- package/src/proxy/server.ts +0 -1172
- package/src/proxy/sessionStore.ts +0 -94
- package/src/proxy/types.ts +0 -13
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File-based session store for cross-proxy session resume.
|
|
3
|
-
*
|
|
4
|
-
* When running per-terminal proxies (each on a different port),
|
|
5
|
-
* sessions need to be shared so you can resume a conversation
|
|
6
|
-
* started in one terminal from another. This stores session
|
|
7
|
-
* mappings in a JSON file that all proxy instances read/write.
|
|
8
|
-
*
|
|
9
|
-
* Format: { [key]: { claudeSessionId, createdAt, lastUsedAt } }
|
|
10
|
-
* Keys are either OpenCode session IDs or conversation fingerprints.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from "fs"
|
|
14
|
-
import { join, dirname } from "path"
|
|
15
|
-
import { homedir } from "os"
|
|
16
|
-
|
|
17
|
-
export interface StoredSession {
|
|
18
|
-
claudeSessionId: string
|
|
19
|
-
createdAt: number
|
|
20
|
-
lastUsedAt: number
|
|
21
|
-
messageCount: number
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const SESSION_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
|
|
25
|
-
|
|
26
|
-
function getStorePath(): string {
|
|
27
|
-
const dir = process.env.CLAUDE_PROXY_SESSION_DIR
|
|
28
|
-
|| join(homedir(), ".cache", "opencode-claude-max-proxy")
|
|
29
|
-
if (!existsSync(dir)) {
|
|
30
|
-
mkdirSync(dir, { recursive: true })
|
|
31
|
-
}
|
|
32
|
-
return join(dir, "sessions.json")
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function readStore(): Record<string, StoredSession> {
|
|
36
|
-
const path = getStorePath()
|
|
37
|
-
if (!existsSync(path)) return {}
|
|
38
|
-
try {
|
|
39
|
-
const data = readFileSync(path, "utf-8")
|
|
40
|
-
const store = JSON.parse(data) as Record<string, StoredSession>
|
|
41
|
-
// Prune expired entries
|
|
42
|
-
const now = Date.now()
|
|
43
|
-
const pruned: Record<string, StoredSession> = {}
|
|
44
|
-
for (const [key, session] of Object.entries(store)) {
|
|
45
|
-
if (now - session.lastUsedAt < SESSION_TTL_MS) {
|
|
46
|
-
pruned[key] = session
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return pruned
|
|
50
|
-
} catch {
|
|
51
|
-
return {}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function writeStore(store: Record<string, StoredSession>): void {
|
|
56
|
-
const path = getStorePath()
|
|
57
|
-
const tmp = path + ".tmp"
|
|
58
|
-
try {
|
|
59
|
-
writeFileSync(tmp, JSON.stringify(store, null, 2))
|
|
60
|
-
renameSync(tmp, path) // atomic write
|
|
61
|
-
} catch {
|
|
62
|
-
// If rename fails, try direct write
|
|
63
|
-
try {
|
|
64
|
-
writeFileSync(path, JSON.stringify(store, null, 2))
|
|
65
|
-
} catch {}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function lookupSharedSession(key: string): StoredSession | undefined {
|
|
70
|
-
const store = readStore()
|
|
71
|
-
const session = store[key]
|
|
72
|
-
if (!session) return undefined
|
|
73
|
-
if (Date.now() - session.lastUsedAt >= SESSION_TTL_MS) return undefined
|
|
74
|
-
return session
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function storeSharedSession(key: string, claudeSessionId: string, messageCount?: number): void {
|
|
78
|
-
const store = readStore()
|
|
79
|
-
const existing = store[key]
|
|
80
|
-
store[key] = {
|
|
81
|
-
claudeSessionId,
|
|
82
|
-
createdAt: existing?.createdAt || Date.now(),
|
|
83
|
-
lastUsedAt: Date.now(),
|
|
84
|
-
messageCount: messageCount ?? existing?.messageCount ?? 0,
|
|
85
|
-
}
|
|
86
|
-
writeStore(store)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function clearSharedSessions(): void {
|
|
90
|
-
const path = getStorePath()
|
|
91
|
-
try {
|
|
92
|
-
writeFileSync(path, "{}")
|
|
93
|
-
} catch {}
|
|
94
|
-
}
|
package/src/proxy/types.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface ProxyConfig {
|
|
2
|
-
port: number
|
|
3
|
-
host: string
|
|
4
|
-
debug: boolean
|
|
5
|
-
idleTimeoutSeconds: number
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const DEFAULT_PROXY_CONFIG: ProxyConfig = {
|
|
9
|
-
port: 3456,
|
|
10
|
-
host: "127.0.0.1",
|
|
11
|
-
debug: process.env.CLAUDE_PROXY_DEBUG === "1",
|
|
12
|
-
idleTimeoutSeconds: 120
|
|
13
|
-
}
|