@sentry/junior 0.286.0 → 0.288.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 (78) hide show
  1. package/dist/{adapter-JQZaJ-B_.js → adapter-Cikcqdty.js} +1 -1
  2. package/dist/{admin-Dm2bimJ-.js → admin-BcSxHuTB.js} +2 -1
  3. package/dist/{agent-runner-DGCwOEyL.js → agent-runner-9MXyWUL8.js} +784 -368
  4. package/dist/api/schema.d.ts +2 -2
  5. package/dist/api/schema.js +9 -8
  6. package/dist/api.d.ts +1 -1
  7. package/dist/api.js +411 -65
  8. package/dist/{app-BKq0JzWx.d.ts → app-BUklJVBe.d.ts} +4 -2
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +555 -71
  11. package/dist/{assistant-reply-CAPafcUY.js → assistant-reply-mj47jMRV.js} +1 -1
  12. package/dist/{automation-B-jJN_gM.js → automation-DDXwHQs5.js} +4 -7
  13. package/dist/{background-compaction-queue-Btu2oab_.js → background-compaction-queue-CjllSPir.js} +161 -90
  14. package/dist/{briefs-UMeYehUe.js → briefs-DW9iuolG.js} +7 -5
  15. package/dist/{catalog-runtime-Bym8GVdh.js → catalog-runtime-B3gfH58M.js} +1 -1
  16. package/dist/cli/chat.js +14 -14
  17. package/dist/cli/check.js +3 -3
  18. package/dist/cli/main.js +3 -3
  19. package/dist/cli/plugins.js +4 -4
  20. package/dist/cli/snapshot-create.js +4 -4
  21. package/dist/cli/upgrade.d.ts +1 -1
  22. package/dist/cli/upgrade.js +3 -3
  23. package/dist/config-CLJcyYEF.js +1762 -0
  24. package/dist/{connections-CQ7p0aNJ.js → connections-BtdJftow.js} +9 -9
  25. package/dist/{conversation-BusI2uzj.js → conversation-DhoqHtQ7.js} +30 -6
  26. package/dist/{conversation-pending-messages-DwehU0Fd.js → conversation-pending-messages-DHV0S4uF.js} +2 -5
  27. package/dist/{conversation-privacy-Cd_nZZBM.js → conversation-privacy-BPirIVlX.js} +1 -1
  28. package/dist/core-model-BTt5E5b0.js +182 -0
  29. package/dist/{credential-sync-DmiJi_At.js → credential-sync-Co8Q2xRW.js} +28 -20
  30. package/dist/{viewer-CH-ASQzh.js → db-Co7DTYYh.js} +62 -358
  31. package/dist/{db-C5zi4ecs.d.ts → db-zIs8-Ba3.d.ts} +6 -2
  32. package/dist/{executor-Dipi2Ixl.js → executor-m0kIN71Q.js} +102 -14
  33. package/dist/{media-B-BpXo41.js → history-IjdmO_r6.js} +8 -88
  34. package/dist/instrumentation.js +2 -2
  35. package/dist/{logging-CMFhLLj4.js → logging-DbD-dErY.js} +3 -2
  36. package/dist/media-BAHvgkok.js +85 -0
  37. package/dist/{message-D1xLljUF.js → message-DKTdTYm-.js} +10 -10
  38. package/dist/nitro.d.ts +1 -1
  39. package/dist/nitro.js +19 -41
  40. package/dist/{oauth-callback-server-DCAFIUQr.js → oauth-callback-server-CpbepSbp.js} +2 -2
  41. package/dist/{projection-CoeMNxJ4.js → projection-BViECfYu.js} +361 -746
  42. package/dist/{prompt-C9OQEfan.js → prompt-KT6MaDHN.js} +1 -1
  43. package/dist/{registry-u-sFYtx_.js → registry-D-Acyjhh.js} +1 -1
  44. package/dist/{reporting-window-B4TwyuJo.js → reporting-window-B3Ze-Qnt.js} +4 -1
  45. package/dist/{resolve-DYqgL3Eo.js → resolve-gkT2R66z.js} +3 -3
  46. package/dist/{result-CescSwAw.js → result-DHmCFEt8.js} +8 -8
  47. package/dist/{runner-Cr67a8TB.js → runner-DBKjGjH-.js} +8 -8
  48. package/dist/{sandbox-egress-signals-DLOazy5W.js → sandbox-egress-signals-9n8hqx29.js} +1 -1
  49. package/dist/{schedule-BTp__wrw.js → schedule-cP0AACm1.js} +11 -2
  50. package/dist/{schema-Ih60j59-.d.ts → schema-B_6aOcx5.d.ts} +159 -3
  51. package/dist/{schema-BUSi3sgv.js → schema-DxicIQbc.js} +79 -14
  52. package/dist/{service-account-CsKxktLk.js → service-account-Bi0HsY6w.js} +3 -3
  53. package/dist/{service-account-CGEqz9wG.js → service-account-CDlC9ssy.js} +3 -3
  54. package/dist/{session-stop-CGz5DByb.js → session-stop-BWOsuo8p.js} +62 -20
  55. package/dist/{skills-COCqf61f.js → skills-DO5K68Rq.js} +2 -2
  56. package/dist/spawn-BBqZDcPa.js +79 -0
  57. package/dist/{stop-GyFZkHuQ.js → stop-WC97cmHz.js} +832 -552
  58. package/dist/{store-D0-8plWp.js → store-ByR1Lr7e.js} +4 -16
  59. package/dist/{task-runner-xPuQmEot.js → task-runner-B-Ewf8TX.js} +30 -21
  60. package/dist/{turn-failure-response-BOviBdT-.js → turn-failure-response-CpdPoZSl.js} +25 -11
  61. package/dist/{validation-DZDKorGz.js → validation-B4sbIoES.js} +1 -1
  62. package/dist/{version-BTIz7fGi.js → version-D6lpuAgL.js} +1 -1
  63. package/dist/version.js +1 -1
  64. package/dist/viewer-CeP27tC3.js +337 -0
  65. package/dist/warmup-P_GJCL1c.js +767 -0
  66. package/dist/{work-C75_IM5e.js → work-DI7x1Slm.js} +32 -20
  67. package/dist/{worker-Dl47I729.js → worker-CYPTOT4j.js} +6 -7
  68. package/migrations/0088_conversation_unsubscribe.sql +1 -0
  69. package/migrations/0089_conversation_paused_status.sql +3 -0
  70. package/migrations/0090_guardian_review_time_index.sql +20 -0
  71. package/migrations/meta/0088_snapshot.json +4372 -0
  72. package/migrations/meta/0089_snapshot.json +4372 -0
  73. package/migrations/meta/0090_snapshot.json +4388 -0
  74. package/migrations/meta/_journal.json +21 -0
  75. package/package.json +5 -4
  76. package/dist/client-B0aAs7wC.js +0 -793
  77. package/dist/config-B9f9Lqo5.js +0 -579
  78. package/dist/spawn-C8F_iXWO.js +0 -42
@@ -1,12 +1,12 @@
1
- import { Ri as startOAuthFlow, Z as loadTurnCheckpoint, it as getTurnRecord, rt as failTurnRecord } from "./projection-CoeMNxJ4.js";
2
- import { n as botConfig } from "./config-B9f9Lqo5.js";
3
- import { C as getSqlExecutor, G as deleteProviderIdentityForUser, W as deleteProviderIdentityForSlackUser, x as getConversationStore, y as getConversationEventStore } from "./viewer-CH-ASQzh.js";
4
- import { u as hasRequiredOAuthScope } from "./registry-u-sFYtx_.js";
5
- import { n as pluginCatalogRuntime } from "./catalog-runtime-Bym8GVdh.js";
6
- import { c as deleteMcpAuthSessionsForUserProvider, l as deleteMcpServerSessionId, u as deleteMcpStoredOAuthCredentials } from "./agent-runner-DGCwOEyL.js";
7
- import { _ as getVercelConversationWorkQueue } from "./background-compaction-queue-Btu2oab_.js";
8
- import { T as requestConversationWork, h as ensureConversationWake } from "./store-D0-8plWp.js";
9
- import { mt as resolveTurnSessionRouting } from "./task-runner-xPuQmEot.js";
1
+ import { Mi as startOAuthFlow, et as loadTurnCheckpoint, ot as failTurnRecord, st as getTurnRecord } from "./projection-BViECfYu.js";
2
+ import { n as botConfig } from "./config-CLJcyYEF.js";
3
+ import { A as deleteProviderIdentityForUser, a as getConversationStore, k as deleteProviderIdentityForSlackUser, r as getConversationEventStore, s as getSqlExecutor } from "./db-Co7DTYYh.js";
4
+ import { u as hasRequiredOAuthScope } from "./registry-D-Acyjhh.js";
5
+ import { n as pluginCatalogRuntime } from "./catalog-runtime-B3gfH58M.js";
6
+ import { c as deleteMcpServerSessionId, l as deleteMcpStoredOAuthCredentials, s as deleteMcpAuthSessionsForUserProvider } from "./agent-runner-9MXyWUL8.js";
7
+ import { g as getVercelConversationWorkQueue } from "./background-compaction-queue-CjllSPir.js";
8
+ import { S as requestConversationWork, m as ensureConversationWake } from "./store-ByR1Lr7e.js";
9
+ import { mt as resolveTurnSessionRouting } from "./task-runner-B-Ewf8TX.js";
10
10
  import { randomBytes } from "node:crypto";
11
11
  import * as z from "zod";
12
12
  // src/chat/task-execution/authorized-turn.ts
@@ -1,4 +1,5 @@
1
- import { c as conversationTurnFailureCodeSchema, l as conversationTurnFailureReasonSchema, n as INPUT_IMAGE_TYPES, y as usageSchema } from "./media-B-BpXo41.js";
1
+ import { a as conversationTurnFailureReasonSchema, h as usageSchema, i as conversationTurnFailureCodeSchema } from "./history-IjdmO_r6.js";
2
+ import { n as INPUT_IMAGE_TYPES } from "./media-BAHvgkok.js";
2
3
  import * as z from "zod";
3
4
  import { codeChangeStateSchema, conversationAnnotationInputSchema, conversationEventPresentationSchema, conversationSidebarAnnotationSchema, objectFactFields, objectTypeSchema } from "@sentry/junior-plugin-api";
4
5
  // src/chat/briefs/schema.ts
@@ -135,11 +136,15 @@ function parseBriefInput(input) {
135
136
  /** Bound JSON image input below the hosting platform's request size limit. */
136
137
  const MAX_INPUT_IMAGE_BYTES = 3145728;
137
138
  const MAX_INPUT_IMAGES = 3;
139
+ /** Base64 file bytes in a JSON request body, up to `maxBytes` once decoded. */
140
+ function base64DataSchema(maxBytes) {
141
+ return z.string().min(4).max(maxBytes * 4 / 3).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine((data) => data.length % 4 === 0);
142
+ }
138
143
  /** Image bytes accepted with a web message, never stored in its mailbox row. */
139
144
  const inputImageSchema = z.object({
140
145
  filename: z.string().trim().min(1).max(255),
141
146
  contentType: z.enum(INPUT_IMAGE_TYPES),
142
- data: z.string().min(4).max(MAX_INPUT_IMAGE_BYTES * 4 / 3).regex(/^[A-Za-z0-9+/]*={0,2}$/).refine((data) => data.length % 4 === 0)
147
+ data: base64DataSchema(MAX_INPUT_IMAGE_BYTES)
143
148
  }).strict();
144
149
  /** Safe attachment facts shared by mailbox input and transcript messages. */
145
150
  const messageAttachmentSchema = z.object({
@@ -274,6 +279,15 @@ const conversationReadPositionSchema = z.object({ lastReadSeq: z.number().int().
274
279
  * flag from this, so it does not refetch the feed after each report.
275
280
  */
276
281
  const conversationReadReportSchema = conversationReadPositionSchema.extend({ unreadReply: z.boolean() }).strict();
282
+ // src/api/schema/conversation-title.ts
283
+ /** Longest Conversation title that a rename can save. */
284
+ const CONVERSATION_TITLE_MAX_LENGTH = 200;
285
+ /** A Conversation title that a caller chooses, at creation or on rename. */
286
+ const conversationTitleSchema = z.string().trim().min(1).max(200);
287
+ /** A participant's new title for one Conversation. Every viewer sees it. */
288
+ const renameConversationBodySchema = z.object({ title: conversationTitleSchema }).strict();
289
+ /** The stored title after the rename. */
290
+ const renameConversationResponseSchema = z.object({ title: z.string().min(1) }).strict();
277
291
  // src/api/schema/child-agent-totals.ts
278
292
  /**
279
293
  * The part of a Conversation total that its child agents spent, at any depth.
@@ -367,9 +381,12 @@ const createConversationMessageBodySchema = z.object({
367
381
  message: z.string().trim().max(32e3),
368
382
  images: z.array(inputImageSchema).max(3).optional()
369
383
  }).strict().refine((body) => Boolean(body.message || body.images?.length), "Add a message or an image.").refine((body) => (body.images ?? []).reduce((sum, image) => sum + image.data.length, 0) <= MAX_INPUT_IMAGE_BYTES * 4 / 3, "Images must total 3 MB or less.");
370
- const createConversationBodySchema = createConversationMessageBodySchema.safeExtend({
371
- /** New roots default public. Private roots stay participant-only. */
372
- visibility: z.enum(["private", "public"]).optional() });
384
+ const createConversationBodySchema = createConversationMessageBodySchema.safeExtend({
385
+ /** Saved title. Title generation runs only when it is omitted. */
386
+ title: conversationTitleSchema.optional(),
387
+ /** New roots default public. Private roots stay participant-only. */
388
+ visibility: z.enum(["private", "public"]).optional()
389
+ });
373
390
  const acceptedConversationMessageSchema = z.object({
374
391
  conversationId: z.string().min(1),
375
392
  messageId: z.string().min(1),
@@ -696,6 +713,8 @@ const conversationReportSubagentEventDataSchema = z.object({
696
713
  startedSeq: z.number().int().nonnegative(),
697
714
  startedAt: z.string().datetime(),
698
715
  childConversationId: z.string().min(1),
716
+ /** The child's Conversation kind. Only a Thread has its own page link. */
717
+ childKind: z.enum(["thread", "task"]),
699
718
  subagentKind: z.string().min(1),
700
719
  agentName: z.string().min(1).optional(),
701
720
  task: z.string().min(1).optional(),
@@ -877,6 +896,11 @@ const conversationDetailReportSchema = conversationSummaryReportSchema.extend({
877
896
  canFork: z.boolean().optional(),
878
897
  /** The viewer can move this dashboard conversation to a Slack thread. */
879
898
  canContinueInSlack: z.literal(true).optional(),
899
+ /**
900
+ * The viewer gets this conversation in their active feed. Participants
901
+ * only. False after an unsubscribe, until they mention Junior again.
902
+ */
903
+ subscribed: z.boolean().optional(),
880
904
  /** How far the signed-in viewer has read. Absent until they read. */
881
905
  readPosition: conversationReadPositionSchema.optional(),
882
906
  /**
@@ -935,4 +959,4 @@ const conversationFeedSchema = z.object({
935
959
  source: z.literal("conversation_index"),
936
960
  generatedAt: z.string()
937
961
  }).strict();
938
- export { reviewItemChangeRecordSchema as A, readMessageAttachments as B, createConversationBodySchema as C, conversationChildAgentTotalsSchema as D, forkConversationResponseSchema as E, removedCardSchema as F, conversationBriefSchema as G, briefLinkSchema as H, resolveMessageCards as I, parseBriefInput as K, MAX_INPUT_IMAGES as L, messageCardRef as M, messageCardText as N, conversationReadPositionSchema as O, readMessageCardRefs as P, MAX_INPUT_IMAGE_BYTES as R, conversationUsageSchema as S, forkConversationBodySchema as T, briefOutcomeStatusSchema as U, briefCodeChangeSchema as V, briefResourceLabel as W, conversationReportEventSchema as _, conversationActivityPreviewSchema as a, conversationSummaryReportSchema as b, conversationDetailQuerySchema as c, conversationEventPageSchema as d, conversationEventsQuerySchema as f, conversationReportEventDataSchema as g, conversationParamsSchema as h, actorIdentitySchema as i, annotationCard as j, conversationReadReportSchema as k, conversationDetailReportSchema as l, conversationFeedSchema as m, CONVERSATION_VERSION_HEADER as n, conversationAttachmentParamsSchema as o, conversationFeedQuerySchema as p, parseStoredBrief as q, acceptedConversationMessageSchema as r, conversationAuxiliaryCostsSchema as s, CONVERSATION_DETAIL_VERSION_HEADER as t, conversationEventHistorySchema as u, conversationReportMessageEventSchema as v, createConversationMessageBodySchema as w, conversationSurfaceSchema as x, conversationReportStatusSchema as y, messageAttachmentSchema as z };
962
+ export { renameConversationBodySchema as A, resolveMessageCards as B, createConversationBodySchema as C, conversationChildAgentTotalsSchema as D, forkConversationResponseSchema as E, annotationCard as F, readMessageAttachments as G, MAX_INPUT_IMAGE_BYTES as H, messageCardRef as I, briefOutcomeStatusSchema as J, briefCodeChangeSchema as K, messageCardText as L, conversationReadPositionSchema as M, conversationReadReportSchema as N, CONVERSATION_TITLE_MAX_LENGTH as O, reviewItemChangeRecordSchema as P, parseStoredBrief as Q, readMessageCardRefs as R, conversationUsageSchema as S, forkConversationBodySchema as T, base64DataSchema as U, MAX_INPUT_IMAGES as V, messageAttachmentSchema as W, conversationBriefSchema as X, briefResourceLabel as Y, parseBriefInput as Z, conversationReportEventSchema as _, conversationActivityPreviewSchema as a, conversationSummaryReportSchema as b, conversationDetailQuerySchema as c, conversationEventPageSchema as d, conversationEventsQuerySchema as f, conversationReportEventDataSchema as g, conversationParamsSchema as h, actorIdentitySchema as i, renameConversationResponseSchema as j, conversationTitleSchema as k, conversationDetailReportSchema as l, conversationFeedSchema as m, CONVERSATION_VERSION_HEADER as n, conversationAttachmentParamsSchema as o, conversationFeedQuerySchema as p, briefLinkSchema as q, acceptedConversationMessageSchema as r, conversationAuxiliaryCostsSchema as s, CONVERSATION_DETAIL_VERSION_HEADER as t, conversationEventHistorySchema as u, conversationReportMessageEventSchema as v, createConversationMessageBodySchema as w, conversationSurfaceSchema as x, conversationReportStatusSchema as y, removedCardSchema as z };
@@ -1,4 +1,4 @@
1
- import { A as reviewItemChangeRecordSchema, i as actorIdentitySchema, l as conversationDetailReportSchema, z as messageAttachmentSchema } from "./conversation-BusI2uzj.js";
1
+ import { P as reviewItemChangeRecordSchema, W as messageAttachmentSchema, i as actorIdentitySchema, l as conversationDetailReportSchema } from "./conversation-DhoqHtQ7.js";
2
2
  import * as z from "zod";
3
3
  // src/reporting-schema.ts
4
4
  const healthReportSchema = z.object({
@@ -102,9 +102,6 @@ const pluginOperationalReportFeedSchema = z.object({
102
102
  reports: z.array(pluginOperationalReportSchema),
103
103
  source: z.literal("plugins")
104
104
  }).strict();
105
- // src/api/schema/common.ts
106
- /** Stable error body returned by Junior-owned REST endpoints. */
107
- const apiErrorSchema = z.object({ error: z.string().min(1) }).strict();
108
105
  // src/api/schema/conversation-pending-messages.ts
109
106
  /** Mailbox delivery mode for one accepted inbound message. */
110
107
  const conversationPendingMessageDeliverySchema = z.enum(["defer", "interrupt"]);
@@ -178,4 +175,4 @@ const steerConversationPendingMessagesResponseSchema = z.object({
178
175
  conversationId: z.string().min(1),
179
176
  steeredInboundMessageIds: z.array(z.string().min(1))
180
177
  }).strict();
181
- export { pluginSchema as _, conversationPendingMessageDeliverySchema as a, skillReportSchema as b, conversationUnchangedDetailWithMailboxSchema as c, apiErrorSchema as d, healthReportSchema as f, pluginPackageContentReportSchema as g, pluginPackageContentItemReportSchema as h, conversationPendingAuthorizationSchema as i, steerConversationPendingMessagesBodySchema as l, pluginOperationalReportSchema as m, cancelConversationPendingMessagesResponseSchema as n, conversationPendingMessageSchema as o, pluginOperationalReportFeedSchema as p, conversationDetailWithMailboxReportSchema as r, conversationPendingMessagesReportSchema as s, cancelConversationPendingMessagesBodySchema as t, steerConversationPendingMessagesResponseSchema as u, pluginsSchema as v, skillReportsSchema as x, runtimeInfoReportSchema as y };
178
+ export { pluginsSchema as _, conversationPendingMessageDeliverySchema as a, skillReportsSchema as b, conversationUnchangedDetailWithMailboxSchema as c, healthReportSchema as d, pluginOperationalReportFeedSchema as f, pluginSchema as g, pluginPackageContentReportSchema as h, conversationPendingAuthorizationSchema as i, steerConversationPendingMessagesBodySchema as l, pluginPackageContentItemReportSchema as m, cancelConversationPendingMessagesResponseSchema as n, conversationPendingMessageSchema as o, pluginOperationalReportSchema as p, conversationDetailWithMailboxReportSchema as r, conversationPendingMessagesReportSchema as s, cancelConversationPendingMessagesBodySchema as t, steerConversationPendingMessagesResponseSchema as u, runtimeInfoReportSchema as v, skillReportSchema as y };
@@ -1,4 +1,4 @@
1
- import { h as logWarn } from "./logging-CMFhLLj4.js";
1
+ import { h as logWarn } from "./logging-DbD-dErY.js";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  // src/chat/conversation-privacy.ts
4
4
  const SAFE_METADATA_KEY_LIMIT = 20;
@@ -0,0 +1,182 @@
1
+ import { C as completeText$1, S as completeObject$1, x as completeDecision$1 } from "./config-CLJcyYEF.js";
2
+ import { _ as runBestEffort, a as extractGenAiUsageSummary } from "./logging-DbD-dErY.js";
3
+ import { W as agentTurnCostUsd, r as getConversationEventStore } from "./db-Co7DTYYh.js";
4
+ import * as z from "zod";
5
+ import { conversationEventPresentationSchema, defineConversationEvent } from "@sentry/junior-plugin-api";
6
+ // src/chat/conversations/structured-events.ts
7
+ /** Reserved namespace for Junior-owned conversation metadata events. */
8
+ const JUNIOR_NATIVE_EVENT_NAMESPACE = "junior";
9
+ const authenticationEventContentSchema = z.object({
10
+ accountLabel: z.string().trim().min(1).max(120).optional(),
11
+ actorId: z.string().min(1),
12
+ authorizationId: z.string().min(1).optional(),
13
+ provider: z.string().regex(/^[a-z][a-z0-9-]*$/),
14
+ providerLabel: z.string().trim().min(1).max(80).optional()
15
+ }).strict();
16
+ const agentsInstructionsUpdatedContentSchema = z.object({
17
+ action: z.enum([
18
+ "loaded",
19
+ "replaced",
20
+ "cleared"
21
+ ]),
22
+ directory: z.string().trim().min(1).max(500).optional(),
23
+ fingerprint: z.string().trim().min(1).max(128),
24
+ sources: z.array(z.object({
25
+ content: z.string().min(1).max(32768),
26
+ path: z.string().trim().min(1).max(500)
27
+ }).strict()).max(32),
28
+ textBytes: z.number().int().nonnegative().optional()
29
+ }).strict();
30
+ function providerTitle(content) {
31
+ return content.providerLabel?.trim() || content.provider;
32
+ }
33
+ function agentsInstructionsTitle(action) {
34
+ if (action === "loaded") return "Loaded AGENTS.md";
35
+ if (action === "replaced") return "Updated AGENTS.md";
36
+ return "Cleared AGENTS.md";
37
+ }
38
+ function sourceFilename(sourcePath) {
39
+ return sourcePath.split("/").at(-1) || sourcePath;
40
+ }
41
+ function formatBytes(bytes) {
42
+ if (bytes < 1024) return `${bytes} bytes`;
43
+ const kilobytes = bytes / 1024;
44
+ return `${Number.isInteger(kilobytes) ? kilobytes : kilobytes.toFixed(1)} KB`;
45
+ }
46
+ function agentsInstructionsPreview(content) {
47
+ const source = content.sources[0];
48
+ if (!source) return void 0;
49
+ const filename = sourceFilename(source.path);
50
+ const label = content.sources.length === 1 ? filename : `${content.sources.length} AGENTS.md files`;
51
+ return typeof content.textBytes === "number" ? `${label} · ${formatBytes(content.textBytes)}` : label;
52
+ }
53
+ /** Junior-owned account-link transcript event. */
54
+ const authenticationLinkedEvent = defineConversationEvent({
55
+ name: "authentication_linked",
56
+ version: 1,
57
+ schema: authenticationEventContentSchema,
58
+ renderEvent(event) {
59
+ const provider = providerTitle(event);
60
+ return {
61
+ icon: "link",
62
+ title: `${provider} connected`,
63
+ ...event.accountLabel ? { preview: `Connected as \`${event.accountLabel}\`` } : void 0,
64
+ details: [{
65
+ title: `${provider} connected`,
66
+ ...event.accountLabel ? { description: `Connected as \`${event.accountLabel}\`` } : void 0,
67
+ metadata: [event.provider]
68
+ }]
69
+ };
70
+ }
71
+ });
72
+ /** Junior-owned account-unlink transcript event. */
73
+ const authenticationUnlinkedEvent = defineConversationEvent({
74
+ name: "authentication_unlinked",
75
+ version: 1,
76
+ schema: authenticationEventContentSchema,
77
+ renderEvent(event) {
78
+ const provider = providerTitle(event);
79
+ return {
80
+ icon: "key",
81
+ title: `${provider} disconnected`,
82
+ details: [{
83
+ title: `${provider} disconnected`,
84
+ metadata: [event.provider]
85
+ }]
86
+ };
87
+ }
88
+ });
89
+ /** Junior-owned AGENTS.md bootstrap transition for the dashboard timeline. */
90
+ const agentsInstructionsUpdatedEvent = defineConversationEvent({
91
+ name: "agents_instructions_updated",
92
+ version: 1,
93
+ schema: agentsInstructionsUpdatedContentSchema,
94
+ renderEvent(event) {
95
+ const title = agentsInstructionsTitle(event.action);
96
+ const preview = agentsInstructionsPreview(event);
97
+ return {
98
+ icon: "brain",
99
+ title,
100
+ ...preview ? { preview } : void 0,
101
+ ...event.sources.length > 0 ? { details: event.sources.map((source) => ({
102
+ title: sourceFilename(source.path),
103
+ content: source.content
104
+ })) } : void 0
105
+ };
106
+ }
107
+ });
108
+ /** Core-written Conversation note. `notes.ts` owns when the model sees it. */
109
+ const conversationNoteEvent = defineConversationEvent({
110
+ name: "conversation_note",
111
+ version: 1,
112
+ schema: z.object({ text: z.string().trim().min(1).max(500) }).strict(),
113
+ renderEvent(event) {
114
+ return {
115
+ icon: "info",
116
+ title: "Note for the next Turn",
117
+ preview: event.text
118
+ };
119
+ }
120
+ });
121
+ const NATIVE_EVENT_DEFINITIONS = [
122
+ authenticationLinkedEvent,
123
+ authenticationUnlinkedEvent,
124
+ agentsInstructionsUpdatedEvent,
125
+ conversationNoteEvent
126
+ ];
127
+ /** Resolve a registered Junior-native conversation event definition. */
128
+ function getJuniorNativeEventDefinition(args) {
129
+ return NATIVE_EVENT_DEFINITIONS.find((definition) => definition.eventName === args.name && definition.version === args.version);
130
+ }
131
+ /** Render one Junior-native event through its active definition. */
132
+ function renderJuniorNativeConversationEvent(args) {
133
+ if (args.namespace !== "junior") return void 0;
134
+ const definition = getJuniorNativeEventDefinition(args);
135
+ if (!definition) return void 0;
136
+ const presentation = definition.renderEvent(definition.parse(args.content));
137
+ return presentation === void 0 ? void 0 : conversationEventPresentationSchema.parse(presentation);
138
+ }
139
+ // src/chat/core-model.ts
140
+ function gatewayParams(params) {
141
+ const { cost: _cost, operation, ...rest } = params;
142
+ return {
143
+ ...rest,
144
+ promptName: `junior.${operation}`
145
+ };
146
+ }
147
+ async function recordCost(attribution, costUsd) {
148
+ const { cost, operation } = attribution;
149
+ if (costUsd === void 0 || !("conversationId" in cost)) return;
150
+ await runBestEffort(async () => {
151
+ await getConversationEventStore().append(cost.conversationId, [{
152
+ createdAtMs: Date.now(),
153
+ data: {
154
+ type: "structured_event",
155
+ namespace: JUNIOR_NATIVE_EVENT_NAMESPACE,
156
+ name: operation,
157
+ version: 1,
158
+ ...cost.turnId ? { turnId: cost.turnId } : void 0,
159
+ content: { costUsd }
160
+ }
161
+ }], { activity: "preserve" });
162
+ }, "model_cost.record.failed", { "gen_ai.prompt.name": `junior.${operation}` });
163
+ }
164
+ /** Run a text completion and attribute its cost. */
165
+ async function completeText(params) {
166
+ const result = await completeText$1(gatewayParams(params));
167
+ await recordCost(params, agentTurnCostUsd(extractGenAiUsageSummary(result.message)));
168
+ return result;
169
+ }
170
+ /** Run a schema-constrained completion and attribute its cost. */
171
+ async function completeObject(params) {
172
+ const result = await completeObject$1(gatewayParams(params));
173
+ await recordCost(params, result.costUsd);
174
+ return result;
175
+ }
176
+ /** Answer decision questions and attribute the cost. */
177
+ async function completeDecision(params) {
178
+ const result = await completeDecision$1(gatewayParams(params));
179
+ await recordCost(params, result.costUsd);
180
+ return result;
181
+ }
182
+ export { agentsInstructionsUpdatedEvent as a, conversationNoteEvent as c, JUNIOR_NATIVE_EVENT_NAMESPACE as i, renderJuniorNativeConversationEvent as l, completeObject as n, authenticationLinkedEvent as o, completeText as r, authenticationUnlinkedEvent as s, completeDecision as t };
@@ -1,19 +1,19 @@
1
- import { Bn as resolvePluginOAuthAccount, Fi as formatProviderLabel, Ii as parseOAuthStatePayload, In as createUserTokenStore, J as getConversationPendingAuth, Li as resolveBaseUrl, Zi as postSlackMessage, d as recordAuthorizationCompleted, it as getTurnRecord, sa as getSlackClient, u as recordAuthenticationLinked } from "./projection-CoeMNxJ4.js";
2
- import { m as escapeXml } from "./client-B0aAs7wC.js";
3
- import { a as getRuntimeMetadata, n as botConfig } from "./config-B9f9Lqo5.js";
4
- import { H as isNativeIdentityProvider, _ as runBestEffort, h as logWarn, p as logException } from "./logging-CMFhLLj4.js";
1
+ import { Ai as parseOAuthStatePayload, Dn as createUserTokenStore, Gi as postSlackMessage, Q as getConversationPendingAuth, d as recordAuthorizationCompleted, ji as resolveBaseUrl, jn as resolvePluginOAuthAccount, ki as formatProviderLabel, na as getSlackClient, st as getTurnRecord, u as recordAuthenticationLinked } from "./projection-BViECfYu.js";
2
+ import { R as escapeXml, a as getRuntimeMetadata, n as botConfig } from "./config-CLJcyYEF.js";
3
+ import { W as isNativeIdentityProvider, _ as runBestEffort, h as logWarn, p as logException } from "./logging-DbD-dErY.js";
5
4
  import { p as parseSlackUserId } from "./actor-6jsm_v96.js";
6
- import { C as getSqlExecutor, H as resolveActorIdentityId, K as findUserByVerifiedEmails, X as upsertLinkedIdentity, o as readIdentityById } from "./viewer-CH-ASQzh.js";
5
+ import { D as resolveActorIdentityId, F as upsertLinkedIdentity, j as findUserByVerifiedEmails, s as getSqlExecutor } from "./db-Co7DTYYh.js";
7
6
  import { i as homeDir } from "./package-discovery-DJhGdS4c.js";
8
- import { n as buildOAuthTokenRequest, r as parseOAuthTokenResponse, u as hasRequiredOAuthScope } from "./registry-u-sFYtx_.js";
9
- import { n as pluginCatalogRuntime } from "./catalog-runtime-Bym8GVdh.js";
10
- import { t as discoverSkills } from "./skills-COCqf61f.js";
11
- import { Mt as deleteWebAuthorization, d as getMcpAuthSession, f as getMcpStoredOAuthCredentials, o as finalizeMcpAuthorization, p as putMcpStoredOAuthCredentials, s as deleteMcpAuthSession, y as lookupSlackUserProfile } from "./agent-runner-DGCwOEyL.js";
7
+ import { n as buildOAuthTokenRequest, r as parseOAuthTokenResponse, u as hasRequiredOAuthScope } from "./registry-D-Acyjhh.js";
8
+ import { n as pluginCatalogRuntime } from "./catalog-runtime-B3gfH58M.js";
9
+ import { t as discoverSkills } from "./skills-DO5K68Rq.js";
10
+ import { Bt as deleteWebAuthorization, a as finalizeMcpAuthorization, d as getMcpStoredOAuthCredentials, f as putMcpStoredOAuthCredentials, o as deleteMcpAuthSession, u as getMcpAuthSession, y as lookupSlackUserProfile } from "./agent-runner-9MXyWUL8.js";
12
11
  import { r as acquireActiveLock } from "./locks-D-0h111u.js";
13
- import { r as getStateAdapter } from "./adapter-JQZaJ-B_.js";
14
- import { _t as getPersistedThreadState, bt as coerceThreadConversationState } from "./task-runner-xPuQmEot.js";
15
- import { _ as getMcpProviderErrorAttributes } from "./service-account-CGEqz9wG.js";
16
- import { d as wakePausedTurn, i as readConnectedOAuthTokens, s as htmlCallbackResponse, u as wakeAuthorizedTurn } from "./connections-CQ7p0aNJ.js";
12
+ import { o as readIdentityById } from "./viewer-CeP27tC3.js";
13
+ import { r as getStateAdapter } from "./adapter-Cikcqdty.js";
14
+ import { _t as getPersistedThreadState, bt as coerceThreadConversationState } from "./task-runner-B-Ewf8TX.js";
15
+ import { _ as getMcpProviderErrorAttributes } from "./service-account-CDlC9ssy.js";
16
+ import { d as wakePausedTurn, i as readConnectedOAuthTokens, s as htmlCallbackResponse, u as wakeAuthorizedTurn } from "./connections-BtdJftow.js";
17
17
  import { n as relayLocalOAuthCallback } from "./oauth-relay-D6xxVywK.js";
18
18
  import path from "node:path";
19
19
  import { createHmac, createSecretKey, timingSafeEqual } from "node:crypto";
@@ -51,6 +51,11 @@ function callbackPages(botName) {
51
51
  message: `This authorization link is no longer active. Return to ${botName} and retry the original request.`,
52
52
  status: 400
53
53
  },
54
+ connected: {
55
+ title: "Authorization complete",
56
+ message: `Your MCP access is connected. The request that asked for it no longer waits, so ask ${botName} again when you need it.`,
57
+ status: 200
58
+ },
54
59
  success: {
55
60
  title: "Authorization complete",
56
61
  message: `Your MCP access is connected. ${botName} will continue the paused request.`,
@@ -79,7 +84,7 @@ function htmlResponse(kind, options) {
79
84
  ...pages.success,
80
85
  message: `Your MCP access is connected. ${botName} will continue the paused request in the local client.`
81
86
  } : pages[kind];
82
- const footerMessage = kind === "success" && !options?.local ? `You can close this tab and return to ${botName}.` : void 0;
87
+ const footerMessage = (kind === "success" || kind === "connected") && !options?.local ? `You can close this tab and return to ${botName}.` : void 0;
83
88
  return htmlCallbackResponse(page.title, page.message, page.status, { footerMessage });
84
89
  }
85
90
  /** Queue the exact MCP authorization attempt without changing thread state. */
@@ -102,9 +107,9 @@ async function wakeAuthorizedMcpTurn(args) {
102
107
  })
103
108
  }, args.queue);
104
109
  }
105
- async function isCurrentMcpAuthorizationAttempt(authSession, provider) {
110
+ async function readMcpAuthorizationAttempt(authSession, provider) {
106
111
  const conversationId = mcpConversationId(authSession);
107
- if (!conversationId) return false;
112
+ if (!conversationId) return "expired";
108
113
  const currentState = await getPersistedThreadState(conversationId);
109
114
  const conversation = coerceThreadConversationState(currentState);
110
115
  const pendingAuth = getConversationPendingAuth({
@@ -113,13 +118,14 @@ async function isCurrentMcpAuthorizationAttempt(authSession, provider) {
113
118
  provider,
114
119
  actorId: authSession.userId
115
120
  });
116
- return pendingAuth?.authSessionId === authSession.authSessionId && pendingAuth.sessionId === authSession.sessionId;
121
+ if (!pendingAuth) return "ended";
122
+ return pendingAuth.authSessionId === authSession.authSessionId && pendingAuth.sessionId === authSession.sessionId ? "waiting" : "expired";
117
123
  }
118
124
  function mcpConversationId(authSession) {
119
125
  if (authSession.destination?.platform === "local" || authSession.source?.kind === "web") return authSession.conversationId;
120
126
  if (authSession.channelId && authSession.threadTs) return `slack:${authSession.channelId}:${authSession.threadTs}`;
121
127
  }
122
- /** Commit one shared credential mutation only while this attempt owns the thread. */
128
+ /** Commit one shared credential mutation only while no newer attempt replaced this one. */
123
129
  async function runCurrentMcpCredentialMutation(authSession, provider, mutation) {
124
130
  const conversationId = mcpConversationId(authSession);
125
131
  if (!conversationId) throw new McpOAuthAttemptExpiredError();
@@ -128,7 +134,7 @@ async function runCurrentMcpCredentialMutation(authSession, provider, mutation)
128
134
  const lock = await acquireActiveLock(stateAdapter, conversationId);
129
135
  if (!lock) throw new Error(`Could not acquire MCP OAuth callback lock for ${conversationId}`);
130
136
  try {
131
- if (!await isCurrentMcpAuthorizationAttempt(authSession, provider)) throw new McpOAuthAttemptExpiredError();
137
+ if (await readMcpAuthorizationAttempt(authSession, provider) === "expired") throw new McpOAuthAttemptExpiredError();
132
138
  return await mutation();
133
139
  } finally {
134
140
  await stateAdapter.releaseLock(lock);
@@ -167,7 +173,8 @@ async function GET$1(request, provider, waitUntil, options) {
167
173
  if (!code) return htmlResponse("missing_code");
168
174
  try {
169
175
  const pendingSession = await getMcpAuthSession(state);
170
- if (!pendingSession || pendingSession.provider !== provider || !await isCurrentMcpAuthorizationAttempt(pendingSession, provider)) {
176
+ const attempt = pendingSession?.provider === provider ? await readMcpAuthorizationAttempt(pendingSession, provider) : "expired";
177
+ if (!pendingSession || attempt === "expired") {
171
178
  if (pendingSession) await deleteMcpAuthSession(pendingSession.authSessionId);
172
179
  return htmlResponse("expired");
173
180
  }
@@ -227,6 +234,7 @@ async function GET$1(request, provider, waitUntil, options) {
227
234
  queue: options.conversationWorkQueue,
228
235
  provider
229
236
  });
237
+ if (attempt === "ended") return htmlResponse("connected");
230
238
  return htmlResponse("success", { local: authSession.destination?.platform === "local" && authSession.source?.kind !== "web" });
231
239
  } catch (callbackError) {
232
240
  if (callbackError instanceof McpOAuthAttemptExpiredError) {