opencode-cursor-proxy 1.0.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/LICENSE +21 -0
- package/README.md +139 -0
- package/README.zh-CN.md +136 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/api/agent-service.d.ts +136 -0
- package/dist/lib/api/agent-service.js +938 -0
- package/dist/lib/api/agent-service.js.map +1 -0
- package/dist/lib/api/ai-service.d.ts +26 -0
- package/dist/lib/api/ai-service.js +38 -0
- package/dist/lib/api/ai-service.js.map +1 -0
- package/dist/lib/api/cursor-client.d.ts +119 -0
- package/dist/lib/api/cursor-client.js +511 -0
- package/dist/lib/api/cursor-client.js.map +1 -0
- package/dist/lib/api/cursor-models.d.ts +13 -0
- package/dist/lib/api/cursor-models.js +34 -0
- package/dist/lib/api/cursor-models.js.map +1 -0
- package/dist/lib/api/openai-compat.d.ts +10 -0
- package/dist/lib/api/openai-compat.js +262 -0
- package/dist/lib/api/openai-compat.js.map +1 -0
- package/dist/lib/api/proto/agent-messages.d.ts +25 -0
- package/dist/lib/api/proto/agent-messages.js +132 -0
- package/dist/lib/api/proto/agent-messages.js.map +1 -0
- package/dist/lib/api/proto/bidi.d.ts +17 -0
- package/dist/lib/api/proto/bidi.js +24 -0
- package/dist/lib/api/proto/bidi.js.map +1 -0
- package/dist/lib/api/proto/decoding.d.ts +19 -0
- package/dist/lib/api/proto/decoding.js +118 -0
- package/dist/lib/api/proto/decoding.js.map +1 -0
- package/dist/lib/api/proto/encoding.d.ts +64 -0
- package/dist/lib/api/proto/encoding.js +180 -0
- package/dist/lib/api/proto/encoding.js.map +1 -0
- package/dist/lib/api/proto/exec.d.ts +12 -0
- package/dist/lib/api/proto/exec.js +383 -0
- package/dist/lib/api/proto/exec.js.map +1 -0
- package/dist/lib/api/proto/index.d.ts +13 -0
- package/dist/lib/api/proto/index.js +10 -0
- package/dist/lib/api/proto/index.js.map +1 -0
- package/dist/lib/api/proto/interaction.d.ts +15 -0
- package/dist/lib/api/proto/interaction.js +99 -0
- package/dist/lib/api/proto/interaction.js.map +1 -0
- package/dist/lib/api/proto/kv.d.ts +52 -0
- package/dist/lib/api/proto/kv.js +156 -0
- package/dist/lib/api/proto/kv.js.map +1 -0
- package/dist/lib/api/proto/tool-calls.d.ts +9 -0
- package/dist/lib/api/proto/tool-calls.js +144 -0
- package/dist/lib/api/proto/tool-calls.js.map +1 -0
- package/dist/lib/api/proto/types.d.ts +201 -0
- package/dist/lib/api/proto/types.js +10 -0
- package/dist/lib/api/proto/types.js.map +1 -0
- package/dist/lib/auth/helpers.d.ts +40 -0
- package/dist/lib/auth/helpers.js +103 -0
- package/dist/lib/auth/helpers.js.map +1 -0
- package/dist/lib/auth/index.d.ts +7 -0
- package/dist/lib/auth/index.js +10 -0
- package/dist/lib/auth/index.js.map +1 -0
- package/dist/lib/auth/login.d.ts +55 -0
- package/dist/lib/auth/login.js +184 -0
- package/dist/lib/auth/login.js.map +1 -0
- package/dist/lib/config.d.ts +153 -0
- package/dist/lib/config.js +182 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/openai-compat/handler.d.ts +40 -0
- package/dist/lib/openai-compat/handler.js +808 -0
- package/dist/lib/openai-compat/handler.js.map +1 -0
- package/dist/lib/openai-compat/index.d.ts +9 -0
- package/dist/lib/openai-compat/index.js +13 -0
- package/dist/lib/openai-compat/index.js.map +1 -0
- package/dist/lib/openai-compat/types.d.ts +127 -0
- package/dist/lib/openai-compat/types.js +6 -0
- package/dist/lib/openai-compat/types.js.map +1 -0
- package/dist/lib/openai-compat/utils.d.ts +143 -0
- package/dist/lib/openai-compat/utils.js +348 -0
- package/dist/lib/openai-compat/utils.js.map +1 -0
- package/dist/lib/session-reuse.d.ts +88 -0
- package/dist/lib/session-reuse.js +198 -0
- package/dist/lib/session-reuse.js.map +1 -0
- package/dist/lib/storage.d.ts +55 -0
- package/dist/lib/storage.js +159 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/utils/cache.d.ts +131 -0
- package/dist/lib/utils/cache.js +297 -0
- package/dist/lib/utils/cache.js.map +1 -0
- package/dist/lib/utils/fetch.d.ts +84 -0
- package/dist/lib/utils/fetch.js +261 -0
- package/dist/lib/utils/fetch.js.map +1 -0
- package/dist/lib/utils/index.d.ts +13 -0
- package/dist/lib/utils/index.js +22 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/jwt.d.ts +40 -0
- package/dist/lib/utils/jwt.js +102 -0
- package/dist/lib/utils/jwt.js.map +1 -0
- package/dist/lib/utils/logger.d.ts +107 -0
- package/dist/lib/utils/logger.js +227 -0
- package/dist/lib/utils/logger.js.map +1 -0
- package/dist/lib/utils/model-resolver.d.ts +49 -0
- package/dist/lib/utils/model-resolver.js +503 -0
- package/dist/lib/utils/model-resolver.js.map +1 -0
- package/dist/lib/utils/request-pool.d.ts +38 -0
- package/dist/lib/utils/request-pool.js +105 -0
- package/dist/lib/utils/request-pool.js.map +1 -0
- package/dist/lib/utils/request-transformer.d.ts +87 -0
- package/dist/lib/utils/request-transformer.js +154 -0
- package/dist/lib/utils/request-transformer.js.map +1 -0
- package/dist/lib/utils/tokenizer.d.ts +14 -0
- package/dist/lib/utils/tokenizer.js +76 -0
- package/dist/lib/utils/tokenizer.js.map +1 -0
- package/dist/plugin/index.d.ts +8 -0
- package/dist/plugin/index.js +9 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/plugin.d.ts +21 -0
- package/dist/plugin/plugin.js +309 -0
- package/dist/plugin/plugin.js.map +1 -0
- package/dist/plugin/types.d.ts +120 -0
- package/dist/plugin/types.js +7 -0
- package/dist/plugin/types.js.map +1 -0
- package/dist/server.d.ts +15 -0
- package/dist/server.js +95 -0
- package/dist/server.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Configuration Module
|
|
3
|
+
*
|
|
4
|
+
* All configuration values should be defined here for easy management.
|
|
5
|
+
* Environment variables are read once at module load time.
|
|
6
|
+
*/
|
|
7
|
+
export declare const config: {
|
|
8
|
+
/**
|
|
9
|
+
* Debug and logging settings
|
|
10
|
+
*/
|
|
11
|
+
readonly debug: {
|
|
12
|
+
/** Enable verbose debug logging */
|
|
13
|
+
readonly enabled: boolean;
|
|
14
|
+
/** Enable performance timing logs */
|
|
15
|
+
readonly timing: boolean;
|
|
16
|
+
/** Log level: error, warn, info, debug */
|
|
17
|
+
readonly level: "error" | "warn" | "info" | "debug";
|
|
18
|
+
/** Enable request/response logging for debugging */
|
|
19
|
+
readonly requestLogging: boolean;
|
|
20
|
+
/** Log filtered IDs and item_references during request transformation */
|
|
21
|
+
readonly logFilteredIds: boolean;
|
|
22
|
+
/** Log multimodal content detection */
|
|
23
|
+
readonly logMultimodal: boolean;
|
|
24
|
+
/** Output logs in JSON format */
|
|
25
|
+
readonly jsonFormat: boolean;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Session management settings
|
|
29
|
+
*/
|
|
30
|
+
readonly session: {
|
|
31
|
+
/** Enable session reuse for tool calling */
|
|
32
|
+
readonly reuseEnabled: boolean;
|
|
33
|
+
/** Session timeout in milliseconds */
|
|
34
|
+
readonly timeoutMs: number;
|
|
35
|
+
/** Maximum number of cached sessions */
|
|
36
|
+
readonly maxSessions: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Cache settings
|
|
40
|
+
*/
|
|
41
|
+
readonly cache: {
|
|
42
|
+
/** Model cache TTL in milliseconds */
|
|
43
|
+
readonly modelTtlMs: number;
|
|
44
|
+
/** Maximum number of cached blobs */
|
|
45
|
+
readonly maxBlobs: number;
|
|
46
|
+
/** Maximum blob size in bytes */
|
|
47
|
+
readonly maxBlobSize: number;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Network request settings
|
|
51
|
+
*/
|
|
52
|
+
readonly network: {
|
|
53
|
+
/** Request timeout in milliseconds */
|
|
54
|
+
readonly requestTimeoutMs: number;
|
|
55
|
+
/** Maximum retry attempts for failed requests */
|
|
56
|
+
readonly maxRetries: number;
|
|
57
|
+
/** Base delay for exponential backoff in milliseconds */
|
|
58
|
+
readonly retryBaseDelayMs: number;
|
|
59
|
+
/** Maximum delay between retries in milliseconds */
|
|
60
|
+
readonly retryMaxDelayMs: number;
|
|
61
|
+
/** Enable automatic retry on transient errors */
|
|
62
|
+
readonly retryEnabled: boolean;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Heartbeat detection settings
|
|
66
|
+
*/
|
|
67
|
+
readonly heartbeat: {
|
|
68
|
+
/** Idle timeout after progress in milliseconds */
|
|
69
|
+
readonly idleAfterProgressMs: number;
|
|
70
|
+
/** Idle timeout before progress in milliseconds */
|
|
71
|
+
readonly idleBeforeProgressMs: number;
|
|
72
|
+
/** Maximum heartbeats allowed after progress */
|
|
73
|
+
readonly maxAfterProgress: number;
|
|
74
|
+
/** Maximum heartbeats allowed before progress */
|
|
75
|
+
readonly maxBeforeProgress: number;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Server settings (for standalone proxy)
|
|
79
|
+
*/
|
|
80
|
+
readonly server: {
|
|
81
|
+
/** Server port */
|
|
82
|
+
readonly port: number;
|
|
83
|
+
/** Server host */
|
|
84
|
+
readonly host: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Cursor API settings
|
|
88
|
+
*/
|
|
89
|
+
readonly api: {
|
|
90
|
+
/** Main API base URL */
|
|
91
|
+
readonly baseUrl: string;
|
|
92
|
+
/** Agent privacy mode URL */
|
|
93
|
+
readonly agentPrivacyUrl: string;
|
|
94
|
+
/** Agent non-privacy mode URL */
|
|
95
|
+
readonly agentNonPrivacyUrl: string;
|
|
96
|
+
/** Enable privacy mode */
|
|
97
|
+
readonly privacyMode: boolean;
|
|
98
|
+
/** Try API5 fallback endpoints */
|
|
99
|
+
readonly tryApi5Fallback: boolean;
|
|
100
|
+
/** Client version override */
|
|
101
|
+
readonly clientVersion: string;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Security settings
|
|
105
|
+
*/
|
|
106
|
+
readonly security: {
|
|
107
|
+
/** Enable shell command validation */
|
|
108
|
+
readonly validateShellCommands: boolean;
|
|
109
|
+
/** Maximum shell command execution time in milliseconds */
|
|
110
|
+
readonly shellTimeoutMs: number;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
export type Config = typeof config;
|
|
114
|
+
export type DebugConfig = typeof config.debug;
|
|
115
|
+
export type SessionConfig = typeof config.session;
|
|
116
|
+
export type CacheConfig = typeof config.cache;
|
|
117
|
+
export type NetworkConfig = typeof config.network;
|
|
118
|
+
export type HeartbeatConfig = typeof config.heartbeat;
|
|
119
|
+
export type ServerConfig = typeof config.server;
|
|
120
|
+
export type ApiConfig = typeof config.api;
|
|
121
|
+
export type SecurityConfig = typeof config.security;
|
|
122
|
+
/**
|
|
123
|
+
* Check if debug mode is enabled
|
|
124
|
+
*/
|
|
125
|
+
export declare function isDebugEnabled(): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Check if timing logs are enabled
|
|
128
|
+
*/
|
|
129
|
+
export declare function isTimingEnabled(): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Check if session reuse is enabled
|
|
132
|
+
*/
|
|
133
|
+
export declare function isSessionReuseEnabled(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Get the effective log level
|
|
136
|
+
*/
|
|
137
|
+
export declare function getLogLevel(): "error" | "warn" | "info" | "debug";
|
|
138
|
+
/**
|
|
139
|
+
* Check if request logging is enabled
|
|
140
|
+
*/
|
|
141
|
+
export declare function isRequestLoggingEnabled(): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Check if filtered IDs should be logged
|
|
144
|
+
*/
|
|
145
|
+
export declare function shouldLogFilteredIds(): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* Check if multimodal content should be logged
|
|
148
|
+
*/
|
|
149
|
+
export declare function shouldLogMultimodal(): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Check if JSON log format is enabled
|
|
152
|
+
*/
|
|
153
|
+
export declare function isJsonLogFormat(): boolean;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized Configuration Module
|
|
3
|
+
*
|
|
4
|
+
* All configuration values should be defined here for easy management.
|
|
5
|
+
* Environment variables are read once at module load time.
|
|
6
|
+
*/
|
|
7
|
+
// --- Environment Variable Helpers ---
|
|
8
|
+
function envBool(key, defaultValue) {
|
|
9
|
+
const value = process.env[key];
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
return defaultValue;
|
|
12
|
+
return value === "1" || value.toLowerCase() === "true";
|
|
13
|
+
}
|
|
14
|
+
function envInt(key, defaultValue) {
|
|
15
|
+
const value = process.env[key];
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
return defaultValue;
|
|
18
|
+
const parsed = parseInt(value, 10);
|
|
19
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
20
|
+
}
|
|
21
|
+
function envString(key, defaultValue) {
|
|
22
|
+
return process.env[key] ?? defaultValue;
|
|
23
|
+
}
|
|
24
|
+
// --- Configuration Object ---
|
|
25
|
+
export const config = {
|
|
26
|
+
/**
|
|
27
|
+
* Debug and logging settings
|
|
28
|
+
*/
|
|
29
|
+
debug: {
|
|
30
|
+
/** Enable verbose debug logging */
|
|
31
|
+
enabled: envBool("CURSOR_DEBUG", false),
|
|
32
|
+
/** Enable performance timing logs */
|
|
33
|
+
timing: envBool("CURSOR_TIMING", false),
|
|
34
|
+
/** Log level: error, warn, info, debug */
|
|
35
|
+
level: envString("CURSOR_LOG_LEVEL", "info"),
|
|
36
|
+
/** Enable request/response logging for debugging */
|
|
37
|
+
requestLogging: envBool("CURSOR_REQUEST_LOGGING", false),
|
|
38
|
+
/** Log filtered IDs and item_references during request transformation */
|
|
39
|
+
logFilteredIds: envBool("CURSOR_LOG_FILTERED_IDS", false),
|
|
40
|
+
/** Log multimodal content detection */
|
|
41
|
+
logMultimodal: envBool("CURSOR_LOG_MULTIMODAL", false),
|
|
42
|
+
/** Output logs in JSON format */
|
|
43
|
+
jsonFormat: envBool("CURSOR_LOG_JSON", false),
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* Session management settings
|
|
47
|
+
*/
|
|
48
|
+
session: {
|
|
49
|
+
/** Enable session reuse for tool calling */
|
|
50
|
+
reuseEnabled: envBool("CURSOR_SESSION_REUSE", true),
|
|
51
|
+
/** Session timeout in milliseconds */
|
|
52
|
+
timeoutMs: envInt("CURSOR_SESSION_TIMEOUT_MS", 15 * 60 * 1000),
|
|
53
|
+
/** Maximum number of cached sessions */
|
|
54
|
+
maxSessions: envInt("CURSOR_MAX_SESSIONS", 100),
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Cache settings
|
|
58
|
+
*/
|
|
59
|
+
cache: {
|
|
60
|
+
/** Model cache TTL in milliseconds */
|
|
61
|
+
modelTtlMs: envInt("CURSOR_MODEL_CACHE_TTL_MS", 5 * 60 * 1000),
|
|
62
|
+
/** Maximum number of cached blobs */
|
|
63
|
+
maxBlobs: envInt("CURSOR_MAX_BLOBS", 1000),
|
|
64
|
+
/** Maximum blob size in bytes */
|
|
65
|
+
maxBlobSize: envInt("CURSOR_MAX_BLOB_SIZE", 10 * 1024 * 1024),
|
|
66
|
+
},
|
|
67
|
+
/**
|
|
68
|
+
* Network request settings
|
|
69
|
+
*/
|
|
70
|
+
network: {
|
|
71
|
+
/** Request timeout in milliseconds */
|
|
72
|
+
requestTimeoutMs: envInt("CURSOR_REQUEST_TIMEOUT_MS", 120000),
|
|
73
|
+
/** Maximum retry attempts for failed requests */
|
|
74
|
+
maxRetries: envInt("CURSOR_MAX_RETRIES", 3),
|
|
75
|
+
/** Base delay for exponential backoff in milliseconds */
|
|
76
|
+
retryBaseDelayMs: envInt("CURSOR_RETRY_BASE_DELAY_MS", 1000),
|
|
77
|
+
/** Maximum delay between retries in milliseconds */
|
|
78
|
+
retryMaxDelayMs: envInt("CURSOR_RETRY_MAX_DELAY_MS", 30000),
|
|
79
|
+
/** Enable automatic retry on transient errors */
|
|
80
|
+
retryEnabled: envBool("CURSOR_RETRY_ENABLED", true),
|
|
81
|
+
},
|
|
82
|
+
/**
|
|
83
|
+
* Heartbeat detection settings
|
|
84
|
+
*/
|
|
85
|
+
heartbeat: {
|
|
86
|
+
/** Idle timeout after progress in milliseconds */
|
|
87
|
+
idleAfterProgressMs: envInt("CURSOR_HEARTBEAT_IDLE_PROGRESS_MS", 120000),
|
|
88
|
+
/** Idle timeout before progress in milliseconds */
|
|
89
|
+
idleBeforeProgressMs: envInt("CURSOR_HEARTBEAT_IDLE_NOPROGRESS_MS", 180000),
|
|
90
|
+
/** Maximum heartbeats allowed after progress */
|
|
91
|
+
maxAfterProgress: envInt("CURSOR_HEARTBEAT_MAX_PROGRESS", 1000),
|
|
92
|
+
/** Maximum heartbeats allowed before progress */
|
|
93
|
+
maxBeforeProgress: envInt("CURSOR_HEARTBEAT_MAX_NOPROGRESS", 1000),
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Server settings (for standalone proxy)
|
|
97
|
+
*/
|
|
98
|
+
server: {
|
|
99
|
+
/** Server port */
|
|
100
|
+
port: envInt("PORT", 18741),
|
|
101
|
+
/** Server host */
|
|
102
|
+
host: envString("HOST", "localhost"),
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* Cursor API settings
|
|
106
|
+
*/
|
|
107
|
+
api: {
|
|
108
|
+
/** Main API base URL */
|
|
109
|
+
baseUrl: envString("CURSOR_API_URL", "https://api2.cursor.sh"),
|
|
110
|
+
/** Agent privacy mode URL */
|
|
111
|
+
agentPrivacyUrl: envString("CURSOR_AGENT_PRIVACY_URL", "https://agent.api5.cursor.sh"),
|
|
112
|
+
/** Agent non-privacy mode URL */
|
|
113
|
+
agentNonPrivacyUrl: envString("CURSOR_AGENT_NON_PRIVACY_URL", "https://agentn.api5.cursor.sh"),
|
|
114
|
+
/** Enable privacy mode */
|
|
115
|
+
privacyMode: envBool("CURSOR_PRIVACY_MODE", true),
|
|
116
|
+
/** Try API5 fallback endpoints */
|
|
117
|
+
tryApi5Fallback: envBool("CURSOR_AGENT_TRY_API5", false),
|
|
118
|
+
/** Client version override */
|
|
119
|
+
clientVersion: envString("CURSOR_CLIENT_VERSION", ""),
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Security settings
|
|
123
|
+
*/
|
|
124
|
+
security: {
|
|
125
|
+
/** Enable shell command validation */
|
|
126
|
+
validateShellCommands: envBool("CURSOR_VALIDATE_SHELL", false),
|
|
127
|
+
/** Maximum shell command execution time in milliseconds */
|
|
128
|
+
shellTimeoutMs: envInt("CURSOR_SHELL_TIMEOUT_MS", 60000),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
// --- Utility Functions ---
|
|
132
|
+
/**
|
|
133
|
+
* Check if debug mode is enabled
|
|
134
|
+
*/
|
|
135
|
+
export function isDebugEnabled() {
|
|
136
|
+
return config.debug.enabled;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Check if timing logs are enabled
|
|
140
|
+
*/
|
|
141
|
+
export function isTimingEnabled() {
|
|
142
|
+
return config.debug.timing || config.debug.enabled;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if session reuse is enabled
|
|
146
|
+
*/
|
|
147
|
+
export function isSessionReuseEnabled() {
|
|
148
|
+
return config.session.reuseEnabled;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get the effective log level
|
|
152
|
+
*/
|
|
153
|
+
export function getLogLevel() {
|
|
154
|
+
if (config.debug.enabled)
|
|
155
|
+
return "debug";
|
|
156
|
+
return config.debug.level;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if request logging is enabled
|
|
160
|
+
*/
|
|
161
|
+
export function isRequestLoggingEnabled() {
|
|
162
|
+
return config.debug.requestLogging || config.debug.enabled;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Check if filtered IDs should be logged
|
|
166
|
+
*/
|
|
167
|
+
export function shouldLogFilteredIds() {
|
|
168
|
+
return config.debug.logFilteredIds || config.debug.enabled;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Check if multimodal content should be logged
|
|
172
|
+
*/
|
|
173
|
+
export function shouldLogMultimodal() {
|
|
174
|
+
return config.debug.logMultimodal || config.debug.enabled;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if JSON log format is enabled
|
|
178
|
+
*/
|
|
179
|
+
export function isJsonLogFormat() {
|
|
180
|
+
return config.debug.jsonFormat;
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uCAAuC;AAEvC,SAAS,OAAO,CAAC,GAAW,EAAE,YAAqB;IACjD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC;IAC7C,OAAO,KAAK,KAAK,GAAG,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC;AACzD,CAAC;AAED,SAAS,MAAM,CAAC,GAAW,EAAE,YAAoB;IAC/C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC;IAC7C,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC;AAC/C,CAAC;AAED,SAAS,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AM,CAAC,KAAK,CAAC,OAAO,CAAC;AAC5D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-Compatible Request Handler
|
|
3
|
+
*
|
|
4
|
+
* Core request handling logic that can be used by both:
|
|
5
|
+
* - Plugin's custom fetch function (serverless)
|
|
6
|
+
* - Standalone server (Bun.serve)
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Options for the request handler
|
|
10
|
+
*/
|
|
11
|
+
export interface RequestHandlerOptions {
|
|
12
|
+
/** Access token for Cursor API */
|
|
13
|
+
accessToken: string;
|
|
14
|
+
/** Optional logger for debugging */
|
|
15
|
+
log?: (message: string, ...args: unknown[]) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a request handler function that can be used with custom fetch
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const handler = createRequestHandler({ accessToken: "..." });
|
|
23
|
+
*
|
|
24
|
+
* // Use in plugin
|
|
25
|
+
* return {
|
|
26
|
+
* fetch: (input, init) => handler(new Request(input, init)),
|
|
27
|
+
* };
|
|
28
|
+
*
|
|
29
|
+
* // Use in server
|
|
30
|
+
* Bun.serve({ fetch: handler });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createRequestHandler(options: RequestHandlerOptions): (req: Request) => Promise<Response>;
|
|
34
|
+
/**
|
|
35
|
+
* Create a custom fetch handler for use in OpenCode plugin
|
|
36
|
+
*
|
|
37
|
+
* This wraps createRequestHandler to match the FetchInput signature
|
|
38
|
+
* that OpenCode expects from plugins.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createPluginFetch(options: RequestHandlerOptions): (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|