@1presence/bridge 0.1.17 → 0.1.18
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/claude.js +3 -2
- package/dist/index.js +12 -9
- package/package.json +1 -1
package/dist/claude.js
CHANGED
|
@@ -10,12 +10,13 @@ const sessions_1 = require("./sessions");
|
|
|
10
10
|
const active = new Map();
|
|
11
11
|
// ─── Spawn ────────────────────────────────────────────────────────────────────
|
|
12
12
|
function spawnClaude(params) {
|
|
13
|
-
const { conversationId, presenceSessionId, text, uid, onEvent, onDone, onError } = params;
|
|
13
|
+
const { conversationId, presenceSessionId, text, uid, vaultFileOpen, onEvent, onDone, onError } = params;
|
|
14
14
|
const systemPromptPath = (0, path_1.join)((0, os_1.tmpdir)(), `agent-${uid}.md`);
|
|
15
15
|
const mcpConfigPath = (0, path_1.join)((0, os_1.tmpdir)(), `mcp-${uid}.json`);
|
|
16
16
|
const claudeSessionId = presenceSessionId ? (0, sessions_1.getClaudeSession)(presenceSessionId) : undefined;
|
|
17
|
+
const promptText = vaultFileOpen ? `[vault_file_open: ${vaultFileOpen}]\n\n${text}` : text;
|
|
17
18
|
const args = [
|
|
18
|
-
'-p',
|
|
19
|
+
'-p', promptText,
|
|
19
20
|
'--output-format', 'stream-json',
|
|
20
21
|
'--verbose',
|
|
21
22
|
'--allowedTools', 'mcp__1presence__*',
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ const GATEWAY_HTTP = GATEWAY_URL.replace(/^wss?:/, 'https:').replace(/\/$/, '');
|
|
|
20
20
|
const PWA_URL = process.env.BRIDGE_PWA_URL ?? GATEWAY_HTTP.replace('://api.', '://');
|
|
21
21
|
// ─── In-memory state ──────────────────────────────────────────────────────────
|
|
22
22
|
let currentAuth = null;
|
|
23
|
+
let currentWs = null;
|
|
23
24
|
// ─── Vault file fetch ─────────────────────────────────────────────────────────
|
|
24
25
|
async function fetchVaultFile(path, token) {
|
|
25
26
|
try {
|
|
@@ -58,7 +59,7 @@ async function writeSetupFiles(auth) {
|
|
|
58
59
|
(0, fs_1.writeFileSync)(tmpFile(`mcp-${uid}.json`), JSON.stringify(mcpConfig, null, 2), 'utf-8');
|
|
59
60
|
}
|
|
60
61
|
// ─── Handle a single incoming message (token refresh + spawn) ─────────────────
|
|
61
|
-
async function handleMessage(conversationId, text, sessionId,
|
|
62
|
+
async function handleMessage(conversationId, text, sessionId, auth, vaultFileOpen) {
|
|
62
63
|
// Refresh JWT if <10 min remaining before spawning Claude
|
|
63
64
|
let activeAuth = auth;
|
|
64
65
|
try {
|
|
@@ -78,13 +79,14 @@ async function handleMessage(conversationId, text, sessionId, ws, auth) {
|
|
|
78
79
|
presenceSessionId: sessionId,
|
|
79
80
|
text,
|
|
80
81
|
uid: activeAuth.uid,
|
|
82
|
+
vaultFileOpen,
|
|
81
83
|
onEvent: (event) => {
|
|
82
84
|
if (!responding && event['type'] === 'assistant') {
|
|
83
85
|
responding = true;
|
|
84
86
|
console.log(`[${new Date().toLocaleTimeString()}] ◐ responding…`);
|
|
85
87
|
}
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
+
if (currentWs?.readyState === ws_1.default.OPEN) {
|
|
89
|
+
currentWs.send(JSON.stringify({ type: 'stream', conversationId, event }));
|
|
88
90
|
}
|
|
89
91
|
},
|
|
90
92
|
onDone: (messageCount, costUsd, usage) => {
|
|
@@ -95,14 +97,14 @@ async function handleMessage(conversationId, text, sessionId, ws, auth) {
|
|
|
95
97
|
parts.push(costStr);
|
|
96
98
|
const suffix = parts.length ? ` ${parts.join(' ')}` : '';
|
|
97
99
|
console.log(`[${new Date().toLocaleTimeString()}] ✓ done${suffix}`);
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
+
if (currentWs?.readyState === ws_1.default.OPEN) {
|
|
101
|
+
currentWs.send(JSON.stringify({ type: 'done', conversationId, messageCount, costUsd }));
|
|
100
102
|
}
|
|
101
103
|
},
|
|
102
104
|
onError: (message) => {
|
|
103
105
|
console.error(`[${new Date().toLocaleTimeString()}] ✗ ${message}`);
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
+
if (currentWs?.readyState === ws_1.default.OPEN) {
|
|
107
|
+
currentWs.send(JSON.stringify({ type: 'error', conversationId, message }));
|
|
106
108
|
}
|
|
107
109
|
},
|
|
108
110
|
});
|
|
@@ -144,6 +146,7 @@ function connect(auth, retryDelay = 1000) {
|
|
|
144
146
|
}
|
|
145
147
|
});
|
|
146
148
|
ws.on('open', () => {
|
|
149
|
+
currentWs = ws;
|
|
147
150
|
console.log('✓ Bridge connected. Local Mode active on all your devices.\n');
|
|
148
151
|
startPing();
|
|
149
152
|
});
|
|
@@ -157,11 +160,11 @@ function connect(auth, retryDelay = 1000) {
|
|
|
157
160
|
}
|
|
158
161
|
if (msg.type !== 'message' || !msg.conversationId || !msg.text)
|
|
159
162
|
return;
|
|
160
|
-
const { conversationId, text, sessionId } = msg;
|
|
163
|
+
const { conversationId, text, sessionId, vaultFileOpen } = msg;
|
|
161
164
|
const ts = new Date().toLocaleTimeString();
|
|
162
165
|
const preview = text.length > 80 ? text.slice(0, 80) + '…' : text;
|
|
163
166
|
console.log(`[${ts}] ▶ ${preview}`);
|
|
164
|
-
handleMessage(conversationId, text, sessionId ?? null,
|
|
167
|
+
handleMessage(conversationId, text, sessionId ?? null, auth, vaultFileOpen).catch((err) => {
|
|
165
168
|
console.error(`[bridge] handleMessage error: ${err.message}`);
|
|
166
169
|
});
|
|
167
170
|
});
|