-
Notifications
You must be signed in to change notification settings - Fork 563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add Gumloop flow trigger pipe #639
Open
divanshu-go
wants to merge
1
commit into
mediar-ai:main
Choose a base branch
from
divanshu-go:gumloop-pipe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
{ | ||
"fields": [ | ||
{ | ||
"name": "interval", | ||
"type": "number", | ||
"default": 60, | ||
"description": "Interval in seconds to trigger the Gumloop flow." | ||
}, | ||
{ | ||
"name": "Frequency", | ||
"type": "string", | ||
"default": "daily", | ||
"description": "Frequency of summary execution: 'daily' for once a day at flowTime, or 'hourly:X' for every X hours (e.g., 'hourly:4')." | ||
}, | ||
{ | ||
"name": "flowTime", | ||
"type": "time", | ||
"default": "11:00", | ||
"description": "Time to trigger the Gumloop flow daily (only if Frequency is 'daily')." | ||
}, | ||
{ | ||
"name": "gumloopApiToken", | ||
"type": "string", | ||
"default": "<your_gumloop_api_token>", | ||
"description": "API token for Gumloop authentication." | ||
}, | ||
{ | ||
"name": "userId", | ||
"type": "string", | ||
"default": "<your_user_id>", | ||
"description": "User ID for the Gumloop API request." | ||
}, | ||
{ | ||
"name": "flowId", | ||
"type": "string", | ||
"default": "<your_flow_id>", | ||
"description": "The saved item ID for the Gumloop flow to be triggered." | ||
}, | ||
{ | ||
"name": "pageSize", | ||
"type": "number", | ||
"default": 100, | ||
"description": "Number of records to retrieve from Screenpipe per page for structured extraction. Increase this value if using audio." | ||
}, | ||
{ | ||
"name": "customPrompt", | ||
"type": "string", | ||
"default": "You are an AI assistant tasked with extracting structured information from screen data (OCR). Analyze the following screen data and extract relevant information about my daily activity.", | ||
"description": "Custom prompt for the AI assistant that will be used to extract information from the screen data." | ||
}, | ||
{ | ||
"name": "windowName", | ||
"type": "string", | ||
"default": "", | ||
"description": "Filter by specific window name in screen data (e.g., 'gmail', 'slack', etc.)." | ||
}, | ||
{ | ||
"name": "appName", | ||
"type": "string", | ||
"default": "", | ||
"description": "Filter by specific application name in screen data (e.g., 'Chrome', 'Visual Studio Code', etc.)." | ||
}, | ||
{ | ||
"name": "contentType", | ||
"type": "string", | ||
"default": "ocr", | ||
"description": "Type of content to analyze: 'ocr', 'audio', or 'all'." | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import * as fs from "node:fs"; | ||
import { queryScreenpipe, loadPipeConfig, ContentItem, pipe } from "@screenpipe/js"; | ||
import fetch from "node-fetch"; | ||
import process from "node:process"; | ||
|
||
async function triggerGumloopFlow( | ||
gumloopApiToken: string, | ||
userId: string, | ||
flowId: string, | ||
prompt: string, | ||
screenData: ContentItem[] | ||
): Promise<void> { | ||
const url = 'https://api.gumloop.com/api/v1/start_pipeline'; | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${gumloopApiToken}`, | ||
}; | ||
|
||
const data = { | ||
user_id: userId, | ||
saved_item_id: flowId, | ||
pipeline_inputs: [ | ||
{ input_name: 'prompt', value: prompt }, | ||
{ input_name: 'screen_data', value: JSON.stringify(screenData) } | ||
] | ||
}; | ||
|
||
const response = await fetch(url, { | ||
method: 'POST', | ||
headers: headers, | ||
body: JSON.stringify(data), | ||
}); | ||
|
||
const result = await response.json(); | ||
console.log(`Gumloop flow triggered with response: ${JSON.stringify(result)}`); | ||
} | ||
|
||
async function dailyGumloopPipeline(): Promise<void> { | ||
console.log("Starting Gumloop flow execution"); | ||
|
||
const config = await loadPipeConfig(); | ||
const interval = config.interval * 1000; | ||
const customPrompt = config.customPrompt; | ||
const gumloopApiToken = config.gumloopApiToken; | ||
const userId = config.userId; | ||
const flowId = config.flowId; | ||
const windowName = config.windowName || ""; | ||
const appName = config.appName || ""; | ||
const pageSize = config.pageSize; | ||
const contentType = config.contentType || "ocr"; | ||
|
||
pipe.scheduler | ||
.task("triggerGumloopFlow") | ||
.every(interval) | ||
.do(async () => { | ||
const now = new Date(); | ||
const oneMinuteAgo = new Date(now.getTime() - interval); | ||
|
||
const screenData = await queryScreenpipe({ | ||
startTime: oneMinuteAgo.toISOString(), | ||
endTime: now.toISOString(), | ||
windowName: windowName, | ||
appName: appName, | ||
limit: pageSize, | ||
contentType: contentType, | ||
}); | ||
|
||
if (screenData && screenData.data && screenData.data.length > 0) { | ||
await triggerGumloopFlow(gumloopApiToken, userId, flowId, customPrompt, screenData.data); | ||
} | ||
}); | ||
|
||
if (config.Frequency === "daily") { | ||
const [flowHour, flowMinute] = config.flowTime.split(":").map(Number); | ||
pipe.scheduler | ||
.task("triggerDailyGumloopFlow") | ||
.every("1 day") | ||
.at(`${flowHour}:${flowMinute}`) | ||
.do(async () => { | ||
const todayLogs = getTodayLogs(); | ||
if (todayLogs.length > 0) { | ||
await triggerGumloopFlow(gumloopApiToken, userId, flowId, customPrompt, todayLogs); | ||
} | ||
}); | ||
} else if (config.Frequency.startsWith("hourly:")) { | ||
const hours = parseInt(config.Frequency.split(":")[1], 10); | ||
pipe.scheduler | ||
.task("triggerHourlyGumloopFlow") | ||
.every(`${hours} hours`) | ||
.do(async () => { | ||
const todayLogs = getTodayLogs(); | ||
if (todayLogs.length > 0) { | ||
await triggerGumloopFlow(gumloopApiToken, userId, flowId, customPrompt, todayLogs); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
function getTodayLogs(): ContentItem[] { | ||
const logsDir = `${process.env.PIPE_DIR}/logs`; | ||
const today = new Date().toISOString().replace(/:/g, "-").split("T")[0]; | ||
const files = fs.readdirSync(logsDir); | ||
const todayFiles = files.filter(file => file.startsWith(today)); | ||
const logs: ContentItem[] = []; | ||
for (const file of todayFiles) { | ||
const content = fs.readFileSync(`${logsDir}/${file}`, "utf8"); | ||
logs.push(JSON.parse(content)); | ||
} | ||
return logs; | ||
} | ||
|
||
dailyGumloopPipeline(); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how are logs created?