@sentry/junior 0.311.0 → 0.313.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 (120) hide show
  1. package/dist/{adapter-B1wujchl.js → adapter-CYAvJzZS.js} +1 -1
  2. package/dist/{adapter-context-G2M0y6rP.js → adapter-context-CVsHoVSf.js} +2 -2
  3. package/dist/{admin-DCiBhUT1.js → admin-Cyhb4TwZ.js} +1 -1
  4. package/dist/{agent-runner-BVHPUIc8.js → agent-runner-B5y9MsT-.js} +3487 -3493
  5. package/dist/api/schema.d.ts +2 -2
  6. package/dist/api/schema.js +6 -6
  7. package/dist/api.d.ts +2 -2
  8. package/dist/api.js +294 -311
  9. package/dist/{app-Cw5Vy6H6.d.ts → app-DA8-hCMj.d.ts} +2 -9
  10. package/dist/app.d.ts +1 -1
  11. package/dist/app.js +336 -604
  12. package/dist/{background-compaction-queue-CJDnWVOJ.js → background-compaction-queue-iZXadLV3.js} +60 -85
  13. package/dist/{catalog-runtime-DMY3VV-D.js → catalog-runtime-kkE3hvCX.js} +1 -1
  14. package/dist/channel-access-mt7K6dPh.js +221 -0
  15. package/dist/cli/chat.js +18 -19
  16. package/dist/cli/check.js +3 -3
  17. package/dist/cli/init.js +0 -1
  18. package/dist/cli/main.js +3 -7
  19. package/dist/cli/plugins.js +4 -4
  20. package/dist/cli/run.d.ts +1 -2
  21. package/dist/cli/run.js +1 -2
  22. package/dist/cli/snapshot-create.js +5 -5
  23. package/dist/cli/upgrade.d.ts +1 -1
  24. package/dist/cli/upgrade.js +3 -3
  25. package/dist/{config-BrXDQefC.js → config-CWbwKj0j.js} +59 -27
  26. package/dist/{continue-in-slack-DNXSC9So.js → continue-in-slack-CxyFzdlF.js} +7 -8
  27. package/dist/{conversation-feed-DkinDu5o.js → conversation-feed-BEXLD3Me.js} +86 -21
  28. package/dist/{conversation-privacy-DxttrKb9.js → conversation-privacy-BrMiDN61.js} +1 -1
  29. package/dist/{conversation-turn-DWw7Xhdr.js → conversation-turn-B35eu0uz.js} +78 -56
  30. package/dist/{credential-sync-Bk8wGb8Y.js → credential-sync-DWTOEQrm.js} +15 -15
  31. package/dist/{projection-Cns7XwWa.js → credentialed-Dyv8b-lu.js} +16306 -20732
  32. package/dist/{db-7ETESH44.d.ts → db-DYGcXYl3.d.ts} +11 -6
  33. package/dist/{db-DTxzH7u5.js → db-PwSRzWWn.js} +181 -100
  34. package/dist/{executor-DqTiYj9S.js → executor-CgWyWfYz.js} +117 -99
  35. package/dist/{html-B9Sl4Axb.js → html-DidUcRhI.js} +6 -6
  36. package/dist/ingest-B0AggUEC.js +7931 -0
  37. package/dist/{install-Sg4ePfLl.js → install-2urLLXNt.js} +2 -2
  38. package/dist/instrumentation.js +3 -3
  39. package/dist/{lineage-BHAMpNKr.js → lineage-BXplQAVH.js} +2 -2
  40. package/dist/{stop-CYsfc0Ed.js → list-DyIyReSV.js} +709 -475
  41. package/dist/{logging-FjclQsXu.js → logging-DNt-qOIO.js} +1 -1
  42. package/dist/{schedule-BLJ476XQ.js → media-B0pZJ0bG.js} +1058 -11
  43. package/dist/{message-CJ7_RL50.js → message-Z5YKC-Af.js} +35 -28
  44. package/dist/{model-input-CMLh4Cwq.js → model-input-BhPJYdSV.js} +3 -3
  45. package/dist/nitro.d.ts +1 -1
  46. package/dist/nitro.js +4 -3
  47. package/dist/{oauth-callback-server-RVcbiDjL.js → oauth-callback-server-ByvDdcdY.js} +2 -2
  48. package/dist/{oauth-relay-Bu9kkaQu.js → oauth-relay-D-kK0yoN.js} +1 -1
  49. package/dist/{registry-BPwuOP2O.js → registry-POH4bZC4.js} +1 -1
  50. package/dist/reporting-window-C4dbzDiR.js +124 -0
  51. package/dist/request-deadline-BUiRYQYj.js +24 -0
  52. package/dist/{resolve-BK29bBry.js → resolve-CWtBNSKP.js} +3 -3
  53. package/dist/{runner-BcAE-cJm.js → runner-CsZ_VRxp.js} +14 -16
  54. package/dist/{sandbox-egress-signals-C-q0go5b.js → sandbox-egress-signals-FbCk1FkN.js} +1 -1
  55. package/dist/{schema-DYcJeV7d.d.ts → schema-DBf18QPS.d.ts} +2773 -3630
  56. package/dist/{schema-BLgSZXcL.js → schema-DojR2uCL.js} +106 -121
  57. package/dist/{service-account-iJoCtkHR.js → service-account-CDYb9hfX.js} +3 -3
  58. package/dist/{service-account-gN0zqf0S.js → service-account-o15pZWcJ.js} +5 -5
  59. package/dist/{skills-BoZ80epJ.js → skills-B0jP4whm.js} +2 -2
  60. package/dist/{slack-conversation-unfurl-CogYrITA.js → slack-conversation-unfurl-D26t9kBC.js} +9 -9
  61. package/dist/{spawn-Dk92r7mX.js → spawn-BjljgExZ.js} +14 -32
  62. package/dist/start-conversation-DbVujrwO.js +755 -0
  63. package/dist/{state-DH3Cmgp3.js → state-BTawTCme.js} +4 -4
  64. package/dist/statuses-BKwqCPhj.js +69 -0
  65. package/dist/store-CjXrp-Up.js +492 -0
  66. package/dist/task-queue-Cwlatjz3.js +90 -0
  67. package/dist/task-runner--Ke8KSMf.js +1432 -0
  68. package/dist/{thread-context-BW2BsQbH.js → thread-context-B8exINEe.js} +6 -7
  69. package/dist/turn-membership-DTR3SaKD.js +5859 -0
  70. package/dist/{validation-DrJd0nnq.js → validation-Ce0qbMlT.js} +1 -1
  71. package/dist/{task-queue-C_zldF5J.js → vercel-queue-q4z8w5QO.js} +93 -172
  72. package/dist/{version-CNKZ8owc.js → version-DFh4n9nr.js} +1 -1
  73. package/dist/version.js +1 -1
  74. package/dist/{warmup-BWdHew2H.js → warmup-D5hzqTcp.js} +4853 -13605
  75. package/dist/web-message-id-C6P83ans.js +10 -0
  76. package/dist/{worker-t9qpu_Zx.js → worker-CDg9Lbpg.js} +20 -7
  77. package/migrations/0143_todos.sql +14 -0
  78. package/migrations/0144_inbox_items.sql +32 -0
  79. package/migrations/0145_todo_changed_by_agent.sql +1 -0
  80. package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
  81. package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
  82. package/migrations/0148_authorization_request_index.sql +1 -0
  83. package/migrations/0149_conversation_metadata.sql +10 -0
  84. package/migrations/0150_conversation_metadata_fill.sql +39 -0
  85. package/migrations/0151_conversation_search_index.sql +1 -0
  86. package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
  87. package/migrations/0153_artifact_expiry.sql +1 -0
  88. package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
  89. package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
  90. package/migrations/0156_conversation_kind_lead.sql +6 -0
  91. package/migrations/0157_conversation_lead_actor_index.sql +1 -0
  92. package/migrations/0158_keep_legacy_archive_columns.sql +5 -0
  93. package/migrations/0159_conversation_embeddings_fk_validate.sql +5 -0
  94. package/migrations/meta/0143_snapshot.json +6434 -0
  95. package/migrations/meta/0144_snapshot.json +6434 -0
  96. package/migrations/meta/0145_snapshot.json +6440 -0
  97. package/migrations/meta/0146_snapshot.json +6446 -0
  98. package/migrations/meta/0147_snapshot.json +6452 -0
  99. package/migrations/meta/0148_snapshot.json +6474 -0
  100. package/migrations/meta/0149_snapshot.json +6490 -0
  101. package/migrations/meta/0150_snapshot.json +6490 -0
  102. package/migrations/meta/0151_snapshot.json +6505 -0
  103. package/migrations/meta/0152_snapshot.json +6505 -0
  104. package/migrations/meta/0153_snapshot.json +6511 -0
  105. package/migrations/meta/0154_snapshot.json +6533 -0
  106. package/migrations/meta/0155_snapshot.json +6511 -0
  107. package/migrations/meta/0156_snapshot.json +6511 -0
  108. package/migrations/meta/0157_snapshot.json +6527 -0
  109. package/migrations/meta/0158_snapshot.json +6515 -0
  110. package/migrations/meta/0159_snapshot.json +6515 -0
  111. package/migrations/meta/_journal.json +120 -1
  112. package/package.json +6 -6
  113. package/skills/design-automation-skill/SKILL.md +108 -0
  114. package/dist/briefs-BDjnug6Y.js +0 -395
  115. package/dist/conversation-ca__NDQW.js +0 -1063
  116. package/dist/prompt-CDqcsDYC.js +0 -910
  117. package/dist/store-DmmMIrQi.js +0 -335
  118. package/dist/task-runner-C7oCJQIx.js +0 -294
  119. package/dist/turn-session-routing-Xh_2nSQe.js +0 -261
  120. package/dist/web-message-id-Ch5dPq-a.js +0 -306
@@ -1,9 +1,9 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { N as actorFromRun, P as toolInvocationDestination } from "./agent-runner-BVHPUIc8.js";
3
- import { In as enqueueAgentInvocation, Jn as getActiveAgentInvocationForConversation, On as enqueueAgentMessageToParent, Zn as getLatestAgentInvocationForConversation, fi as admitAutomatedTurn, ir as findChildAgentConversationId, jn as readChildConversationSender, nn as EVENT_WAIT_MS, nr as AgentMessagePausedError, or as PARENT_AGENT_TARGET, qn as createAgentInvocationForMessage, rr as AgentMessageTargetError, vn as postAutomatedTurnLimitNoticeForConversation } from "./warmup-BWdHew2H.js";
4
- import { Yt as SYSTEM_IDENTITY_ID, a as getConversationStore, dn as canAccessConversation, hn as readConversationAccessFromSql, o as getDb } from "./db-DTxzH7u5.js";
5
- import { at as renderUntrustedTag, n as botConfig } from "./config-BrXDQefC.js";
6
- import { r as appendAndEnqueueInboundMessage } from "./store-DmmMIrQi.js";
2
+ import { A as actorFromRun, j as toolInvocationDestination } from "./agent-runner-B5y9MsT-.js";
3
+ import { H as createAgentInvocationForMessage, J as AgentMessageTargetError, Pt as enqueueAutomatedInput, U as messageChildAgent, Z as findChildAgentConversationId, _ as enqueueAgentInvocation, at as getLatestAgentInvocationForConversation, et as readChildConversationSender, ft as PARENT_AGENT_TARGET, nt as getActiveAgentInvocationForConversation, xt as EVENT_WAIT_MS, z as enqueueAgentMessageToParent } from "./ingest-B0AggUEC.js";
4
+ import { Zt as SYSTEM_IDENTITY_ID, a as getConversationStore, o as getDb, pn as canAccessConversation, vn as readConversationAccessFromSql } from "./db-PwSRzWWn.js";
5
+ import { it as renderUntrustedTag } from "./config-CWbwKj0j.js";
6
+ import { i as leadPersonParticipates } from "./start-conversation-DbVujrwO.js";
7
7
  // src/chat/agent-invocations/top-level-message.ts
8
8
  const AGENT_MESSAGE_EVENT_NAMESPACE = "junior";
9
9
  /** Event type of a message from another top-level agent. */
@@ -12,7 +12,9 @@ const TOP_LEVEL_AGENT_MESSAGE_EVENT_TYPE = "agent.top_level_message";
12
12
  * Check that a top-level agent can message another top-level agent under
13
13
  * `policies/conversation-access.md`. Public agents can message each other.
14
14
  * A private agent can message only agents at its own Destination, such as
15
- * another thread in the same private Slack channel.
15
+ * another thread in the same private Slack channel. A Lead can also message
16
+ * a public root where its person is a Participant, so it can steer the
17
+ * person's work.
16
18
  * Every target that the sender cannot reach gets the same error, so the
17
19
  * error does not show that a private Conversation exists.
18
20
  */
@@ -30,7 +32,10 @@ async function requireTopLevelAgentAccess(args) {
30
32
  requester: sender,
31
33
  target: receiver
32
34
  })) throw notReachable;
33
- if (receiver.visibility === "public" && sender.visibility !== "public") throw new AgentMessageTargetError(`"${args.to}" is a public conversation and this conversation is private. A private conversation can message only conversations in its own channel or DM`);
35
+ if (receiver.visibility === "public" && sender.visibility !== "public" && !await leadPersonParticipates({
36
+ leadConversationId: args.senderConversationId,
37
+ rootConversationId: args.to
38
+ })) throw new AgentMessageTargetError(`"${args.to}" is a public conversation and this conversation is private. A private conversation can message only conversations in its own channel or DM`);
34
39
  }
35
40
  function renderTopLevelMessageInput(args) {
36
41
  return renderUntrustedTag("agent-message", {
@@ -40,28 +45,14 @@ function renderTopLevelMessageInput(args) {
40
45
  }
41
46
  /**
42
47
  * Send one message from a top-level agent to another top-level agent and
43
- * wake the target. The access check runs on each call. A paused target
44
- * (automated-turn limit) takes no message, so two agents cannot keep each
45
- * other running. Repeat calls with the same `messageKey` are safe.
48
+ * wake the target. The access check runs on each call. A stopped target
49
+ * holds the message, so once the automated-turn limit stops one of two
50
+ * agents, they cannot keep each other running. Repeat calls with the same
51
+ * `messageKey` are safe.
46
52
  */
47
53
  async function enqueueTopLevelAgentMessage(args) {
48
54
  await requireTopLevelAgentAccess(args);
49
55
  const nowMs = args.nowMs ?? Date.now();
50
- const maxTurns = botConfig.maxConsecutiveAutomatedTurns;
51
- const decision = await admitAutomatedTurn({
52
- conversationId: args.to,
53
- maxTurns,
54
- nowMs,
55
- state: args.state
56
- });
57
- if (decision.status === "paused") {
58
- if (decision.shouldPostNotice) await postAutomatedTurnLimitNoticeForConversation({
59
- conversationId: args.to,
60
- maxTurns,
61
- nowMs
62
- });
63
- throw new AgentMessagePausedError(args.to);
64
- }
65
56
  const inboundMessageId = `agent-message:${args.senderConversationId}:${args.messageKey}`;
66
57
  const summary = `Top-level agent ${args.senderConversationId} sent a message.`;
67
58
  const metadata = {
@@ -74,7 +65,7 @@ async function enqueueTopLevelAgentMessage(args) {
74
65
  trustedSummary: summary
75
66
  }
76
67
  };
77
- await appendAndEnqueueInboundMessage({
68
+ await enqueueAutomatedInput({
78
69
  message: {
79
70
  conversationId: args.to,
80
71
  createdAtMs: nowMs,
@@ -145,15 +136,31 @@ function bindMessageAgent(run, options) {
145
136
  delivery: "queued"
146
137
  };
147
138
  }
148
- const { invocation, queued } = await createAgentInvocationForMessage({
139
+ const message = {
149
140
  actor,
150
141
  childConversationId,
151
142
  ...run.credentialContext ? { credentialContext: run.credentialContext } : void 0,
152
- destination: toolInvocationDestination(run),
153
143
  idempotencyKey: `${run.turnId}:${call.toolCallId}`,
154
144
  input: input.text,
155
145
  parentConversationId: run.conversationId,
156
146
  parentToolCallId: call.toolCallId
147
+ };
148
+ if (!await getLatestAgentInvocationForConversation(childConversationId)) {
149
+ const { delivery } = await messageChildAgent({
150
+ ...message,
151
+ parentTurnId: run.turnId
152
+ }, {
153
+ ...options,
154
+ queue
155
+ });
156
+ return {
157
+ conversationId: childConversationId,
158
+ delivery
159
+ };
160
+ }
161
+ const { invocation, queued } = await createAgentInvocationForMessage({
162
+ ...message,
163
+ destination: toolInvocationDestination(run)
157
164
  });
158
165
  await enqueueAgentInvocation(invocation, {
159
166
  ...options,
@@ -1,7 +1,7 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { s as getSqlExecutor } from "./db-DTxzH7u5.js";
3
- import { m as isVisionImageMediaType, p as detectImageMediaType } from "./web-message-id-Ch5dPq-a.js";
4
- import { Ja as readLiveAttachment } from "./projection-Cns7XwWa.js";
2
+ import { s as getSqlExecutor } from "./db-PwSRzWWn.js";
3
+ import { i as isVisionImageMediaType, r as detectImageMediaType } from "./media-B0pZJ0bG.js";
4
+ import { i as readLiveAttachment } from "./store-CjXrp-Up.js";
5
5
  import { escapeTagText, renderTag } from "@sentry/junior-plugin-api";
6
6
  // src/chat/attachments/model-input.ts
7
7
  var model_input_exports = /* @__PURE__ */ __exportAll({ loadInputAttachments: () => loadInputAttachments });
package/dist/nitro.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as JuniorPluginSet } from "./plugins-fBrz8PCV.js";
2
- import { i as JuniorDashboardOptions } from "./app-Cw5Vy6H6.js";
2
+ import { i as JuniorDashboardOptions } from "./app-DA8-hCMj.js";
3
3
  import { withSentryConfig as withSentryConfig$1 } from "@sentry/nitro";
4
4
  type SentryNitroConfig = Parameters<typeof withSentryConfig$1>[0];
5
5
  type SentryNitroOptions = NonNullable<Parameters<typeof withSentryConfig$1>[1]>;
package/dist/nitro.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { d as resolvePackageDir, t as discoverInstalledPluginPackageContent, u as isValidPackageName } from "./package-discovery-DD9vencX.js";
2
2
  import { a as pluginRuntimeRegistrationsFromPluginSet, r as pluginCatalogConfigFromPluginSet } from "./plugins-Bkk0XRo2.js";
3
- import { a as CACHE_WARMUP_QUEUE_TOPIC, h as resolveConversationWorkQueueTopic, t as BACKGROUND_COMPACTION_QUEUE_TOPIC, u as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC } from "./background-compaction-queue-CJDnWVOJ.js";
4
- import { t as PLUGIN_TASK_QUEUE_TOPIC } from "./task-queue-C_zldF5J.js";
5
- import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, B as getDeploymentServiceVersion, D as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, F as JUNIOR_RETENTION_CRON_SCHEDULE, I as JUNIOR_RETENTION_ROUTE, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, M as JUNIOR_HEARTBEAT_CRON_SCHEDULE, N as JUNIOR_HEARTBEAT_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, j as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE } from "./logging-FjclQsXu.js";
3
+ import { a as CACHE_WARMUP_QUEUE_TOPIC, d as WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, t as BACKGROUND_COMPACTION_QUEUE_TOPIC } from "./background-compaction-queue-iZXadLV3.js";
4
+ import { t as PLUGIN_TASK_QUEUE_TOPIC } from "./task-queue-Cwlatjz3.js";
5
+ import { n as resolveConversationWorkQueueTopic } from "./vercel-queue-q4z8w5QO.js";
6
+ import { A as JUNIOR_CONTEXT_COMPACTION_CALLBACK_ROUTE, B as getDeploymentServiceVersion, D as JUNIOR_AUTO_ARCHIVE_CRON_SCHEDULE, F as JUNIOR_RETENTION_CRON_SCHEDULE, I as JUNIOR_RETENTION_ROUTE, L as JUNIOR_WORKSPACE_SNAPSHOT_JOB_CALLBACK_ROUTE, M as JUNIOR_HEARTBEAT_CRON_SCHEDULE, N as JUNIOR_HEARTBEAT_ROUTE, O as JUNIOR_AUTO_ARCHIVE_ROUTE, P as JUNIOR_PLUGIN_TASK_CALLBACK_ROUTE, j as JUNIOR_CONVERSATION_WORK_CALLBACK_ROUTE, k as JUNIOR_CACHE_WARMUP_CALLBACK_ROUTE } from "./logging-DNt-qOIO.js";
6
7
  import { n as loadPluginSetFromModule, r as resolvePluginModule } from "./plugin-module-Cv2ETe8Y.js";
7
8
  import path from "node:path";
8
9
  import { cpSync, existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
@@ -1,5 +1,5 @@
1
- import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-Bk8wGb8Y.js";
2
- import { Cn as createUserTokenStore } from "./projection-Cns7XwWa.js";
1
+ import { a as GET, n as syncLocalOAuthCredential, r as GET$1 } from "./credential-sync-DWTOEQrm.js";
2
+ import { r as createUserTokenStore } from "./credentialed-Dyv8b-lu.js";
3
3
  import { createServer } from "node:http";
4
4
  // src/chat/local/oauth-callback-server.ts
5
5
  const LOCAL_OAUTH_TIMEOUT_MS = 6e5;
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { d as readJuniorSecret } from "./task-queue-C_zldF5J.js";
2
+ import { f as readJuniorSecret } from "./vercel-queue-q4z8w5QO.js";
3
3
  import * as z from "zod";
4
4
  import { randomBytes } from "node:crypto";
5
5
  import { SignJWT, jwtVerify } from "jose";
@@ -1,5 +1,5 @@
1
1
  import { n as normalizePluginPackageNames, o as pluginRoots, t as discoverInstalledPluginPackageContent } from "./package-discovery-DD9vencX.js";
2
- import { b as setSpanAttributes, h as logWarn, m as logInfo } from "./logging-FjclQsXu.js";
2
+ import { b as setSpanAttributes, h as logWarn, m as logInfo } from "./logging-DNt-qOIO.js";
3
3
  import { o as isUserActor, s as parseActorUserId } from "./actor-BsBdxDXQ.js";
4
4
  import * as z from "zod";
5
5
  import path from "node:path";
@@ -0,0 +1,124 @@
1
+ // src/api/reporting-window.ts
2
+ /** Shared UTC day/hour/six-hour windows for dashboard activity series. */
3
+ const HOUR_MS = 36e5;
4
+ const SIX_HOUR_MS = 6 * HOUR_MS;
5
+ const DAY_MS = 24 * HOUR_MS;
6
+ /** Start of the UTC calendar day containing `valueMs`. */
7
+ function startOfUtcDay(valueMs) {
8
+ const date = new Date(valueMs);
9
+ date.setUTCHours(0, 0, 0, 0);
10
+ return date;
11
+ }
12
+ /** Start of the UTC hour containing `valueMs`. */
13
+ function startOfUtcHour(valueMs) {
14
+ const date = new Date(valueMs);
15
+ date.setUTCMinutes(0, 0, 0);
16
+ return date;
17
+ }
18
+ /** Start of the UTC 6-hour bucket containing `valueMs` (00/06/12/18). */
19
+ function startOfUtcSixHour(valueMs) {
20
+ const date = startOfUtcHour(valueMs);
21
+ date.setUTCHours(Math.floor(date.getUTCHours() / 6) * 6, 0, 0, 0);
22
+ return date;
23
+ }
24
+ /** UTC day key `YYYY-MM-DD`. */
25
+ function utcDayKey(value) {
26
+ return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 10);
27
+ }
28
+ /** UTC hour key `YYYY-MM-DDTHH`. */
29
+ function utcHourKey(value) {
30
+ return (typeof value === "number" ? new Date(value) : value).toISOString().slice(0, 13);
31
+ }
32
+ /** UTC 6-hour bucket key `YYYY-MM-DDTHH` at 00/06/12/18. */
33
+ function utcSixHourKey(value) {
34
+ return utcHourKey(startOfUtcSixHour(typeof value === "number" ? value : value.getTime()));
35
+ }
36
+ /** Inclusive trailing UTC day window ending on today's UTC day. */
37
+ function trailingUtcDayWindow(nowMs, dayCount) {
38
+ const end = startOfUtcDay(nowMs);
39
+ const start = new Date(end);
40
+ start.setUTCDate(start.getUTCDate() - (dayCount - 1));
41
+ return {
42
+ end,
43
+ start
44
+ };
45
+ }
46
+ /** Inclusive trailing UTC hour window ending on the current UTC hour. */
47
+ function trailingUtcHourWindow(nowMs, hourCount = 24) {
48
+ const end = startOfUtcHour(nowMs);
49
+ return {
50
+ end,
51
+ start: /* @__PURE__ */ new Date(end.getTime() - (hourCount - 1) * HOUR_MS)
52
+ };
53
+ }
54
+ /** Inclusive trailing UTC 6-hour window ending on the current 6h bucket. */
55
+ function trailingUtcSixHourWindow(nowMs, bucketCount = 28) {
56
+ const end = startOfUtcSixHour(nowMs);
57
+ return {
58
+ end,
59
+ start: /* @__PURE__ */ new Date(end.getTime() - (bucketCount - 1) * SIX_HOUR_MS)
60
+ };
61
+ }
62
+ /** Fill a fixed UTC day window from a sparse map. */
63
+ function fillUtcDays(args) {
64
+ const { end, start } = trailingUtcDayWindow(args.nowMs, args.count);
65
+ const items = [];
66
+ for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setUTCDate(cursor.getUTCDate() + 1)) {
67
+ const date = utcDayKey(cursor);
68
+ items.push(args.rows.get(date) ?? args.empty(date));
69
+ }
70
+ return items;
71
+ }
72
+ /** Fill a fixed UTC hour window from a sparse map. */
73
+ function fillUtcHours(args) {
74
+ const hourCount = args.count ?? 24;
75
+ const { end, start } = trailingUtcHourWindow(args.nowMs, hourCount);
76
+ const items = [];
77
+ for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + HOUR_MS)) {
78
+ const date = utcHourKey(cursor);
79
+ items.push(args.rows.get(date) ?? args.empty(date));
80
+ }
81
+ return items;
82
+ }
83
+ /** Fill a fixed UTC 6-hour window from a map of known rows. */
84
+ function fillUtcSixHours(args) {
85
+ const bucketCount = args.count ?? 28;
86
+ const { end, start } = trailingUtcSixHourWindow(args.nowMs, bucketCount);
87
+ const items = [];
88
+ for (const cursor = new Date(start); cursor.getTime() <= end.getTime(); cursor.setTime(cursor.getTime() + SIX_HOUR_MS)) {
89
+ const date = utcSixHourKey(cursor);
90
+ items.push(args.rows.get(date) ?? args.empty(date));
91
+ }
92
+ return items;
93
+ }
94
+ /**
95
+ * Sum hour rows into trailing 6-hour buckets.
96
+ * Adds number fields. Keeps other fields from the first row in the bucket.
97
+ * Sets `date` to the 6-hour bucket key.
98
+ */
99
+ function sumUtcHoursIntoSixHours(args) {
100
+ const bucketCount = args.count ?? 28;
101
+ const bySix = /* @__PURE__ */ new Map();
102
+ for (const hour of args.hours) {
103
+ const key = utcSixHourKey(Date.parse(`${hour.date}:00:00.000Z`));
104
+ const next = {
105
+ ...bySix.get(key) ?? args.empty(key),
106
+ date: key
107
+ };
108
+ for (const [field, value] of Object.entries(hour)) {
109
+ if (field === "date") continue;
110
+ if (typeof value === "number") {
111
+ const prior = next[field];
112
+ next[field] = (typeof prior === "number" ? prior : 0) + value;
113
+ }
114
+ }
115
+ bySix.set(key, next);
116
+ }
117
+ return fillUtcSixHours({
118
+ count: bucketCount,
119
+ empty: args.empty,
120
+ nowMs: args.nowMs,
121
+ rows: bySix
122
+ });
123
+ }
124
+ export { fillUtcSixHours as a, trailingUtcDayWindow as c, utcHourKey as d, fillUtcHours as i, trailingUtcHourWindow as l, HOUR_MS as n, startOfUtcHour as o, fillUtcDays as r, sumUtcHoursIntoSixHours as s, DAY_MS as t, trailingUtcSixHourWindow as u };
@@ -0,0 +1,24 @@
1
+ import { r as getChatConfig } from "./config-CWbwKj0j.js";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ // src/chat/runtime/request-deadline.ts
4
+ const requestDeadlineStorage = new AsyncLocalStorage();
5
+ function createTurnRequestDeadline(startedAtMs) {
6
+ return {
7
+ startedAtMs,
8
+ deadlineAtMs: startedAtMs + Math.max(1, getChatConfig().functionMaxDurationSeconds * 1e3 - 2e4)
9
+ };
10
+ }
11
+ /** Return the host request deadline inherited by the current async turn. */
12
+ function getTurnRequestDeadline() {
13
+ return requestDeadlineStorage.getStore();
14
+ }
15
+ /** Run work under the current host request deadline, or start one. */
16
+ function runWithTurnRequestDeadline(callback, startedAtMs = Date.now()) {
17
+ if (requestDeadlineStorage.getStore()) return callback();
18
+ return runWithNewTurnRequestDeadline(callback, startedAtMs);
19
+ }
20
+ /** Run work that a new host request owns, even inside another request. */
21
+ function runWithNewTurnRequestDeadline(callback, startedAtMs = Date.now()) {
22
+ return requestDeadlineStorage.run(createTurnRequestDeadline(startedAtMs), callback);
23
+ }
24
+ export { runWithNewTurnRequestDeadline as n, runWithTurnRequestDeadline as r, getTurnRequestDeadline as t };
@@ -1,6 +1,6 @@
1
- import { i as trace, n as postinstall, o as getSandboxResources, t as dependencies } from "./install-Sg4ePfLl.js";
2
- import { Ni as getSandboxProvider, ji as isStale, ki as create, os as sleep } from "./projection-Cns7XwWa.js";
3
- import { i as getStateAdapter } from "./adapter-B1wujchl.js";
1
+ import { i as trace, n as postinstall, o as getSandboxResources, t as dependencies } from "./install-2urLLXNt.js";
2
+ import { Jt as create, Qt as getSandboxProvider, Xt as isStale, zo as sleep } from "./credentialed-Dyv8b-lu.js";
3
+ import { i as getStateAdapter } from "./adapter-CYAvJzZS.js";
4
4
  import * as z from "zod";
5
5
  // src/chat/sandbox/snapshot/resolve.ts
6
6
  const SNAPSHOT_CACHE_PREFIX = "junior:sandbox_snapshot_profile:v2";
@@ -1,13 +1,11 @@
1
- import { Y as messageCardText } from "./conversation-ca__NDQW.js";
2
- import { a as buildDeliveredTurnStatePatch, o as loadPendingMessageCards, r as completeAuthPauseTurn, t as buildTurnThreadContext } from "./thread-context-BW2BsQbH.js";
3
- import { A as latestConversationMessageSeq, I as upsertConversationMessage, M as normalizeConversationText, N as recordDeliveredAssistantMessage, S as persistConversationMessages, W as authorizationId, b as hydrateConversationMessages, dn as getAssistantReplyText, f as recordAuthorizationCompleted, j as markConversationMessage, nt as saveTurnCheckpoint, o as loadProjection, t as commitAcceptedReply, xn as persistWithRetry } from "./projection-Cns7XwWa.js";
4
- import { S as setTags, T as withLogContext, p as logException } from "./logging-FjclQsXu.js";
5
- import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner-C7oCJQIx.js";
6
- import { a as getPersistedThreadState, c as coerceThreadConversationState, i as getPersistedSandboxState, s as persistThreadStateById } from "./turn-session-routing-Xh_2nSQe.js";
7
- import { Ir as ConversationTurnLifecycleService, Mr as markTurnFailed, Nr as startActiveTurn } from "./warmup-BWdHew2H.js";
8
- import { F as finalizeFailedTurnReplyWithEvent } from "./agent-runner-BVHPUIc8.js";
9
- import { p as credentialContextForActor } from "./registry-BPwuOP2O.js";
10
- import { Yt as SYSTEM_IDENTITY_ID, a as getConversationStore, r as getConversationEventStore } from "./db-DTxzH7u5.js";
1
+ import { xt as messageCardText } from "./media-B0pZJ0bG.js";
2
+ import { a as buildDeliveredTurnStatePatch, o as loadPendingMessageCards, r as completeAuthPauseTurn, t as buildTurnThreadContext } from "./thread-context-B8exINEe.js";
3
+ import { Bt as authorizationId, Ct as recordDeliveredAssistantMessage, Et as upsertConversationMessage, In as finalizeFailedTurnReplyWithEvent, Qt as saveTurnCheckpoint, St as normalizeConversationText, X as loadConversationProjection, bt as latestConversationMessageSeq, d as getPersistedThreadState, dr as persistWithRetry, ft as persistConversationMessages, m as coerceThreadConversationState, nt as recordAuthorizationCompleted, p as persistThreadStateById, q as commitAcceptedReply, tr as getAssistantReplyText, u as getPersistedSandboxState, ut as hydrateConversationMessages, wn as getTurnLifecycle, xt as markConversationMessage } from "./turn-membership-DTR3SaKD.js";
4
+ import { S as setTags, T as withLogContext, p as logException } from "./logging-DNt-qOIO.js";
5
+ import { n as scheduleSessionCompletedPluginTasks, t as processPluginTask } from "./task-runner--Ke8KSMf.js";
6
+ import { en as markTurnFailed, tn as startActiveTurn } from "./ingest-B0AggUEC.js";
7
+ import { p as credentialContextForActor } from "./registry-POH4bZC4.js";
8
+ import { Zt as SYSTEM_IDENTITY_ID, a as getConversationStore } from "./db-PwSRzWWn.js";
11
9
  import { randomUUID } from "node:crypto";
12
10
  import { createLocalSource, localDestinationSchema } from "@sentry/junior-plugin-api";
13
11
  // src/chat/local/runner.ts
@@ -50,8 +48,8 @@ function captureLocalBoundaryFailure(args) {
50
48
  }
51
49
  /** Load durable local Pi history from the conversation-event projection. */
52
50
  async function loadLocalPiMessages(args) {
53
- const projection = await loadProjection({ conversationId: args.conversationId });
54
- if (projection.length === 0) return;
51
+ const projection = await loadConversationProjection({ conversationId: args.conversationId });
52
+ if (projection.messages.length === 0) return;
55
53
  return projection;
56
54
  }
57
55
  /** Run one local CLI message through Junior's shared agent-run boundary. */
@@ -70,7 +68,7 @@ async function runLocalAgentTurnInContext(input, deps) {
70
68
  if (!text) throw new Error("Local agent message must not be empty");
71
69
  const destination = localDestination(input.conversationId);
72
70
  const source = createLocalSource(destination.conversationId);
73
- const lifecycle = new ConversationTurnLifecycleService(getConversationEventStore());
71
+ const lifecycle = getTurnLifecycle();
74
72
  await getConversationStore().recordActivity({
75
73
  conversationId: input.conversationId,
76
74
  destination,
@@ -171,7 +169,7 @@ async function runLocalAgentTurnInContext(input, deps) {
171
169
  await persistThreadStateById(input.conversationId, { conversation });
172
170
  const piMessages = await loadLocalPiMessages({ conversationId: input.conversationId });
173
171
  failureCode = "agent_run_failed";
174
- const runAgent = async (messages) => {
172
+ const runAgent = async (history) => {
175
173
  currentRunId = localRunId();
176
174
  setTags({ runId: currentRunId });
177
175
  const authorization = deps.authorization ? {
@@ -188,11 +186,11 @@ async function runLocalAgentTurnInContext(input, deps) {
188
186
  conversation,
189
187
  conversationId: input.conversationId,
190
188
  excludeMessageIds: [userMessageId],
191
- hasHistory: Boolean(messages?.length),
189
+ hasHistory: Boolean(history?.messages.length),
192
190
  turnId
193
191
  })
194
192
  },
195
- history: messages,
193
+ history,
196
194
  actor: localActor,
197
195
  credentialContext: credentialContextForActor(localActor),
198
196
  destination,
@@ -1,4 +1,4 @@
1
- import { ra as sandboxEgressSignalsResponseSchema } from "./projection-Cns7XwWa.js";
1
+ import { Cn as sandboxEgressSignalsResponseSchema } from "./credentialed-Dyv8b-lu.js";
2
2
  // src/chat/local/sandbox-egress-signals.ts
3
3
  const SANDBOX_EGRESS_SIGNALS_PATH = "/api/internal/sandbox-egress/signals";
4
4
  const LOCAL_DEV_SERVER_TIMEOUT_MS = 1e3;