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
Fix notion/obsidian pipe settings (#1342)
shaik-zeeshand1bfa9ec3c54
diff --git a/pipes/notion/src/app/api/intelligence/route.ts b/pipes/notion/src/app/api/intelligence/route.tsindex 95a9e4bd3..894d23db1 100644--- a/pipes/notion/src/app/api/intelligence/route.ts+++ b/pipes/notion/src/app/api/intelligence/route.ts@@ -4,31 +4,31 @@ import { generateObject } from "ai";import { ollama } from "ollama-ai-provider";import { Client } from "@notionhq/client";import { NotionClient } from "@/lib/notion/client";-import { pipe } from "@screenpipe/js";+import { getScreenpipeAppSettings } from "@/lib/actions/get-screenpipe-app-settings";// rich schema for relationship intelligenceconst contactSchema = z.object({- name: z.string(),- company: z.string().optional(),- lastInteraction: z.string(),- sentiment: z.number(), // -1 to 1- topics: z.array(z.string()),- nextSteps: z.array(z.string()),+ name: z.string(),+ company: z.string().optional(),+ lastInteraction: z.string(),+ sentiment: z.number(), // -1 to 1+ topics: z.array(z.string()),+ nextSteps: z.array(z.string()),});const relationshipIntelligence = z.object({- contacts: z.array(contactSchema),- insights: z.object({- followUps: z.array(z.string()),- opportunities: z.array(z.string()),- }),+ contacts: z.array(contactSchema),+ insights: z.object({+ followUps: z.array(z.string()),+ opportunities: z.array(z.string()),+ }),});async function analyzeRelationships(- recentLogs: string,- model: string+ recentLogs: string,+ model: string,): Promise<z.infer<typeof relationshipIntelligence>> {- const prompt = `analyze these work logs and create a comprehensive relationship intelligence report.+ const prompt = `analyze these work logs and create a comprehensive relationship intelligence report.focus on:- identifying key people and their roles- tracking interaction patterns and sentiment@@ -66,118 +66,120 @@ async function analyzeRelationships(of course adapt the example response to the actual data you have, do not use John Doe in your example response, use the names and companies of the people you see in the logs.`;- const provider = ollama(model);- console.log("prompt", prompt);- const response = await generateObject({- model: provider,- messages: [{ role: "user", content: prompt }],- schema: relationshipIntelligence,- maxRetries: 5,- });-- console.log(response.object);- return response.object;+ const provider = ollama(model);+ console.log("prompt", prompt);+ const response = await generateObject({+ model: provider,+ messages: [{ role: "user", content: prompt }],+ schema: relationshipIntelligence,+ maxRetries: 5,+ });++ console.log(response.object);+ return response.object;}async function readRecentLogs(- client: Client,- databaseId: string,- since: Date+ client: Client,+ databaseId: string,+ since: Date,): Promise<string> {- try {- const response = await client.databases.query({- database_id: databaseId,- filter: {- and: [- {- property: "Date",- date: {- on_or_after: since.toISOString().split("T")[0],- },- },- ],- },- sorts: [- {- property: "Date",- direction: "ascending",- },- ],- });-- return response.results- .map((page: any) => {- const title = page.properties.Title?.title[0]?.text?.content || "";- const description =- page.properties.Description?.rich_text[0]?.text?.content || "";- return `${title}\n${description}`;- })- .join("\n\n");- } catch (error) {- console.error("Failed to read logs:", error);- return "";- }+ try {+ const response = await client.databases.query({+ database_id: databaseId,+ filter: {+ and: [+ {+ property: "Date",+ date: {+ on_or_after: since.toISOString().split("T")[0],+ },+ },+ ],+ },+ sorts: [+ {+ property: "Date",+ direction: "ascending",+ },+ ],+ });++ return response.results+ .map((page: any) => {+ const title = page.properties.Title?.title[0]?.text?.content || "";+ const description =+ page.properties.Description?.rich_text[0]?.text?.content || "";+ return `${title}\n${description}`;+ })+ .join("\n\n");+ } catch (error) {+ console.error("Failed to read logs:", error);+ return "";+ }}export async function GET() {- try {- const settings = await pipe.settings.getNamespaceSettings("notion");-- if (- !settings?.notion?.accessToken ||- !settings?.notion?.databaseId ||- !settings?.notion?.intelligenceDbId- ) {- return NextResponse.json(- { error: "notion not configured" },- { status: 400 }- );- }-- const client = new Client({ auth: settings.notion.accessToken });-- // Get last 24 hours of logs- const today = new Date();- const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000);-- const recentLogs = await readRecentLogs(- client,- settings.notion.databaseId,- yesterday- );-- if (!recentLogs) {- return NextResponse.json(- { message: "no logs found for analysis" },- { status: 404 }- );- }-- const intelligence = await analyzeRelationships(- recentLogs,- settings.aiModel || "mistral"- );-- const notion = new NotionClient(settings.notion);-- const deepLink = await notion.createIntelligence(intelligence);-- return NextResponse.json({- message: "relationship intelligence updated",- intelligence,- deepLink,- summary: {- contacts: intelligence.contacts.length,- opportunities: intelligence.insights.opportunities.length,- needsFollowUp: intelligence.insights.followUps.length,- logsAnalyzed: recentLogs.length,- },- });- } catch (error) {- console.error("error in intelligence api:", error);- return NextResponse.json(- { error: `failed to process intelligence: ${error}` },- { status: 500 }- );- }+ try {+ const settings = (await getScreenpipeAppSettings())["customSettings"]![+ "notion"+ ];++ if (+ !settings?.notion?.accessToken ||+ !settings?.notion?.databaseId ||+ !settings?.notion?.intelligenceDbId+ ) {+ return NextResponse.json(+ { error: "notion not configured" },+ { status: 400 },+ );+ }++ const client = new Client({ auth: settings.notion.accessToken });++ // Get last 24 hours of logs+ const today = new Date();+ const yesterday = new Date(today.getTime() - 24 * 60 * 60 * 1000);++ const recentLogs = await readRecentLogs(+ client,+ settings.notion.databaseId,+ yesterday,+ );++ if (!recentLogs) {+ return NextResponse.json(+ { message: "no logs found for analysis" },+ { status: 404 },+ );+ }++ const intelligence = await analyzeRelationships(+ recentLogs,+ settings.aiModel || "mistral",+ );++ const notion = new NotionClient(settings.notion);++ const deepLink = await notion.createIntelligence(intelligence);++ return NextResponse.json({+ message: "relationship intelligence updated",+ intelligence,+ deepLink,+ summary: {+ contacts: intelligence.contacts.length,+ opportunities: intelligence.insights.opportunities.length,+ needsFollowUp: intelligence.insights.followUps.length,+ logsAnalyzed: recentLogs.length,+ },+ });+ } catch (error) {+ console.error("error in intelligence api:", error);+ return NextResponse.json(+ { error: `failed to process intelligence: ${error}` },+ { status: 500 },+ );+ }}diff --git a/pipes/notion/src/app/api/log/route.ts b/pipes/notion/src/app/api/log/route.tsindex bad605369..523de7058 100644--- a/pipes/notion/src/app/api/log/route.ts+++ b/pipes/notion/src/app/api/log/route.ts@@ -2,12 +2,15 @@ import { NextResponse } from "next/server";import { pipe } from "@screenpipe/js";import { generateWorkLog } from "@/lib/helpers";import { NotionClient } from "@/lib/notion/client";+import { getScreenpipeAppSettings } from "@/lib/actions/get-screenpipe-app-settings";const minute = (min: number) => min * 60 * 1000;export async function GET() {try {- const settings = await pipe.settings.getNamespaceSettings("notion");+ const settings = (await getScreenpipeAppSettings())["customSettings"]![+ "notion"+ ];const model = settings?.aiModel;const pageSize = settings?.pageSize || 50;@@ -17,14 +20,14 @@ export async function GET() {if (!model) {return NextResponse.json({ error: "model not selected" },- { status: 401 }+ { status: 401 },);}if (!settings?.notion?.accessToken || !settings?.notion?.databaseId) {return NextResponse.json({ error: "notion not configured" },- { status: 400 }+ { status: 400 },);}@@ -41,7 +44,7 @@ export async function GET() {if (!screenData || screenData.data.length === 0) {return NextResponse.json({ message: "no screen data found" },- { status: 404 }+ { status: 404 },);}@@ -50,7 +53,7 @@ export async function GET() {model,oneHourAgo,now,- customPrompt+ customPrompt,);console.log(logEntry);@@ -67,7 +70,7 @@ export async function GET() {console.error("error in work log api:", error);return NextResponse.json({ error: `failed to process work log: ${error}` },- { status: 500 }+ { status: 500 },);}}diff --git a/pipes/notion/src/app/api/setup/route.ts b/pipes/notion/src/app/api/setup/route.tsindex e9bbd62fd..e6cc562a7 100644--- a/pipes/notion/src/app/api/setup/route.ts+++ b/pipes/notion/src/app/api/setup/route.ts@@ -1,17 +1,27 @@import { NextResponse } from "next/server";import { automateNotionSetup } from "@/lib/notion/setup";-import { pipe } from "@screenpipe/js";+import { getScreenpipeAppSettings } from "@/lib/actions/get-screenpipe-app-settings";export async function GET() {- try {- const settings = await pipe.settings.getNamespaceSettings("notion");- const credentials = await automateNotionSetup(settings?.workspace);- return NextResponse.json(credentials);- } catch (error) {- console.log(error);- return NextResponse.json(- { error: "Failed to setup Notion" },- { status: 500 }- );- }+ try {+ const settings = (await getScreenpipeAppSettings())["customSettings"]![+ "notion"+ ];++ if (!settings.workspace) {+ return NextResponse.json(+ { error: "Please provide workspace name" },+ { status: 404 },+ );+ }++ const credentials = await automateNotionSetup(settings?.workspace);+ return NextResponse.json(credentials);+ } catch (error) {+ console.log(error);+ return NextResponse.json(+ { error: "Failed to setup Notion" },+ { status: 500 },+ );+ }}diff --git a/pipes/notion/src/components/notion-settings.tsx b/pipes/notion/src/components/notion-settings.tsxindex d2dab6cac..7f0466fd1 100644--- a/pipes/notion/src/components/notion-settings.tsx+++ b/pipes/notion/src/components/notion-settings.tsx@@ -16,7 +16,7 @@ import { validateCredentials } from "@/lib/notion/notion";import { toast } from "@/hooks/use-toast";import { useNotionSettings } from "@/lib/hooks/use-pipe-settings";import { ChevronDown, Loader2 } from "lucide-react";-import { NotionCredentials, Settings } from "@/lib/types";+import { Settings } from "@/lib/types";import { updatePipeConfig } from "@/lib/actions/update-pipe-config";import { FileSuggestTextarea } from "./file-suggest-textarea";import {@@ -41,10 +41,9 @@ export function NotionSettings() {const [testingLog, setTestingLog] = useState(false);const [testingIntelligence, setTestingIntelligence] = useState(false);const [localSettings, setLocalSettings] = useState<Partial<Settings> | null>(- {}+ {},);-useEffect(() => {setLocalSettings({...settings,@@ -346,7 +345,9 @@ export function NotionSettings() {setLocalSettings({...localSettings!,notion: {- ...localSettings?.notion!,+ databaseId: localSettings?.notion?.databaseId || "",+ intelligenceDbId:+ localSettings?.notion?.intelligenceDbId || "",accessToken: e.target.value,},})@@ -372,7 +373,12 @@ export function NotionSettings() {onChange={(value) =>setLocalSettings({...localSettings!,- notion: { ...localSettings?.notion!, databaseId: value },+ notion: {+ accessToken: localSettings?.notion?.accessToken || "",+ intelligenceDbId:+ localSettings?.notion?.intelligenceDbId || "",+ databaseId: value,+ },})}dialogTitle="Extract Database ID from URL"@@ -386,7 +392,8 @@ export function NotionSettings() {setLocalSettings({...localSettings!,notion: {- ...localSettings?.notion!,+ accessToken: localSettings?.notion?.accessToken || "",+ databaseId: localSettings?.notion?.databaseId || "",intelligenceDbId: value,},})diff --git a/pipes/notion/src/lib/hooks/use-pipe-settings.tsx b/pipes/notion/src/lib/hooks/use-pipe-settings.tsxindex 5780665d1..34fb6a166 100644--- a/pipes/notion/src/lib/hooks/use-pipe-settings.tsx+++ b/pipes/notion/src/lib/hooks/use-pipe-settings.tsx@@ -41,12 +41,25 @@ export function useNotionSettings() {const loadSettings = async () => {try {- // Load notion settings from localStorage- const storedSettings = localStorage.getItem(STORAGE_KEY);- const notionSettings = storedSettings ? JSON.parse(storedSettings) : {};-// Load screenpipe app settingsconst screenpipeSettings = await getScreenpipeAppSettings();++ console.log(screenpipeSettings);+ // Load notion settings from localStorage+ // const storedSettings = localStorage.getItem(STORAGE_KEY);+ // const notionSettings = storedSettings+ // ? JSON.parse(storedSettings)+ // : {+ // ...(screenpipeSettings.customSettings?.notion && {+ // ...screenpipeSettings.customSettings?.notion,+ // }),+ // };+ const notionSettings = {+ ...(screenpipeSettings.customSettings?.notion && {+ ...screenpipeSettings.customSettings?.notion,+ }),+ };+// Merge everything togethersetSettings({...DEFAULT_SETTINGS,@@ -76,11 +89,11 @@ export function useNotionSettings() {...screenpipeAppSettings,customSettings: {...screenpipeAppSettings?.customSettings,- notion: mergedNotionSettings,+ notion: notionSettings,},});- localStorage.setItem(STORAGE_KEY, JSON.stringify(mergedNotionSettings));+ // localStorage.setItem(STORAGE_KEY, JSON.stringify(mergedNotionSettings));// Update state with everythingsetSettings({diff --git a/pipes/obsidian/src/components/obsidian-settings.tsx b/pipes/obsidian/src/components/obsidian-settings.tsxindex ba8266a92..14dda90f7 100644--- a/pipes/obsidian/src/components/obsidian-settings.tsx+++ b/pipes/obsidian/src/components/obsidian-settings.tsx@@ -108,7 +108,10 @@ export function ObsidianSettings() {prompt: customPrompt || "",};- await updateSettings(obsidianSettings);+ await updateSettings({+ ...settings!,+ ...obsidianSettings,+ });await updatePipeConfig(interval / 60000);loadingToast.update({@@ -129,7 +132,7 @@ export function ObsidianSettings() {setTestLogLoading(true);try {const formData = new FormData(- document.querySelector("form") as HTMLFormElement+ document.querySelector("form") as HTMLFormElement,);const interval = parseInt(formData.get("interval") as string) * 60000;const obsidianSettings = {@@ -140,7 +143,10 @@ export function ObsidianSettings() {prompt: customPrompt || "",};- await updateSettings(obsidianSettings);+ await updateSettings({+ ...settings!,+ ...obsidianSettings,+ });await updatePipeConfig(interval / 60000);// Then test log generation@@ -184,6 +190,7 @@ export function ObsidianSettings() {}await updateSettings({+ ...settings!,vaultPath: path,});@@ -277,7 +284,7 @@ export function ObsidianSettings() {const searchQuery = `path:"${relativePath}"`;const deepLink = `obsidian://search?vault=${encodeURIComponent(- vaultName+ vaultName,)}&query=${encodeURIComponent(searchQuery)}`;window.open(deepLink, "_blank");@@ -373,7 +380,7 @@ export function ObsidianSettings() {});}}, 500),- []+ [],);// Add this new useEffect for initial path validation@@ -452,8 +459,8 @@ export function ObsidianSettings() {pathValidation.isValid? "border-green-500": pathValidation.message- ? "border-red-500"- : ""+ ? "border-red-500"+ : ""}`}onChange={(e) => validatePath(e.target.value)}/>@@ -468,7 +475,7 @@ export function ObsidianSettings() {className="cursor-pointer hover:bg-muted"onClick={() => {const input = document.getElementById(- "vaultPath"+ "vaultPath",) as HTMLInputElement;if (input) {input.value = path;@@ -718,7 +725,7 @@ export function ObsidianSettings() {>• {item}</div>- )+ ),)}</div></div>diff --git a/pipes/obsidian/src/lib/hooks/use-pipe-settings.tsx b/pipes/obsidian/src/lib/hooks/use-pipe-settings.tsxindex c535b844f..fe7ace9c9 100644--- a/pipes/obsidian/src/lib/hooks/use-pipe-settings.tsx+++ b/pipes/obsidian/src/lib/hooks/use-pipe-settings.tsx@@ -6,7 +6,7 @@ import {} from "../actions/get-screenpipe-app-settings";const DEFAULT_SETTINGS: Partial<Settings> = {- prompt: `yo, you're my personal data detective! 🕵️♂️+ prompt: `yo, you're my personal data detective! 🕵rules for the investigation:- extract names of people i interact with and what we discussed, when i encounter a person, make sure to extract their name like this [[John Doe]] so it's linked in my notes@@ -39,21 +39,32 @@ export function usePipeSettings() {const [settings, setSettings] = useState<Partial<Settings> | null>(null);const [loading, setLoading] = useState(true);- console.log("settings", settings);-useEffect(() => {loadSettings();}, []);const loadSettings = async () => {try {- // Load notion settings from localStorage- const storedSettings = localStorage.getItem(STORAGE_KEY);- const notionSettings = storedSettings ? JSON.parse(storedSettings) : {};-// Load screenpipe app settingsconst screenpipeSettings = await getScreenpipeAppSettings();+ console.log(screenpipeSettings);++ // Load notion settings from localStorage+ //const storedSettings = localStorage.getItem(STORAGE_KEY);+ //const notionSettings = storedSettings+ // ? JSON.parse(storedSettings)+ // : {+ // ...(screenpipeSettings.customSettings?.obsidian && {+ // ...screenpipeSettings.customSettings?.obsidian,+ // }),+ // };+ const notionSettings = {+ ...(screenpipeSettings.customSettings?.obsidian && {+ ...screenpipeSettings.customSettings?.obsidian,+ }),+ };+// Merge everything togethersetSettings({...DEFAULT_SETTINGS,@@ -77,20 +88,17 @@ export function usePipeSettings() {...obsidianSettings,};- const appSettings = {+ // Update screenpipe settings if provided+ await updateScreenpipeAppSettings({...screenpipeAppSettings,customSettings: {...screenpipeAppSettings?.customSettings,obsidian: obsidianSettings,},- };- console.log("updating store settings", appSettings);-- // Update screenpipe settings if provided- await updateScreenpipeAppSettings(appSettings);+ });// Update notion settings in localStorage- localStorage.setItem(STORAGE_KEY, JSON.stringify(mergedObsidianSettings));+ // localStorage.setItem(STORAGE_KEY, JSON.stringify(mergedObsidianSettings));// Update state with everythingsetSettings({