@sentry/junior-dashboard 0.275.0 → 0.276.0

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.
Files changed (37) hide show
  1. package/dist/app.js +28 -9
  2. package/dist/client.js +115 -92
  3. package/dist/index.js +28 -9
  4. package/dist/tailwind.css +1 -1
  5. package/package.json +5 -4
  6. package/src/app.ts +8 -3
  7. package/src/client/conversations/ConversationComposer.tsx +42 -26
  8. package/src/client/conversations/ConversationDetails.tsx +63 -35
  9. package/src/client/conversations/ConversationHeader.tsx +10 -2
  10. package/src/client/conversations/ConversationListStatusIcon.tsx +16 -11
  11. package/src/client/conversations/ConversationMemories.tsx +118 -78
  12. package/src/client/conversations/ConversationMeta.tsx +47 -42
  13. package/src/client/conversations/ConversationPage.tsx +168 -58
  14. package/src/client/conversations/ConversationTranscript.tsx +37 -8
  15. package/src/client/conversations/ConversationWatches.tsx +37 -15
  16. package/src/client/conversations/PendingMailboxStack.tsx +11 -1
  17. package/src/client/conversations/QuickQuestion.tsx +476 -0
  18. package/src/client/conversations/TelemetryMetrics.tsx +2 -1
  19. package/src/client/conversations/TranscriptActivityGroup.tsx +5 -0
  20. package/src/client/conversations/TranscriptEventView.tsx +25 -2
  21. package/src/client/conversations/TranscriptMemoryPopover.tsx +179 -0
  22. package/src/client/conversations/TranscriptMessageView.tsx +46 -16
  23. package/src/client/conversations/TranscriptRows.tsx +9 -2
  24. package/src/client/conversations/UsageCard.tsx +3 -3
  25. package/src/client/conversations/conversationMemory.ts +138 -0
  26. package/src/client/conversations/eventTranscript.ts +8 -0
  27. package/src/client/review-desk/ReviewItemActions.tsx +1 -1
  28. package/src/client/review-desk/ReviewItemChangeRow.tsx +85 -0
  29. package/src/client/review-desk/ReviewItemContext.tsx +41 -23
  30. package/src/client/review-desk/reviewItemFormat.ts +16 -0
  31. package/src/client/sentry.ts +77 -0
  32. package/src/client/types.ts +6 -0
  33. package/src/client.tsx +3 -0
  34. package/src/mock-reporting/watches.ts +2 -0
  35. package/src/shell.ts +27 -2
  36. package/src/tailwind.css +8 -19
  37. package/src/client/components/ActiveIndicator.tsx +0 -14
@@ -9,28 +9,39 @@ import { ConversationTranscriptView } from "../conversations/ConversationTranscr
9
9
  import { TranscriptLoading } from "../conversations/TranscriptLoading";
10
10
  import { useConversationData } from "../conversations/queries";
11
11
  import type { ConversationTranscript } from "../types";
12
+ import { excerptMessage } from "./reviewItemFormat";
12
13
 
13
14
  /** Messages before the item that the excerpt shows. */
14
15
  const BEFORE_COUNT = 3;
15
- /** Messages after the item that the excerpt shows, newest last. */
16
- const AFTER_COUNT = 8;
16
+ /** Messages after the item that the excerpt shows. */
17
+ const AFTER_COUNT = 3;
17
18
 
18
19
  /**
19
- * Split the messages of a Conversation at the time an item was added. Only
20
- * messages show: the tool call that added the item would repeat its card.
20
+ * Pick the messages nearest the time an item was added. Only messages show:
21
+ * the tool call that added the item would repeat its card. For a closed item,
22
+ * messages from its close on do not show: the card already has the answer.
21
23
  */
22
24
  function conversationExcerpt(
23
25
  events: readonly ConversationReportEvent[],
24
- itemCreatedAt: string,
26
+ item: Pick<ReviewItemPayload, "closedAt" | "createdAt">,
25
27
  ): { after: ConversationReportEvent[]; before: ConversationReportEvent[] } {
26
- const askedAt = Date.parse(itemCreatedAt);
27
- const messages = events.filter(
28
- (event) => event.data.type === "message" && event.data.role !== "system",
29
- );
28
+ const askedAt = Date.parse(item.createdAt);
29
+ const closedAt = item.closedAt ? Date.parse(item.closedAt) : Infinity;
30
+ // Changes to items show on their cards, not as context for this one.
31
+ const messages = events.flatMap((event) => {
32
+ if (event.data.type !== "message" || event.data.role === "system") {
33
+ return [];
34
+ }
35
+ const message = excerptMessage(event);
36
+ return message ? [message] : [];
37
+ });
30
38
  return {
31
39
  after: messages
32
- .filter((event) => Date.parse(event.createdAt) > askedAt)
33
- .slice(-AFTER_COUNT),
40
+ .filter((event) => {
41
+ const at = Date.parse(event.createdAt);
42
+ return at > askedAt && at < closedAt;
43
+ })
44
+ .slice(0, AFTER_COUNT),
34
45
  before: messages
35
46
  .filter((event) => Date.parse(event.createdAt) <= askedAt)
36
47
  .slice(-BEFORE_COUNT),
@@ -49,8 +60,8 @@ function Excerpt(props: {
49
60
  }
50
61
 
51
62
  /**
52
- * Show the end of the Conversation that added an item, split where the agent
53
- * asked. Returns `fallback` when the viewer cannot read its messages.
63
+ * Show the messages around the point where the agent added an item, split
64
+ * where it asked. Returns `fallback` when the viewer cannot read its messages.
54
65
  */
55
66
  export function ReviewItemContext(props: {
56
67
  fallback: ReactNode;
@@ -60,30 +71,37 @@ export function ReviewItemContext(props: {
60
71
  const data = detail.data;
61
72
  const events = data?.events;
62
73
  const excerpt = useMemo(
63
- () =>
64
- events ? conversationExcerpt(events, props.item.createdAt) : undefined,
65
- [events, props.item.createdAt],
74
+ () => (events ? conversationExcerpt(events, props.item) : undefined),
75
+ [events, props.item],
66
76
  );
67
77
  // The first page holds the newest events. Load earlier pages until the
68
- // page reaches the time the item was added, or history ends.
78
+ // page reaches the time the item was added, or history ends. Until then
79
+ // the loaded messages after the ask are not the first ones, so the
80
+ // excerpt waits.
69
81
  const loadPreviousPageRef = useRef(detail.loadPreviousPage);
70
82
  loadPreviousPageRef.current = detail.loadPreviousPage;
71
83
  const oldest = events?.[0]?.createdAt;
72
- const loadEarlier =
84
+ // Redacted or expired history has no messages to wait for.
85
+ const available = data?.eventHistory.status === "available";
86
+ const missingEarlier =
87
+ available &&
73
88
  oldest !== undefined &&
74
89
  Date.parse(oldest) > Date.parse(props.item.createdAt) &&
75
- detail.hasPreviousPage &&
76
- !detail.isLoadingPreviousPage &&
77
- !detail.historyError;
90
+ detail.hasPreviousPage;
91
+ const loadEarlier =
92
+ missingEarlier && !detail.isLoadingPreviousPage && !detail.historyError;
78
93
  useEffect(() => {
79
94
  if (loadEarlier) loadPreviousPageRef.current();
80
95
  }, [loadEarlier, oldest]);
81
96
 
82
- if (detail.isPending) return <TranscriptLoading />;
97
+ if (detail.isPending || (missingEarlier && !detail.historyError)) {
98
+ return <TranscriptLoading />;
99
+ }
83
100
  if (
84
101
  !data ||
85
102
  !excerpt ||
86
- data.eventHistory.status !== "available" ||
103
+ !available ||
104
+ missingEarlier ||
87
105
  excerpt.before.length + excerpt.after.length === 0
88
106
  ) {
89
107
  return props.fallback;
@@ -91,6 +91,22 @@ export function latestReviewItemId(
91
91
  return undefined;
92
92
  }
93
93
 
94
+ /**
95
+ * Return a message for another item's excerpt, without the Review item
96
+ * changes that it records: those show on their own items. Returns undefined
97
+ * when nothing else remains.
98
+ */
99
+ export function excerptMessage(
100
+ event: ConversationReportEvent,
101
+ ): ConversationReportEvent | undefined {
102
+ const { data } = event;
103
+ if (data.type !== "message" || !data.reviewItemChanges) return event;
104
+ // A message with changes lists its own Events. With none, it only
105
+ // records changes.
106
+ if (!data.events) return undefined;
107
+ return { ...event, data: { ...data, reviewItemChanges: undefined } };
108
+ }
109
+
94
110
  /** True when an open item asks a question that the viewer can answer. */
95
111
  export function reviewItemWaitsForAnswer(item: ReviewItemPayload): boolean {
96
112
  return (
@@ -0,0 +1,77 @@
1
+ import {
2
+ browserTracingIntegration,
3
+ init,
4
+ type BrowserOptions,
5
+ } from "@sentry/browser";
6
+ import type { BrowserSentryConfig } from "@sentry/junior/instrumentation";
7
+
8
+ declare global {
9
+ interface Window {
10
+ __JUNIOR_DASHBOARD_SENTRY__?: Omit<
11
+ BrowserSentryConfig,
12
+ "baggage" | "sentryTrace"
13
+ >;
14
+ }
15
+ }
16
+
17
+ type StreamedSpanJSON = Parameters<
18
+ NonNullable<BrowserOptions["beforeSendSpan"]>
19
+ >[0];
20
+
21
+ const QUERY_ATTRIBUTE_KEYS = [
22
+ "http.fragment",
23
+ "http.query",
24
+ "url.fragment",
25
+ "url.query",
26
+ ];
27
+ // Element selectors in interaction and web vital attributes include these
28
+ // attribute values, such as a conversation title in an `aria-label`. The SDK
29
+ // does not escape quotes in values, so a value can contain `"]` and fake
30
+ // selector parts. Cutting from the first marker to the last `"]` removes every
31
+ // value, at the cost of the selector parts between them.
32
+ const ELEMENT_ATTRIBUTE_START = /\[(?:aria-label|type|name|title|alt)="/;
33
+
34
+ function scrubSelector(value: string): string {
35
+ const start = value.search(ELEMENT_ATTRIBUTE_START);
36
+ if (start === -1) return value;
37
+ const end = value.lastIndexOf('"]');
38
+ return end < start
39
+ ? value.slice(0, start)
40
+ : value.slice(0, start) + value.slice(end + 2);
41
+ }
42
+
43
+ function scrubAttribute(value: string): string {
44
+ // Page and API URLs carry search text in the query string.
45
+ if (/^https?:\/\//.test(value)) return value.split(/[?#]/, 1)[0] ?? value;
46
+ return scrubSelector(value);
47
+ }
48
+
49
+ // Browser span names are fixed labels such as "Click" or "GET localhost". The
50
+ // page content they describe is in their attributes.
51
+ function scrubSpan(span: StreamedSpanJSON): StreamedSpanJSON {
52
+ for (const key of QUERY_ATTRIBUTE_KEYS) {
53
+ delete span.attributes[key];
54
+ }
55
+ for (const [key, value] of Object.entries(span.attributes)) {
56
+ if (typeof value === "string") {
57
+ span.attributes[key] = scrubAttribute(value);
58
+ }
59
+ }
60
+ return span;
61
+ }
62
+
63
+ /**
64
+ * Send dashboard performance spans to the server's Sentry project when the
65
+ * server provides a DSN. Only tracing is enabled: error events and
66
+ * breadcrumbs could carry conversation content shown on the page.
67
+ */
68
+ export function initDashboardSentry(): void {
69
+ const config = window.__JUNIOR_DASHBOARD_SENTRY__;
70
+ if (!config) return;
71
+ init({
72
+ ...config,
73
+ beforeSendSpan: scrubSpan,
74
+ defaultIntegrations: false,
75
+ integrations: [browserTracingIntegration()],
76
+ });
77
+ }
@@ -15,6 +15,7 @@ import type {
15
15
  ConversationSummaryReport,
16
16
  ConversationTurnFailureCode,
17
17
  ConversationTurnFailureReason,
18
+ ReviewItemChangeRecord,
18
19
  } from "@sentry/junior/api/schema";
19
20
  import type { ConversationDetailReport } from "@sentry/junior/api/schema";
20
21
  import type { ConversationEventPresentation } from "@sentry/junior-plugin-api";
@@ -90,6 +91,8 @@ export type TranscriptViewStructuredEventPart = {
90
91
  name: string;
91
92
  namespace: string;
92
93
  presentation: ConversationEventPresentation;
94
+ /** Turn that emitted the event. */
95
+ turnId?: string;
93
96
  type: "structured_event";
94
97
  version: number;
95
98
  };
@@ -113,6 +116,7 @@ export type TranscriptViewTurnContext = {
113
116
  kind: string;
114
117
  loadedAt: string;
115
118
  pluginName: string;
119
+ turnId: string;
116
120
  version: number;
117
121
  };
118
122
 
@@ -134,6 +138,8 @@ export type TranscriptViewMessage = {
134
138
  events?: ConversationReportMessageEvent[];
135
139
  /** Whether the source message addressed Junior directly. */
136
140
  explicitMention?: boolean;
141
+ /** Person changes to Review items that this message records. */
142
+ reviewItemChanges?: ReviewItemChangeRecord[];
137
143
  /** People mentioned in the event text, resolved by the API. */
138
144
  mentions?: ActorIdentity[];
139
145
  /** Whether a non-mention message was used as input to a turn. */
package/src/client.tsx CHANGED
@@ -7,6 +7,7 @@ import { Toaster } from "./client/components/ui/toast";
7
7
  import { TooltipProvider } from "./client/components/ui/tooltip";
8
8
  import { DashboardShell } from "./client/App";
9
9
  import { getDashboardAgentName } from "./client/agentName";
10
+ import { initDashboardSentry } from "./client/sentry";
10
11
 
11
12
  declare global {
12
13
  interface Window {
@@ -66,6 +67,8 @@ function DashboardErrorPanel(props: { error: Error }) {
66
67
  );
67
68
  }
68
69
 
70
+ initDashboardSentry();
71
+
69
72
  const root = document.getElementById("dashboard-root");
70
73
  if (!root) {
71
74
  throw new Error("Junior dashboard root element was not found");
@@ -43,6 +43,7 @@ export function readMockConversationWatches(
43
43
  label: "getsentry/junior#2383",
44
44
  namespace: "github",
45
45
  resourceType: "pull_request",
46
+ url: "https://github.com/getsentry/junior/pull/2383",
46
47
  },
47
48
  {
48
49
  createdAt: iso(-2 * HOUR_MS),
@@ -79,6 +80,7 @@ export function readMockConversationWatches(
79
80
  label: "getsentry/junior#2351",
80
81
  namespace: "github",
81
82
  resourceType: "pull_request",
83
+ url: "https://github.com/getsentry/junior/pull/2351",
82
84
  },
83
85
  {
84
86
  createdAt: iso(-10 * 60_000),
package/src/shell.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, readFileSync } from "node:fs";
2
2
  import path from "node:path";
3
+ import type { BrowserSentryConfig } from "@sentry/junior/instrumentation";
3
4
  import {
4
5
  dashboardAvatarHeaderAsset,
5
6
  dashboardFaviconAsset,
@@ -210,9 +211,32 @@ export function renderInstallIcon(): Response {
210
211
  });
211
212
  }
212
213
 
214
+ function scriptJson(value: unknown): string {
215
+ return JSON.stringify(value).replace(/</g, "\\u003c");
216
+ }
217
+
218
+ // The browser SDK reads these meta tags to continue the trace of the request
219
+ // that served this page, so its pageload span joins the server spans.
220
+ function renderSentryHead(sentry: BrowserSentryConfig | undefined): string {
221
+ if (!sentry) return "";
222
+ const { baggage, sentryTrace, ...options } = sentry;
223
+ return [
224
+ sentryTrace &&
225
+ `<meta name="sentry-trace" content="${escapeHtml(sentryTrace)}" />`,
226
+ baggage && `<meta name="baggage" content="${escapeHtml(baggage)}" />`,
227
+ `<script>window.__JUNIOR_DASHBOARD_SENTRY__ = ${scriptJson(options)};</script>`,
228
+ ]
229
+ .filter(Boolean)
230
+ .join("\n ");
231
+ }
232
+
213
233
  /** Render the authenticated dashboard HTML shell. */
214
- export function renderDashboard(basePath: string, agentName: string): Response {
215
- const encodedAgentName = JSON.stringify(agentName).replace(/</g, "\\u003c");
234
+ export function renderDashboard(
235
+ basePath: string,
236
+ agentName: string,
237
+ sentry?: BrowserSentryConfig,
238
+ ): Response {
239
+ const encodedAgentName = scriptJson(agentName);
216
240
  return new Response(
217
241
  `<!DOCTYPE html>
218
242
  <html lang="en">
@@ -228,6 +252,7 @@ export function renderDashboard(basePath: string, agentName: string): Response {
228
252
  <link rel="manifest" href="${DASHBOARD_MANIFEST_PATH}" />
229
253
  <link rel="apple-touch-icon" href="${DASHBOARD_INSTALL_ICON_PATH}" />
230
254
  <title>${escapeHtml(agentName)}</title>
255
+ ${renderSentryHead(sentry)}
231
256
  <style>
232
257
  ${readDashboardTailwind()}
233
258
  </style>
package/src/tailwind.css CHANGED
@@ -342,30 +342,19 @@
342
342
  }
343
343
  }
344
344
 
345
- @keyframes junior-active-indicator {
346
- 0%,
347
- 100% {
348
- box-shadow:
349
- 0 0 0 0 rgba(110, 231, 183, 0),
350
- 0 0 8px rgba(110, 231, 183, 0.35);
351
- }
352
-
353
- 50% {
354
- box-shadow:
355
- 0 0 0 4px rgba(110, 231, 183, 0.18),
356
- 0 0 14px rgba(110, 231, 183, 0.65);
357
- }
358
- }
359
-
360
345
  @media (max-width: 767px) {
361
346
  /* Keep long mobile feeds cheap while preserving their full scroll range. */
362
347
  .mobile-conversation-row {
363
348
  content-visibility: auto;
364
349
  contain-intrinsic-size: auto 3.5rem;
365
350
  }
351
+ }
366
352
 
367
- .mobile-transcript-row {
368
- content-visibility: auto;
369
- contain-intrinsic-size: auto 12rem;
370
- }
353
+ /* The Quick question selection. Utilities cannot style a highlight. */
354
+ ::highlight(quick-question) {
355
+ background-color: color-mix(
356
+ in oklab,
357
+ var(--color-dashboard-accent) 30%,
358
+ transparent
359
+ );
371
360
  }
@@ -1,14 +0,0 @@
1
- import { cn } from "../styles";
2
-
3
- /** Render the animated dot used to show active work. */
4
- export function ActiveIndicator(props: { className?: string }) {
5
- return (
6
- <span
7
- aria-hidden="true"
8
- className={cn(
9
- "shrink-0 rounded-full bg-emerald-300 shadow-[0_0_10px_rgba(110,231,183,0.55)] animate-[junior-active-indicator_1.8s_ease-in-out_infinite] motion-reduce:animate-none",
10
- props.className,
11
- )}
12
- />
13
- );
14
- }