Repository navigation
feat(learning): connect Trajectories through Runtime and Gateway - #7566
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository: CopilotKit/CopilotKit/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/learning
@copilotkit/mcp-apps-renderer
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
|
Size Change: +12.9 kB (+0.74%) Total Size: 1.75 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Thread links: the fields the backend reads, for when linking moves out of deferred The authenticated path in this PR sends no Thread context, and one test checks that no When you add linking, the gateway reads these fields. They match what #7556's open-Thread registry and click enrichment already produce:
A link is made only to a live Thread in the same project whose owner is the same app user as the join token. Any other The contract is in (Ben, drafted with Claude.) |
9cb62a9
into
alem/pe-471-pair-on-browser-interaction-capture-experiments
Try it: `pnpm --filter demo exec next dev --turbopack -p 3471`, then open `http://localhost:3471/learning` and click through a deal. This PR adds Trajectory capture to CopilotKit. `@copilotkit/learning` records browser activity (clicks, form edits, page changes, and network requests) as AG-UI `CUSTOM` events. With CopilotKit, Core authenticates through Runtime and sends the events to the Intelligence Realtime Gateway. Apps that do not pass `learning` behave exactly as before. This PR now also contains #7566 (Runtime authentication and Gateway delivery), which was stacked on it. ## What does this PR do? - **`@copilotkit/learning`** (new, about 5.8 KB gzip): the collector. Capture follows the approved October 9 self-hosted scope: maximum resolution, with no filtering or categorization. Two kinds of values never leave the browser: password values and credential headers become `[redacted]`. - **Runtime:** a `trajectory/connect` route (REST and single endpoint). It resolves the user with `identifyUser` and requests a single-use join token from Intelligence. The project key stays on the server. - **Core:** - A `learning` config, plus `startTrajectory()`, `stopTrajectory()`, `emitTrajectoryEvent()`, and `registerOpenThread()`. - Batches go over Phoenix with sequence numbers, receipts, the Gateway limits, and `dropped` counts. A failed batch is never resent. - A custom `sink` keeps the standalone mode, which also adds Thread, message, and tool context. - **React:** a `learning` prop on `CopilotKitProvider`, with automatic or manual start and cleanup on unmount. The `data-tool-call-id` wrapper renders only while capture is active. - **Demo and docs:** the `/learning` pages in `examples/v2/react/demo`, and three Intelligence docs pages. ## Related PRs and Issues - Linear: [PE-471](https://linear.app/copilotkit/issue/PE-471), [PE-506](https://linear.app/copilotkit/issue/PE-506) - Includes #7566. Backend: CopilotKit/Intelligence#1569 (ingestion) and #1580 (read APIs). ## Checklist - [ ] I have read the [Contribution Guide](https://github.com/copilotkit/copilotkit/blob/master/CONTRIBUTING.md) - [x] If the PR changes or adds functionality, I have updated the relevant documentation - [ ] "Allow edits by maintainers" is checked (lets us help iterate on your PR directly — faster turnaround for everyone) ## Changes in the latest push - Merged #7566 and `main`. - **Fix:** with `"auto"` transport (the default), capture started before `/info` finished and sent a single-endpoint request to REST runtimes, which failed. Core now waits for transport detection. - **CodeRabbit:** - Password values and credential headers are redacted. - `data-copilotkit-ignore` now works through shadow roots. - Click text is capped at 1,000 characters, so a large container cannot exceed the 16 KiB event limit. - Reopening an in-flight XHR no longer reports the old request. ## Existing users (PE-506) With no `learning` prop or config: - No listeners, patches, timers, sockets, or Core or agent subscriptions are installed. The tests `installs nothing without the learning prop` and `warns and captures nothing without the learning option` cover this. - The tool-call DOM is unchanged, because the wrapper renders only during capture. - Runtime routes are unchanged. `trajectory/connect` is new and returns clear errors outside Intelligence. - `fetch`, XHR, and streaming responses are untouched. ## Testing Commands run (Windows, local): - `pnpm nx run-many --targets=test,check-types --projects=@copilotkit/learning,@copilotkit/core,@copilotkit/react-core,@copilotkit/runtime`: all pass. learning 77 tests, core 1,140, react-core 1,786 (plus 54 node checks), runtime 2,803. Types pass in all four. - `node packages/learning/scripts/check-size.mjs`: 5,783 bytes gzip (budget 6,144). - `oxfmt` and `oxlint` on the changed files: 0 errors. - Skipped: the local lefthook hooks (heavy, and flaky on this machine). CI runs the full checks. Manual test: 1. Run the demo, then open `/learning`. 2. Click **Open** on a deal, send a chat message, and click **Approve** in the approval prompt. 3. Open **Captured events**. Check the click, page, network, and agent events. How this PR makes testing easy: unit tests in all four packages, a real-Phoenix boundary test in Core, and the demo pages. ## Risk / rollback Low for existing users, because nothing runs without `learning`. Core now bundles the collector, so `@copilotkit/core` grows. Rollback: revert this PR. Open items, not in this PR: - In the authenticated mode, events carry no Thread context yet. The backend already supports Thread links. This was deferred on purpose, and the decision is tracked in PE-504. - No real round trip against Intelligence Dev yet. That is PE-507. ## Public API change **Before** ```tsx <CopilotKitProvider runtimeUrl="/api/copilotkit">{children}</CopilotKitProvider> ``` **After** ```tsx <CopilotKitProvider runtimeUrl="/api/copilotkit" learning={{ trajectoryId }}> {children} </CopilotKitProvider>; // Or start capture yourself: const result = await copilotkit.startTrajectory(); // { status: "started", trajectoryId } copilotkit.emitTrajectoryEvent("deal.approved", { dealId: "deal-1" }); copilotkit.stopTrajectory(); ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added learning and interaction capture for page navigation, clicks, form input, network activity, agent messages, and tool interactions, with credential redaction. * Added controls to start and stop trajectories, send custom events, filter captured data, and deliver event batches to custom endpoints. * Added authenticated trajectory capture through the CopilotKit provider. * Added a demo for reviewing captured events and trying deal approval flows. * **Documentation** * Added guides for interaction capture, standalone collection, captured data, and setup. * **Bug Fixes** * Preserved message and tool-call identifiers in custom chat layouts for interaction attribution. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…opilotKit#7601) Application servers can assign browser Trajectories to existing Learning Spaces without a Thread. `getTrajectoryLearningContainerIds` selects Spaces from the verified application user and Trajectory ID; browser-supplied assignments remain ignored. The Runtime validates and deduplicates IDs, logs selector errors, and returns a sanitized `LEARNING_CONTAINER_SELECTION_FAILED` HTTP 500. Core treats that code as terminal. Selectors have a five-second deadline and an optional second `AbortSignal` argument. Tests cover invalid results, cancellation, timeout, and both Runtime route modes. Each connect adds memberships. `[]` adds none; `null` or `undefined` omits the assignment field. None removes existing memberships. A missing Space stops capture with `LEARNING_CONTAINER_NOT_FOUND`. Usage docs state these rules and describe only the user context the callback receives. **Companion:** [Intelligence CopilotKit#1621](https://github.com/CopilotKit/Intelligence/pull/1621) adds native Trajectory analysis and evidence viewing. Both PRs target `main`; CopilotKit#7556 and CopilotKit#7566 are already merged. Thread linking and chat events remain deferred on this connection path. Validation on this revision: - `pnpm nx test @copilotkit/runtime --excludeTaskDependencies -- <four Trajectory/selector test files>`: 96 passed. Focused Core connection suite: 52 passed. - `pnpm nx run-many -t check-types -p @copilotkit/runtime @copilotkit/core --excludeTaskDependencies` passed; matching `build` passed. - Uncached `publint`, `attw`, and `check-dts` passed for both packages. Public API manifest is current. - Normal pre-commit ran `test,publint,attw` for 25 affected projects and passed, including all 2,827 Runtime tests. - Previously verified local flow: real browser activity → server assignment → stored events → automatic model run → one saved insight with 19 event references. Expense records were demo data. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Authenticated browser Trajectories can now be assigned to existing Learning Spaces using a server-side selector, without requiring a Thread or agent conversation. * Assignments are validated and deduplicated, with a five-second limit. Reconnecting adds memberships without removing existing ones. * **Bug Fixes** * Assignment failures no longer prevent Trajectory capture from connecting; missing Spaces trigger a warning, while selector errors are logged. * **Documentation** * Clarified server-side assignment setup and the limits of browser-provided Learning Space IDs. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
The SDK now sends raw Trajectory activity through Runtime authentication and the Phoenix Realtime Gateway. This connects the collector in #7556 to Intelligence while retaining the public methods
startTrajectory,stopTrajectory, andemitTrajectoryEvent.This PR follows Ben’s feedback on the contract Notion doc and the backend API in Intelligence #1569, checked at
a8242078. Capture scope follows Tyler’s self-hosted update.Behavior
502 CONNECTION_FAILED; missing user identity returns401 IDENTITY_REQUIRED.eventsbatches with sequence numbers and dropped counts. Ben’s limits remain 16 KiB/event, 50 events/batch, and 64 KiB/batch. Each body snapshot has a 4 KiB serialized budget and a one-second read timeout; truncation or unavailable content is marked. Oversized events report loss instead of bypassing Gateway limits.trajectory_over_shareandtrajectory_outbox_fullare known rejections.storage_unavailablecan mean a Redis timeout after a write, so it reportsPERSISTENCE_UNKNOWNwithout replaying events or drop counts.Scope and limits
Thread linking, container assignment, and Inspector work remain deferred. October 9 targets self-hosted ingestion and the saved Trajectories view behind a feature flag. Live updates in the Intelligence web app move to October 16; the SDK’s ingestion socket remains required. Web UI, backend flag rollout, and managed-service privacy/security work are separate from this SDK PR.
Each new Core instance needs a new Trajectory UUID. Sequence numbers persist across reconnects and stop/start on that instance, but there is no cross-tab or reload resume cursor. Initial offline start returns
CONNECTION_LOST; callers retry when online.Validation
Production SDK code is exercised with synthetic browser data and mocked external services; no deployed Gateway, Redis, or Postgres is claimed.
publint, andattwpass. The expanded package is about 5.5 KiB gzipped; its bundle budget is now 6 KiB.The broad package commit hook was excluded because unrelated native prerequisites are unavailable locally. Scoped Nx checks ran separately; CI covers the complete PR.
Review/merge order: #7556, then #7566. This is a dependent branch stack; GitHub’s native stack feature is not enabled.