xcode-copilot-server 1.0.4 → 2.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/README.md +56 -29
- package/config.json5 +49 -41
- package/dist/config.d.ts +9 -4
- package/dist/config.js +25 -7
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +1 -0
- package/dist/conversation-manager.d.ts +32 -0
- package/dist/conversation-manager.js +120 -0
- package/dist/conversation-manager.js.map +1 -0
- package/dist/copilot-service.d.ts +1 -3
- package/dist/copilot-service.js +3 -23
- package/dist/copilot-service.js.map +1 -1
- package/dist/handlers/completions/streaming.d.ts +1 -1
- package/dist/handlers/completions/streaming.js +13 -24
- package/dist/handlers/completions/streaming.js.map +1 -1
- package/dist/handlers/completions.d.ts +2 -2
- package/dist/handlers/completions.js +75 -63
- package/dist/handlers/completions.js.map +1 -1
- package/dist/handlers/errors.d.ts +5 -0
- package/dist/handlers/errors.js +10 -0
- package/dist/handlers/errors.js.map +1 -0
- package/dist/handlers/messages/count-tokens.d.ts +3 -0
- package/dist/handlers/messages/count-tokens.js +72 -0
- package/dist/handlers/messages/count-tokens.js.map +1 -0
- package/dist/handlers/messages/streaming.d.ts +6 -0
- package/dist/handlers/messages/streaming.js +274 -0
- package/dist/handlers/messages/streaming.js.map +1 -0
- package/dist/handlers/messages/tool-result-handler.d.ts +4 -0
- package/dist/handlers/messages/tool-result-handler.js +19 -0
- package/dist/handlers/messages/tool-result-handler.js.map +1 -0
- package/dist/handlers/messages.d.ts +4 -0
- package/dist/handlers/messages.js +150 -0
- package/dist/handlers/messages.js.map +1 -0
- package/dist/handlers/models.d.ts +0 -1
- package/dist/handlers/models.js +1 -2
- package/dist/handlers/models.js.map +1 -1
- package/dist/handlers/session-config.d.ts +15 -0
- package/dist/handlers/session-config.js +79 -0
- package/dist/handlers/session-config.js.map +1 -0
- package/dist/handlers/streaming-utils.d.ts +9 -0
- package/dist/handlers/streaming-utils.js +19 -0
- package/dist/handlers/streaming-utils.js.map +1 -0
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +0 -1
- package/dist/logger.js +4 -10
- package/dist/logger.js.map +1 -1
- package/dist/providers/anthropic.d.ts +5 -0
- package/dist/providers/anthropic.js +28 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +15 -0
- package/dist/providers/index.js +7 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +5 -0
- package/dist/providers/openai.js +25 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +7 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/schemas/anthropic.d.ts +140 -0
- package/dist/schemas/anthropic.js +58 -0
- package/dist/schemas/anthropic.js.map +1 -0
- package/dist/schemas/config.d.ts +127 -0
- package/dist/schemas/config.js +44 -0
- package/dist/schemas/config.js.map +1 -0
- package/dist/schemas/openai.d.ts +98 -0
- package/dist/schemas/openai.js +76 -0
- package/dist/schemas/openai.js.map +1 -0
- package/dist/server.d.ts +2 -1
- package/dist/server.js +11 -20
- package/dist/server.js.map +1 -1
- package/dist/tool-bridge/index.d.ts +4 -0
- package/dist/tool-bridge/index.js +8 -0
- package/dist/tool-bridge/index.js.map +1 -0
- package/dist/tool-bridge/reply-tracker.d.ts +10 -0
- package/dist/tool-bridge/reply-tracker.js +28 -0
- package/dist/tool-bridge/reply-tracker.js.map +1 -0
- package/dist/tool-bridge/routes.d.ts +4 -0
- package/dist/tool-bridge/routes.js +111 -0
- package/dist/tool-bridge/routes.js.map +1 -0
- package/dist/tool-bridge/session-lifecycle.d.ts +16 -0
- package/dist/tool-bridge/session-lifecycle.js +43 -0
- package/dist/tool-bridge/session-lifecycle.js.map +1 -0
- package/dist/tool-bridge/state.d.ts +34 -0
- package/dist/tool-bridge/state.js +77 -0
- package/dist/tool-bridge/state.js.map +1 -0
- package/dist/tool-bridge/tool-cache.d.ts +10 -0
- package/dist/tool-bridge/tool-cache.js +82 -0
- package/dist/tool-bridge/tool-cache.js.map +1 -0
- package/dist/tool-bridge/tool-router.d.ts +12 -0
- package/dist/tool-bridge/tool-router.js +82 -0
- package/dist/tool-bridge/tool-router.js.map +1 -0
- package/dist/utils/anthropic-prompt.d.ts +2 -0
- package/dist/utils/anthropic-prompt.js +52 -0
- package/dist/utils/anthropic-prompt.js.map +1 -0
- package/dist/utils/model-resolver.d.ts +3 -0
- package/dist/utils/model-resolver.js +45 -0
- package/dist/utils/model-resolver.js.map +1 -0
- package/dist/utils/prompt.d.ts +2 -14
- package/dist/utils/prompt.js +11 -14
- package/dist/utils/prompt.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-utils.js","sourceRoot":"","sources":["../../src/handlers/streaming-utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,cAAc,EAAE,mBAAmB;IACnC,eAAe,EAAE,UAAU;IAC3B,UAAU,EAAE,YAAY;IACxB,mBAAmB,EAAE,IAAI;CACgB,CAAC;AAE5C,MAAM,UAAU,YAAY,CAAC,KAAmB,EAAE,IAAY,EAAE,IAAa;IAC3E,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,IAAI,WAAW,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC5C,IACE,CAAC,IAAI;QACL,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,CAAC,qBAAqB,IAAI,IAAI,CAAC;QAChC,CAAC,CAAC,sBAAsB,IAAI,IAAI,CAAC,EACjC,CAAC;QACD,OAAO,6BAA6B,CAAC;IACvC,CAAC;IACD,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC;AAC9F,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,21 +2,27 @@
|
|
|
2
2
|
import { join, dirname } from "node:path";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
4
|
import { CopilotService } from "./copilot-service.js";
|
|
5
|
-
import { loadConfig } from "./config.js";
|
|
5
|
+
import { loadConfig, resolveConfigPath } from "./config.js";
|
|
6
6
|
import { createServer } from "./server.js";
|
|
7
7
|
import { Logger, LEVEL_PRIORITY } from "./logger.js";
|
|
8
|
+
import { providers } from "./providers/index.js";
|
|
8
9
|
const PACKAGE_ROOT = dirname(import.meta.dirname);
|
|
9
10
|
const DEFAULT_CONFIG_PATH = join(PACKAGE_ROOT, "config.json5");
|
|
10
11
|
const VALID_LOG_LEVELS = Object.keys(LEVEL_PRIORITY);
|
|
12
|
+
const VALID_PROXIES = Object.keys(providers);
|
|
11
13
|
function isLogLevel(value) {
|
|
12
14
|
return value in LEVEL_PRIORITY;
|
|
13
15
|
}
|
|
16
|
+
function isProxy(value) {
|
|
17
|
+
return value in providers;
|
|
18
|
+
}
|
|
14
19
|
const USAGE = `Usage: xcode-copilot-server [options]
|
|
15
20
|
|
|
16
21
|
Options:
|
|
17
22
|
--port <number> Port to listen on (default: 8080)
|
|
23
|
+
--proxy <provider> API format to expose: ${VALID_PROXIES.join(", ")} (default: openai)
|
|
18
24
|
--log-level <level> Log verbosity: ${VALID_LOG_LEVELS.join(", ")} (default: info)
|
|
19
|
-
--config <path> Path to config file (
|
|
25
|
+
--config <path> Path to config file (auto-detected from --cwd, then process cwd, else bundled)
|
|
20
26
|
--cwd <path> Working directory for Copilot sessions (default: process cwd)
|
|
21
27
|
--help Show this help message`;
|
|
22
28
|
function parseCliArgs() {
|
|
@@ -24,8 +30,9 @@ function parseCliArgs() {
|
|
|
24
30
|
return parseArgs({
|
|
25
31
|
options: {
|
|
26
32
|
port: { type: "string", default: "8080" },
|
|
33
|
+
proxy: { type: "string", default: "openai" },
|
|
27
34
|
"log-level": { type: "string", default: "info" },
|
|
28
|
-
config: { type: "string"
|
|
35
|
+
config: { type: "string" },
|
|
29
36
|
cwd: { type: "string" },
|
|
30
37
|
help: { type: "boolean", default: false },
|
|
31
38
|
},
|
|
@@ -50,6 +57,12 @@ async function main() {
|
|
|
50
57
|
console.error(`Invalid port "${values.port}". Must be 1-65535.`);
|
|
51
58
|
process.exit(1);
|
|
52
59
|
}
|
|
60
|
+
const proxy = values.proxy;
|
|
61
|
+
if (!isProxy(proxy)) {
|
|
62
|
+
console.error(`Invalid proxy "${proxy}". Valid: ${VALID_PROXIES.join(", ")}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const provider = providers[proxy];
|
|
53
66
|
const rawLevel = values["log-level"];
|
|
54
67
|
if (!isLogLevel(rawLevel)) {
|
|
55
68
|
console.error(`Invalid log level "${rawLevel}". Valid: ${VALID_LOG_LEVELS.join(", ")}`);
|
|
@@ -57,7 +70,8 @@ async function main() {
|
|
|
57
70
|
}
|
|
58
71
|
const logLevel = rawLevel;
|
|
59
72
|
const logger = new Logger(logLevel);
|
|
60
|
-
const
|
|
73
|
+
const configPath = values.config ?? resolveConfigPath(values.cwd, process.cwd(), DEFAULT_CONFIG_PATH);
|
|
74
|
+
const config = await loadConfig(configPath, logger, proxy);
|
|
61
75
|
const cwd = values.cwd;
|
|
62
76
|
const service = new CopilotService({
|
|
63
77
|
logLevel,
|
|
@@ -74,11 +88,12 @@ async function main() {
|
|
|
74
88
|
process.exit(1);
|
|
75
89
|
}
|
|
76
90
|
logger.info(`Authenticated as ${auth.login ?? "unknown"} (${auth.authType ?? "unknown"})`);
|
|
77
|
-
const ctx = { service, logger, config };
|
|
78
|
-
const app = await createServer(ctx);
|
|
91
|
+
const ctx = { service, logger, config, port };
|
|
92
|
+
const app = await createServer(ctx, provider);
|
|
79
93
|
await app.listen({ port, host: "127.0.0.1" });
|
|
80
94
|
logger.info(`Listening on http://localhost:${String(port)}`);
|
|
81
|
-
logger.info(
|
|
95
|
+
logger.info(`Provider: ${provider.name} (--proxy ${proxy})`);
|
|
96
|
+
logger.info(`Routes: ${provider.routes.join(", ")}`);
|
|
82
97
|
logger.info(`Current working directory: ${service.cwd}`);
|
|
83
98
|
const shutdown = async (signal) => {
|
|
84
99
|
logger.info(`Got ${signal}, shutting down...`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,cAAc,EAAiB,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,SAAS,EAAkB,MAAM,sBAAsB,CAAC;AAGjE,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAClD,MAAM,mBAAmB,GAAG,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;AAE/D,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAe,CAAC;AACnE,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CA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AAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/logger.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare const LEVEL_PRIORITY: {
|
|
|
7
7
|
readonly all: 5;
|
|
8
8
|
};
|
|
9
9
|
export type LogLevel = keyof typeof LEVEL_PRIORITY;
|
|
10
|
-
export declare function truncate(value: unknown, maxLen?: number): string;
|
|
11
10
|
export declare class Logger {
|
|
12
11
|
readonly level: LogLevel;
|
|
13
12
|
private threshold;
|
package/dist/logger.js
CHANGED
|
@@ -6,12 +6,6 @@ export const LEVEL_PRIORITY = {
|
|
|
6
6
|
debug: 4,
|
|
7
7
|
all: 5,
|
|
8
8
|
};
|
|
9
|
-
export function truncate(value, maxLen = 200) {
|
|
10
|
-
const s = typeof value === "string" ? value : JSON.stringify(value);
|
|
11
|
-
if (s.length <= maxLen)
|
|
12
|
-
return s;
|
|
13
|
-
return s.slice(0, maxLen) + "…";
|
|
14
|
-
}
|
|
15
9
|
export class Logger {
|
|
16
10
|
level;
|
|
17
11
|
threshold;
|
|
@@ -21,22 +15,22 @@ export class Logger {
|
|
|
21
15
|
}
|
|
22
16
|
error(msg, ...args) {
|
|
23
17
|
if (this.threshold >= LEVEL_PRIORITY.error) {
|
|
24
|
-
console.error(`[ERROR] ${msg}`, ...args);
|
|
18
|
+
console.error(`[${new Date().toISOString()}] [ERROR] ${msg}`, ...args);
|
|
25
19
|
}
|
|
26
20
|
}
|
|
27
21
|
warn(msg, ...args) {
|
|
28
22
|
if (this.threshold >= LEVEL_PRIORITY.warning) {
|
|
29
|
-
console.warn(`[WARN] ${msg}`, ...args);
|
|
23
|
+
console.warn(`[${new Date().toISOString()}] [WARN] ${msg}`, ...args);
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
26
|
info(msg, ...args) {
|
|
33
27
|
if (this.threshold >= LEVEL_PRIORITY.info) {
|
|
34
|
-
console.log(`[INFO] ${msg}`, ...args);
|
|
28
|
+
console.log(`[${new Date().toISOString()}] [INFO] ${msg}`, ...args);
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
31
|
debug(msg, ...args) {
|
|
38
32
|
if (this.threshold >= LEVEL_PRIORITY.debug) {
|
|
39
|
-
console.log(`[DEBUG] ${msg}`, ...args);
|
|
33
|
+
console.log(`[${new Date().toISOString()}] [DEBUG] ${msg}`, ...args);
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
36
|
}
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,CAAC;CACmC,CAAC;AAI5C,MAAM,OAAO,MAAM;IACR,KAAK,CAAW;IACjB,SAAS,CAAS;IAE1B,YAAY,QAAkB,MAAM;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,GAAG,IAAe;QACnC,IAAI,IAAI,CAAC,SAAS,IAAI,cAAc,CAAC,KAAK,EAAE,CAAC;YAC3C,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACzE,CAAC;IACH,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,GAAG,IAAe;QAClC,IAAI,IAAI,CAAC,SAAS,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,GAAG,IAAe;QAClC,IAAI,IAAI,CAAC,SAAS,IAAI,cAAc,CAAC,IAAI,EAAE,CAAC;YAC1C,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAW,EAAE,GAAG,IAAe;QACnC,IAAI,IAAI,CAAC,SAAS,IAAI,cAAc,CAAC,KAAK,EAAE,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,aAAa,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const anthropicProvider: {
|
|
2
|
+
name: string;
|
|
3
|
+
routes: string[];
|
|
4
|
+
register(app: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, ctx: import("../context.js").AppContext): void;
|
|
5
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { registerToolBridge } from "../tool-bridge/index.js";
|
|
2
|
+
import { createMessagesHandler } from "../handlers/messages.js";
|
|
3
|
+
import { createCountTokensHandler } from "../handlers/messages/count-tokens.js";
|
|
4
|
+
export const anthropicProvider = {
|
|
5
|
+
name: "Anthropic",
|
|
6
|
+
routes: ["POST /v1/messages", "POST /v1/messages/count_tokens"],
|
|
7
|
+
register(app, ctx) {
|
|
8
|
+
app.addHook("onRequest", (request, reply, done) => {
|
|
9
|
+
// MCP routes come from the SDK's own HTTP client, not from Xcode,
|
|
10
|
+
// so they won't have the claude-cli/ user-agent
|
|
11
|
+
if (request.url.startsWith("/mcp/")) {
|
|
12
|
+
done();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const ua = request.headers["user-agent"] ?? "";
|
|
16
|
+
if (!ua.startsWith("claude-cli/")) {
|
|
17
|
+
ctx.logger.warn(`Rejected request from unexpected user-agent: ${ua}`);
|
|
18
|
+
void reply.code(403).type("application/json").send('{"error":"Forbidden"}\n');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
done();
|
|
22
|
+
});
|
|
23
|
+
const manager = registerToolBridge(app, ctx.logger);
|
|
24
|
+
app.post("/v1/messages", createMessagesHandler(ctx, manager));
|
|
25
|
+
app.post("/v1/messages/count_tokens", createCountTokensHandler(ctx));
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,CAAC,mBAAmB,EAAE,gCAAgC,CAAC;IAE/D,QAAQ,CAAC,GAAG,EAAE,GAAG;QACf,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,kEAAkE;YAClE,gDAAgD;YAChD,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;gBACpC,IAAI,EAAE,CAAC;gBACP,OAAO;YACT,CAAC;YACD,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YAC/C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;gBAClC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gDAAgD,EAAE,EAAE,CAAC,CAAC;gBACtE,KAAK,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;gBAC9E,OAAO;YACT,CAAC;YACD,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QACpD,GAAG,CAAC,IAAI,CAAC,cAAc,EAAE,qBAAqB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9D,GAAG,CAAC,IAAI,CAAC,2BAA2B,EAAE,wBAAwB,CAAC,GAAG,CAAC,CAAC,CAAC;IACvE,CAAC;CACiB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Provider } from "./types.js";
|
|
2
|
+
export type { Provider };
|
|
3
|
+
export declare const providers: {
|
|
4
|
+
openai: {
|
|
5
|
+
name: string;
|
|
6
|
+
routes: string[];
|
|
7
|
+
register(app: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, ctx: import("../context.js").AppContext): void;
|
|
8
|
+
};
|
|
9
|
+
anthropic: {
|
|
10
|
+
name: string;
|
|
11
|
+
routes: string[];
|
|
12
|
+
register(app: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, ctx: import("../context.js").AppContext): void;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type ProxyName = keyof typeof providers;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAKnD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,cAAc;IACtB,SAAS,EAAE,iBAAiB;CACM,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const openaiProvider: {
|
|
2
|
+
name: string;
|
|
3
|
+
routes: string[];
|
|
4
|
+
register(app: import("fastify").FastifyInstance<import("fastify").RawServerDefault, import("node:http").IncomingMessage, import("node:http").ServerResponse<import("node:http").IncomingMessage>, import("fastify").FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>, ctx: import("../context.js").AppContext): void;
|
|
5
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createModelsHandler } from "../handlers/models.js";
|
|
2
|
+
import { createCompletionsHandler } from "../handlers/completions.js";
|
|
3
|
+
import { ConversationManager } from "../conversation-manager.js";
|
|
4
|
+
export const openaiProvider = {
|
|
5
|
+
name: "OpenAI",
|
|
6
|
+
routes: ["GET /v1/models", "POST /v1/chat/completions"],
|
|
7
|
+
register(app, ctx) {
|
|
8
|
+
app.addHook("onRequest", (request, reply, done) => {
|
|
9
|
+
const ua = request.headers["user-agent"] ?? "";
|
|
10
|
+
if (!ua.startsWith("Xcode/")) {
|
|
11
|
+
ctx.logger.warn(`Rejected request from unexpected user-agent: ${ua}`);
|
|
12
|
+
void reply
|
|
13
|
+
.code(403)
|
|
14
|
+
.type("application/json")
|
|
15
|
+
.send('{"error":"Forbidden"}\n');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
done();
|
|
19
|
+
});
|
|
20
|
+
const manager = new ConversationManager(ctx.logger);
|
|
21
|
+
app.get("/v1/models", createModelsHandler(ctx));
|
|
22
|
+
app.post("/v1/chat/completions", createCompletionsHandler(ctx, manager));
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.js","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE,CAAC,gBAAgB,EAAE,2BAA2B,CAAC;IAEvD,QAAQ,CAAC,GAAG,EAAE,GAAG;QACf,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YAChD,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;YAC/C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC7B,GAAG,CAAC,MAAM,CAAC,IAAI,CACb,gDAAgD,EAAE,EAAE,CACrD,CAAC;gBACF,KAAK,KAAK;qBACP,IAAI,CAAC,GAAG,CAAC;qBACT,IAAI,CAAC,kBAAkB,CAAC;qBACxB,IAAI,CAAC,yBAAyB,CAAC,CAAC;gBACnC,OAAO;YACT,CAAC;YAED,IAAI,EAAE,CAAC;QACT,CAAC,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpD,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC;QAChD,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;CACiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export interface TextBlock {
|
|
3
|
+
type: "text";
|
|
4
|
+
text: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ToolUseBlock {
|
|
7
|
+
type: "tool_use";
|
|
8
|
+
id: string;
|
|
9
|
+
name: string;
|
|
10
|
+
input: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface ToolResultBlock {
|
|
13
|
+
type: "tool_result";
|
|
14
|
+
tool_use_id: string;
|
|
15
|
+
content?: string | TextBlock[] | undefined;
|
|
16
|
+
}
|
|
17
|
+
export type ContentBlock = TextBlock | ToolUseBlock | ToolResultBlock;
|
|
18
|
+
export interface AnthropicMessage {
|
|
19
|
+
role: "user" | "assistant";
|
|
20
|
+
content: string | ContentBlock[];
|
|
21
|
+
}
|
|
22
|
+
export interface AnthropicToolDefinition {
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string | undefined;
|
|
25
|
+
input_schema: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface MessageStartEvent {
|
|
28
|
+
type: "message_start";
|
|
29
|
+
message: {
|
|
30
|
+
id: string;
|
|
31
|
+
type: "message";
|
|
32
|
+
role: "assistant";
|
|
33
|
+
content: [];
|
|
34
|
+
model: string;
|
|
35
|
+
stop_reason: null;
|
|
36
|
+
usage: {
|
|
37
|
+
input_tokens: number;
|
|
38
|
+
output_tokens: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export type TextContentBlock = {
|
|
43
|
+
type: "text";
|
|
44
|
+
text: "";
|
|
45
|
+
};
|
|
46
|
+
export type ToolUseContentBlock = {
|
|
47
|
+
type: "tool_use";
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
input: Record<string, unknown>;
|
|
51
|
+
};
|
|
52
|
+
export interface ContentBlockStartEvent {
|
|
53
|
+
type: "content_block_start";
|
|
54
|
+
index: number;
|
|
55
|
+
content_block: TextContentBlock | ToolUseContentBlock;
|
|
56
|
+
}
|
|
57
|
+
export type TextDelta = {
|
|
58
|
+
type: "text_delta";
|
|
59
|
+
text: string;
|
|
60
|
+
};
|
|
61
|
+
export type InputJsonDelta = {
|
|
62
|
+
type: "input_json_delta";
|
|
63
|
+
partial_json: string;
|
|
64
|
+
};
|
|
65
|
+
export interface ContentBlockDeltaEvent {
|
|
66
|
+
type: "content_block_delta";
|
|
67
|
+
index: number;
|
|
68
|
+
delta: TextDelta | InputJsonDelta;
|
|
69
|
+
}
|
|
70
|
+
export interface ContentBlockStopEvent {
|
|
71
|
+
type: "content_block_stop";
|
|
72
|
+
index: number;
|
|
73
|
+
}
|
|
74
|
+
export interface MessageDeltaEvent {
|
|
75
|
+
type: "message_delta";
|
|
76
|
+
delta: {
|
|
77
|
+
stop_reason: string;
|
|
78
|
+
stop_sequence: null;
|
|
79
|
+
};
|
|
80
|
+
usage: {
|
|
81
|
+
output_tokens: number;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export interface MessageStopEvent {
|
|
85
|
+
type: "message_stop";
|
|
86
|
+
}
|
|
87
|
+
export type AnthropicSSEEvent = MessageStartEvent | ContentBlockStartEvent | ContentBlockDeltaEvent | ContentBlockStopEvent | MessageDeltaEvent | MessageStopEvent;
|
|
88
|
+
export interface AnthropicErrorResponse {
|
|
89
|
+
type: "error";
|
|
90
|
+
error: {
|
|
91
|
+
type: "invalid_request_error" | "api_error";
|
|
92
|
+
message: string;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
export interface CountTokensResponse {
|
|
96
|
+
input_tokens: number;
|
|
97
|
+
}
|
|
98
|
+
export declare const AnthropicMessagesRequestSchema: z.ZodObject<{
|
|
99
|
+
model: z.ZodString;
|
|
100
|
+
max_tokens: z.ZodNumber;
|
|
101
|
+
system: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodObject<{
|
|
102
|
+
type: z.ZodLiteral<"text">;
|
|
103
|
+
text: z.ZodString;
|
|
104
|
+
}, z.core.$strip>>]>>;
|
|
105
|
+
messages: z.ZodArray<z.ZodObject<{
|
|
106
|
+
role: z.ZodEnum<{
|
|
107
|
+
user: "user";
|
|
108
|
+
assistant: "assistant";
|
|
109
|
+
}>;
|
|
110
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
111
|
+
type: z.ZodLiteral<"text">;
|
|
112
|
+
text: z.ZodString;
|
|
113
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
114
|
+
type: z.ZodLiteral<"tool_use">;
|
|
115
|
+
id: z.ZodString;
|
|
116
|
+
name: z.ZodString;
|
|
117
|
+
input: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
118
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
119
|
+
type: z.ZodLiteral<"tool_result">;
|
|
120
|
+
tool_use_id: z.ZodString;
|
|
121
|
+
content: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodObject<{
|
|
122
|
+
type: z.ZodLiteral<"text">;
|
|
123
|
+
text: z.ZodString;
|
|
124
|
+
}, z.core.$strip>>]>>;
|
|
125
|
+
}, z.core.$strip>], "type">>]>;
|
|
126
|
+
}, z.core.$strip>>;
|
|
127
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
128
|
+
name: z.ZodString;
|
|
129
|
+
description: z.ZodOptional<z.ZodString>;
|
|
130
|
+
input_schema: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
131
|
+
}, z.core.$strip>>>;
|
|
132
|
+
stream: z.ZodOptional<z.ZodBoolean>;
|
|
133
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
134
|
+
top_p: z.ZodOptional<z.ZodNumber>;
|
|
135
|
+
top_k: z.ZodOptional<z.ZodNumber>;
|
|
136
|
+
stop_sequences: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
137
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
138
|
+
}, z.core.$strip>;
|
|
139
|
+
export type AnthropicMessagesRequest = z.infer<typeof AnthropicMessagesRequestSchema>;
|
|
140
|
+
export declare function extractAnthropicSystem(system: string | TextBlock[] | undefined): string | undefined;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const TextBlockSchema = z.object({
|
|
3
|
+
type: z.literal("text"),
|
|
4
|
+
text: z.string(),
|
|
5
|
+
});
|
|
6
|
+
const ToolUseBlockSchema = z.object({
|
|
7
|
+
type: z.literal("tool_use"),
|
|
8
|
+
id: z.string(),
|
|
9
|
+
name: z.string(),
|
|
10
|
+
input: z.record(z.string(), z.unknown()),
|
|
11
|
+
});
|
|
12
|
+
const ToolResultContentSchema = z.union([
|
|
13
|
+
z.string(),
|
|
14
|
+
z.array(TextBlockSchema),
|
|
15
|
+
]);
|
|
16
|
+
const ToolResultBlockSchema = z.object({
|
|
17
|
+
type: z.literal("tool_result"),
|
|
18
|
+
tool_use_id: z.string(),
|
|
19
|
+
content: ToolResultContentSchema.optional(),
|
|
20
|
+
});
|
|
21
|
+
const ContentBlockSchema = z.discriminatedUnion("type", [
|
|
22
|
+
TextBlockSchema,
|
|
23
|
+
ToolUseBlockSchema,
|
|
24
|
+
ToolResultBlockSchema,
|
|
25
|
+
]);
|
|
26
|
+
const AnthropicMessageSchema = z.object({
|
|
27
|
+
role: z.enum(["user", "assistant"]),
|
|
28
|
+
content: z.union([z.string(), z.array(ContentBlockSchema)]),
|
|
29
|
+
});
|
|
30
|
+
const AnthropicToolDefinitionSchema = z.object({
|
|
31
|
+
name: z.string(),
|
|
32
|
+
description: z.string().optional(),
|
|
33
|
+
input_schema: z.record(z.string(), z.unknown()),
|
|
34
|
+
});
|
|
35
|
+
export const AnthropicMessagesRequestSchema = z.object({
|
|
36
|
+
model: z.string().min(1, "Model is required"),
|
|
37
|
+
max_tokens: z.number().int().positive("max_tokens must be positive"),
|
|
38
|
+
system: z.union([z.string(), z.array(TextBlockSchema)]).optional(),
|
|
39
|
+
messages: z.array(AnthropicMessageSchema).min(1, "Messages are required"),
|
|
40
|
+
tools: z.array(AnthropicToolDefinitionSchema).optional(),
|
|
41
|
+
stream: z.boolean().optional(),
|
|
42
|
+
temperature: z.number().optional(),
|
|
43
|
+
top_p: z.number().optional(),
|
|
44
|
+
top_k: z.number().optional(),
|
|
45
|
+
stop_sequences: z.array(z.string()).optional(),
|
|
46
|
+
metadata: z.record(z.string(), z.unknown()).optional(),
|
|
47
|
+
});
|
|
48
|
+
// The Anthropic API accepts system as a string or an array of text blocks,
|
|
49
|
+
// so we flatten it into a single string for the Copilot SDK.
|
|
50
|
+
export function extractAnthropicSystem(system) {
|
|
51
|
+
if (system == null)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (typeof system === "string")
|
|
54
|
+
return system;
|
|
55
|
+
const text = system.map((b) => b.text).join("\n\n");
|
|
56
|
+
return text || undefined;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/schemas/anthropic.ts"],"names":[],"mappings":"A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,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE;CACvD,CAAC,CAAC;AAIH,2EAA2E;AAC3E,6DAA6D;AAC7D,MAAM,UAAU,sBAAsB,CACpC,MAAwC;IAExC,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,SAAS,CAAC;IACrC,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpD,OAAO,IAAI,IAAI,SAAS,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const MCPLocalServerSchema: z.ZodObject<{
|
|
3
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"local">, z.ZodLiteral<"stdio">]>;
|
|
4
|
+
command: z.ZodString;
|
|
5
|
+
args: z.ZodArray<z.ZodString>;
|
|
6
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
7
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
8
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
9
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
declare const MCPRemoteServerSchema: z.ZodObject<{
|
|
12
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>;
|
|
13
|
+
url: z.ZodURL;
|
|
14
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
15
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
16
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
declare const MCPServerSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
19
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"local">, z.ZodLiteral<"stdio">]>;
|
|
20
|
+
command: z.ZodString;
|
|
21
|
+
args: z.ZodArray<z.ZodString>;
|
|
22
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
23
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
24
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>;
|
|
28
|
+
url: z.ZodURL;
|
|
29
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
30
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
31
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
}, z.core.$strip>]>;
|
|
33
|
+
declare const ApprovalRuleSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodEnum<{
|
|
34
|
+
url: "url";
|
|
35
|
+
read: "read";
|
|
36
|
+
write: "write";
|
|
37
|
+
shell: "shell";
|
|
38
|
+
mcp: "mcp";
|
|
39
|
+
}>>]>;
|
|
40
|
+
declare const ReasoningEffortSchema: z.ZodEnum<{
|
|
41
|
+
low: "low";
|
|
42
|
+
medium: "medium";
|
|
43
|
+
high: "high";
|
|
44
|
+
xhigh: "xhigh";
|
|
45
|
+
}>;
|
|
46
|
+
declare const ToolBridgeServerSchema: z.ZodBoolean;
|
|
47
|
+
export type MCPLocalServer = z.infer<typeof MCPLocalServerSchema>;
|
|
48
|
+
export type MCPRemoteServer = z.infer<typeof MCPRemoteServerSchema>;
|
|
49
|
+
export type MCPServer = z.infer<typeof MCPServerSchema>;
|
|
50
|
+
export type ApprovalRule = z.infer<typeof ApprovalRuleSchema>;
|
|
51
|
+
export type ReasoningEffort = z.infer<typeof ReasoningEffortSchema>;
|
|
52
|
+
export type ToolBridgeServer = z.infer<typeof ToolBridgeServerSchema>;
|
|
53
|
+
declare const ProviderConfigSchema: z.ZodObject<{
|
|
54
|
+
toolBridge: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
55
|
+
mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
56
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"local">, z.ZodLiteral<"stdio">]>;
|
|
57
|
+
command: z.ZodString;
|
|
58
|
+
args: z.ZodArray<z.ZodString>;
|
|
59
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
60
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
61
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
63
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
64
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>;
|
|
65
|
+
url: z.ZodURL;
|
|
66
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
67
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
69
|
+
}, z.core.$strip>]>>>;
|
|
70
|
+
}, z.core.$strip>;
|
|
71
|
+
export type ProviderConfig = z.infer<typeof ProviderConfigSchema>;
|
|
72
|
+
export declare const ServerConfigSchema: z.ZodObject<{
|
|
73
|
+
openai: z.ZodDefault<z.ZodObject<{
|
|
74
|
+
toolBridge: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
75
|
+
mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
76
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"local">, z.ZodLiteral<"stdio">]>;
|
|
77
|
+
command: z.ZodString;
|
|
78
|
+
args: z.ZodArray<z.ZodString>;
|
|
79
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
80
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
81
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
84
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>;
|
|
85
|
+
url: z.ZodURL;
|
|
86
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
87
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
88
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
}, z.core.$strip>]>>>;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
anthropic: z.ZodDefault<z.ZodObject<{
|
|
92
|
+
toolBridge: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
93
|
+
mcpServers: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
94
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"local">, z.ZodLiteral<"stdio">]>;
|
|
95
|
+
command: z.ZodString;
|
|
96
|
+
args: z.ZodArray<z.ZodString>;
|
|
97
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
98
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
99
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
100
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
101
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
+
type: z.ZodUnion<readonly [z.ZodLiteral<"http">, z.ZodLiteral<"sse">]>;
|
|
103
|
+
url: z.ZodURL;
|
|
104
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
105
|
+
allowedTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
106
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
107
|
+
}, z.core.$strip>]>>>;
|
|
108
|
+
}, z.core.$strip>>;
|
|
109
|
+
allowedCliTools: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
110
|
+
excludedFilePatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
111
|
+
bodyLimitMiB: z.ZodDefault<z.ZodNumber>;
|
|
112
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
113
|
+
low: "low";
|
|
114
|
+
medium: "medium";
|
|
115
|
+
high: "high";
|
|
116
|
+
xhigh: "xhigh";
|
|
117
|
+
}>>;
|
|
118
|
+
autoApprovePermissions: z.ZodDefault<z.ZodUnion<readonly [z.ZodBoolean, z.ZodArray<z.ZodEnum<{
|
|
119
|
+
url: "url";
|
|
120
|
+
read: "read";
|
|
121
|
+
write: "write";
|
|
122
|
+
shell: "shell";
|
|
123
|
+
mcp: "mcp";
|
|
124
|
+
}>>]>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
export type RawServerConfig = z.infer<typeof ServerConfigSchema>;
|
|
127
|
+
export {};
|