Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@ai-sdk/openai-compatible": "^1.0.19",
"@ai-sdk/react": "^2.0.35",
"@ai-sdk/xai": "^2.0.16",
"@blink-sdk/compute": "^0.0.15",
"@blink-sdk/compute-protocol": "^0.0.6",
"@blink.so/api": "^1.0.0",
"@clack/prompts": "^0.11.0",
Expand Down Expand Up @@ -2594,6 +2595,8 @@

"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=="],

"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=="],

"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=="],

"body-parser/iconv-lite": ["iconv-lite@0.6.3", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw=="],
Expand Down
1 change: 1 addition & 0 deletions packages/blink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"@ai-sdk/openai-compatible": "^1.0.19",
"@ai-sdk/react": "^2.0.35",
"@ai-sdk/xai": "^2.0.16",
"@blink-sdk/compute": "^0.0.15",
"@blink-sdk/compute-protocol": "^0.0.6",
"@blink.so/api": "^1.0.0",
"@clack/prompts": "^0.11.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/blink/src/cli/chat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import open from "open";
import { WebSocket } from "ws";
import { WorkspaceConnect } from "./connect";
import { openUrl } from "./lib/util";

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

const token = await tokenPromise;

Expand Down
26 changes: 2 additions & 24 deletions packages/blink/src/cli/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import XDGAppPaths from "xdg-app-paths";
import chalk from "chalk";
import { spinner } from "@clack/prompts";
import open from "open";
import { openUrl } from "./util";

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

/**
* Opens the browser at the given URL and handles errors.
*/
async function openBrowser(url: string): Promise<void> {
try {
const subprocess = await open(url);
// Catch spawn errors without waiting for the browser to close
subprocess.once("error", (_err: Error) => {
console.log(
chalk.yellow(
`Could not open the browser. Please visit the URL manually: ${url}`
)
);
});
} catch (_err) {
console.log(
chalk.yellow(
`Could not open the browser. Please visit the URL manually: ${url}`
)
);
}
}

/**
* Login makes the CLI output the URL to authenticate with Blink.
* It returns a valid auth token.
Expand Down Expand Up @@ -184,7 +162,7 @@ export async function login(): Promise<string> {

// Wait for authUrl to be initialized before opening
await authUrlInitializedPromise;
await openBrowser(authUrl!);
await openUrl(authUrl!);
}
});

Expand Down
26 changes: 26 additions & 0 deletions packages/blink/src/cli/lib/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import open from "open";
import chalk from "chalk";

export async function openUrl(
url: string,
errorMessage: string | undefined = undefined
): Promise<void> {
try {
const proc = await open(url);
proc.once("error", (_error) => {
console.log(
chalk.yellow(
errorMessage ??
`Could not open the browser. Please visit the URL manually: ${url}`
)
);
});
} catch (_error) {
console.log(
chalk.yellow(
errorMessage ??
`Could not open the browser. Please visit the URL manually: ${url}`
)
);
}
}
12 changes: 5 additions & 7 deletions packages/blink/src/cli/setup-slack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Client from "@blink.so/api";
import crypto from "crypto";
import chalk from "chalk";
import util from "node:util";
import { openUrl } from "./lib/util";

export async function verifySlackCredentials(
botToken: string
Expand Down Expand Up @@ -366,13 +367,10 @@ export async function setupSlackApp(
}

if (shouldOpen) {
try {
await open(slackAppUrl);
} catch (error) {
log.warn(
`Could not automatically open browser. Please visit the URL manually.`
);
}
await openUrl(
slackAppUrl,
"Could not open the browser. Please visit the URL manually."
);
}

// Ask for app ID
Expand Down
15 changes: 3 additions & 12 deletions packages/blink/src/edit/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from "./tools/create-github-app";
import { createSlackApp, createSlackAppSchema } from "./tools/create-slack-app";
import { TSServer } from "./tsserver";
import { openUrl } from "../cli/lib/util";

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

// Open the URL in the browser
const opened = await open(url);
opened.once("error", (err) => {
console.log(
`Could not open the browser. Please visit the URL manually: ${url}`
);
});
const opened = await openUrl(url);

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

// Open the URL in the browser
const opened = await open(url);
opened.once("error", (err) => {
console.log(
`Could not open the browser. Please visit the URL manually: ${url}`
);
});
await openUrl(url);

return `Opened Slack App creation URL in browser: ${url}`;
},
Expand Down
Loading