@sentry/junior 0.305.0 → 0.306.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-BpvbUki8.js → adapter-context-CnY-i32r.js} +2 -2
- package/dist/{admin-CoDt35ny.js → admin-BLLdLnXh.js} +2 -2
- package/dist/{agent-runner-C5d6rY5g.js → agent-runner-BaLjEjPR.js} +261 -190
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -8
- package/dist/api.d.ts +19 -4
- package/dist/api.js +137 -40
- package/dist/{app-Cs157Zc5.d.ts → app-DvYbM9UD.d.ts} +2 -2
- package/dist/app.d.ts +1 -1
- package/dist/app.js +487 -434
- package/dist/{background-compaction-queue-BTqMIfTA.js → background-compaction-queue-D2wzxtGU.js} +2 -2
- package/dist/{briefs-BRdznF7c.js → briefs-DvyzXfrF.js} +3 -3
- package/dist/{catalog-runtime-J52Tej47.js → catalog-runtime-B1R-nHd3.js} +1 -1
- package/dist/cli/chat.js +15 -15
- package/dist/cli/check.js +3 -3
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.js +4 -4
- 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-CBZp0udd.js → config-DUD-zMvp.js} +111 -13
- package/dist/{connections-BYmuJ6Vm.js → connections-CDhsqPcC.js} +6 -6
- package/dist/{continue-in-slack-Cvot6S38.js → continue-in-slack-BXQizz9o.js} +5 -5
- package/dist/{conversation-BOqdRtUx.js → conversation--f85g4zL.js} +132 -132
- package/dist/{conversation-feed-CgpgP7yi.js → conversation-feed-BNs9KiqC.js} +1 -1
- package/dist/{conversation-privacy-D2pOzBNl.js → conversation-privacy-YE54gMN8.js} +1 -1
- package/dist/{conversation-turn-CI8WDpnK.js → conversation-turn-BzdmrHb0.js} +22 -40
- package/dist/{credential-sync-COqnZ1Dx.js → credential-sync-Cdm-e1vJ.js} +14 -13
- package/dist/{db-DU84dCVu.js → db-DV2ZUb1Y.js} +90 -11
- package/dist/{db-zbN5ZV_o.d.ts → db-pH357Dkt.d.ts} +1 -1
- package/dist/{executor-CFyrgOu1.js → executor-CjNhwwnj.js} +47 -4
- package/dist/{history-m2-ceTTX.js → history-N7IVbUom.js} +5 -1
- package/dist/{install-CQ76CfRw.js → install-DbD7C5td.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{lineage-DLd2UxVP.js → lineage-BFdIPb3o.js} +2 -2
- package/dist/{logging-BPNTQVFu.js → logging-oYpJYr-S.js} +1 -1
- package/dist/{message-BWJLeQ5e.js → message-BBPcMKJY.js} +8 -8
- package/dist/{model-input-DoM9Ht-d.js → model-input-DYYF3a8B.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -4
- package/dist/{oauth-callback-server-DeHbnAQl.js → oauth-callback-server-C7Q987su.js} +2 -2
- package/dist/{projection-CcFBVFUo.js → projection-CWXDE0f6.js} +7738 -6166
- package/dist/{prompt-C5LREK2p.js → prompt-P3eRqO8C.js} +15 -7
- package/dist/{queue-B2AAL3ym.js → queue-7FSijgqG.js} +4 -4
- package/dist/{registry-BjZZqKqi.js → registry-1pzXmplY.js} +1 -1
- package/dist/{resolve-CeJgXuH1.js → resolve-n87oXY-d.js} +3 -3
- package/dist/{result-icDrueyB.js → result-BmF9v9bv.js} +9 -9
- package/dist/{runner-nVfMkMMB.js → runner-4j7ZsxP5.js} +13 -15
- package/dist/{sandbox-egress-signals-H9vQ5qRf.js → sandbox-egress-signals-BRQI8HvT.js} +1 -1
- package/dist/{automation-CuA3yEcD.js → schedule-CHPWQn-x.js} +347 -5
- package/dist/{schema-CKcu-IK6.d.ts → schema-CVbIjrF3.d.ts} +71 -1
- package/dist/{schema-Bx0Mlo32.js → schema-D7iIEh6t.js} +52 -6
- package/dist/{service-account-Dw06p3zm.js → service-account-BDQ9xzta.js} +3 -3
- package/dist/{service-account-DU5865XA.js → service-account-DzQiOmqa.js} +5 -5
- package/dist/{session-stop-uotLtp4g.js → session-stop-BQxgHR4X.js} +854 -160
- package/dist/{skills-Bex1EaO5.js → skills-CPf4vNuC.js} +2 -2
- package/dist/{slack-conversation-unfurl-EPG3riWF.js → slack-conversation-unfurl-B1KEptUg.js} +10 -9
- package/dist/{spawn-CoD3vDuS.js → spawn-CjGddiAU.js} +6 -6
- package/dist/{state-nCR4Muhn.js → state-9wfj6aSD.js} +4 -4
- package/dist/{stop-BFVd0P0m.js → stop-CsQGuN5n.js} +62 -117
- package/dist/{store-Ca6G962n.js → store-Dz3YZ7gQ.js} +5 -5
- package/dist/{task-queue-BLPZU6kC.js → task-queue-CFlrJguF.js} +3 -3
- package/dist/{task-runner-xsOPIxCZ.js → task-runner-frzlUvFD.js} +8 -9
- package/dist/{thread-context-BOvZhsKK.js → thread-context-C4QuZlM8.js} +8 -91
- package/dist/turn-session-routing-BXaubz2w.js +244 -0
- package/dist/{turn-user-message-BrhuyYrH.js → turn-user-message-DNC0eRZ7.js} +3 -3
- package/dist/users-XCCKn3xW.js +181 -0
- package/dist/{validation-BnY9K5WB.js → validation-L5fdjmFX.js} +1 -1
- package/dist/{version-qROlRQGF.js → version-BFmuwgxP.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-CxUiOraX.js → viewer-DKOeHpv3.js} +3 -3
- package/dist/{warmup--Gkz7iB-.js → warmup-mTMIatCV.js} +267 -272
- package/dist/{web-message-id-lNodcCOI.js → web-message-id-CUaSiGme.js} +16 -1
- package/dist/{worker-DJ8d9fmD.js → worker-Bz4KNxjI.js} +7 -7
- package/migrations/0114_plan_items.sql +22 -0
- package/migrations/meta/0114_snapshot.json +5203 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +6 -6
- package/dist/schedule-cP0AACm1.js +0 -344
- package/dist/turn-session-routing-2bW2qfeb.js +0 -1792
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { _ as getConversationWorkState } from "./store-Ca6G962n.js";
|
|
1
|
+
import { J as clearPendingAuth, bo as listConversationAnnotations, k as markConversationMessage, v as hydrateConversationMessages, w as buildConversationContext } from "./projection-CWXDE0f6.js";
|
|
2
|
+
import { K as isRecord, b as setSpanAttributes } from "./logging-oYpJYr-S.js";
|
|
3
|
+
import { o as getDb, r as getConversationEventStore } from "./db-DV2ZUb1Y.js";
|
|
4
|
+
import { J as readMessageCardRefs, X as resolveMessageCards, Y as removedCardSchema } from "./conversation--f85g4zL.js";
|
|
5
|
+
import { S as listChildMessages, m as markTurnCompleted, n as getTurnUserMessageId, p as markTurnClosed, x as isAgentInvocationResult } from "./turn-user-message-DNC0eRZ7.js";
|
|
6
|
+
import { _ as getConversationWorkState } from "./store-Dz3YZ7gQ.js";
|
|
7
|
+
import { a as getPersistedThreadState, c as coerceThreadConversationState, s as persistThreadStateById } from "./turn-session-routing-BXaubz2w.js";
|
|
9
8
|
// src/chat/conversations/pending-cards.ts
|
|
10
9
|
/**
|
|
11
10
|
* Add the cards that tool results selected since the last visible assistant
|
|
@@ -111,88 +110,6 @@ async function persistAuthPauseTurnState(args) {
|
|
|
111
110
|
});
|
|
112
111
|
await persistThreadStateById(args.threadStateId, { conversation });
|
|
113
112
|
}
|
|
114
|
-
// src/chat/interruption-marker.ts
|
|
115
|
-
const INTERRUPTED_MARKER = "\n\n[Response interrupted before completion]";
|
|
116
|
-
/** Return the marker added when a visible reply ended mid-execution. */
|
|
117
|
-
function getInterruptionMarker() {
|
|
118
|
-
return INTERRUPTED_MARKER;
|
|
119
|
-
}
|
|
120
|
-
// src/chat/services/turn-failure-response.ts
|
|
121
|
-
/** Require captured turn failures to carry a real Sentry event reference. */
|
|
122
|
-
function requireTurnFailureEventId(eventId, eventName) {
|
|
123
|
-
if (!eventId) throw new Error(`Sentry did not return an event ID for ${eventName}`);
|
|
124
|
-
return eventId;
|
|
125
|
-
}
|
|
126
|
-
function getExecutionFailureReason(reply) {
|
|
127
|
-
const errorMessage = reply.diagnostics.errorMessage?.trim();
|
|
128
|
-
if (errorMessage) return errorMessage;
|
|
129
|
-
if (reply.diagnostics.toolErrorCount > 0) return `${reply.diagnostics.toolErrorCount} tool result error(s)`;
|
|
130
|
-
if (reply.diagnostics.assistantMessageCount > 0) return "assistant returned no text";
|
|
131
|
-
return "empty assistant turn";
|
|
132
|
-
}
|
|
133
|
-
/** Return a fixed reason label for a failed model turn. */
|
|
134
|
-
function getTurnFailureReason(reply) {
|
|
135
|
-
if (reply.diagnostics.outcome === "success") return;
|
|
136
|
-
if (reply.diagnostics.outcome === "provider_error") return findProviderError(reply.diagnostics.providerError)?.kind ?? "unknown";
|
|
137
|
-
if (reply.diagnostics.toolErrorCount > 0) return "tool_errors";
|
|
138
|
-
if (reply.diagnostics.usedPrimaryText && reply.diagnostics.assistantMessageCount > 0) return "suppressed_output";
|
|
139
|
-
return "empty_output";
|
|
140
|
-
}
|
|
141
|
-
function getFailureCapture(reply) {
|
|
142
|
-
if (reply.diagnostics.outcome === "provider_error") {
|
|
143
|
-
const providerError = findProviderError(reply.diagnostics.providerError);
|
|
144
|
-
return {
|
|
145
|
-
eventName: "agent.turn.provider_error",
|
|
146
|
-
error: reply.diagnostics.providerError ?? new Error(reply.diagnostics.errorMessage ?? "Provider error without explicit message"),
|
|
147
|
-
attributes: providerError ? getProviderErrorAttributes(providerError) : {},
|
|
148
|
-
body: "Agent turn failed with provider error"
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
const failureReason = getExecutionFailureReason(reply);
|
|
152
|
-
return {
|
|
153
|
-
eventName: "agent.turn.execution.failed",
|
|
154
|
-
error: /* @__PURE__ */ new Error(`Agent turn execution failure: ${failureReason}`),
|
|
155
|
-
attributes: { "app.ai.execution_failure_reason": failureReason },
|
|
156
|
-
body: "Agent turn completed with execution failure"
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
/** Keep failed-turn Sentry captures and completion spans on the same keys. */
|
|
160
|
-
function getAgentTurnDiagnosticsAttributes(reply) {
|
|
161
|
-
return {
|
|
162
|
-
"app.ai.outcome": reply.diagnostics.outcome,
|
|
163
|
-
"app.ai.assistant_messages": reply.diagnostics.assistantMessageCount,
|
|
164
|
-
"app.ai.tool_results": reply.diagnostics.toolResultCount,
|
|
165
|
-
"app.ai.tool_error_results": reply.diagnostics.toolErrorCount,
|
|
166
|
-
"app.ai.tool_call_count": reply.diagnostics.toolCalls.length,
|
|
167
|
-
"app.ai.used_primary_text": reply.diagnostics.usedPrimaryText,
|
|
168
|
-
...reply.diagnostics.reasoningLevel ? { "gen_ai.request.reasoning.level": reply.diagnostics.reasoningLevel } : void 0,
|
|
169
|
-
...reply.diagnostics.stopReason ? { "gen_ai.response.finish_reasons": [reply.diagnostics.stopReason] } : void 0,
|
|
170
|
-
...reply.diagnostics.errorMessage && reply.diagnostics.outcome !== "provider_error" ? { "exception.message": reply.diagnostics.errorMessage } : void 0
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
/** Enforce one captured failure response and return its structured correlation. */
|
|
174
|
-
function finalizeFailedTurnReplyWithEvent(args) {
|
|
175
|
-
if (args.reply.diagnostics.outcome === "success") return { reply: args.reply };
|
|
176
|
-
const failureReason = getTurnFailureReason(args.reply);
|
|
177
|
-
const capture = getFailureCapture(args.reply);
|
|
178
|
-
const eventId = requireTurnFailureEventId(args.logException(capture.error, capture.eventName, {
|
|
179
|
-
...getAgentTurnDiagnosticsAttributes(args.reply),
|
|
180
|
-
...args.attributes,
|
|
181
|
-
...capture.attributes,
|
|
182
|
-
...failureReason ? { "app.ai.failure_reason": failureReason } : void 0
|
|
183
|
-
}), capture.eventName);
|
|
184
|
-
const providerPartialText = args.reply.diagnostics.outcome === "provider_error" && args.reply.diagnostics.assistantMessageCount > 0 ? args.reply.text.trim() : "";
|
|
185
|
-
const providerUserMessage = args.reply.diagnostics.providerError instanceof ProviderError ? getProviderErrorUserMessage(args.reply.diagnostics.providerError) : "";
|
|
186
|
-
const failureText = providerUserMessage ? `${providerUserMessage} Reference: \`event_id=${eventId}\`.` : buildTurnFailureResponse(eventId);
|
|
187
|
-
return {
|
|
188
|
-
eventId,
|
|
189
|
-
...failureReason ? { failureReason } : void 0,
|
|
190
|
-
reply: {
|
|
191
|
-
...args.reply,
|
|
192
|
-
text: providerPartialText ? `${providerPartialText}${getInterruptionMarker()}` : failureText
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
113
|
// src/chat/conversations/thread-context.ts
|
|
197
114
|
const CURSOR_TURN_LOOKBACK = 10;
|
|
198
115
|
async function loadThreadContextCursor(args) {
|
|
@@ -245,4 +162,4 @@ async function buildTurnThreadContext(args) {
|
|
|
245
162
|
});
|
|
246
163
|
return block.text;
|
|
247
164
|
}
|
|
248
|
-
export {
|
|
165
|
+
export { buildDeliveredTurnStatePatch as a, persistAuthPauseTurnState as i, loadThreadContextTrimFloor as n, loadPendingMessageCards as o, completeAuthPauseTurn as r, buildTurnThreadContext as t };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { Zc as createDurableLocationConfigurationService, b as persistConversationMessages, qc as JUNIOR_THREAD_STATE_TTL_MS } from "./projection-CWXDE0f6.js";
|
|
2
|
+
import { J as toOptionalString, K as isRecord, q as toOptionalNumber } from "./logging-oYpJYr-S.js";
|
|
3
|
+
import { $ as getStateAdapter, o as getDb } from "./db-DV2ZUb1Y.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-DV2ZUb1Y.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
|
+
export { getPersistedThreadState as a, coerceThreadConversationState as c, getPersistedSandboxState as i, resolveTurnSessionRouting as n, persistThreadRuntimeState as o, getLocationConfigurationService as r, persistThreadStateById as s, resolveConversationRouting as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { qt as readInboundMessageSender } from "./projection-CWXDE0f6.js";
|
|
2
2
|
import { v as parseSlackMessageTs } from "./actor-D2iXzvlN.js";
|
|
3
|
-
import { r as getConversationEventStore, s as getSqlExecutor } from "./db-
|
|
4
|
-
import {
|
|
3
|
+
import { r as getConversationEventStore, s as getSqlExecutor } from "./db-DV2ZUb1Y.js";
|
|
4
|
+
import { v as juniorAgentInvocations } from "./executor-CjNhwwnj.js";
|
|
5
5
|
import { createHash } from "node:crypto";
|
|
6
6
|
import { inArray } from "drizzle-orm";
|
|
7
7
|
// src/chat/state/turn-id.ts
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { as as SlackActionError, gs as withSlackRetries, ls as getSlackClient } from "./projection-CWXDE0f6.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 { n as pluginCatalogRuntime } from "./catalog-runtime-
|
|
2
|
+
import { n as pluginCatalogRuntime } from "./catalog-runtime-B1R-nHd3.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.
|
|
2
|
+
var version = "0.306.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-
|
|
1
|
+
export { t as JUNIOR_VERSION } from "./version-BFmuwgxP.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { F as findActorIdentityId,
|
|
2
|
-
import {
|
|
3
|
-
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER } from "./logging-
|
|
1
|
+
import { F as findActorIdentityId, J as clearCachedUser, Y as readCachedUserByEmail, o as getDb } from "./db-DV2ZUb1Y.js";
|
|
2
|
+
import { I as juniorIdentities, L as juniorUsers } from "./executor-CjNhwwnj.js";
|
|
3
|
+
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER } from "./logging-oYpJYr-S.js";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { and, asc, eq, inArray, isNotNull } from "drizzle-orm";
|
|
6
6
|
import { identitySchema, userSchema } from "@sentry/junior-plugin-api";
|