@vanillagreen/pi-claude-bridge 4.0.0 → 4.0.2
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 +41 -90
- package/bundle/connector-inventory.js +8 -7
- package/bundle/index.js +34086 -25259
- package/package.json +5 -3
- package/src/account-router.ts +3 -3
- package/src/assistant-stream.ts +95 -79
- package/src/auth-presence.ts +1 -2
- package/src/billing-identity.ts +116 -0
- package/src/bridge-commands.ts +1 -1
- package/src/bridge-state.ts +14 -12
- package/src/config.ts +14 -6
- package/src/connector-audit.ts +16 -16
- package/src/connector-cache.ts +6 -7
- package/src/connector-inventory.ts +13 -15
- package/src/connector-runtime.ts +8 -8
- package/src/connectors.ts +35 -35
- package/src/consume-query.ts +20 -5
- package/src/convert.ts +1 -1
- package/src/debug.ts +2 -2
- package/src/index.ts +238 -71
- package/src/models.ts +5 -5
- package/src/native-provider.ts +3 -1
- package/src/query-options.ts +4 -4
- package/src/query-state.ts +102 -54
- package/src/query-teardown.ts +19 -3
- package/src/rate-limit.ts +1 -1
- package/src/session-persistence.ts +13 -13
- package/src/session-verify.ts +5 -5
- package/src/tool-mapping.ts +41 -8
- package/src/tool-pairing-audit.ts +7 -7
package/src/tool-mapping.ts
CHANGED
|
@@ -1,11 +1,48 @@
|
|
|
1
|
+
import { isMcpResourceTool } from "./connectors.js";
|
|
1
2
|
import { MCP_SERVER_NAME, MCP_TOOL_PREFIX } from "./skills.js";
|
|
2
3
|
|
|
3
4
|
const SDK_TO_PI_TOOL_NAME: Record<string, string> = {
|
|
4
5
|
read: "read", write: "write", edit: "edit", bash: "bash",
|
|
5
6
|
};
|
|
6
7
|
|
|
8
|
+
const BRIDGED_TOOL_PREFIXES = [
|
|
9
|
+
MCP_TOOL_PREFIX,
|
|
10
|
+
`mcp__${MCP_SERVER_NAME.replace(/-/g, "_")}__`,
|
|
11
|
+
`mcp/${MCP_SERVER_NAME}/`,
|
|
12
|
+
`mcp/${MCP_SERVER_NAME.replace(/-/g, "_")}/`,
|
|
13
|
+
];
|
|
14
|
+
|
|
7
15
|
// --- Provider helpers: tool name mapping ---
|
|
8
16
|
|
|
17
|
+
function bridgedToolSuffix(normalized: string): string | undefined {
|
|
18
|
+
const prefix = BRIDGED_TOOL_PREFIXES.find((candidate) => normalized.startsWith(candidate));
|
|
19
|
+
return prefix ? normalized.slice(prefix.length) : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isForeignMcpTool(name: unknown): boolean {
|
|
23
|
+
if (typeof name !== "string") return false;
|
|
24
|
+
const normalized = name.toLowerCase();
|
|
25
|
+
return (normalized.startsWith("mcp__") || normalized.startsWith("mcp/")) && bridgedToolSuffix(normalized) === undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isPiDispatchable(name: unknown, customToolNameToPi?: Map<string, string>): boolean {
|
|
29
|
+
if (typeof name !== "string" || !name) return false;
|
|
30
|
+
const normalized = name.toLowerCase();
|
|
31
|
+
const hasManifest = Boolean(customToolNameToPi?.size);
|
|
32
|
+
if (customToolNameToPi?.has(name) || customToolNameToPi?.has(normalized)) return true;
|
|
33
|
+
const bridgedSuffix = bridgedToolSuffix(normalized);
|
|
34
|
+
if (bridgedSuffix !== undefined) {
|
|
35
|
+
if (!hasManifest) return true;
|
|
36
|
+
return customToolNameToPi?.has(`${MCP_TOOL_PREFIX}${bridgedSuffix}`) ?? false;
|
|
37
|
+
}
|
|
38
|
+
// A foreign MCP namespace belongs to a child-loaded server, not Pi's bridge.
|
|
39
|
+
if (isForeignMcpTool(name)) return false;
|
|
40
|
+
// Resource discovery is deliberately mirrored as Pi's account-access audit.
|
|
41
|
+
if (isMcpResourceTool(name)) return true;
|
|
42
|
+
// A populated manifest is authoritative: every other bare name is a naming slip.
|
|
43
|
+
return !hasManifest;
|
|
44
|
+
}
|
|
45
|
+
|
|
9
46
|
export function mapToolName(name: string, customToolNameToPi?: Map<string, string>): string {
|
|
10
47
|
const normalized = name.toLowerCase();
|
|
11
48
|
const builtin = SDK_TO_PI_TOOL_NAME[normalized];
|
|
@@ -14,19 +51,15 @@ export function mapToolName(name: string, customToolNameToPi?: Map<string, strin
|
|
|
14
51
|
const mapped = customToolNameToPi.get(name) ?? customToolNameToPi.get(normalized);
|
|
15
52
|
if (mapped) return mapped;
|
|
16
53
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
`mcp/${MCP_SERVER_NAME}/`,
|
|
21
|
-
`mcp/${MCP_SERVER_NAME.replace(/-/g, "_")}/`,
|
|
22
|
-
]) {
|
|
23
|
-
if (normalized.startsWith(prefix)) return normalized.slice(prefix.length);
|
|
54
|
+
const bridgedSuffix = bridgedToolSuffix(normalized);
|
|
55
|
+
if (bridgedSuffix !== undefined) {
|
|
56
|
+
return customToolNameToPi?.get(`${MCP_TOOL_PREFIX}${bridgedSuffix}`) ?? bridgedSuffix;
|
|
24
57
|
}
|
|
25
58
|
return name;
|
|
26
59
|
}
|
|
27
60
|
|
|
28
61
|
// Renames for Claude Code SDK param names that differ from pi's native names.
|
|
29
|
-
// Keys not listed here pass through unchanged, so
|
|
62
|
+
// Keys not listed here pass through unchanged, so additional Pi parameters work automatically.
|
|
30
63
|
const SDK_KEY_RENAMES: Record<string, Record<string, string>> = {
|
|
31
64
|
read: { file_path: "path" },
|
|
32
65
|
write: { file_path: "path" },
|
|
@@ -122,7 +122,8 @@ export function findUnpairedToolUses(messages: Array<{ role?: string; content?:
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
export const LOST_TOOL_RESULT_TEXT =
|
|
125
|
-
"
|
|
125
|
+
"tool-result-lost=interrupted\n"
|
|
126
|
+
+ "Claude bridge: the result of this tool call was lost before the session was rebuilt "
|
|
126
127
|
+ "(the turn was interrupted). Treat the call as failed — it may or may not have executed. "
|
|
127
128
|
+ "Re-run the tool if its output is still needed.";
|
|
128
129
|
|
|
@@ -131,13 +132,12 @@ export const LOST_TOOL_RESULT_TEXT =
|
|
|
131
132
|
* IN PLACE, before cc-session-io's repairToolPairing runs.
|
|
132
133
|
*
|
|
133
134
|
* repairToolPairing backfills with a bare "[no tool result recorded]" — a
|
|
134
|
-
* placeholder the model reads as tool OUTPUT and
|
|
135
|
-
*
|
|
136
|
-
* returned). An is_error result that says what happened and what to do turns a
|
|
135
|
+
* placeholder the model reads as tool OUTPUT and continues to reason from.
|
|
136
|
+
* An is_error result that says what happened and what to do turns a
|
|
137
137
|
* silent correctness hazard into a recoverable failure.
|
|
138
138
|
*
|
|
139
139
|
* Results are prepended to the immediately following user message (tool_result
|
|
140
|
-
* blocks must lead a user message), or a
|
|
140
|
+
* blocks must lead a user message), or a synthetic user message is inserted when none
|
|
141
141
|
* follows. `missing` must come from findUnpairedToolUses on the same array.
|
|
142
142
|
*/
|
|
143
143
|
export function insertLostToolResultPlaceholders(
|
|
@@ -151,8 +151,8 @@ export function insertLostToolResultPlaceholders(
|
|
|
151
151
|
group.push(item);
|
|
152
152
|
byAssistant.set(item.assistantIndex, group);
|
|
153
153
|
}
|
|
154
|
-
// Descending order
|
|
155
|
-
//
|
|
154
|
+
// Descending order ensures that inserting a user message does not shift an index
|
|
155
|
+
// for a group that is earlier in the array.
|
|
156
156
|
for (const assistantIndex of [...byAssistant.keys()].sort((a, b) => b - a)) {
|
|
157
157
|
const group = byAssistant.get(assistantIndex)!;
|
|
158
158
|
const blocks = group.map((item) => block(item.id));
|