Skip to content

feat: add source handle_events API#359

Open
tonyxiao wants to merge 2 commits intomainfrom
cursor/e7fa9c81
Open

feat: add source handle_events API#359
tonyxiao wants to merge 2 commits intomainfrom
cursor/e7fa9c81

Conversation

@tonyxiao
Copy link
Copy Markdown
Collaborator

@tonyxiao tonyxiao commented May 5, 2026

Summary

  • Adds an optional handle_events method to the source protocol for stateless event-driven processing.
  • Exposes pipeline_handle_events through the engine interface, remote engine client, and POST /pipeline_handle_events HTTP endpoint.
  • Implements handle_events for source-stripe by sharing the existing webhook/Stripe-event dispatch path used by read().
  • Regenerates the engine OpenAPI spec/types and adds focused API/source tests.

Test Plan

  • pnpm --filter @stripe/sync-protocol exec tsc --noEmit
  • pnpm --filter @stripe/sync-source-stripe exec tsc --noEmit
  • pnpm --filter @stripe/sync-engine exec tsc --noEmit
  • pnpm --filter @stripe/sync-service exec tsc --noEmit
  • ./scripts/generate-openapi.sh

Note: Vitest was not run locally because the macOS environment rejects the installed esbuild binary before the runner starts.

…point

Add an optional handle_events hook on the Source protocol for stateless,
event-driven processing (webhooks, push payloads, etc.) decoupled from
read()'s backfill/polling. Wire it through the engine as
pipeline_handle_events on both createEngine and createRemoteEngine, expose
it as POST /pipeline_handle_events in the engine HTTP API, and implement
it on source-stripe by extracting the existing event-dispatch logic into
a shared processEventInput helper now reused by read()'s stdin and
live-mode loops.

Co-authored-by: Cursor <cursoragent@cursor.com>
Committed-By-Agent: cursor
@tonyxiao tonyxiao changed the title feat: add handle_events source method and /pipeline_handle_events end… feat: add source handle_events API May 5, 2026
Use connector source_input schemas to expose pipeline_handle_events as typed events grouped by source type, e.g. events.stripe: StripeEvent[].

Co-authored-by: Cursor <cursoragent@cursor.com>
Committed-By-Agent: cursor
@tonyxiao tonyxiao marked this pull request as ready for review May 5, 2026 08:20
Copilot AI review requested due to automatic review settings May 5, 2026 08:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new stateless handle_events path for sources and threads it through the engine so externally delivered events can be processed without going through the regular read() flow. In this repo, that primarily extends the Stripe source and the engine’s HTTP/OpenAPI surface.

Changes:

  • Added optional handle_events() support to the source/engine protocol and implemented pipeline_handle_events in the in-process engine, remote engine client, and HTTP API.
  • Refactored source-stripe to reuse shared event-dispatch logic for both read() and handle_events().
  • Added targeted source/API tests and regenerated OpenAPI artifacts for the new endpoint.

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/source-stripe/src/src-webhook.ts Added shared event-input dispatch helper for webhook/raw-event handling.
packages/source-stripe/src/index.ts Switched Stripe event paths to shared dispatch logic and added handle_events() implementation.
packages/source-stripe/src/index.test.ts Added unit tests for Stripe handle_events() behavior.
packages/protocol/src/protocol.ts Extended the source protocol with optional handle_events().
apps/engine/src/lib/source-test.ts Added test-source passthrough implementation of handle_events().
apps/engine/src/lib/remote-engine.ts Added remote client support for pipeline_handle_events.
apps/engine/src/lib/engine.ts Added engine-level pipeline_handle_events orchestration.
apps/engine/src/lib/createSchemas.ts Added request schema generation for grouped source events.
apps/engine/src/api/app.ts Added POST /pipeline_handle_events route and request validation.
apps/engine/src/api/app.test.ts Added endpoint tests for /pipeline_handle_events.
apps/engine/src/__generated__/openapi.json Regenerated OpenAPI spec with new endpoint and schemas.
apps/engine/src/__generated__/openapi.d.ts Regenerated typed OpenAPI declarations for the new endpoint.
Files not reviewed (1)
  • apps/engine/src/generated/openapi.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +113 to +116
const SourceEvents =
inputSchemas.length > 0
? configUnion(inputSchemas.map((s) => s.variant)).meta({ id: 'SourceEvents' })
: z.record(z.string(), z.array(z.unknown())).meta({ id: 'SourceEvents' })
Comment on lines +425 to +428
'Streams the supplied events into the source connector\'s `handle_events` hook ' +
'and returns the derived NDJSON messages (records, logs, traces). Stateless — ' +
'no checkpointing or time limits. Fails 400 if the source does not implement ' +
'`handle_events`.',
Comment on lines +158 to +160
const eventBatch: unknown[] = []
for await (const event of events) eventBatch.push(event)
const res = await post(
Comment on lines +424 to +429
let accountId: string
try {
accountId = (await resolveAccountMetadata(config, client)).accountId
} catch (err) {
yield errorToConnectionStatus(err)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants