@sentry/junior 0.315.0 → 0.317.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 (139) hide show
  1. package/dist/{admin-5jUYY46p.js → admin-CAugg87B.js} +1 -1
  2. package/dist/{agent-runner-C7GNLRB6.js → agent-runner-AjrEV6Qe.js} +13532 -12811
  3. package/dist/{reporting-window-C4dbzDiR.js → agent-status-BA5x3Xtp.js} +33 -1
  4. package/dist/{agent-update-delivery-BNEYQsAf.js → agent-update-delivery-B_YIZcgf.js} +10 -37
  5. package/dist/api/schema.d.ts +609 -104
  6. package/dist/api/schema.js +6 -6
  7. package/dist/api.js +373 -469
  8. package/dist/{app-D_bAXRDe.d.ts → app-MoNAsVV5.d.ts} +52 -28
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +177 -132
  11. package/dist/catalog-runtime-DfSpJZdY.js +6 -0
  12. package/dist/{change-record-Bqsa5ZXE.d.ts → change-record-BzJgLsv7.d.ts} +60 -1
  13. package/dist/{adapter-context-BlSGE44V.js → channel-access-j-YAVYK4.js} +2 -42
  14. package/dist/{chat-core-engine-CxkwRpn9.js → chat-core-engine-aH85nEHv.js} +4 -3
  15. package/dist/{child-message--2G3Ft26.js → child-message-DHjQLEd1.js} +1 -1
  16. package/dist/cli/chat.js +23 -23
  17. package/dist/cli/check.js +5 -5
  18. package/dist/cli/main.js +2 -2
  19. package/dist/cli/plugins.js +5 -4
  20. package/dist/cli/snapshot-create.js +5 -2
  21. package/dist/cli/upgrade.js +27 -5
  22. package/dist/config-CHQ8X251.js +2422 -0
  23. package/dist/{continue-in-slack-BGKjIdFp.js → continue-in-slack-D-FZ8Fin.js} +2 -3
  24. package/dist/{conversation-feed-Sl8lKKmR.js → conversation-feed--9S0_PXL.js} +9 -4
  25. package/dist/{proxy-path-Dc-0jXGi.js → conversation-privacy-B1uXn5sf.js} +2 -16
  26. package/dist/{conversation-turn-BoLK9i6g.js → conversation-turn-BUE_7xaN.js} +102 -172
  27. package/dist/{create-BOycVH9h.js → create-DoDIYgtZ.js} +12 -10
  28. package/dist/{credential-sync-Mn4OdkEh.js → credential-sync-BJOqGnjV.js} +17 -12
  29. package/dist/{db-DXTOYRzR.js → db-BFmyYZtJ.js} +20276 -27398
  30. package/dist/{deployment-CG3TchWh.js → deployment-DXq9ZLU4.js} +17 -15
  31. package/dist/{engine-context-dyWlfNdD.js → engine-context-CgQ7mlHt.js} +264 -50
  32. package/dist/{html-CfXEwl_h.js → html-B3VKTGbJ.js} +6 -2
  33. package/dist/instrumentation.js +15 -7
  34. package/dist/{job-runner-CySgpi9v.js → job-runner-A1lCkybD.js} +397 -22
  35. package/dist/{lineage-tRTOcrsL.js → lineage-Bktb0UcV.js} +1 -1
  36. package/dist/{list-DXBz8SYL.js → list-Bxvg5wXf.js} +260 -698
  37. package/dist/{logging-czs0nqLC.js → logging--smS7XRK.js} +2 -2
  38. package/dist/{mailbox-turn-79Nv1JXv.js → mailbox-turn-uSXhUFc9.js} +648 -2957
  39. package/dist/{message-BTox2Cmb.js → message-BNenhsmB.js} +12 -22
  40. package/dist/{model-input-IRGa98V7.js → model-input-BReSnwHp.js} +3 -3
  41. package/dist/nitro.d.ts +1 -1
  42. package/dist/nitro.js +20 -6
  43. package/dist/{oauth-callback-server-NXK7AlBp.js → oauth-callback-server-CE4soEIY.js} +2 -2
  44. package/dist/{oauth-relay-6NBPSpFE.js → oauth-relay-C36gX1gH.js} +2 -2
  45. package/dist/{package-discovery-BI6T_RkD.js → package-discovery-DD9vencX.js} +1 -50
  46. package/dist/{parent-result-Dg6P6roR.js → parent-result-Ck1rFYRQ.js} +93 -106
  47. package/dist/{plugins-BXMdNdyA.js → plugins-D_Ru4CWc.js} +1 -1
  48. package/dist/profile-BQ-iBDsZ.js +4657 -0
  49. package/dist/{transcript-BHhJVY0P.js → prompt-Dv7gkpD6.js} +97 -103
  50. package/dist/proxy-path-BHYoKZdq.js +15 -0
  51. package/dist/registry-iXMT5Jmh.js +3279 -0
  52. package/dist/reports-WKHfGTsU.js +195 -0
  53. package/dist/{resolve-BUFkmxkT.js → resolve-tony4ibz.js} +9 -29
  54. package/dist/{result-DfATzX77.js → result-Bta_dlWa.js} +42 -117
  55. package/dist/run-conversation-DL6ru7iW.js +336 -0
  56. package/dist/{runner-CmKP3inb.js → runner-BstDRbD9.js} +7 -7
  57. package/dist/{sandbox-egress-signals-DYo5BsM7.js → sandbox-egress-signals-oSJMJOnn.js} +1 -1
  58. package/dist/{schema-DrBMdPmv.js → schema-DfqrHACA.js} +67 -84
  59. package/dist/sender-actors-CPglLd5R.js +83 -0
  60. package/dist/{service-account-CxTX7nnR.js → service-account-CTV_jaNu.js} +3 -1
  61. package/dist/{skills-BlHUDj7k.js → skills-BCEU41zM.js} +4 -4
  62. package/dist/{slack-conversation-unfurl-Dhe3lB1U.js → slack-conversation-unfurl-DxVmhbGP.js} +7 -6
  63. package/dist/{spawn-CfvlFdfz.js → spawn-frczVPIr.js} +11 -8
  64. package/dist/{system-prompt-table-CDCYVwqN.js → system-prompt-table-CiXy0eNR.js} +91 -70
  65. package/dist/{task-runner-DcdQJd9e.js → task-runner-C9Yc2_ae.js} +35 -49
  66. package/dist/{thread-context-DF5uDcWN.js → thread-context-CqZDKErp.js} +6 -6
  67. package/dist/topics-SRN7IVX-.js +24 -0
  68. package/dist/turn-membership-CENFf3kI.js +856 -0
  69. package/dist/{turn-wake-um5Ubd4m.js → turn-wake-BhloiI2h.js} +4 -5
  70. package/dist/{media-Cr9pGkzr.js → types-C4iC-IMC.js} +819 -777
  71. package/dist/user-customization-CvfuY9Eo.js +93 -0
  72. package/dist/users-ByG5RCEJ.js +181 -0
  73. package/dist/{validation-CJyuOPD2.js → validation-8gjfR91V.js} +1 -1
  74. package/dist/{version-Bhe7RPIe.js → version-BeZhWWBE.js} +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/{worker-D8PRgUqr.js → worker-BqMQQNRk.js} +5 -4
  77. package/migrations/20261125171254_conversation_visibility/migration.sql +4 -0
  78. package/migrations/20261125171254_conversation_visibility/snapshot.json +67 -0
  79. package/migrations/20261125171257_conversation_visibility_backfill/migration.sql +25 -0
  80. package/migrations/20261125171257_conversation_visibility_backfill/snapshot.json +9 -0
  81. package/migrations/20261125213232_drop_versions_notify/migration.sql +19 -0
  82. package/migrations/20261125213232_drop_versions_notify/snapshot.json +9 -0
  83. package/migrations/20261125225138_conversation_kind_root_thread/migration.sql +23 -0
  84. package/migrations/20261125225138_conversation_kind_root_thread/snapshot.json +55 -0
  85. package/migrations/20261125225142_conversation_kind_root_thread_backfill/migration.sql +7 -0
  86. package/migrations/20261125225142_conversation_kind_root_thread_backfill/snapshot.json +9 -0
  87. package/migrations/20261126000151_conversation_event_message_role_seq_index/migration.sql +1 -0
  88. package/migrations/20261126000151_conversation_event_message_role_seq_index/snapshot.json +69 -0
  89. package/migrations/20261126012917_merge_leaves/migration.sql +2 -0
  90. package/migrations/20261126012917_merge_leaves/snapshot.json +12 -0
  91. package/migrations/20261126025226_drop_agent_invocations/migration.sql +6 -0
  92. package/migrations/20261126025226_drop_agent_invocations/snapshot.json +9 -0
  93. package/migrations/20261126033000_space_conversations_lead_children/migration.sql +155 -0
  94. package/migrations/20261126033000_space_conversations_lead_children/snapshot.json +9 -0
  95. package/migrations/20261126144620_drop_user_message_time_index/migration.sql +1 -0
  96. package/migrations/20261126144620_drop_user_message_time_index/snapshot.json +38 -0
  97. package/migrations/20261126153100_inbox_item_subjects/migration.sql +140 -0
  98. package/migrations/20261126153100_inbox_item_subjects/snapshot.json +9 -0
  99. package/migrations/20261126153103_inbox_item_subjects_not_null/migration.sql +12 -0
  100. package/migrations/20261126153103_inbox_item_subjects_not_null/snapshot.json +9 -0
  101. package/migrations/20261126153105_inbox_item_subject_indexes/migration.sql +1 -0
  102. package/migrations/20261126153105_inbox_item_subject_indexes/snapshot.json +9 -0
  103. package/migrations/20261126153108_automation_run_conversation_index/migration.sql +1 -0
  104. package/migrations/20261126153108_automation_run_conversation_index/snapshot.json +9 -0
  105. package/migrations/20261126153159_inbox_item_subjects_schema/migration.sql +4 -0
  106. package/migrations/20261126153159_inbox_item_subjects_schema/snapshot.json +437 -0
  107. package/migrations/20261126153259_inbox_questions/migration.sql +76 -0
  108. package/migrations/20261126153259_inbox_questions/snapshot.json +9 -0
  109. package/migrations/20261126153301_inbox_questions_valid/migration.sql +3 -0
  110. package/migrations/20261126153301_inbox_questions_valid/snapshot.json +9 -0
  111. package/migrations/20261126153343_inbox_questions_schema/migration.sql +5 -0
  112. package/migrations/20261126153343_inbox_questions_schema/snapshot.json +407 -0
  113. package/migrations/20261126154025_inbox_item_owners/migration.sql +74 -0
  114. package/migrations/20261126154025_inbox_item_owners/snapshot.json +9 -0
  115. package/migrations/20261126154048_inbox_item_open_subject_key_index/migration.sql +1 -0
  116. package/migrations/20261126154048_inbox_item_open_subject_key_index/snapshot.json +9 -0
  117. package/migrations/20261126154051_drop_inbox_item_owner_indexes/migration.sql +7 -0
  118. package/migrations/20261126154051_drop_inbox_item_owner_indexes/snapshot.json +9 -0
  119. package/migrations/20261126154121_inbox_item_owners_schema/migration.sql +8 -0
  120. package/migrations/20261126154121_inbox_item_owners_schema/snapshot.json +311 -0
  121. package/migrations/20261126175601_conversation_event_turn/migration.sql +5 -0
  122. package/migrations/20261126175601_conversation_event_turn/snapshot.json +103 -0
  123. package/migrations/20261126175614_conversation_event_turn_index/migration.sql +1 -0
  124. package/migrations/20261126175614_conversation_event_turn_index/snapshot.json +62 -0
  125. package/migrations/20261126230028_merge_leaves/migration.sql +2 -0
  126. package/migrations/20261126230028_merge_leaves/snapshot.json +12 -0
  127. package/migrations/20261126231932_space_lead_holds_name/migration.sql +46 -0
  128. package/migrations/20261126231932_space_lead_holds_name/snapshot.json +58 -0
  129. package/migrations/20261127001022_merge_leaves/migration.sql +2 -0
  130. package/migrations/20261127001022_merge_leaves/snapshot.json +12 -0
  131. package/package.json +5 -5
  132. package/skills/jr-rpc/SKILL.md +3 -5
  133. package/dist/direct-url-BYgYfuIy.js +0 -22
  134. package/dist/markers-CE0HMXWT.js +0 -67
  135. package/dist/people-Cegp1Iwq.js +0 -81
  136. package/dist/start-conversation-Uh8Sk1EF.js +0 -162
  137. package/dist/turn-session-routing-GtetHsdO.js +0 -1309
  138. package/dist/user-customization-B27StpVQ.js +0 -9
  139. package/dist/web-message-id-C6P83ans.js +0 -10
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "b0589de0-a625-4e86-86be-e62c1bd9cdae",
6
+ "prevIds": ["0e1b857d-8d81-45fd-b576-822a76b32c70"],
7
+ "footprints": [],
8
+ "deltas": []
9
+ }
@@ -0,0 +1,155 @@
1
+ -- A Space's Conversations are now children of its Lead, and only the Lead
2
+ -- stores `space_id`. The Lead is the root of every Conversation in its
3
+ -- Space, so `root_conversation_id` of each moved Conversation's work becomes
4
+ -- the Lead.
5
+
6
+ -- A Space that has no Lead yet gets one, as the first open of the Space
7
+ -- would make it. Its first Actor is the Space's creator. The Lead holds the
8
+ -- Space's Conversations and, as its Participants, the Space's members.
9
+ WITH "needs_lead" AS (
10
+ SELECT
11
+ "space"."id" AS "space_id",
12
+ "space"."name",
13
+ "space"."visibility",
14
+ 'local:web:' || gen_random_uuid()::text AS "conversation_id",
15
+ gen_random_uuid()::text AS "destination_id",
16
+ (
17
+ SELECT "identity"."id"
18
+ FROM "junior_identities" "identity"
19
+ WHERE "identity"."user_id" = "space"."created_by_user_id"
20
+ ORDER BY ("identity"."provider" = 'web') DESC, "identity"."created_at"
21
+ LIMIT 1
22
+ ) AS "actor_identity_id"
23
+ FROM "junior_spaces" "space"
24
+ WHERE NOT EXISTS (
25
+ SELECT 1
26
+ FROM "junior_conversations" "lead"
27
+ WHERE "lead"."space_id" = "space"."id" AND "lead"."kind" = 'lead'
28
+ )
29
+ ),
30
+ "lead_destination" AS (
31
+ INSERT INTO "junior_destinations" (
32
+ "id",
33
+ "provider",
34
+ "provider_tenant_id",
35
+ "provider_destination_id",
36
+ "kind",
37
+ "visibility",
38
+ "metadata_json",
39
+ "created_at",
40
+ "updated_at"
41
+ )
42
+ SELECT
43
+ "destination_id",
44
+ 'local',
45
+ 'web',
46
+ "conversation_id",
47
+ 'local_conversation',
48
+ "visibility",
49
+ '{"platform":"local"}'::jsonb,
50
+ now(),
51
+ now()
52
+ FROM "needs_lead"
53
+ )
54
+ INSERT INTO "junior_conversations" (
55
+ "conversation_id",
56
+ "source",
57
+ "source_json",
58
+ "destination_id",
59
+ "actor_identity_id",
60
+ "title",
61
+ "created_at",
62
+ "last_activity_at",
63
+ "updated_at",
64
+ "execution_updated_at",
65
+ "execution_status",
66
+ "root_conversation_id",
67
+ "kind",
68
+ "space_id",
69
+ "visibility"
70
+ )
71
+ SELECT
72
+ "conversation_id",
73
+ 'web',
74
+ jsonb_build_object(
75
+ 'kind', 'web',
76
+ 'visibility', "visibility",
77
+ 'conversationId', "conversation_id"
78
+ ),
79
+ "destination_id",
80
+ "actor_identity_id",
81
+ "name",
82
+ now(),
83
+ now(),
84
+ now(),
85
+ now(),
86
+ 'idle',
87
+ "conversation_id",
88
+ 'lead',
89
+ "space_id",
90
+ "visibility"
91
+ FROM "needs_lead";
92
+ --> statement-breakpoint
93
+
94
+ -- A move never makes private work public, so a private Conversation in a
95
+ -- public Space leaves the Space and stays a private one-off. An Automation
96
+ -- run never has a parent, so it leaves its Space too.
97
+ -- junior:bounded-backfill: runs once, on the few roots in a Space. Spaces are new and small.
98
+ UPDATE "junior_conversations"
99
+ SET "space_id" = NULL, "detail_version" = "detail_version" + 1
100
+ WHERE "space_id" IS NOT NULL
101
+ AND "kind" IS DISTINCT FROM 'lead'
102
+ AND (
103
+ "kind" = 'automation'
104
+ OR (
105
+ "visibility" IS DISTINCT FROM 'public'
106
+ AND "space_id" IN (
107
+ SELECT "id" FROM "junior_spaces" WHERE "visibility" = 'public'
108
+ )
109
+ )
110
+ );
111
+ --> statement-breakpoint
112
+
113
+ -- The work of every other root in a Space joins the Lead's tree.
114
+ -- junior:bounded-backfill: runs once, on the work of the few roots in a Space. Spaces are new and small.
115
+ UPDATE "junior_conversations" "work"
116
+ SET
117
+ "root_conversation_id" = "lead"."conversation_id",
118
+ "detail_version" = "work"."detail_version" + 1
119
+ FROM "junior_conversations" "member", "junior_conversations" "lead"
120
+ WHERE "lead"."kind" = 'lead'
121
+ AND "lead"."space_id" = "member"."space_id"
122
+ AND "member"."kind" IS DISTINCT FROM 'lead'
123
+ AND "member"."parent_conversation_id" IS NULL
124
+ AND coalesce("work"."root_conversation_id", "work"."conversation_id") = "member"."conversation_id";
125
+ --> statement-breakpoint
126
+
127
+ -- Each such root becomes a child of the Space's Lead. A Lead's children are
128
+ -- its child agents, so each stores an agent config.
129
+ -- junior:bounded-backfill: runs once, on the few roots in a Space. Spaces are new and small.
130
+ UPDATE "junior_conversations" "member"
131
+ SET
132
+ "parent_conversation_id" = "lead"."conversation_id",
133
+ "agent_config_json" = coalesce("member"."agent_config_json", '{}'::jsonb),
134
+ "space_id" = NULL,
135
+ "detail_version" = "member"."detail_version" + 1
136
+ FROM "junior_conversations" "lead"
137
+ WHERE "lead"."kind" = 'lead'
138
+ AND "lead"."space_id" = "member"."space_id"
139
+ AND "member"."kind" IS DISTINCT FROM 'lead'
140
+ AND "member"."parent_conversation_id" IS NULL;
141
+ --> statement-breakpoint
142
+
143
+ -- A Space's members become the Participants of its Lead. A member who was
144
+ -- already one keeps their row.
145
+ -- junior:bounded-backfill: runs once, on the few members of each Space. Spaces are new and small.
146
+ INSERT INTO "junior_conversation_participants" (
147
+ "user_id",
148
+ "root_conversation_id",
149
+ "last_message_at"
150
+ )
151
+ SELECT "member"."user_id", "lead"."conversation_id", "member"."joined_at"
152
+ FROM "junior_space_members" "member"
153
+ JOIN "junior_conversations" "lead"
154
+ ON "lead"."space_id" = "member"."space_id" AND "lead"."kind" = 'lead'
155
+ ON CONFLICT ("user_id", "root_conversation_id") DO NOTHING;
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "3b9b0905-bde7-4127-8ac0-cb005dd77b4f",
6
+ "prevIds": ["b0589de0-a625-4e86-86be-e62c1bd9cdae"],
7
+ "footprints": [],
8
+ "deltas": []
9
+ }
@@ -0,0 +1 @@
1
+ DROP INDEX "junior_conversation_events_user_message_time_idx";
@@ -0,0 +1,38 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "7fa7b36c-167a-4f6b-8b90-a14c8028e3a5",
6
+ "prevIds": ["3b9b0905-bde7-4127-8ac0-cb005dd77b4f"],
7
+ "footprints": [
8
+ {
9
+ "statementType": "drop_index",
10
+ "statementTarget": [
11
+ "index",
12
+ "public",
13
+ "junior_conversation_events",
14
+ "junior_conversation_events_user_message_time_idx"
15
+ ],
16
+ "writes": [
17
+ "s|idx|public.junior_conversation_events_user_message_time_idx",
18
+ "n|idx|public.junior_conversation_events_user_message_time_idx",
19
+ "e|idx|public.junior_conversation_events_user_message_time_idx",
20
+ "n|rel|public.junior_conversation_events_user_message_time_idx"
21
+ ],
22
+ "reads": [
23
+ "e|tbl|public.junior_conversation_events",
24
+ "n|sch|public",
25
+ "e|col|public.junior_conversation_events.conversation_id",
26
+ "e|col|public.junior_conversation_events.created_at",
27
+ "e|col|public.junior_conversation_events.seq"
28
+ ],
29
+ "sharedWrites": []
30
+ }
31
+ ],
32
+ "deltas": [
33
+ {
34
+ "op": "drop",
35
+ "key": "indexes\u0000[\"public\",\"junior_conversation_events_user_message_time_idx\"]"
36
+ }
37
+ ]
38
+ }
@@ -0,0 +1,140 @@
1
+ ALTER TABLE "junior_inbox_items" ADD COLUMN "subject_kind" text;--> statement-breakpoint
2
+ -- Each item gets its subject. The kind comes from the old key prefix. The
3
+ -- subject kind and id now name the item. New code still gets a dedupe key,
4
+ -- and the other old columns and checks stay, so the release before this
5
+ -- one can still read and write every row after a rollback
6
+ -- (20261126154025_inbox_item_owners). A later release drops them.
7
+ -- A GitHub pull request has one item for all of its asks, and its id is
8
+ -- GitHub's id of the pull request, read from the code change records by the
9
+ -- repository and number in the old key, or else by the number and the owner
10
+ -- Conversation, after a repository rename. A plugin item uses its subject
11
+ -- link as the id when it had one. An agent's item is a question, and its
12
+ -- old key is its id, so two questions about one object stay two items. Its
13
+ -- old subject link, in `subject_url` or else in `subject_id`, becomes its
14
+ -- first evidence link. A notice keeps no request, so its link stays in
15
+ -- `subject_url`, and its question reads it from there
16
+ -- (20261126153259_inbox_questions).
17
+ -- `automation_id` needs no copy:
18
+ -- the run of the owner Conversation names the same Automation.
19
+ --
20
+ -- Old workers still add items without a subject while this release rolls
21
+ -- out, so a trigger gives each such row its subject by the same rules. The
22
+ -- backfill below fires the same trigger.
23
+ --
24
+ -- New code stores each http(s) evidence link as `URL.href`, so a link
25
+ -- matches the same link that another item cites. Postgres has no URL
26
+ -- parser, so this function makes only the common changes of `URL.href`: it
27
+ -- lowercases the scheme and host, and gives a bare origin its `/`. It goes
28
+ -- with the legacy trigger.
29
+ CREATE OR REPLACE FUNCTION "junior_inbox_items_web_link"(link text)
30
+ RETURNS text
31
+ LANGUAGE sql
32
+ IMMUTABLE
33
+ AS $function$
34
+ SELECT lower(origin) || CASE WHEN rest = '' OR left(rest, 1) IN ('?', '#') THEN '/' || rest ELSE rest END
35
+ FROM (SELECT substring(link from '^[A-Za-z][A-Za-z0-9+.-]*://[^/?#]*') AS origin) AS parts,
36
+ LATERAL (SELECT substr(link, length(origin) + 1) AS rest) AS tail
37
+ $function$;--> statement-breakpoint
38
+ CREATE OR REPLACE FUNCTION "junior_inbox_items_legacy_subject"()
39
+ RETURNS trigger
40
+ LANGUAGE plpgsql
41
+ AS $function$
42
+ DECLARE
43
+ github_ref text := CASE
44
+ WHEN NEW."dedupe_key" ~ '^plugin:github:(pull-request-action|pull-request-ready|pull-request-review-requested|merge-conflict):[^#]+#[0-9]+$'
45
+ THEN regexp_replace(NEW."dedupe_key", '^plugin:github:[a-z-]+:', '')
46
+ END;
47
+ github_id text;
48
+ -- An agent item kept its link in `subject_url`, or else in `subject_id`.
49
+ legacy_link text := "junior_inbox_items_web_link"(CASE
50
+ WHEN NEW."subject_url" ~* '^https?://' THEN NEW."subject_url"
51
+ WHEN NEW."subject_id" ~* '^https?://' THEN NEW."subject_id"
52
+ END);
53
+ BEGIN
54
+ IF github_ref IS NOT NULL THEN
55
+ SELECT c."provider_id" INTO github_id
56
+ FROM "junior_code_changes" c
57
+ JOIN "junior_code_repositories" r ON r."id" = c."repository_id"
58
+ WHERE c."provider" = 'github'
59
+ AND lower(r."name") = lower(split_part(github_ref, '#', 1))
60
+ AND c."number" = split_part(github_ref, '#', 2)::integer
61
+ LIMIT 1;
62
+ -- A renamed repository no longer matches the name in the key. Then the
63
+ -- change with that number that the owner Conversation opened names the
64
+ -- id, when only one change matches.
65
+ IF github_id IS NULL AND NEW."owner_kind" = 'conversation' THEN
66
+ SELECT min(c."provider_id") INTO github_id
67
+ FROM "junior_code_changes" c
68
+ WHERE c."provider" = 'github'
69
+ AND c."number" = split_part(github_ref, '#', 2)::integer
70
+ AND c."conversation_ids" @> ARRAY[NEW."owner_id"]
71
+ HAVING count(*) = 1;
72
+ END IF;
73
+ END IF;
74
+ NEW."subject_kind" := CASE
75
+ WHEN NEW."owner_kind" = 'automation' THEN 'automation'
76
+ WHEN NEW."dedupe_key" LIKE 'plugin:github:merge-conflict:%' THEN 'github:merge_conflict'
77
+ WHEN github_ref IS NOT NULL THEN 'github:pull_request'
78
+ WHEN NEW."dedupe_key" LIKE 'plugin:%' THEN split_part(NEW."dedupe_key", ':', 2) || ':item'
79
+ WHEN NEW."dedupe_key" LIKE 'reply:%' THEN 'reply'
80
+ WHEN NEW."dedupe_key" LIKE 'todo:%' THEN 'todo'
81
+ ELSE 'question'
82
+ END;
83
+ NEW."subject_id" := CASE
84
+ WHEN NEW."owner_kind" = 'automation' THEN NEW."owner_id"
85
+ WHEN NEW."dedupe_key" LIKE 'reply:%' THEN NEW."owner_id"
86
+ WHEN NEW."dedupe_key" LIKE 'todo:%' THEN substr(NEW."dedupe_key", length('todo:') + 1)
87
+ WHEN github_ref IS NOT NULL THEN coalesce(github_id, NEW."subject_url", github_ref)
88
+ WHEN NEW."dedupe_key" LIKE 'plugin:%' THEN coalesce(NEW."subject_url", NEW."subject_id", substr(NEW."dedupe_key", length('plugin:' || split_part(NEW."dedupe_key", ':', 2) || ':') + 1))
89
+ ELSE coalesce(NEW."dedupe_key", 'ask:' || NEW."id"::text)
90
+ END;
91
+ -- Every item's http(s) evidence links get the form that new code stores,
92
+ -- also a closed item's, so the duplicate check below sees its old link.
93
+ IF jsonb_typeof(NEW."request"->'evidence') = 'array' THEN
94
+ NEW."request" := jsonb_set(NEW."request", '{evidence}', (SELECT coalesce(jsonb_agg(CASE WHEN entry->>'url' ~* '^https?://' THEN jsonb_set(entry, '{url}', to_jsonb("junior_inbox_items_web_link"(entry->>'url'))) ELSE entry END ORDER BY position), '[]'::jsonb) FROM jsonb_array_elements(NEW."request"->'evidence') WITH ORDINALITY AS evidence(entry, position)));
95
+ END IF;
96
+ -- A question reads what it is about from its evidence links, so its old
97
+ -- subject link becomes its first evidence link. A notice keeps no request,
98
+ -- because the old kind check still holds, so its link stays in
99
+ -- `subject_url`.
100
+ IF NEW."subject_kind" = 'question' AND NEW."kind" = 'notice' AND legacy_link IS NOT NULL THEN
101
+ NEW."subject_url" := legacy_link;
102
+ ELSIF NEW."subject_kind" = 'question'
103
+ AND legacy_link IS NOT NULL
104
+ AND NOT coalesce(NEW."request"->'evidence', '[]'::jsonb) @> jsonb_build_array(jsonb_build_object('url', legacy_link))
105
+ THEN
106
+ NEW."request" := jsonb_set(coalesce(NEW."request", '{}'::jsonb), '{evidence}', jsonb_build_array(jsonb_build_object('label', left(coalesce(nullif(NEW."subject_title", ''), legacy_link), 120), 'url', legacy_link)) || coalesce(NEW."request"->'evidence', '[]'::jsonb));
107
+ END IF;
108
+ RETURN NEW;
109
+ END;
110
+ $function$;--> statement-breakpoint
111
+ CREATE TRIGGER "junior_inbox_items_legacy_subject" BEFORE INSERT OR UPDATE ON "junior_inbox_items" FOR EACH ROW WHEN (NEW."subject_kind" IS NULL) EXECUTE FUNCTION "junior_inbox_items_legacy_subject"();--> statement-breakpoint
112
+ -- junior:bounded-backfill: every row needs its subject before the next migration sets NOT NULL, so the update runs once over the whole Inbox item table. That table holds only asks and notices for people, and the update writes each row once. The same write gives the evidence links of every row the stored form.
113
+ UPDATE "junior_inbox_items" SET "subject_kind" = NULL;--> statement-breakpoint
114
+ -- junior:bounded-backfill: before the unique open subject index below, the older of two open items that now share a subject closes. It reads only the open items and closes the few duplicates, such as the review and merge asks of one pull request.
115
+ UPDATE "junior_inbox_items" AS "item" SET "status" = 'dismissed', "closed_at" = now(), "close_reason" = 'A newer item asks about the same subject.', "updated_at" = now() WHERE "item"."status" = 'open' AND EXISTS (SELECT 1 FROM "junior_inbox_items" AS "newer" WHERE "newer"."status" = 'open' AND coalesce("newer"."provider", '') = coalesce("item"."provider", '') AND coalesce("newer"."provider_tenant_id", '') = coalesce("item"."provider_tenant_id", '') AND "newer"."subject_kind" = "item"."subject_kind" AND "newer"."subject_id" = "item"."subject_id" AND ("newer"."updated_at", "newer"."id") > ("item"."updated_at", "item"."id"));--> statement-breakpoint
116
+ -- junior:bounded-backfill: a snooze of a closed duplicate moves to the item that stays open, so that item stays hidden. It reads only the snoozes of the few duplicates. A person who also snoozed the open item keeps that snooze: its wake time is in the timer store, not here.
117
+ UPDATE "junior_inbox_snoozes" AS "snooze" SET "inbox_item_id" = "move"."open_id" FROM (SELECT DISTINCT ON ("snooze"."user_id", "open"."id") "snooze"."id", "open"."id" AS "open_id" FROM "junior_inbox_snoozes" AS "snooze" JOIN "junior_inbox_items" AS "item" ON "item"."id" = "snooze"."inbox_item_id" JOIN "junior_inbox_items" AS "open" ON "open"."status" = 'open' AND coalesce("open"."provider", '') = coalesce("item"."provider", '') AND coalesce("open"."provider_tenant_id", '') = coalesce("item"."provider_tenant_id", '') AND "open"."subject_kind" = "item"."subject_kind" AND "open"."subject_id" = "item"."subject_id" WHERE "snooze"."state" = 'snoozed' AND "item"."status" = 'dismissed' AND "item"."close_reason" = 'A newer item asks about the same subject.' AND NOT EXISTS (SELECT 1 FROM "junior_inbox_snoozes" AS "kept" WHERE "kept"."inbox_item_id" = "open"."id" AND "kept"."user_id" = "snooze"."user_id" AND "kept"."state" = 'snoozed') ORDER BY "snooze"."user_id", "open"."id", "snooze"."created_at" DESC) AS "move" WHERE "snooze"."id" = "move"."id";--> statement-breakpoint
118
+ -- junior:bounded-backfill: the assignees of a closed duplicate join the item that stays open, so they keep their ask. It reads only the assignees of the few duplicates. An open item with no assignees asks everyone, so it gets none.
119
+ INSERT INTO "junior_inbox_item_assignees" ("item_id", "user_id") SELECT DISTINCT "open"."id", "assignee"."user_id" FROM "junior_inbox_item_assignees" AS "assignee" JOIN "junior_inbox_items" AS "item" ON "item"."id" = "assignee"."item_id" JOIN "junior_inbox_items" AS "open" ON "open"."status" = 'open' AND coalesce("open"."provider", '') = coalesce("item"."provider", '') AND coalesce("open"."provider_tenant_id", '') = coalesce("item"."provider_tenant_id", '') AND "open"."subject_kind" = "item"."subject_kind" AND "open"."subject_id" = "item"."subject_id" WHERE "item"."status" = 'dismissed' AND "item"."close_reason" = 'A newer item asks about the same subject.' AND EXISTS (SELECT 1 FROM "junior_inbox_item_assignees" AS "kept" WHERE "kept"."item_id" = "open"."id") ON CONFLICT DO NOTHING;--> statement-breakpoint
120
+ -- junior:bounded-backfill: the sent pushes of a closed duplicate clear, as for any closed item, so the devices close it. It reads only the deliveries of the few duplicates.
121
+ UPDATE "junior_inbox_item_deliveries" AS "delivery" SET "status" = 'cleared', "updated_at" = now() FROM "junior_inbox_items" AS "item" WHERE "item"."id" = "delivery"."item_id" AND "delivery"."status" = 'sent' AND "item"."status" = 'dismissed' AND "item"."close_reason" = 'A newer item asks about the same subject.';--> statement-breakpoint
122
+ -- The subject now names an open item. The index is built here, in the
123
+ -- transaction that closed the duplicates, so an old worker cannot add a
124
+ -- second open item for a subject while this release rolls out. That insert
125
+ -- fails instead. It reads only the open items.
126
+ -- squawk-ignore require-concurrent-index-creation
127
+ CREATE UNIQUE INDEX "junior_inbox_items_open_subject_uidx" ON "junior_inbox_items" USING btree (coalesce("provider", ''),coalesce("provider_tenant_id", ''),"subject_kind","subject_id") WHERE "junior_inbox_items"."status" = 'open';--> statement-breakpoint
128
+ -- NOT VALID: the backfill gave every row its subject, and the checks still
129
+ -- hold for every new write. The next migration validates the NOT NULL checks without a
130
+ -- lock that blocks reads, then sets NOT NULL.
131
+ ALTER TABLE "junior_inbox_items" ADD CONSTRAINT "junior_inbox_items_subject_kind_not_null" CHECK ("subject_kind" IS NOT NULL) NOT VALID;--> statement-breakpoint
132
+ ALTER TABLE "junior_inbox_items" ADD CONSTRAINT "junior_inbox_items_subject_id_not_null" CHECK ("subject_id" IS NOT NULL) NOT VALID;
133
+ -- The snapshot no longer has subject_title, subject_url, subject_title_parts,
134
+ -- automation_id, its foreign key, junior_inbox_items_automation_idx, or
135
+ -- junior_inbox_items_open_dedupe_uidx. That index still lets an old worker
136
+ -- add only one open item per dedupe key, because a question it adds gets
137
+ -- the item's id as its subject (20261126153259_inbox_questions). They
138
+ -- stay in the database for one release, because old workers still name them
139
+ -- in every insert while this migration runs. The next release drops them
140
+ -- with the trigger above.
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "98c44f12-b0fc-48dd-ab52-83d230e4f31b",
6
+ "prevIds": ["7fa7b36c-167a-4f6b-8b90-a14c8028e3a5"],
7
+ "footprints": [],
8
+ "deltas": []
9
+ }
@@ -0,0 +1,12 @@
1
+ -- VALIDATE CONSTRAINT takes only SHARE UPDATE EXCLUSIVE, so reads and writes
2
+ -- keep going during the scan. SET NOT NULL then reads the valid checks and
3
+ -- skips its own scan. The previous migration added the two checks, so no
4
+ -- release uses them.
5
+ ALTER TABLE "junior_inbox_items" VALIDATE CONSTRAINT "junior_inbox_items_subject_kind_not_null";--> statement-breakpoint
6
+ ALTER TABLE "junior_inbox_items" VALIDATE CONSTRAINT "junior_inbox_items_subject_id_not_null";--> statement-breakpoint
7
+ ALTER TABLE "junior_inbox_items" ALTER COLUMN "subject_kind" SET NOT NULL;--> statement-breakpoint
8
+ ALTER TABLE "junior_inbox_items" ALTER COLUMN "subject_id" SET NOT NULL;--> statement-breakpoint
9
+ -- squawk-ignore ban-drop-constraint -- unused since 0.315.0
10
+ ALTER TABLE "junior_inbox_items" DROP CONSTRAINT "junior_inbox_items_subject_kind_not_null";--> statement-breakpoint
11
+ -- squawk-ignore ban-drop-constraint -- unused since 0.315.0
12
+ ALTER TABLE "junior_inbox_items" DROP CONSTRAINT "junior_inbox_items_subject_id_not_null";
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "5e18d9a9-9f33-43d7-9148-2357ce185af6",
6
+ "prevIds": ["98c44f12-b0fc-48dd-ab52-83d230e4f31b"],
7
+ "footprints": [],
8
+ "deltas": []
9
+ }
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_inbox_items_subject_kind_idx" ON "junior_inbox_items" USING btree ("subject_kind","status");
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "5999c4b2-7246-43e8-862c-3f5b7d718855",
6
+ "prevIds": ["5e18d9a9-9f33-43d7-9148-2357ce185af6"],
7
+ "footprints": [],
8
+ "deltas": []
9
+ }
@@ -0,0 +1 @@
1
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS "junior_automation_runs_conversation_idx" ON "junior_automation_runs" USING btree ("conversation_id");
@@ -0,0 +1,9 @@
1
+ {
2
+ "type": "diff",
3
+ "version": "10",
4
+ "dialect": "postgres",
5
+ "id": "9adf29c7-813a-42e4-920d-f95fa91eb136",
6
+ "prevIds": ["5999c4b2-7246-43e8-862c-3f5b7d718855"],
7
+ "footprints": [],
8
+ "deltas": []
9
+ }
@@ -0,0 +1,4 @@
1
+ -- This migration does not change the database. The four migrations before
2
+ -- it change `junior_inbox_items` by hand, because data moves between their
3
+ -- statements. This snapshot records the schema that they leave, so
4
+ -- `drizzle-kit generate` does not write their changes again.