Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion apps/mesh/src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import oauthProxyRoutes, {
fetchProtectedResourceMetadata,
} from "./routes/oauth-proxy";
import proxyRoutes from "./routes/proxy";
import { isDecoHostedMcp, DECO_STORE_URL } from "../core/well-known-mcp";
import {
isDecoHostedMcp,
DECO_STORE_URL,
WellKnownOrgMCPId,
} from "../core/well-known-mcp";
import type { MeshContext } from "../core/mesh-context";

// Track current event bus instance for cleanup during HMR
Expand Down Expand Up @@ -525,6 +529,23 @@ export function createApp(options: CreateAppOptions = {}) {
// LLM API routes (OpenAI-compatible)
app.route("/api", modelsRoutes);

// Public Events endpoint
app.post("/org/:organizationId/events/:type", async (c) => {
const orgId = c.req.param("organizationId");
await c.var.meshContext.eventBus.publish(
orgId,
WellKnownOrgMCPId.SELF(orgId),
{
data: await c.req.json(),
type: `public:${c.req.param("type")}`,
subject: c.req.query("subject"),
deliverAt: c.req.query("deliverAt"),
cron: c.req.query("cron"),
},
);
return c.json({ success: true });
});

// ============================================================================
// 404 Handler
// ============================================================================
Expand Down
4 changes: 4 additions & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface RequestContext<
}) => User | undefined;
callerApp?: string;
connectionId?: string;
organizationId?: string;
}

const withDefaultBindings = ({
Expand Down Expand Up @@ -183,6 +184,7 @@ export const withBindings = <TEnv>({
state?: Record<string, unknown>;
meshUrl?: string;
connectionId?: string;
organizationId?: string;
}) ?? {};

context = {
Expand All @@ -191,6 +193,8 @@ export const withBindings = <TEnv>({
token: tokenOrContext,
meshUrl: (decoded.meshUrl as string) ?? metadata.meshUrl,
connectionId: (decoded.connectionId as string) ?? metadata.connectionId,
organizationId:
(decoded.organizationId as string) ?? metadata.organizationId,
ensureAuthenticated: AUTHENTICATED(decoded.user ?? decoded.sub),
} as RequestContext<any>;
} else if (typeof tokenOrContext === "object") {
Expand Down