@1presence/bridge 0.1.16 → 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 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', text,
19
+ '-p', promptText,
19
20
  '--output-format', 'stream-json',
20
21
  '--verbose',
21
22
  '--allowedTools', 'mcp__1presence__*',
@@ -79,13 +80,27 @@ function spawnClaude(params) {
79
80
  }
80
81
  const content = msg?.['content'];
81
82
  if (Array.isArray(content)) {
83
+ let wroteText = false;
82
84
  for (const block of content) {
83
85
  if (block['type'] === 'tool_use') {
86
+ if (wroteText) {
87
+ process.stderr.write('\n');
88
+ wroteText = false;
89
+ }
84
90
  const toolName = block['name'];
85
91
  const prefix = toolName.startsWith('mcp__') ? '[mcp]' : '[tool]';
86
92
  process.stderr.write(`[bridge] ${prefix} ${toolName}\n`);
87
93
  }
94
+ else if (block['type'] === 'text') {
95
+ const text = block['text'];
96
+ if (text) {
97
+ process.stderr.write(text.replace(/\n+/g, ' '));
98
+ wroteText = true;
99
+ }
100
+ }
88
101
  }
102
+ if (wroteText)
103
+ process.stderr.write('\n');
89
104
  }
90
105
  }
91
106
  // Extract cost from the final result event
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, ws, auth) {
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 (ws.readyState === ws_1.default.OPEN) {
87
- ws.send(JSON.stringify({ type: 'stream', conversationId, event }));
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 (ws.readyState === ws_1.default.OPEN) {
99
- ws.send(JSON.stringify({ type: 'done', conversationId, messageCount, costUsd }));
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 (ws.readyState === ws_1.default.OPEN) {
105
- ws.send(JSON.stringify({ type: 'error', conversationId, message }));
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, ws, auth).catch((err) => {
167
+ handleMessage(conversationId, text, sessionId ?? null, auth, vaultFileOpen).catch((err) => {
165
168
  console.error(`[bridge] handleMessage error: ${err.message}`);
166
169
  });
167
170
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1presence/bridge",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Run 1Presence on your Mac and use your Claude.ai Pro subscription from any device",
5
5
  "bin": {
6
6
  "1presence-bridge": "dist/index.js"