@vanillagreen/pi-claude-bridge 1.6.2 → 1.9.0
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 +87 -6
- package/bundle/connector-inventory.js +137 -0
- package/bundle/index.js +28385 -22407
- package/package.json +10 -6
- package/src/agents-md.ts +12 -4
- package/src/assistant-stream.ts +307 -0
- package/src/auth-presence.ts +158 -0
- package/src/bridge-state.ts +136 -0
- package/src/claude-executable.ts +264 -0
- package/src/config.ts +83 -5
- package/src/connector-inventory.ts +281 -0
- package/src/connectors.ts +359 -0
- package/src/debug.ts +80 -0
- package/src/index.ts +339 -1428
- package/src/models.ts +22 -1
- package/src/prompt-context.ts +3 -8
- package/src/query-state.ts +42 -0
- package/src/rate-limit.ts +63 -0
- package/src/session-persistence.ts +329 -0
- package/src/stream-idle-watchdog.ts +134 -0
- package/src/tool-mapping.ts +53 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { MCP_SERVER_NAME, MCP_TOOL_PREFIX } from "./skills.js";
|
|
2
|
+
|
|
3
|
+
const SDK_TO_PI_TOOL_NAME: Record<string, string> = {
|
|
4
|
+
read: "read", write: "write", edit: "edit", bash: "bash",
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// --- Provider helpers: tool name mapping ---
|
|
8
|
+
|
|
9
|
+
export function mapToolName(name: string, customToolNameToPi?: Map<string, string>): string {
|
|
10
|
+
const normalized = name.toLowerCase();
|
|
11
|
+
const builtin = SDK_TO_PI_TOOL_NAME[normalized];
|
|
12
|
+
if (builtin) return builtin;
|
|
13
|
+
if (customToolNameToPi) {
|
|
14
|
+
const mapped = customToolNameToPi.get(name) ?? customToolNameToPi.get(normalized);
|
|
15
|
+
if (mapped) return mapped;
|
|
16
|
+
}
|
|
17
|
+
for (const prefix of [
|
|
18
|
+
MCP_TOOL_PREFIX,
|
|
19
|
+
`mcp__${MCP_SERVER_NAME.replace(/-/g, "_")}__`,
|
|
20
|
+
`mcp/${MCP_SERVER_NAME}/`,
|
|
21
|
+
`mcp/${MCP_SERVER_NAME.replace(/-/g, "_")}/`,
|
|
22
|
+
]) {
|
|
23
|
+
if (normalized.startsWith(prefix)) return normalized.slice(prefix.length);
|
|
24
|
+
}
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Renames for Claude Code SDK param names that differ from pi's native names.
|
|
29
|
+
// Keys not listed here pass through unchanged, so new pi params work automatically.
|
|
30
|
+
const SDK_KEY_RENAMES: Record<string, Record<string, string>> = {
|
|
31
|
+
read: { file_path: "path" },
|
|
32
|
+
write: { file_path: "path" },
|
|
33
|
+
edit: { file_path: "path", old_string: "oldText", new_string: "newText", old_text: "oldText", new_text: "newText" },
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Maps SDK tool args to pi tool args via key renaming + pass-through.
|
|
37
|
+
// Pi's own prepareArguments hooks handle any structural transforms (e.g. edit oldText/newText → edits[]).
|
|
38
|
+
export function mapToolArgs(
|
|
39
|
+
toolName: string, args: Record<string, unknown> | undefined,
|
|
40
|
+
): Record<string, unknown> {
|
|
41
|
+
const input = args ?? {};
|
|
42
|
+
const renames = SDK_KEY_RENAMES[toolName.toLowerCase()];
|
|
43
|
+
const result: Record<string, unknown> = {};
|
|
44
|
+
for (const [key, value] of Object.entries(input)) {
|
|
45
|
+
const piKey = renames?.[key] ?? key;
|
|
46
|
+
if (!(piKey in result)) result[piKey] = value; // first alias wins
|
|
47
|
+
}
|
|
48
|
+
// Pi bash has no default timeout; add a safety default
|
|
49
|
+
if (toolName.toLowerCase() === "bash" && result.timeout == null) {
|
|
50
|
+
result.timeout = 120;
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|