npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@copilotkit/learning

v1.91.0

Published

Capture clicks, page changes, and network metadata in the browser as AG-UI CUSTOM events

Readme

@copilotkit/learning

Capture page context, navigation, clicks, form edits, network requests, and developer events as AG-UI CUSTOM events. Use the authenticated Core integration to send events to CopilotKit Intelligence.

Capture retains raw URLs, query strings, hashes, page titles, referrers, element text, attributes, and live control values by default. Network events include browser-visible request and response headers and body snapshots. Each body snapshot has a 4 KiB limit and an explicit status for incomplete or unavailable content. Only passwords and credentials are replaced with [redacted], in the browser:

  • Values of password fields: type="password", fields that had it earlier in the session (show-password toggles), fields with a credential key as name, and autocomplete current-password, new-password, or one-time-code.
  • Values typed into password fields, wherever they appear in body snapshots, URLs, or element attributes (the last 20 values of 4 or more characters, kept in memory until stop, also when input capture is off).
  • Values of credential keys such as password, secret, api_key, access_token, authorization, cookie, jwt, or token in JSON, URL-encoded, and FormData bodies, key: value text, query strings, hashes, and element attributes, including inside JSON strings nested up to four levels deep. Booleans and null stay.
  • Element attributes named like credentials (data-api-key, data-token).
  • Values of headers whose name is a credential key (authorization, cookie, x-api-key, x-csrf-token, …), plus x-amz-security-token, private-token, and x-token.
  • URL user names and passwords (https://user:pass@host), which are removed anywhere in captured text.

Redaction runs on the first 16 KiB of a body, before the 4 KiB limit applies. Everything else is captured raw. Binary bodies, hand-built multipart text, XML, single-quoted objects, percent-encoded JSON inside form values, OAuth code= values, path tokens, and passwords shorter than 4 characters are not redacted. See Captured data for the matching rules and limits.

Use capture, beforeSend, ignoreUrls, and data-copilotkit-ignore for your app's exclusions. The deprecated routes option no longer masks or transforms paths.

Click events also include target.label, a short, cleaned name of the clicked control. Automatic Learning shows this name to the model. It comes from the first of aria-labelledby, aria-label, the caption of a submit, button, reset, or image input, title (controls only), and the text of a control named by its content: buttons, links with href, summary, and roles such as tab, menuitem, or option. Images inside a control count with their alt, aria-label, or <title>, and a clicked icon without its own name takes the name of the control around it. Control text is not used when it looks like separate fields, as cards do: longer than 80 characters, containing headings, lists, tables, fields, or more than one paragraph, or split across two divs that hold text, directly or through inline elements, or three text-carrying siblings. ARIA autocomplete suggestions, and anything inside them, get no label from any source: aria-labelledby, aria-label, title, and text are all ignored, and aria-labelledby elsewhere that points into a suggestion list gives no name. Use data-copilotkit-action to name a suggestion. Containers, editable content, text slotted into web components, and the <label> of a native checkbox or radio button (use aria-label or data-copilotkit-action there) never contribute their text; script, style, template, and hidden content is skipped. Invisible characters are removed, passwords and credentials become [redacted], URLs [url], emails [email], and JWT or other token-like strings [redacted]. Other names are cut at 80 characters with …, and label is omitted when no name remains. Raw text, attributes, and values are unchanged. data-copilotkit-action gives a control an explicit name in target.action. To exclude a control or a suggestion list without ARIA roles, add data-copilotkit-ignore, or remove the label in beforeSend:

beforeSend: (event) => {
  if (event.name === "click" || event.name === "input")
    delete (event.value.target as { label?: string }).label;
  return event;
},

See Click labels for the full rules.

Input events also include target.label, a cleaned name of the edited field. It comes from the first of aria-labelledby, aria-label, and the field's <label> elements. Fields inside a <label>, and their values and options, are left out. The name never comes from the value, the placeholder, title, or the field's own text, and a <label> inside data-copilotkit-ignore is not used. For a select, the visible text of the chosen options follows the name, as in Deal stage: Negotiation. Cleaning follows the click label rules. See Field labels.

Text edits are combined per field and recorded after a 300 ms pause. Committing or leaving the field, pressing Enter outside input-method composition, clicking, navigating, emitting a developer event, or stopping capture records the pending edit first. Paired input and change notifications for the same edit produce one record; a later user edit can record the same value again. Checkbox and select changes remain immediate. See Form edit timing for composition and delivery behavior.

Error capture records page.error events with a kind: uncaught (errors that nothing catches), rejection (unhandled promise rejections), resource (failed image, script, stylesheet, media, or frame loads), invalid (native form validation failures, with the field label and the failed validity checks, never the value), and alert (text in role="alert" or aria-live="assertive" regions, only with capture: { alerts: true }, because alert text can contain names). Messages, validation messages, and alert text are cleaned like labels and capped. The cleanup removes emails, URLs, and credentials, not names, so keep personal data out of error messages or remove it in beforeSend. Stacks hold the cleaned message, have URL and credential redaction, and are capped at 1,000 characters. Each distinct error is sent at its 1st, 10th, 100th, … occurrence, with count, and a session sends at most 50. Set capture: { errors: false } to turn it off. See Page errors.

Authenticated Trajectories

Use Core to connect capture to CopilotKit Intelligence. This experimental integration targets the join and batch APIs in Intelligence #1569.

import { CopilotKitCore } from "@copilotkit/core";

const copilotkit = new CopilotKitCore({
  runtimeUrl: "/api/copilotkit",
  runtimeTransport: "single",
  learning: {
    onError: ({ code }) => console.warn("Trajectory capture:", code),
  },
});

const result = await copilotkit.startTrajectory();
if (result.status === "started") {
  copilotkit.emitTrajectoryEvent("deal.approved", { dealId: "deal-1" });
}

// Stop on consent withdrawal or when capture is no longer needed.
copilotkit.stopTrajectory();

An omitted trajectoryId generates a UUID. Start succeeds after Runtime authentication and the Phoenix channel join. The Runtime resolves the user on the server. Browser-supplied identity and container IDs are ignored. Setting learningContainerIds in browser capture configuration produces a warning; that option applies only to custom sinks.

To assign authenticated capture to an existing Learning Space, configure the Runtime on the server:

const intelligence = new CopilotKitIntelligence({
  apiKey: process.env.CPK_INTELLIGENCE_API_KEY!,
  getTrajectoryLearningContainerIds: ({ trajectoryId, user }) => {
    // Use the verified application user to choose existing Spaces.
    return ["expense-review"];
  },
});

The selector accepts synchronous or asynchronous results. Return [] to request no new assignments explicitly. Return null or undefined to omit assignments from the connect request. Each connect adds memberships; none of these results removes existing memberships, and a membership removed in Intelligence stays removed. Keep the result stable across reconnects. The selector needs no agent run or Thread, and a linked Thread's Space does not add the Trajectory. The browser chooses the Trajectory ID; the user comes from the Runtime. Intelligence validates that the selected Spaces belong to the API key's project.

Assignment problems never stop capture. If a selected Space does not exist, the Runtime logs a warning with the Trajectory and Space IDs and connects without any assignments, including the Spaces that exist. The selector has a five-second deadline and receives an optional second AbortSignal argument for cancelling its work when the request ends or the deadline expires. A callback error, invalid result, or deadline expiry logs a server error, and the Trajectory connects without assignments. Processing assigned events requires an Intelligence backend with Trajectory inputs enabled for Automatic Learning.

Capture includes page context, navigation, clicks, form edits, network requests, and developer events. Paths remain unchanged. The page event at start carries this package's version in sdkVersion, and your app's version in appVersion when you set the appVersion option. When Runtime starts an agent run, Core sends thread.linked with the run's threadId, once for each Thread. Runtime creates the Thread before the run starts, so Intelligence can store the link. Click Thread context and agent events are deferred for this connection path.

Core sends Phoenix events messages with { events, dropped }. It flushes after two seconds, at 50 events, or before the batch exceeds 64 KiB. Each event must fit within 16 KiB, including sequence metadata. Sizes use serialized UTF-8 JSON. The Gateway replies with { highestSeq, accepted, rejected }. This receipt confirms Redis acceptance, not a Postgres commit. Postgres projection follows asynchronously. The receipt does not identify individual rejected events.

Developer events accept any JSON value. Core adds seq to object values. It wraps scalars, arrays, null, and objects that already contain seq as { data: value, seq }, preserving the developer's data.

Sequence numbers increase for the lifetime of a Core instance, including reconnects and stop/start. They start from the Core instance's creation time in microseconds, not 0, so a new Core instance that reuses a Trajectory ID after a page reload continues above the earlier seqs. The Gateway stores each seq once per Trajectory and acknowledges a repeat as accepted, so a new Core instance can still lose events as duplicates if it starts the same ID before the earlier one's seqs run past its own start, roughly when it starts within (seqs used by the earlier instance ÷ 1000) milliseconds. Prefer a new Trajectory UUID for each Core instance when you do not need to continue one.

Capture pauses while disconnected. Reconnect requests fresh credentials. Developer events emitted during recovery count toward dropped; their content is not buffered. Core keeps one batch awaiting a receipt and one bounded queue; it does not resend failed batches. Known client losses are reported through dropped. Server rejections are already counted by the Gateway. A missing receipt reports PERSISTENCE_UNKNOWN through onError, because the server may have saved the batch. An unauthorized or trajectory_mismatch reply stops capture and reconnect attempts.

Stop cancels pending starts and reconnects. It attempts one final queued batch if no receipt is pending, then disconnects without waiting. Stop is not a guarantee that the last batch was saved. A batch still awaiting its receipt reports PERSISTENCE_UNKNOWN, including during a normal stop.

If a start or an established capture ends with an error and no onError is set, Core logs a console warning with the error code and a setup hint, such as a missing runtimeUrl, a Runtime without intelligence, or a missing identifyUser. Each outcome warns once per Core instance. Server error messages are never shown in the browser. Setting onError replaces the warning. Stops and recoverable connection loss do not warn.

React

Capture needs a Runtime configured with intelligence and identifyUser, and a project with Trajectories enabled. Then turn capture on in the provider:

<CopilotKitProvider runtimeUrl="/api/copilotkit" learning>
  {children}
</CopilotKitProvider>

learning turns capture on. For options, pass an object, such as learning={{ onError }}. learning={false} or removing the prop turns capture off, which suits a consent switch: learning={hasConsent}.

Capture starts after mount. Without learning.trajectoryId, the provider generates the Trajectory ID. The ID stays the same across rerenders, React StrictMode effect replays, reconnects, and option changes. Turning capture off and on again starts a new Trajectory with a new ID. If the browser stays disconnected longer than Intelligence's reconnect window (120 seconds by default), Intelligence seals the Trajectory. Capture then continues on a new Trajectory with a new ID and notifies onTrajectoryChanged. The sealed Trajectory keeps its losses. With your own learning.trajectoryId, or an ID you pass to startTrajectory(), capture ends with TRAJECTORY_CLOSED instead, and you choose the next ID. Unmounting the provider stops capture. Read the active ID from copilotkit.trajectoryId, or subscribe with onTrajectoryChanged.

Set learning.trajectoryId to use your own ID instead.

To decide yourself when capture starts, set autoStart: false. The provider configures capture and waits for your app to call copilotkit.startTrajectory():

<CopilotKitProvider
  runtimeUrl="/api/copilotkit"
  learning={{ autoStart: false }}
>
  {children}
</CopilotKitProvider>

With autoStart: false, the provider ignores learning.trajectoryId and logs a console warning. Pass the ID to startTrajectory({ trajectoryId }) instead.

Earlier versions waited for startTrajectory() when the object had no trajectoryId, for example learning={{ onError }}. Those objects now start capture after mount. Add autoStart: false to keep the manual start.

Custom batch sinks

The original createCollector API supports an experimental self-hosted custom batch sink with the same browser capture defaults. It does not authenticate or connect to the Gateway.

import { createCollector, httpSink } from "@copilotkit/learning";

const collector = createCollector({
  sink: httpSink("/api/learning-events"),
});

collector.start({ trajectoryId: crypto.randomUUID() });

With the custom-sink integration, pass learning to CopilotKitProvider instead. Core adds Thread context and emits agent and tool events. Agent message text is included in full unless capture.agentText is false. These additions belong to the custom-sink integration, not standalone browser capture.

Event sequence numbers increase for the lifetime of the collector or Core instance, including across stop/start cycles.

Docs: https://docs.copilotkit.ai/intelligence/capture-interactions