@1presence/bridge 0.1.9 → 0.1.11

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
@@ -27,6 +27,7 @@ function spawnClaude(params) {
27
27
  }
28
28
  const proc = (0, child_process_1.spawn)('claude', args, {
29
29
  env: { ...process.env },
30
+ stdio: ['ignore', 'pipe', 'pipe'],
30
31
  });
31
32
  active.set(conversationId, proc);
32
33
  let sessionIdExtracted = false;
@@ -58,16 +59,23 @@ function spawnClaude(params) {
58
59
  }
59
60
  sessionIdExtracted = true;
60
61
  }
61
- // Count complete assistant turns
62
- if (type === 'assistant')
62
+ // Count complete assistant turns + accumulate token usage
63
+ if (type === 'assistant') {
63
64
  messageCount++;
64
- // Extract cost + usage from the final result event
65
+ const msg = event['message'];
66
+ const u = msg?.['usage'];
67
+ if (u) {
68
+ usage = {
69
+ input_tokens: (usage?.input_tokens ?? 0) + (u['input_tokens'] ?? 0),
70
+ output_tokens: (usage?.output_tokens ?? 0) + (u['output_tokens'] ?? 0),
71
+ };
72
+ }
73
+ }
74
+ // Extract cost from the final result event
65
75
  if (type === 'result') {
66
- if (typeof event['cost_usd'] === 'number')
67
- costUsd = event['cost_usd'];
68
- const u = event['usage'];
69
- if (u)
70
- usage = { input_tokens: u['input_tokens'] ?? 0, output_tokens: u['output_tokens'] ?? 0 };
76
+ const c = event['cost_usd'] ?? event['total_cost_usd'];
77
+ if (typeof c === 'number')
78
+ costUsd = c;
71
79
  }
72
80
  onEvent(event);
73
81
  }
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ const os_1 = require("os");
10
10
  const path_1 = require("path");
11
11
  const auth_1 = require("./auth");
12
12
  const claude_1 = require("./claude");
13
+ const update_1 = require("./update");
13
14
  const package_json_1 = require("../package.json");
14
15
  // ─── Config ───────────────────────────────────────────────────────────────────
15
16
  const GATEWAY_URL = process.env.BRIDGE_GATEWAY_URL ?? 'https://api.1presence.com';
@@ -97,9 +98,9 @@ function connect(auth, retryDelay = 1000) {
97
98
  const parts = [];
98
99
  if (usage)
99
100
  parts.push(`in:${usage.input_tokens} out:${usage.output_tokens}`);
100
- if (costUsd > 0)
101
- parts.push(`$${costUsd.toFixed(4)}`);
102
- const suffix = parts.length ? ` (${parts.join(' ')})` : '';
101
+ const costStr = costUsd === 0 ? '$0.0000 (plan usage)' : `$${costUsd.toFixed(4)}`;
102
+ parts.push(costStr);
103
+ const suffix = parts.length ? ` ${parts.join(' ')}` : '';
103
104
  console.log(`[${new Date().toLocaleTimeString()}] ✓ done${suffix}`);
104
105
  if (ws.readyState === ws_1.default.OPEN) {
105
106
  ws.send(JSON.stringify({ type: 'done', conversationId, messageCount, costUsd }));
@@ -142,6 +143,8 @@ function connect(auth, retryDelay = 1000) {
142
143
  // ─── Main ─────────────────────────────────────────────────────────────────────
143
144
  async function main() {
144
145
  console.log(`1Presence Bridge v${package_json_1.version}\n`);
146
+ if (await (0, update_1.checkAndUpdate)())
147
+ return;
145
148
  // Auth
146
149
  const auth = await (0, auth_1.getValidAuth)(GATEWAY_HTTP, PWA_URL);
147
150
  currentAuth = auth;
package/dist/update.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkAndUpdate = checkAndUpdate;
4
+ const child_process_1 = require("child_process");
5
+ const package_json_1 = require("../package.json");
6
+ function isNewer(a, b) {
7
+ const pa = a.split('.').map(Number);
8
+ const pb = b.split('.').map(Number);
9
+ for (let i = 0; i < 3; i++) {
10
+ if ((pa[i] ?? 0) > (pb[i] ?? 0))
11
+ return true;
12
+ if ((pa[i] ?? 0) < (pb[i] ?? 0))
13
+ return false;
14
+ }
15
+ return false;
16
+ }
17
+ async function checkAndUpdate() {
18
+ try {
19
+ const res = await fetch('https://registry.npmjs.org/@1presence/bridge/latest', {
20
+ signal: AbortSignal.timeout(3000),
21
+ });
22
+ if (!res.ok)
23
+ return false;
24
+ const data = await res.json();
25
+ const latest = data.version;
26
+ if (!isNewer(latest, package_json_1.version))
27
+ return false;
28
+ console.log(`Updating to v${latest}…\n`);
29
+ const child = (0, child_process_1.spawn)('npx', ['--yes', `@1presence/bridge@${latest}`], {
30
+ stdio: 'inherit',
31
+ env: process.env,
32
+ });
33
+ child.on('close', (code) => process.exit(code ?? 0));
34
+ return true;
35
+ }
36
+ catch {
37
+ // Non-fatal — registry unreachable or fetch unavailable (old Node)
38
+ return false;
39
+ }
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1presence/bridge",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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"