@sentry/junior 0.146.0 → 0.147.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 (155) hide show
  1. package/dist/{agent-hooks-SLJADYE5.js → agent-hooks-HS6VGUPM.js} +10 -10
  2. package/dist/api/conversations/detail.d.ts +1 -0
  3. package/dist/api/conversations/event-list.d.ts +1 -0
  4. package/dist/api/schema/conversation.d.ts +4 -0
  5. package/dist/api/schema.js +1 -1
  6. package/dist/api.js +26 -22
  7. package/dist/app.js +220 -238
  8. package/dist/{catalog-runtime-RQIMSDPR.js → catalog-runtime-M6ZTPYRV.js} +5 -5
  9. package/dist/chat/agent/prompt.d.ts +0 -2
  10. package/dist/chat/agent/request.d.ts +2 -5
  11. package/dist/chat/agent/sandbox.d.ts +2 -2
  12. package/dist/chat/agent/tools.d.ts +0 -2
  13. package/dist/chat/agent-dispatch/types.d.ts +2 -2
  14. package/dist/chat/capabilities/jr-rpc-command.d.ts +2 -2
  15. package/dist/chat/configuration/service.d.ts +5 -2
  16. package/dist/chat/configuration/sql.d.ts +9 -0
  17. package/dist/chat/configuration/types.d.ts +17 -13
  18. package/dist/chat/conversations/history.d.ts +3 -0
  19. package/dist/chat/conversations/projection.d.ts +10 -0
  20. package/dist/chat/credentials/unlink-provider.d.ts +2 -1
  21. package/dist/chat/credentials/user-token-store.d.ts +2 -0
  22. package/dist/chat/event-tasks/tool-support.d.ts +2 -0
  23. package/dist/chat/identities/sql.d.ts +8 -0
  24. package/dist/chat/logging.d.ts +2 -0
  25. package/dist/chat/mcp/auth-store.d.ts +0 -2
  26. package/dist/chat/mcp/oauth.d.ts +0 -2
  27. package/dist/chat/oauth-flow.d.ts +3 -1
  28. package/dist/chat/pi/client.d.ts +2 -0
  29. package/dist/chat/plugins/credential-hooks.d.ts +2 -0
  30. package/dist/chat/prompt.d.ts +0 -2
  31. package/dist/chat/resource-events/notification.d.ts +2 -1
  32. package/dist/chat/runtime/delivered-turn-state.d.ts +1 -4
  33. package/dist/chat/runtime/thread-state.d.ts +8 -11
  34. package/dist/chat/runtime/turn-input.d.ts +4 -2
  35. package/dist/chat/runtime/turn-preparation.d.ts +2 -4
  36. package/dist/chat/sandbox/command-result.d.ts +2 -0
  37. package/dist/chat/sandbox/egress/schemas.d.ts +6 -0
  38. package/dist/chat/scheduled-tasks/tool-support.d.ts +2 -0
  39. package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -0
  40. package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -0
  41. package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -0
  42. package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -0
  43. package/dist/chat/scheduled-tasks/tools/update.d.ts +2 -0
  44. package/dist/chat/services/mcp-auth-orchestration.d.ts +0 -3
  45. package/dist/chat/services/plugin-auth-orchestration.d.ts +2 -1
  46. package/dist/chat/services/provider-default-config.d.ts +2 -2
  47. package/dist/chat/services/subscribed-decision.d.ts +3 -0
  48. package/dist/chat/services/subscribed-reply-policy.d.ts +1 -0
  49. package/dist/chat/services/turn-result.d.ts +0 -3
  50. package/dist/chat/services/turn-router.d.ts +3 -0
  51. package/dist/chat/slack/assistant-thread/lifecycle.d.ts +0 -1
  52. package/dist/chat/slack/assistant-thread/title.d.ts +0 -3
  53. package/dist/chat/slack/dispatch-turn.d.ts +1 -1
  54. package/dist/chat/slack/tools/canvas/context.d.ts +0 -10
  55. package/dist/chat/slack/tools/canvas/create.d.ts +2 -0
  56. package/dist/chat/slack/tools/canvas/edit.d.ts +2 -0
  57. package/dist/chat/slack/tools/canvas/read.d.ts +2 -0
  58. package/dist/chat/slack/tools/canvas/write.d.ts +2 -0
  59. package/dist/chat/slack/tools/channel-list-messages.d.ts +2 -0
  60. package/dist/chat/slack/tools/conversation-message-search.d.ts +2 -0
  61. package/dist/chat/slack/tools/list/add-items.d.ts +4 -1
  62. package/dist/chat/slack/tools/list/api.d.ts +8 -1
  63. package/dist/chat/slack/tools/list/create.d.ts +2 -0
  64. package/dist/chat/slack/tools/list/get-items.d.ts +5 -3
  65. package/dist/chat/slack/tools/list/update-item.d.ts +5 -1
  66. package/dist/chat/slack/tools/message-add-reaction.d.ts +2 -0
  67. package/dist/chat/slack/tools/public-search.d.ts +2 -0
  68. package/dist/chat/slack/tools/send-files.d.ts +2 -0
  69. package/dist/chat/slack/tools/thread-read.d.ts +2 -0
  70. package/dist/chat/slack/vision-cache.d.ts +5 -0
  71. package/dist/chat/state/conversation.d.ts +4 -5
  72. package/dist/chat/tool-support/structured-result.d.ts +1 -0
  73. package/dist/chat/tool-support/timed-out-tool-result.d.ts +11 -0
  74. package/dist/chat/tools/create-event-task.d.ts +2 -0
  75. package/dist/chat/tools/delete-event-task.d.ts +2 -0
  76. package/dist/chat/tools/handoff/tool.d.ts +2 -0
  77. package/dist/chat/tools/list-event-tasks.d.ts +2 -0
  78. package/dist/chat/tools/list-resource-event-subscriptions.d.ts +2 -0
  79. package/dist/chat/tools/runtime/report-progress.d.ts +2 -0
  80. package/dist/chat/tools/runtime/spawn-agent.d.ts +2 -0
  81. package/dist/chat/tools/search-conversation-events.d.ts +2 -0
  82. package/dist/chat/tools/search-resource-event-types.d.ts +2 -0
  83. package/dist/chat/tools/search-tools.d.ts +2 -0
  84. package/dist/chat/tools/skill/load-skill.d.ts +2 -0
  85. package/dist/chat/tools/skill/search-mcp-tools.d.ts +2 -0
  86. package/dist/chat/tools/stop-watching-resources.d.ts +2 -0
  87. package/dist/chat/tools/system-time.d.ts +2 -0
  88. package/dist/chat/tools/types.d.ts +0 -6
  89. package/dist/chat/tools/update-event-task.d.ts +2 -0
  90. package/dist/chat/tools/user-lookup.d.ts +29 -0
  91. package/dist/chat/tools/watch-resource-events.d.ts +2 -0
  92. package/dist/chat/tools/web/fetch-tool.d.ts +2 -0
  93. package/dist/chat/tools/web/image-generate.d.ts +2 -0
  94. package/dist/chat/tools/web/search.d.ts +2 -0
  95. package/dist/{chunk-LVW7BLLT.js → chunk-34GS7B6L.js} +2 -2
  96. package/dist/{chunk-B63BF443.js → chunk-4LJO56OJ.js} +9 -1
  97. package/dist/{chunk-H6U2U3EP.js → chunk-6H5SZR24.js} +16 -20
  98. package/dist/{chunk-M6ZWP4RI.js → chunk-745QJ3ZA.js} +1 -1
  99. package/dist/{chunk-BLETMLRX.js → chunk-7A4M7PCV.js} +231 -472
  100. package/dist/{chunk-MKRIZ4VG.js → chunk-7NVJVJID.js} +4 -2
  101. package/dist/{chunk-ZDGHGY74.js → chunk-7UQIVT6G.js} +13 -6
  102. package/dist/{chunk-GDQEU4I7.js → chunk-AIOK6LAG.js} +28 -489
  103. package/dist/{chunk-QSXZ42KX.js → chunk-AVOCH2Z5.js} +3 -3
  104. package/dist/{chunk-FXDDDSPL.js → chunk-AVZDSUFB.js} +4 -4
  105. package/dist/{chunk-OFPYOC3M.js → chunk-AYU72WO7.js} +102 -72
  106. package/dist/chunk-AZ7EAOBE.js +566 -0
  107. package/dist/{chunk-PH4Q3A6W.js → chunk-CSZINQJ2.js} +1 -1
  108. package/dist/{chunk-X2WMBTS3.js → chunk-CWP5RHVX.js} +4 -4
  109. package/dist/{chunk-HQE6EJS5.js → chunk-DLDRQHG5.js} +1 -1
  110. package/dist/{chunk-MCFIXAV5.js → chunk-DU74WPIC.js} +55 -37
  111. package/dist/{chunk-X22KCSCO.js → chunk-EFLJ2WJH.js} +6 -4
  112. package/dist/{chunk-37JJDS4H.js → chunk-GGB4WL5A.js} +1 -1
  113. package/dist/{chunk-F7REGDKO.js → chunk-IIOOO4FQ.js} +1 -1
  114. package/dist/{chunk-PB222GIA.js → chunk-JUUKWRBE.js} +1 -1
  115. package/dist/{chunk-T5GXFFLA.js → chunk-K4SZAP3K.js} +1 -1
  116. package/dist/{chunk-GYEKOX7N.js → chunk-ORO3PWKQ.js} +1 -1
  117. package/dist/{chunk-AISNSNDV.js → chunk-PVNG6UMU.js} +3 -3
  118. package/dist/{chunk-47OSH2ZO.js → chunk-Q4R73I43.js} +365 -206
  119. package/dist/{chunk-QG7OOKIN.js → chunk-RXBVB2JM.js} +1 -1
  120. package/dist/{chunk-V6SRLKUB.js → chunk-SGZO7UWH.js} +2 -2
  121. package/dist/{chunk-JLMVCNXL.js → chunk-SVHUEHUL.js} +1 -0
  122. package/dist/{chunk-FEKQHPVA.js → chunk-X5UY34KT.js} +6 -5
  123. package/dist/{chunk-FGHADGIC.js → chunk-YBVXBNSV.js} +2 -2
  124. package/dist/{chunk-JUA6VU2Z.js → chunk-YEO3VX72.js} +10 -23
  125. package/dist/{chunk-SCGVWUZX.js → chunk-YHDERDRO.js} +7 -6
  126. package/dist/{chunk-TCEJ7XXM.js → chunk-YNTTROJT.js} +1 -1
  127. package/dist/{chunk-37EVZP66.js → chunk-YSB2N563.js} +49 -8
  128. package/dist/{chunk-W65V465O.js → chunk-Z4YU7Z4L.js} +3 -2
  129. package/dist/cli/chat.js +32 -32
  130. package/dist/cli/check.js +6 -6
  131. package/dist/cli/plugins.js +13 -13
  132. package/dist/cli/snapshot-create.js +9 -9
  133. package/dist/cli/upgrade.js +7 -7
  134. package/dist/db/schema/location-configurations.d.ts +127 -0
  135. package/dist/db/schema.d.ts +128 -1
  136. package/dist/{db-WWOMXWTT.js → db-CSEW4RII.js} +7 -7
  137. package/dist/instrumentation.js +4 -4
  138. package/dist/nitro.js +2 -2
  139. package/dist/{oauth-callback-server-A6ZZX74U.js → oauth-callback-server-FUEV5HNG.js} +24 -24
  140. package/dist/{runner-KSGB2UAV.js → runner-U3XHSKSH.js} +21 -39
  141. package/dist/{skills-26QPWKVS.js → skills-AKE6W3WI.js} +6 -6
  142. package/dist/spawn-B6GDTWJ4.js +39 -0
  143. package/dist/{validation-OPSRGFGH.js → validation-WDTAULUF.js} +6 -6
  144. package/dist/version.js +1 -1
  145. package/dist/{work-VMSW7STJ.js → work-C3HAO2BG.js} +17 -17
  146. package/dist/{worker-2JNFB7C7.js → worker-LNP4YKBM.js} +10 -10
  147. package/migrations/0024_misty_typhoid_mary.sql +12 -0
  148. package/migrations/meta/0024_snapshot.json +2275 -0
  149. package/migrations/meta/_journal.json +7 -0
  150. package/package.json +5 -5
  151. package/dist/chat/slack/tools/user-lookup.d.ts +0 -27
  152. package/dist/chat/state/artifacts.d.ts +0 -30
  153. package/dist/chat/tool-support/turn-deadline-result.d.ts +0 -3
  154. package/dist/chunk-Q6QZTTLS.js +0 -55
  155. package/dist/spawn-5LAJXZ2P.js +0 -39
@@ -3,7 +3,7 @@ import {
3
3
  toCanonicalInputMessage,
4
4
  toCanonicalOutputMessage,
5
5
  toGenAiMessagesTraceAttributes
6
- } from "./chunk-QG7OOKIN.js";
6
+ } from "./chunk-RXBVB2JM.js";
7
7
  import {
8
8
  extractGenAiUsageAttributes,
9
9
  logException,
@@ -11,7 +11,7 @@ import {
11
11
  normalizeGenAiFinishReason,
12
12
  serializeGenAiAttribute,
13
13
  withSpan
14
- } from "./chunk-B63BF443.js";
14
+ } from "./chunk-4LJO56OJ.js";
15
15
 
16
16
  // src/chat/services/provider-error.ts
17
17
  var ProviderError = class extends Error {
@@ -385,6 +385,7 @@ async function completeText(params) {
385
385
  "gen_ai.operation.name": GEN_AI_OPERATION_CHAT,
386
386
  "gen_ai.request.model": params.modelId,
387
387
  "gen_ai.output.type": "text",
388
+ ...params.promptName ? { "gen_ai.prompt.name": params.promptName } : {},
388
389
  "server.address": GEN_AI_SERVER_ADDRESS,
389
390
  "server.port": GEN_AI_SERVER_PORT,
390
391
  ...hasCompactedConversationContext(params.messages) ? { "gen_ai.conversation.compacted": true } : {},
@@ -545,6 +546,7 @@ async function completeObject(params) {
545
546
  "gen_ai.operation.name": GEN_AI_OPERATION_CHAT,
546
547
  "gen_ai.request.model": params.modelId,
547
548
  "gen_ai.output.type": "json",
549
+ ...params.promptName ? { "gen_ai.prompt.name": params.promptName } : {},
548
550
  "server.address": GEN_AI_SERVER_ADDRESS,
549
551
  "server.port": GEN_AI_SERVER_PORT,
550
552
  "gen_ai.provider.auth_mode": credential?.mode ?? "api_key",
@@ -4,19 +4,19 @@ import {
4
4
  isDmChannel,
5
5
  normalizeSlackConversationId,
6
6
  withSlackRetries
7
- } from "./chunk-V6SRLKUB.js";
7
+ } from "./chunk-SGZO7UWH.js";
8
8
  import {
9
9
  parseDestination
10
- } from "./chunk-37EVZP66.js";
10
+ } from "./chunk-YSB2N563.js";
11
11
  import {
12
12
  getStateAdapter
13
- } from "./chunk-GYEKOX7N.js";
13
+ } from "./chunk-ORO3PWKQ.js";
14
14
  import {
15
15
  normalizeSlackEmojiName
16
- } from "./chunk-MKRIZ4VG.js";
16
+ } from "./chunk-7NVJVJID.js";
17
17
  import {
18
18
  pluginCatalogRuntime
19
- } from "./chunk-PB222GIA.js";
19
+ } from "./chunk-JUUKWRBE.js";
20
20
  import {
21
21
  parseSlackMessageTs,
22
22
  parseSlackUserId
@@ -25,7 +25,7 @@ import {
25
25
  isRecord,
26
26
  logInfo,
27
27
  logWarn
28
- } from "./chunk-B63BF443.js";
28
+ } from "./chunk-4LJO56OJ.js";
29
29
 
30
30
  // src/chat/slack/outbound.ts
31
31
  var MAX_SLACK_MESSAGE_TEXT_CHARS = 4e4;
@@ -289,6 +289,7 @@ async function removeReactionFromMessage(input) {
289
289
  // src/chat/oauth-flow.ts
290
290
  import { randomBytes } from "crypto";
291
291
  import {
292
+ actorSchema,
292
293
  sourceSchema
293
294
  } from "@sentry/junior-plugin-api";
294
295
 
@@ -517,6 +518,10 @@ function parseOAuthStatePayload(value) {
517
518
  if (typeof value.userId !== "string" || typeof value.provider !== "string") {
518
519
  return void 0;
519
520
  }
521
+ const actor = value.actor === void 0 ? void 0 : actorSchema.safeParse(value.actor);
522
+ if (value.actor !== void 0 && (!actor || !actor.success)) {
523
+ return void 0;
524
+ }
520
525
  const destination = parseDestination(value.destination);
521
526
  if (value.destination !== void 0 && !destination) {
522
527
  return void 0;
@@ -528,6 +533,7 @@ function parseOAuthStatePayload(value) {
528
533
  return {
529
534
  userId: value.userId,
530
535
  provider: value.provider,
536
+ ...actor?.success ? { actor: actor.data } : {},
531
537
  ...optionalString(value.channelId) ? { channelId: optionalString(value.channelId) } : {},
532
538
  ...destination ? { destination } : {},
533
539
  ...source?.success ? { source: source.data } : {},
@@ -650,6 +656,7 @@ async function startOAuthFlow(provider, input) {
650
656
  {
651
657
  userId: input.actorId,
652
658
  provider,
659
+ ...input.actor ? { actor: input.actor } : {},
653
660
  ...input.channelId ? { channelId: input.channelId } : {},
654
661
  ...input.destination ? { destination: input.destination } : {},
655
662
  ...input.source ? { source: input.source } : {},
@@ -1,6 +1,3 @@
1
- import {
2
- JUNIOR_THREAD_STATE_TTL_MS
3
- } from "./chunk-3Y47VMHV.js";
4
1
  import {
5
2
  JUNIOR_NATIVE_EVENT_NAMESPACE,
6
3
  ToolInputError,
@@ -21,7 +18,7 @@ import {
21
18
  instructionProvenanceFor,
22
19
  sanitizePostgresJson,
23
20
  withConversationEventLock
24
- } from "./chunk-37EVZP66.js";
21
+ } from "./chunk-YSB2N563.js";
25
22
  import {
26
23
  SANDBOX_WORKSPACE_ROOT,
27
24
  sleep
@@ -31,21 +28,18 @@ import {
31
28
  fenceLock,
32
29
  getStateAdapter,
33
30
  withLock
34
- } from "./chunk-GYEKOX7N.js";
31
+ } from "./chunk-ORO3PWKQ.js";
35
32
  import {
36
33
  botConfig,
37
34
  unwrapCurrentInstruction
38
- } from "./chunk-MKRIZ4VG.js";
35
+ } from "./chunk-7NVJVJID.js";
39
36
  import {
40
37
  toStoredSlackActor
41
38
  } from "./chunk-HZF5P5UN.js";
42
39
  import {
43
40
  getActiveTraceId,
44
- isRecord,
45
- logException,
46
- toOptionalNumber,
47
- toOptionalString
48
- } from "./chunk-B63BF443.js";
41
+ logException
42
+ } from "./chunk-4LJO56OJ.js";
49
43
 
50
44
  // src/chat/turn-context-tag.ts
51
45
  var TURN_CONTEXT_TAG = "runtime-turn-context";
@@ -914,6 +908,26 @@ async function recordAgentsInstructionsUpdated(args) {
914
908
  }
915
909
  ]);
916
910
  }
911
+ async function recordSubscribedReplyRoute(args) {
912
+ await getConversationEventStore().append(args.conversationId, [
913
+ {
914
+ idempotencyKey: `native:${JUNIOR_NATIVE_EVENT_NAMESPACE}:passive_reply_routed:${args.runId}`,
915
+ createdAtMs: Date.now(),
916
+ data: {
917
+ type: "structured_event",
918
+ namespace: JUNIOR_NATIVE_EVENT_NAMESPACE,
919
+ name: "passive_reply_routed",
920
+ version: 1,
921
+ content: {
922
+ costUsd: args.costUsd,
923
+ reason: args.reason,
924
+ shouldReply: args.shouldReply,
925
+ ...args.shouldUnsubscribe !== void 0 ? { shouldUnsubscribe: args.shouldUnsubscribe } : {}
926
+ }
927
+ }
928
+ }
929
+ ]);
930
+ }
917
931
  async function loadTurnRoute(args) {
918
932
  const event = await getConversationEventStore().loadByIdempotencyKey(
919
933
  args.conversationId,
@@ -937,6 +951,7 @@ async function recordTurnRoute(args) {
937
951
  turnId: args.turnId,
938
952
  modelProfile: args.modelProfile,
939
953
  modelId: args.modelId,
954
+ ...args.costUsd !== void 0 ? { costUsd: args.costUsd } : {},
940
955
  reasoningLevel: args.reasoningLevel,
941
956
  ...args.confidence !== void 0 ? { confidence: args.confidence } : {},
942
957
  source: args.source
@@ -2292,473 +2307,6 @@ async function saveDone(args) {
2292
2307
  });
2293
2308
  }
2294
2309
 
2295
- // src/chat/state/conversation.ts
2296
- function defaultConversationState() {
2297
- return {
2298
- schemaVersion: 1,
2299
- messages: [],
2300
- compactions: [],
2301
- processing: {},
2302
- vision: {
2303
- byFileId: {}
2304
- }
2305
- };
2306
- }
2307
- function coercePendingAuthState(value) {
2308
- if (!isRecord(value)) {
2309
- return void 0;
2310
- }
2311
- const kind = value.kind;
2312
- const provider = toOptionalString(value.provider);
2313
- const actorId = toOptionalString(value.actorId);
2314
- const authSessionId = toOptionalString(value.authSessionId);
2315
- const scope = toOptionalString(value.scope);
2316
- const sessionId = toOptionalString(value.sessionId);
2317
- const linkSentAtMs = toOptionalNumber(value.linkSentAtMs);
2318
- if (kind !== "mcp" && kind !== "plugin" || !provider || !actorId || kind === "mcp" && !authSessionId || !sessionId || typeof linkSentAtMs !== "number") {
2319
- return void 0;
2320
- }
2321
- const base = {
2322
- provider,
2323
- actorId,
2324
- ...scope ? { scope } : {},
2325
- sessionId,
2326
- linkSentAtMs
2327
- };
2328
- return kind === "mcp" ? { ...base, authSessionId, kind } : { ...base, kind };
2329
- }
2330
- function coerceThreadConversationState(value) {
2331
- if (!isRecord(value)) {
2332
- return defaultConversationState();
2333
- }
2334
- const root = value;
2335
- const rawConversation = isRecord(root.conversation) ? root.conversation : {};
2336
- const messages = [];
2337
- const compactions = [];
2338
- const rawProcessing = isRecord(rawConversation.processing) ? rawConversation.processing : {};
2339
- const processing = {
2340
- activeTurnId: toOptionalString(rawProcessing.activeTurnId),
2341
- lastCompletedAtMs: toOptionalNumber(rawProcessing.lastCompletedAtMs),
2342
- pendingAuth: coercePendingAuthState(rawProcessing.pendingAuth)
2343
- };
2344
- const rawVision = isRecord(rawConversation.vision) ? rawConversation.vision : {};
2345
- const rawVisionByFileId = isRecord(rawVision.byFileId) ? rawVision.byFileId : {};
2346
- const byFileId = {};
2347
- for (const [fileId, value2] of Object.entries(rawVisionByFileId)) {
2348
- if (typeof fileId !== "string" || fileId.trim().length === 0) continue;
2349
- if (!isRecord(value2)) continue;
2350
- const summary = toOptionalString(value2.summary);
2351
- const analyzedAtMs = toOptionalNumber(value2.analyzedAtMs);
2352
- if (!summary || !analyzedAtMs) continue;
2353
- byFileId[fileId] = {
2354
- summary,
2355
- analyzedAtMs
2356
- };
2357
- }
2358
- return {
2359
- schemaVersion: 1,
2360
- messages,
2361
- compactions,
2362
- processing,
2363
- vision: {
2364
- backfillCompletedAtMs: toOptionalNumber(rawVision.backfillCompletedAtMs),
2365
- byFileId
2366
- }
2367
- };
2368
- }
2369
- function buildConversationStatePatch(conversation) {
2370
- return {
2371
- conversation: {
2372
- schemaVersion: 1,
2373
- processing: { ...conversation.processing },
2374
- vision: {
2375
- backfillCompletedAtMs: conversation.vision.backfillCompletedAtMs,
2376
- byFileId: { ...conversation.vision.byFileId }
2377
- }
2378
- }
2379
- };
2380
- }
2381
-
2382
- // src/chat/state/artifacts.ts
2383
- function coerceThreadArtifactsState(value) {
2384
- if (!value || typeof value !== "object") {
2385
- return {};
2386
- }
2387
- const raw = value;
2388
- const artifacts = raw.artifacts ?? {};
2389
- const listColumnMap = artifacts.listColumnMap ?? {};
2390
- const recentCanvases = [];
2391
- if (Array.isArray(artifacts.recentCanvases)) {
2392
- for (const entry of artifacts.recentCanvases) {
2393
- if (!entry || typeof entry !== "object") {
2394
- continue;
2395
- }
2396
- const candidate = entry;
2397
- if (typeof candidate.id !== "string" || candidate.id.trim().length === 0) {
2398
- continue;
2399
- }
2400
- recentCanvases.push({
2401
- id: candidate.id,
2402
- title: typeof candidate.title === "string" ? candidate.title : void 0,
2403
- url: typeof candidate.url === "string" ? candidate.url : void 0,
2404
- createdAt: typeof candidate.createdAt === "string" ? candidate.createdAt : void 0
2405
- });
2406
- }
2407
- }
2408
- return {
2409
- assistantContextChannelId: typeof artifacts.assistantContextChannelId === "string" ? artifacts.assistantContextChannelId : void 0,
2410
- assistantTitle: typeof artifacts.assistantTitle === "string" ? artifacts.assistantTitle : void 0,
2411
- assistantTitleSourceMessageId: typeof artifacts.assistantTitleSourceMessageId === "string" ? artifacts.assistantTitleSourceMessageId : void 0,
2412
- lastCanvasId: typeof artifacts.lastCanvasId === "string" ? artifacts.lastCanvasId : void 0,
2413
- lastCanvasUrl: typeof artifacts.lastCanvasUrl === "string" ? artifacts.lastCanvasUrl : void 0,
2414
- recentCanvases,
2415
- lastListId: typeof artifacts.lastListId === "string" ? artifacts.lastListId : void 0,
2416
- lastListUrl: typeof artifacts.lastListUrl === "string" ? artifacts.lastListUrl : void 0,
2417
- listColumnMap: {
2418
- titleColumnId: typeof listColumnMap.titleColumnId === "string" ? listColumnMap.titleColumnId : void 0,
2419
- completedColumnId: typeof listColumnMap.completedColumnId === "string" ? listColumnMap.completedColumnId : void 0,
2420
- assigneeColumnId: typeof listColumnMap.assigneeColumnId === "string" ? listColumnMap.assigneeColumnId : void 0,
2421
- dueDateColumnId: typeof listColumnMap.dueDateColumnId === "string" ? listColumnMap.dueDateColumnId : void 0
2422
- },
2423
- updatedAt: typeof artifacts.updatedAt === "string" ? artifacts.updatedAt : void 0
2424
- };
2425
- }
2426
- function buildArtifactStatePatch(patch) {
2427
- return {
2428
- artifacts: {
2429
- ...patch,
2430
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
2431
- }
2432
- };
2433
- }
2434
-
2435
- // src/chat/configuration/validation.ts
2436
- var CONFIG_KEY_RE = /^[a-z0-9]+(?:\.[a-z0-9-]+)+$/;
2437
- var SECRET_KEY_RE = /(?:^|[_.-])(token|secret|password|passphrase|api[-_]?key|private[-_]?key|credential|auth)(?:$|[_.-])/i;
2438
- var SECRET_VALUE_PATTERNS = [
2439
- /\bBearer\s+[A-Za-z0-9._-]{16,}\b/i,
2440
- /-----BEGIN [A-Z ]*PRIVATE KEY-----/,
2441
- /\b(?:ghp|ghs|github_pat)_[A-Za-z0-9_]{20,}\b/,
2442
- /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/i,
2443
- /\bsk-[A-Za-z0-9]{20,}\b/,
2444
- /\bAIza[0-9A-Za-z\-_]{30,}\b/,
2445
- /\bAKIA[0-9A-Z]{16}\b/,
2446
- /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/
2447
- ];
2448
- function validateConfigKey(key) {
2449
- const trimmed = key.trim();
2450
- if (!trimmed) {
2451
- return "Configuration key must not be empty";
2452
- }
2453
- if (!CONFIG_KEY_RE.test(trimmed)) {
2454
- return `Invalid configuration key "${key}"; expected dotted lowercase namespace (for example "provider.repo")`;
2455
- }
2456
- if (SECRET_KEY_RE.test(trimmed)) {
2457
- return `Configuration key "${key}" appears to be secret-related and is not allowed`;
2458
- }
2459
- return void 0;
2460
- }
2461
- function collectStringValues(value, output, depth = 0) {
2462
- if (depth > 5) {
2463
- return;
2464
- }
2465
- if (typeof value === "string") {
2466
- output.push(value);
2467
- return;
2468
- }
2469
- if (Array.isArray(value)) {
2470
- for (const item of value) {
2471
- collectStringValues(item, output, depth + 1);
2472
- }
2473
- return;
2474
- }
2475
- if (value && typeof value === "object") {
2476
- for (const [key, nested] of Object.entries(
2477
- value
2478
- )) {
2479
- output.push(key);
2480
- collectStringValues(nested, output, depth + 1);
2481
- }
2482
- }
2483
- }
2484
- function validateConfigValue(value) {
2485
- const stringValues = [];
2486
- collectStringValues(value, stringValues);
2487
- for (const text of stringValues) {
2488
- for (const pattern of SECRET_VALUE_PATTERNS) {
2489
- if (pattern.test(text)) {
2490
- return "Configuration value appears to contain secret material and is not allowed";
2491
- }
2492
- }
2493
- }
2494
- return void 0;
2495
- }
2496
-
2497
- // src/chat/configuration/service.ts
2498
- function defaultState() {
2499
- return {
2500
- schemaVersion: 1,
2501
- entries: {}
2502
- };
2503
- }
2504
- function sanitizeEntry(value) {
2505
- if (!isRecord(value)) {
2506
- return void 0;
2507
- }
2508
- const key = toOptionalString(value.key);
2509
- if (!key) {
2510
- return void 0;
2511
- }
2512
- if (validateConfigKey(key)) {
2513
- return void 0;
2514
- }
2515
- const updatedAt = toOptionalString(value.updatedAt);
2516
- if (!updatedAt) {
2517
- return void 0;
2518
- }
2519
- if (value.scope !== "channel" && value.scope !== "conversation") {
2520
- return void 0;
2521
- }
2522
- const scope = "conversation";
2523
- return {
2524
- key,
2525
- value: value.value,
2526
- scope,
2527
- updatedAt,
2528
- updatedBy: toOptionalString(value.updatedBy),
2529
- source: toOptionalString(value.source),
2530
- expiresAt: toOptionalString(value.expiresAt)
2531
- };
2532
- }
2533
- function coerceState(raw) {
2534
- if (!isRecord(raw)) {
2535
- return defaultState();
2536
- }
2537
- const rawConfig = isRecord(raw.configuration) ? raw.configuration : {};
2538
- const rawEntries = isRecord(rawConfig.entries) ? rawConfig.entries : {};
2539
- const entries = {};
2540
- for (const [key, value] of Object.entries(rawEntries)) {
2541
- const entry = sanitizeEntry(value);
2542
- if (!entry) {
2543
- continue;
2544
- }
2545
- entries[key] = entry;
2546
- }
2547
- return {
2548
- schemaVersion: 1,
2549
- entries
2550
- };
2551
- }
2552
- function createChannelConfigurationService(storage) {
2553
- const getState = async () => {
2554
- const loaded = await storage.load();
2555
- return coerceState(loaded);
2556
- };
2557
- const saveState = async (state) => {
2558
- await storage.save({
2559
- schemaVersion: 1,
2560
- entries: state.entries
2561
- });
2562
- };
2563
- const get = async (key) => {
2564
- const normalizedKey = key.trim();
2565
- const state = await getState();
2566
- return state.entries[normalizedKey];
2567
- };
2568
- const set = async (input) => {
2569
- const normalizedKey = input.key.trim();
2570
- const keyError = validateConfigKey(normalizedKey);
2571
- if (keyError) {
2572
- throw new Error(keyError);
2573
- }
2574
- const valueError = validateConfigValue(input.value);
2575
- if (valueError) {
2576
- throw new Error(valueError);
2577
- }
2578
- const state = await getState();
2579
- const nextEntry = {
2580
- key: normalizedKey,
2581
- value: input.value,
2582
- scope: "conversation",
2583
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2584
- updatedBy: toOptionalString(input.updatedBy),
2585
- source: toOptionalString(input.source),
2586
- expiresAt: toOptionalString(input.expiresAt)
2587
- };
2588
- state.entries[normalizedKey] = nextEntry;
2589
- await saveState(state);
2590
- return nextEntry;
2591
- };
2592
- const unset = async (key) => {
2593
- const normalizedKey = key.trim();
2594
- const state = await getState();
2595
- if (!state.entries[normalizedKey]) {
2596
- return false;
2597
- }
2598
- delete state.entries[normalizedKey];
2599
- await saveState(state);
2600
- return true;
2601
- };
2602
- const list = async (options = {}) => {
2603
- const state = await getState();
2604
- const prefix = options.prefix?.trim();
2605
- return Object.values(state.entries).filter((entry) => prefix ? entry.key.startsWith(prefix) : true).sort((a, b) => a.key.localeCompare(b.key));
2606
- };
2607
- const resolve = async (key) => {
2608
- const entry = await get(key);
2609
- return entry?.value;
2610
- };
2611
- const resolveValues = async (options = {}) => {
2612
- const keys = Array.isArray(options.keys) ? options.keys.map((entry) => entry.trim()).filter((entry) => entry.length > 0) : void 0;
2613
- const entries = options.prefix ? await list({ prefix: options.prefix }) : await list({});
2614
- const filtered = keys ? entries.filter((entry) => keys.includes(entry.key)) : entries;
2615
- const resolved = {};
2616
- for (const entry of filtered) {
2617
- resolved[entry.key] = entry.value;
2618
- }
2619
- return resolved;
2620
- };
2621
- return {
2622
- get,
2623
- set,
2624
- unset,
2625
- list,
2626
- resolve,
2627
- resolveValues
2628
- };
2629
- }
2630
-
2631
- // src/chat/runtime/thread-state.ts
2632
- function threadStateKey(threadId) {
2633
- return `thread-state:${threadId}`;
2634
- }
2635
- function channelStateKey(channelId) {
2636
- return `channel-state:${channelId}`;
2637
- }
2638
- function buildThreadStatePayload(patch) {
2639
- const payload = {};
2640
- if (patch.artifacts) {
2641
- Object.assign(payload, buildArtifactStatePatch(patch.artifacts));
2642
- }
2643
- if (patch.conversation) {
2644
- Object.assign(payload, buildConversationStatePatch(patch.conversation));
2645
- }
2646
- if (patch.sandboxRef !== void 0) {
2647
- payload.app_sandbox_id = patch.sandboxRef?.id ?? "";
2648
- payload.app_sandbox_dependency_profile_hash = patch.sandboxRef?.profileHash ?? "";
2649
- }
2650
- return payload;
2651
- }
2652
- async function mergePersistedState(key, payload) {
2653
- if (Object.keys(payload).length === 0) {
2654
- return;
2655
- }
2656
- const stateAdapter = getStateAdapter();
2657
- await stateAdapter.connect();
2658
- const existing = await stateAdapter.get(key) ?? {};
2659
- await stateAdapter.set(
2660
- key,
2661
- { ...existing, ...payload },
2662
- JUNIOR_THREAD_STATE_TTL_MS
2663
- );
2664
- }
2665
- function mergeArtifactsState(artifacts, patch) {
2666
- if (!patch) {
2667
- return artifacts;
2668
- }
2669
- return {
2670
- ...artifacts,
2671
- ...patch,
2672
- listColumnMap: {
2673
- ...artifacts.listColumnMap,
2674
- ...patch.listColumnMap
2675
- }
2676
- };
2677
- }
2678
- function getPersistedSandboxState(state) {
2679
- const id = toOptionalString(state.app_sandbox_id);
2680
- if (!id) {
2681
- return void 0;
2682
- }
2683
- const profileHash = toOptionalString(
2684
- state.app_sandbox_dependency_profile_hash
2685
- );
2686
- return {
2687
- id,
2688
- ...profileHash ? { profileHash } : {}
2689
- };
2690
- }
2691
- async function persistThreadState(thread, patch) {
2692
- if (patch.conversation) {
2693
- await persistConversationMessages({
2694
- conversation: patch.conversation,
2695
- conversationId: toOptionalString(thread.id) ?? toOptionalString(thread.runId)
2696
- });
2697
- }
2698
- await persistThreadRuntimeState(thread, patch);
2699
- }
2700
- async function persistThreadRuntimeState(thread, patch) {
2701
- const threadId = toOptionalString(thread.id) ?? toOptionalString(thread.runId);
2702
- if (!threadId) {
2703
- throw new Error("thread id is required to persist runtime scratch");
2704
- }
2705
- await mergePersistedState(
2706
- threadStateKey(threadId),
2707
- buildThreadStatePayload(patch)
2708
- );
2709
- }
2710
- async function getPersistedThreadState(threadId) {
2711
- const stateAdapter = getStateAdapter();
2712
- await stateAdapter.connect();
2713
- return await stateAdapter.get(
2714
- threadStateKey(threadId)
2715
- ) ?? {};
2716
- }
2717
- async function getPersistedChannelState(channelId) {
2718
- const stateAdapter = getStateAdapter();
2719
- await stateAdapter.connect();
2720
- return await stateAdapter.get(
2721
- channelStateKey(channelId)
2722
- ) ?? {};
2723
- }
2724
- async function persistThreadStateById(threadId, patch) {
2725
- if (patch.conversation) {
2726
- await persistConversationMessages({
2727
- conversation: patch.conversation,
2728
- conversationId: threadId
2729
- });
2730
- }
2731
- await mergePersistedState(
2732
- threadStateKey(threadId),
2733
- buildThreadStatePayload(patch)
2734
- );
2735
- }
2736
- function getChannelConfigurationService(thread) {
2737
- const channel = thread.channel;
2738
- const channelId = toOptionalString(thread.channelId) ?? toOptionalString(channel.id);
2739
- if (!channelId) {
2740
- throw new Error("channel id is required to load channel configuration");
2741
- }
2742
- return createChannelConfigurationService({
2743
- load: async () => await channel.state,
2744
- save: async (state) => {
2745
- await mergePersistedState(channelStateKey(channelId), {
2746
- configuration: state
2747
- });
2748
- }
2749
- });
2750
- }
2751
- function getChannelConfigurationServiceById(channelId) {
2752
- return createChannelConfigurationService({
2753
- load: async () => await getPersistedChannelState(channelId),
2754
- save: async (state) => {
2755
- await mergePersistedState(channelStateKey(channelId), {
2756
- configuration: state
2757
- });
2758
- }
2759
- });
2760
- }
2761
-
2762
2310
  // src/chat/services/pending-auth.ts
2763
2311
  var AUTH_LINK_REUSE_WINDOW_MS = 10 * 60 * 1e3;
2764
2312
  var NON_REQUEST_SKIPPED_REASON_PREFIXES = [
@@ -2854,6 +2402,7 @@ export {
2854
2402
  recordAuthorizationCompleted,
2855
2403
  recordAuthenticationLinked,
2856
2404
  recordAgentsInstructionsUpdated,
2405
+ recordSubscribedReplyRoute,
2857
2406
  loadTurnRoute,
2858
2407
  recordTurnRoute,
2859
2408
  recordToolExecutionStarted,
@@ -2913,15 +2462,5 @@ export {
2913
2462
  getConversationPendingAuth,
2914
2463
  clearPendingAuth,
2915
2464
  abandonReplacedPendingAuth,
2916
- isPendingAuthLatestRequest,
2917
- coerceThreadConversationState,
2918
- coerceThreadArtifactsState,
2919
- mergeArtifactsState,
2920
- getPersistedSandboxState,
2921
- persistThreadState,
2922
- persistThreadRuntimeState,
2923
- getPersistedThreadState,
2924
- persistThreadStateById,
2925
- getChannelConfigurationService,
2926
- getChannelConfigurationServiceById
2465
+ isPendingAuthLatestRequest
2927
2466
  };
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  getDb
3
- } from "./chunk-37EVZP66.js";
3
+ } from "./chunk-YSB2N563.js";
4
4
  import {
5
5
  juniorConversations,
6
6
  juniorTaskExecutions
7
- } from "./chunk-MCFIXAV5.js";
7
+ } from "./chunk-DU74WPIC.js";
8
8
  import {
9
9
  logWarn
10
- } from "./chunk-B63BF443.js";
10
+ } from "./chunk-4LJO56OJ.js";
11
11
 
12
12
  // src/chat/tasks/execution-stats.ts
13
13
  import {