@copilotkit/learning 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog — learning lane
2
+
3
+ `@copilotkit/learning` versions independently of the monorepo packages
4
+ (`scopes.learning` in `release.config.json`).
5
+
6
+ `release / create-pr` prepends a section here for each release, and
7
+ `release / publish` reads that section back as the GitHub Release body.
8
+
9
+ Entries begin with the first independent release cut after this file was added.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Atai Barkai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @copilotkit/learning
2
+
3
+ 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.
4
+
5
+ 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:
6
+
7
+ - 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`.
8
+ - 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).
9
+ - 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.
10
+ - Element attributes named like credentials (`data-api-key`, `data-token`).
11
+ - 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`.
12
+ - URL user names and passwords (`https://user:pass@host`), which are removed anywhere in captured text.
13
+
14
+ 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](https://docs.copilotkit.ai/intelligence/captured-data) for the matching rules and limits.
15
+
16
+ Use `capture`, `beforeSend`, `ignoreUrls`, and `data-copilotkit-ignore` for your app's exclusions. The deprecated `routes` option no longer masks or transforms paths.
17
+
18
+ ## Authenticated Trajectories
19
+
20
+ Use Core to connect capture to CopilotKit Intelligence. This experimental integration targets the join and batch APIs in [Intelligence #1569](https://github.com/CopilotKit/Intelligence/pull/1569).
21
+
22
+ ```ts
23
+ import { CopilotKitCore } from "@copilotkit/core";
24
+
25
+ const copilotkit = new CopilotKitCore({
26
+ runtimeUrl: "/api/copilotkit",
27
+ runtimeTransport: "single",
28
+ learning: {
29
+ onError: ({ code }) => console.warn("Trajectory capture:", code),
30
+ },
31
+ });
32
+
33
+ const result = await copilotkit.startTrajectory();
34
+ if (result.status === "started") {
35
+ copilotkit.emitTrajectoryEvent("deal.approved", { dealId: "deal-1" });
36
+ }
37
+
38
+ // Stop on consent withdrawal or when capture is no longer needed.
39
+ copilotkit.stopTrajectory();
40
+ ```
41
+
42
+ An omitted `trajectoryId` generates a UUID. Start succeeds after Runtime authentication and the Phoenix channel join. The Runtime resolves the user on the server and sends only their ID to Intelligence. Browser-supplied identity and container IDs are ignored; container assignment is deferred. Setting `learningContainerIds` for authenticated capture produces a warning. That option applies only to custom sinks.
43
+
44
+ Capture includes page context, navigation, clicks, form edits, network requests, and developer events. Paths remain unchanged. Thread linking and agent events are deferred for this connection path.
45
+
46
+ 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.
47
+
48
+ 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.
49
+
50
+ 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.
51
+
52
+ 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.
53
+
54
+ 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.
55
+
56
+ In React, pass the same configuration to `CopilotKitProvider`. Set `learning.trajectoryId` to start automatically, or call the Core methods to control capture.
57
+
58
+ ## Custom batch sinks
59
+
60
+ 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.
61
+
62
+ ```ts
63
+ import { createCollector, httpSink } from "@copilotkit/learning";
64
+
65
+ const collector = createCollector({
66
+ sink: httpSink("/api/learning-events"),
67
+ });
68
+
69
+ collector.start({ trajectoryId: crypto.randomUUID() });
70
+ ```
71
+
72
+ 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.
73
+
74
+ Event sequence numbers increase for the lifetime of the collector or Core instance, including across stop/start cycles.
75
+
76
+ Docs: https://docs.copilotkit.ai/intelligence/capture-interactions