Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/proxy-plugin-anthropic-ping/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"dependencies": {
"@jixo/proxy-plugin": "workspace:*",
"@jixo/proxy-plugin-server": "workspace:*",
"jmespath": "^0.16.0"
},
"devDependencies": {
Expand Down
28 changes: 12 additions & 16 deletions packages/proxy-plugin-anthropic-ping/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* - debug: 是否开启调试日志
*/

import { definePlugin, getPluginConfigWithDefaults } from "@jixo/proxy-plugin";
import { createProxyServer } from "@jixo/proxy-plugin-server";
import { getPluginConfigWithDefaults } from "@jixo/proxy-plugin";
import { createAnthropicPingPlugin } from "./plugin";

export { AnthropicPingMiddleware } from "./ping-middleware";
Expand Down Expand Up @@ -52,19 +53,15 @@ export interface AnthropicPingConfig {
}

if (import.meta.main) {
// 从环境变量 PLUGIN_CONFIG 读取配置
const config = getPluginConfigWithDefaults({
maxKeepAliveDurationMs: 60 * 60 * 1000, // 60 分钟
cacheTtlMs: 5 * 60 * 1000, // 5 分钟,Anthropic 官方值
pingLeadTimeMs: 1 * 60 * 1000, // 提前 1 分钟开始保活
maxKeepAliveDurationMs: 60 * 60 * 1000,
cacheTtlMs: 5 * 60 * 1000,
pingLeadTimeMs: 1 * 60 * 1000,
pollingIntervalMs: 30 * 1000,
debug: false,
});

// 也支持通过环境变量直接配置(向后兼容)
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1" || config.debug;

// 计算实际的 idle 阈值
const idleThresholdMs = config.cacheTtlMs - config.pingLeadTimeMs;

console.log("[AnthropicPing] Starting with config:", {
Expand All @@ -76,12 +73,11 @@ if (import.meta.main) {
debug,
});

void idleThresholdMs;
void config;
void debug;
void definePlugin;
void createAnthropicPingPlugin;
throw new Error(
`[anthropic-ping] standalone plugin server mode is no longer supported: hooks are now in-process and streaming-native.`,
);
createProxyServer({
plugin: createAnthropicPingPlugin({
...config,
debug,
idleThresholdMs,
}),
});
}
3 changes: 2 additions & 1 deletion packages/proxy-plugin-anthropic4codex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"test": "bun test"
},
"dependencies": {
"@jixo/proxy-plugin": "workspace:*"
"@jixo/proxy-plugin": "workspace:*",
"@jixo/proxy-plugin-server": "workspace:*"
},
"devDependencies": {
"@types/bun": "latest",
Expand Down
12 changes: 7 additions & 5 deletions packages/proxy-plugin-anthropic4codex/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* - Response Hook: 将 Claude Messages SSE 响应转换为 Codex Responses SSE 响应
*/

import { createProxyServer } from "@jixo/proxy-plugin-server";
import { createCodexPlugin } from "./plugin";

// Plugin
Expand Down Expand Up @@ -93,9 +94,10 @@ export type {

// 作为独立进程运行时启动服务器
if (import.meta.main) {
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1";
void debug;
throw new Error(
`[anthropic4codex] standalone plugin server mode is no longer supported: hooks are now in-process and streaming-native.`,
);
const config = JSON.parse(process.env.PLUGIN_CONFIG || "{}");
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1" || config.debug;

createProxyServer({
plugin: createCodexPlugin({ ...config, debug }),
});
}
3 changes: 2 additions & 1 deletion packages/proxy-plugin-anthropic4droid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"dependencies": {
"@anthropic-ai/sdk": "^0.71.2",
"@jixo/proxy-plugin": "workspace:*"
"@jixo/proxy-plugin": "workspace:*",
"@jixo/proxy-plugin-server": "workspace:*"
},
"devDependencies": {
"@types/bun": "latest",
Expand Down
12 changes: 7 additions & 5 deletions packages/proxy-plugin-anthropic4droid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* - Response Hook: 将上游错误重写为 context_length_exceeded 以触发 auto-compact
*/

import { createProxyServer } from "@jixo/proxy-plugin-server";
import { createDroidPlugin } from "./plugin";

// 导出公共 API
Expand Down Expand Up @@ -39,9 +40,10 @@ export type { RequestBody, Message, TextBlock, RewriteResult } from "./types";

// 作为独立进程运行时启动服务器
if (import.meta.main) {
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1";
void debug;
throw new Error(
`[anthropic4droid] standalone plugin server mode is no longer supported: hooks are now in-process and streaming-native.`,
);
const config = JSON.parse(process.env.PLUGIN_CONFIG || "{}");
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1" || config.debug;

createProxyServer({
plugin: createDroidPlugin({ ...config, debug }),
});
}
3 changes: 2 additions & 1 deletion packages/proxy-plugin-gemini4droid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test": "bun test"
},
"dependencies": {
"@jixo/proxy-plugin": "workspace:*"
"@jixo/proxy-plugin": "workspace:*",
"@jixo/proxy-plugin-server": "workspace:*"
},
"devDependencies": {
"@types/bun": "latest",
Expand Down
30 changes: 11 additions & 19 deletions packages/proxy-plugin-gemini4droid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* droid --provider anthropic → proxy → gemini4droid → 用户的 Gemini 服务
*/

import { definePlugin } from "@jixo/proxy-plugin";
import { createProxyServer } from "@jixo/proxy-plugin-server";
import { createGeminiPlugin } from "./plugin";

// 导出插件工厂
Expand Down Expand Up @@ -75,35 +75,27 @@ export type {
RequestConversionResult,
ResponseConversionResult,
} from "./types";
export const createPlugin=createGeminiPlugin

export const createPlugin = createGeminiPlugin;

// 作为独立进程运行时启动服务器
if (import.meta.main) {
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1";

// 从环境变量或 PLUGIN_CONFIG 读取配置
let upstreamBaseUrl = process.env.GEMINI_UPSTREAM_URL;
const config = JSON.parse(process.env.PLUGIN_CONFIG || "{}");
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1" || config.debug;

// 尝试从 PLUGIN_CONFIG 读取(proxy hook config 传递)
if (!upstreamBaseUrl && process.env.PLUGIN_CONFIG) {
try {
const pluginConfig = JSON.parse(process.env.PLUGIN_CONFIG);
upstreamBaseUrl = pluginConfig.upstreamBaseUrl;
} catch {
// ignore parse errors
}
}
// 从环境变量或 config 读取 upstream URL
const upstreamBaseUrl = process.env.GEMINI_UPSTREAM_URL || config.upstreamBaseUrl;

console.log("Starting gemini4droid plugin server...");
if (upstreamBaseUrl) {
console.log(`Upstream URL: ${upstreamBaseUrl}`);
}

definePlugin(
createGeminiPlugin({
createProxyServer({
plugin: createGeminiPlugin({
...config,
debug,
upstreamBaseUrl,
}),
{ debug }
);
});
}
3 changes: 2 additions & 1 deletion packages/proxy-plugin-openai4droid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"test": "bun test"
},
"dependencies": {
"@jixo/proxy-plugin": "workspace:*"
"@jixo/proxy-plugin": "workspace:*",
"@jixo/proxy-plugin-server": "workspace:*"
},
"devDependencies": {
"@types/bun": "latest",
Expand Down
12 changes: 7 additions & 5 deletions packages/proxy-plugin-openai4droid/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* 注意:websearch 响应解析由 droid-patch 的 websearch-native.ts 处理
*/

import { createProxyServer } from "@jixo/proxy-plugin-server";
import { createDroidPlugin } from "./plugin";

// 导出公共 API
Expand All @@ -20,9 +21,10 @@ export type { RequestBody, RewriteResult, AnyTool, WebSearchTool, FunctionTool }

// 作为独立进程运行时启动服务器
if (import.meta.main) {
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1";
void debug;
throw new Error(
`[openai4droid] standalone plugin server mode is no longer supported: hooks are now in-process and streaming-native.`,
);
const config = JSON.parse(process.env.PLUGIN_CONFIG || "{}");
const debug = process.env.DEBUG === "true" || process.env.DEBUG === "1" || config.debug;

createProxyServer({
plugin: createDroidPlugin({ ...config, debug }),
});
}
1 change: 1 addition & 0 deletions packages/proxy-plugin-responses4claudecode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@jixo/proxy-plugin": "workspace:*",
"@jixo/proxy-plugin-server": "workspace:*",
"zod": "^4.1.12"
},
"devDependencies": {
Expand Down
19 changes: 9 additions & 10 deletions packages/proxy-plugin-responses4claudecode/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
* 2. 作为模块导入: import { createResponses4ClaudeCodePlugin } from "@jixo/proxy-plugin-responses4claudecode"
*/

import { startPlugin } from "./plugin";
import { createProxyServer } from "@jixo/proxy-plugin-server";
import { createResponses4ClaudeCodePlugin } from "./plugin";

// 导出公共 API
export { startPlugin, createResponses4ClaudeCodePlugin, type Responses4ClaudeCodePluginOptions } from "./plugin";
export { createResponses4ClaudeCodePlugin, type Responses4ClaudeCodePluginOptions } from "./plugin";
export { isClaudeRequest, rewriteRequest, convertRequest } from "./request-converter";
export { SSEStreamConverter, convertSSEResponse, convertErrorResponse, convertSuccessResponse, isCodexSuccessResponse } from "./response-converter";
export * from "./types";
Expand All @@ -23,14 +24,12 @@ export * from "./task-executor";

// 如果直接运行,启动插件服务器
if (import.meta.main) {
const config = JSON.parse(process.env.PLUGIN_CONFIG || "{}");
const debug = process.env.DEBUG_RESPONSES4CLAUDECODE === "1" || config.debug;

console.log(`[responses4claudecode] Starting plugin server...`);

startPlugin()
.then(() => {
console.log(`[responses4claudecode] Ready to convert Claude Messages API → OpenAI Responses API`);
})
.catch((err) => {
console.error(`[responses4claudecode] Failed to start:`, err);
process.exit(1);
});
createProxyServer({
plugin: createResponses4ClaudeCodePlugin({ ...config, debug }),
});
}
13 changes: 1 addition & 12 deletions packages/proxy-plugin-responses4claudecode/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { z } from "zod";
import {
startPluginServer,
type RequestHookParams,
type RequestHookResult,
type ResponseHookParams,
Expand Down Expand Up @@ -378,14 +377,4 @@ export function createResponses4ClaudeCodePlugin(options: Responses4ClaudeCodePl
};
}

/**
* 启动插件服务器
*/
export async function startPlugin(): Promise<void> {
const debug = process.env.DEBUG_RESPONSES4CLAUDECODE === "1";
const plugin = createResponses4ClaudeCodePlugin({ debug });
void plugin;
throw new Error(
`[responses4claudecode] startPlugin is no longer supported: hooks are now in-process and streaming-native.`,
);
}

Loading