-
Notifications
You must be signed in to change notification settings - Fork 1
feat(github): publish webhook events to Event Bus #315
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||
| /** | ||||||
| * Event Bus reference cache. | ||||||
| * | ||||||
| * Captured during onChange (when the runtime has full state), | ||||||
| * so the webhook handler can publish events without going through | ||||||
| * the authenticated runtime path. | ||||||
| */ | ||||||
|
|
||||||
| type EventPublishFn = (event: { | ||||||
| type: string; | ||||||
| subject: string; | ||||||
| data?: Record<string, unknown>; | ||||||
| }) => Promise<unknown>; | ||||||
|
|
||||||
| let cachedPublish: EventPublishFn | null = null; | ||||||
|
|
||||||
| export function setEventPublisher(publish: EventPublishFn): void { | ||||||
| cachedPublish = publish; | ||||||
| } | ||||||
|
|
||||||
| export function clearEventPublisher(): void { | ||||||
| cachedPublish = null; | ||||||
| } | ||||||
|
|
||||||
| export async function publishEvent(event: { | ||||||
| type: string; | ||||||
| subject: string; | ||||||
| data?: Record<string, unknown>; | ||||||
| }): Promise<void> { | ||||||
| if (!cachedPublish) { | ||||||
| console.warn( | ||||||
| "[EventBus] No publisher available — EVENT_BUS not yet configured", | ||||||
| ); | ||||||
| return; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: Returning here silently drops the webhook event. Prompt for AI agents
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| await cachedPublish(event); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import type { Registry } from "@decocms/mcps-shared/registry"; | |
| import { serve } from "@decocms/mcps-shared/serve"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This webhook path can silently drop valid events until Prompt for AI agents |
||
| import { withRuntime } from "@decocms/runtime"; | ||
| import { exchangeCodeForToken } from "./lib/github-client.ts"; | ||
| import { setEventPublisher } from "./lib/event-bus.ts"; | ||
| import { captureInstallationMappings } from "./lib/installation-map.ts"; | ||
| import { | ||
| handleProxiedRequest, | ||
|
|
@@ -72,12 +73,19 @@ const runtime = withRuntime<Env, typeof StateSchema, Registry>({ | |
| onChange: async (env) => { | ||
| invalidateUpstreamCache(); | ||
|
|
||
| // Capture Event Bus reference for webhook handler | ||
| const eventBus = env.MESH_REQUEST_CONTEXT?.state?.EVENT_BUS; | ||
| if (eventBus) { | ||
| setEventPublisher((event) => eventBus.EVENT_PUBLISH(event)); | ||
| } | ||
|
|
||
| const token = env.MESH_REQUEST_CONTEXT?.authorization; | ||
| const connectionId = env.MESH_REQUEST_CONTEXT?.connectionId; | ||
| if (token && connectionId) { | ||
| await captureInstallationMappings(token, connectionId); | ||
| } | ||
| }, | ||
| scopes: ["EVENT_BUS::*"], | ||
| state: StateSchema, | ||
| }, | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,14 +3,12 @@ | |
| */ | ||
|
|
||
| import type { Registry } from "@decocms/mcps-shared/registry"; | ||
| import { type DefaultEnv } from "@decocms/runtime"; | ||
| import { BindingOf, type DefaultEnv } from "@decocms/runtime"; | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * State schema — no user-configurable options needed. | ||
| * The upstream URL is always https://api.githubcopilot.com/mcp/. | ||
| */ | ||
| export const StateSchema = z.object({}); | ||
| export const StateSchema = z.object({ | ||
| EVENT_BUS: BindingOf("@deco/event-bus"), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1: This required Prompt for AI agents |
||
| }); | ||
|
|
||
| /** | ||
| * Environment type combining Deco bindings with shared Registry | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
P1: This singleton publisher will send every webhook through the last connection that ran
onChange, so multi-connection installs can publish into the wrong Event Bus context.Prompt for AI agents