@1presence/bridge 0.50.0 → 0.52.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/auth.js +25 -7
- package/dist/claude.js +2 -2
- package/dist/index.js +4 -3
- package/package.json +1 -1
package/dist/auth.js
CHANGED
|
@@ -47,6 +47,30 @@ function openBrowser(url) {
|
|
|
47
47
|
export class AuthCancelledError extends Error {
|
|
48
48
|
constructor() { super('Sign-in cancelled — the browser tab was closed.'); }
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Applies the localhost auth server's CORS headers, scoped to the legitimate
|
|
52
|
+
* PWA origin. Exported so the Private Network Access behaviour stays under test.
|
|
53
|
+
*
|
|
54
|
+
* The `Access-Control-Allow-Private-Network` reflection is load-bearing: when
|
|
55
|
+
* the HTTPS PWA (a public/secure context) fetches this 127.0.0.1 server (a
|
|
56
|
+
* private address), Chrome sends a CORS preflight carrying
|
|
57
|
+
* `Access-Control-Request-Private-Network: true`. Without the matching allow
|
|
58
|
+
* header, Chrome (PNA enforcement, ~v130+) blocks the request outright — even a
|
|
59
|
+
* plain GET, even for localhost, which is exempt from mixed-content blocking —
|
|
60
|
+
* and the PWA shows "Could not reach the bridge" though the server is up.
|
|
61
|
+
*/
|
|
62
|
+
export function applyAuthCorsHeaders(req, res, pwaOrigin) {
|
|
63
|
+
const reqOrigin = req.headers['origin'] ?? '';
|
|
64
|
+
if (pwaOrigin && reqOrigin === pwaOrigin) {
|
|
65
|
+
res.setHeader('Access-Control-Allow-Origin', pwaOrigin);
|
|
66
|
+
}
|
|
67
|
+
res.setHeader('Vary', 'Origin');
|
|
68
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
69
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
70
|
+
if (req.headers['access-control-request-private-network'] === 'true') {
|
|
71
|
+
res.setHeader('Access-Control-Allow-Private-Network', 'true');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
50
74
|
function runBrowserAuthFlow(gatewayUrl, pwaUrl) {
|
|
51
75
|
return new Promise((resolve, reject) => {
|
|
52
76
|
let resolved = false;
|
|
@@ -74,13 +98,7 @@ function runBrowserAuthFlow(gatewayUrl, pwaUrl) {
|
|
|
74
98
|
}
|
|
75
99
|
})();
|
|
76
100
|
const server = createServer((req, res) => {
|
|
77
|
-
|
|
78
|
-
if (pwaOrigin && reqOrigin === pwaOrigin) {
|
|
79
|
-
res.setHeader('Access-Control-Allow-Origin', pwaOrigin);
|
|
80
|
-
}
|
|
81
|
-
res.setHeader('Vary', 'Origin');
|
|
82
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
83
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
101
|
+
applyAuthCorsHeaders(req, res, pwaOrigin);
|
|
84
102
|
if (req.method === 'OPTIONS') {
|
|
85
103
|
res.writeHead(204);
|
|
86
104
|
res.end();
|
package/dist/claude.js
CHANGED
|
@@ -234,7 +234,7 @@ async function* promptStream(messages) {
|
|
|
234
234
|
}
|
|
235
235
|
// ─── Spawn (drive one turn through the SDK) ──────────────────────────────────────
|
|
236
236
|
export function spawnClaude(params) {
|
|
237
|
-
const { conversationId, presenceSessionId, text, uid, history, vaultFileOpen, clientCapabilities, syncedFolders, onEvent, onDone, onError, onNotice } = params;
|
|
237
|
+
const { conversationId, presenceSessionId, text, uid, history, vaultFileOpen, clientCapabilities, syncedFolders, model: perTurnModel, onEvent, onDone, onError, onNotice } = params;
|
|
238
238
|
const systemPromptPath = join(tmpdir(), `agent-${uid}.md`);
|
|
239
239
|
const mcpConfigPath = join(tmpdir(), `mcp-${uid}.json`);
|
|
240
240
|
if (verbose) {
|
|
@@ -337,7 +337,7 @@ export function spawnClaude(params) {
|
|
|
337
337
|
if (!safeEnv['MAX_MCP_OUTPUT_TOKENS']) {
|
|
338
338
|
safeEnv['MAX_MCP_OUTPUT_TOKENS'] = '200000';
|
|
339
339
|
}
|
|
340
|
-
const pinnedModel = getBridgeModel();
|
|
340
|
+
const pinnedModel = perTurnModel ?? getBridgeModel();
|
|
341
341
|
// Process one translated raw stream-json event: bookkeeping + forward. Mirrors
|
|
342
342
|
// the old CLI stdout parser so the gateway/accumulator see identical shapes.
|
|
343
343
|
// Returns false when the event must be suppressed (errors) or the turn was
|
package/dist/index.js
CHANGED
|
@@ -219,7 +219,7 @@ function isUuid(value) {
|
|
|
219
219
|
return UUID_RE.test(value);
|
|
220
220
|
}
|
|
221
221
|
// ─── Handle a single incoming message (token refresh + spawn) ─────────────────
|
|
222
|
-
async function handleMessage(conversationId, text, sessionId, history, auth, vaultFileOpen, clientCapabilities, syncedFolders, agentSlug) {
|
|
222
|
+
async function handleMessage(conversationId, text, sessionId, history, auth, vaultFileOpen, clientCapabilities, syncedFolders, agentSlug, model) {
|
|
223
223
|
// Refresh JWT if <10 min remaining before spawning Claude
|
|
224
224
|
let activeAuth = auth;
|
|
225
225
|
try {
|
|
@@ -322,6 +322,7 @@ async function handleMessage(conversationId, text, sessionId, history, auth, vau
|
|
|
322
322
|
vaultFileOpen,
|
|
323
323
|
clientCapabilities,
|
|
324
324
|
syncedFolders,
|
|
325
|
+
model,
|
|
325
326
|
onEvent: (event) => {
|
|
326
327
|
accumulator.consume(event);
|
|
327
328
|
if (!responding && event['type'] === 'assistant') {
|
|
@@ -500,12 +501,12 @@ function connect(auth, retryDelay = 1000) {
|
|
|
500
501
|
}
|
|
501
502
|
if (msg.type !== 'message' || !msg.conversationId || !msg.text)
|
|
502
503
|
return;
|
|
503
|
-
const { conversationId, text, sessionId, history, vaultFileOpen, clientCapabilities, syncedFolders, agentSlug } = msg;
|
|
504
|
+
const { conversationId, text, sessionId, history, vaultFileOpen, clientCapabilities, syncedFolders, agentSlug, model } = msg;
|
|
504
505
|
const ts = new Date().toLocaleTimeString();
|
|
505
506
|
const hist = Array.isArray(history) ? history : [];
|
|
506
507
|
console.log(`[${ts}] ▶ ${text}${hist.length ? ` (history: ${hist.length} turn${hist.length === 1 ? '' : 's'})` : ''}`);
|
|
507
508
|
startTurnTimer();
|
|
508
|
-
handleMessage(conversationId, text, sessionId ?? null, hist, auth, vaultFileOpen, clientCapabilities, syncedFolders, agentSlug).catch((err) => {
|
|
509
|
+
handleMessage(conversationId, text, sessionId ?? null, hist, auth, vaultFileOpen, clientCapabilities, syncedFolders, agentSlug, model).catch((err) => {
|
|
509
510
|
stopTurnTimer();
|
|
510
511
|
console.error(`[bridge] handleMessage error: ${err.message}`);
|
|
511
512
|
});
|