@sentry/junior 0.310.0 → 0.312.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.
- package/dist/{adapter-context-BhKpjpGD.js → adapter-context-BRjEWRy1.js} +2 -2
- package/dist/adapter-iIq7ihf7.js +259 -0
- package/dist/{admin-tgZEZAk2.js → admin-DhInw5K9.js} +1 -2
- package/dist/{agent-runner-D9cvNlQl.js → agent-runner-C9iDurwX.js} +6507 -7721
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -6
- package/dist/api.d.ts +21 -3
- package/dist/api.js +1625 -535
- package/dist/{app-B_7Wn0en.d.ts → app-DRFrC8Mw.d.ts} +14 -10
- package/dist/app.d.ts +2 -2
- package/dist/app.js +454 -994
- package/dist/{background-compaction-queue-BGHqkhkY.js → background-compaction-queue-DrKi7w3d.js} +10 -85
- package/dist/callback-mFlTUWWx.js +75 -0
- package/dist/{catalog-runtime-BxwzbLKY.js → catalog-runtime-D7xapBAX.js} +1 -1
- package/dist/channel-access-CJGfNTdn.js +221 -0
- package/dist/child-message-DcsritGf.js +179 -0
- package/dist/cli/chat.js +18 -19
- package/dist/cli/check.js +23 -29
- package/dist/cli/init.js +1 -7
- package/dist/cli/main.js +3 -7
- package/dist/cli/plugins.js +8 -7
- package/dist/cli/run.d.ts +1 -2
- package/dist/cli/run.js +1 -2
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-Dkt2Le2b.js → config-kXB2Y5tl.js} +294 -28
- package/dist/{continue-in-slack-BWVwePKD.js → continue-in-slack-O6pV5004.js} +7 -7
- package/dist/{conversation-feed-Ci6YD1N-.js → conversation-feed-uNOv_x68.js} +87 -24
- package/dist/{conversation-privacy-C39g8BY4.js → conversation-privacy-L4ja1_W6.js} +1 -1
- package/dist/{conversation-turn-CBlZIH02.js → conversation-turn-CeLbHqdw.js} +56 -49
- package/dist/{credential-sync-vGnrB0BY.js → credential-sync-I8VBGk05.js} +16 -16
- package/dist/{projection-jZSlEAXG.js → credentialed-Cb6E2phL.js} +16268 -16821
- package/dist/{db-B4Hjxr-u.d.ts → db-BbC5stfa.d.ts} +13 -6
- package/dist/{db-CFZggNoy.js → db-LAyyX8tk.js} +1698 -1046
- package/dist/{executor-BPkZDx5-.js → executor-SCub-fAq.js} +552 -181
- package/dist/{html-2r2KmLwi.js → html-BCZ3Xtb_.js} +6 -6
- package/dist/{session-stop-BfY4rhJs.js → ingest-BDf3D50j.js} +2134 -2553
- package/dist/{install-C-oE6C_u.js → install-DCFJFkC0.js} +2 -2
- package/dist/instrumentation.js +4 -4
- package/dist/{lineage-CsvrEFQe.js → lineage-B_m-4TJw.js} +2 -2
- package/dist/{stop-DYzjRf2U.js → list-CN2QA2R9.js} +1656 -685
- package/dist/{logging-D5gkyvnK.js → logging-dQ9ZRGQ8.js} +47 -9
- package/dist/media-CYm1QD8T.js +2356 -0
- package/dist/{message-DwvJ-I3w.js → message-DSXGj1hM.js} +19 -29
- package/dist/{model-input-MAq2881y.js → model-input--TrP9hYV.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-DIF6Li06.js → oauth-callback-server-DHCZC6B4.js} +2 -2
- package/dist/{oauth-relay-DPE-wrwO.js → oauth-relay-pPMGnDZt.js} +1 -1
- package/dist/{registry-BBkWFCl8.js → registry-CZOzddwu.js} +5 -8
- package/dist/{resolve-B38MkHXE.js → resolve-cKOQ14Dh.js} +3 -3
- package/dist/{result-BaqSZcJb.js → result-DcvEOe1r.js} +119 -93
- package/dist/result-event-type-BdIJuZxg.js +48 -0
- package/dist/rule-DAxQY-1h.js +20 -0
- package/dist/{runner-11h8PrHh.js → runner-DBfUW44l.js} +14 -16
- package/dist/{sandbox-egress-signals-CTcACAtJ.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
- package/dist/{schema-DriSvB40.d.ts → schema-BEHKxr4I.d.ts} +861 -298
- package/dist/{schema-obw5jvR4.js → schema-Bk9Nm2E8.js} +344 -153
- package/dist/{service-account-Bx93N1n1.js → service-account-CVYsFjty.js} +3 -3
- package/dist/{service-account-Zc5bUcIJ.js → service-account-Ts4ulcrV.js} +68 -68
- package/dist/{skills-C8Npu5zO.js → skills-VTnhAJWm.js} +2 -2
- package/dist/{slack-conversation-unfurl-DlRVA02H.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -11
- package/dist/{spawn-CXr58R0x.js → spawn-vxAarlX5.js} +6 -6
- package/dist/start-conversation-CEn2KH1A.js +941 -0
- package/dist/{state-CGrGVeQC.js → state-C1P3_Ywk.js} +4 -4
- package/dist/statuses-_cRJHXK7.js +150 -0
- package/dist/store-DFZaN-Ix.js +492 -0
- package/dist/task-queue-Cx4Lmjyk.js +90 -0
- package/dist/task-runner-CbTwFA6k.js +1432 -0
- package/dist/{thread-context-Dyj1KWaY.js → thread-context-BkAZDTX2.js} +13 -11
- package/dist/thread-state-DhPndWi1.js +5625 -0
- package/dist/{validation-DxVNIxA0.js → validation-nIzMtAVJ.js} +1 -1
- package/dist/{task-queue-CaZffYaH.js → vercel-queue-hW90XzbG.js} +93 -172
- package/dist/{version-Cr7Z71yG.js → version-Brbtz4Qf.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-C6LOZ2d2.js → warmup-BDA5myRK.js} +5832 -4567
- package/dist/web-message-id-C6P83ans.js +10 -0
- package/dist/{worker-CUBtu1Li.js → worker-D63RcaVD.js} +20 -8
- package/migrations/0126_artifact_drop_public.sql +8 -0
- package/migrations/0127_artifact_path.sql +4 -0
- package/migrations/0128_artifact_path_index.sql +1 -0
- package/migrations/0129_review_item_answered_index.sql +1 -0
- package/migrations/0130_review_item_status_index.sql +1 -0
- package/migrations/0131_brief_outcome_status.sql +1 -0
- package/migrations/0132_brief_outcome_status_backfill.sql +7 -0
- package/migrations/0133_brief_created_at_index.sql +1 -0
- package/migrations/0134_slack_person_search_index.sql +1 -0
- package/migrations/0135_code_change_size.sql +3 -0
- package/migrations/0136_merge_conflict_notice_dismiss.sql +16 -0
- package/migrations/0137_inbox_snoozes.sql +27 -0
- package/migrations/0138_code_change_search_index.sql +2 -0
- package/migrations/0139_review_item_owner.sql +22 -0
- package/migrations/0140_review_item_owner_index.sql +1 -0
- package/migrations/0141_memory_core_adoption.sql +89 -0
- package/migrations/0142_memory_core_indexes.sql +17 -0
- package/migrations/0143_todos.sql +14 -0
- package/migrations/0144_inbox_items.sql +32 -0
- package/migrations/0145_todo_changed_by_agent.sql +1 -0
- package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
- package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
- package/migrations/0148_authorization_request_index.sql +1 -0
- package/migrations/0149_conversation_metadata.sql +10 -0
- package/migrations/0150_conversation_metadata_fill.sql +39 -0
- package/migrations/0151_conversation_search_index.sql +1 -0
- package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
- package/migrations/0153_artifact_expiry.sql +1 -0
- package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
- package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
- package/migrations/0156_conversation_kind_lead.sql +6 -0
- package/migrations/0157_conversation_lead_actor_index.sql +1 -0
- package/migrations/meta/0126_snapshot.json +5488 -0
- package/migrations/meta/0127_snapshot.json +5519 -0
- package/migrations/meta/0128_snapshot.json +5519 -0
- package/migrations/meta/0129_snapshot.json +5547 -0
- package/migrations/meta/0130_snapshot.json +5563 -0
- package/migrations/meta/0131_snapshot.json +5569 -0
- package/migrations/meta/0132_snapshot.json +5569 -0
- package/migrations/meta/0133_snapshot.json +5590 -0
- package/migrations/meta/0134_snapshot.json +5606 -0
- package/migrations/meta/0135_snapshot.json +5624 -0
- package/migrations/meta/0136_snapshot.json +5624 -0
- package/migrations/meta/0137_snapshot.json +5864 -0
- package/migrations/meta/0138_snapshot.json +5894 -0
- package/migrations/meta/0139_snapshot.json +5898 -0
- package/migrations/meta/0140_snapshot.json +5919 -0
- package/migrations/meta/0141_snapshot.json +6429 -0
- package/migrations/meta/0142_snapshot.json +6457 -0
- package/migrations/meta/0143_snapshot.json +6434 -0
- package/migrations/meta/0144_snapshot.json +6434 -0
- package/migrations/meta/0145_snapshot.json +6440 -0
- package/migrations/meta/0146_snapshot.json +6446 -0
- package/migrations/meta/0147_snapshot.json +6452 -0
- package/migrations/meta/0148_snapshot.json +6474 -0
- package/migrations/meta/0149_snapshot.json +6490 -0
- package/migrations/meta/0150_snapshot.json +6490 -0
- package/migrations/meta/0151_snapshot.json +6505 -0
- package/migrations/meta/0152_snapshot.json +6505 -0
- package/migrations/meta/0153_snapshot.json +6511 -0
- package/migrations/meta/0154_snapshot.json +6533 -0
- package/migrations/meta/0155_snapshot.json +6511 -0
- package/migrations/meta/0156_snapshot.json +6511 -0
- package/migrations/meta/0157_snapshot.json +6527 -0
- package/migrations/meta/_journal.json +224 -0
- package/package.json +7 -8
- package/skills/design-automation-skill/SKILL.md +108 -0
- package/dist/briefs-DKxkoruh.js +0 -395
- package/dist/conversation-M9KZ5JxF.js +0 -1024
- package/dist/prompt-CaMyeCpA.js +0 -910
- package/dist/schedule-DWxZ3kja.js +0 -1146
- package/dist/store-D4FQ1Nml.js +0 -335
- package/dist/task-runner-Dm7BHbGp.js +0 -287
- package/dist/turn-session-routing-CD0BRCex.js +0 -263
- package/dist/turn-user-message-9IxeEv5v.js +0 -364
- package/dist/users-CaUAYMb3.js +0 -181
- package/dist/viewer-AHldghAD.js +0 -212
- package/dist/web-message-id-BT8Mg8LL.js +0 -418
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import { Qo as getDispatchRecord, S as persistConversationMessages, Yo as getDispatchConversationId, dl as JUNIOR_THREAD_STATE_TTL_MS, hl as createDurableLocationConfigurationService } from "./projection-jZSlEAXG.js";
|
|
2
|
-
import { J as toOptionalString, K as isRecord, q as toOptionalNumber } from "./logging-D5gkyvnK.js";
|
|
3
|
-
import { o as getDb, tt as getStateAdapter } from "./db-CFZggNoy.js";
|
|
4
|
-
// src/chat/state/conversation.ts
|
|
5
|
-
function defaultConversationState() {
|
|
6
|
-
return {
|
|
7
|
-
schemaVersion: 1,
|
|
8
|
-
messages: [],
|
|
9
|
-
processing: {},
|
|
10
|
-
vision: { byFileId: {} }
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
function coercePendingAuthState(value) {
|
|
14
|
-
if (!isRecord(value)) return;
|
|
15
|
-
const kind = value["kind"];
|
|
16
|
-
const provider = toOptionalString(value["provider"]);
|
|
17
|
-
const actorId = toOptionalString(value["actorId"]);
|
|
18
|
-
const authSessionId = toOptionalString(value["authSessionId"]);
|
|
19
|
-
const scope = toOptionalString(value["scope"]);
|
|
20
|
-
const sessionId = toOptionalString(value["sessionId"]);
|
|
21
|
-
const linkSentAtMs = toOptionalNumber(value["linkSentAtMs"]);
|
|
22
|
-
if (kind !== "mcp" && kind !== "plugin" || !provider || !actorId || kind === "mcp" && !authSessionId || !sessionId || typeof linkSentAtMs !== "number") return;
|
|
23
|
-
const base = {
|
|
24
|
-
provider,
|
|
25
|
-
actorId,
|
|
26
|
-
...scope ? { scope } : void 0,
|
|
27
|
-
sessionId,
|
|
28
|
-
linkSentAtMs
|
|
29
|
-
};
|
|
30
|
-
return kind === "mcp" ? {
|
|
31
|
-
...base,
|
|
32
|
-
authSessionId,
|
|
33
|
-
kind
|
|
34
|
-
} : {
|
|
35
|
-
...base,
|
|
36
|
-
kind
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
/** Safely coerce an unknown persisted value into a ThreadConversationState. */
|
|
40
|
-
function coerceThreadConversationState(value) {
|
|
41
|
-
if (!isRecord(value)) return defaultConversationState();
|
|
42
|
-
const root = value;
|
|
43
|
-
const rawConversation = isRecord(root.conversation) ? root.conversation : {};
|
|
44
|
-
const messages = [];
|
|
45
|
-
const rawProcessing = isRecord(rawConversation["processing"]) ? rawConversation["processing"] : {};
|
|
46
|
-
const processing = {
|
|
47
|
-
activeTurnId: toOptionalString(rawProcessing["activeTurnId"]),
|
|
48
|
-
lastCompletedAtMs: toOptionalNumber(rawProcessing["lastCompletedAtMs"]),
|
|
49
|
-
pendingAuth: coercePendingAuthState(rawProcessing["pendingAuth"])
|
|
50
|
-
};
|
|
51
|
-
const rawVision = isRecord(rawConversation["vision"]) ? rawConversation["vision"] : {};
|
|
52
|
-
const rawVisionByFileId = isRecord(rawVision["byFileId"]) ? rawVision["byFileId"] : {};
|
|
53
|
-
const byFileId = {};
|
|
54
|
-
for (const [fileId, value] of Object.entries(rawVisionByFileId)) {
|
|
55
|
-
if (typeof fileId !== "string" || fileId.trim().length === 0) continue;
|
|
56
|
-
if (!isRecord(value)) continue;
|
|
57
|
-
const summary = toOptionalString(value["summary"]);
|
|
58
|
-
const analyzedAtMs = toOptionalNumber(value["analyzedAtMs"]);
|
|
59
|
-
if (!summary || !analyzedAtMs) continue;
|
|
60
|
-
byFileId[fileId] = {
|
|
61
|
-
summary,
|
|
62
|
-
analyzedAtMs
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
schemaVersion: 1,
|
|
67
|
-
messages,
|
|
68
|
-
processing,
|
|
69
|
-
vision: {
|
|
70
|
-
backfillCompletedAtMs: toOptionalNumber(rawVision["backfillCompletedAtMs"]),
|
|
71
|
-
byFileId
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Wrap active conversation control into the thread scratch envelope.
|
|
77
|
-
*
|
|
78
|
-
* Visible history lives in SQL. Image summaries use a separate disposable
|
|
79
|
-
* cache, so thread scratch does not retain them.
|
|
80
|
-
*/
|
|
81
|
-
function buildConversationStatePatch(conversation) {
|
|
82
|
-
return { conversation: {
|
|
83
|
-
schemaVersion: 1,
|
|
84
|
-
processing: { ...conversation.processing }
|
|
85
|
-
} };
|
|
86
|
-
}
|
|
87
|
-
// src/chat/runtime/thread-state.ts
|
|
88
|
-
function threadStateKey(threadId) {
|
|
89
|
-
return `thread-state:${threadId}`;
|
|
90
|
-
}
|
|
91
|
-
function channelStateKey(channelId) {
|
|
92
|
-
return `channel-state:${channelId}`;
|
|
93
|
-
}
|
|
94
|
-
function buildThreadStatePayload(patch) {
|
|
95
|
-
const payload = {};
|
|
96
|
-
if (patch.conversation) Object.assign(payload, buildConversationStatePatch(patch.conversation));
|
|
97
|
-
if (patch.sandboxRef !== void 0) {
|
|
98
|
-
payload["app_sandbox_id"] = patch.sandboxRef?.id ?? "";
|
|
99
|
-
payload["app_sandbox_dependency_profile_hash"] = patch.sandboxRef?.profileHash ?? "";
|
|
100
|
-
payload["app_sandbox_workspace_id"] = patch.sandboxRef?.workspaceId ?? "";
|
|
101
|
-
}
|
|
102
|
-
return payload;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Merge a payload into thread scratch with Junior's TTL.
|
|
106
|
-
*
|
|
107
|
-
* Chat SDK state writes hardcode a 30-day TTL. This boundary owns Junior's
|
|
108
|
-
* shorter retention policy for the same scratch keys.
|
|
109
|
-
*/
|
|
110
|
-
async function mergePersistedState(key, payload) {
|
|
111
|
-
if (Object.keys(payload).length === 0) return;
|
|
112
|
-
const stateAdapter = getStateAdapter();
|
|
113
|
-
await stateAdapter.connect();
|
|
114
|
-
const existing = await stateAdapter.get(key) ?? {};
|
|
115
|
-
await stateAdapter.set(key, {
|
|
116
|
-
...existing,
|
|
117
|
-
...payload
|
|
118
|
-
}, JUNIOR_THREAD_STATE_TTL_MS);
|
|
119
|
-
}
|
|
120
|
-
/** Extract persisted sandbox metadata from thread state payload. */
|
|
121
|
-
function getPersistedSandboxState(state) {
|
|
122
|
-
const id = toOptionalString(state["app_sandbox_id"]);
|
|
123
|
-
if (!id) return;
|
|
124
|
-
const profileHash = toOptionalString(state["app_sandbox_dependency_profile_hash"]);
|
|
125
|
-
const workspaceId = toOptionalString(state["app_sandbox_workspace_id"]);
|
|
126
|
-
return {
|
|
127
|
-
id,
|
|
128
|
-
...profileHash ? { profileHash } : void 0,
|
|
129
|
-
...workspaceId ? { workspaceId } : void 0
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
/** Persist only the Redis-backed runtime scratch in a thread-state patch. */
|
|
133
|
-
async function persistThreadRuntimeState(conversationId, patch) {
|
|
134
|
-
await mergePersistedState(threadStateKey(conversationId), buildThreadStatePayload(patch));
|
|
135
|
-
}
|
|
136
|
-
/** Load the persisted state payload for a thread without requiring a Chat singleton. */
|
|
137
|
-
async function getPersistedThreadState(threadId) {
|
|
138
|
-
const stateAdapter = getStateAdapter();
|
|
139
|
-
await stateAdapter.connect();
|
|
140
|
-
return await stateAdapter.get(threadStateKey(threadId)) ?? {};
|
|
141
|
-
}
|
|
142
|
-
/** Persist a thread-state patch by thread id without constructing a Chat thread. */
|
|
143
|
-
async function persistThreadStateById(threadId, patch) {
|
|
144
|
-
if (patch.conversation) await persistConversationMessages({
|
|
145
|
-
conversation: patch.conversation,
|
|
146
|
-
conversationId: threadId
|
|
147
|
-
});
|
|
148
|
-
await mergePersistedState(threadStateKey(threadId), buildThreadStatePayload(patch));
|
|
149
|
-
}
|
|
150
|
-
/** Load legacy Redis-backed channel state during the SQL cutover. */
|
|
151
|
-
async function getLegacyChannelState(channelId) {
|
|
152
|
-
const stateAdapter = getStateAdapter();
|
|
153
|
-
await stateAdapter.connect();
|
|
154
|
-
return await stateAdapter.get(channelStateKey(channelId)) ?? {};
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Resolve durable location configuration.
|
|
158
|
-
*
|
|
159
|
-
* Slack still reads the old channel-id Redis bag once during cutover.
|
|
160
|
-
*/
|
|
161
|
-
function getLocationConfigurationService(destination) {
|
|
162
|
-
if (destination.platform !== "slack") throw new Error("Location configuration requires a Slack Location");
|
|
163
|
-
return createDurableLocationConfigurationService({
|
|
164
|
-
destination,
|
|
165
|
-
db: getDb(),
|
|
166
|
-
loadLegacy: async () => await getLegacyChannelState(destination.channelId)
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
// src/chat/services/turn-session-routing.ts
|
|
170
|
-
async function loadConversationChain(conversationId, conversationStore) {
|
|
171
|
-
const chain = [];
|
|
172
|
-
const seen = /* @__PURE__ */ new Set();
|
|
173
|
-
let cursor = conversationId;
|
|
174
|
-
while (cursor && !seen.has(cursor)) {
|
|
175
|
-
seen.add(cursor);
|
|
176
|
-
const conversation = await conversationStore.get({ conversationId: cursor });
|
|
177
|
-
if (!conversation) break;
|
|
178
|
-
chain.push(conversation);
|
|
179
|
-
cursor = conversation.parentConversationId;
|
|
180
|
-
}
|
|
181
|
-
return chain;
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Normalize a stored Slack session source against the conversation destination.
|
|
185
|
-
*
|
|
186
|
-
* Does not create channel or thread values from the conversation id.
|
|
187
|
-
*/
|
|
188
|
-
function slackSourceForDestination(args) {
|
|
189
|
-
if (args.source?.kind !== "slack" || args.source.channelId !== args.destination.channelId) return;
|
|
190
|
-
const threadTs = args.source.threadTs?.trim();
|
|
191
|
-
return {
|
|
192
|
-
kind: "slack",
|
|
193
|
-
visibility: args.source.visibility ?? "public",
|
|
194
|
-
teamId: args.source.teamId?.trim() || args.destination.teamId,
|
|
195
|
-
channelId: args.source.channelId,
|
|
196
|
-
...threadTs ? { threadTs } : void 0
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Resolve the Conversation Location, Destination, and session Source.
|
|
201
|
-
*
|
|
202
|
-
* Reads parent Conversations when this Conversation has no Destination.
|
|
203
|
-
*/
|
|
204
|
-
async function resolveConversationRouting(args) {
|
|
205
|
-
const conversationStore = args.conversationStore ?? (await import("./db-CFZggNoy.js").then((n) => n.n)).getConversationStore();
|
|
206
|
-
const chain = await loadConversationChain(args.conversationId, conversationStore);
|
|
207
|
-
let destination;
|
|
208
|
-
let source;
|
|
209
|
-
let location;
|
|
210
|
-
for (const conversation of chain) {
|
|
211
|
-
destination ??= conversation.destination;
|
|
212
|
-
source ??= conversation.sessionSource;
|
|
213
|
-
location ??= conversation.location;
|
|
214
|
-
if (destination && source) break;
|
|
215
|
-
}
|
|
216
|
-
if (!destination) return;
|
|
217
|
-
if (destination.platform === "slack") {
|
|
218
|
-
const slackSource = slackSourceForDestination({
|
|
219
|
-
destination,
|
|
220
|
-
source
|
|
221
|
-
});
|
|
222
|
-
return {
|
|
223
|
-
destination,
|
|
224
|
-
...location ? { location } : void 0,
|
|
225
|
-
...slackSource ? { source: slackSource } : void 0
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
return {
|
|
229
|
-
destination,
|
|
230
|
-
...location ? { location } : void 0,
|
|
231
|
-
...source ? { source } : void 0
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
/** Require the Conversation Destination and Source from SQL. */
|
|
235
|
-
async function resolveTurnSessionRouting(args) {
|
|
236
|
-
const routing = await resolveConversationRouting(args);
|
|
237
|
-
if (!routing?.destination || !routing.source) throw new Error(`Conversation ${args.conversationId} is missing durable routing metadata`);
|
|
238
|
-
return {
|
|
239
|
-
destination: routing.destination,
|
|
240
|
-
...routing.location ? { location: routing.location } : void 0,
|
|
241
|
-
source: routing.source
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Require the Destination and Source to resume a Turn.
|
|
246
|
-
*
|
|
247
|
-
* A dispatch Conversation stores the dispatch Source, which has no session
|
|
248
|
-
* Source. Its dispatch record owns the Destination and Source.
|
|
249
|
-
*/
|
|
250
|
-
async function resolveTurnResumeRouting(args) {
|
|
251
|
-
if (!args.dispatchId) return await resolveTurnSessionRouting(args);
|
|
252
|
-
const dispatch = await getDispatchRecord(args.dispatchId);
|
|
253
|
-
if (!dispatch) throw new Error(`Dispatch record is missing for ${args.dispatchId}`);
|
|
254
|
-
const dispatchConversationId = getDispatchConversationId(dispatch);
|
|
255
|
-
if (dispatchConversationId !== args.conversationId) throw new Error(`Dispatch ${dispatch.id} belongs to ${dispatchConversationId}, not ${args.conversationId}`);
|
|
256
|
-
const location = (await resolveConversationRouting(args))?.location;
|
|
257
|
-
return {
|
|
258
|
-
destination: dispatch.destination,
|
|
259
|
-
...location ? { location } : void 0,
|
|
260
|
-
source: dispatch.source
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
export { getPersistedThreadState as a, coerceThreadConversationState as c, getPersistedSandboxState as i, resolveTurnResumeRouting as n, persistThreadRuntimeState as o, getLocationConfigurationService as r, persistThreadStateById as s, resolveConversationRouting as t };
|
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
import { Yt as readInboundMessageSender } from "./projection-jZSlEAXG.js";
|
|
2
|
-
import { v as parseSlackMessageTs } from "./actor-BsBdxDXQ.js";
|
|
3
|
-
import { r as getConversationEventStore, s as getSqlExecutor } from "./db-CFZggNoy.js";
|
|
4
|
-
import { y as juniorAgentInvocations } from "./executor-BPkZDx5-.js";
|
|
5
|
-
import { createHash } from "node:crypto";
|
|
6
|
-
import { inArray } from "drizzle-orm";
|
|
7
|
-
// src/chat/state/turn-id.ts
|
|
8
|
-
/** Build a stable turn identifier from a message ID. */
|
|
9
|
-
function buildDeterministicTurnId(messageId) {
|
|
10
|
-
return `turn_${messageId.replace(/[^a-zA-Z0-9_-]/g, "_")}`;
|
|
11
|
-
}
|
|
12
|
-
/** Build the stable visible assistant-message identity for one logical turn. */
|
|
13
|
-
function buildDeterministicAssistantMessageId(turnId) {
|
|
14
|
-
return `${turnId}:assistant:1`;
|
|
15
|
-
}
|
|
16
|
-
// src/chat/agent-invocations/ids.ts
|
|
17
|
-
const CREATE_LOCK_PREFIX = "junior:agent_invocation:create";
|
|
18
|
-
/**
|
|
19
|
-
* Return the SQL lock that one parent Conversation takes to start, message,
|
|
20
|
-
* or stop its child agents.
|
|
21
|
-
*/
|
|
22
|
-
function getChildAgentLockName(parentConversationId) {
|
|
23
|
-
return `${CREATE_LOCK_PREFIX}:${parentConversationId}`;
|
|
24
|
-
}
|
|
25
|
-
function stableId(prefix, ...parts) {
|
|
26
|
-
return `${prefix}:${createHash("sha256").update(parts.join("\0")).digest("hex").slice(0, 32)}`;
|
|
27
|
-
}
|
|
28
|
-
/** Return the stable identity for one retry-safe delegated task. */
|
|
29
|
-
function getAgentInvocationId(parentConversationId, idempotencyKey) {
|
|
30
|
-
return stableId("agent-invocation", parentConversationId, idempotencyKey);
|
|
31
|
-
}
|
|
32
|
-
/** Return the stable child identity for one invocation without a named binding. */
|
|
33
|
-
function getUnnamedAgentConversationId(invocationId) {
|
|
34
|
-
return stableId("agent", invocationId);
|
|
35
|
-
}
|
|
36
|
-
/** Return the stable child identity for one named binding. */
|
|
37
|
-
function getNamedAgentConversationId(parentConversationId, name) {
|
|
38
|
-
return stableId("agent", parentConversationId, name);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Return the stable identity of the agent invocation that gives one child
|
|
42
|
-
* agent result to the child Conversation that started that child agent.
|
|
43
|
-
*/
|
|
44
|
-
function getAgentInvocationIdForResult(resultInvocationId) {
|
|
45
|
-
return stableId("agent-invocation", "result", resultInvocationId);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Return the stable identity of the agent invocation that gives one message
|
|
49
|
-
* from a child agent to the child Conversation that started that child agent.
|
|
50
|
-
*/
|
|
51
|
-
function getAgentInvocationIdForMessage(messageId) {
|
|
52
|
-
return stableId("agent-invocation", "message", messageId);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Return the stable identity of the agent invocation that gives one batch of
|
|
56
|
-
* watch events to a child Conversation. The first message of the batch names
|
|
57
|
-
* it.
|
|
58
|
-
*/
|
|
59
|
-
function getAgentInvocationIdForEvents(messageId) {
|
|
60
|
-
return stableId("agent-invocation", "events", messageId);
|
|
61
|
-
}
|
|
62
|
-
/** Return the stable turn identity advanced by one agent invocation. */
|
|
63
|
-
function getAgentInvocationTurnId(invocationId) {
|
|
64
|
-
return `agent-invocation:${invocationId}`;
|
|
65
|
-
}
|
|
66
|
-
/** Return the stable mailbox identity for one agent invocation. */
|
|
67
|
-
function getAgentInvocationMessageId(invocationId) {
|
|
68
|
-
return `agent-invocation:${invocationId}:input`;
|
|
69
|
-
}
|
|
70
|
-
const REPLY_MESSAGE_PREFIX = "agent-reply:";
|
|
71
|
-
/**
|
|
72
|
-
* Return the parent mailbox identity of one child agent `reply` call.
|
|
73
|
-
* `senderId` is the Agent invocation that sent it, or the child Conversation
|
|
74
|
-
* when no Agent invocation names the child.
|
|
75
|
-
*/
|
|
76
|
-
function getAgentReplyMessageId(senderId, toolCallId) {
|
|
77
|
-
return `${REPLY_MESSAGE_PREFIX}${senderId}:${toolCallId}`;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Return the key of the `reply` of one Turn on a child's Conversation loop.
|
|
81
|
-
* Readers take the sender from the message's sender fields, not this key.
|
|
82
|
-
*/
|
|
83
|
-
function getTurnReplyKey(turnId, toolCallId) {
|
|
84
|
-
return `${turnId}:${toolCallId}`;
|
|
85
|
-
}
|
|
86
|
-
/** Return the stable parent mailbox identity for one terminal result. */
|
|
87
|
-
function getAgentInvocationResultMessageId(invocationId) {
|
|
88
|
-
return `agent-invocation:${invocationId}:result`;
|
|
89
|
-
}
|
|
90
|
-
// src/chat/agent-invocations/child-message.ts
|
|
91
|
-
/** Mailbox metadata that stores who sent one child reply or result. */
|
|
92
|
-
function childMessageSenderMetadata(sender) {
|
|
93
|
-
return { sender };
|
|
94
|
-
}
|
|
95
|
-
/** Read who sent one child reply or result in a parent's mailbox. */
|
|
96
|
-
async function readChildMessageSender(message) {
|
|
97
|
-
return readInboundMessageSender(message) ?? (await readLegacyChildMessageSenders([message.inboundMessageId])).get(message.inboundMessageId);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Read who sent each child reply or result, in message order. Messages
|
|
101
|
-
* without stored sender fields share one legacy read.
|
|
102
|
-
*/
|
|
103
|
-
async function readChildMessageSenders(messages) {
|
|
104
|
-
const stored = messages.map((message) => readInboundMessageSender(message));
|
|
105
|
-
const legacy = await readLegacyChildMessageSenders(messages.flatMap((message, index) => stored[index] ? [] : [message.inboundMessageId]));
|
|
106
|
-
return messages.map((message, index) => stored[index] ?? legacy.get(message.inboundMessageId));
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* List the child replies and results among the ids that reached one
|
|
110
|
-
* mailbox, oldest first, with the sender fields that the mailbox keeps.
|
|
111
|
-
*/
|
|
112
|
-
async function listChildMessages(inboundMessageIds, messageSenders) {
|
|
113
|
-
const legacy = await readLegacyChildMessageSenders(inboundMessageIds.filter((id) => !messageSenders[id]));
|
|
114
|
-
return inboundMessageIds.flatMap((inboundMessageId) => {
|
|
115
|
-
const sender = messageSenders[inboundMessageId] ?? legacy.get(inboundMessageId);
|
|
116
|
-
return sender ? [{
|
|
117
|
-
inboundMessageId,
|
|
118
|
-
sender
|
|
119
|
-
}] : [];
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Return the Agent invocation whose own Turn sent the message. A Turn on the
|
|
124
|
-
* child's Conversation loop has none, even when the message names the
|
|
125
|
-
* child's newest Agent invocation.
|
|
126
|
-
*
|
|
127
|
-
* TODO(dcramer): Remove with Agent invocation rows (#3060 step 7).
|
|
128
|
-
*/
|
|
129
|
-
function ownAgentInvocation(sender) {
|
|
130
|
-
const { agentInvocationId } = sender;
|
|
131
|
-
return agentInvocationId && sender.turnId === getAgentInvocationTurnId(agentInvocationId) ? agentInvocationId : void 0;
|
|
132
|
-
}
|
|
133
|
-
/** Return whether the message is the result of an Agent invocation. */
|
|
134
|
-
function isAgentInvocationResult(message) {
|
|
135
|
-
const agentInvocationId = ownAgentInvocation(message.sender);
|
|
136
|
-
return agentInvocationId !== void 0 && message.inboundMessageId === getAgentInvocationResultMessageId(agentInvocationId);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Return whether one Agent invocation sent a reply to its parent: a message
|
|
140
|
-
* names it as sender and is not its own result.
|
|
141
|
-
*/
|
|
142
|
-
function hasAgentInvocationReply(messages, agentInvocationId) {
|
|
143
|
-
return messages.some((message) => message.sender.agentInvocationId === agentInvocationId && !isAgentInvocationResult(message));
|
|
144
|
-
}
|
|
145
|
-
const LEGACY_REPLY_ID = /^agent-reply:(agent(?:-invocation)?:[0-9a-f]{32}):(?:(turn_[A-Za-z0-9_-]+)(?::|$))?/;
|
|
146
|
-
const LEGACY_RESULT_ID = /^agent-invocation:(agent-invocation:[0-9a-f]{32}):result$/;
|
|
147
|
-
/**
|
|
148
|
-
* Read the sender of child messages that reached a mailbox before senders
|
|
149
|
-
* stored their fields, from their ids.
|
|
150
|
-
*
|
|
151
|
-
* TODO: remove one release after this ships. Step 7 of #3060 deletes it and
|
|
152
|
-
* makes the id a plain generated key.
|
|
153
|
-
*/
|
|
154
|
-
async function readLegacyChildMessageSenders(inboundMessageIds) {
|
|
155
|
-
const senders = /* @__PURE__ */ new Map();
|
|
156
|
-
const byAgentInvocation = /* @__PURE__ */ new Map();
|
|
157
|
-
for (const id of inboundMessageIds) {
|
|
158
|
-
const result = LEGACY_RESULT_ID.exec(id);
|
|
159
|
-
const reply = result ? void 0 : LEGACY_REPLY_ID.exec(id);
|
|
160
|
-
const senderId = result?.[1] ?? reply?.[1];
|
|
161
|
-
if (!senderId) continue;
|
|
162
|
-
const turnId = reply?.[2];
|
|
163
|
-
if (senderId.startsWith("agent-invocation:")) byAgentInvocation.set(id, {
|
|
164
|
-
agentInvocationId: senderId,
|
|
165
|
-
turnId
|
|
166
|
-
});
|
|
167
|
-
else if (turnId) senders.set(id, {
|
|
168
|
-
conversationId: senderId,
|
|
169
|
-
turnId
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
if (byAgentInvocation.size === 0) return senders;
|
|
173
|
-
const rows = await getSqlExecutor().db().select({
|
|
174
|
-
childConversationId: juniorAgentInvocations.childConversationId,
|
|
175
|
-
invocationId: juniorAgentInvocations.invocationId
|
|
176
|
-
}).from(juniorAgentInvocations).where(inArray(juniorAgentInvocations.invocationId, [...new Set([...byAgentInvocation.values()].map((s) => s.agentInvocationId))]));
|
|
177
|
-
const childOf = new Map(rows.map((row) => [row.invocationId, row.childConversationId]));
|
|
178
|
-
for (const [id, { agentInvocationId, turnId }] of byAgentInvocation) {
|
|
179
|
-
const conversationId = childOf.get(agentInvocationId);
|
|
180
|
-
if (!conversationId) continue;
|
|
181
|
-
senders.set(id, {
|
|
182
|
-
agentInvocationId,
|
|
183
|
-
conversationId,
|
|
184
|
-
turnId: turnId ?? getAgentInvocationTurnId(agentInvocationId)
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
return senders;
|
|
188
|
-
}
|
|
189
|
-
// src/chat/conversations/turn-lifecycle.ts
|
|
190
|
-
/** Persist correlated turn lifecycle facts with retry-safe terminal exclusion. */
|
|
191
|
-
var ConversationTurnLifecycleService = class {
|
|
192
|
-
events;
|
|
193
|
-
constructor(events) {
|
|
194
|
-
this.events = events;
|
|
195
|
-
}
|
|
196
|
-
/** Record the turn start once after every input message is durable. */
|
|
197
|
-
async start(input) {
|
|
198
|
-
await this.events.append(input.conversationId, [{
|
|
199
|
-
idempotencyKey: `turn:${input.turnId}:started`,
|
|
200
|
-
createdAtMs: input.createdAtMs,
|
|
201
|
-
data: {
|
|
202
|
-
type: "turn_started",
|
|
203
|
-
turnId: input.turnId,
|
|
204
|
-
inputMessageIds: input.inputMessageIds,
|
|
205
|
-
surface: input.surface,
|
|
206
|
-
...input.threadContextThroughSeq === void 0 ? void 0 : { threadContextThroughSeq: input.threadContextThroughSeq }
|
|
207
|
-
}
|
|
208
|
-
}]);
|
|
209
|
-
}
|
|
210
|
-
/** Return the input message ids that started a Turn, when it started. */
|
|
211
|
-
async loadInputMessageIds(conversationId, turnId) {
|
|
212
|
-
const event = await this.events.loadByIdempotencyKey(conversationId, `turn:${turnId}:started`);
|
|
213
|
-
return event?.data.type === "turn_started" ? event.data.inputMessageIds : void 0;
|
|
214
|
-
}
|
|
215
|
-
/** Record a completion that is not a failure once. */
|
|
216
|
-
async complete(input) {
|
|
217
|
-
await this.events.append(input.conversationId, [{
|
|
218
|
-
idempotencyKey: `turn:${input.turnId}:terminal`,
|
|
219
|
-
createdAtMs: input.createdAtMs,
|
|
220
|
-
data: {
|
|
221
|
-
type: "turn_completed",
|
|
222
|
-
turnId: input.turnId,
|
|
223
|
-
outcome: input.outcome
|
|
224
|
-
}
|
|
225
|
-
}]);
|
|
226
|
-
}
|
|
227
|
-
/** Record a classified failure once. Do not store raw error text. */
|
|
228
|
-
async fail(input) {
|
|
229
|
-
await this.events.append(input.conversationId, [{
|
|
230
|
-
idempotencyKey: `turn:${input.turnId}:terminal`,
|
|
231
|
-
createdAtMs: input.createdAtMs,
|
|
232
|
-
data: {
|
|
233
|
-
type: "turn_failed",
|
|
234
|
-
turnId: input.turnId,
|
|
235
|
-
failureCode: input.failureCode,
|
|
236
|
-
...input.failureReason ? { failureReason: input.failureReason } : void 0,
|
|
237
|
-
...input.eventId ? { eventId: input.eventId } : void 0
|
|
238
|
-
}
|
|
239
|
-
}]);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
/** Return the Turn lifecycle that records Conversation events. */
|
|
243
|
-
function getTurnLifecycle() {
|
|
244
|
-
return new ConversationTurnLifecycleService(getConversationEventStore());
|
|
245
|
-
}
|
|
246
|
-
// src/chat/runtime/turn.ts
|
|
247
|
-
/** Classified Slack turn failure carrying the owning Sentry capture outward. */
|
|
248
|
-
var ConversationTurnBoundaryError = class extends Error {
|
|
249
|
-
eventId;
|
|
250
|
-
failureCode;
|
|
251
|
-
constructor(args) {
|
|
252
|
-
super(args.cause instanceof Error ? args.cause.message : String(args.cause), { cause: args.cause });
|
|
253
|
-
this.name = "ConversationTurnBoundaryError";
|
|
254
|
-
this.eventId = args.eventId;
|
|
255
|
-
this.failureCode = args.failureCode;
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
/** Return a classified Slack boundary failure without erasing its cause. */
|
|
259
|
-
function getConversationTurnBoundaryError(error) {
|
|
260
|
-
return error instanceof ConversationTurnBoundaryError ? error : void 0;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Queue-worker yield routing: respond.ts returns a suspended AgentRunOutcome
|
|
264
|
-
* and the Slack executor raises this at the worker boundary so the lease owner
|
|
265
|
-
* requeues the conversation.
|
|
266
|
-
*/
|
|
267
|
-
var CooperativeTurnYieldError = class extends Error {
|
|
268
|
-
code = "cooperative_turn_yield";
|
|
269
|
-
constructor(message = "Agent turn yielded at a safe boundary") {
|
|
270
|
-
super(message);
|
|
271
|
-
this.name = "CooperativeTurnYieldError";
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
function isCooperativeTurnYieldError(error) {
|
|
275
|
-
return error instanceof CooperativeTurnYieldError;
|
|
276
|
-
}
|
|
277
|
-
/** Error indicating durable turn input could not be committed by the worker owner. */
|
|
278
|
-
var TurnInputCommitLostError = class extends Error {
|
|
279
|
-
code = "turn_input_commit_lost";
|
|
280
|
-
constructor(message = "Turn input commit lost its durable owner") {
|
|
281
|
-
super(message);
|
|
282
|
-
this.name = "TurnInputCommitLostError";
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
/** Return whether an error means the durable worker lost input ownership. */
|
|
286
|
-
function isTurnInputCommitLostError(error) {
|
|
287
|
-
return error instanceof TurnInputCommitLostError;
|
|
288
|
-
}
|
|
289
|
-
/** Error indicating durable turn input should stay pending for a later worker. */
|
|
290
|
-
var TurnInputDeferredError = class extends Error {
|
|
291
|
-
code = "turn_input_deferred";
|
|
292
|
-
constructor(message = "Turn input is deferred until the active resume ends") {
|
|
293
|
-
super(message);
|
|
294
|
-
this.name = "TurnInputDeferredError";
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
/** Return whether an error means the durable worker should redeliver input later. */
|
|
298
|
-
function isTurnInputDeferredError(error) {
|
|
299
|
-
return error instanceof TurnInputDeferredError;
|
|
300
|
-
}
|
|
301
|
-
/** Mark a turn as the active turn in conversation state. */
|
|
302
|
-
function startActiveTurn(args) {
|
|
303
|
-
args.conversation.processing.activeTurnId = args.nextTurnId;
|
|
304
|
-
}
|
|
305
|
-
function clearActiveTurn(conversation, sessionId) {
|
|
306
|
-
if (!sessionId || conversation.processing.activeTurnId === sessionId) conversation.processing.activeTurnId = void 0;
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Close the active turn without marking a Pi session reusable for future
|
|
310
|
-
* history. Use this for auth handoffs and recovery replies that end the live
|
|
311
|
-
* turn but do not produce a completed Pi session.
|
|
312
|
-
*/
|
|
313
|
-
function markTurnClosed(args) {
|
|
314
|
-
clearActiveTurn(args.conversation, args.sessionId);
|
|
315
|
-
args.conversation.processing.lastCompletedAtMs = args.nowMs;
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* Mark a turn as completed after its assistant output has been handled.
|
|
319
|
-
*/
|
|
320
|
-
function markTurnCompleted(args) {
|
|
321
|
-
clearActiveTurn(args.conversation, args.sessionId);
|
|
322
|
-
args.conversation.processing.lastCompletedAtMs = args.nowMs;
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Mark a turn as failed when execution or final user-visible reply delivery
|
|
326
|
-
* cannot be completed. If `sessionId` is provided, `activeTurnId` is only
|
|
327
|
-
* cleared when it still matches the failing turn.
|
|
328
|
-
*/
|
|
329
|
-
function markTurnFailed(args) {
|
|
330
|
-
clearActiveTurn(args.conversation, args.sessionId);
|
|
331
|
-
args.conversation.processing.lastCompletedAtMs = args.nowMs;
|
|
332
|
-
args.markConversationMessage(args.conversation, args.userMessageId, {
|
|
333
|
-
replied: false,
|
|
334
|
-
skippedReason: "reply failed"
|
|
335
|
-
});
|
|
336
|
-
}
|
|
337
|
-
// src/chat/runtime/turn-user-message.ts
|
|
338
|
-
/** Return the user message for a persisted turn/session, if one exists. */
|
|
339
|
-
function getTurnUserMessage(conversation, sessionId) {
|
|
340
|
-
for (let index = conversation.messages.length - 1; index >= 0; index -= 1) {
|
|
341
|
-
const message = conversation.messages[index];
|
|
342
|
-
if (message?.role !== "user") continue;
|
|
343
|
-
if (buildDeterministicTurnId(message.id) === sessionId) return message;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
/** Return the persisted user-message id for a turn/session, if one exists. */
|
|
347
|
-
function getTurnUserMessageId(conversation, sessionId) {
|
|
348
|
-
return getTurnUserMessage(conversation, sessionId)?.id;
|
|
349
|
-
}
|
|
350
|
-
/** Return the Slack timestamp for the user message that a resumed turn acts on. */
|
|
351
|
-
function getTurnUserSlackMessageTs(message) {
|
|
352
|
-
return parseSlackMessageTs(message?.meta?.slackTs);
|
|
353
|
-
}
|
|
354
|
-
/** Rebuild attachment context for a resumed turn from the persisted user message. */
|
|
355
|
-
function getTurnUserReplyAttachmentContext(message) {
|
|
356
|
-
const inboundAttachmentCount = message?.meta?.attachmentCount ?? 0;
|
|
357
|
-
const imageAttachmentCount = message?.meta?.imageAttachmentCount ?? 0;
|
|
358
|
-
const imagesHydrated = message?.meta?.imagesHydrated === true;
|
|
359
|
-
return {
|
|
360
|
-
...inboundAttachmentCount > 0 ? { inboundAttachmentCount } : void 0,
|
|
361
|
-
...!imagesHydrated && imageAttachmentCount > 0 ? { omittedImageAttachmentCount: imageAttachmentCount } : void 0
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
export { getAgentInvocationMessageId as A, ownAgentInvocation as C, getAgentInvocationIdForEvents as D, getAgentInvocationId as E, getNamedAgentConversationId as F, getTurnReplyKey as I, getUnnamedAgentConversationId as L, getAgentInvocationTurnId as M, getAgentReplyMessageId as N, getAgentInvocationIdForMessage as O, getChildAgentLockName as P, buildDeterministicAssistantMessageId as R, listChildMessages as S, readChildMessageSenders as T, ConversationTurnLifecycleService as _, ConversationTurnBoundaryError as a, hasAgentInvocationReply as b, TurnInputDeferredError as c, isTurnInputCommitLostError as d, isTurnInputDeferredError as f, startActiveTurn as g, markTurnFailed as h, getTurnUserSlackMessageTs as i, getAgentInvocationResultMessageId as j, getAgentInvocationIdForResult as k, getConversationTurnBoundaryError as l, markTurnCompleted as m, getTurnUserMessageId as n, CooperativeTurnYieldError as o, markTurnClosed as p, getTurnUserReplyAttachmentContext as r, TurnInputCommitLostError as s, getTurnUserMessage as t, isCooperativeTurnYieldError as u, getTurnLifecycle as v, readChildMessageSender as w, isAgentInvocationResult as x, childMessageSenderMetadata as y, buildDeterministicTurnId as z };
|