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
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
feat: share AI provider presets to team (e2e encrypted)
Louis Beaumont098fa8e139c8
diff --git a/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx b/apps/screenpipe-app-tauri/components/settings/ai-presets.tsxindex 244678118..1da9f1833 100644--- a/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx+++ b/apps/screenpipe-app-tauri/components/settings/ai-presets.tsx@@ -75,6 +75,7 @@ import { toast } from "../ui/use-toast";import { Card, CardContent } from "../ui/card";import { AIProviderType } from "@/lib/hooks/use-settings";import { useIsEnterpriseBuild } from "@/lib/hooks/use-is-enterprise-build";+import { useTeam } from "@/lib/hooks/use-team";import {AlertDialog,AlertDialogAction,@@ -1659,7 +1660,9 @@ function SortablePresetCard({onDuplicate,onSetDefault,onDelete,+ onShareToTeam,isLoading,+ isTeamAdmin,}: {preset: AIPreset;isDefault: boolean;@@ -1668,7 +1671,9 @@ function SortablePresetCard({onDuplicate: () => void;onSetDefault: () => void;onDelete: () => void;+ onShareToTeam?: () => void;isLoading: boolean;+ isTeamAdmin?: boolean;}) {const {attributes,@@ -1744,6 +1749,11 @@ function SortablePresetCard({<Button variant="ghost" size="sm" className="text-[11px] h-6 px-2" onClick={(e) => { e.stopPropagation(); onSetDefault(); }} disabled={isLoading || isDefault}><Star className="w-3 h-3 mr-1" />{isDefault ? "default" : "set default"}</Button>+ {isTeamAdmin && onShareToTeam && (+ <Button variant="ghost" size="sm" className="text-[11px] h-6 px-2" onClick={(e) => { e.stopPropagation(); onShareToTeam(); }} disabled={isLoading}>+ share to team+ </Button>+ )}{!isDefault && (<Button variant="ghost" size="sm" className="text-[11px] h-6 px-2 text-destructive hover:text-destructive ml-auto" onClick={(e) => { e.stopPropagation(); onDelete(); }} disabled={isLoading}><Trash2 className="w-3 h-3" />@@ -1767,6 +1777,17 @@ export const AIPresets = () => {const [isDuplicating, setIsDuplicating] = useState(false);const isEnterprise = useIsEnterpriseBuild();const [piAvailable, setPiAvailable] = useState(false);+ const team = useTeam();+ const isTeamAdmin = !!team.team && team.role === "admin";++ const sharePresetToTeam = async (preset: AIPreset) => {+ try {+ await team.pushConfig("ai_provider", preset.id, preset);+ toast({ title: "shared to team", description: `"${formatPresetName(preset.id)}" is now available to all team members (e2e encrypted)` });+ } catch (err: any) {+ toast({ title: "failed to share to team", description: err.message, variant: "destructive" });+ }+ };// Drag-and-drop sensors with activation distance to avoid conflicts with clicksconst sensors = useSensors(@@ -2021,7 +2042,9 @@ export const AIPresets = () => {onDuplicate={() => duplicatePreset(preset.id)}onSetDefault={() => setPresetToSetDefault(preset.id)}onDelete={() => setPresetToDelete(preset.id)}+ onShareToTeam={isTeamAdmin ? () => sharePresetToTeam(preset) : undefined}isLoading={isLoading}+ isTeamAdmin={isTeamAdmin}/>))}</div>diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-team-sync.ts b/apps/screenpipe-app-tauri/lib/hooks/use-team-sync.tsindex 42fb7df6d..3d07f47b1 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-team-sync.ts+++ b/apps/screenpipe-app-tauri/lib/hooks/use-team-sync.ts@@ -4,10 +4,11 @@import { useEffect, useRef } from "react";import { useSettings } from "./use-settings";+import { AIPreset } from "@/lib/utils/tauri";import { TeamConfig } from "./use-team";/**- * Auto-syncs team configs (window_filter, url_filter) into local settings.+ * Auto-syncs team configs (window_filter, url_filter, ai_provider) into local settings.* Call inside a component that already has useTeam() mounted.*/export function useTeamSync(configs: TeamConfig[], hasTeam: boolean) {@@ -70,12 +71,31 @@ export function useTeamSync(configs: TeamConfig[], hasTeam: boolean) {ignoredUrls: [...new Set(ignoredUrls)],};+ // Merge team AI provider presets into local presets+ const aiProviderConfigs = configs.filter(+ (c) => c.config_type === "ai_provider" && c.scope === "team" && c.value+ );+ let updatedPresets = [...settings.aiPresets];+ for (const c of aiProviderConfigs) {+ const teamPreset = c.value as AIPreset;+ if (!teamPreset.id || !teamPreset.provider) continue;+ const existing = updatedPresets.findIndex((p) => p.id === teamPreset.id);+ if (existing >= 0) {+ // Update in place, preserve local defaultPreset flag+ const merged = { ...teamPreset, defaultPreset: updatedPresets[existing].defaultPreset } as AIPreset;+ updatedPresets[existing] = merged;+ } else {+ // Add new team preset (not default)+ updatedPresets.push({ ...teamPreset, defaultPreset: false } as AIPreset);+ }+ }+// Fingerprint to avoid redundant writes- const fingerprint = JSON.stringify(teamFilters);+ const fingerprint = JSON.stringify({ teamFilters, presetIds: aiProviderConfigs.map((c) => `${c.key}:${c.updated_at}`) });if (fingerprint === lastFingerprint.current) return;lastFingerprint.current = fingerprint;- updateSettings({ teamFilters });+ updateSettings({ teamFilters, aiPresets: updatedPresets });// eslint-disable-next-line react-hooks/exhaustive-deps}, [configs, hasTeam]);}