mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-13 23:53:25 +00:00
Compare commits
27 Commits
feat/model
...
fix/mar26-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc90766714 | ||
|
|
de50c5b378 | ||
|
|
ffe48948ff | ||
|
|
03b45013a6 | ||
|
|
aa85907212 | ||
|
|
085352a6f0 | ||
|
|
c0578d0e53 | ||
|
|
663c18ee97 | ||
|
|
48727750b4 | ||
|
|
30a3a96a57 | ||
|
|
6773ce39da | ||
|
|
342a3e4a07 | ||
|
|
09406ea794 | ||
|
|
1f00cbc9cc | ||
|
|
422a829f5e | ||
|
|
ed109fcedf | ||
|
|
19af96d08e | ||
|
|
e0304b203c | ||
|
|
af65bdbcfb | ||
|
|
d79c2a4123 | ||
|
|
e3d57e5347 | ||
|
|
392312f203 | ||
|
|
0f193055c7 | ||
|
|
f45cb58889 | ||
|
|
37ead6d129 | ||
|
|
5ea9463030 | ||
|
|
dde35ccbd5 |
2
.github/workflows/pr-title.yml
vendored
2
.github/workflows/pr-title.yml
vendored
@@ -2,7 +2,7 @@ name: PR Conventional Commit Validation
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, edited]
|
||||
types: [opened, edited]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
|
||||
148
.github/workflows/release-agent-extension.yml
vendored
Normal file
148
.github/workflows/release-agent-extension.yml
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
name: Release Agent Extension
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: release-agent-extension
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
release:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
defaults:
|
||||
run:
|
||||
working-directory: packages/browseros-agent/apps/agent
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun ci
|
||||
working-directory: packages/browseros-agent
|
||||
|
||||
- name: Build and zip extension
|
||||
run: bun run codegen && bun run zip
|
||||
env:
|
||||
VITE_PUBLIC_BROWSEROS_API: https://api.browseros.com
|
||||
|
||||
- name: Get version and zip path
|
||||
id: version
|
||||
run: |
|
||||
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
|
||||
echo "release_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
||||
ZIP_FILE=$(ls "$(pwd)/dist/"*-chrome.zip | head -n 1)
|
||||
echo "zip_path=$ZIP_FILE" >> "$GITHUB_OUTPUT"
|
||||
echo "zip_name=$(basename "$ZIP_FILE")" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Generate release notes
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
AGENT_PATH="packages/browseros-agent/apps/agent"
|
||||
CURRENT_TAG="agent-extension-v${{ steps.version.outputs.version }}"
|
||||
PREV_TAG=$(git tag -l "agent-extension-v*" --sort=-v:refname | grep -v "^${CURRENT_TAG}$" | head -n 1)
|
||||
|
||||
if [ -z "$PREV_TAG" ]; then
|
||||
echo "Initial release" > /tmp/release-notes.md
|
||||
else
|
||||
COMMITS=$(git log "$PREV_TAG"..HEAD --pretty=format:"%H" -- "$AGENT_PATH")
|
||||
|
||||
if [ -z "$COMMITS" ]; then
|
||||
echo "No notable changes." > /tmp/release-notes.md
|
||||
else
|
||||
echo "## What's Changed" > /tmp/release-notes.md
|
||||
echo "" >> /tmp/release-notes.md
|
||||
|
||||
while IFS= read -r SHA; do
|
||||
SUBJECT=$(git log -1 --pretty=format:"%s" "$SHA")
|
||||
PR_NUM=$(gh api "/repos/${{ github.repository }}/commits/${SHA}/pulls" --jq '.[0].number // empty' 2>/dev/null)
|
||||
|
||||
# Skip PR number if already in the commit subject (squash merges include it)
|
||||
if [ -n "$PR_NUM" ] && ! echo "$SUBJECT" | grep -qF "(#${PR_NUM})"; then
|
||||
echo "- ${SUBJECT} (#${PR_NUM})" >> /tmp/release-notes.md
|
||||
else
|
||||
echo "- ${SUBJECT}" >> /tmp/release-notes.md
|
||||
fi
|
||||
done <<< "$COMMITS"
|
||||
fi
|
||||
fi
|
||||
working-directory: ${{ github.workspace }}
|
||||
|
||||
- name: Create GitHub release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TAG="agent-extension-v${{ steps.version.outputs.version }}"
|
||||
RELEASE_SHA="${{ steps.version.outputs.release_sha }}"
|
||||
TITLE="BrowserOS Agent Extension v${{ steps.version.outputs.version }}"
|
||||
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG already exists, skipping tag creation"
|
||||
else
|
||||
git tag "$TAG" "$RELEASE_SHA"
|
||||
fi
|
||||
|
||||
if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
|
||||
echo "Tag $TAG already on remote, skipping push"
|
||||
else
|
||||
git push origin "$TAG"
|
||||
fi
|
||||
|
||||
if gh release view "$TAG" >/dev/null 2>&1; then
|
||||
echo "Release $TAG already exists, updating"
|
||||
gh release edit "$TAG" --title "$TITLE" --notes-file /tmp/release-notes.md
|
||||
gh release upload "$TAG" "${{ steps.version.outputs.zip_path }}" --clobber
|
||||
else
|
||||
gh release create "$TAG" \
|
||||
--title "$TITLE" \
|
||||
--notes-file /tmp/release-notes.md \
|
||||
"${{ steps.version.outputs.zip_path }}"
|
||||
fi
|
||||
working-directory: ${{ github.workspace }}
|
||||
|
||||
- name: Update CHANGELOG.md via PR
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
DATE=$(date -u +"%Y-%m-%d")
|
||||
BRANCH="docs/agent-extension-changelog-v${VERSION}"
|
||||
CHANGELOG="packages/browseros-agent/apps/agent/CHANGELOG.md"
|
||||
|
||||
git checkout main
|
||||
|
||||
{
|
||||
head -n 1 "$CHANGELOG"
|
||||
echo ""
|
||||
echo "## v${VERSION} (${DATE})"
|
||||
echo ""
|
||||
cat /tmp/release-notes.md
|
||||
echo ""
|
||||
tail -n +2 "$CHANGELOG"
|
||||
} > /tmp/new-changelog.md
|
||||
mv /tmp/new-changelog.md "$CHANGELOG"
|
||||
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git checkout -b "$BRANCH"
|
||||
git add "$CHANGELOG"
|
||||
git commit -m "docs: update agent extension changelog for v${VERSION}"
|
||||
git push origin "$BRANCH"
|
||||
|
||||
gh pr create \
|
||||
--title "docs: update agent extension changelog for v${VERSION}" \
|
||||
--body "Auto-generated changelog update for BrowserOS Agent Extension v${VERSION}." \
|
||||
--base main \
|
||||
--head "$BRANCH"
|
||||
|
||||
gh pr merge "$BRANCH" --squash --auto || true
|
||||
working-directory: ${{ github.workspace }}
|
||||
131
.github/workflows/release-agent-sdk.yml
vendored
131
.github/workflows/release-agent-sdk.yml
vendored
@@ -3,16 +3,25 @@ name: Release Agent SDK
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: release-agent-sdk
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
defaults:
|
||||
run:
|
||||
working-directory: packages/browseros-agent/packages/agent-sdk
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
|
||||
@@ -31,7 +40,129 @@ jobs:
|
||||
- name: Test
|
||||
run: bun test
|
||||
|
||||
- name: Get version
|
||||
id: version
|
||||
run: |
|
||||
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
|
||||
echo "release_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Generate release notes
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
SDK_PATH="packages/browseros-agent/packages/agent-sdk"
|
||||
CURRENT_TAG="agent-sdk-v${{ steps.version.outputs.version }}"
|
||||
# Find the previous tag, excluding the current version's tag
|
||||
# (which may already exist from a prior failed run)
|
||||
PREV_TAG=$(git tag -l "agent-sdk-v*" --sort=-v:refname | grep -v "^${CURRENT_TAG}$" | head -n 1)
|
||||
|
||||
if [ -z "$PREV_TAG" ]; then
|
||||
echo "Initial release" > /tmp/release-notes.md
|
||||
else
|
||||
# Get commits scoped to the SDK directory
|
||||
COMMITS=$(git log "$PREV_TAG"..HEAD --pretty=format:"%H" -- "$SDK_PATH")
|
||||
|
||||
if [ -z "$COMMITS" ]; then
|
||||
echo "No notable changes." > /tmp/release-notes.md
|
||||
else
|
||||
echo "## What's Changed" > /tmp/release-notes.md
|
||||
echo "" >> /tmp/release-notes.md
|
||||
|
||||
# For each commit, find the associated PR and format with author
|
||||
CONTRIBUTORS=""
|
||||
while IFS= read -r SHA; do
|
||||
# Get commit subject and author
|
||||
SUBJECT=$(git log -1 --pretty=format:"%s" "$SHA")
|
||||
AUTHOR=$(git log -1 --pretty=format:"%an" "$SHA")
|
||||
GITHUB_USER=$(gh api "/repos/${{ github.repository }}/commits/${SHA}" --jq '.author.login // empty' 2>/dev/null)
|
||||
|
||||
# Find associated PR number
|
||||
PR_NUM=$(gh api "/repos/${{ github.repository }}/commits/${SHA}/pulls" --jq '.[0].number // empty' 2>/dev/null)
|
||||
|
||||
# Format line: skip PR number if already in the commit subject
|
||||
# (squash merges include "(#123)" in the subject automatically)
|
||||
if [ -n "$PR_NUM" ] && ! echo "$SUBJECT" | grep -qF "(#${PR_NUM})"; then
|
||||
echo "- ${SUBJECT} (#${PR_NUM})" >> /tmp/release-notes.md
|
||||
else
|
||||
echo "- ${SUBJECT}" >> /tmp/release-notes.md
|
||||
fi
|
||||
done <<< "$COMMITS"
|
||||
fi
|
||||
fi
|
||||
working-directory: ${{ github.workspace }}
|
||||
|
||||
- name: Publish
|
||||
run: npm publish --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- name: Create GitHub release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TAG="agent-sdk-v${{ steps.version.outputs.version }}"
|
||||
RELEASE_SHA="${{ steps.version.outputs.release_sha }}"
|
||||
TITLE="@browseros-ai/agent-sdk v${{ steps.version.outputs.version }}"
|
||||
|
||||
# Create or reuse tag (idempotent for re-runs)
|
||||
if git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
echo "Tag $TAG already exists, skipping tag creation"
|
||||
else
|
||||
git tag "$TAG" "$RELEASE_SHA"
|
||||
fi
|
||||
|
||||
# Push tag (skip if already on remote)
|
||||
if git ls-remote --tags origin "$TAG" | grep -q "$TAG"; then
|
||||
echo "Tag $TAG already on remote, skipping push"
|
||||
else
|
||||
git push origin "$TAG"
|
||||
fi
|
||||
|
||||
# Create or update release
|
||||
if gh release view "$TAG" >/dev/null 2>&1; then
|
||||
echo "Release $TAG already exists, updating"
|
||||
gh release edit "$TAG" --title "$TITLE" --notes-file /tmp/release-notes.md
|
||||
else
|
||||
gh release create "$TAG" --title "$TITLE" --notes-file /tmp/release-notes.md
|
||||
fi
|
||||
working-directory: ${{ github.workspace }}
|
||||
|
||||
- name: Update CHANGELOG.md via PR
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
VERSION="${{ steps.version.outputs.version }}"
|
||||
DATE=$(date -u +"%Y-%m-%d")
|
||||
BRANCH="docs/agent-sdk-changelog-v${VERSION}"
|
||||
CHANGELOG="packages/browseros-agent/packages/agent-sdk/CHANGELOG.md"
|
||||
|
||||
# Return to main before branching
|
||||
git checkout main
|
||||
|
||||
# Use head/tail to safely insert without sed quoting issues
|
||||
{
|
||||
head -n 1 "$CHANGELOG"
|
||||
echo ""
|
||||
echo "## v${VERSION} (${DATE})"
|
||||
echo ""
|
||||
cat /tmp/release-notes.md
|
||||
echo ""
|
||||
tail -n +2 "$CHANGELOG"
|
||||
} > /tmp/new-changelog.md
|
||||
mv /tmp/new-changelog.md "$CHANGELOG"
|
||||
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git checkout -b "$BRANCH"
|
||||
git add "$CHANGELOG"
|
||||
git commit -m "docs: update agent-sdk changelog for v${VERSION}"
|
||||
git push origin "$BRANCH"
|
||||
|
||||
gh pr create \
|
||||
--title "docs: update agent-sdk changelog for v${VERSION}" \
|
||||
--body "Auto-generated changelog update for @browseros-ai/agent-sdk v${VERSION}." \
|
||||
--base main \
|
||||
--head "$BRANCH"
|
||||
|
||||
gh pr merge "$BRANCH" --squash --auto || true
|
||||
working-directory: ${{ github.workspace }}
|
||||
|
||||
122
.github/workflows/release-cli.yml
vendored
Normal file
122
.github/workflows/release-cli.yml
vendored
Normal file
@@ -0,0 +1,122 @@
|
||||
name: Release CLI
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: "Release version (e.g. 0.1.0)"
|
||||
required: true
|
||||
type: string
|
||||
|
||||
concurrency:
|
||||
group: release-cli
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
release:
|
||||
if: github.ref == 'refs/heads/main'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
defaults:
|
||||
run:
|
||||
working-directory: packages/browseros-agent/apps/cli
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: packages/browseros-agent/apps/cli/go.mod
|
||||
|
||||
- name: Run tests
|
||||
run: go test ./... -v
|
||||
|
||||
- name: Run vet
|
||||
run: go vet ./...
|
||||
|
||||
- name: Build all platforms
|
||||
run: |
|
||||
VERSION="${{ inputs.version }}"
|
||||
LDFLAGS="-s -w -X main.version=${VERSION}"
|
||||
DIST="dist"
|
||||
mkdir -p "$DIST"
|
||||
|
||||
for pair in darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64 windows/arm64; do
|
||||
OS="${pair%/*}"
|
||||
ARCH="${pair#*/}"
|
||||
BIN="browseros-cli"
|
||||
EXT=""
|
||||
if [ "$OS" = "windows" ]; then EXT=".exe"; fi
|
||||
|
||||
echo "Building ${OS}/${ARCH}..."
|
||||
GOOS=$OS GOARCH=$ARCH CGO_ENABLED=0 go build -trimpath -ldflags "$LDFLAGS" -o "${DIST}/${BIN}${EXT}" .
|
||||
|
||||
ARCHIVE="browseros-cli_${VERSION}_${OS}_${ARCH}"
|
||||
if [ "$OS" = "windows" ]; then
|
||||
(cd "$DIST" && zip "${ARCHIVE}.zip" "${BIN}${EXT}")
|
||||
else
|
||||
(cd "$DIST" && tar czf "${ARCHIVE}.tar.gz" "${BIN}")
|
||||
fi
|
||||
rm "${DIST}/${BIN}${EXT}"
|
||||
done
|
||||
|
||||
(cd "$DIST" && sha256sum *.tar.gz *.zip > checksums.txt)
|
||||
echo "=== Built artifacts ==="
|
||||
ls -lh "$DIST"
|
||||
|
||||
- name: Generate release notes
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
CLI_PATH="packages/browseros-agent/apps/cli"
|
||||
TAG="browseros-cli-v${{ inputs.version }}"
|
||||
PREV_TAG=$(git tag -l "browseros-cli-v*" --sort=-v:refname | grep -v "^${TAG}$" | head -n 1)
|
||||
|
||||
if [ -z "$PREV_TAG" ]; then
|
||||
echo "Initial release of browseros-cli." > /tmp/release-notes.md
|
||||
else
|
||||
COMMITS=$(git log "$PREV_TAG"..HEAD --pretty=format:"%H" -- "$CLI_PATH")
|
||||
|
||||
if [ -z "$COMMITS" ]; then
|
||||
echo "No notable changes." > /tmp/release-notes.md
|
||||
else
|
||||
echo "## What's Changed" > /tmp/release-notes.md
|
||||
echo "" >> /tmp/release-notes.md
|
||||
|
||||
while IFS= read -r SHA; do
|
||||
SUBJECT=$(git log -1 --pretty=format:"%s" "$SHA")
|
||||
PR_NUM=$(gh api "/repos/${{ github.repository }}/commits/${SHA}/pulls" --jq '.[0].number // empty' 2>/dev/null)
|
||||
|
||||
if [ -n "$PR_NUM" ] && ! echo "$SUBJECT" | grep -qF "(#${PR_NUM})"; then
|
||||
echo "- ${SUBJECT} (#${PR_NUM})" >> /tmp/release-notes.md
|
||||
else
|
||||
echo "- ${SUBJECT}" >> /tmp/release-notes.md
|
||||
fi
|
||||
done <<< "$COMMITS"
|
||||
fi
|
||||
fi
|
||||
working-directory: ${{ github.workspace }}
|
||||
|
||||
- name: Create tag and release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
TAG="browseros-cli-v${{ inputs.version }}"
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
|
||||
git tag -a "$TAG" -m "browseros-cli v${{ inputs.version }}"
|
||||
git push origin "$TAG"
|
||||
fi
|
||||
|
||||
CLI_DIST="packages/browseros-agent/apps/cli/dist"
|
||||
gh release create "$TAG" \
|
||||
--title "browseros-cli v${{ inputs.version }}" \
|
||||
--notes-file /tmp/release-notes.md \
|
||||
${CLI_DIST}/*
|
||||
working-directory: ${{ github.workspace }}
|
||||
19
README.md
19
README.md
@@ -43,6 +43,24 @@
|
||||
|
||||
4. Start automating!
|
||||
|
||||
## Install `browseros-cli`
|
||||
|
||||
Use `browseros-cli` when you want to control BrowserOS from the terminal or scripts via the BrowserOS MCP server.
|
||||
|
||||
### macOS / Linux
|
||||
|
||||
```bash
|
||||
curl -fsSL https://cdn.browseros.com/cli/install.sh | bash
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
```powershell
|
||||
irm https://cdn.browseros.com/cli/install.ps1 | iex
|
||||
```
|
||||
|
||||
After install, run `browseros-cli init` to point the CLI at your BrowserOS MCP server.
|
||||
|
||||
## What makes BrowserOS special
|
||||
- 🏠 Feels like home — same Chrome interface, all your extensions just work
|
||||
- 🤖 AI agents that run on YOUR browser, not in the cloud
|
||||
@@ -164,4 +182,3 @@ Thank you to all our supporters!
|
||||
Built with ❤️ from San Francisco
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
1
packages/browseros-agent/.gitignore
vendored
1
packages/browseros-agent/.gitignore
vendored
@@ -195,3 +195,4 @@ test-results/
|
||||
.agent/
|
||||
.llm/
|
||||
.grove/
|
||||
docs/plans/2026-03-24-models-dev-integration.md
|
||||
|
||||
@@ -81,6 +81,9 @@ bun run dev:server # Build server for development
|
||||
bun run dev:ext # Build extension for development
|
||||
bun run dist:server # Build server for production (all targets)
|
||||
bun run dist:ext # Build extension for production
|
||||
|
||||
# Refresh models.dev data
|
||||
bun run generate:models # Fetches latest from models.dev/api.json
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
6
packages/browseros-agent/apps/agent/CHANGELOG.md
Normal file
6
packages/browseros-agent/apps/agent/CHANGELOG.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# BrowserOS Agent Extension
|
||||
|
||||
## v0.0.52 (2026-03-26)
|
||||
|
||||
Initial release
|
||||
|
||||
@@ -66,7 +66,7 @@ export const RunResultDialog: FC<RunResultDialogProps> = ({
|
||||
|
||||
return (
|
||||
<Dialog open={!!run} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="sm:max-w-2xl">
|
||||
<DialogContent className="sm:w-[70vw] sm:max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
{run.status === 'completed' ? (
|
||||
@@ -94,7 +94,7 @@ export const RunResultDialog: FC<RunResultDialogProps> = ({
|
||||
<p className="text-destructive text-sm">{run.result}</p>
|
||||
</div>
|
||||
) : run.result ? (
|
||||
<div className="prose prose-sm dark:prose-invert [&_[data-streamdown='code-block']]:!w-full [&_[data-streamdown='table-wrapper']]:!w-full max-w-none break-words rounded-lg border border-border bg-muted/50 p-4">
|
||||
<div className="prose prose-sm dark:prose-invert [&_[data-streamdown='code-block']]:!w-full [&_[data-streamdown='table-wrapper']]:!w-full max-w-none break-words rounded-lg border border-border bg-muted/50 p-4 [&_[data-streamdown='table-wrapper']]:overflow-x-auto">
|
||||
<MessageResponse>{run.result}</MessageResponse>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
@@ -14,7 +14,7 @@ export const CreditBadge: FC<CreditBadgeProps> = ({ credits, onClick }) => {
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className={cn(
|
||||
'inline-flex items-center gap-1 rounded-md px-1.5 py-0.5 font-medium text-xs transition-colors hover:bg-muted/50',
|
||||
'inline-flex cursor-pointer items-center gap-1 rounded-md px-1.5 py-0.5 font-medium text-xs transition-colors hover:bg-muted/50',
|
||||
getCreditTextColor(credits),
|
||||
)}
|
||||
title={`${credits} credits remaining`}
|
||||
|
||||
@@ -17,7 +17,7 @@ export const McpPromoBanner: FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="relative flex items-center gap-4 rounded-xl border border-border bg-card p-4 shadow-sm transition-all hover:shadow-md">
|
||||
<div className="flex items-center gap-4 rounded-xl border border-border bg-card p-4 shadow-sm transition-all hover:shadow-md">
|
||||
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-[var(--accent-orange)]/10">
|
||||
<Server className="h-5 w-5 text-[var(--accent-orange)]" />
|
||||
</div>
|
||||
@@ -48,7 +48,7 @@ export const McpPromoBanner: FC = () => {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setDismissed(true)}
|
||||
className="absolute top-2 right-2 rounded-sm p-1 text-muted-foreground opacity-50 transition-opacity hover:opacity-100"
|
||||
className="shrink-0 rounded-sm p-1 text-muted-foreground opacity-50 transition-opacity hover:opacity-100"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { CheckCircle2, ExternalLink, Loader2, XCircle } from 'lucide-react'
|
||||
import { type FC, useEffect, useState } from 'react'
|
||||
import {
|
||||
CheckCircle2,
|
||||
ChevronDown,
|
||||
ExternalLink,
|
||||
Loader2,
|
||||
SearchIcon,
|
||||
XCircle,
|
||||
} from 'lucide-react'
|
||||
import { type FC, useEffect, useRef, useState } from 'react'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { z } from 'zod/v3'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -47,7 +54,12 @@ import {
|
||||
import { type TestResult, testProvider } from '@/lib/llm-providers/testProvider'
|
||||
import type { LlmProviderConfig, ProviderType } from '@/lib/llm-providers/types'
|
||||
import { track } from '@/lib/metrics/track'
|
||||
import { getModelContextLength, getModelOptions } from './models'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
getModelContextLength,
|
||||
getModelsForProvider,
|
||||
type ModelInfo,
|
||||
} from './models'
|
||||
|
||||
const providerTypeEnum = z.enum([
|
||||
'moonshot',
|
||||
@@ -163,6 +175,107 @@ export const providerFormSchema = z
|
||||
*/
|
||||
export type ProviderFormValues = z.infer<typeof providerFormSchema>
|
||||
|
||||
function formatContextWindow(tokens: number): string {
|
||||
if (tokens >= 1000000)
|
||||
return `${(tokens / 1000000).toFixed(tokens % 1000000 === 0 ? 0 : 1)}M`
|
||||
if (tokens >= 1000) return `${Math.round(tokens / 1000)}K`
|
||||
return `${tokens}`
|
||||
}
|
||||
|
||||
function ModelPickerList({
|
||||
models,
|
||||
selectedModelId,
|
||||
onSelect,
|
||||
onCustomSubmit,
|
||||
onClose,
|
||||
}: {
|
||||
models: ModelInfo[]
|
||||
selectedModelId: string
|
||||
onSelect: (modelId: string) => void
|
||||
onCustomSubmit: (modelId: string) => void
|
||||
onClose: () => void
|
||||
}) {
|
||||
const [search, setSearch] = useState('')
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
inputRef.current?.focus()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (e: MouseEvent) => {
|
||||
if (
|
||||
containerRef.current &&
|
||||
!containerRef.current.contains(e.target as Node)
|
||||
) {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside)
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside)
|
||||
}, [onClose])
|
||||
|
||||
const query = search.toLowerCase()
|
||||
const filtered = query
|
||||
? models.filter((m) => m.modelId.toLowerCase().includes(query))
|
||||
: models
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' && search) {
|
||||
e.preventDefault()
|
||||
onCustomSubmit(search)
|
||||
}
|
||||
if (e.key === 'Escape') {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={containerRef} className="rounded-md border">
|
||||
<div className="flex items-center gap-2 border-b px-3">
|
||||
<SearchIcon className="h-4 w-4 shrink-0 text-muted-foreground opacity-50" />
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="Search or type a custom model ID..."
|
||||
className="flex h-9 w-full bg-transparent py-2 text-sm outline-none placeholder:text-muted-foreground"
|
||||
/>
|
||||
</div>
|
||||
<div className="max-h-[200px] overflow-y-auto">
|
||||
{filtered.length > 0 ? (
|
||||
filtered.map((model) => {
|
||||
const isSelected = selectedModelId === model.modelId
|
||||
return (
|
||||
<button
|
||||
key={model.modelId}
|
||||
type="button"
|
||||
onClick={() => onSelect(model.modelId)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between px-3 py-2 text-left text-sm transition-colors hover:bg-accent',
|
||||
isSelected && 'bg-accent font-medium',
|
||||
)}
|
||||
>
|
||||
<span className="truncate">{model.modelId}</span>
|
||||
<span className="ml-2 shrink-0 rounded-md bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground">
|
||||
{formatContextWindow(model.contextLength)}
|
||||
</span>
|
||||
</button>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<div className="px-3 py-6 text-center text-muted-foreground text-sm">
|
||||
No models match. Press Enter to use "{search}"
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Props for NewProviderDialog
|
||||
* @public
|
||||
@@ -188,9 +301,9 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
initialValues,
|
||||
onSave,
|
||||
}) => {
|
||||
const [isCustomModel, setIsCustomModel] = useState(false)
|
||||
const [isTesting, setIsTesting] = useState(false)
|
||||
const [testResult, setTestResult] = useState<TestResult | null>(null)
|
||||
const [modelListOpen, setModelListOpen] = useState(false)
|
||||
const { supports } = useCapabilities()
|
||||
const { baseUrl: agentServerUrl } = useAgentServerUrl()
|
||||
const kimiLaunch = useKimiLaunch()
|
||||
@@ -261,8 +374,7 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
watchedSessionToken,
|
||||
])
|
||||
|
||||
// Get model options for current provider type
|
||||
const modelOptions = getModelOptions(watchedType as ProviderType)
|
||||
const modelInfoList = getModelsForProvider(watchedType as ProviderType)
|
||||
|
||||
// Handle provider type change (user-initiated via Select)
|
||||
const handleTypeChange = (newType: ProviderType) => {
|
||||
@@ -272,14 +384,13 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
form.setValue('baseUrl', defaultUrl)
|
||||
}
|
||||
form.setValue('modelId', '')
|
||||
setIsCustomModel(false)
|
||||
}
|
||||
|
||||
// Auto-fill context window when model changes (only for new providers)
|
||||
useEffect(() => {
|
||||
if (initialValues?.id) return
|
||||
|
||||
if (watchedModelId && watchedModelId !== 'custom') {
|
||||
if (watchedModelId) {
|
||||
const contextLength = getModelContextLength(
|
||||
watchedType as ProviderType,
|
||||
watchedModelId,
|
||||
@@ -290,17 +401,6 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
}
|
||||
}, [watchedModelId, watchedType, form, initialValues?.id])
|
||||
|
||||
// Handle model selection (including custom option)
|
||||
const handleModelChange = (value: string) => {
|
||||
if (value === 'custom') {
|
||||
setIsCustomModel(true)
|
||||
form.setValue('modelId', '')
|
||||
} else {
|
||||
setIsCustomModel(false)
|
||||
form.setValue('modelId', value)
|
||||
}
|
||||
}
|
||||
|
||||
// Reset form when initialValues change
|
||||
useEffect(() => {
|
||||
if (initialValues) {
|
||||
@@ -325,7 +425,6 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
reasoningEffort: initialValues.reasoningEffort || 'high',
|
||||
reasoningSummary: initialValues.reasoningSummary || 'auto',
|
||||
})
|
||||
setIsCustomModel(false)
|
||||
}
|
||||
}, [initialValues, form])
|
||||
|
||||
@@ -352,7 +451,6 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
reasoningEffort: 'high',
|
||||
reasoningSummary: 'auto',
|
||||
})
|
||||
setIsCustomModel(false)
|
||||
}
|
||||
// Clear test result when dialog opens/closes
|
||||
setTestResult(null)
|
||||
@@ -811,52 +909,51 @@ export const NewProviderDialog: FC<NewProviderDialogProps> = ({
|
||||
control={form.control}
|
||||
name="modelId"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormItem className="flex flex-col">
|
||||
<FormLabel>Model *</FormLabel>
|
||||
{isCustomModel || modelOptions.length === 1 ? (
|
||||
<>
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder={
|
||||
watchedType === 'azure'
|
||||
? 'Enter your deployment name'
|
||||
: watchedType === 'bedrock'
|
||||
? 'e.g., anthropic.claude-3-5-sonnet-20241022-v2:0'
|
||||
: 'Enter custom model ID'
|
||||
}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
{modelOptions.length > 1 && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="link"
|
||||
size="sm"
|
||||
className="h-auto p-0 text-xs"
|
||||
onClick={() => setIsCustomModel(false)}
|
||||
>
|
||||
← Back to model list
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
{modelInfoList.length === 0 ? (
|
||||
<FormControl>
|
||||
<Input
|
||||
placeholder={
|
||||
watchedType === 'azure'
|
||||
? 'Enter your deployment name'
|
||||
: watchedType === 'bedrock'
|
||||
? 'e.g., anthropic.claude-3-5-sonnet-20241022-v2:0'
|
||||
: 'Enter model ID'
|
||||
}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
) : modelListOpen ? (
|
||||
<ModelPickerList
|
||||
models={modelInfoList}
|
||||
selectedModelId={field.value}
|
||||
onSelect={(modelId) => {
|
||||
form.setValue('modelId', modelId)
|
||||
setModelListOpen(false)
|
||||
}}
|
||||
onCustomSubmit={(modelId) => {
|
||||
form.setValue('modelId', modelId)
|
||||
setModelListOpen(false)
|
||||
}}
|
||||
onClose={() => setModelListOpen(false)}
|
||||
/>
|
||||
) : (
|
||||
<Select
|
||||
onValueChange={handleModelChange}
|
||||
value={field.value}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setModelListOpen(true)}
|
||||
className={cn(
|
||||
'flex h-9 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-xs',
|
||||
field.value
|
||||
? 'text-foreground'
|
||||
: 'text-muted-foreground',
|
||||
)}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Select a model" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{modelOptions.map((modelId) => (
|
||||
<SelectItem key={modelId} value={modelId}>
|
||||
{modelId === 'custom' ? '+ Custom model' : modelId}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<span className="truncate">
|
||||
{field.value || 'Select a model...'}
|
||||
</span>
|
||||
<ChevronDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</button>
|
||||
)}
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
@@ -1,98 +1,21 @@
|
||||
import {
|
||||
getModelsDevModels,
|
||||
type ModelsDevModel,
|
||||
} from '@/lib/llm-providers/models-dev'
|
||||
import type { ProviderType } from '@/lib/llm-providers/types'
|
||||
|
||||
/**
|
||||
* Model information with context length
|
||||
*/
|
||||
export interface ModelInfo {
|
||||
modelId: string
|
||||
contextLength: number
|
||||
supportsImages?: boolean
|
||||
supportsReasoning?: boolean
|
||||
supportsToolCall?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Models data organized by provider type (matches backend AIProvider enum)
|
||||
*/
|
||||
export interface ModelsData {
|
||||
anthropic: ModelInfo[]
|
||||
openai: ModelInfo[]
|
||||
'openai-compatible': ModelInfo[]
|
||||
google: ModelInfo[]
|
||||
openrouter: ModelInfo[]
|
||||
azure: ModelInfo[]
|
||||
ollama: ModelInfo[]
|
||||
lmstudio: ModelInfo[]
|
||||
bedrock: ModelInfo[]
|
||||
browseros: ModelInfo[]
|
||||
moonshot: ModelInfo[]
|
||||
'chatgpt-pro': ModelInfo[]
|
||||
'github-copilot': ModelInfo[]
|
||||
'qwen-code': ModelInfo[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Available models per provider with context lengths
|
||||
* Based on: https://github.com/browseros-ai/BrowserOS-agent/blob/main/src/options/data/models.ts
|
||||
*/
|
||||
export const MODELS_DATA: ModelsData = {
|
||||
moonshot: [{ modelId: 'kimi-k2.5', contextLength: 200000 }],
|
||||
anthropic: [
|
||||
{ modelId: 'claude-opus-4-5-20251101', contextLength: 200000 },
|
||||
{ modelId: 'claude-haiku-4-5-20251001', contextLength: 200000 },
|
||||
{ modelId: 'claude-sonnet-4-5-20250929', contextLength: 200000 },
|
||||
{ modelId: 'claude-sonnet-4-20250514', contextLength: 200000 },
|
||||
{ modelId: 'claude-opus-4-20250514', contextLength: 200000 },
|
||||
{ modelId: 'claude-3-7-sonnet-20250219', contextLength: 200000 },
|
||||
{ modelId: 'claude-3-5-haiku-20241022', contextLength: 200000 },
|
||||
],
|
||||
openai: [
|
||||
{ modelId: 'gpt-5.2', contextLength: 200000 },
|
||||
{ modelId: 'gpt-5.2-pro', contextLength: 200000 },
|
||||
{ modelId: 'gpt-5', contextLength: 200000 },
|
||||
{ modelId: 'gpt-5-mini', contextLength: 200000 },
|
||||
{ modelId: 'gpt-5-nano', contextLength: 200000 },
|
||||
{ modelId: 'gpt-4.1', contextLength: 200000 },
|
||||
{ modelId: 'gpt-4.1-mini', contextLength: 200000 },
|
||||
{ modelId: 'o4-mini', contextLength: 200000 },
|
||||
{ modelId: 'o3-mini', contextLength: 200000 },
|
||||
{ modelId: 'gpt-4o', contextLength: 128000 },
|
||||
{ modelId: 'gpt-4o-mini', contextLength: 128000 },
|
||||
],
|
||||
'openai-compatible': [],
|
||||
google: [
|
||||
{ modelId: 'gemini-3-pro-preview', contextLength: 1048576 },
|
||||
{ modelId: 'gemini-3-flash-preview', contextLength: 1048576 },
|
||||
{ modelId: 'gemini-2.5-flash', contextLength: 1048576 },
|
||||
{ modelId: 'gemini-2.5-pro', contextLength: 1048576 },
|
||||
],
|
||||
openrouter: [
|
||||
{ modelId: 'google/gemini-3-pro-preview', contextLength: 1048576 },
|
||||
{ modelId: 'google/gemini-3-flash-preview', contextLength: 1048576 },
|
||||
{ modelId: 'google/gemini-2.5-flash', contextLength: 1048576 },
|
||||
{ modelId: 'anthropic/claude-opus-4.5', contextLength: 200000 },
|
||||
{ modelId: 'anthropic/claude-haiku-4.5', contextLength: 200000 },
|
||||
{ modelId: 'anthropic/claude-sonnet-4.5', contextLength: 200000 },
|
||||
{ modelId: 'anthropic/claude-sonnet-4', contextLength: 200000 },
|
||||
{ modelId: 'anthropic/claude-3.7-sonnet', contextLength: 200000 },
|
||||
{ modelId: 'openai/gpt-4o', contextLength: 128000 },
|
||||
{ modelId: 'openai/gpt-oss-120b', contextLength: 128000 },
|
||||
{ modelId: 'openai/gpt-oss-20b', contextLength: 128000 },
|
||||
{ modelId: 'qwen/qwen3-14b', contextLength: 131072 },
|
||||
{ modelId: 'qwen/qwen3-8b', contextLength: 131072 },
|
||||
],
|
||||
azure: [],
|
||||
ollama: [
|
||||
{ modelId: 'qwen3:4b', contextLength: 262144 },
|
||||
{ modelId: 'qwen3:8b', contextLength: 40960 },
|
||||
{ modelId: 'qwen3:14b', contextLength: 40960 },
|
||||
{ modelId: 'gpt-oss:20b', contextLength: 128000 },
|
||||
{ modelId: 'gpt-oss:120b', contextLength: 128000 },
|
||||
],
|
||||
lmstudio: [
|
||||
{ modelId: 'openai/gpt-oss-20b', contextLength: 128000 },
|
||||
{ modelId: 'openai/gpt-oss-120b', contextLength: 128000 },
|
||||
{ modelId: 'qwen/qwen3-vl-8b', contextLength: 131072 },
|
||||
],
|
||||
bedrock: [],
|
||||
const CUSTOM_PROVIDER_MODELS: Partial<Record<ProviderType, ModelInfo[]>> = {
|
||||
browseros: [{ modelId: 'browseros-auto', contextLength: 200000 }],
|
||||
'openai-compatible': [],
|
||||
ollama: [],
|
||||
'chatgpt-pro': [
|
||||
{ modelId: 'gpt-5.4', contextLength: 400000 },
|
||||
{ modelId: 'gpt-5.3-codex', contextLength: 400000 },
|
||||
@@ -103,32 +26,6 @@ export const MODELS_DATA: ModelsData = {
|
||||
{ modelId: 'gpt-5.1-codex-mini', contextLength: 400000 },
|
||||
{ modelId: 'gpt-5.1', contextLength: 200000 },
|
||||
],
|
||||
'github-copilot': [
|
||||
// Free tier (unlimited with Pro)
|
||||
{ modelId: 'gpt-5-mini', contextLength: 128000 },
|
||||
{ modelId: 'claude-haiku-4.5', contextLength: 128000 },
|
||||
{ modelId: 'gpt-4o', contextLength: 64000 },
|
||||
{ modelId: 'gpt-4.1', contextLength: 64000 },
|
||||
// Premium models (Pro: 300/mo, Pro+: 1500/mo)
|
||||
{ modelId: 'claude-sonnet-4.6', contextLength: 128000 },
|
||||
{ modelId: 'claude-sonnet-4.5', contextLength: 128000 },
|
||||
{ modelId: 'claude-sonnet-4', contextLength: 128000 },
|
||||
{ modelId: 'claude-opus-4.6', contextLength: 128000 },
|
||||
{ modelId: 'claude-opus-4.5', contextLength: 128000 },
|
||||
{ modelId: 'gemini-2.5-pro', contextLength: 128000 },
|
||||
{ modelId: 'gemini-3-pro-preview', contextLength: 128000 },
|
||||
{ modelId: 'gemini-3-flash-preview', contextLength: 128000 },
|
||||
{ modelId: 'gemini-3.1-pro-preview', contextLength: 128000 },
|
||||
{ modelId: 'gpt-5.4', contextLength: 272000 },
|
||||
{ modelId: 'gpt-5.4-mini', contextLength: 128000 },
|
||||
{ modelId: 'gpt-5.3-codex', contextLength: 272000 },
|
||||
{ modelId: 'gpt-5.2-codex', contextLength: 272000 },
|
||||
{ modelId: 'gpt-5.2', contextLength: 128000 },
|
||||
{ modelId: 'gpt-5.1-codex', contextLength: 128000 },
|
||||
{ modelId: 'gpt-5.1-codex-max', contextLength: 128000 },
|
||||
{ modelId: 'gpt-5.1', contextLength: 128000 },
|
||||
{ modelId: 'grok-code-fast-1', contextLength: 128000 },
|
||||
],
|
||||
'qwen-code': [
|
||||
{ modelId: 'coder-model', contextLength: 1000000 },
|
||||
{ modelId: 'qwen3-coder-plus', contextLength: 1000000 },
|
||||
@@ -137,25 +34,23 @@ export const MODELS_DATA: ModelsData = {
|
||||
],
|
||||
}
|
||||
|
||||
/**
|
||||
* Get models for a specific provider type
|
||||
*/
|
||||
function fromModelsDevModel(m: ModelsDevModel): ModelInfo {
|
||||
return {
|
||||
modelId: m.id,
|
||||
contextLength: m.contextWindow,
|
||||
supportsImages: m.supportsImages,
|
||||
supportsReasoning: m.supportsReasoning,
|
||||
supportsToolCall: m.supportsToolCall,
|
||||
}
|
||||
}
|
||||
|
||||
export function getModelsForProvider(providerType: ProviderType): ModelInfo[] {
|
||||
return MODELS_DATA[providerType] || []
|
||||
const custom = CUSTOM_PROVIDER_MODELS[providerType]
|
||||
if (custom !== undefined) return custom
|
||||
|
||||
return getModelsDevModels(providerType).map(fromModelsDevModel)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get model options for select dropdown (model IDs + custom option)
|
||||
*/
|
||||
export function getModelOptions(providerType: ProviderType): string[] {
|
||||
const models = getModelsForProvider(providerType)
|
||||
const modelIds = models.map((m) => m.modelId)
|
||||
return modelIds.length > 0 ? [...modelIds, 'custom'] : ['custom']
|
||||
}
|
||||
|
||||
/**
|
||||
* Get context length for a specific model
|
||||
*/
|
||||
export function getModelContextLength(
|
||||
providerType: ProviderType,
|
||||
modelId: string,
|
||||
@@ -164,14 +59,3 @@ export function getModelContextLength(
|
||||
const model = models.find((m) => m.modelId === modelId)
|
||||
return model?.contextLength
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if model ID is a custom (user-entered) value
|
||||
*/
|
||||
export function isCustomModel(
|
||||
providerType: ProviderType,
|
||||
modelId: string,
|
||||
): boolean {
|
||||
const models = getModelsForProvider(providerType)
|
||||
return !models.some((m) => m.modelId === modelId)
|
||||
}
|
||||
|
||||
@@ -169,8 +169,15 @@ export const NewTabChat: FC = () => {
|
||||
onDismissJtbdPopup={() => {}}
|
||||
/>
|
||||
)}
|
||||
{agentUrlError && <ChatError error={agentUrlError} />}
|
||||
{chatError && <ChatError error={chatError} />}
|
||||
{agentUrlError && (
|
||||
<ChatError
|
||||
error={agentUrlError}
|
||||
providerType={selectedProvider?.type}
|
||||
/>
|
||||
)}
|
||||
{chatError && (
|
||||
<ChatError error={chatError} providerType={selectedProvider?.type} />
|
||||
)}
|
||||
</main>
|
||||
|
||||
<div className="mx-auto w-full max-w-3xl flex-shrink-0 px-4 pb-2">
|
||||
|
||||
@@ -224,7 +224,12 @@ export const Chat = () => {
|
||||
onDismissJtbdPopup={onDismissJtbdPopup}
|
||||
/>
|
||||
)}
|
||||
{agentUrlError && <ChatError error={agentUrlError} />}
|
||||
{agentUrlError && (
|
||||
<ChatError
|
||||
error={agentUrlError}
|
||||
providerType={selectedProvider?.type}
|
||||
/>
|
||||
)}
|
||||
{chatError && (
|
||||
<ChatError error={chatError} providerType={selectedProvider?.type} />
|
||||
)}
|
||||
|
||||
@@ -34,11 +34,9 @@ function parseErrorMessage(
|
||||
} {
|
||||
const isBrowserosProvider = providerType === 'browseros'
|
||||
|
||||
// Detect MCP server connection failures (universal — affects all providers)
|
||||
if (
|
||||
(message.includes('Failed to fetch') || message.includes('fetch failed')) &&
|
||||
message.includes('127.0.0.1')
|
||||
) {
|
||||
// All chat requests go through the local BrowserOS agent server, so any
|
||||
// fetch failure is always a local connection issue.
|
||||
if (message.includes('Failed to fetch') || message.includes('fetch failed')) {
|
||||
return {
|
||||
text: 'Unable to connect to BrowserOS agent. Follow below instructions.',
|
||||
url: 'https://docs.browseros.com/troubleshooting/connection-issues',
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,35 @@
|
||||
import data from './models-dev-data.json'
|
||||
|
||||
export interface ModelsDevModel {
|
||||
id: string
|
||||
name: string
|
||||
contextWindow: number
|
||||
maxOutput: number
|
||||
supportsImages: boolean
|
||||
supportsReasoning: boolean
|
||||
supportsToolCall: boolean
|
||||
inputCost?: number
|
||||
outputCost?: number
|
||||
}
|
||||
|
||||
export interface ModelsDevProvider {
|
||||
name: string
|
||||
api?: string
|
||||
doc: string
|
||||
models: ModelsDevModel[]
|
||||
}
|
||||
|
||||
const modelsDevData: Record<string, ModelsDevProvider> = data as Record<
|
||||
string,
|
||||
ModelsDevProvider
|
||||
>
|
||||
|
||||
export function getModelsDevProvider(
|
||||
providerId: string,
|
||||
): ModelsDevProvider | undefined {
|
||||
return modelsDevData[providerId]
|
||||
}
|
||||
|
||||
export function getModelsDevModels(providerId: string): ModelsDevModel[] {
|
||||
return modelsDevData[providerId]?.models ?? []
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getModelsDevProvider } from './models-dev'
|
||||
import type { ProviderType } from './types'
|
||||
|
||||
/**
|
||||
@@ -15,6 +16,30 @@ export interface ProviderTemplate {
|
||||
apiKeyUrl?: string
|
||||
}
|
||||
|
||||
function enrichTemplate(
|
||||
providerId: ProviderType,
|
||||
overrides: {
|
||||
defaultModelId: string
|
||||
defaultBaseUrl?: string
|
||||
apiKeyUrl?: string
|
||||
setupGuideUrl?: string
|
||||
},
|
||||
): ProviderTemplate {
|
||||
const provider = getModelsDevProvider(providerId)
|
||||
const model = provider?.models.find((m) => m.id === overrides.defaultModelId)
|
||||
|
||||
return {
|
||||
id: providerId,
|
||||
name: provider?.name ?? providerId,
|
||||
defaultBaseUrl: overrides.defaultBaseUrl ?? provider?.api ?? '',
|
||||
defaultModelId: overrides.defaultModelId,
|
||||
supportsImages: model?.supportsImages ?? true,
|
||||
contextWindow: model?.contextWindow ?? 128000,
|
||||
...(overrides.apiKeyUrl && { apiKeyUrl: overrides.apiKeyUrl }),
|
||||
...(overrides.setupGuideUrl && { setupGuideUrl: overrides.setupGuideUrl }),
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Available provider templates for quick setup
|
||||
* @public
|
||||
@@ -57,17 +82,12 @@ export const providerTemplates: ProviderTemplate[] = [
|
||||
apiKeyUrl: 'https://platform.moonshot.ai/console/api-keys',
|
||||
setupGuideUrl: 'https://platform.moonshot.ai/console/api-keys',
|
||||
},
|
||||
{
|
||||
id: 'openai',
|
||||
name: 'OpenAI',
|
||||
defaultBaseUrl: 'https://api.openai.com/v1',
|
||||
defaultModelId: 'gpt-4',
|
||||
supportsImages: true,
|
||||
contextWindow: 128000,
|
||||
enrichTemplate('openai', {
|
||||
defaultModelId: 'gpt-5',
|
||||
apiKeyUrl: 'https://platform.openai.com/api-keys',
|
||||
setupGuideUrl:
|
||||
'https://docs.browseros.com/features/bring-your-own-llm#openai',
|
||||
},
|
||||
}),
|
||||
{
|
||||
id: 'openai-compatible',
|
||||
name: 'OpenAI Compatible',
|
||||
@@ -76,28 +96,18 @@ export const providerTemplates: ProviderTemplate[] = [
|
||||
supportsImages: true,
|
||||
contextWindow: 128000,
|
||||
},
|
||||
{
|
||||
id: 'anthropic',
|
||||
name: 'Anthropic',
|
||||
defaultBaseUrl: 'https://api.anthropic.com/v1',
|
||||
defaultModelId: 'claude-3-5-sonnet-20241022',
|
||||
supportsImages: true,
|
||||
contextWindow: 200000,
|
||||
enrichTemplate('anthropic', {
|
||||
defaultModelId: 'claude-sonnet-4-6',
|
||||
apiKeyUrl: 'https://console.anthropic.com/settings/keys',
|
||||
setupGuideUrl:
|
||||
'https://docs.browseros.com/features/bring-your-own-llm#claude',
|
||||
},
|
||||
{
|
||||
id: 'google',
|
||||
name: 'Gemini',
|
||||
defaultBaseUrl: 'https://generativelanguage.googleapis.com/v1beta',
|
||||
defaultModelId: 'gemini-1.5-pro',
|
||||
supportsImages: true,
|
||||
contextWindow: 1000000,
|
||||
}),
|
||||
enrichTemplate('google', {
|
||||
defaultModelId: 'gemini-2.5-flash',
|
||||
apiKeyUrl: 'https://aistudio.google.com/app/apikey',
|
||||
setupGuideUrl:
|
||||
'https://docs.browseros.com/features/bring-your-own-llm#gemini',
|
||||
},
|
||||
}),
|
||||
{
|
||||
id: 'ollama',
|
||||
name: 'Ollama',
|
||||
@@ -108,47 +118,28 @@ export const providerTemplates: ProviderTemplate[] = [
|
||||
setupGuideUrl:
|
||||
'https://docs.browseros.com/features/bring-your-own-llm#ollama',
|
||||
},
|
||||
{
|
||||
id: 'openrouter',
|
||||
name: 'OpenRouter',
|
||||
defaultBaseUrl: 'https://openrouter.ai/api/v1',
|
||||
defaultModelId: 'openai/gpt-4-turbo',
|
||||
supportsImages: true,
|
||||
contextWindow: 128000,
|
||||
enrichTemplate('openrouter', {
|
||||
defaultModelId: 'anthropic/claude-sonnet-4.5',
|
||||
apiKeyUrl: 'https://openrouter.ai/keys',
|
||||
setupGuideUrl:
|
||||
'https://docs.browseros.com/features/bring-your-own-llm#openrouter',
|
||||
},
|
||||
{
|
||||
id: 'lmstudio',
|
||||
name: 'LM Studio',
|
||||
}),
|
||||
enrichTemplate('lmstudio', {
|
||||
defaultModelId: 'openai/gpt-oss-20b',
|
||||
defaultBaseUrl: 'http://localhost:1234/v1',
|
||||
defaultModelId: 'local-model',
|
||||
supportsImages: false,
|
||||
contextWindow: 32000,
|
||||
setupGuideUrl:
|
||||
'https://docs.browseros.com/features/bring-your-own-llm#lmstudio',
|
||||
},
|
||||
{
|
||||
id: 'azure',
|
||||
name: 'Azure',
|
||||
defaultBaseUrl: '',
|
||||
}),
|
||||
enrichTemplate('azure', {
|
||||
defaultModelId: '',
|
||||
supportsImages: true,
|
||||
contextWindow: 128000,
|
||||
apiKeyUrl:
|
||||
'https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI',
|
||||
},
|
||||
{
|
||||
id: 'bedrock',
|
||||
name: 'AWS Bedrock',
|
||||
defaultBaseUrl: '',
|
||||
defaultModelId: '',
|
||||
supportsImages: true,
|
||||
contextWindow: 200000,
|
||||
}),
|
||||
enrichTemplate('bedrock', {
|
||||
defaultModelId: 'anthropic.claude-sonnet-4-6',
|
||||
setupGuideUrl:
|
||||
'https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html',
|
||||
},
|
||||
}),
|
||||
]
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Production upload env for CLI installer scripts
|
||||
|
||||
R2_ACCOUNT_ID=
|
||||
R2_ACCESS_KEY_ID=
|
||||
R2_SECRET_ACCESS_KEY=
|
||||
R2_BUCKET=browseros
|
||||
R2_UPLOAD_PREFIX=cli
|
||||
1
packages/browseros-agent/apps/cli/.gitignore
vendored
1
packages/browseros-agent/apps/cli/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
browseros-cli
|
||||
dist
|
||||
|
||||
50
packages/browseros-agent/apps/cli/.goreleaser.yml
Normal file
50
packages/browseros-agent/apps/cli/.goreleaser.yml
Normal file
@@ -0,0 +1,50 @@
|
||||
version: 2
|
||||
|
||||
project_name: browseros-cli
|
||||
|
||||
monorepo:
|
||||
tag_prefix: browseros-cli-
|
||||
|
||||
builds:
|
||||
- main: .
|
||||
binary: browseros-cli
|
||||
env:
|
||||
- CGO_ENABLED=0
|
||||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- -s -w -X main.version={{ .Version }}
|
||||
targets:
|
||||
- darwin_amd64
|
||||
- darwin_arm64
|
||||
- linux_amd64
|
||||
- linux_arm64
|
||||
- windows_amd64
|
||||
- windows_arm64
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
|
||||
files:
|
||||
- "none*"
|
||||
|
||||
checksum:
|
||||
name_template: checksums.txt
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
- "^ci:"
|
||||
|
||||
release:
|
||||
github:
|
||||
owner: browseros-ai
|
||||
name: BrowserOS
|
||||
prerelease: auto
|
||||
name_template: "browseros-cli v{{ .Version }}"
|
||||
1
packages/browseros-agent/apps/cli/CHANGELOG.md
Normal file
1
packages/browseros-agent/apps/cli/CHANGELOG.md
Normal file
@@ -0,0 +1 @@
|
||||
# BrowserOS CLI
|
||||
@@ -18,3 +18,9 @@ vet:
|
||||
|
||||
test:
|
||||
go test -tags integration -v -timeout 120s ./...
|
||||
|
||||
release-dry:
|
||||
goreleaser release --snapshot --clean
|
||||
|
||||
release:
|
||||
goreleaser release --clean
|
||||
|
||||
@@ -17,8 +17,10 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
var autoDiscover bool
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Use: "init [url]",
|
||||
Short: "Configure the BrowserOS server connection",
|
||||
Long: `Set up the CLI by providing the MCP server URL from BrowserOS.
|
||||
|
||||
@@ -26,33 +28,59 @@ Open BrowserOS → Settings → BrowserOS MCP to find your Server URL.
|
||||
The URL looks like: http://127.0.0.1:9004/mcp
|
||||
|
||||
The port varies per installation, so this step is required on first use.
|
||||
Run again if your port changes.`,
|
||||
Run again if your port changes.
|
||||
|
||||
Three modes:
|
||||
browseros-cli init <url> Non-interactive, use the provided URL
|
||||
browseros-cli init --auto Auto-discover from ~/.browseros/server.json
|
||||
browseros-cli init Interactive prompt`,
|
||||
Annotations: map[string]string{"group": "Setup:"},
|
||||
Args: cobra.NoArgs,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
bold := color.New(color.Bold)
|
||||
green := color.New(color.FgGreen)
|
||||
dim := color.New(color.Faint)
|
||||
|
||||
fmt.Println()
|
||||
bold.Println("BrowserOS CLI Setup")
|
||||
fmt.Println()
|
||||
fmt.Println("Open BrowserOS → Settings → BrowserOS MCP")
|
||||
fmt.Println("Copy the Server URL shown there.")
|
||||
fmt.Println()
|
||||
dim.Println("It looks like: http://127.0.0.1:9004/mcp")
|
||||
fmt.Println()
|
||||
var input string
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Print("Server URL: ")
|
||||
input, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
output.Error("failed to read input", 1)
|
||||
}
|
||||
input = strings.TrimSpace(input)
|
||||
switch {
|
||||
case len(args) == 1:
|
||||
// Non-interactive: URL provided as argument
|
||||
input = args[0]
|
||||
|
||||
if input == "" {
|
||||
output.Error("no URL provided", 1)
|
||||
case autoDiscover:
|
||||
// Auto-discover: server.json → config → probe common ports
|
||||
discovered := probeRunningServer()
|
||||
if discovered == "" {
|
||||
output.Error("auto-discovery failed: no running BrowserOS found.\n\n"+
|
||||
" If not running: browseros-cli launch\n"+
|
||||
" If not installed: browseros-cli install", 1)
|
||||
}
|
||||
input = discovered
|
||||
fmt.Printf("Auto-discovered server at %s\n", input)
|
||||
|
||||
default:
|
||||
// Interactive prompt (original behavior)
|
||||
fmt.Println()
|
||||
bold.Println("BrowserOS CLI Setup")
|
||||
fmt.Println()
|
||||
fmt.Println("Open BrowserOS → Settings → BrowserOS MCP")
|
||||
fmt.Println("Copy the Server URL shown there.")
|
||||
fmt.Println()
|
||||
dim.Println("It looks like: http://127.0.0.1:9004/mcp")
|
||||
fmt.Println()
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
fmt.Print("Server URL: ")
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
output.Error("failed to read input", 1)
|
||||
}
|
||||
input = strings.TrimSpace(line)
|
||||
|
||||
if input == "" {
|
||||
output.Error("no URL provided", 1)
|
||||
}
|
||||
}
|
||||
|
||||
baseURL := normalizeServerURL(input)
|
||||
@@ -88,5 +116,6 @@ Run again if your port changes.`,
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().BoolVar(&autoDiscover, "auto", false, "Auto-discover server URL from ~/.browseros/server.json")
|
||||
rootCmd.AddCommand(cmd)
|
||||
}
|
||||
|
||||
247
packages/browseros-agent/apps/cli/cmd/install.go
Normal file
247
packages/browseros-agent/apps/cli/cmd/install.go
Normal file
@@ -0,0 +1,247 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"browseros-cli/output"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
cmd := &cobra.Command{
|
||||
Use: "install",
|
||||
Short: "Download and install BrowserOS for the current platform",
|
||||
Long: `Download BrowserOS for your platform and start the installation.
|
||||
|
||||
macOS: Downloads .dmg, mounts it, and copies BrowserOS to /Applications
|
||||
Windows: Downloads installer .exe and launches it
|
||||
Linux: Downloads AppImage (or .deb with --deb flag)
|
||||
|
||||
After installation:
|
||||
browseros-cli launch # start BrowserOS
|
||||
browseros-cli init --auto # configure the CLI`,
|
||||
Annotations: map[string]string{"group": "Setup:"},
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dir, _ := cmd.Flags().GetString("dir")
|
||||
deb, _ := cmd.Flags().GetBool("deb")
|
||||
|
||||
if deb && runtime.GOOS != "linux" {
|
||||
output.Error("--deb is only available on Linux", 1)
|
||||
}
|
||||
|
||||
downloadURL, filename := resolveDownload(deb)
|
||||
destPath := filepath.Join(dir, filename)
|
||||
|
||||
bold := color.New(color.Bold)
|
||||
green := color.New(color.FgGreen)
|
||||
dim := color.New(color.Faint)
|
||||
|
||||
bold.Printf("Downloading BrowserOS for %s...\n", platformDisplayName())
|
||||
dim.Printf(" %s\n", downloadURL)
|
||||
fmt.Println()
|
||||
|
||||
client := &http.Client{Timeout: 10 * time.Minute}
|
||||
resp, err := client.Get(downloadURL)
|
||||
if err != nil {
|
||||
output.Errorf(1, "download failed: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
output.Errorf(1, "download failed: HTTP %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
file, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
output.Errorf(1, "create file: %v", err)
|
||||
}
|
||||
|
||||
written, err := io.Copy(file, resp.Body)
|
||||
file.Close()
|
||||
if err != nil {
|
||||
os.Remove(destPath)
|
||||
output.Errorf(1, "download interrupted: %v", err)
|
||||
}
|
||||
|
||||
green.Printf("Downloaded %s (%.1f MB)\n", filename, float64(written)/(1024*1024))
|
||||
fmt.Println()
|
||||
|
||||
runPostInstall(destPath, deb, dim)
|
||||
|
||||
fmt.Println()
|
||||
bold.Println("Next steps:")
|
||||
dim.Println(" browseros-cli launch # start BrowserOS")
|
||||
dim.Println(" browseros-cli init --auto # configure the CLI")
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().String("dir", ".", "Directory to download the installer to")
|
||||
cmd.Flags().Bool("deb", false, "Download .deb package instead of AppImage (Linux only)")
|
||||
|
||||
rootCmd.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func resolveDownload(deb bool) (url, filename string) {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return "https://files.browseros.com/download/BrowserOS.dmg", "BrowserOS.dmg"
|
||||
case "windows":
|
||||
return "https://files.browseros.com/download/BrowserOS_installer.exe", "BrowserOS_installer.exe"
|
||||
case "linux":
|
||||
if deb {
|
||||
return "https://cdn.browseros.com/download/BrowserOS.deb", "BrowserOS.deb"
|
||||
}
|
||||
return "https://files.browseros.com/download/BrowserOS.AppImage", "BrowserOS.AppImage"
|
||||
default:
|
||||
output.Errorf(1, "unsupported platform: %s/%s\n Download manually from https://browseros.com", runtime.GOOS, runtime.GOARCH)
|
||||
return "", ""
|
||||
}
|
||||
}
|
||||
|
||||
func platformDisplayName() string {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
return "macOS"
|
||||
case "windows":
|
||||
return "Windows"
|
||||
case "linux":
|
||||
return "Linux"
|
||||
default:
|
||||
return runtime.GOOS
|
||||
}
|
||||
}
|
||||
|
||||
func runPostInstall(path string, deb bool, dim *color.Color) {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
installMacOS(path, dim)
|
||||
|
||||
case "linux":
|
||||
if deb {
|
||||
dim.Println("Install the .deb package:")
|
||||
fmt.Printf(" sudo dpkg -i %s\n", path)
|
||||
} else {
|
||||
os.Chmod(path, 0755)
|
||||
dim.Printf("AppImage is ready to run: ./%s\n", filepath.Base(path))
|
||||
}
|
||||
|
||||
case "windows":
|
||||
fmt.Println("Launching installer...")
|
||||
if err := exec.Command("cmd", "/c", "start", "", path).Run(); err != nil {
|
||||
dim.Printf("Could not launch installer automatically. Run: %s\n", path)
|
||||
} else {
|
||||
dim.Println("Follow the installer prompts to complete setup.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// installMacOS mounts the DMG and copies BrowserOS.app to /Applications.
|
||||
func installMacOS(dmgPath string, dim *color.Color) {
|
||||
fmt.Println("Mounting disk image...")
|
||||
mountOut, err := exec.Command("hdiutil", "attach", dmgPath, "-nobrowse", "-quiet").Output()
|
||||
if err != nil {
|
||||
dim.Println("Could not mount DMG automatically.")
|
||||
dim.Printf(" Open it manually: open %s\n", dmgPath)
|
||||
return
|
||||
}
|
||||
|
||||
// Find the mount point (last field of last line of hdiutil output)
|
||||
mountPoint := ""
|
||||
for _, line := range splitLines(string(mountOut)) {
|
||||
fields := splitTabs(line)
|
||||
if len(fields) > 0 {
|
||||
mountPoint = fields[len(fields)-1]
|
||||
}
|
||||
}
|
||||
|
||||
if mountPoint == "" {
|
||||
dim.Println("DMG mounted but could not determine mount point.")
|
||||
dim.Printf(" Open it manually: open %s\n", dmgPath)
|
||||
return
|
||||
}
|
||||
|
||||
// Look for BrowserOS.app in the mounted volume
|
||||
appSrc := filepath.Join(mountPoint, "BrowserOS.app")
|
||||
if _, err := os.Stat(appSrc); err != nil {
|
||||
dim.Printf("DMG mounted at %s but BrowserOS.app not found inside.\n", mountPoint)
|
||||
dim.Printf(" Check the volume manually: open %s\n", mountPoint)
|
||||
exec.Command("hdiutil", "detach", mountPoint, "-quiet").Run()
|
||||
return
|
||||
}
|
||||
|
||||
appDest := "/Applications/BrowserOS.app"
|
||||
fmt.Printf("Installing to %s...\n", appDest)
|
||||
|
||||
// Remove existing installation if present
|
||||
os.RemoveAll(appDest)
|
||||
|
||||
// Copy using cp -R (preserves code signatures, symlinks, etc.)
|
||||
if err := exec.Command("cp", "-R", appSrc, appDest).Run(); err != nil {
|
||||
dim.Printf("Could not copy to /Applications (may need sudo).\n")
|
||||
dim.Printf(" Try: sudo cp -R \"%s\" /Applications/\n", appSrc)
|
||||
exec.Command("hdiutil", "detach", mountPoint, "-quiet").Run()
|
||||
return
|
||||
}
|
||||
|
||||
// Unmount
|
||||
exec.Command("hdiutil", "detach", mountPoint, "-quiet").Run()
|
||||
|
||||
// Clean up DMG
|
||||
os.Remove(dmgPath)
|
||||
|
||||
fmt.Println("BrowserOS installed to /Applications/BrowserOS.app")
|
||||
}
|
||||
|
||||
func splitLines(s string) []string {
|
||||
var lines []string
|
||||
for _, line := range filepath.SplitList(s) {
|
||||
lines = append(lines, line)
|
||||
}
|
||||
// filepath.SplitList uses : on unix, not newlines — use manual split
|
||||
result := []string{}
|
||||
start := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == '\n' {
|
||||
line := s[start:i]
|
||||
if len(line) > 0 {
|
||||
result = append(result, line)
|
||||
}
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
if start < len(s) {
|
||||
result = append(result, s[start:])
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func splitTabs(s string) []string {
|
||||
result := []string{}
|
||||
start := 0
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == '\t' {
|
||||
field := s[start:i]
|
||||
if len(field) > 0 {
|
||||
result = append(result, field)
|
||||
}
|
||||
start = i + 1
|
||||
}
|
||||
}
|
||||
if start < len(s) {
|
||||
field := s[start:]
|
||||
if len(field) > 0 {
|
||||
result = append(result, field)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
287
packages/browseros-agent/apps/cli/cmd/launch.go
Normal file
287
packages/browseros-agent/apps/cli/cmd/launch.go
Normal file
@@ -0,0 +1,287 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"browseros-cli/output"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// macOS bundle identifier — verified from BrowserOS.app/Contents/Info.plist
|
||||
const browserOSBundleID = "com.browseros.BrowserOS"
|
||||
|
||||
func init() {
|
||||
cmd := &cobra.Command{
|
||||
Use: "launch",
|
||||
Short: "Launch the BrowserOS application",
|
||||
Long: `Find and launch the BrowserOS application.
|
||||
|
||||
Uses platform-native detection to find BrowserOS, launches it,
|
||||
and waits for the server to become ready.
|
||||
|
||||
If BrowserOS is already running, reports the server URL.`,
|
||||
Annotations: map[string]string{"group": "Setup:"},
|
||||
Args: cobra.NoArgs,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
green := color.New(color.FgGreen)
|
||||
dim := color.New(color.Faint)
|
||||
waitSecs, _ := cmd.Flags().GetInt("wait")
|
||||
|
||||
if url := probeRunningServer(); url != "" {
|
||||
green.Printf("BrowserOS is already running at %s\n", url)
|
||||
return
|
||||
}
|
||||
|
||||
if !isBrowserOSInstalled() {
|
||||
output.Error("BrowserOS is not installed.\n\n"+
|
||||
" To install: browseros-cli install", 1)
|
||||
}
|
||||
|
||||
fmt.Println("Launching BrowserOS...")
|
||||
if err := startBrowserOS(); err != nil {
|
||||
output.Errorf(1, "failed to launch: %v", err)
|
||||
}
|
||||
|
||||
fmt.Print("Waiting for server")
|
||||
url, ok := waitForServer(time.Duration(waitSecs) * time.Second)
|
||||
fmt.Println()
|
||||
|
||||
if !ok {
|
||||
output.Error("BrowserOS launched but server didn't respond within "+
|
||||
fmt.Sprintf("%d seconds.\n", waitSecs)+
|
||||
" Check if BrowserOS is fully loaded, then retry.", 1)
|
||||
}
|
||||
|
||||
green.Printf("BrowserOS is ready at %s\n", url)
|
||||
fmt.Println()
|
||||
dim.Println("Next: browseros-cli init --auto")
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().Int("wait", 30, "Seconds to wait for server to start")
|
||||
rootCmd.AddCommand(cmd)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Server probing
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// probeRunningServer checks server.json, config, and common ports for a running server.
|
||||
func probeRunningServer() string {
|
||||
check := func(baseURL string) bool {
|
||||
client := &http.Client{Timeout: 2 * time.Second}
|
||||
resp, err := client.Get(baseURL + "/health")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
resp.Body.Close()
|
||||
return resp.StatusCode == 200
|
||||
}
|
||||
|
||||
// 1. server.json — written by BrowserOS on startup with the actual port
|
||||
if url := loadBrowserosServerURL(); url != "" && check(url) {
|
||||
return url
|
||||
}
|
||||
|
||||
// 2. Saved config / env var
|
||||
if url := defaultServerURL(); url != "" && check(url) {
|
||||
return url
|
||||
}
|
||||
|
||||
// 3. Probe common BrowserOS ports as last resort
|
||||
for _, port := range []int{9100, 9200, 9300} {
|
||||
url := fmt.Sprintf("http://127.0.0.1:%d", port)
|
||||
if check(url) {
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Platform-native installation detection
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// isBrowserOSInstalled checks if BrowserOS is installed using platform-native methods.
|
||||
//
|
||||
// macOS: `open -Ra "BrowserOS"` — queries Launch Services (finds apps anywhere)
|
||||
// Linux: checks /usr/bin/browseros (.deb), browseros.desktop, or AppImage files
|
||||
// Windows: checks executable at %LOCALAPPDATA%\BrowserOS\Application\BrowserOS.exe
|
||||
// and registry uninstall key (per-user Chromium install pattern)
|
||||
func isBrowserOSInstalled() bool {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
// open -Ra checks if Launch Services knows about the app without launching it.
|
||||
// Works regardless of where the app is installed.
|
||||
return exec.Command("open", "-Ra", "BrowserOS").Run() == nil
|
||||
|
||||
case "linux":
|
||||
// .deb install puts `browseros` in /usr/bin/
|
||||
if _, err := exec.LookPath("browseros"); err == nil {
|
||||
return true
|
||||
}
|
||||
// .deb also creates browseros.desktop
|
||||
for _, dir := range []string{
|
||||
"/usr/share/applications",
|
||||
filepath.Join(userHomeDir(), ".local/share/applications"),
|
||||
} {
|
||||
if _, err := os.Stat(filepath.Join(dir, "browseros.desktop")); err == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// AppImage — user may have it in ~/Downloads, ~/Applications, etc.
|
||||
return findLinuxAppImage() != ""
|
||||
|
||||
case "windows":
|
||||
// Chromium per-user install: %LOCALAPPDATA%\BrowserOS\Application\BrowserOS.exe
|
||||
if exePath := windowsBrowserOSExe(); exePath != "" {
|
||||
if _, err := os.Stat(exePath); err == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// Fallback: check uninstall registry (per-user install uses HKCU)
|
||||
for _, root := range []string{"HKCU", "HKLM"} {
|
||||
key := root + `\Software\Microsoft\Windows\CurrentVersion\Uninstall\BrowserOS`
|
||||
if exec.Command("reg", "query", key, "/v", "DisplayName").Run() == nil {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Platform-native launch
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// startBrowserOS launches BrowserOS using platform-native methods.
|
||||
//
|
||||
// macOS: `open -b com.browseros.BrowserOS` — launches by bundle ID
|
||||
// Linux: runs `browseros` binary or AppImage directly
|
||||
// Windows: runs BrowserOS.exe from the known install path
|
||||
func startBrowserOS() error {
|
||||
switch runtime.GOOS {
|
||||
case "darwin":
|
||||
// Launch by bundle ID via Launch Services — no hardcoded paths needed.
|
||||
return exec.Command("open", "-b", browserOSBundleID).Run()
|
||||
|
||||
case "linux":
|
||||
// .deb install: browseros is in PATH
|
||||
if p, err := exec.LookPath("browseros"); err == nil {
|
||||
return startDetached(p)
|
||||
}
|
||||
// AppImage: run it directly
|
||||
if appImage := findLinuxAppImage(); appImage != "" {
|
||||
return startDetached(appImage)
|
||||
}
|
||||
// .desktop file: use gtk-launch (not xdg-open, which opens by MIME type)
|
||||
if _, err := exec.LookPath("gtk-launch"); err == nil {
|
||||
return exec.Command("gtk-launch", "browseros").Run()
|
||||
}
|
||||
return fmt.Errorf("BrowserOS found but could not determine how to launch it")
|
||||
|
||||
case "windows":
|
||||
if exePath := windowsBrowserOSExe(); exePath != "" {
|
||||
if _, err := os.Stat(exePath); err == nil {
|
||||
return startDetached(exePath)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("BrowserOS.exe not found at expected location")
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unsupported platform: %s", runtime.GOOS)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Helpers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// startDetached starts a process in the background without inheriting stdio.
|
||||
func startDetached(path string, args ...string) error {
|
||||
cmd := exec.Command(path, args...)
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
cmd.Stdin = nil
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
// windowsBrowserOSExe returns the expected BrowserOS.exe path on Windows.
|
||||
// Chromium per-user installs go to %LOCALAPPDATA%\<base_app_name>\Application\<binary>.
|
||||
// base_app_name = "BrowserOS" (from chromium_install_modes.h)
|
||||
func windowsBrowserOSExe() string {
|
||||
localAppData := os.Getenv("LOCALAPPDATA")
|
||||
if localAppData == "" {
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(localAppData, "BrowserOS", "Application", "BrowserOS.exe")
|
||||
}
|
||||
|
||||
// findLinuxAppImage searches common locations for a BrowserOS AppImage.
|
||||
func findLinuxAppImage() string {
|
||||
home := userHomeDir()
|
||||
if home == "" {
|
||||
return ""
|
||||
}
|
||||
for _, dir := range []string{
|
||||
home,
|
||||
filepath.Join(home, "Applications"),
|
||||
filepath.Join(home, "Downloads"),
|
||||
"/opt",
|
||||
} {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, e := range entries {
|
||||
name := e.Name()
|
||||
if strings.HasPrefix(name, "BrowserOS") && strings.HasSuffix(name, ".AppImage") {
|
||||
return filepath.Join(dir, name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// userHomeDir returns the home directory or empty string.
|
||||
func userHomeDir() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return home
|
||||
}
|
||||
|
||||
// waitForServer polls until a BrowserOS server responds or timeout.
|
||||
func waitForServer(maxWait time.Duration) (string, bool) {
|
||||
client := &http.Client{Timeout: 2 * time.Second}
|
||||
deadline := time.Now().Add(maxWait)
|
||||
|
||||
for time.Now().Before(deadline) {
|
||||
// server.json is written by BrowserOS on startup with the actual port
|
||||
if url := loadBrowserosServerURL(); url != "" {
|
||||
resp, err := client.Get(url + "/health")
|
||||
if err == nil {
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode == 200 {
|
||||
return url, true
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Print(".")
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
@@ -167,10 +167,17 @@ func envBool(key string) bool {
|
||||
}
|
||||
|
||||
func defaultServerURL() string {
|
||||
// 1. Explicit env var always wins
|
||||
if env := normalizeServerURL(os.Getenv("BROWSEROS_URL")); env != "" {
|
||||
return env
|
||||
}
|
||||
|
||||
// 2. Live discovery file from running BrowserOS (most current)
|
||||
if url := loadBrowserosServerURL(); url != "" {
|
||||
return url
|
||||
}
|
||||
|
||||
// 3. Saved config (may be stale if port changed)
|
||||
cfg, err := config.Load()
|
||||
if err == nil {
|
||||
if url := normalizeServerURL(cfg.ServerURL); url != "" {
|
||||
@@ -178,10 +185,6 @@ func defaultServerURL() string {
|
||||
}
|
||||
}
|
||||
|
||||
if url := loadBrowserosServerURL(); url != "" {
|
||||
return url
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -225,6 +228,9 @@ func validateServerURL(raw string) (string, error) {
|
||||
}
|
||||
|
||||
return "", fmt.Errorf(
|
||||
"BrowserOS server URL is not configured.\n Open BrowserOS -> Settings -> BrowserOS MCP and copy the Server URL.\n Then run: browseros-cli init",
|
||||
"BrowserOS server URL is not configured.\n\n" +
|
||||
" If BrowserOS is running: browseros-cli init --auto\n" +
|
||||
" If BrowserOS is closed: browseros-cli launch\n" +
|
||||
" If not installed: browseros-cli install",
|
||||
)
|
||||
}
|
||||
|
||||
@@ -44,7 +44,10 @@ func (c *Client) connect(ctx context.Context) (*sdkmcp.ClientSession, error) {
|
||||
|
||||
session, err := sdkClient.Connect(ctx, transport, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot connect to BrowserOS at %s: %w\n Is the server running? Try: browseros-cli init", c.BaseURL, err)
|
||||
return nil, fmt.Errorf("cannot connect to BrowserOS at %s: %w\n\n"+
|
||||
" If BrowserOS is running on a different port: browseros-cli init --auto\n"+
|
||||
" If BrowserOS is not running: browseros-cli launch\n"+
|
||||
" If not installed: browseros-cli install", c.BaseURL, err)
|
||||
}
|
||||
return session, nil
|
||||
}
|
||||
@@ -184,7 +187,10 @@ func (c *Client) Status() (map[string]any, error) {
|
||||
func (c *Client) restGET(path string) (map[string]any, error) {
|
||||
resp, err := c.HTTPClient.Get(c.BaseURL + path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot connect to BrowserOS at %s: %w\n Try: browseros-cli init", c.BaseURL, err)
|
||||
return nil, fmt.Errorf("cannot connect to BrowserOS at %s: %w\n\n"+
|
||||
" If BrowserOS is running on a different port: browseros-cli init --auto\n"+
|
||||
" If BrowserOS is not running: browseros-cli launch\n"+
|
||||
" If not installed: browseros-cli install", c.BaseURL, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
147
packages/browseros-agent/apps/cli/scripts/install.ps1
Normal file
147
packages/browseros-agent/apps/cli/scripts/install.ps1
Normal file
@@ -0,0 +1,147 @@
|
||||
#
|
||||
# Install browseros-cli for Windows — downloads the latest release binary.
|
||||
#
|
||||
# Usage (PowerShell — save and run):
|
||||
# Invoke-WebRequest -Uri "https://cdn.browseros.com/cli/install.ps1" -OutFile install.ps1
|
||||
# .\install.ps1
|
||||
# .\install.ps1 -Version "0.1.0" -Dir "C:\tools\browseros"
|
||||
#
|
||||
# Usage (one-liner, uses env vars for options):
|
||||
# & { $env:BROWSEROS_VERSION="0.1.0"; irm https://cdn.browseros.com/cli/install.ps1 | iex }
|
||||
#
|
||||
|
||||
param(
|
||||
[string]$Version = "",
|
||||
[string]$Dir = ""
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
# TLS 1.2 — required for GitHub, older PS 5.1 defaults to TLS 1.0
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
$Repo = "browseros-ai/BrowserOS"
|
||||
$Binary = "browseros-cli"
|
||||
|
||||
# When piped via irm | iex, param() is ignored — fall back to env vars
|
||||
if (-not $Version) { $Version = $env:BROWSEROS_VERSION }
|
||||
if (-not $Dir) { $Dir = if ($env:BROWSEROS_DIR) { $env:BROWSEROS_DIR } else { "$env:LOCALAPPDATA\browseros-cli\bin" } }
|
||||
|
||||
# ── Resolve latest version ───────────────────────────────────────────────────
|
||||
|
||||
if (-not $Version) {
|
||||
Write-Host "Fetching latest version..."
|
||||
$releases = Invoke-RestMethod "https://api.github.com/repos/$Repo/releases?per_page=100"
|
||||
$tag = ($releases `
|
||||
| Where-Object { $_.tag_name -match "^browseros-cli-v" -and $_.tag_name -notmatch "-rc" } `
|
||||
| Select-Object -First 1).tag_name
|
||||
if (-not $tag) {
|
||||
Write-Error "Could not determine latest version. Try: -Version 0.1.0"
|
||||
exit 1
|
||||
}
|
||||
$Version = $tag -replace "^browseros-cli-v", ""
|
||||
}
|
||||
|
||||
Write-Host "Installing browseros-cli v$Version..."
|
||||
|
||||
# ── Detect architecture ──────────────────────────────────────────────────────
|
||||
|
||||
# $env:PROCESSOR_ARCHITECTURE lies under x64 emulation on ARM64 Windows.
|
||||
# Use .NET RuntimeInformation when available, fall back to PROCESSOR_ARCHITEW6432.
|
||||
$Arch = "amd64"
|
||||
try {
|
||||
$osArch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
|
||||
if ($osArch -eq [System.Runtime.InteropServices.Architecture]::Arm64) { $Arch = "arm64" }
|
||||
} catch {
|
||||
if ($env:PROCESSOR_ARCHITEW6432 -eq "ARM64" -or $env:PROCESSOR_ARCHITECTURE -eq "ARM64") {
|
||||
$Arch = "arm64"
|
||||
}
|
||||
}
|
||||
|
||||
if (-not [Environment]::Is64BitOperatingSystem) {
|
||||
Write-Error "32-bit Windows is not supported."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ── Download and extract ─────────────────────────────────────────────────────
|
||||
|
||||
$Tag = "browseros-cli-v$Version"
|
||||
$Filename = "${Binary}_${Version}_windows_${Arch}.zip"
|
||||
$Url = "https://github.com/$Repo/releases/download/$Tag/$Filename"
|
||||
$ChecksumUrl = "https://github.com/$Repo/releases/download/$Tag/checksums.txt"
|
||||
$TmpDir = Join-Path ([System.IO.Path]::GetTempPath()) ("browseros-cli-install-" + [System.IO.Path]::GetRandomFileName())
|
||||
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $TmpDir | Out-Null
|
||||
|
||||
$ZipPath = Join-Path $TmpDir $Filename
|
||||
|
||||
Write-Host "Downloading $Url..."
|
||||
Invoke-WebRequest -Uri $Url -OutFile $ZipPath -UseBasicParsing
|
||||
|
||||
$ChecksumPath = Join-Path $TmpDir "checksums.txt"
|
||||
$ChecksumAvailable = $true
|
||||
try {
|
||||
Invoke-WebRequest -Uri $ChecksumUrl -OutFile $ChecksumPath -UseBasicParsing
|
||||
} catch {
|
||||
$ChecksumAvailable = $false
|
||||
Write-Warning "Could not fetch checksums.txt; skipping checksum verification. $($_.Exception.Message)"
|
||||
}
|
||||
|
||||
if ($ChecksumAvailable) {
|
||||
$ExpectedChecksum = $null
|
||||
foreach ($line in Get-Content $ChecksumPath) {
|
||||
$parts = $line -split '\s+', 2
|
||||
if ($parts.Length -eq 2 -and $parts[1] -eq $Filename) {
|
||||
$ExpectedChecksum = $parts[0].ToLowerInvariant()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if ($ExpectedChecksum) {
|
||||
$ActualChecksum = (Get-FileHash -Path $ZipPath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
if ($ActualChecksum -ne $ExpectedChecksum) {
|
||||
Write-Error "Checksum mismatch (expected $ExpectedChecksum, got $ActualChecksum)"
|
||||
exit 1
|
||||
}
|
||||
Write-Host "Checksum verified."
|
||||
} else {
|
||||
Write-Warning "Checksum not found in checksums.txt; skipping checksum verification."
|
||||
}
|
||||
}
|
||||
|
||||
Expand-Archive -Path $ZipPath -DestinationPath $TmpDir -Force
|
||||
|
||||
$Exe = Get-ChildItem -Path $TmpDir -Filter "$Binary.exe" -File -Recurse | Select-Object -First 1
|
||||
if (-not $Exe) {
|
||||
Write-Error "Binary not found in archive."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# ── Install ──────────────────────────────────────────────────────────────
|
||||
|
||||
if (-not (Test-Path $Dir)) {
|
||||
New-Item -ItemType Directory -Path $Dir -Force | Out-Null
|
||||
}
|
||||
|
||||
Move-Item -Force $Exe.FullName (Join-Path $Dir "$Binary.exe")
|
||||
|
||||
Write-Host "Installed $Binary.exe to $Dir"
|
||||
} finally {
|
||||
if (Test-Path $TmpDir) { Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue }
|
||||
}
|
||||
|
||||
# ── PATH ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
|
||||
$PathEntries = $UserPath -split ";" | Where-Object { $_ -ne "" }
|
||||
if ($Dir -notin $PathEntries) {
|
||||
Write-Host ""
|
||||
Write-Host "Adding $Dir to your user PATH..."
|
||||
[Environment]::SetEnvironmentVariable("Path", "$Dir;$UserPath", "User")
|
||||
$env:Path = "$Dir;$env:Path"
|
||||
Write-Host "Done. Restart your terminal for PATH changes to take effect."
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Run 'browseros-cli --help' to get started."
|
||||
153
packages/browseros-agent/apps/cli/scripts/install.sh
Executable file
153
packages/browseros-agent/apps/cli/scripts/install.sh
Executable file
@@ -0,0 +1,153 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Install browseros-cli — downloads the latest release binary for your platform.
|
||||
#
|
||||
# Usage:
|
||||
# curl -fsSL https://cdn.browseros.com/cli/install.sh | bash
|
||||
#
|
||||
# # Or with options:
|
||||
# curl -fsSL https://cdn.browseros.com/cli/install.sh | bash -s -- --version 0.1.0 --dir /usr/local/bin
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
REPO="browseros-ai/BrowserOS"
|
||||
BINARY="browseros-cli"
|
||||
INSTALL_DIR="${HOME}/.browseros/bin"
|
||||
|
||||
# ── Parse arguments ──────────────────────────────────────────────────────────
|
||||
|
||||
VERSION=""
|
||||
CUSTOM_DIR=""
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--version)
|
||||
[[ $# -lt 2 ]] && { echo "Error: --version requires a value" >&2; exit 1; }
|
||||
VERSION="$2"; shift 2 ;;
|
||||
--dir)
|
||||
[[ $# -lt 2 ]] && { echo "Error: --dir requires a value" >&2; exit 1; }
|
||||
CUSTOM_DIR="$2"; shift 2 ;;
|
||||
--help)
|
||||
echo "Usage: install.sh [--version VERSION] [--dir INSTALL_DIR]"
|
||||
echo ""
|
||||
echo " --version Install a specific version (default: latest)"
|
||||
echo " --dir Install directory (default: ~/.browseros/bin)"
|
||||
exit 0
|
||||
;;
|
||||
*) echo "Unknown option: $1" >&2; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -n "$CUSTOM_DIR" ]] && INSTALL_DIR="$CUSTOM_DIR"
|
||||
|
||||
# ── Resolve latest version ───────────────────────────────────────────────────
|
||||
|
||||
if [[ -z "$VERSION" ]]; then
|
||||
# Use per_page=1 with a tag name filter via the releases endpoint.
|
||||
# The tags all start with "browseros-cli-v" so we grab page 1 of those.
|
||||
VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases?per_page=100" \
|
||||
| grep -o '"tag_name": *"browseros-cli-v[^"]*"' \
|
||||
| grep -v -- "-rc" \
|
||||
| head -1 \
|
||||
| sed 's/.*browseros-cli-v//; s/"//')
|
||||
|
||||
if [[ -z "$VERSION" ]]; then
|
||||
echo "Error: could not determine latest version." >&2
|
||||
echo " Try: install.sh --version 0.1.0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installing browseros-cli v${VERSION}..."
|
||||
|
||||
# ── Detect platform ──────────────────────────────────────────────────────────
|
||||
|
||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||
ARCH=$(uname -m)
|
||||
|
||||
case "$OS" in
|
||||
darwin) OS="darwin" ;;
|
||||
linux) OS="linux" ;;
|
||||
*) echo "Error: unsupported OS: $OS" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
case "$ARCH" in
|
||||
x86_64|amd64) ARCH="amd64" ;;
|
||||
arm64|aarch64) ARCH="arm64" ;;
|
||||
*) echo "Error: unsupported architecture: $ARCH" >&2; exit 1 ;;
|
||||
esac
|
||||
|
||||
# ── Download and extract ─────────────────────────────────────────────────────
|
||||
|
||||
FILENAME="${BINARY}_${VERSION}_${OS}_${ARCH}.tar.gz"
|
||||
TAG="browseros-cli-v${VERSION}"
|
||||
URL="https://github.com/${REPO}/releases/download/${TAG}/${FILENAME}"
|
||||
CHECKSUM_URL="https://github.com/${REPO}/releases/download/${TAG}/checksums.txt"
|
||||
|
||||
TMPDIR_DL=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPDIR_DL"' EXIT
|
||||
|
||||
echo "Downloading ${URL}..."
|
||||
curl -fSL --progress-bar -o "${TMPDIR_DL}/${FILENAME}" "$URL"
|
||||
|
||||
# Verify checksum if sha256sum/shasum is available
|
||||
if curl -fsSL -o "${TMPDIR_DL}/checksums.txt" "$CHECKSUM_URL" 2>/dev/null; then
|
||||
expected=$(awk -v filename="$FILENAME" '$2 == filename { print $1; exit }' "${TMPDIR_DL}/checksums.txt")
|
||||
if [[ -n "$expected" ]]; then
|
||||
if command -v sha256sum >/dev/null 2>&1; then
|
||||
actual=$(sha256sum "${TMPDIR_DL}/${FILENAME}" | awk '{print $1}')
|
||||
elif command -v shasum >/dev/null 2>&1; then
|
||||
actual=$(shasum -a 256 "${TMPDIR_DL}/${FILENAME}" | awk '{print $1}')
|
||||
else
|
||||
actual=""
|
||||
echo "Warning: no sha256sum/shasum found; skipping checksum verification." >&2
|
||||
fi
|
||||
if [[ -n "$actual" && "$actual" != "$expected" ]]; then
|
||||
echo "Error: checksum mismatch (expected ${expected}, got ${actual})" >&2
|
||||
exit 1
|
||||
fi
|
||||
[[ -n "$actual" ]] && echo "Checksum verified."
|
||||
else
|
||||
echo "Warning: checksum not found in checksums.txt; skipping verification." >&2
|
||||
fi
|
||||
else
|
||||
echo "Warning: could not fetch checksums.txt; skipping checksum verification." >&2
|
||||
fi
|
||||
|
||||
tar -xzf "${TMPDIR_DL}/${FILENAME}" -C "$TMPDIR_DL"
|
||||
|
||||
BINARY_PATH="${TMPDIR_DL}/${BINARY}"
|
||||
if [[ ! -f "$BINARY_PATH" ]]; then
|
||||
BINARY_PATH=$(find "$TMPDIR_DL" -type f -name "$BINARY" -print -quit)
|
||||
fi
|
||||
|
||||
if [[ -z "$BINARY_PATH" || ! -f "$BINARY_PATH" ]]; then
|
||||
echo "Error: binary not found in archive." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ── Install ──────────────────────────────────────────────────────────────────
|
||||
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
mv "$BINARY_PATH" "${INSTALL_DIR}/${BINARY}"
|
||||
chmod +x "${INSTALL_DIR}/${BINARY}"
|
||||
|
||||
echo "Installed ${BINARY} to ${INSTALL_DIR}/${BINARY}"
|
||||
|
||||
# ── PATH hint ────────────────────────────────────────────────────────────────
|
||||
|
||||
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
|
||||
echo ""
|
||||
echo "Add browseros-cli to your PATH:"
|
||||
echo ""
|
||||
|
||||
SHELL_NAME=$(basename "${SHELL:-/bin/bash}")
|
||||
case "$SHELL_NAME" in
|
||||
zsh) echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.zshrc && source ~/.zshrc" ;;
|
||||
fish) echo " fish_add_path ${INSTALL_DIR}" ;;
|
||||
*) echo " echo 'export PATH=\"${INSTALL_DIR}:\$PATH\"' >> ~/.bashrc && source ~/.bashrc" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Run 'browseros-cli --help' to get started."
|
||||
@@ -1225,7 +1225,7 @@
|
||||
const score = graders[firstKey].score;
|
||||
if (typeof score === 'number') {
|
||||
const pct = Math.round(score * 100);
|
||||
return { label: pct + '%', cls: pct >= 75 ? 'pass' : 'fail' };
|
||||
return { label: `${pct}%`, cls: pct >= 75 ? 'pass' : 'fail' };
|
||||
}
|
||||
const anyPass = keys.some((k) => graders[k].pass);
|
||||
return { label: anyPass ? 'PASS' : 'FAIL', cls: anyPass ? 'pass' : 'fail' };
|
||||
|
||||
@@ -20,6 +20,7 @@ import './lib/polyfill'
|
||||
import { EXIT_CODES } from '@browseros/shared/constants/exit-codes'
|
||||
import { CommanderError } from 'commander'
|
||||
import { loadServerConfig } from './config'
|
||||
import { isPortInUseError } from './lib/port-binding'
|
||||
import { Sentry } from './lib/sentry'
|
||||
import { Application } from './main'
|
||||
|
||||
@@ -39,6 +40,9 @@ try {
|
||||
if (error instanceof CommanderError) {
|
||||
process.exit(error.exitCode)
|
||||
}
|
||||
if (isPortInUseError(error)) {
|
||||
process.exit(EXIT_CODES.PORT_CONFLICT)
|
||||
}
|
||||
Sentry.captureException(error)
|
||||
console.error('Failed to start server:', error)
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR)
|
||||
|
||||
@@ -231,7 +231,6 @@ export class Application {
|
||||
console.error(
|
||||
`[FATAL] Failed to start ${serverName} on port ${port}: ${errorMsg}`,
|
||||
)
|
||||
Sentry.captureException(error)
|
||||
|
||||
if (isPortInUseError(error)) {
|
||||
console.error(
|
||||
@@ -240,6 +239,7 @@ export class Application {
|
||||
process.exit(EXIT_CODES.PORT_CONFLICT)
|
||||
}
|
||||
|
||||
Sentry.captureException(error)
|
||||
process.exit(EXIT_CODES.GENERAL_ERROR)
|
||||
}
|
||||
|
||||
@@ -255,7 +255,9 @@ export class Application {
|
||||
{ port },
|
||||
)
|
||||
}
|
||||
Sentry.captureException(error)
|
||||
if (!isPortInUseError(error)) {
|
||||
Sentry.captureException(error)
|
||||
}
|
||||
}
|
||||
|
||||
private logStartupSummary(controllerServerStarted: boolean): void {
|
||||
|
||||
@@ -231,7 +231,7 @@
|
||||
},
|
||||
"packages/agent-sdk": {
|
||||
"name": "@browseros-ai/agent-sdk",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.7",
|
||||
"dependencies": {
|
||||
"eventsource-parser": "^3.0.6",
|
||||
"zod-to-json-schema": "^3.24.1",
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
"start:agent": "bun ./scripts/build/controller-ext.ts && bun run --filter @browseros/agent dev",
|
||||
"build": "bun run build:server && bun run build:agent && bun run build:ext",
|
||||
"build:server": "FORCE_COLOR=1 bun scripts/build/server.ts --target=all",
|
||||
"build:server:ci": "FORCE_COLOR=1 bun scripts/build/server.ts --target=all --compile-only",
|
||||
"build:server:test": "FORCE_COLOR=1 bun scripts/build/server.ts --target=darwin-arm64 --no-upload",
|
||||
"upload:cli-installers": "bun scripts/build/cli.ts",
|
||||
"start:server:test": "bun run build:server:test && set -a && . apps/server/.env.development && set +a && dist/prod/server/.tmp/binaries/browseros-server-darwin-arm64",
|
||||
"build:agent:dev": "FORCE_COLOR=1 bun run --filter @browseros/agent --elide-lines=0 build:dev",
|
||||
"build:agent": "bun run codegen:agent && bun run --filter @browseros/agent build",
|
||||
@@ -34,6 +36,7 @@
|
||||
"lint": "bunx biome check",
|
||||
"lint:fix": "bunx biome check --write --unsafe",
|
||||
"gen:cdp": "bun scripts/codegen/cdp-protocol.ts",
|
||||
"generate:models": "bun scripts/generate-models.ts",
|
||||
"clean": "rimraf dist"
|
||||
},
|
||||
"repository": "browseros-ai/BrowserOS-server",
|
||||
|
||||
12
packages/browseros-agent/packages/agent-sdk/CHANGELOG.md
Normal file
12
packages/browseros-agent/packages/agent-sdk/CHANGELOG.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# @browseros-ai/agent-sdk
|
||||
|
||||
## v0.0.7 (2026-03-26)
|
||||
|
||||
## What's Changed
|
||||
|
||||
- chore: bump @browseros-ai/agent-sdk to 0.0.7 (#569) (#569) @DaniAkash
|
||||
|
||||
## Contributors
|
||||
|
||||
- @DaniAkash
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@browseros-ai/agent-sdk",
|
||||
"version": "0.0.5",
|
||||
"version": "0.0.7",
|
||||
"description": "Browser automation SDK for BrowserOS - navigate, interact, extract data with natural language",
|
||||
"type": "module",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
|
||||
9
packages/browseros-agent/scripts/build/cli.ts
Normal file
9
packages/browseros-agent/scripts/build/cli.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { runCliInstallerUpload } from './cli/upload'
|
||||
|
||||
runCliInstallerUpload().catch((error) => {
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
console.error(`\n✗ ${message}\n`)
|
||||
process.exit(1)
|
||||
})
|
||||
52
packages/browseros-agent/scripts/build/cli/config.ts
Normal file
52
packages/browseros-agent/scripts/build/cli/config.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { parse } from 'dotenv'
|
||||
|
||||
import type { R2Config } from '../server/types'
|
||||
|
||||
const PROD_ENV_PATH = join('apps', 'cli', '.env.production')
|
||||
const PROD_ENV_TEMPLATE_PATH = join('apps', 'cli', '.env.production.example')
|
||||
|
||||
function pickEnv(name: string, fileEnv: Record<string, string>): string {
|
||||
const value = process.env[name] ?? fileEnv[name]
|
||||
if (!value || value.trim().length === 0) {
|
||||
throw new Error(`Missing required environment variable: ${name}`)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
function loadProdEnv(rootDir: string): Record<string, string> {
|
||||
const prodEnvPath = join(rootDir, PROD_ENV_PATH)
|
||||
if (!existsSync(prodEnvPath)) {
|
||||
const templatePath = join(rootDir, PROD_ENV_TEMPLATE_PATH)
|
||||
if (existsSync(templatePath)) {
|
||||
throw new Error(
|
||||
`Missing ${PROD_ENV_PATH}. Create it from ${PROD_ENV_TEMPLATE_PATH} before running upload:cli-installers.`,
|
||||
)
|
||||
}
|
||||
throw new Error(
|
||||
`Missing ${PROD_ENV_PATH}. The template file ${PROD_ENV_TEMPLATE_PATH} was not found.`,
|
||||
)
|
||||
}
|
||||
return parse(readFileSync(prodEnvPath, 'utf-8'))
|
||||
}
|
||||
|
||||
export interface CliUploadConfig {
|
||||
r2: R2Config
|
||||
}
|
||||
|
||||
export function loadCliUploadConfig(rootDir: string): CliUploadConfig {
|
||||
const fileEnv = loadProdEnv(rootDir)
|
||||
return {
|
||||
r2: {
|
||||
accountId: pickEnv('R2_ACCOUNT_ID', fileEnv),
|
||||
accessKeyId: pickEnv('R2_ACCESS_KEY_ID', fileEnv),
|
||||
secretAccessKey: pickEnv('R2_SECRET_ACCESS_KEY', fileEnv),
|
||||
bucket: pickEnv('R2_BUCKET', fileEnv),
|
||||
downloadPrefix: '',
|
||||
uploadPrefix:
|
||||
process.env.R2_UPLOAD_PREFIX ?? fileEnv.R2_UPLOAD_PREFIX ?? 'cli',
|
||||
},
|
||||
}
|
||||
}
|
||||
56
packages/browseros-agent/scripts/build/cli/upload.ts
Normal file
56
packages/browseros-agent/scripts/build/cli/upload.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { existsSync } from 'node:fs'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { log } from '../log'
|
||||
import { createR2Client, joinObjectKey, uploadFileToObject } from '../server/r2'
|
||||
import { loadCliUploadConfig } from './config'
|
||||
|
||||
const CDN_BASE_URL = 'https://cdn.browseros.com'
|
||||
|
||||
const INSTALLERS = [
|
||||
{
|
||||
filePath: join('apps', 'cli', 'scripts', 'install.sh'),
|
||||
objectName: 'install.sh',
|
||||
contentType: 'text/x-shellscript; charset=utf-8',
|
||||
},
|
||||
{
|
||||
filePath: join('apps', 'cli', 'scripts', 'install.ps1'),
|
||||
objectName: 'install.ps1',
|
||||
contentType: 'text/plain; charset=utf-8',
|
||||
},
|
||||
] as const
|
||||
|
||||
export async function runCliInstallerUpload(): Promise<void> {
|
||||
const rootDir = resolve(dirname(fileURLToPath(import.meta.url)), '../../..')
|
||||
process.chdir(rootDir)
|
||||
await uploadCliInstallers(rootDir)
|
||||
}
|
||||
|
||||
export async function uploadCliInstallers(rootDir: string): Promise<void> {
|
||||
const { r2 } = loadCliUploadConfig(rootDir)
|
||||
const client = createR2Client(r2)
|
||||
|
||||
log.header('Uploading BrowserOS CLI installer scripts')
|
||||
|
||||
try {
|
||||
for (const installer of INSTALLERS) {
|
||||
const absolutePath = join(rootDir, installer.filePath)
|
||||
if (!existsSync(absolutePath)) {
|
||||
throw new Error(`Installer script not found: ${installer.filePath}`)
|
||||
}
|
||||
|
||||
const objectKey = joinObjectKey(r2.uploadPrefix, installer.objectName)
|
||||
log.step(`Uploading ${installer.filePath}`)
|
||||
await uploadFileToObject(client, r2, objectKey, absolutePath, {
|
||||
contentType: installer.contentType,
|
||||
})
|
||||
log.success(`Uploaded ${objectKey}`)
|
||||
log.info(`${CDN_BASE_URL}/${objectKey}`)
|
||||
}
|
||||
|
||||
log.done('CLI installer upload completed')
|
||||
} finally {
|
||||
client.destroy()
|
||||
}
|
||||
}
|
||||
@@ -21,16 +21,24 @@ export function parseBuildArgs(argv: string[]): BuildArgs {
|
||||
)
|
||||
.option('--upload', 'Upload artifact zips to R2')
|
||||
.option('--no-upload', 'Skip zip upload to R2')
|
||||
.option(
|
||||
'--compile-only',
|
||||
'Compile binaries only (skip R2 staging and upload)',
|
||||
)
|
||||
program.parse(argv, { from: 'user' })
|
||||
const options = program.opts<{
|
||||
target: string
|
||||
manifest: string
|
||||
upload: boolean
|
||||
compileOnly: boolean
|
||||
}>()
|
||||
|
||||
const compileOnly = options.compileOnly ?? false
|
||||
|
||||
return {
|
||||
targets: resolveTargets(options.target),
|
||||
manifestPath: options.manifest,
|
||||
upload: options.upload ?? true,
|
||||
upload: compileOnly ? false : (options.upload ?? true),
|
||||
compileOnly,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,14 @@ function validateProductionEnv(envVars: Record<string, string>): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function loadBuildConfig(rootDir: string): BuildConfig {
|
||||
export interface LoadBuildConfigOptions {
|
||||
compileOnly?: boolean
|
||||
}
|
||||
|
||||
export function loadBuildConfig(
|
||||
rootDir: string,
|
||||
options: LoadBuildConfigOptions = {},
|
||||
): BuildConfig {
|
||||
const fileEnv = loadProdEnv(rootDir)
|
||||
const envVars = buildInlineEnv(fileEnv)
|
||||
validateProductionEnv(envVars)
|
||||
@@ -85,6 +92,10 @@ export function loadBuildConfig(rootDir: string): BuildConfig {
|
||||
...process.env,
|
||||
}
|
||||
|
||||
if (options.compileOnly) {
|
||||
return { version: readServerVersion(rootDir), envVars, processEnv }
|
||||
}
|
||||
|
||||
return {
|
||||
version: readServerVersion(rootDir),
|
||||
envVars,
|
||||
|
||||
@@ -15,19 +15,14 @@ export async function runProdResourceBuild(argv: string[]): Promise<void> {
|
||||
process.chdir(rootDir)
|
||||
|
||||
const args = parseBuildArgs(argv)
|
||||
const manifestPath = resolve(rootDir, args.manifestPath)
|
||||
if (!existsSync(manifestPath)) {
|
||||
throw new Error(`Manifest not found: ${manifestPath}`)
|
||||
}
|
||||
|
||||
const buildConfig = loadBuildConfig(rootDir)
|
||||
const manifest = loadManifest(manifestPath)
|
||||
const distRoot = getDistProdRoot()
|
||||
const buildConfig = loadBuildConfig(rootDir, {
|
||||
compileOnly: args.compileOnly,
|
||||
})
|
||||
|
||||
log.header(`Building BrowserOS server artifacts v${buildConfig.version}`)
|
||||
log.info(`Targets: ${args.targets.map((target) => target.id).join(', ')}`)
|
||||
log.info(`Manifest: ${manifestPath}`)
|
||||
log.info(`Upload: ${args.upload ? 'enabled' : 'disabled'}`)
|
||||
log.info(`Mode: ${args.compileOnly ? 'compile-only' : 'full'}`)
|
||||
|
||||
const compiled = await compileServerBinaries(
|
||||
args.targets,
|
||||
@@ -36,7 +31,26 @@ export async function runProdResourceBuild(argv: string[]): Promise<void> {
|
||||
buildConfig.version,
|
||||
)
|
||||
|
||||
const client = createR2Client(buildConfig.r2)
|
||||
if (args.compileOnly) {
|
||||
log.done('Compile-only build completed')
|
||||
for (const binary of compiled) {
|
||||
log.info(`${binary.target.id}: ${binary.binaryPath}`)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const manifestPath = resolve(rootDir, args.manifestPath)
|
||||
if (!existsSync(manifestPath)) {
|
||||
throw new Error(`Manifest not found: ${manifestPath}`)
|
||||
}
|
||||
|
||||
const manifest = loadManifest(manifestPath)
|
||||
const distRoot = getDistProdRoot()
|
||||
const r2 = buildConfig.r2
|
||||
if (!r2) {
|
||||
throw new Error('R2 configuration is required for full builds')
|
||||
}
|
||||
const client = createR2Client(r2)
|
||||
const stagedArtifacts = []
|
||||
|
||||
try {
|
||||
@@ -51,7 +65,7 @@ export async function runProdResourceBuild(argv: string[]): Promise<void> {
|
||||
binary.target,
|
||||
rules,
|
||||
client,
|
||||
buildConfig.r2,
|
||||
r2,
|
||||
buildConfig.version,
|
||||
)
|
||||
stagedArtifacts.push(staged)
|
||||
@@ -62,7 +76,7 @@ export async function runProdResourceBuild(argv: string[]): Promise<void> {
|
||||
stagedArtifacts,
|
||||
buildConfig.version,
|
||||
client,
|
||||
buildConfig.r2,
|
||||
r2,
|
||||
args.upload,
|
||||
)
|
||||
|
||||
|
||||
@@ -10,6 +10,10 @@ import {
|
||||
|
||||
import type { R2Config } from './types'
|
||||
|
||||
export interface UploadFileOptions {
|
||||
contentType?: string
|
||||
}
|
||||
|
||||
function createClientConfig(r2: R2Config): S3ClientConfig {
|
||||
return {
|
||||
region: 'auto',
|
||||
@@ -81,6 +85,7 @@ export async function uploadFileToObject(
|
||||
r2: R2Config,
|
||||
key: string,
|
||||
filePath: string,
|
||||
options: UploadFileOptions = {},
|
||||
): Promise<void> {
|
||||
const data = await readFile(filePath)
|
||||
await client.send(
|
||||
@@ -88,7 +93,7 @@ export async function uploadFileToObject(
|
||||
Bucket: r2.bucket,
|
||||
Key: key,
|
||||
Body: data,
|
||||
ContentType: 'application/zip',
|
||||
ContentType: options.contentType ?? 'application/zip',
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface BuildArgs {
|
||||
targets: BuildTarget[]
|
||||
manifestPath: string
|
||||
upload: boolean
|
||||
compileOnly: boolean
|
||||
}
|
||||
|
||||
export interface R2Config {
|
||||
@@ -36,7 +37,7 @@ export interface BuildConfig {
|
||||
version: string
|
||||
envVars: Record<string, string>
|
||||
processEnv: NodeJS.ProcessEnv
|
||||
r2: R2Config
|
||||
r2?: R2Config
|
||||
}
|
||||
|
||||
export interface ResourceSource {
|
||||
|
||||
145
packages/browseros-agent/scripts/generate-models.ts
Normal file
145
packages/browseros-agent/scripts/generate-models.ts
Normal file
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* Fetches models.dev/api.json and generates a compact models data file
|
||||
* for BrowserOS. Run: bun scripts/generate-models.ts
|
||||
*/
|
||||
|
||||
const API_URL = 'https://models.dev/api.json'
|
||||
const OUTPUT_PATH = new URL(
|
||||
'../apps/agent/lib/llm-providers/models-dev-data.json',
|
||||
import.meta.url,
|
||||
).pathname
|
||||
|
||||
interface ModelsDevModel {
|
||||
id: string
|
||||
name: string
|
||||
family?: string
|
||||
attachment: boolean
|
||||
reasoning: boolean
|
||||
tool_call: boolean
|
||||
structured_output?: boolean
|
||||
modalities: { input: string[]; output: string[] }
|
||||
cost?: {
|
||||
input: number
|
||||
output: number
|
||||
cache_read?: number
|
||||
cache_write?: number
|
||||
}
|
||||
limit: { context: number; output: number; input?: number }
|
||||
status?: string
|
||||
release_date: string
|
||||
last_updated: string
|
||||
}
|
||||
|
||||
interface ModelsDevProvider {
|
||||
id: string
|
||||
name: string
|
||||
npm: string
|
||||
api?: string
|
||||
doc: string
|
||||
env: string[]
|
||||
models: Record<string, ModelsDevModel>
|
||||
}
|
||||
|
||||
interface OutputModel {
|
||||
id: string
|
||||
name: string
|
||||
contextWindow: number
|
||||
maxOutput: number
|
||||
supportsImages: boolean
|
||||
supportsReasoning: boolean
|
||||
supportsToolCall: boolean
|
||||
inputCost?: number
|
||||
outputCost?: number
|
||||
}
|
||||
|
||||
interface OutputProvider {
|
||||
name: string
|
||||
api?: string
|
||||
doc: string
|
||||
models: OutputModel[]
|
||||
}
|
||||
|
||||
// models.dev ID → BrowserOS provider ID
|
||||
const PROVIDER_MAP: Record<string, string> = {
|
||||
anthropic: 'anthropic',
|
||||
openai: 'openai',
|
||||
google: 'google',
|
||||
openrouter: 'openrouter',
|
||||
azure: 'azure',
|
||||
'amazon-bedrock': 'bedrock',
|
||||
lmstudio: 'lmstudio',
|
||||
moonshotai: 'moonshot',
|
||||
'github-copilot': 'github-copilot',
|
||||
}
|
||||
|
||||
function transformModel(model: ModelsDevModel): OutputModel | null {
|
||||
if (model.status === 'deprecated') return null
|
||||
|
||||
const supportsImages =
|
||||
model.attachment || model.modalities.input.includes('image')
|
||||
|
||||
return {
|
||||
id: model.id,
|
||||
name: model.name,
|
||||
contextWindow: model.limit.context,
|
||||
maxOutput: model.limit.output,
|
||||
supportsImages,
|
||||
supportsReasoning: model.reasoning,
|
||||
supportsToolCall: model.tool_call,
|
||||
...(model.cost && {
|
||||
inputCost: model.cost.input,
|
||||
outputCost: model.cost.output,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log(`Fetching ${API_URL}...`)
|
||||
const response = await fetch(API_URL)
|
||||
if (!response.ok) throw new Error(`Failed to fetch: ${response.status}`)
|
||||
|
||||
const data: Record<string, ModelsDevProvider> = await response.json()
|
||||
console.log(`Fetched ${Object.keys(data).length} providers`)
|
||||
|
||||
const output: Record<string, OutputProvider> = {}
|
||||
|
||||
for (const [modelsDevId, browserosId] of Object.entries(PROVIDER_MAP)) {
|
||||
const provider = data[modelsDevId]
|
||||
if (!provider) {
|
||||
console.warn(`Provider not found in models.dev: ${modelsDevId}`)
|
||||
continue
|
||||
}
|
||||
|
||||
const models = Object.values(provider.models)
|
||||
.map(transformModel)
|
||||
.filter((m): m is OutputModel => m !== null)
|
||||
.sort((a, b) => {
|
||||
const dateA = provider.models[a.id]?.last_updated ?? ''
|
||||
const dateB = provider.models[b.id]?.last_updated ?? ''
|
||||
return dateB.localeCompare(dateA)
|
||||
})
|
||||
|
||||
output[browserosId] = {
|
||||
name: provider.name,
|
||||
...(provider.api && { api: provider.api }),
|
||||
doc: provider.doc,
|
||||
models,
|
||||
}
|
||||
}
|
||||
|
||||
const totalModels = Object.values(output).reduce(
|
||||
(sum, p) => sum + p.models.length,
|
||||
0,
|
||||
)
|
||||
console.log(
|
||||
`Generated ${Object.keys(output).length} providers with ${totalModels} models`,
|
||||
)
|
||||
|
||||
await Bun.write(OUTPUT_PATH, JSON.stringify(output, null, 2))
|
||||
console.log(`Written to ${OUTPUT_PATH}`)
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user