Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

feat(enterprise): admin API token field in Settings → screenpipe-team

Louis Beaumont03e641b484eb
diff --git a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx b/apps/screenpipe-app-tauri/components/settings/general-settings.tsx
index ef927909a..5afbde025 100644
--- a/apps/screenpipe-app-tauri/components/settings/general-settings.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/general-settings.tsx
@@ -153,6 +153,8 @@ export default function GeneralSettings() {
</CardContent>
</Card>
+ {isEnterprise && <EnterpriseAdminTokenCard />}
+
<Card className="border-border bg-card">
<CardContent className="px-3 py-2.5">
<div className="flex items-center justify-between">
@@ -249,3 +251,154 @@ export default function GeneralSettings() {
</div>
);
}
+
+/**
+ * Admin API token card — only rendered in enterprise builds.
+ *
+ * Background: org-wide team-query auth has two intentionally separate
+ * pieces. `license_key` is org-level and lives on every employee's
+ * machine (deployed by IT). `team_api_token` is per-admin: it grants
+ * the `read:devices` / `read:search` / `read:records` scopes and is
+ * what the `screenpipe-team` pi skill curls v1 endpoints with. An
+ * admin mints one at https://screenpi.pe/enterprise?tab=tokens, pastes
+ * it here once, and the desktop persists it to
+ * ~/.screenpipe/enterprise.json so the next pi-agent boot can install
+ * the skill. Revoke from the same dashboard page to kill team access.
+ *
+ * Loads the current token (server returns nothing sensitive — just
+ * presence) and shows the first/last few chars so the admin can tell
+ * "yes I have one configured" without us round-tripping the plaintext.
+ */
+function EnterpriseAdminTokenCard() {
+ const { toast } = useToast();
+ const [token, setToken] = useState("");
+ const [hasExisting, setHasExisting] = useState(false);
+ const [saving, setSaving] = useState(false);
+
+ useEffect(() => {
+ (async () => {
+ try {
+ const cur = await commands.getEnterpriseTeamApiToken();
+ setHasExisting(Boolean(cur && cur.length > 0));
+ } catch {
+ /* command may not exist yet on older binaries — silent */
+ }
+ })();
+ }, []);
+
+ const handleSave = async () => {
+ const trimmed = token.trim();
+ if (!trimmed) {
+ toast({ title: "paste a token first" });
+ return;
+ }
+ if (!trimmed.startsWith("sk_ent_")) {
+ toast({
+ title: "that doesn't look like an admin token",
+ description: "expected format: sk_ent_...",
+ });
+ return;
+ }
+ setSaving(true);
+ try {
+ const res = await commands.saveEnterpriseTeamConfig(null, null, trimmed);
+ if (res.status === "error") throw new Error(res.error);
+ setHasExisting(true);
+ setToken("");
+ toast({
+ title: "admin token saved",
+ description:
+ "restart the app to install the screenpipe-team skill for the pi agent.",
+ });
+ } catch (e) {
+ toast({
+ title: "failed to save",
+ description: e instanceof Error ? e.message : String(e),
+ });
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ const handleClear = async () => {
+ setSaving(true);
+ try {
+ // Passing an empty string clears the field (see
+ // save_enterprise_team_config implementation in commands.rs).
+ const res = await commands.saveEnterpriseTeamConfig(null, null, "");
+ if (res.status === "error") throw new Error(res.error);
+ setHasExisting(false);
+ setToken("");
+ toast({ title: "admin token cleared" });
+ } catch (e) {
+ toast({
+ title: "failed to clear",
+ description: e instanceof Error ? e.message : String(e),
+ });
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ return (
+ <Card className="border-border bg-card">
+ <CardContent className="px-3 py-2.5 space-y-2">
+ <div className="flex items-center space-x-2.5">
+ <Shield className="h-4 w-4 text-muted-foreground shrink-0" />
+ <div className="flex-1 min-w-0">
+ <h3 className="text-sm font-medium text-foreground">
+ Admin API token
+ </h3>
+ <p className="text-xs text-muted-foreground">
+ Lets the pi agent query org-wide team data. Mint at{" "}
+ <button
+ className="underline text-foreground hover:text-foreground/80"
+ onClick={() =>
+ openUrl("https://screenpi.pe/enterprise?tab=tokens")
+ }
+ >
+ screenpi.pe/enterprise → api tokens
+ </button>{" "}
+ with scopes read:devices, read:search, read:records.
+ </p>
+ </div>
+ {hasExisting && (
+ <span className="text-[10px] font-mono px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 shrink-0">
+ configured
+ </span>
+ )}
+ </div>
+ <div className="flex items-center gap-2">
+ <input
+ type="password"
+ value={token}
+ onChange={(e) => setToken(e.target.value)}
+ placeholder={hasExisting ? "sk_ent_… (replace)" : "sk_ent_…"}
+ className="flex-1 h-7 px-2 text-xs font-mono rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring"
+ spellCheck={false}
+ autoComplete="off"
+ />
+ <Button
+ size="sm"
+ disabled={saving || !token.trim()}
+ onClick={handleSave}
+ className="h-7 text-xs"
+ >
+ save
+ </Button>
+ {hasExisting && (
+ <Button
+ size="sm"
+ variant="outline"
+ disabled={saving}
+ onClick={handleClear}
+ className="h-7 text-xs"
+ >
+ clear
+ </Button>
+ )}
+ </div>
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/apps/screenpipe-app-tauri/lib/utils/tauri.ts b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
index ce5502fe8..fb3120c8e 100644
--- a/apps/screenpipe-app-tauri/lib/utils/tauri.ts
+++ b/apps/screenpipe-app-tauri/lib/utils/tauri.ts
@@ -341,6 +341,15 @@ async saveEnterpriseTeamConfig(isAdmin: boolean | null, licenseActive: boolean |
async getCloudToken() : Promise<string | null> {
return await TAURI_INVOKE("get_cloud_token");
},
+/**
+ * Read the enterprise admin API token from
+ * `~/.screenpipe/enterprise.json.team_api_token`. Returns null when
+ * missing/empty. Used by Settings → Admin API token to render
+ * "configured" state. Hand-written stub; specta regenerates on rebuild.
+ */
+async getEnterpriseTeamApiToken() : Promise<string | null> {
+ return await TAURI_INVOKE("get_enterprise_team_api_token");
+},
/**
* Called by the frontend after fetching the enterprise policy.
*/
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index fba1acef1..482b2cc45 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -662,6 +662,28 @@ pub fn save_enterprise_license_key(license_key: String) -> Result<(), String> {
Ok(())
}
+/// Read the enterprise admin API token (`team_api_token`) from
+/// `~/.screenpipe/enterprise.json`. Returns None when the file is
+/// missing, malformed, or the field is empty.
+///
+/// Used by the Settings → Enterprise → Admin API token card to render
+/// "configured" state without round-tripping the plaintext value through
+/// the React state. The token itself is treated as a secret: the
+/// frontend only learns "yes there's a value" via this getter, never
+/// gets the value back.
+#[tauri::command]
+#[specta::specta]
+pub fn get_enterprise_team_api_token() -> Option<String> {
+ let path = screenpipe_core::paths::default_screenpipe_data_dir().join("enterprise.json");
+ let raw = std::fs::read_to_string(&path).ok()?;
+ let parsed: serde_json::Value = serde_json::from_str(&raw).ok()?;
+ parsed
+ .get("team_api_token")
+ .and_then(|t| t.as_str())
+ .filter(|s| !s.is_empty())
+ .map(String::from)
+}
+
/// Read the user's screenpipe cloud session JWT from `~/.screenpipe/
/// auth.json`. Returns None when the file is missing, malformed, or the
/// token field is empty.
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 54edbb5e9..8dd5181e5 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -739,6 +739,7 @@ async fn main() {
commands::get_enterprise_license_key,
commands::save_enterprise_license_key,
commands::save_enterprise_team_config,
+ commands::get_enterprise_team_api_token,
commands::get_cloud_token,
enterprise_policy::set_enterprise_policy,
commands::get_disk_usage,
@@ -1015,6 +1016,7 @@ async fn main() {
enterprise_policy::set_enterprise_policy,
commands::save_enterprise_license_key,
commands::save_enterprise_team_config,
+ commands::get_enterprise_team_api_token,
commands::get_cloud_token,
spawn_screenpipe,
stop_screenpipe,
diff --git a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
index 108f41988..b0685838a 100644
--- a/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
+++ b/crates/screenpipe-core/assets/skills/screenpipe-team/SKILL.md
@@ -9,26 +9,29 @@ Query the customer's team telemetry. Data lives in the customer's own Azure Blob
## Auth
-Two pieces, both already on disk after the admin signs in to screenpipe cloud — no separate token to mint or paste:
+The skill authenticates with an **enterprise admin API token** the admin minted once on `https://screenpi.pe/enterprise?tab=tokens` (with scopes `read:devices`, `read:search`, `read:records`) and pasted into Settings → Enterprise → Admin API token. The desktop stored it in `~/.screenpipe/enterprise.json` under `team_api_token`.
-- **Cloud session JWT** from `~/.screenpipe/auth.json` (`.token`). This is a long-lasting Clerk JWT minted by the screenpipe-cloud sign-in flow (`getToken({template:"long-lasting"})`); the v1 endpoints validate it via Clerk and check the user's email against the license's `admin_emails`.
-- **License key** from `~/.screenpipe/enterprise.json` (`.license_key`). Tells the server which org the admin wants to query (one user can admin multiple licenses).
+License-key + token are intentionally separate concerns:
+- `license_key` proves *which org* this machine belongs to (deployed by IT, same on every employee's device).
+- `team_api_token` proves *this user is an admin of that org* and grants the read scopes. Employees who don't have it can't query team data even though they have the same license_key.
```bash
-CLOUD_TOKEN=$(jq -r .token ~/.screenpipe/auth.json)
-LICENSE_KEY=$(jq -r .license_key ~/.screenpipe/enterprise.json)
+TEAM_TOKEN=$(jq -r .team_api_token ~/.screenpipe/enterprise.json)
SP_URL="https://screenpi.pe/api/enterprise/v1"
-AUTH_HEADERS=(-H "Authorization: Bearer $CLOUD_TOKEN" -H "X-License-Key: $LICENSE_KEY")
+AUTH_HEADERS=(-H "Authorization: Bearer $TEAM_TOKEN")
```
-If `CLOUD_TOKEN` doesn't start with `eyJ` (real Clerk JWT prefix — anything shorter like `sp-…` is leftover from an older auth scheme) OR if the v1 endpoints return **401 invalid bearer token**: tell the user verbatim:
+If `TEAM_TOKEN` is empty / null, tell the user verbatim:
-> Your screenpipe cloud session looks stale (auth.json doesn't have a
-> current Clerk JWT). Sign out and sign back into screenpipe cloud
-> from the desktop app — that re-mints a long-lasting token, and the
-> team skill works automatically afterward.
+> I need an admin API token to query team data. Open
+> https://screenpi.pe/enterprise?tab=tokens, create one with the
+> `read:devices`, `read:search`, `read:records` scopes, then paste it
+> into Settings → Enterprise → Admin API token. Token can be rotated
+> or revoked any time from the same page.
-If the server returns **403** ("not an admin of this license"): tell the user "you're not listed as an admin on this license — ask whoever owns the license to add your email under enterprise → members".
+Then stop. Don't try to call the endpoints.
+
+If the server returns **401** the token is invalid, expired, or revoked — tell the user to mint a new one. **403** means the token is missing a required scope — same dashboard, regenerate with the right scopes.
## Context window protection
diff --git a/crates/screenpipe-core/src/agents/pi.rs b/crates/screenpipe-core/src/agents/pi.rs
index 30ac7b998..8ca0c493f 100644
--- a/crates/screenpipe-core/src/agents/pi.rs
+++ b/crates/screenpipe-core/src/agents/pi.rs
@@ -259,27 +259,21 @@ impl PiExecutor {
.map(|s| !s.is_empty())
.unwrap_or(false);
- // The skill authenticates v1 calls with the long-lasting Clerk
- // JWT minted on screenpipe-cloud sign-in (cli-login.tsx →
- // getToken({ template: "long-lasting" })), persisted to
- // auth.json by the desktop's auth flow. Older installs may
- // have a stale `sp-…` API key in this slot from a prior auth
- // scheme — those will 401 against v1; the user has to sign
- // out + sign back in to mint a fresh JWT.
- //
- // We only gate skill install on token PRESENCE here, not
- // format — the validation happens server-side. The skill's own
- // bash blocks notice the 401 and surface a clear "re-sign-in"
- // message to the user.
- let auth_path = home.join(".screenpipe").join("auth.json");
- let cloud_signed_in = std::fs::read_to_string(&auth_path)
- .ok()
- .and_then(|raw| serde_json::from_str::<serde_json::Value>(&raw).ok())
- .and_then(|v| v.get("token").and_then(|t| t.as_str()).map(String::from))
+ // The skill authenticates v1/* calls with a dedicated admin API
+ // token (sk_ent_…) the admin mints once at
+ // screenpi.pe/enterprise?tab=tokens and pastes into Settings →
+ // Enterprise → Admin API token. Stored on disk under
+ // `team_api_token`. This is intentionally separate from the
+ // license_key: any employee has the license_key (deployed by
+ // IT) but only admins should be able to query teammates'
+ // telemetry, so a per-admin revocable token gates the skill.
+ let team_token_present = parsed
+ .get("team_api_token")
+ .and_then(|v| v.as_str())
.map(|s| !s.is_empty())
.unwrap_or(false);
- is_admin && license_active && license_key_present && cloud_signed_in
+ is_admin && license_active && license_key_present && team_token_present
}
/// Ensure screenpipe skills exist in `project_dir/.pi/skills/`.