@sentry/junior 0.316.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 (122) hide show
  1. package/dist/{admin-QYiDMnsu.js → admin-CAugg87B.js} +1 -1
  2. package/dist/{agent-runner-Cr5Fhjf-.js → agent-runner-AjrEV6Qe.js} +13438 -13149
  3. package/dist/{reporting-window-C4dbzDiR.js → agent-status-BA5x3Xtp.js} +33 -1
  4. package/dist/{agent-update-delivery-BY13DPSD.js → agent-update-delivery-B_YIZcgf.js} +5 -5
  5. package/dist/api/schema.d.ts +558 -102
  6. package/dist/api/schema.js +6 -6
  7. package/dist/api.js +230 -213
  8. package/dist/{app-BhvzRD__.d.ts → app-MoNAsVV5.d.ts} +34 -14
  9. package/dist/app.d.ts +1 -1
  10. package/dist/app.js +167 -122
  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-Bref7aPI.js → channel-access-j-YAVYK4.js} +2 -42
  14. package/dist/{chat-core-engine-3dtlMku3.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 +5 -3
  22. package/dist/config-CHQ8X251.js +2422 -0
  23. package/dist/{continue-in-slack-DbQUFe_F.js → continue-in-slack-D-FZ8Fin.js} +2 -3
  24. package/dist/{conversation-feed-B84pMjHo.js → conversation-feed--9S0_PXL.js} +3 -3
  25. package/dist/{proxy-path-BTmXDjfx.js → conversation-privacy-B1uXn5sf.js} +2 -16
  26. package/dist/{conversation-turn-DzEpTIaf.js → conversation-turn-BUE_7xaN.js} +99 -76
  27. package/dist/{create-DUJBXr6E.js → create-DoDIYgtZ.js} +12 -9
  28. package/dist/{credential-sync-JH_K9Adg.js → credential-sync-BJOqGnjV.js} +17 -12
  29. package/dist/{db-DhzvUY23.js → db-BFmyYZtJ.js} +20265 -27551
  30. package/dist/{deployment-BhvrhQeh.js → deployment-DXq9ZLU4.js} +17 -15
  31. package/dist/{engine-context-C9Nal48K.js → engine-context-CgQ7mlHt.js} +264 -47
  32. package/dist/{html-B_12WjKT.js → html-B3VKTGbJ.js} +6 -2
  33. package/dist/instrumentation.js +15 -7
  34. package/dist/{job-runner-DO8nslyY.js → job-runner-A1lCkybD.js} +391 -24
  35. package/dist/{lineage-D3AZAJVe.js → lineage-Bktb0UcV.js} +1 -1
  36. package/dist/{list-B0zsb5Cp.js → list-Bxvg5wXf.js} +224 -544
  37. package/dist/{logging-B8KEJegM.js → logging--smS7XRK.js} +2 -2
  38. package/dist/{session-stop-DponjDUZ.js → mailbox-turn-uSXhUFc9.js} +4747 -7039
  39. package/dist/{message-B5fKDYzz.js → message-BNenhsmB.js} +12 -22
  40. package/dist/{model-input-CuMWy37l.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-B3Vvlydo.js → oauth-callback-server-CE4soEIY.js} +2 -2
  44. package/dist/{oauth-relay-6ERrGPbA.js → oauth-relay-C36gX1gH.js} +2 -2
  45. package/dist/{package-discovery-BI6T_RkD.js → package-discovery-DD9vencX.js} +1 -50
  46. package/dist/{list-mkB_GU8R.js → parent-result-Ck1rFYRQ.js} +107 -92
  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-CCi7323k.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-D5JVvv6A.js → resolve-tony4ibz.js} +9 -29
  54. package/dist/{result-CS_7mo8a.js → result-Bta_dlWa.js} +25 -116
  55. package/dist/run-conversation-DL6ru7iW.js +336 -0
  56. package/dist/{runner-BzAES5W3.js → runner-BstDRbD9.js} +7 -7
  57. package/dist/{sandbox-egress-signals-Dwhk2Q5F.js → sandbox-egress-signals-oSJMJOnn.js} +1 -1
  58. package/dist/{schema-z5-wA6N4.js → schema-DfqrHACA.js} +48 -86
  59. package/dist/sender-actors-CPglLd5R.js +83 -0
  60. package/dist/{service-account-D6AsAtc1.js → service-account-CTV_jaNu.js} +3 -1
  61. package/dist/{skills-DgJ9GBPR.js → skills-BCEU41zM.js} +4 -4
  62. package/dist/{slack-conversation-unfurl-Dq71EkhM.js → slack-conversation-unfurl-DxVmhbGP.js} +7 -6
  63. package/dist/{spawn-BJWpdwhQ.js → spawn-frczVPIr.js} +11 -8
  64. package/dist/{system-prompt-table-iIgpmslr.js → system-prompt-table-CiXy0eNR.js} +88 -69
  65. package/dist/{task-runner-BJae4JwE.js → task-runner-C9Yc2_ae.js} +20 -46
  66. package/dist/{thread-context-fiMNylbg.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-BjDW7x-5.js → turn-wake-BhloiI2h.js} +4 -5
  70. package/dist/{media-BebquhET.js → types-C4iC-IMC.js} +801 -771
  71. package/dist/user-customization-CvfuY9Eo.js +93 -0
  72. package/dist/users-ByG5RCEJ.js +181 -0
  73. package/dist/{validation-D5WmmmhX.js → validation-8gjfR91V.js} +1 -1
  74. package/dist/{version-CBQoanXb.js → version-BeZhWWBE.js} +1 -1
  75. package/dist/version.js +1 -1
  76. package/dist/{worker-Cyb4kF17.js → worker-BqMQQNRk.js} +5 -4
  77. package/migrations/20261126025226_drop_agent_invocations/migration.sql +6 -0
  78. package/migrations/20261126025226_drop_agent_invocations/snapshot.json +9 -0
  79. package/migrations/20261126033000_space_conversations_lead_children/migration.sql +155 -0
  80. package/migrations/20261126033000_space_conversations_lead_children/snapshot.json +9 -0
  81. package/migrations/20261126144620_drop_user_message_time_index/migration.sql +1 -0
  82. package/migrations/20261126144620_drop_user_message_time_index/snapshot.json +38 -0
  83. package/migrations/20261126153100_inbox_item_subjects/migration.sql +140 -0
  84. package/migrations/20261126153100_inbox_item_subjects/snapshot.json +9 -0
  85. package/migrations/20261126153103_inbox_item_subjects_not_null/migration.sql +12 -0
  86. package/migrations/20261126153103_inbox_item_subjects_not_null/snapshot.json +9 -0
  87. package/migrations/20261126153105_inbox_item_subject_indexes/migration.sql +1 -0
  88. package/migrations/20261126153105_inbox_item_subject_indexes/snapshot.json +9 -0
  89. package/migrations/20261126153108_automation_run_conversation_index/migration.sql +1 -0
  90. package/migrations/20261126153108_automation_run_conversation_index/snapshot.json +9 -0
  91. package/migrations/20261126153159_inbox_item_subjects_schema/migration.sql +4 -0
  92. package/migrations/20261126153159_inbox_item_subjects_schema/snapshot.json +437 -0
  93. package/migrations/20261126153259_inbox_questions/migration.sql +76 -0
  94. package/migrations/20261126153259_inbox_questions/snapshot.json +9 -0
  95. package/migrations/20261126153301_inbox_questions_valid/migration.sql +3 -0
  96. package/migrations/20261126153301_inbox_questions_valid/snapshot.json +9 -0
  97. package/migrations/20261126153343_inbox_questions_schema/migration.sql +5 -0
  98. package/migrations/20261126153343_inbox_questions_schema/snapshot.json +407 -0
  99. package/migrations/20261126154025_inbox_item_owners/migration.sql +74 -0
  100. package/migrations/20261126154025_inbox_item_owners/snapshot.json +9 -0
  101. package/migrations/20261126154048_inbox_item_open_subject_key_index/migration.sql +1 -0
  102. package/migrations/20261126154048_inbox_item_open_subject_key_index/snapshot.json +9 -0
  103. package/migrations/20261126154051_drop_inbox_item_owner_indexes/migration.sql +7 -0
  104. package/migrations/20261126154051_drop_inbox_item_owner_indexes/snapshot.json +9 -0
  105. package/migrations/20261126154121_inbox_item_owners_schema/migration.sql +8 -0
  106. package/migrations/20261126154121_inbox_item_owners_schema/snapshot.json +311 -0
  107. package/migrations/20261126175601_conversation_event_turn/migration.sql +5 -0
  108. package/migrations/20261126175601_conversation_event_turn/snapshot.json +103 -0
  109. package/migrations/20261126175614_conversation_event_turn_index/migration.sql +1 -0
  110. package/migrations/20261126175614_conversation_event_turn_index/snapshot.json +62 -0
  111. package/migrations/20261126230028_merge_leaves/migration.sql +2 -0
  112. package/migrations/20261126230028_merge_leaves/snapshot.json +12 -0
  113. package/migrations/20261126231932_space_lead_holds_name/migration.sql +46 -0
  114. package/migrations/20261126231932_space_lead_holds_name/snapshot.json +58 -0
  115. package/migrations/20261127001022_merge_leaves/migration.sql +2 -0
  116. package/migrations/20261127001022_merge_leaves/snapshot.json +12 -0
  117. package/package.json +5 -5
  118. package/dist/people-CUtFApfL.js +0 -81
  119. package/dist/start-conversation-B-LIqqNi.js +0 -162
  120. package/dist/turn-session-routing-D15orfwy.js +0 -1309
  121. package/dist/user-customization-B27StpVQ.js +0 -9
  122. package/dist/web-message-id-C6P83ans.js +0 -10
@@ -0,0 +1,93 @@
1
+ import * as z from "zod";
2
+ // src/chat/attachments/media.ts
3
+ const INPUT_IMAGE_TYPES = [
4
+ "image/png",
5
+ "image/jpeg",
6
+ "image/gif",
7
+ "image/webp"
8
+ ];
9
+ /** Video types that browsers play in a `<video>` element. */
10
+ const INLINE_VIDEO_TYPES = ["video/mp4", "video/webm"];
11
+ /** Leading bytes of each accepted image type. `null` matches any byte. */
12
+ const IMAGE_SIGNATURES = [
13
+ {
14
+ mediaType: "image/png",
15
+ bytes: [
16
+ 137,
17
+ 80,
18
+ 78,
19
+ 71,
20
+ 13,
21
+ 10,
22
+ 26,
23
+ 10
24
+ ]
25
+ },
26
+ {
27
+ mediaType: "image/jpeg",
28
+ bytes: [
29
+ 255,
30
+ 216,
31
+ 255
32
+ ]
33
+ },
34
+ {
35
+ mediaType: "image/gif",
36
+ bytes: [
37
+ 71,
38
+ 73,
39
+ 70,
40
+ 56,
41
+ 55,
42
+ 97
43
+ ]
44
+ },
45
+ {
46
+ mediaType: "image/gif",
47
+ bytes: [
48
+ 71,
49
+ 73,
50
+ 70,
51
+ 56,
52
+ 57,
53
+ 97
54
+ ]
55
+ },
56
+ {
57
+ mediaType: "image/webp",
58
+ bytes: [
59
+ 82,
60
+ 73,
61
+ 70,
62
+ 70,
63
+ null,
64
+ null,
65
+ null,
66
+ null,
67
+ 87,
68
+ 69,
69
+ 66,
70
+ 80
71
+ ]
72
+ }
73
+ ];
74
+ /**
75
+ * Detect an accepted image type from file bytes. Use this instead of a file
76
+ * name or declared content type, which can be wrong.
77
+ */
78
+ function detectImageMediaType(data) {
79
+ return IMAGE_SIGNATURES.find(({ bytes }) => data.length >= bytes.length && bytes.every((byte, index) => byte === null || data[index] === byte))?.mediaType;
80
+ }
81
+ /** Report whether a media type is a raster image accepted by vision models. */
82
+ function isVisionImageMediaType(mediaType) {
83
+ const normalized = mediaType.split(";", 1)[0]?.trim().toLowerCase();
84
+ return normalized ? INPUT_IMAGE_TYPES.some((type) => type === normalized) : false;
85
+ }
86
+ // src/api/schema/user-customization.ts
87
+ /** Longest customization text one user can save. */
88
+ const USER_CUSTOMIZATION_MAX_CHARS = 1e3;
89
+ /** Saved customization text. An empty string means none. */
90
+ const userCustomizationTextSchema = z.string().trim().max(USER_CUSTOMIZATION_MAX_CHARS);
91
+ /** Request and response body for the viewer's customization. */
92
+ const userCustomizationSchema = z.object({ customization: userCustomizationTextSchema }).strict();
93
+ export { INPUT_IMAGE_TYPES as a, INLINE_VIDEO_TYPES as i, userCustomizationSchema as n, detectImageMediaType as o, userCustomizationTextSchema as r, isVisionImageMediaType as s, USER_CUSTOMIZATION_MAX_CHARS as t };
@@ -0,0 +1,181 @@
1
+ import { Fs as SlackActionError, qs as withSlackRetries, zs as getSlackClient } from "./db-BFmyYZtJ.js";
2
+ import * as z from "zod";
3
+ // src/chat/slack/users.ts
4
+ const profileFieldsSchema = z.object({ fields: z.record(z.string(), z.object({
5
+ value: z.string().optional(),
6
+ alt: z.string().optional(),
7
+ label: z.string().optional()
8
+ }).nullable()).nullish() });
9
+ function normalizeUser(raw) {
10
+ const rawFields = profileFieldsSchema.parse(raw.profile ?? {}).fields;
11
+ const profileFields = [];
12
+ if (rawFields) for (const [id, field] of Object.entries(rawFields)) {
13
+ if (!field) continue;
14
+ profileFields.push({
15
+ id,
16
+ label: field.label || void 0,
17
+ value: field.value || void 0,
18
+ alt: field.alt || void 0
19
+ });
20
+ }
21
+ return {
22
+ id: raw.id ?? "",
23
+ team_id: raw.team_id || void 0,
24
+ name: raw.name || void 0,
25
+ real_name: raw.real_name || raw.profile?.real_name || void 0,
26
+ display_name: raw.profile?.display_name || void 0,
27
+ title: raw.profile?.title || void 0,
28
+ email: raw.profile?.email || void 0,
29
+ status_text: raw.profile?.status_text ?? void 0,
30
+ status_emoji: raw.profile?.status_emoji ?? void 0,
31
+ avatar_url: raw.profile?.image_512 || void 0,
32
+ is_bot: raw.is_bot ?? false,
33
+ is_deleted: raw.deleted ?? false,
34
+ timezone: raw.tz || void 0,
35
+ ...profileFields.length > 0 ? { profile_fields: profileFields } : void 0
36
+ };
37
+ }
38
+ function normalizeNameTokens(value) {
39
+ return value.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter(Boolean);
40
+ }
41
+ function nameFields(user) {
42
+ return [
43
+ user.name ?? "",
44
+ user.profile?.display_name ?? "",
45
+ user.real_name ?? user.profile?.real_name ?? ""
46
+ ].map((value) => value.toLowerCase().trim()).filter(Boolean);
47
+ }
48
+ /** Look up a Slack user by ID, returning the full profile including custom fields. */
49
+ async function lookupSlackUserProfile(userId) {
50
+ const client = getSlackClient();
51
+ const user = (await withSlackRetries(() => client.users.info({ user: userId }), 3, { action: "users.info" })).user;
52
+ if (!user) throw new Error(`Slack users.info returned no user for ${userId}`);
53
+ return normalizeUser(user);
54
+ }
55
+ /**
56
+ * Look up one Slack user who is a current human member of a workspace.
57
+ *
58
+ * Returns undefined for a user that Slack cannot find, a deleted user, a bot,
59
+ * or a user of another workspace. Other lookup errors propagate.
60
+ */
61
+ async function lookupActiveSlackWorkspaceMember(userId, teamId) {
62
+ let user;
63
+ try {
64
+ user = await lookupSlackUserProfile(userId);
65
+ } catch (error) {
66
+ if (error instanceof SlackActionError && error.apiError === "user_not_found") return;
67
+ throw error;
68
+ }
69
+ return user.id === userId && user.team_id === teamId && !user.is_deleted && !user.is_bot ? user : void 0;
70
+ }
71
+ /** Look up a Slack bot by ID. Returns undefined when Slack has no such bot. */
72
+ async function lookupSlackBot(botId) {
73
+ try {
74
+ return (await withSlackRetries(() => getSlackClient().bots.info({ bot: botId }), 3, { action: "bots.info" })).bot;
75
+ } catch (error) {
76
+ if (error instanceof SlackActionError && error.apiError === "bot_not_found") return;
77
+ throw error;
78
+ }
79
+ }
80
+ /** Look up a Slack user by email. Returns null when no user matches. */
81
+ async function lookupSlackUserByEmail(email) {
82
+ const client = getSlackClient();
83
+ let result;
84
+ try {
85
+ result = await withSlackRetries(() => client.users.lookupByEmail({ email }), 3, { action: "users.lookupByEmail" });
86
+ } catch (error) {
87
+ if (error instanceof SlackActionError && error.apiError === "users_not_found") return null;
88
+ throw error;
89
+ }
90
+ const user = result.user;
91
+ if (!user) return null;
92
+ return normalizeUser(user);
93
+ }
94
+ /**
95
+ * Rank Slack name-search quality for one candidate.
96
+ * Exact field and token matches beat field prefixes so a display-name prefix
97
+ * cannot outrank a real-name first-name hit.
98
+ */
99
+ function scoreNameMatch(user, query) {
100
+ const queryLower = query.toLowerCase().trim();
101
+ if (!queryLower) return 0;
102
+ const fields = nameFields(user);
103
+ if (fields.length === 0) return 0;
104
+ let best = 0;
105
+ const queryTokens = normalizeNameTokens(queryLower);
106
+ for (const field of fields) {
107
+ if (field === queryLower) {
108
+ best = Math.max(best, 100);
109
+ continue;
110
+ }
111
+ if (field.startsWith(queryLower)) best = Math.max(best, 70);
112
+ else if (field.includes(queryLower)) best = Math.max(best, 25);
113
+ const tokens = normalizeNameTokens(field);
114
+ for (const token of tokens) if (token === queryLower) best = Math.max(best, 85);
115
+ else if (token.startsWith(queryLower)) best = Math.max(best, 60);
116
+ if (queryTokens.length > 1 && queryTokens.every((queryToken) => tokens.some((token) => token === queryToken || token.startsWith(queryToken)))) best = Math.max(best, 95);
117
+ }
118
+ return best;
119
+ }
120
+ function compareNameMatches(left, right) {
121
+ if (right.score !== left.score) return right.score - left.score;
122
+ return (left.user.name ?? "").localeCompare(right.user.name ?? "");
123
+ }
124
+ async function listWorkspaceUsers(options) {
125
+ const client = getSlackClient();
126
+ const matches = [];
127
+ let cursor;
128
+ let pages = 0;
129
+ let totalScanned = 0;
130
+ while (pages < options.maxPages) {
131
+ pages++;
132
+ const result = await withSlackRetries(() => client.users.list({
133
+ limit: 200,
134
+ ...cursor ? { cursor } : void 0
135
+ }), 3, { action: "users.list" });
136
+ const members = result.members ?? [];
137
+ totalScanned += members.length;
138
+ for (const member of members) {
139
+ if (!options.includeDeleted && member.deleted) continue;
140
+ if (!options.includeBots && member.is_bot) continue;
141
+ if (member.id === "USLACKBOT") continue;
142
+ const score = options.score(member);
143
+ if (score <= 0) continue;
144
+ matches.push({
145
+ user: member,
146
+ score
147
+ });
148
+ }
149
+ const nextCursor = result.response_metadata?.next_cursor;
150
+ if (!nextCursor) {
151
+ cursor = void 0;
152
+ break;
153
+ }
154
+ cursor = nextCursor;
155
+ }
156
+ return {
157
+ matches,
158
+ searched_pages: pages,
159
+ searched_user_count: totalScanned,
160
+ truncated: pages >= options.maxPages && Boolean(cursor)
161
+ };
162
+ }
163
+ /** Search workspace users by name with bounded pagination through `users.list`. */
164
+ async function searchSlackUsers(options) {
165
+ const { query, limit = 10, maxPages = 3, includeDeleted = false, includeBots = false } = options;
166
+ const queryLower = query.toLowerCase().trim();
167
+ const listed = await listWorkspaceUsers({
168
+ maxPages,
169
+ includeDeleted,
170
+ includeBots,
171
+ score: (member) => scoreNameMatch(member, queryLower)
172
+ });
173
+ listed.matches.sort(compareNameMatches);
174
+ return {
175
+ users: listed.matches.slice(0, limit).map((m) => normalizeUser(m.user)),
176
+ searched_pages: listed.searched_pages,
177
+ searched_user_count: listed.searched_user_count,
178
+ truncated: listed.truncated
179
+ };
180
+ }
181
+ export { searchSlackUsers as a, lookupSlackUserProfile as i, lookupSlackBot as n, lookupSlackUserByEmail as r, lookupActiveSlackWorkspaceMember as t };
@@ -1,5 +1,5 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { jr as pluginCatalogRuntime } from "./db-DhzvUY23.js";
2
+ import { n as pluginCatalogRuntime } from "./catalog-runtime-DfSpJZdY.js";
3
3
  import { isDeepStrictEqual } from "node:util";
4
4
  // src/chat/plugins/validation.ts
5
5
  var validation_exports = /* @__PURE__ */ __exportAll({
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.316.0";
2
+ var version = "0.317.0";
3
3
  // src/version.ts
4
4
  /** Installed Junior package version, or `unknown` when package metadata is unavailable. */
5
5
  const JUNIOR_VERSION = typeof version === "string" && version.trim() ? version : "unknown";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export { t as JUNIOR_VERSION } from "./version-CBQoanXb.js";
1
+ export { t as JUNIOR_VERSION } from "./version-BeZhWWBE.js";
@@ -1,7 +1,8 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
2
- import { Dp as isProviderRetryError, Ff as getChatConfig, ia as nudgeIdempotencyKey, ta as ConversationQueueMessageRejectedError, xn as getTurnRequestDeadline } from "./db-DhzvUY23.js";
3
- import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging-B8KEJegM.js";
4
- import { $t as recordAttemptFailure, Gt as deadLetterAttempt, It as beginConversationResume, Jt as ensureConversationWake, Kt as drainConversationMailbox, Nt as ackMessages, Rt as checkInConversationWork, Ut as completeConversationStop, Vt as clearConsumedConversationWake, Wt as completeConversationWork, Xt as getConversationWorkState, bi as selectAttemptMessages, ci as hasConversationStop, di as isInvalidConversationRecordError, en as recordConversationRetry, i as saveHeldInput, in as startConversationWork, n as getConversationStoppedAtMs, nn as requestAnotherSlice, oi as countPendingConversationMessages, tn as releaseConversationWork, ui as isFinalAttempt, yi as isAttemptInterrupt, zt as claimConversationAttempt } from "./session-stop-DponjDUZ.js";
2
+ import { $t as drainConversationMailbox, An as isAttemptInterrupt, Gt as checkInConversationWork, Ir as nudgeIdempotencyKey, Jt as clearConsumedConversationWake, Kt as claimConversationAttempt, Nr as ConversationQueueMessageRejectedError, Qt as deadLetterAttempt, Sn as isInvalidConversationRecordError, Ut as beginConversationResume, Xt as completeConversationStop, Zt as completeConversationWork, _n as countPendingConversationMessages, cn as releaseConversationWork, cr as getTurnRequestDeadline, dn as startConversationWork, jn as selectAttemptMessages, ln as requestAnotherSlice, on as recordAttemptFailure, ou as ownsLocation, rn as getConversationWorkState, sn as recordConversationRetry, tn as ensureConversationWake, xn as isFinalAttempt, yn as hasConversationStop, zt as ackMessages } from "./db-BFmyYZtJ.js";
3
+ import { $ as isProviderRetryError, n as getChatConfig } from "./config-CHQ8X251.js";
4
+ import { T as withLogContext, b as setSpanAttributes, h as logWarn, m as logInfo, p as logException } from "./logging--smS7XRK.js";
5
+ import { K as saveHeldInput, W as getConversationStoppedAtMs } from "./mailbox-turn-uSXhUFc9.js";
5
6
  // src/chat/task-execution/lost-lease.ts
6
7
  /**
7
8
  * Count a slice that lost its Conversation Lease as a failed attempt, then
@@ -212,7 +213,7 @@ async function processConversationWorkInContext(message, options) {
212
213
  let destination = initial.destination;
213
214
  if (!destination && options.conversationStore) {
214
215
  const stored = await options.conversationStore.get({ conversationId });
215
- if (stored && !stored.parentConversationId) destination = stored.destination;
216
+ if (stored && ownsLocation(stored)) destination = stored.destination;
216
217
  }
217
218
  const lease = await startConversationWork({
218
219
  conversationId,
@@ -0,0 +1,6 @@
1
+ -- Drop the junior_agent_invocations table that 0160_agent_config_backfill
2
+ -- kept in the database. No runtime code reads or writes it since 0.314.0.
3
+ -- Retention purge in 0.316.0 still deletes its rows, so a purge that runs on
4
+ -- that release during the deploy fails, and the next run retries the tree.
5
+ -- squawk-ignore ban-drop-table -- unused since 0.314.0
6
+ DROP TABLE IF EXISTS "junior_agent_invocations";
@@ -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
+ }