@1presence/bridge 0.40.0 → 0.43.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.
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeBridgeAccumulator = makeBridgeAccumulator;
4
- exports.postSaveTurn = postSaveTurn;
5
- function makeBridgeAccumulator() {
1
+ export function makeBridgeAccumulator() {
6
2
  const state = {
7
3
  assistantText: '',
8
4
  toolCalls: [],
@@ -105,7 +101,7 @@ function makeBridgeAccumulator() {
105
101
  },
106
102
  };
107
103
  }
108
- async function postSaveTurn(gatewayHttp, token, record) {
104
+ export async function postSaveTurn(gatewayHttp, token, record) {
109
105
  let res;
110
106
  try {
111
107
  res = await fetch(`${gatewayHttp}/bridge/save-turn`, {
package/dist/auth.js CHANGED
@@ -1,20 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AuthCancelledError = void 0;
4
- exports.isTokenValid = isTokenValid;
5
- exports.ensureFreshToken = ensureFreshToken;
6
- exports.getValidAuth = getValidAuth;
7
- const http_1 = require("http");
8
- const fs_1 = require("fs");
9
- const os_1 = require("os");
10
- const path_1 = require("path");
11
- const child_process_1 = require("child_process");
12
- const crypto_1 = require("crypto");
1
+ import { createServer } from 'http';
2
+ import { rmSync } from 'fs';
3
+ import { homedir } from 'os';
4
+ import { join } from 'path';
5
+ import { exec } from 'child_process';
6
+ import { randomBytes, timingSafeEqual } from 'crypto';
13
7
  // Auth lives only in process memory. Earlier versions persisted tokens to
14
8
  // ~/.1presence/auth.json; remove any leftover file on startup so a stale,
15
9
  // permission-bearing token can't survive a bridge restart.
16
- const LEGACY_AUTH_FILE = (0, path_1.join)((0, os_1.homedir)(), '.1presence', 'auth.json');
17
- (0, fs_1.rmSync)(LEGACY_AUTH_FILE, { force: true });
10
+ const LEGACY_AUTH_FILE = join(homedir(), '.1presence', 'auth.json');
11
+ rmSync(LEGACY_AUTH_FILE, { force: true });
18
12
  // ─── JWT helpers ──────────────────────────────────────────────────────────────
19
13
  function parseJwt(token) {
20
14
  try {
@@ -26,7 +20,7 @@ function parseJwt(token) {
26
20
  return {};
27
21
  }
28
22
  }
29
- function isTokenValid(token) {
23
+ export function isTokenValid(token) {
30
24
  const { exp } = parseJwt(token);
31
25
  if (!exp)
32
26
  return false;
@@ -45,15 +39,14 @@ function openBrowser(url) {
45
39
  const cmd = platform === 'darwin' ? `open "${url}"`
46
40
  : platform === 'win32' ? `start "" "${url}"`
47
41
  : `xdg-open "${url}"`;
48
- (0, child_process_1.exec)(cmd, (err) => {
42
+ exec(cmd, (err) => {
49
43
  if (err)
50
44
  console.error('Could not open browser automatically. Please open this URL manually:\n' + url);
51
45
  });
52
46
  }
53
- class AuthCancelledError extends Error {
47
+ export class AuthCancelledError extends Error {
54
48
  constructor() { super('Sign-in cancelled — the browser tab was closed.'); }
55
49
  }
56
- exports.AuthCancelledError = AuthCancelledError;
57
50
  function runBrowserAuthFlow(gatewayUrl, pwaUrl) {
58
51
  return new Promise((resolve, reject) => {
59
52
  let resolved = false;
@@ -61,7 +54,7 @@ function runBrowserAuthFlow(gatewayUrl, pwaUrl) {
61
54
  // required on every request to this localhost server. Without it, a
62
55
  // malicious page in the user's browser could scan ephemeral ports during
63
56
  // the auth window and POST a forged token to hijack the bridge.
64
- const nonce = (0, crypto_1.randomBytes)(32).toString('base64url');
57
+ const nonce = randomBytes(32).toString('base64url');
65
58
  const nonceBuf = Buffer.from(nonce, 'utf-8');
66
59
  function checkNonce(provided) {
67
60
  if (!provided)
@@ -69,7 +62,7 @@ function runBrowserAuthFlow(gatewayUrl, pwaUrl) {
69
62
  const provBuf = Buffer.from(provided, 'utf-8');
70
63
  if (provBuf.length !== nonceBuf.length)
71
64
  return false;
72
- return (0, crypto_1.timingSafeEqual)(provBuf, nonceBuf);
65
+ return timingSafeEqual(provBuf, nonceBuf);
73
66
  }
74
67
  // CORS allowlist scoped to the legitimate PWA origin only.
75
68
  const pwaOrigin = (() => {
@@ -80,7 +73,7 @@ function runBrowserAuthFlow(gatewayUrl, pwaUrl) {
80
73
  return null;
81
74
  }
82
75
  })();
83
- const server = (0, http_1.createServer)((req, res) => {
76
+ const server = createServer((req, res) => {
84
77
  const reqOrigin = req.headers['origin'] ?? '';
85
78
  if (pwaOrigin && reqOrigin === pwaOrigin) {
86
79
  res.setHeader('Access-Control-Allow-Origin', pwaOrigin);
@@ -187,7 +180,7 @@ async function refreshIdToken(refreshToken) {
187
180
  return data.id_token;
188
181
  }
189
182
  /** Returns auth with a fresh ID token. Refreshes in-memory if <10 minutes remain. */
190
- async function ensureFreshToken(auth) {
183
+ export async function ensureFreshToken(auth) {
191
184
  const { exp } = parseJwt(auth.token);
192
185
  const tenMinutes = 10 * 60;
193
186
  if (exp && exp > Math.floor(Date.now() / 1000) + tenMinutes)
@@ -201,7 +194,7 @@ async function ensureFreshToken(auth) {
201
194
  // No cache — every bridge launch goes through the browser flow. This means
202
195
  // permission revocations take effect on the next restart, and the PWA's
203
196
  // CliAuthPage no-permission screen is what users see if access is denied.
204
- async function getValidAuth(gatewayUrl, pwaUrl) {
197
+ export async function getValidAuth(gatewayUrl, pwaUrl) {
205
198
  console.log('Sign-in required.');
206
199
  return runBrowserAuthFlow(gatewayUrl, pwaUrl);
207
200
  }