@1presence/bridge 0.86.0 → 0.89.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/dist/accumulator.js +1 -1
- package/dist/claude.js +15 -8
- package/dist/index.js +7 -4
- package/package.json +1 -1
package/dist/accumulator.js
CHANGED
|
@@ -49,7 +49,7 @@ export function makeBridgeAccumulator() {
|
|
|
49
49
|
const input = block['input'] ?? {};
|
|
50
50
|
if (!id || !name)
|
|
51
51
|
continue;
|
|
52
|
-
const bareName = name.replace(/^
|
|
52
|
+
const bareName = name.replace(/^mcp__(?:1presence-bridge|1presence)__/, '');
|
|
53
53
|
state.toolCalls.push({ id, name: bareName, input });
|
|
54
54
|
currentTurn().toolUseIds.push(id);
|
|
55
55
|
if (bareName === 'set_conversation_title') {
|
package/dist/claude.js
CHANGED
|
@@ -116,25 +116,32 @@ function joinErrorDetail(...parts) {
|
|
|
116
116
|
return out.join(' | ');
|
|
117
117
|
}
|
|
118
118
|
const SDK_STDERR_ERROR_RE = /\b(error|exception|fail(?:ed|ure)?|invalid|unauthor|forbidden|refus|denied|40[0-9]|429|5\d\d|overloaded|rate.?limit)\b/i;
|
|
119
|
-
const REMOTE_MCP_SERVER_NAME = '1presence';
|
|
119
|
+
export const REMOTE_MCP_SERVER_NAME = '1presence-bridge';
|
|
120
|
+
const MCP_TOOL_PREFIX = `mcp__${REMOTE_MCP_SERVER_NAME}__`;
|
|
121
|
+
const LEGACY_MCP_TOOL_PREFIX = 'mcp__1presence__';
|
|
122
|
+
function isPresenceToolName(name) {
|
|
123
|
+
return name.startsWith(MCP_TOOL_PREFIX) || name.startsWith(LEGACY_MCP_TOOL_PREFIX);
|
|
124
|
+
}
|
|
120
125
|
const MCP_SESSION_EXPIRED_RE = /session not found or expired|Error POSTing to endpoint \(HTTP 404\)/i;
|
|
121
126
|
const MCP_TRANSPORT_DEAD_RE = /SSE (?:stream|error)|not connected|connection (?:closed|error|reset|refused|dropped)|dropped connection|socket hang up|ECONNRESET|ECONNREFUSED|ETIMEDOUT|EPIPE|fetch failed|terminated|transport (?:closed|error)|request timed out|-32001|\(HTTP 50\d\)/i;
|
|
122
127
|
const OUTBOUND_NETWORK_TOOLS = new Set([
|
|
123
|
-
|
|
124
|
-
|
|
128
|
+
`${MCP_TOOL_PREFIX}web_fetch`,
|
|
129
|
+
`${MCP_TOOL_PREFIX}web_search`,
|
|
130
|
+
`${LEGACY_MCP_TOOL_PREFIX}web_fetch`,
|
|
131
|
+
`${LEGACY_MCP_TOOL_PREFIX}web_search`,
|
|
125
132
|
]);
|
|
126
133
|
const PERMISSION_TRANSPORT_DEAD_RE = /Tool permission request failed/i;
|
|
127
134
|
export function isPermissionTransportFailure(text) {
|
|
128
135
|
return PERMISSION_TRANSPORT_DEAD_RE.test(text);
|
|
129
136
|
}
|
|
130
|
-
const MCP_TOOL_UNREGISTERED_RE =
|
|
137
|
+
const MCP_TOOL_UNREGISTERED_RE = new RegExp(`No such tool available:\\s*(?:${MCP_TOOL_PREFIX}|${LEGACY_MCP_TOOL_PREFIX})`, 'i');
|
|
131
138
|
export function shouldReconnectRemoteMcp(args) {
|
|
132
139
|
const { toolName, isError, text } = args;
|
|
133
140
|
if (MCP_SESSION_EXPIRED_RE.test(text))
|
|
134
141
|
return true;
|
|
135
142
|
if (MCP_TOOL_UNREGISTERED_RE.test(text))
|
|
136
143
|
return true;
|
|
137
|
-
if (!isError || !toolName
|
|
144
|
+
if (!isError || !isPresenceToolName(toolName))
|
|
138
145
|
return false;
|
|
139
146
|
if (OUTBOUND_NETWORK_TOOLS.has(toolName))
|
|
140
147
|
return false;
|
|
@@ -143,7 +150,7 @@ export function shouldReconnectRemoteMcp(args) {
|
|
|
143
150
|
export function assessRemoteMcpSurface(init) {
|
|
144
151
|
const entry = (init.mcp_servers ?? []).find((s) => s?.name === REMOTE_MCP_SERVER_NAME);
|
|
145
152
|
const status = entry?.status ?? 'absent';
|
|
146
|
-
const toolCount = (init.tools ?? []).filter((t) => t
|
|
153
|
+
const toolCount = (init.tools ?? []).filter((t) => isPresenceToolName(t)).length;
|
|
147
154
|
return { status, toolCount, usable: status === 'connected' && toolCount > 0 };
|
|
148
155
|
}
|
|
149
156
|
function toolResultText(content) {
|
|
@@ -281,7 +288,7 @@ export function spawnClaude(params) {
|
|
|
281
288
|
let apiErrorText = '';
|
|
282
289
|
let producedRealOutput = false;
|
|
283
290
|
const canUseTool = async (toolName, input) => {
|
|
284
|
-
if (toolName
|
|
291
|
+
if (isPresenceToolName(toolName) || toolName.startsWith('mcp__local__')) {
|
|
285
292
|
return { behavior: 'allow', updatedInput: input };
|
|
286
293
|
}
|
|
287
294
|
return { behavior: 'deny', message: `Tool ${toolName} is not allowed in Local Mode`, interrupt: true };
|
|
@@ -357,7 +364,7 @@ export function spawnClaude(params) {
|
|
|
357
364
|
process.stderr.write(paint(SECTION_COLORS.input, `[bridge:verbose] ─── input ${toolName} ───\n${formatPayload(block['input'])}\n[bridge:verbose] ─── end input ───`) + '\n');
|
|
358
365
|
}
|
|
359
366
|
}
|
|
360
|
-
const isMcp1presence = toolName
|
|
367
|
+
const isMcp1presence = isPresenceToolName(toolName);
|
|
361
368
|
const isMcpLocal = toolName.startsWith('mcp__local__');
|
|
362
369
|
const isBareName = /^[a-z][a-z0-9_]*$/.test(toolName);
|
|
363
370
|
if (!isMcp1presence && !isMcpLocal && !isBareName) {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { fileURLToPath } from 'url';
|
|
|
7
7
|
import { createRequire } from 'module';
|
|
8
8
|
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
9
9
|
import { getValidAuth, ensureFreshToken, forceRefreshToken, isTokenValid, AuthCancelledError } from './auth.js';
|
|
10
|
-
import { spawnClaude, killAll, cancelConversation, setVerbose, setDebug, paint, SECTION_COLORS, getCliVersion, getRateLimitWindow } from './claude.js';
|
|
10
|
+
import { spawnClaude, killAll, cancelConversation, setVerbose, setDebug, paint, SECTION_COLORS, getCliVersion, getRateLimitWindow, REMOTE_MCP_SERVER_NAME as BRIDGE_MCP_SERVER_NAME } from './claude.js';
|
|
11
11
|
import { ensureModelChoice } from './config.js';
|
|
12
12
|
import { probeClaudeAuth, launchClaudeLogin, waitForClaudeLogin, promptYesNo } from './claudeAuth.js';
|
|
13
13
|
import { checkAndUpdate, warnIfRuntimeStale } from './update.js';
|
|
@@ -101,7 +101,7 @@ async function fetchSystemPrompt(token, agentSlug) {
|
|
|
101
101
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
102
102
|
const agentParam = agentSlug ? `&agent=${encodeURIComponent(agentSlug)}` : '';
|
|
103
103
|
const url = `${GATEWAY_HTTP}/system-prompt-for-bridge?timezone=${encodeURIComponent(tz)}${agentParam}`;
|
|
104
|
-
const headers = { Authorization: `Bearer ${token}
|
|
104
|
+
const headers = { Authorization: `Bearer ${token}`, 'X-Bridge-Mcp-Name': BRIDGE_MCP_SERVER_NAME };
|
|
105
105
|
const maxAttempts = 8;
|
|
106
106
|
let res = null;
|
|
107
107
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
@@ -167,10 +167,13 @@ function writeMcpConfig(auth) {
|
|
|
167
167
|
const { uid, token } = auth;
|
|
168
168
|
const mcpConfig = {
|
|
169
169
|
mcpServers: {
|
|
170
|
-
|
|
170
|
+
[BRIDGE_MCP_SERVER_NAME]: {
|
|
171
171
|
type: 'sse',
|
|
172
172
|
url: `${GATEWAY_HTTP}/mcp/bridge`,
|
|
173
|
-
headers: {
|
|
173
|
+
headers: {
|
|
174
|
+
Authorization: `Bearer ${token}`,
|
|
175
|
+
'X-Bridge-Mcp-Name': BRIDGE_MCP_SERVER_NAME,
|
|
176
|
+
},
|
|
174
177
|
alwaysLoad: true,
|
|
175
178
|
},
|
|
176
179
|
},
|