-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update cloudflare worker, fix configuration
- Loading branch information
Showing
7 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -176,3 +176,7 @@ dist | |
|
||
# Astro | ||
.astro | ||
|
||
# Cloudflare | ||
.wrangler | ||
.dev.vars |
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
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,67 @@ | ||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference | ||
/// <reference types="@cloudflare/workers-types" /> | ||
|
||
import type { ExportedHandler } from '@cloudflare/workers-types' | ||
import { execute } from 'flows-ai' | ||
import * as process from 'process' | ||
|
||
/** | ||
* You must define the environment variables in the worker. | ||
* You must also create a .dev.vars file in the root of the project with them, | ||
* if you want to run this locally. | ||
*/ | ||
type Worker = ExportedHandler<{ | ||
OPENAI_API_KEY: string | ||
SLACK_API_KEY: string | ||
SLACK_CHANNEL_ID: string | ||
FIRECRAWL_API_KEY: string | ||
}> | ||
|
||
/** | ||
* Cloudflare Worker example | ||
*/ | ||
export default { | ||
async fetch() { | ||
return new Response('This worker does not handle fetch events.', { status: 200 }) | ||
}, | ||
async scheduled(_req, env) { | ||
/** | ||
* For simplicity, we run worker in nodejs_compat mode. | ||
* This means we can use process.env to set the environment variables. | ||
*/ | ||
process.env['OPENAI_API_KEY'] = env.OPENAI_API_KEY | ||
process.env['SLACK_API_KEY'] = env.SLACK_API_KEY | ||
process.env['SLACK_CHANNEL_ID'] = env.SLACK_CHANNEL_ID | ||
process.env['FIRECRAWL_API_KEY'] = env.FIRECRAWL_API_KEY | ||
|
||
/** | ||
* Import the agents and flows after setting the environment variables. | ||
*/ | ||
const { githubAgent, slackAgent, analysisAgent, npmAgent } = await import('./agents') | ||
const { organizationAnalysisWithSlackMessageFlow } = await import('./flows') | ||
|
||
/** | ||
* Execute the flow and log the response (for debugging purposes in Cloudflare Dashboard) | ||
*/ | ||
try { | ||
const response = await execute(organizationAnalysisWithSlackMessageFlow, { | ||
agents: { | ||
githubAgent, | ||
slackAgent, | ||
npmAgent, | ||
analysisAgent, | ||
}, | ||
input: 'callstackincubator', | ||
onFlowStart: (flow) => { | ||
console.log({ agent: flow.agent.name, input: flow.input }) | ||
}, | ||
onFlowFinish: (flow, response) => { | ||
console.log({ agent: flow.agent.name, response }) | ||
}, | ||
}) | ||
console.log({ response }) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
}, | ||
} satisfies Worker |
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 |
---|---|---|
|
@@ -3,7 +3,12 @@ | |
"private": true, | ||
"devDependencies": { | ||
"@clack/prompts": "^0.9.1", | ||
"flows-ai": "workspace:*" | ||
"@cloudflare/workers-types": "^4.20250124.3", | ||
"flows-ai": "workspace:*", | ||
"wrangler": "^3.105.1" | ||
}, | ||
"scripts": { | ||
"dev": "wrangler dev ./cloudflare-worker.ts" | ||
}, | ||
"author": "Mike Grabowski <[email protected]>", | ||
"license": "MIT", | ||
|
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"extends": "../tsconfig.json" | ||
} | ||
|
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,11 @@ | ||
name = "run-organization-analysis-with-slack-message" | ||
account_id = "509f0d5925f8d9fa1d5bfb6c110a7f03" | ||
workers_dev = true | ||
compatibility_date = "2025-01-26" | ||
compatibility_flags = [ "nodejs_compat" ] | ||
|
||
[triggers] | ||
crons = ["0 8 * * 2"] | ||
|
||
[observability] | ||
enabled = true |