@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.
- package/dist/{adapter-JQZaJ-B_.js → adapter-Cikcqdty.js} +1 -1
- package/dist/{admin-Dm2bimJ-.js → admin-BcSxHuTB.js} +2 -1
- package/dist/{agent-runner-DGCwOEyL.js → agent-runner-9MXyWUL8.js} +784 -368
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +9 -8
- package/dist/api.d.ts +1 -1
- package/dist/api.js +411 -65
- package/dist/{app-BKq0JzWx.d.ts → app-BUklJVBe.d.ts} +4 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +555 -71
- package/dist/{assistant-reply-CAPafcUY.js → assistant-reply-mj47jMRV.js} +1 -1
- package/dist/{automation-B-jJN_gM.js → automation-DDXwHQs5.js} +4 -7
- package/dist/{background-compaction-queue-Btu2oab_.js → background-compaction-queue-CjllSPir.js} +161 -90
- package/dist/{briefs-UMeYehUe.js → briefs-DW9iuolG.js} +7 -5
- package/dist/{catalog-runtime-Bym8GVdh.js → catalog-runtime-B3gfH58M.js} +1 -1
- package/dist/cli/chat.js +14 -14
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/config-CLJcyYEF.js +1762 -0
- package/dist/{connections-CQ7p0aNJ.js → connections-BtdJftow.js} +9 -9
- package/dist/{conversation-BusI2uzj.js → conversation-DhoqHtQ7.js} +30 -6
- package/dist/{conversation-pending-messages-DwehU0Fd.js → conversation-pending-messages-DHV0S4uF.js} +2 -5
- package/dist/{conversation-privacy-Cd_nZZBM.js → conversation-privacy-BPirIVlX.js} +1 -1
- package/dist/core-model-BTt5E5b0.js +182 -0
- package/dist/{credential-sync-DmiJi_At.js → credential-sync-Co8Q2xRW.js} +28 -20
- package/dist/{viewer-CH-ASQzh.js → db-Co7DTYYh.js} +62 -358
- package/dist/{db-C5zi4ecs.d.ts → db-zIs8-Ba3.d.ts} +6 -2
- package/dist/{executor-Dipi2Ixl.js → executor-m0kIN71Q.js} +102 -14
- package/dist/{media-B-BpXo41.js → history-IjdmO_r6.js} +8 -88
- package/dist/instrumentation.js +2 -2
- package/dist/{logging-CMFhLLj4.js → logging-DbD-dErY.js} +3 -2
- package/dist/media-BAHvgkok.js +85 -0
- package/dist/{message-D1xLljUF.js → message-DKTdTYm-.js} +10 -10
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +19 -41
- package/dist/{oauth-callback-server-DCAFIUQr.js → oauth-callback-server-CpbepSbp.js} +2 -2
- package/dist/{projection-CoeMNxJ4.js → projection-BViECfYu.js} +361 -746
- package/dist/{prompt-C9OQEfan.js → prompt-KT6MaDHN.js} +1 -1
- package/dist/{registry-u-sFYtx_.js → registry-D-Acyjhh.js} +1 -1
- package/dist/{reporting-window-B4TwyuJo.js → reporting-window-B3Ze-Qnt.js} +4 -1
- package/dist/{resolve-DYqgL3Eo.js → resolve-gkT2R66z.js} +3 -3
- package/dist/{result-CescSwAw.js → result-DHmCFEt8.js} +8 -8
- package/dist/{runner-Cr67a8TB.js → runner-DBKjGjH-.js} +8 -8
- package/dist/{sandbox-egress-signals-DLOazy5W.js → sandbox-egress-signals-9n8hqx29.js} +1 -1
- package/dist/{schedule-BTp__wrw.js → schedule-cP0AACm1.js} +11 -2
- package/dist/{schema-Ih60j59-.d.ts → schema-B_6aOcx5.d.ts} +159 -3
- package/dist/{schema-BUSi3sgv.js → schema-DxicIQbc.js} +79 -14
- package/dist/{service-account-CsKxktLk.js → service-account-Bi0HsY6w.js} +3 -3
- package/dist/{service-account-CGEqz9wG.js → service-account-CDlC9ssy.js} +3 -3
- package/dist/{session-stop-CGz5DByb.js → session-stop-BWOsuo8p.js} +62 -20
- package/dist/{skills-COCqf61f.js → skills-DO5K68Rq.js} +2 -2
- package/dist/spawn-BBqZDcPa.js +79 -0
- package/dist/{stop-GyFZkHuQ.js → stop-WC97cmHz.js} +832 -552
- package/dist/{store-D0-8plWp.js → store-ByR1Lr7e.js} +4 -16
- package/dist/{task-runner-xPuQmEot.js → task-runner-B-Ewf8TX.js} +30 -21
- package/dist/{turn-failure-response-BOviBdT-.js → turn-failure-response-CpdPoZSl.js} +25 -11
- package/dist/{validation-DZDKorGz.js → validation-B4sbIoES.js} +1 -1
- package/dist/{version-BTIz7fGi.js → version-D6lpuAgL.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/viewer-CeP27tC3.js +337 -0
- package/dist/warmup-P_GJCL1c.js +767 -0
- package/dist/{work-C75_IM5e.js → work-DI7x1Slm.js} +32 -20
- package/dist/{worker-Dl47I729.js → worker-CYPTOT4j.js} +6 -7
- package/migrations/0088_conversation_unsubscribe.sql +1 -0
- package/migrations/0089_conversation_paused_status.sql +3 -0
- package/migrations/0090_guardian_review_time_index.sql +20 -0
- package/migrations/meta/0088_snapshot.json +4372 -0
- package/migrations/meta/0089_snapshot.json +4372 -0
- package/migrations/meta/0090_snapshot.json +4388 -0
- package/migrations/meta/_journal.json +21 -0
- package/package.json +5 -4
- package/dist/client-B0aAs7wC.js +0 -793
- package/dist/config-B9f9Lqo5.js +0 -579
- package/dist/spawn-C8F_iXWO.js +0 -42
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as botConfig } from "./config-
|
|
3
|
-
import {
|
|
4
|
-
import { u as hasRequiredOAuthScope } from "./registry-
|
|
5
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
6
|
-
import { c as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { mt as resolveTurnSessionRouting } from "./task-runner-
|
|
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 {
|
|
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:
|
|
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
|
-
/**
|
|
372
|
-
|
|
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 {
|
|
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 };
|
package/dist/{conversation-pending-messages-DwehU0Fd.js → conversation-pending-messages-DHV0S4uF.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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 };
|
|
@@ -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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
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-
|
|
9
|
-
import { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
10
|
-
import { t as discoverSkills } from "./skills-
|
|
11
|
-
import {
|
|
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 {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
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
|
|
110
|
+
async function readMcpAuthorizationAttempt(authSession, provider) {
|
|
106
111
|
const conversationId = mcpConversationId(authSession);
|
|
107
|
-
if (!conversationId) return
|
|
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
|
-
|
|
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
|
|
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 (
|
|
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
|
-
|
|
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) {
|