@sentry/junior 0.305.0 → 0.307.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 (98) hide show
  1. package/dist/{adapter-context-BpvbUki8.js → adapter-context-B69WPn6b.js} +2 -2
  2. package/dist/{admin-CoDt35ny.js → admin-nCJXMgkp.js} +2 -2
  3. package/dist/{agent-runner-C5d6rY5g.js → agent-runner-DdFcxAxG.js} +463 -303
  4. package/dist/api/schema.d.ts +2 -2
  5. package/dist/api/schema.js +7 -8
  6. package/dist/api.d.ts +19 -4
  7. package/dist/api.js +437 -310
  8. package/dist/{app-Cs157Zc5.d.ts → app-EZur8cVC.d.ts} +12 -3
  9. package/dist/app.d.ts +2 -2
  10. package/dist/app.js +532 -439
  11. package/dist/background-compaction-queue-BhEe4UfU.js +231 -0
  12. package/dist/{briefs-BRdznF7c.js → briefs-Dl9lxi7J.js} +3 -3
  13. package/dist/{catalog-runtime-J52Tej47.js → catalog-runtime-OXrv2Ewn.js} +1 -1
  14. package/dist/cli/chat.d.ts +1 -1
  15. package/dist/cli/chat.js +17 -16
  16. package/dist/cli/check.js +58 -48
  17. package/dist/cli/main.js +3 -3
  18. package/dist/cli/plugins.d.ts +1 -1
  19. package/dist/cli/plugins.js +4 -4
  20. package/dist/cli/snapshot-create.js +5 -5
  21. package/dist/cli/upgrade.d.ts +2 -2
  22. package/dist/cli/upgrade.js +3 -8
  23. package/dist/{config-CBZp0udd.js → config-362yMSIz.js} +183 -49
  24. package/dist/{connections-BYmuJ6Vm.js → connections-BJv3EjmB.js} +10 -8
  25. package/dist/{continue-in-slack-Cvot6S38.js → continue-in-slack-CFEevC7z.js} +5 -5
  26. package/dist/{conversation-BOqdRtUx.js → conversation--f85g4zL.js} +132 -132
  27. package/dist/{conversation-feed-CgpgP7yi.js → conversation-feed-BNs9KiqC.js} +1 -1
  28. package/dist/{conversation-privacy-D2pOzBNl.js → conversation-privacy-Tjj5P2W6.js} +1 -1
  29. package/dist/{conversation-turn-CI8WDpnK.js → conversation-turn-DU0_WDAr.js} +26 -72
  30. package/dist/{credential-sync-COqnZ1Dx.js → credential-sync-D6aFARKE.js} +28 -27
  31. package/dist/{db-DU84dCVu.js → db-Bcbd9zQc.js} +226 -18
  32. package/dist/{db-zbN5ZV_o.d.ts → db-C41UgdBj.d.ts} +1 -1
  33. package/dist/{executor-CFyrgOu1.js → executor-DBMBrpNV.js} +137 -33
  34. package/dist/{history-m2-ceTTX.js → history-N7IVbUom.js} +5 -1
  35. package/dist/{install-CQ76CfRw.js → install-CgoAbzfF.js} +2 -2
  36. package/dist/instrumentation.js +2 -2
  37. package/dist/{lineage-DLd2UxVP.js → lineage-CsZDmz3e.js} +2 -2
  38. package/dist/{logging-BPNTQVFu.js → logging-CHCuQ5iz.js} +1 -1
  39. package/dist/{message-BWJLeQ5e.js → message-B8vCbZZB.js} +8 -8
  40. package/dist/{model-input-DoM9Ht-d.js → model-input-Xluiy-1W.js} +3 -3
  41. package/dist/nitro.d.ts +2 -2
  42. package/dist/nitro.js +3 -4
  43. package/dist/{oauth-callback-server-DeHbnAQl.js → oauth-callback-server-BUuNvfvu.js} +2 -2
  44. package/dist/{oauth-relay-DAmfVmJu.js → oauth-relay-DGAZzg9m.js} +1 -1
  45. package/dist/{plugins-B_0Cr0MO.d.ts → plugins-fBrz8PCV.d.ts} +2 -0
  46. package/dist/{projection-CcFBVFUo.js → projection-xPpvqexa.js} +13423 -11432
  47. package/dist/{prompt-C5LREK2p.js → prompt-D8u4jFs_.js} +15 -7
  48. package/dist/{registry-BjZZqKqi.js → registry-D20hG3r6.js} +19 -9
  49. package/dist/{resolve-CeJgXuH1.js → resolve-BhCySRCW.js} +3 -3
  50. package/dist/{result-icDrueyB.js → result-DddO63S9.js} +13 -11
  51. package/dist/{runner-nVfMkMMB.js → runner-DQR9vYce.js} +13 -15
  52. package/dist/{sandbox-egress-signals-H9vQ5qRf.js → sandbox-egress-signals-DFlNUOnK.js} +1 -1
  53. package/dist/{automation-CuA3yEcD.js → schedule-BG1tEbRF.js} +380 -8
  54. package/dist/{schema-CKcu-IK6.d.ts → schema-CRXcj4fj.d.ts} +420 -143
  55. package/dist/{schema-Bx0Mlo32.js → schema-D4jdesIu.js} +62 -8
  56. package/dist/{service-account-DU5865XA.js → service-account-Bv5QwrEq.js} +8 -6
  57. package/dist/{service-account-Dw06p3zm.js → service-account-CNfycv0z.js} +3 -3
  58. package/dist/{session-stop-uotLtp4g.js → session-stop-BDdwyZaa.js} +878 -171
  59. package/dist/{skills-Bex1EaO5.js → skills-63i1Bcv1.js} +32 -28
  60. package/dist/{slack-conversation-unfurl-EPG3riWF.js → slack-conversation-unfurl-DtpBUlUu.js} +10 -9
  61. package/dist/{spawn-CoD3vDuS.js → spawn-mwimEY9_.js} +6 -6
  62. package/dist/{state-nCR4Muhn.js → state-BBn9L6gC.js} +4 -4
  63. package/dist/{stop-BFVd0P0m.js → stop-Da-Ug7tg.js} +172 -239
  64. package/dist/{store-Ca6G962n.js → store-CdWg2r2L.js} +5 -5
  65. package/dist/{background-compaction-queue-BTqMIfTA.js → task-queue-BcjAYWyB.js} +164 -180
  66. package/dist/{task-runner-xsOPIxCZ.js → task-runner-CoXmMlsW.js} +13 -11
  67. package/dist/{thread-context-BOvZhsKK.js → thread-context-ZPGqOjW7.js} +8 -91
  68. package/dist/turn-session-routing-DFYak28Q.js +263 -0
  69. package/dist/{turn-user-message-BrhuyYrH.js → turn-user-message-B1S8nOnG.js} +3 -3
  70. package/dist/users-DDbENg-I.js +181 -0
  71. package/dist/{validation-BnY9K5WB.js → validation-fl21ps-k.js} +1 -1
  72. package/dist/{version-qROlRQGF.js → version-DCdMMx_0.js} +1 -1
  73. package/dist/version.js +1 -1
  74. package/dist/{viewer-CxUiOraX.js → viewer-DN_xzVKj.js} +3 -3
  75. package/dist/{warmup--Gkz7iB-.js → warmup-CxhEhm71.js} +842 -532
  76. package/dist/{web-message-id-lNodcCOI.js → web-message-id-BT8Mg8LL.js} +16 -1
  77. package/dist/{worker-DJ8d9fmD.js → worker-Btb1SB5h.js} +8 -7
  78. package/migrations/0114_plan_items.sql +22 -0
  79. package/migrations/0115_automation_creator_slack_index.sql +1 -0
  80. package/migrations/0116_conversation_event_search.sql +25 -0
  81. package/migrations/0117_automation_last_run.sql +46 -0
  82. package/migrations/0118_automation_last_run_index.sql +1 -0
  83. package/migrations/0119_money_micro_usd.sql +29 -0
  84. package/migrations/0120_conversation_cost_micro_usd.sql +8 -0
  85. package/migrations/meta/0114_snapshot.json +5203 -0
  86. package/migrations/meta/0115_snapshot.json +5225 -0
  87. package/migrations/meta/0116_snapshot.json +5388 -0
  88. package/migrations/meta/0117_snapshot.json +5413 -0
  89. package/migrations/meta/0118_snapshot.json +5428 -0
  90. package/migrations/meta/0119_snapshot.json +5441 -0
  91. package/migrations/meta/0120_snapshot.json +5441 -0
  92. package/migrations/meta/_journal.json +49 -0
  93. package/package.json +10 -9
  94. package/dist/queue-B2AAL3ym.js +0 -115
  95. package/dist/schedule-cP0AACm1.js +0 -344
  96. package/dist/secrets-DHaJ5TTn.js +0 -18
  97. package/dist/task-queue-BLPZU6kC.js +0 -89
  98. package/dist/turn-session-routing-2bW2qfeb.js +0 -1792
@@ -799,6 +799,55 @@
799
799
  "when": 1794765736832,
800
800
  "tag": "0113_attachment_url_index",
801
801
  "breakpoints": true
802
+ },
803
+ {
804
+ "idx": 114,
805
+ "version": "7",
806
+ "when": 1794825420550,
807
+ "tag": "0114_plan_items",
808
+ "breakpoints": true
809
+ },
810
+ {
811
+ "idx": 115,
812
+ "version": "7",
813
+ "when": 1794909660518,
814
+ "tag": "0115_automation_creator_slack_index",
815
+ "breakpoints": true
816
+ },
817
+ {
818
+ "idx": 116,
819
+ "version": "7",
820
+ "when": 1794921922374,
821
+ "tag": "0116_conversation_event_search",
822
+ "breakpoints": true
823
+ },
824
+ {
825
+ "idx": 117,
826
+ "version": "7",
827
+ "when": 1794933607046,
828
+ "tag": "0117_automation_last_run",
829
+ "breakpoints": true
830
+ },
831
+ {
832
+ "idx": 118,
833
+ "version": "7",
834
+ "when": 1794933647013,
835
+ "tag": "0118_automation_last_run_index",
836
+ "breakpoints": true
837
+ },
838
+ {
839
+ "idx": 119,
840
+ "version": "7",
841
+ "when": 1794949484361,
842
+ "tag": "0119_money_micro_usd",
843
+ "breakpoints": true
844
+ },
845
+ {
846
+ "idx": 120,
847
+ "version": "7",
848
+ "when": 1794949505801,
849
+ "tag": "0120_conversation_cost_micro_usd",
850
+ "breakpoints": true
802
851
  }
803
852
  ]
804
853
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentry/junior",
3
- "version": "0.305.0",
3
+ "version": "0.307.0",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -64,10 +64,11 @@
64
64
  "@logtape/logtape": "^2.1.1",
65
65
  "@modelcontextprotocol/sdk": "1.32.0",
66
66
  "@neondatabase/serverless": "^1.1.0",
67
- "@sentry/junior-plugin-api": "0.305.0",
68
- "@sentry/nitro": "11.10.0",
69
- "@sentry/node": "11.10.0",
70
- "@sentry/server-utils": "11.10.0",
67
+ "@sentry/junior-plugin-api": "0.307.0",
68
+ "@sentry/junior-search": "0.307.0",
69
+ "@sentry/nitro": "11.14.0",
70
+ "@sentry/node": "11.14.0",
71
+ "@sentry/server-utils": "11.14.0",
71
72
  "@sinclair/typebox": "^0.34.49",
72
73
  "@slack/types": "^2.21.1",
73
74
  "@slack/web-api": "^7.16.0",
@@ -115,10 +116,10 @@
115
116
  "@emnapi/core": "^1.10.0",
116
117
  "@emnapi/runtime": "^1.10.0",
117
118
  "@hono/node-server": "2.1.3",
118
- "@sentry/junior-github": "0.305.0",
119
- "@sentry/junior-memory": "0.305.0",
120
- "@sentry/junior-notion": "0.305.0",
121
- "@sentry/junior-sentry": "0.305.0",
119
+ "@sentry/junior-github": "0.307.0",
120
+ "@sentry/junior-memory": "0.307.0",
121
+ "@sentry/junior-notion": "0.307.0",
122
+ "@sentry/junior-sentry": "0.307.0",
122
123
  "@sentry/junior-testing": "0.0.0",
123
124
  "@types/node": "^24.19.2",
124
125
  "@types/pg": "^8.15.6",
@@ -1,115 +0,0 @@
1
- import { i as getChatConfig } from "./config-CBZp0udd.js";
2
- import { h as logWarn } from "./logging-BPNTQVFu.js";
3
- import { a as queueCallback, d as verifyQueueMessage, f as getQueueProvider, l as QUEUE_SIGNATURE_MAX_AGE_MS, u as signQueueMessage } from "./background-compaction-queue-BTqMIfTA.js";
4
- import * as z from "zod";
5
- import { createHash } from "node:crypto";
6
- // src/chat/sandbox/snapshot/job-queue.ts
7
- /** Send Workspace snapshot build messages. */
8
- const SIGNATURE_CONTEXT = "junior.workspace_snapshot_queue.v1";
9
- const SIGNATURE_VERSION = "v1";
10
- const WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC = "junior_workspace_snapshots";
11
- const workspaceSnapshotJobSign = {
12
- context: SIGNATURE_CONTEXT,
13
- schema: z.object({
14
- workspaceId: z.string().uuid(),
15
- profileHash: z.string().min(1)
16
- }).strict(),
17
- signatureVersion: SIGNATURE_VERSION,
18
- parts: (message) => [message.workspaceId, message.profileHash]
19
- };
20
- function jobId(message) {
21
- return `workspace-snapshot_${createHash("sha256").update(message.workspaceId).update("\0").update(message.profileHash).digest("hex").slice(0, 32)}`;
22
- }
23
- /** Sign a Workspace snapshot job for tests and local checks. */
24
- function signWorkspaceSnapshotJobMessage(message, nowMs = Date.now()) {
25
- return signQueueMessage(workspaceSnapshotJobSign, message, nowMs);
26
- }
27
- /** Check that a recent queue message came from Junior. */
28
- function verifyWorkspaceSnapshotJobMessage(value, nowMs = Date.now()) {
29
- return verifyQueueMessage(workspaceSnapshotJobSign, value, nowMs);
30
- }
31
- async function send(message, idempotencyKey) {
32
- const options = { retentionSeconds: QUEUE_SIGNATURE_MAX_AGE_MS / 1e3 };
33
- if (idempotencyKey) options.idempotencyKey = idempotencyKey;
34
- await getQueueProvider().send(WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC, signWorkspaceSnapshotJobMessage(message), options);
35
- }
36
- /** Send a job unless the same Workspace build already has one. */
37
- async function sendWorkspaceSnapshotJob(message) {
38
- await send(message, jobId(message));
39
- }
40
- /** Send the next job for a Workspace build that is still running. */
41
- async function sendNextWorkspaceSnapshotJob(message) {
42
- await send(message);
43
- }
44
- // src/chat/cache-warming/queue.ts
45
- /** Send and receive delayed cache warmup messages. */
46
- /** Deploy topic name. Keep stable for Vercel queue wiring. */
47
- const CACHE_WARMUP_QUEUE_TOPIC = "junior_cache_warmups";
48
- const CACHE_WARMUP_DEV_CONSUMER_GROUP = "junior_cache_warmups_dev";
49
- const cacheWarmupSign = {
50
- context: "junior.cache_warmup_queue.v1",
51
- schema: z.discriminatedUnion("kind", [z.object({
52
- kind: z.literal("warmup"),
53
- conversationId: z.string().min(1),
54
- cycle: z.number().int().positive(),
55
- generation: z.string().min(1),
56
- cacheExpiresAtMs: z.number().int().positive()
57
- }).strict(), z.object({
58
- kind: z.literal("horizon"),
59
- conversationId: z.string().min(1),
60
- generation: z.string().min(1)
61
- }).strict()]),
62
- signatureVersion: "v1",
63
- parts: (message) => [
64
- message.kind,
65
- message.conversationId,
66
- message.generation,
67
- message.kind === "warmup" ? String(message.cycle) : "",
68
- message.kind === "warmup" ? String(message.cacheExpiresAtMs) : ""
69
- ]
70
- };
71
- /** Send a cache warming message that is delivered after `delayMs`. */
72
- async function sendCacheWarmup(message, delayMs) {
73
- await getQueueProvider().send(CACHE_WARMUP_QUEUE_TOPIC, signQueueMessage(cacheWarmupSign, message), {
74
- delaySeconds: Math.max(0, Math.floor(delayMs / 1e3)),
75
- retentionSeconds: message.kind === "warmup" ? Math.min(QUEUE_SIGNATURE_MAX_AGE_MS / 1e3, Math.ceil(Math.max(0, delayMs) / 1e3) + 120) : QUEUE_SIGNATURE_MAX_AGE_MS / 1e3,
76
- idempotencyKey: `cache-warmup_${message.generation}_${message.kind === "warmup" ? message.cycle : message.kind}`
77
- });
78
- }
79
- function logCacheWarmupRejected(reason, metadata, error) {
80
- logWarn("cache_warming.queue_message.rejected", {
81
- "app.queue.consumer_group": metadata.consumerGroup,
82
- "app.queue.delivery_count": metadata.deliveryCount,
83
- "app.queue.message_id": metadata.messageId,
84
- "app.queue.reject_reason": reason,
85
- "app.queue.topic_name": metadata.topicName,
86
- ...error instanceof Error ? { "exception.message": error.message } : void 0
87
- });
88
- }
89
- function cacheWarmupCallback() {
90
- return queueCallback({
91
- consumerGroup: CACHE_WARMUP_DEV_CONSUMER_GROUP,
92
- maxDeliveries: 1,
93
- onRejected: logCacheWarmupRejected,
94
- run: async (message) => {
95
- const { runCacheWarmup } = await import("./warmup--Gkz7iB-.js").then((n) => n.s);
96
- await runCacheWarmup(message);
97
- },
98
- skip: () => !getChatConfig().cacheWarmingEnabled,
99
- topic: CACHE_WARMUP_QUEUE_TOPIC,
100
- verify: (value) => verifyQueueMessage(cacheWarmupSign, value)
101
- });
102
- }
103
- /** Create the HTTP route for cache warmup messages. */
104
- function createVercelCacheWarmupCallback() {
105
- return cacheWarmupCallback().create();
106
- }
107
- /** Return the queue consumer for cache warmups, for a pulling queue worker. */
108
- function cacheWarmupQueueConsumer() {
109
- return cacheWarmupCallback().consumer;
110
- }
111
- /** Receive cache warmup messages during local development. */
112
- function registerVercelCacheWarmupDevConsumer() {
113
- return cacheWarmupCallback().registerDev();
114
- }
115
- export { sendCacheWarmup as a, sendWorkspaceSnapshotJob as c, registerVercelCacheWarmupDevConsumer as i, verifyWorkspaceSnapshotJobMessage as l, cacheWarmupQueueConsumer as n, WORKSPACE_SNAPSHOT_JOB_QUEUE_TOPIC as o, createVercelCacheWarmupCallback as r, sendNextWorkspaceSnapshotJob as s, CACHE_WARMUP_QUEUE_TOPIC as t };
@@ -1,344 +0,0 @@
1
- import * as z from "zod";
2
- // src/chat/scheduled-automations/cadence.ts
3
- const FORMATTERS = /* @__PURE__ */ new Map();
4
- function getFormatter(timezone) {
5
- const existing = FORMATTERS.get(timezone);
6
- if (existing) return existing;
7
- const formatter = new Intl.DateTimeFormat("en-US", {
8
- timeZone: timezone,
9
- hour12: false,
10
- year: "numeric",
11
- month: "2-digit",
12
- day: "2-digit",
13
- hour: "2-digit",
14
- minute: "2-digit",
15
- second: "2-digit"
16
- });
17
- FORMATTERS.set(timezone, formatter);
18
- return formatter;
19
- }
20
- function normalizeHour(hour) {
21
- return hour === 24 ? 0 : hour;
22
- }
23
- function getLocalDateWeekday(date) {
24
- return new Date(Date.UTC(date.year, date.month - 1, date.day)).getUTCDay();
25
- }
26
- function getWeekStart(date) {
27
- return addDays(date, -((getLocalDateWeekday(date) + 6) % 7));
28
- }
29
- /**
30
- * Check that a value is an IANA time zone that this runtime knows. This module
31
- * has no runtime imports, so the dashboard client bundle can use it.
32
- */
33
- function isValidTimeZone(timezone) {
34
- try {
35
- new Intl.DateTimeFormat("en-US", { timeZone: timezone }).format();
36
- return true;
37
- } catch {
38
- return false;
39
- }
40
- }
41
- /** Resolve a UTC timestamp into calendar parts for a named time zone. */
42
- function getZonedDateTimeParts(timestampMs, timezone) {
43
- const parts = getFormatter(timezone).formatToParts(new Date(timestampMs));
44
- const values = new Map(parts.map((part) => [part.type, part.value]));
45
- const year = Number(values.get("year"));
46
- const month = Number(values.get("month"));
47
- const day = Number(values.get("day"));
48
- return {
49
- year,
50
- month,
51
- day,
52
- hour: normalizeHour(Number(values.get("hour"))),
53
- minute: Number(values.get("minute")),
54
- second: Number(values.get("second")),
55
- weekday: getLocalDateWeekday({
56
- year,
57
- month,
58
- day
59
- })
60
- };
61
- }
62
- function getTimeZoneOffsetMs(timestampMs, timezone) {
63
- const parts = getZonedDateTimeParts(timestampMs, timezone);
64
- return Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second) - timestampMs;
65
- }
66
- function localDateTimeToTimestampMs(args) {
67
- const localAsUtcMs = Date.UTC(args.date.year, args.date.month - 1, args.date.day, args.time.hour, args.time.minute, 0);
68
- const offsets = /* @__PURE__ */ new Set();
69
- for (const probeDeltaMs of [
70
- -1296e5,
71
- -432e5,
72
- 0,
73
- 432e5,
74
- 1296e5
75
- ]) offsets.add(getTimeZoneOffsetMs(localAsUtcMs + probeDeltaMs, args.timezone));
76
- const matches = [...offsets].map((offsetMs) => localAsUtcMs - offsetMs).filter((timestampMs) => {
77
- const parts = getZonedDateTimeParts(timestampMs, args.timezone);
78
- return parts.year === args.date.year && parts.month === args.date.month && parts.day === args.date.day && parts.hour === args.time.hour && parts.minute === args.time.minute;
79
- });
80
- if (matches.length === 0) return;
81
- return Math.min(...matches);
82
- }
83
- /** Resolve local time, rejecting DST gaps and choosing the earlier instant in a fold. */
84
- function resolveLocalScheduleAtMs(args) {
85
- const date = parseLocalDate(args.date);
86
- if (!date) return;
87
- return localDateTimeToTimestampMs({
88
- date,
89
- time: args.time,
90
- timezone: args.timezone
91
- });
92
- }
93
- function daysBetween(left, right) {
94
- return Math.floor((Date.UTC(right.year, right.month - 1, right.day) - Date.UTC(left.year, left.month - 1, left.day)) / 864e5);
95
- }
96
- function weeklyRecurrenceMatchesDate(date, start, recurrence) {
97
- if (compareDate(date, start) < 0) return false;
98
- return normalizeWeekdays(recurrence.weekdays).includes(getLocalDateWeekday(date)) && Math.floor(daysBetween(getWeekStart(start), getWeekStart(date)) / 7) % recurrence.interval === 0;
99
- }
100
- function greatestCommonDivisor(left, right) {
101
- let a = Math.abs(left);
102
- let b = Math.abs(right);
103
- while (b !== 0) [a, b] = [b, a % b];
104
- return a;
105
- }
106
- function findNextRunAtMs(args) {
107
- const start = parseLocalDate(args.recurrence.startDate);
108
- const interval = args.recurrence.interval;
109
- if (!start || !Number.isInteger(interval) || interval <= 0) return;
110
- const searchFrom = compareDate(args.searchFrom, start) < 0 ? start : args.searchFrom;
111
- if (args.recurrence.frequency === "daily") {
112
- const offsetDays = daysBetween(start, searchFrom);
113
- let candidateDate = addDays(start, Math.ceil(offsetDays / interval) * interval);
114
- const gregorianCycleDays = 146097;
115
- const candidateCount = gregorianCycleDays / greatestCommonDivisor(gregorianCycleDays, interval);
116
- for (let attempts = 0; attempts < candidateCount; attempts += 1) {
117
- const candidate = buildCandidate({
118
- date: candidateDate,
119
- recurrence: args.recurrence,
120
- timezone: args.timezone
121
- });
122
- if (candidate !== void 0 && candidate > args.afterMs) return candidate;
123
- candidateDate = addDays(candidateDate, interval);
124
- }
125
- return;
126
- }
127
- if (args.recurrence.frequency === "weekly") {
128
- if (normalizeWeekdays(args.recurrence.weekdays).length === 0) return;
129
- let candidateDate = searchFrom;
130
- const gregorianCycleDays = 146097;
131
- const cadenceDays = interval * 7;
132
- const searchDays = gregorianCycleDays * cadenceDays / greatestCommonDivisor(gregorianCycleDays, cadenceDays);
133
- for (let attempts = 0; attempts < searchDays; attempts += 1) {
134
- if (weeklyRecurrenceMatchesDate(candidateDate, start, args.recurrence)) {
135
- const candidate = buildCandidate({
136
- date: candidateDate,
137
- recurrence: args.recurrence,
138
- timezone: args.timezone
139
- });
140
- if (candidate !== void 0 && candidate > args.afterMs) return candidate;
141
- }
142
- candidateDate = addDays(candidateDate, 1);
143
- }
144
- return;
145
- }
146
- if (args.recurrence.frequency === "monthly") {
147
- const startMonth = start.year * 12 + start.month - 1;
148
- const searchMonth = searchFrom.year * 12 + searchFrom.month - 1;
149
- let candidateMonth = startMonth + Math.ceil((searchMonth - startMonth) / interval) * interval;
150
- const gregorianCycleMonths = 4800;
151
- const candidateCount = gregorianCycleMonths / greatestCommonDivisor(gregorianCycleMonths, interval);
152
- for (let attempts = 0; attempts < candidateCount; attempts += 1) {
153
- const candidateDate = {
154
- year: Math.floor(candidateMonth / 12),
155
- month: candidateMonth % 12 + 1,
156
- day: args.recurrence.dayOfMonth ?? 0
157
- };
158
- if (compareDate(candidateDate, searchFrom) >= 0) {
159
- const candidate = buildCandidate({
160
- date: candidateDate,
161
- recurrence: args.recurrence,
162
- timezone: args.timezone
163
- });
164
- if (candidate !== void 0 && candidate > args.afterMs) return candidate;
165
- }
166
- candidateMonth += interval;
167
- }
168
- return;
169
- }
170
- let candidateYear = start.year + Math.ceil((searchFrom.year - start.year) / interval) * interval;
171
- const candidateCount = 400 / greatestCommonDivisor(400, interval);
172
- for (let attempts = 0; attempts < candidateCount; attempts += 1) {
173
- const candidateDate = {
174
- year: candidateYear,
175
- month: args.recurrence.month ?? 0,
176
- day: args.recurrence.dayOfMonth ?? 0
177
- };
178
- if (compareDate(candidateDate, searchFrom) >= 0) {
179
- const candidate = buildCandidate({
180
- date: candidateDate,
181
- recurrence: args.recurrence,
182
- timezone: args.timezone
183
- });
184
- if (candidate !== void 0 && candidate > args.afterMs) return candidate;
185
- }
186
- candidateYear += interval;
187
- }
188
- }
189
- /** Compute the first recurring calendar occurrence strictly after a timestamp. */
190
- function getFirstRunAtMs(args) {
191
- return findNextRunAtMs({
192
- ...args,
193
- searchFrom: getLocalDate(args.afterMs, args.timezone)
194
- });
195
- }
196
- function compareDate(left, right) {
197
- return Date.UTC(left.year, left.month - 1, left.day) - Date.UTC(right.year, right.month - 1, right.day);
198
- }
199
- function addDays(date, days) {
200
- const next = new Date(Date.UTC(date.year, date.month - 1, date.day + days));
201
- return {
202
- year: next.getUTCFullYear(),
203
- month: next.getUTCMonth() + 1,
204
- day: next.getUTCDate()
205
- };
206
- }
207
- function daysInMonth(year, month) {
208
- return new Date(Date.UTC(year, month, 0)).getUTCDate();
209
- }
210
- function parseLocalDate(value) {
211
- const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
212
- if (!match) return;
213
- const year = Number(match[1]);
214
- const month = Number(match[2]);
215
- const day = Number(match[3]);
216
- if (!Number.isInteger(year) || !Number.isInteger(month) || !Number.isInteger(day) || month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) return;
217
- return {
218
- year,
219
- month,
220
- day
221
- };
222
- }
223
- function getLocalDate(timestampMs, timezone) {
224
- const parts = getZonedDateTimeParts(timestampMs, timezone);
225
- return {
226
- year: parts.year,
227
- month: parts.month,
228
- day: parts.day
229
- };
230
- }
231
- function normalizeWeekdays(values) {
232
- return [...new Set((values ?? []).filter((value) => value >= 0 && value <= 6))].sort((a, b) => a - b);
233
- }
234
- function buildCandidate(args) {
235
- return localDateTimeToTimestampMs({
236
- date: args.date,
237
- time: args.recurrence.time,
238
- timezone: args.timezone
239
- });
240
- }
241
- /** Return the next fire time after a completed run, when the task recurs. */
242
- function getNextRunAtMs(task, scheduledForMs, afterMs = scheduledForMs) {
243
- if (task.schedule.kind !== "recurring") return;
244
- const recurrence = task.schedule.recurrence;
245
- if (!recurrence || !Number.isFinite(recurrence.interval) || recurrence.interval <= 0) return;
246
- const timezone = task.schedule.timezone;
247
- const afterDate = getLocalDate(afterMs, timezone);
248
- const nextScheduledDate = addDays(getLocalDate(scheduledForMs, timezone), 1);
249
- return findNextRunAtMs({
250
- afterMs,
251
- recurrence,
252
- searchFrom: compareDate(afterDate, nextScheduledDate) < 0 ? nextScheduledDate : afterDate,
253
- timezone
254
- });
255
- }
256
- // src/chat/notifications/schedule.ts
257
- /**
258
- * Notification hours for one user.
259
- *
260
- * This module imports only zod and the browser-safe cadence helpers, so the
261
- * dashboard client bundle can use it.
262
- */
263
- const clockTimePattern = /^([01]\d|2[0-3]):[0-5]\d$/;
264
- /** Saved notification hours. Weekdays use 0 for Sunday, like `Date#getDay`. */
265
- const notificationScheduleSchema = z.object({
266
- /**
267
- * Follow the linked Slack user's notification schedule. The fields below
268
- * apply only when Junior cannot read it. Absent means on.
269
- */
270
- followSlack: z.boolean().optional(),
271
- /** When false, Junior sends push notifications at any time. */
272
- workingHoursOnly: z.boolean(),
273
- days: z.array(z.number().int().min(0).max(6)).max(7).refine((days) => new Set(days).size === days.length, { message: "Days must be unique." }),
274
- /** Local start time, `HH:MM`. */
275
- start: z.string().regex(clockTimePattern),
276
- /** Local end time, `HH:MM`. An end before the start crosses midnight. */
277
- end: z.string().regex(clockTimePattern),
278
- /** IANA timezone set by the user. Absent means the profile timezone. */
279
- timezone: z.string().min(1).max(64).refine(isValidTimeZone, { message: "Unknown timezone." }).optional()
280
- }).strict().refine((schedule) => schedule.start !== schedule.end, {
281
- message: "Start and end must differ.",
282
- path: ["end"]
283
- });
284
- /**
285
- * Default when a user has not saved a schedule: follow Slack, else
286
- * 09:00–18:00, Mon–Fri.
287
- */
288
- const DEFAULT_NOTIFICATION_SCHEDULE = {
289
- followSlack: true,
290
- workingHoursOnly: true,
291
- days: [
292
- 1,
293
- 2,
294
- 3,
295
- 4,
296
- 5
297
- ],
298
- start: "09:00",
299
- end: "18:00"
300
- };
301
- function clockMinutes(value) {
302
- const [hours, minutes] = value.split(":").map(Number);
303
- return hours * 60 + minutes;
304
- }
305
- const weekdayIndex = {
306
- Sun: 0,
307
- Mon: 1,
308
- Tue: 2,
309
- Wed: 3,
310
- Thu: 4,
311
- Fri: 5,
312
- Sat: 6
313
- };
314
- function localWeekdayAndMinutes(nowMs, timezone) {
315
- const parts = new Intl.DateTimeFormat("en-US", {
316
- hour: "2-digit",
317
- hourCycle: "h23",
318
- minute: "2-digit",
319
- timeZone: timezone,
320
- weekday: "short"
321
- }).formatToParts(new Date(nowMs));
322
- const value = (type) => parts.find((part) => part.type === type)?.value ?? "";
323
- const weekday = weekdayIndex[value("weekday")];
324
- if (weekday === void 0) throw new Error(`Could not read the weekday for timezone ${timezone}`);
325
- return {
326
- minutes: Number(value("hour")) % 24 * 60 + Number(value("minute")),
327
- weekday
328
- };
329
- }
330
- /**
331
- * Return whether a notification may be sent now. A window that crosses
332
- * midnight belongs to the day on which it starts.
333
- */
334
- function isWithinNotificationSchedule(schedule, timezone, nowMs) {
335
- if (!schedule.workingHoursOnly) return true;
336
- const { minutes, weekday } = localWeekdayAndMinutes(nowMs, timezone);
337
- const start = clockMinutes(schedule.start);
338
- const end = clockMinutes(schedule.end);
339
- if (start < end) return schedule.days.includes(weekday) && minutes >= start && minutes < end;
340
- if (minutes >= start) return schedule.days.includes(weekday);
341
- if (minutes < end) return schedule.days.includes((weekday + 6) % 7);
342
- return false;
343
- }
344
- export { getNextRunAtMs as a, resolveLocalScheduleAtMs as c, getFirstRunAtMs as i, isWithinNotificationSchedule as n, getZonedDateTimeParts as o, notificationScheduleSchema as r, isValidTimeZone as s, DEFAULT_NOTIFICATION_SCHEDULE as t };
@@ -1,18 +0,0 @@
1
- // src/chat/secrets.ts
2
- /** Read the server secret that signs internal tokens and payloads. */
3
- function readJuniorSecret() {
4
- return process.env["JUNIOR_SECRET"]?.trim() || void 0;
5
- }
6
- /** Read the raw dashboard session secret, with `JUNIOR_SECRET` as fallback. */
7
- function readSignInSecret() {
8
- return process.env["BETTER_AUTH_SECRET"] ?? process.env["JUNIOR_SECRET"];
9
- }
10
- /** Read the bearer secret that internal cron requests must send. */
11
- function readSchedulerSecret() {
12
- return process.env["JUNIOR_SCHEDULER_SECRET"]?.trim() || process.env["CRON_SECRET"]?.trim();
13
- }
14
- /** Read the VAPID private key that signs web push messages. */
15
- function readWebPushPrivateKey() {
16
- return process.env["JUNIOR_WEB_PUSH_PRIVATE_KEY"]?.trim();
17
- }
18
- export { readWebPushPrivateKey as i, readSchedulerSecret as n, readSignInSecret as r, readJuniorSecret as t };
@@ -1,89 +0,0 @@
1
- import { h as logWarn } from "./logging-BPNTQVFu.js";
2
- import { a as queueCallback, d as verifyQueueMessage, f as getQueueProvider, l as QUEUE_SIGNATURE_MAX_AGE_MS, u as signQueueMessage } from "./background-compaction-queue-BTqMIfTA.js";
3
- import * as z from "zod";
4
- import { createHash } from "node:crypto";
5
- // src/chat/plugins/task-queue.ts
6
- /**
7
- * Delivery for plugin-registered tasks.
8
- *
9
- * Plugins register named tasks. This module owns the shared signed message,
10
- * send path, and HTTP/local callback. Core keeps one topic and one runner.
11
- */
12
- /** Deploy topic name. Keep stable for Vercel queue wiring. */
13
- const PLUGIN_TASK_QUEUE_TOPIC = "junior_plugin_tasks";
14
- const PLUGIN_TASK_DEV_CONSUMER_GROUP = "junior_plugin_tasks_dev";
15
- const PLUGIN_TASK_MAX_DELIVERIES = 5;
16
- const PLUGIN_TASK_SIGN_CONTEXT = "junior.plugin_task_queue.v1";
17
- const PLUGIN_TASK_SIGN_VERSION = "v1";
18
- const pluginTaskParamsSchema = z.object({
19
- conversationId: z.string().min(1),
20
- sessionId: z.string().min(1)
21
- }).strict();
22
- const pluginTaskSign = {
23
- context: PLUGIN_TASK_SIGN_CONTEXT,
24
- schema: z.object({
25
- name: z.string().min(1),
26
- params: pluginTaskParamsSchema,
27
- plugin: z.string().min(1)
28
- }).strict(),
29
- signatureVersion: PLUGIN_TASK_SIGN_VERSION,
30
- parts: (message) => [
31
- message.plugin,
32
- message.name,
33
- message.params.conversationId,
34
- message.params.sessionId
35
- ]
36
- };
37
- /** Build the stable id used for delivery dedupe and tracing. */
38
- function pluginTaskId(args) {
39
- return `plugin-task_${createHash("sha256").update(args.plugin).update("\0").update(args.name).update("\0").update(args.params.conversationId).update("\0").update(args.params.sessionId).digest("hex").slice(0, 32)}`;
40
- }
41
- /** Sign a plugin task message for tests and local checks. */
42
- function signPluginTaskQueueMessage(message, nowMs = Date.now()) {
43
- return signQueueMessage(pluginTaskSign, message, nowMs);
44
- }
45
- function verifyPluginTaskQueueMessage(value, nowMs = Date.now()) {
46
- return verifyQueueMessage(pluginTaskSign, value, nowMs);
47
- }
48
- function logPluginTaskQueueMessageRejected(reason, metadata) {
49
- logWarn("plugin.task.queue_message.rejected", {
50
- "app.queue.consumer_group": metadata.consumerGroup,
51
- "app.queue.delivery_count": metadata.deliveryCount,
52
- "app.queue.message_id": metadata.messageId,
53
- "app.queue.reject_reason": reason,
54
- "app.queue.topic_name": metadata.topicName
55
- });
56
- }
57
- function pluginTaskCallback() {
58
- return queueCallback({
59
- consumerGroup: PLUGIN_TASK_DEV_CONSUMER_GROUP,
60
- maxDeliveries: PLUGIN_TASK_MAX_DELIVERIES,
61
- onRejected: logPluginTaskQueueMessageRejected,
62
- run: async (message) => {
63
- const { processPluginTask } = await import("./task-runner-xsOPIxCZ.js").then((n) => n.r);
64
- await processPluginTask(message);
65
- },
66
- topic: PLUGIN_TASK_QUEUE_TOPIC,
67
- verify: verifyPluginTaskQueueMessage
68
- });
69
- }
70
- /** Send one plugin task through the shared signed delivery path. */
71
- async function sendVercelPluginTask(message) {
72
- await getQueueProvider().send(PLUGIN_TASK_QUEUE_TOPIC, signPluginTaskQueueMessage(message), {
73
- idempotencyKey: pluginTaskId(message),
74
- retentionSeconds: QUEUE_SIGNATURE_MAX_AGE_MS / 1e3
75
- });
76
- }
77
- /** Create the HTTP callback for plugin tasks. */
78
- function createVercelPluginTaskCallback() {
79
- return pluginTaskCallback().create();
80
- }
81
- /** Return the queue consumer for plugin tasks, for a pulling queue worker. */
82
- function pluginTaskQueueConsumer() {
83
- return pluginTaskCallback().consumer;
84
- }
85
- /** Register the local-dev consumer for plugin tasks. */
86
- function registerVercelPluginTaskDevConsumer() {
87
- return pluginTaskCallback().registerDev();
88
- }
89
- export { pluginTaskQueueConsumer as a, pluginTaskParamsSchema as i, createVercelPluginTaskCallback as n, registerVercelPluginTaskDevConsumer as o, pluginTaskId as r, sendVercelPluginTask as s, PLUGIN_TASK_QUEUE_TOPIC as t };