@copilotkit/web-inspector 1.66.4 → 1.67.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/README.md +92 -13
- package/dist/index.cjs +1436 -429
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +118 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1438 -431
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +1721 -533
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/inspector-metadata.cjs +60 -0
- package/dist/lib/inspector-metadata.cjs.map +1 -0
- package/dist/lib/inspector-metadata.mjs +60 -0
- package/dist/lib/inspector-metadata.mjs.map +1 -0
- package/dist/lib/telemetry.cjs +117 -32
- package/dist/lib/telemetry.cjs.map +1 -1
- package/dist/lib/telemetry.mjs +116 -33
- package/dist/lib/telemetry.mjs.map +1 -1
- package/dist/lib/thread-selection.cjs +36 -0
- package/dist/lib/thread-selection.cjs.map +1 -0
- package/dist/lib/thread-selection.mjs +35 -0
- package/dist/lib/thread-selection.mjs.map +1 -0
- package/dist/package.cjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/styles/generated.cjs +1 -1
- package/dist/styles/generated.cjs.map +1 -1
- package/dist/styles/generated.mjs +1 -1
- package/dist/styles/generated.mjs.map +1 -1
- package/package.json +9 -4
- package/CHANGELOG.md +0 -505
- package/dev/css-raw-import.spec.ts +0 -31
- package/dev/index.html +0 -115
- package/dev/main.ts +0 -165
- package/dev/vite.config.ts +0 -30
- package/src/__tests__/memory-recall.spec.ts +0 -76
- package/src/__tests__/telemetry-egress-guard.spec.ts +0 -41
- package/src/__tests__/web-inspector.spec.ts +0 -3935
- package/src/assets/inspector-logo-icon.svg +0 -8
- package/src/assets/inspector-logo.svg +0 -40
- package/src/components.d.ts +0 -20
- package/src/index.ts +0 -11849
- package/src/lib/__tests__/telemetry.test.ts +0 -557
- package/src/lib/context-helpers.ts +0 -166
- package/src/lib/persistence.ts +0 -206
- package/src/lib/telemetry.ts +0 -474
- package/src/lib/testing/telemetry-egress-guard.ts +0 -33
- package/src/lib/types.ts +0 -19
- package/src/styles/generated.css +0 -2
- package/src/styles/tailwind.css +0 -23
- package/src/types/css.d.ts +0 -4
- package/src/types/svg.d.ts +0 -4
- package/tsconfig.json +0 -14
- package/tsdown.config.ts +0 -45
- package/vitest.config.ts +0 -66
- package/vitest.setup.ts +0 -84
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import type { Anchor, ContextState, Position, Size } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export function updateSizeFromElement(
|
|
4
|
-
state: ContextState,
|
|
5
|
-
element: HTMLElement,
|
|
6
|
-
fallback: Size,
|
|
7
|
-
): void {
|
|
8
|
-
const rect = element.getBoundingClientRect();
|
|
9
|
-
state.size = {
|
|
10
|
-
width: rect.width || fallback.width,
|
|
11
|
-
height: rect.height || fallback.height,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function clampSize(
|
|
16
|
-
size: Size,
|
|
17
|
-
viewport: Size,
|
|
18
|
-
edgeMargin: number,
|
|
19
|
-
minWidth: number,
|
|
20
|
-
minHeight: number,
|
|
21
|
-
): Size {
|
|
22
|
-
const maxWidth = Math.max(minWidth, viewport.width - edgeMargin * 2);
|
|
23
|
-
const maxHeight = Math.max(minHeight, viewport.height - edgeMargin * 2);
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
width: clamp(size.width, minWidth, maxWidth),
|
|
27
|
-
height: clamp(size.height, minHeight, maxHeight),
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function constrainToViewport(
|
|
32
|
-
state: ContextState,
|
|
33
|
-
position: Position,
|
|
34
|
-
viewport: Size,
|
|
35
|
-
edgeMargin: number,
|
|
36
|
-
): Position {
|
|
37
|
-
const maxX = Math.max(
|
|
38
|
-
edgeMargin,
|
|
39
|
-
viewport.width - state.size.width - edgeMargin,
|
|
40
|
-
);
|
|
41
|
-
const maxY = Math.max(
|
|
42
|
-
edgeMargin,
|
|
43
|
-
viewport.height - state.size.height - edgeMargin,
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
x: clamp(position.x, edgeMargin, maxX),
|
|
48
|
-
y: clamp(position.y, edgeMargin, maxY),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function keepPositionWithinViewport(
|
|
53
|
-
state: ContextState,
|
|
54
|
-
viewport: Size,
|
|
55
|
-
edgeMargin: number,
|
|
56
|
-
): void {
|
|
57
|
-
state.position = constrainToViewport(
|
|
58
|
-
state,
|
|
59
|
-
state.position,
|
|
60
|
-
viewport,
|
|
61
|
-
edgeMargin,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function centerContext(
|
|
66
|
-
state: ContextState,
|
|
67
|
-
viewport: Size,
|
|
68
|
-
edgeMargin: number,
|
|
69
|
-
): Position {
|
|
70
|
-
const centered: Position = {
|
|
71
|
-
x: Math.round((viewport.width - state.size.width) / 2),
|
|
72
|
-
y: Math.round((viewport.height - state.size.height) / 2),
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
state.position = constrainToViewport(state, centered, viewport, edgeMargin);
|
|
76
|
-
updateAnchorFromPosition(state, viewport, edgeMargin);
|
|
77
|
-
return state.position;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function updateAnchorFromPosition(
|
|
81
|
-
state: ContextState,
|
|
82
|
-
viewport: Size,
|
|
83
|
-
edgeMargin: number,
|
|
84
|
-
): void {
|
|
85
|
-
const centerX = state.position.x + state.size.width / 2;
|
|
86
|
-
const centerY = state.position.y + state.size.height / 2;
|
|
87
|
-
|
|
88
|
-
const horizontal: Anchor["horizontal"] =
|
|
89
|
-
centerX < viewport.width / 2 ? "left" : "right";
|
|
90
|
-
const vertical: Anchor["vertical"] =
|
|
91
|
-
centerY < viewport.height / 2 ? "top" : "bottom";
|
|
92
|
-
|
|
93
|
-
state.anchor = { horizontal, vertical };
|
|
94
|
-
|
|
95
|
-
const maxHorizontalOffset = Math.max(
|
|
96
|
-
edgeMargin,
|
|
97
|
-
viewport.width - state.size.width - edgeMargin,
|
|
98
|
-
);
|
|
99
|
-
const maxVerticalOffset = Math.max(
|
|
100
|
-
edgeMargin,
|
|
101
|
-
viewport.height - state.size.height - edgeMargin,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
state.anchorOffset = {
|
|
105
|
-
x:
|
|
106
|
-
horizontal === "left"
|
|
107
|
-
? clamp(state.position.x, edgeMargin, maxHorizontalOffset)
|
|
108
|
-
: clamp(
|
|
109
|
-
viewport.width - state.position.x - state.size.width,
|
|
110
|
-
edgeMargin,
|
|
111
|
-
maxHorizontalOffset,
|
|
112
|
-
),
|
|
113
|
-
y:
|
|
114
|
-
vertical === "top"
|
|
115
|
-
? clamp(state.position.y, edgeMargin, maxVerticalOffset)
|
|
116
|
-
: clamp(
|
|
117
|
-
viewport.height - state.position.y - state.size.height,
|
|
118
|
-
edgeMargin,
|
|
119
|
-
maxVerticalOffset,
|
|
120
|
-
),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function applyAnchorPosition(
|
|
125
|
-
state: ContextState,
|
|
126
|
-
viewport: Size,
|
|
127
|
-
edgeMargin: number,
|
|
128
|
-
): Position {
|
|
129
|
-
const maxHorizontalOffset = Math.max(
|
|
130
|
-
edgeMargin,
|
|
131
|
-
viewport.width - state.size.width - edgeMargin,
|
|
132
|
-
);
|
|
133
|
-
const maxVerticalOffset = Math.max(
|
|
134
|
-
edgeMargin,
|
|
135
|
-
viewport.height - state.size.height - edgeMargin,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const horizontalOffset = clamp(
|
|
139
|
-
state.anchorOffset.x,
|
|
140
|
-
edgeMargin,
|
|
141
|
-
maxHorizontalOffset,
|
|
142
|
-
);
|
|
143
|
-
const verticalOffset = clamp(
|
|
144
|
-
state.anchorOffset.y,
|
|
145
|
-
edgeMargin,
|
|
146
|
-
maxVerticalOffset,
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const x =
|
|
150
|
-
state.anchor.horizontal === "left"
|
|
151
|
-
? horizontalOffset
|
|
152
|
-
: viewport.width - state.size.width - horizontalOffset;
|
|
153
|
-
|
|
154
|
-
const y =
|
|
155
|
-
state.anchor.vertical === "top"
|
|
156
|
-
? verticalOffset
|
|
157
|
-
: viewport.height - state.size.height - verticalOffset;
|
|
158
|
-
|
|
159
|
-
state.anchorOffset = { x: horizontalOffset, y: verticalOffset };
|
|
160
|
-
state.position = constrainToViewport(state, { x, y }, viewport, edgeMargin);
|
|
161
|
-
return state.position;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function clamp(value: number, min: number, max: number): number {
|
|
165
|
-
return Math.min(Math.max(min, value), max);
|
|
166
|
-
}
|
package/src/lib/persistence.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import type { Anchor, DockMode, Position, Size } from "./types.js";
|
|
2
|
-
|
|
3
|
-
export type PersistedContextState = {
|
|
4
|
-
anchor?: Anchor;
|
|
5
|
-
anchorOffset?: Position;
|
|
6
|
-
size?: Size;
|
|
7
|
-
hasCustomPosition?: boolean;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type PersistedState = {
|
|
11
|
-
button?: Omit<PersistedContextState, "size">;
|
|
12
|
-
window?: PersistedContextState;
|
|
13
|
-
isOpen?: boolean;
|
|
14
|
-
dockMode?: DockMode;
|
|
15
|
-
selectedMenu?: string;
|
|
16
|
-
selectedContext?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function loadInspectorState(storageKey: string): PersistedState | null {
|
|
20
|
-
if (typeof window === "undefined") {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const raw = window.localStorage.getItem(storageKey);
|
|
25
|
-
if (raw) {
|
|
26
|
-
try {
|
|
27
|
-
const parsed = JSON.parse(raw);
|
|
28
|
-
if (parsed && typeof parsed === "object") {
|
|
29
|
-
return parsed as PersistedState;
|
|
30
|
-
}
|
|
31
|
-
} catch {
|
|
32
|
-
// Fall through to cookie migration path
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Backwards compatibility: try to read the legacy cookie and migrate it
|
|
37
|
-
if (typeof document !== "undefined") {
|
|
38
|
-
const prefix = `${storageKey}=`;
|
|
39
|
-
const entry = document.cookie
|
|
40
|
-
.split("; ")
|
|
41
|
-
.find((cookie) => cookie.startsWith(prefix));
|
|
42
|
-
if (entry) {
|
|
43
|
-
const legacyRaw = entry.substring(prefix.length);
|
|
44
|
-
try {
|
|
45
|
-
const parsed = JSON.parse(decodeURIComponent(legacyRaw));
|
|
46
|
-
if (parsed && typeof parsed === "object") {
|
|
47
|
-
return parsed as PersistedState;
|
|
48
|
-
}
|
|
49
|
-
} catch {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function saveInspectorState(
|
|
59
|
-
storageKey: string,
|
|
60
|
-
state: PersistedState,
|
|
61
|
-
): void {
|
|
62
|
-
if (typeof window === "undefined") {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
window.localStorage.setItem(storageKey, JSON.stringify(state));
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.warn("Failed to persist inspector state", error);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function isValidAnchor(value: unknown): value is Anchor {
|
|
74
|
-
if (!value || typeof value !== "object") {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const candidate = value as Anchor;
|
|
79
|
-
return (
|
|
80
|
-
(candidate.horizontal === "left" || candidate.horizontal === "right") &&
|
|
81
|
-
(candidate.vertical === "top" || candidate.vertical === "bottom")
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function isValidPosition(value: unknown): value is Position {
|
|
86
|
-
if (!value || typeof value !== "object") {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const candidate = value as Position;
|
|
91
|
-
return isFiniteNumber(candidate.x) && isFiniteNumber(candidate.y);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function isValidSize(value: unknown): value is Size {
|
|
95
|
-
if (!value || typeof value !== "object") {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const candidate = value as Size;
|
|
100
|
-
return isFiniteNumber(candidate.width) && isFiniteNumber(candidate.height);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function isFiniteNumber(value: unknown): value is number {
|
|
104
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function isValidDockMode(value: unknown): value is DockMode {
|
|
108
|
-
return value === "floating" || value === "docked-left";
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Telemetry persistence — flat per-key localStorage rather than the
|
|
112
|
-
// JSON-blob shape used for window/dock state, because each value is
|
|
113
|
-
// independent and we want to read/write them without round-tripping
|
|
114
|
-
// the whole inspector state object.
|
|
115
|
-
const TELEMETRY_DISTINCT_ID_KEY = "cpk:inspector:telemetry:distinct_id";
|
|
116
|
-
const TELEMETRY_OPT_OUT_KEY = "cpk:inspector:telemetry:opt_out";
|
|
117
|
-
const TELEMETRY_DISCLOSURE_SHOWN_KEY =
|
|
118
|
-
"cpk:inspector:telemetry:disclosure_shown";
|
|
119
|
-
|
|
120
|
-
// Module-level fallback for when localStorage is unavailable (private mode,
|
|
121
|
-
// quota exceeded, etc.). Cached so that banner_viewed and banner_clicked from
|
|
122
|
-
// the same page-load share one distinct_id even without persistent storage —
|
|
123
|
-
// funnel coherence within a session is preserved even when storage fails.
|
|
124
|
-
let inMemoryFallbackId: string | null = null;
|
|
125
|
-
|
|
126
|
-
export function getOrCreateTelemetryDistinctId(): string {
|
|
127
|
-
if (typeof window === "undefined") {
|
|
128
|
-
// SSR / test fallback. A non-persistent ID is preferable to throwing
|
|
129
|
-
// because telemetry must never break the host application.
|
|
130
|
-
return generateUuidV4();
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
const existing = window.localStorage.getItem(TELEMETRY_DISTINCT_ID_KEY);
|
|
135
|
-
if (existing && existing.length > 0) return existing;
|
|
136
|
-
const fresh = generateUuidV4();
|
|
137
|
-
window.localStorage.setItem(TELEMETRY_DISTINCT_ID_KEY, fresh);
|
|
138
|
-
return fresh;
|
|
139
|
-
} catch {
|
|
140
|
-
return (inMemoryFallbackId ??= generateUuidV4());
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Test-only reset so the in-memory fallback doesn't leak between test cases.
|
|
145
|
-
export function _resetTelemetryPersistenceForTesting(): void {
|
|
146
|
-
inMemoryFallbackId = null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function isTelemetryOptedOut(): boolean {
|
|
150
|
-
if (typeof window === "undefined") return false;
|
|
151
|
-
try {
|
|
152
|
-
return window.localStorage.getItem(TELEMETRY_OPT_OUT_KEY) === "true";
|
|
153
|
-
} catch {
|
|
154
|
-
return false;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function setTelemetryOptOut(optedOut: boolean): void {
|
|
159
|
-
if (typeof window === "undefined") return;
|
|
160
|
-
try {
|
|
161
|
-
if (optedOut) {
|
|
162
|
-
window.localStorage.setItem(TELEMETRY_OPT_OUT_KEY, "true");
|
|
163
|
-
} else {
|
|
164
|
-
window.localStorage.removeItem(TELEMETRY_OPT_OUT_KEY);
|
|
165
|
-
}
|
|
166
|
-
} catch {
|
|
167
|
-
// No-op — see getOrCreateTelemetryDistinctId.
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export function hasTelemetryDisclosureBeenShown(): boolean {
|
|
172
|
-
if (typeof window === "undefined") return false;
|
|
173
|
-
try {
|
|
174
|
-
return (
|
|
175
|
-
window.localStorage.getItem(TELEMETRY_DISCLOSURE_SHOWN_KEY) === "true"
|
|
176
|
-
);
|
|
177
|
-
} catch {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function markTelemetryDisclosureShown(): void {
|
|
183
|
-
if (typeof window === "undefined") return;
|
|
184
|
-
try {
|
|
185
|
-
window.localStorage.setItem(TELEMETRY_DISCLOSURE_SHOWN_KEY, "true");
|
|
186
|
-
} catch {
|
|
187
|
-
// No-op.
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function generateUuidV4(): string {
|
|
192
|
-
if (
|
|
193
|
-
typeof globalThis.crypto !== "undefined" &&
|
|
194
|
-
typeof globalThis.crypto.randomUUID === "function"
|
|
195
|
-
) {
|
|
196
|
-
return globalThis.crypto.randomUUID();
|
|
197
|
-
}
|
|
198
|
-
// Fallback for environments without crypto.randomUUID (older browsers,
|
|
199
|
-
// some test runners). Not cryptographically strong; acceptable because
|
|
200
|
-
// the value is just an anonymous correlation ID.
|
|
201
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
202
|
-
const r = (Math.random() * 16) | 0;
|
|
203
|
-
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
204
|
-
return v.toString(16);
|
|
205
|
-
});
|
|
206
|
-
}
|