Skip to content

Commit 0361366

Browse files
authored
fix: dont crash on browser open when xdg-open not available (#1)
1 parent 599ceef commit 0361366

File tree

7 files changed

+42
-44
lines changed

7 files changed

+42
-44
lines changed

bun.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@ai-sdk/openai-compatible": "^1.0.19",
2727
"@ai-sdk/react": "^2.0.35",
2828
"@ai-sdk/xai": "^2.0.16",
29+
"@blink-sdk/compute": "^0.0.15",
2930
"@blink-sdk/compute-protocol": "^0.0.6",
3031
"@blink.so/api": "^1.0.0",
3132
"@clack/prompts": "^0.11.0",
@@ -2594,6 +2595,8 @@
25942595

25952596
"app-builder-lib/tar": ["tar@6.2.1", "", { "dependencies": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", "minipass": "^5.0.0", "minizlib": "^2.1.1", "mkdirp": "^1.0.3", "yallist": "^4.0.0" } }, "sha512-DZ4yORTwrbTj/7MZYq2w+/ZFdI6OZ/f9SFHR+71gIVUZhOQPHzVCLpvRnPgyaMpfWxxk/4ONva3GQSyNIKRv6A=="],
25962597

2598+
"blink/@blink-sdk/compute": ["@blink-sdk/compute@0.0.15", "", { "peerDependencies": { "@blink-sdk/compute-protocol": ">= 0.0.6", "ai": ">= 5", "zod": ">= 4" } }, "sha512-G4OekwJIyZzVfJqcK35huomIZvfnDJMLwDsOGVrcIIhQ2xVwqixb1xZpj4jBtmDmbh+FbjjHplHp+CKRF7mamA=="],
2599+
25972600
"blink/@blink.so/api": ["@blink.so/api@1.0.0", "", { "optionalDependencies": { "@blink-sdk/compute-protocol": ">= 0.0.2" }, "peerDependencies": { "ai": ">= 5", "react": ">= 18", "zod": ">= 4" }, "optionalPeers": ["react"] }, "sha512-mBYfopecR+XaMw/W78H6aGgKyZMh99YwcGAU17LVAL+kk4uweJX3cul7958C3f8ovKSeXuXA33t64DbjY3Zi8w=="],
25982601

25992602
"body-parser/iconv-lite": ["iconv-lite@0.6.3", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw=="],

packages/blink/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@ai-sdk/openai-compatible": "^1.0.19",
8181
"@ai-sdk/react": "^2.0.35",
8282
"@ai-sdk/xai": "^2.0.16",
83+
"@blink-sdk/compute": "^0.0.15",
8384
"@blink-sdk/compute-protocol": "^0.0.6",
8485
"@blink.so/api": "^1.0.0",
8586
"@clack/prompts": "^0.11.0",

packages/blink/src/cli/chat.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import open from "open";
22
import { WebSocket } from "ws";
33
import { WorkspaceConnect } from "./connect";
4+
import { openUrl } from "./lib/util";
45

56
export default async function chat() {
67
const id = crypto.randomUUID();
@@ -21,7 +22,7 @@ export default async function chat() {
2122
});
2223
const url = `https://blink.so/legacy-auth?id=${id}&type=workspace`;
2324
console.log(`Opening the following URL in your browser: ${url}`);
24-
await open(url);
25+
await openUrl(url);
2526

2627
const token = await tokenPromise;
2728

packages/blink/src/cli/lib/auth.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import XDGAppPaths from "xdg-app-paths";
1111
import chalk from "chalk";
1212
import { spinner } from "@clack/prompts";
1313
import open from "open";
14+
import { openUrl } from "./util";
1415

1516
/**
1617
* Gets the auth token for the Blink CLI.
@@ -128,29 +129,6 @@ function setupEnterKeyListener(onEnter: () => void): StdinCleanup {
128129
return { cleanup };
129130
}
130131

131-
/**
132-
* Opens the browser at the given URL and handles errors.
133-
*/
134-
async function openBrowser(url: string): Promise<void> {
135-
try {
136-
const subprocess = await open(url);
137-
// Catch spawn errors without waiting for the browser to close
138-
subprocess.once("error", (_err: Error) => {
139-
console.log(
140-
chalk.yellow(
141-
`Could not open the browser. Please visit the URL manually: ${url}`
142-
)
143-
);
144-
});
145-
} catch (_err) {
146-
console.log(
147-
chalk.yellow(
148-
`Could not open the browser. Please visit the URL manually: ${url}`
149-
)
150-
);
151-
}
152-
}
153-
154132
/**
155133
* Login makes the CLI output the URL to authenticate with Blink.
156134
* It returns a valid auth token.
@@ -184,7 +162,7 @@ export async function login(): Promise<string> {
184162

185163
// Wait for authUrl to be initialized before opening
186164
await authUrlInitializedPromise;
187-
await openBrowser(authUrl!);
165+
await openUrl(authUrl!);
188166
}
189167
});
190168

packages/blink/src/cli/lib/util.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import open from "open";
2+
import chalk from "chalk";
3+
4+
export async function openUrl(
5+
url: string,
6+
errorMessage: string | undefined = undefined
7+
): Promise<void> {
8+
try {
9+
const proc = await open(url);
10+
proc.once("error", (_error) => {
11+
console.log(
12+
chalk.yellow(
13+
errorMessage ??
14+
`Could not open the browser. Please visit the URL manually: ${url}`
15+
)
16+
);
17+
});
18+
} catch (_error) {
19+
console.log(
20+
chalk.yellow(
21+
errorMessage ??
22+
`Could not open the browser. Please visit the URL manually: ${url}`
23+
)
24+
);
25+
}
26+
}

packages/blink/src/cli/setup-slack-app.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Client from "@blink.so/api";
1717
import crypto from "crypto";
1818
import chalk from "chalk";
1919
import util from "node:util";
20+
import { openUrl } from "./lib/util";
2021

2122
export async function verifySlackCredentials(
2223
botToken: string
@@ -366,13 +367,10 @@ export async function setupSlackApp(
366367
}
367368

368369
if (shouldOpen) {
369-
try {
370-
await open(slackAppUrl);
371-
} catch (error) {
372-
log.warn(
373-
`Could not automatically open browser. Please visit the URL manually.`
374-
);
375-
}
370+
await openUrl(
371+
slackAppUrl,
372+
"Could not open the browser. Please visit the URL manually."
373+
);
376374
}
377375

378376
// Ask for app ID

packages/blink/src/edit/agent.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from "./tools/create-github-app";
2626
import { createSlackApp, createSlackAppSchema } from "./tools/create-slack-app";
2727
import { TSServer } from "./tsserver";
28+
import { openUrl } from "../cli/lib/util";
2829

2930
export interface EditAgent {
3031
agent: Agent<UIMessage>;
@@ -234,12 +235,7 @@ GITHUB_PRIVATE_KEY="${btoa(data.pem)}"
234235
);
235236

236237
// Open the URL in the browser
237-
const opened = await open(url);
238-
opened.once("error", (err) => {
239-
console.log(
240-
`Could not open the browser. Please visit the URL manually: ${url}`
241-
);
242-
});
238+
const opened = await openUrl(url);
243239

244240
return `Opening GitHub App creation URL in browser: ${url}`;
245241
},
@@ -260,12 +256,7 @@ You MUST GUIDE THE USER through these steps - do not provide all the steps at on
260256
const url = createSlackApp(args);
261257

262258
// Open the URL in the browser
263-
const opened = await open(url);
264-
opened.once("error", (err) => {
265-
console.log(
266-
`Could not open the browser. Please visit the URL manually: ${url}`
267-
);
268-
});
259+
await openUrl(url);
269260

270261
return `Opened Slack App creation URL in browser: ${url}`;
271262
},

0 commit comments

Comments
 (0)