@sentry/junior 0.181.1 → 0.183.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/{agent-hooks-KO56HJ74.js → agent-hooks-SNRBZYAU.js} +11 -11
- package/dist/api/code/overview.d.ts +35 -0
- package/dist/api/code/routes.d.ts +4 -0
- package/dist/api/schema/code.d.ts +75 -0
- package/dist/api/schema.d.ts +2 -0
- package/dist/api/schema.js +9 -1
- package/dist/api.js +347 -149
- package/dist/app-adapter.d.ts +85 -0
- package/dist/app.d.ts +6 -1
- package/dist/app.js +380 -501
- package/dist/{catalog-runtime-CJTFLCK3.js → catalog-runtime-3I3JOIIH.js} +4 -4
- package/dist/chat/agent-invocations/store.d.ts +4 -2
- package/dist/chat/agent-invocations/work.d.ts +1 -3
- package/dist/chat/api-turns/adapter-conversations.d.ts +15 -0
- package/dist/chat/api-turns/stop.d.ts +12 -0
- package/dist/chat/api-turns/work.d.ts +9 -1
- package/dist/chat/app/conversation-work.d.ts +1 -1
- package/dist/chat/app/factory.d.ts +3 -3
- package/dist/chat/app/services.d.ts +3 -3
- package/dist/chat/code/publisher.d.ts +3 -0
- package/dist/chat/code/store.d.ts +9 -0
- package/dist/chat/event-tasks/store.d.ts +10 -0
- package/dist/chat/event-tasks/tool-support.d.ts +7 -1
- package/dist/chat/event-tasks/types.d.ts +1 -0
- package/dist/chat/experimental.d.ts +1 -1
- package/dist/chat/ingress/slack-webhook.d.ts +1 -1
- package/dist/chat/plugins/agent-hooks.d.ts +5 -0
- package/dist/chat/{runtime/slack-runtime.d.ts → providers/slack/runtime.d.ts} +2 -2
- package/dist/chat/{runtime/reply-executor.d.ts → providers/slack/turn.d.ts} +10 -9
- package/dist/chat/resource-events/catalog.d.ts +11 -1
- package/dist/chat/resource-events/store.d.ts +17 -1
- package/dist/chat/runtime/turn-execution.d.ts +30 -0
- package/dist/chat/services/subscribed-decision.d.ts +2 -1
- package/dist/chat/slack/dispatch-turn.d.ts +12 -14
- package/dist/chat/task-execution/slack-work.d.ts +1 -1
- package/dist/chat/tools/create-event-task.d.ts +3 -0
- package/dist/chat/tools/delete-event-task.d.ts +2 -0
- package/dist/chat/tools/list-event-tasks.d.ts +2 -0
- package/dist/chat/tools/list-resource-event-subscriptions.d.ts +2 -0
- package/dist/chat/tools/search-resource-event-types.d.ts +10 -0
- package/dist/chat/tools/update-event-task.d.ts +3 -0
- package/dist/chat/tools/watch-resource-events.d.ts +3 -0
- package/dist/{chunk-DTRCZOHE.js → chunk-24OJZ5OU.js} +6 -6
- package/dist/{chunk-Z2UG4FBT.js → chunk-2ADFGSUS.js} +1 -1
- package/dist/{chunk-RULGB5NX.js → chunk-2EPYYVJC.js} +9 -9
- package/dist/{chunk-VRS6WDK5.js → chunk-2LYHWMR4.js} +1 -1
- package/dist/{chunk-XQ56HNH5.js → chunk-35PM4YY5.js} +6 -6
- package/dist/{chunk-6TB7JN63.js → chunk-37IQ6DGU.js} +3 -3
- package/dist/{chunk-MR36BRPE.js → chunk-3HJ4F4L7.js} +4 -4
- package/dist/{chunk-4WYHL4EH.js → chunk-3L7CWDQQ.js} +1 -1
- package/dist/{chunk-CJRUBOJI.js → chunk-4WGFWHWP.js} +1 -1
- package/dist/{chunk-VHSBLFNT.js → chunk-56XONJPF.js} +1 -1
- package/dist/{chunk-ULM7P4EQ.js → chunk-6UXDTPEN.js} +233 -173
- package/dist/{chunk-WDNA4LML.js → chunk-AHMWPFIW.js} +188 -11
- package/dist/{chunk-YCW6RZGX.js → chunk-AX3UDIMA.js} +3 -3
- package/dist/{chunk-HG6HNOTQ.js → chunk-AYW7J6K4.js} +130 -200
- package/dist/{chunk-DXK3VTVP.js → chunk-E3OBGRHN.js} +1 -1
- package/dist/{chunk-7UF37LNL.js → chunk-EENQGEIP.js} +1 -1
- package/dist/{chunk-HRTW7FFX.js → chunk-FJMTMGBC.js} +1 -1
- package/dist/{chunk-H6MPFFBE.js → chunk-G2B2XZQW.js} +1 -1
- package/dist/{chunk-4GOZBB22.js → chunk-HUK5XIZL.js} +63 -7
- package/dist/{chunk-DINF4LMR.js → chunk-IO6KFXYE.js} +160 -97
- package/dist/{chunk-KH2SL2HT.js → chunk-KTXOGLNE.js} +2 -2
- package/dist/{chunk-S63LNPIV.js → chunk-LMNMMESF.js} +2 -2
- package/dist/{chunk-2CZ63QCL.js → chunk-LZBPGX5A.js} +1 -1
- package/dist/{chunk-PJ7EGFME.js → chunk-PLZT45VC.js} +5 -5
- package/dist/{chunk-ZQQWJMHE.js → chunk-QI5JW5AG.js} +6 -6
- package/dist/{chunk-IWRPJ3J5.js → chunk-QZV76CM4.js} +58 -32
- package/dist/{chunk-YFJDRORU.js → chunk-R767Y7QV.js} +202 -90
- package/dist/{chunk-4OSVTPYQ.js → chunk-SQHFVIMZ.js} +1 -1
- package/dist/{chunk-J4ID4ZI6.js → chunk-T5MTGX2E.js} +19 -19
- package/dist/{chunk-NRF23QZ4.js → chunk-V64JCZUV.js} +3 -3
- package/dist/{chunk-GITIZ6TZ.js → chunk-VOV3SCM3.js} +1 -1
- package/dist/{chunk-S5X2VQOD.js → chunk-W46NIB5H.js} +3 -2
- package/dist/{chunk-XL3C4NAR.js → chunk-W5JMPEBO.js} +9 -9
- package/dist/{chunk-HPFHC7YR.js → chunk-WOKJRLM2.js} +5 -5
- package/dist/chunk-WVIA7V3M.js +975 -0
- package/dist/{chunk-QA6RE6IB.js → chunk-X52ESOBP.js} +3 -3
- package/dist/cli/chat.js +35 -37
- package/dist/cli/check.js +5 -5
- package/dist/cli/plugins.js +12 -12
- package/dist/cli/snapshot-create.js +9 -9
- package/dist/cli/upgrade.js +6 -6
- package/dist/db/schema/code.d.ts +367 -0
- package/dist/db/schema.d.ts +367 -1
- package/dist/{db-4PXTD3OH.js → db-K2VMNLHQ.js} +6 -6
- package/dist/{experimental-SIJSRDJD.js → experimental-P5FZM4CU.js} +1 -1
- package/dist/instrumentation.js +3 -3
- package/dist/nitro.js +6 -6
- package/dist/{oauth-callback-server-TQWNEVR6.js → oauth-callback-server-DZZMTKSS.js} +26 -26
- package/dist/{runner-G5HLQA43.js → runner-IIAKWDXI.js} +18 -18
- package/dist/{skills-BNNNRYNT.js → skills-EXIQ7BP5.js} +5 -5
- package/dist/spawn-ZR6OOEAN.js +37 -0
- package/dist/task-runner-C52HYCVD.js +32 -0
- package/dist/{validation-IJSBB6JR.js → validation-XUGIWBJF.js} +5 -5
- package/dist/version.js +1 -1
- package/dist/{work-5FQI4P2A.js → work-G4RLJ634.js} +18 -18
- package/dist/worker-R2JEHK67.js +22 -0
- package/migrations/0036_complex_rage.sql +32 -0
- package/migrations/meta/0036_snapshot.json +3186 -0
- package/migrations/meta/_journal.json +8 -1
- package/package.json +6 -5
- package/dist/api/acp/route.d.ts +0 -13
- package/dist/chunk-CZYNWPWD.js +0 -930
- package/dist/spawn-U2RKOFP2.js +0 -37
- package/dist/task-runner-CDZJBEXP.js +0 -32
- package/dist/worker-KJ362GVB.js +0 -22
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createWebAuthorization,
|
|
3
3
|
deleteWebAuthorization
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4WGFWHWP.js";
|
|
5
5
|
import {
|
|
6
6
|
buildDeliveredTurnStatePatch,
|
|
7
7
|
completeAuthPauseTurn,
|
|
8
8
|
finalizeFailedTurnReplyWithEvent,
|
|
9
9
|
getTurnUserMessage
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-WOKJRLM2.js";
|
|
11
11
|
import {
|
|
12
12
|
processPluginTask,
|
|
13
13
|
scheduleSessionCompletedPluginTasks
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-W5JMPEBO.js";
|
|
15
15
|
import {
|
|
16
16
|
ConversationTurnLifecycleService
|
|
17
17
|
} from "./chunk-M3QYTBQ6.js";
|
|
@@ -20,16 +20,17 @@ import {
|
|
|
20
20
|
getPersistedSandboxState,
|
|
21
21
|
getPersistedThreadState,
|
|
22
22
|
persistThreadStateById
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-PLZT45VC.js";
|
|
24
24
|
import {
|
|
25
25
|
healthReportSchema
|
|
26
26
|
} from "./chunk-UTL3MHPC.js";
|
|
27
27
|
import {
|
|
28
28
|
parseSlackThreadId
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-SQHFVIMZ.js";
|
|
30
30
|
import {
|
|
31
|
+
appendAndEnqueueExclusiveInboundMessage,
|
|
31
32
|
appendAndEnqueueInboundMessage
|
|
32
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-HUK5XIZL.js";
|
|
33
34
|
import {
|
|
34
35
|
TurnInputCommitLostError,
|
|
35
36
|
buildDeterministicTurnId,
|
|
@@ -40,7 +41,7 @@ import {
|
|
|
40
41
|
markTurnClosed,
|
|
41
42
|
markTurnFailed,
|
|
42
43
|
startActiveTurn
|
|
43
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-56XONJPF.js";
|
|
44
45
|
import {
|
|
45
46
|
abandonTurnRecord,
|
|
46
47
|
buildConversationContext,
|
|
@@ -55,28 +56,27 @@ import {
|
|
|
55
56
|
recordDeliveredAssistantMessage,
|
|
56
57
|
saveTurnCheckpoint,
|
|
57
58
|
upsertConversationMessage
|
|
58
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-24OJZ5OU.js";
|
|
59
60
|
import {
|
|
60
61
|
normalizeSlackConversationId
|
|
61
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-AHMWPFIW.js";
|
|
62
63
|
import {
|
|
63
64
|
getConversationEventStore,
|
|
64
65
|
getConversationStore,
|
|
65
66
|
getDb
|
|
66
|
-
} from "./chunk-
|
|
67
|
+
} from "./chunk-AX3UDIMA.js";
|
|
67
68
|
import {
|
|
68
|
-
juniorApiTokens,
|
|
69
69
|
juniorConversationParticipants,
|
|
70
70
|
juniorConversations,
|
|
71
71
|
juniorIdentities,
|
|
72
72
|
juniorUsers
|
|
73
|
-
} from "./chunk-
|
|
73
|
+
} from "./chunk-6UXDTPEN.js";
|
|
74
74
|
import {
|
|
75
75
|
juniorDestinations
|
|
76
76
|
} from "./chunk-VFUK3X5B.js";
|
|
77
77
|
import {
|
|
78
78
|
canExposeConversationPayload
|
|
79
|
-
} from "./chunk-
|
|
79
|
+
} from "./chunk-2ADFGSUS.js";
|
|
80
80
|
import {
|
|
81
81
|
credentialContextForActor
|
|
82
82
|
} from "./chunk-CEMMLV5L.js";
|
|
@@ -84,7 +84,7 @@ import {
|
|
|
84
84
|
logException,
|
|
85
85
|
setTags,
|
|
86
86
|
withLogContext
|
|
87
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-LZBPGX5A.js";
|
|
88
88
|
|
|
89
89
|
// src/handlers/health.ts
|
|
90
90
|
function readHealthReport() {
|
|
@@ -122,83 +122,75 @@ function createVercelAttachmentStorage() {
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
// src/
|
|
126
|
-
import {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
125
|
+
// src/chat/api-turns/routing.ts
|
|
126
|
+
import { z } from "zod";
|
|
127
|
+
var apiTurnMailboxMetadataSchema = z.object({
|
|
128
|
+
authorEmail: z.string().email(),
|
|
129
|
+
authorFullName: z.string().min(1).optional(),
|
|
130
|
+
authorUserId: z.string().min(1),
|
|
131
|
+
authorUserName: z.string().min(1).optional(),
|
|
132
|
+
kind: z.literal("api_turn"),
|
|
133
|
+
messageId: z.string().min(1)
|
|
134
|
+
}).strict();
|
|
135
|
+
async function getActiveApiTurnId(conversationId) {
|
|
136
|
+
const summaries = await listTurnSummaries(conversationId);
|
|
137
|
+
const active = summaries.filter(
|
|
138
|
+
(summary) => summary.surface === "api" && !summary.dispatchId && (summary.state === "paused" || summary.state === "running")
|
|
139
|
+
);
|
|
140
|
+
if (active.length > 1) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`Conversation ${conversationId} has multiple active web turns`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const turnId = active[0]?.turnId;
|
|
146
|
+
if (!turnId) return void 0;
|
|
147
|
+
const record = await getTurnRecord(conversationId, turnId);
|
|
148
|
+
return record && record.surface === "api" && !record.dispatchId && (record.state === "paused" || record.state === "running") ? turnId : void 0;
|
|
146
149
|
}
|
|
147
|
-
async function
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
ownerEmailNormalized: normalizeEmail(args.email),
|
|
153
|
-
name: args.name.trim(),
|
|
154
|
-
tokenHash: hashToken(token),
|
|
155
|
-
tokenSuffix: token.slice(-TOKEN_SUFFIX_LENGTH),
|
|
156
|
-
createdAt: now,
|
|
157
|
-
expiresAt: new Date(now.getTime() + DEFAULT_TOKEN_LIFETIME_MS)
|
|
158
|
-
};
|
|
159
|
-
await getDb().insert(juniorApiTokens).values(row);
|
|
160
|
-
return { ...metadata({ ...row, lastUsedAt: null, revokedAt: null }), token };
|
|
150
|
+
async function getAuthPausedApiTurnId(conversationId) {
|
|
151
|
+
const turnId = await getActiveApiTurnId(conversationId);
|
|
152
|
+
if (!turnId) return void 0;
|
|
153
|
+
const record = await getTurnRecord(conversationId, turnId);
|
|
154
|
+
return record?.state === "paused" && record.resumeReason === "auth" ? turnId : void 0;
|
|
161
155
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
)
|
|
169
|
-
)
|
|
170
|
-
|
|
156
|
+
function parseApiTurnMessages(messages) {
|
|
157
|
+
if (messages.length === 0) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
const parsed = messages.map((message) => ({
|
|
161
|
+
message,
|
|
162
|
+
metadata: apiTurnMailboxMetadataSchema.safeParse(message.input.metadata)
|
|
163
|
+
}));
|
|
164
|
+
if (parsed.every((entry) => !entry.metadata.success)) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
if (parsed.some((entry) => !entry.metadata.success)) {
|
|
168
|
+
throw new Error("Conversation mailbox mixes web turns and other input");
|
|
169
|
+
}
|
|
170
|
+
return parsed.map((entry) => {
|
|
171
|
+
if (!entry.metadata.success) {
|
|
172
|
+
throw new Error("API turn mailbox metadata failed validation");
|
|
173
|
+
}
|
|
174
|
+
return { message: entry.message, metadata: entry.metadata.data };
|
|
175
|
+
});
|
|
171
176
|
}
|
|
172
|
-
async function
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
async function resolveApiTurnWork(context) {
|
|
178
|
+
const batch = parseApiTurnMessages(context.attempt.messages);
|
|
179
|
+
if (batch.length > 0) {
|
|
180
|
+
return { kind: "mailbox", batch };
|
|
181
|
+
}
|
|
182
|
+
if (context.attempt.messages.length > 0) {
|
|
183
|
+
return void 0;
|
|
184
|
+
}
|
|
185
|
+
const turnId = await getActiveApiTurnId(context.conversationId);
|
|
186
|
+
return turnId ? { kind: "resume", turnId } : void 0;
|
|
181
187
|
}
|
|
182
|
-
async function
|
|
183
|
-
|
|
184
|
-
const rows = await getDb().select({
|
|
185
|
-
id: juniorApiTokens.id,
|
|
186
|
-
ownerEmailNormalized: juniorApiTokens.ownerEmailNormalized
|
|
187
|
-
}).from(juniorApiTokens).where(
|
|
188
|
-
and(
|
|
189
|
-
eq(juniorApiTokens.tokenHash, hashToken(token)),
|
|
190
|
-
isNull(juniorApiTokens.revokedAt),
|
|
191
|
-
gt(juniorApiTokens.expiresAt, now)
|
|
192
|
-
)
|
|
193
|
-
).limit(1);
|
|
194
|
-
const match = rows[0];
|
|
195
|
-
if (!match) return void 0;
|
|
196
|
-
await getDb().update(juniorApiTokens).set({ lastUsedAt: now }).where(eq(juniorApiTokens.id, match.id));
|
|
197
|
-
return match.ownerEmailNormalized;
|
|
188
|
+
async function isApiTurnWork(context) {
|
|
189
|
+
return await resolveApiTurnWork(context) !== void 0;
|
|
198
190
|
}
|
|
199
191
|
|
|
200
192
|
// src/chat/api-turns/work.ts
|
|
201
|
-
import { createHash
|
|
193
|
+
import { createHash } from "crypto";
|
|
202
194
|
import {
|
|
203
195
|
createWebSource,
|
|
204
196
|
localDestinationSchema
|
|
@@ -301,77 +293,16 @@ async function completeCancelledApiTurn(args) {
|
|
|
301
293
|
await args.acknowledge();
|
|
302
294
|
}
|
|
303
295
|
|
|
304
|
-
// src/chat/api-turns/routing.ts
|
|
305
|
-
import { z } from "zod";
|
|
306
|
-
var apiTurnMailboxMetadataSchema = z.object({
|
|
307
|
-
authorEmail: z.string().email(),
|
|
308
|
-
authorFullName: z.string().min(1).optional(),
|
|
309
|
-
authorUserId: z.string().min(1),
|
|
310
|
-
authorUserName: z.string().min(1).optional(),
|
|
311
|
-
kind: z.literal("api_turn"),
|
|
312
|
-
messageId: z.string().min(1)
|
|
313
|
-
}).strict();
|
|
314
|
-
async function getActiveApiTurnId(conversationId) {
|
|
315
|
-
const summaries = await listTurnSummaries(conversationId);
|
|
316
|
-
const active = summaries.filter(
|
|
317
|
-
(summary) => summary.surface === "api" && !summary.dispatchId && (summary.state === "paused" || summary.state === "running")
|
|
318
|
-
);
|
|
319
|
-
if (active.length > 1) {
|
|
320
|
-
throw new Error(
|
|
321
|
-
`Conversation ${conversationId} has multiple active web turns`
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
const turnId = active[0]?.turnId;
|
|
325
|
-
if (!turnId) return void 0;
|
|
326
|
-
const record = await getTurnRecord(conversationId, turnId);
|
|
327
|
-
return record && record.surface === "api" && !record.dispatchId && (record.state === "paused" || record.state === "running") ? turnId : void 0;
|
|
328
|
-
}
|
|
329
|
-
function parseApiTurnMessages(messages) {
|
|
330
|
-
if (messages.length === 0) {
|
|
331
|
-
return [];
|
|
332
|
-
}
|
|
333
|
-
const parsed = messages.map((message) => ({
|
|
334
|
-
message,
|
|
335
|
-
metadata: apiTurnMailboxMetadataSchema.safeParse(message.input.metadata)
|
|
336
|
-
}));
|
|
337
|
-
if (parsed.every((entry) => !entry.metadata.success)) {
|
|
338
|
-
return [];
|
|
339
|
-
}
|
|
340
|
-
if (parsed.some((entry) => !entry.metadata.success)) {
|
|
341
|
-
throw new Error("Conversation mailbox mixes web turns and other input");
|
|
342
|
-
}
|
|
343
|
-
return parsed.map((entry) => {
|
|
344
|
-
if (!entry.metadata.success) {
|
|
345
|
-
throw new Error("API turn mailbox metadata failed validation");
|
|
346
|
-
}
|
|
347
|
-
return { message: entry.message, metadata: entry.metadata.data };
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
async function resolveApiTurnWork(context) {
|
|
351
|
-
const batch = parseApiTurnMessages(context.attempt.messages);
|
|
352
|
-
if (batch.length > 0) {
|
|
353
|
-
return { kind: "mailbox", batch };
|
|
354
|
-
}
|
|
355
|
-
if (context.attempt.messages.length > 0) {
|
|
356
|
-
return void 0;
|
|
357
|
-
}
|
|
358
|
-
const turnId = await getActiveApiTurnId(context.conversationId);
|
|
359
|
-
return turnId ? { kind: "resume", turnId } : void 0;
|
|
360
|
-
}
|
|
361
|
-
async function isApiTurnWork(context) {
|
|
362
|
-
return await resolveApiTurnWork(context) !== void 0;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
296
|
// src/chat/api-turns/work.ts
|
|
366
|
-
function
|
|
297
|
+
function normalizeEmail(email) {
|
|
367
298
|
return email.trim().toLowerCase();
|
|
368
299
|
}
|
|
369
300
|
function stableHex(...parts) {
|
|
370
|
-
return
|
|
301
|
+
return createHash("sha256").update(parts.join("\0")).digest("hex").slice(0, 24);
|
|
371
302
|
}
|
|
372
303
|
function createApiConversationId(args) {
|
|
373
304
|
return `local:web:${stableHex(
|
|
374
|
-
|
|
305
|
+
normalizeEmail(args.actorEmail),
|
|
375
306
|
args.idempotencyKey
|
|
376
307
|
)}`;
|
|
377
308
|
}
|
|
@@ -403,23 +334,23 @@ function webSourceForConversation(args) {
|
|
|
403
334
|
args.visibility === "private" ? "private" : "public"
|
|
404
335
|
);
|
|
405
336
|
}
|
|
406
|
-
function actorFromMetadata(
|
|
337
|
+
function actorFromMetadata(metadata) {
|
|
407
338
|
return {
|
|
408
339
|
platform: "web",
|
|
409
|
-
userId:
|
|
410
|
-
email:
|
|
411
|
-
...
|
|
412
|
-
...
|
|
340
|
+
userId: metadata.authorUserId,
|
|
341
|
+
email: normalizeEmail(metadata.authorEmail),
|
|
342
|
+
...metadata.authorFullName ? { fullName: metadata.authorFullName } : void 0,
|
|
343
|
+
...metadata.authorUserName ? { userName: metadata.authorUserName } : void 0
|
|
413
344
|
};
|
|
414
345
|
}
|
|
415
346
|
function storedActorFromApi(actor) {
|
|
416
347
|
return {
|
|
417
|
-
...actor.email ? { email:
|
|
348
|
+
...actor.email ? { email: normalizeEmail(actor.email) } : void 0,
|
|
418
349
|
...actor.fullName ? { fullName: actor.fullName } : void 0
|
|
419
350
|
};
|
|
420
351
|
}
|
|
421
352
|
function webActorFromEmail(email, profile) {
|
|
422
|
-
const normalized =
|
|
353
|
+
const normalized = normalizeEmail(email);
|
|
423
354
|
return {
|
|
424
355
|
platform: "web",
|
|
425
356
|
userId: `dashboard:${stableHex(normalized)}`,
|
|
@@ -461,10 +392,10 @@ function buildApiTurnInboundMessage(args) {
|
|
|
461
392
|
authorId: args.actor.userId,
|
|
462
393
|
text,
|
|
463
394
|
metadata: {
|
|
464
|
-
authorEmail:
|
|
465
|
-
...args.actor.fullName
|
|
395
|
+
authorEmail: normalizeEmail(args.actor.email),
|
|
396
|
+
...args.actor.fullName && { authorFullName: args.actor.fullName },
|
|
466
397
|
authorUserId: args.actor.userId,
|
|
467
|
-
...args.actor.userName
|
|
398
|
+
...args.actor.userName && { authorUserName: args.actor.userName },
|
|
468
399
|
kind: "api_turn",
|
|
469
400
|
messageId: args.messageId
|
|
470
401
|
}
|
|
@@ -537,9 +468,10 @@ async function appendAndEnqueueApiConversationMessage(input, options) {
|
|
|
537
468
|
conversationId: input.conversationId,
|
|
538
469
|
conversationStore: options.conversationStore,
|
|
539
470
|
nowMs,
|
|
540
|
-
...input.rootVisibility
|
|
471
|
+
...input.rootVisibility && { rootVisibility: input.rootVisibility }
|
|
541
472
|
});
|
|
542
|
-
const
|
|
473
|
+
const enqueue = options.exclusive ? appendAndEnqueueExclusiveInboundMessage : appendAndEnqueueInboundMessage;
|
|
474
|
+
const result = await enqueue({
|
|
543
475
|
message: buildApiTurnInboundMessage({
|
|
544
476
|
actor: input.actor,
|
|
545
477
|
conversationId: input.conversationId,
|
|
@@ -553,10 +485,11 @@ async function appendAndEnqueueApiConversationMessage(input, options) {
|
|
|
553
485
|
queue: options.queue,
|
|
554
486
|
state: options.state
|
|
555
487
|
});
|
|
488
|
+
const status = result.status === "appended" ? "accepted" : result.status;
|
|
556
489
|
return {
|
|
557
490
|
conversationId: input.conversationId,
|
|
558
491
|
messageId,
|
|
559
|
-
status
|
|
492
|
+
status
|
|
560
493
|
};
|
|
561
494
|
}
|
|
562
495
|
function captureApiBoundaryFailure(args) {
|
|
@@ -1033,13 +966,13 @@ function routeApiTurnWork(options) {
|
|
|
1033
966
|
}
|
|
1034
967
|
|
|
1035
968
|
// src/api/conversations/access.ts
|
|
1036
|
-
import { eq as
|
|
969
|
+
import { eq as eq2, inArray as inArray2 } from "drizzle-orm";
|
|
1037
970
|
import { alias } from "drizzle-orm/pg-core";
|
|
1038
971
|
|
|
1039
972
|
// src/api/conversations/membership.ts
|
|
1040
973
|
import {
|
|
1041
|
-
and
|
|
1042
|
-
eq
|
|
974
|
+
and,
|
|
975
|
+
eq,
|
|
1043
976
|
exists,
|
|
1044
977
|
inArray,
|
|
1045
978
|
isNotNull,
|
|
@@ -1050,12 +983,12 @@ function conversationHasParticipantUser(userId) {
|
|
|
1050
983
|
const participant = getDb().select({
|
|
1051
984
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1052
985
|
}).from(juniorConversationParticipants).where(
|
|
1053
|
-
|
|
1054
|
-
|
|
986
|
+
and(
|
|
987
|
+
eq(
|
|
1055
988
|
juniorConversationParticipants.rootConversationId,
|
|
1056
989
|
juniorConversations.conversationId
|
|
1057
990
|
),
|
|
1058
|
-
|
|
991
|
+
eq(juniorConversationParticipants.userId, userId)
|
|
1059
992
|
)
|
|
1060
993
|
);
|
|
1061
994
|
return exists(participant);
|
|
@@ -1065,14 +998,14 @@ function conversationHasParticipantEmail(email) {
|
|
|
1065
998
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1066
999
|
}).from(juniorConversationParticipants).innerJoin(
|
|
1067
1000
|
juniorUsers,
|
|
1068
|
-
|
|
1001
|
+
eq(juniorUsers.id, juniorConversationParticipants.userId)
|
|
1069
1002
|
).where(
|
|
1070
|
-
|
|
1071
|
-
|
|
1003
|
+
and(
|
|
1004
|
+
eq(
|
|
1072
1005
|
juniorConversationParticipants.rootConversationId,
|
|
1073
1006
|
juniorConversations.conversationId
|
|
1074
1007
|
),
|
|
1075
|
-
|
|
1008
|
+
eq(juniorUsers.primaryEmailNormalized, email)
|
|
1076
1009
|
)
|
|
1077
1010
|
);
|
|
1078
1011
|
return exists(participant);
|
|
@@ -1081,12 +1014,12 @@ function conversationArchivedForUser(userId) {
|
|
|
1081
1014
|
const archive = getDb().select({
|
|
1082
1015
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1083
1016
|
}).from(juniorConversationParticipants).where(
|
|
1084
|
-
|
|
1085
|
-
|
|
1017
|
+
and(
|
|
1018
|
+
eq(
|
|
1086
1019
|
juniorConversationParticipants.rootConversationId,
|
|
1087
1020
|
juniorConversations.conversationId
|
|
1088
1021
|
),
|
|
1089
|
-
|
|
1022
|
+
eq(juniorConversationParticipants.userId, userId),
|
|
1090
1023
|
isNotNull(juniorConversationParticipants.archivedAt)
|
|
1091
1024
|
)
|
|
1092
1025
|
);
|
|
@@ -1096,12 +1029,12 @@ function conversationNotArchivedForUser(userId) {
|
|
|
1096
1029
|
const archive = getDb().select({
|
|
1097
1030
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1098
1031
|
}).from(juniorConversationParticipants).where(
|
|
1099
|
-
|
|
1100
|
-
|
|
1032
|
+
and(
|
|
1033
|
+
eq(
|
|
1101
1034
|
juniorConversationParticipants.rootConversationId,
|
|
1102
1035
|
juniorConversations.conversationId
|
|
1103
1036
|
),
|
|
1104
|
-
|
|
1037
|
+
eq(juniorConversationParticipants.userId, userId),
|
|
1105
1038
|
isNotNull(juniorConversationParticipants.archivedAt)
|
|
1106
1039
|
)
|
|
1107
1040
|
);
|
|
@@ -1112,14 +1045,14 @@ function conversationArchivedForEmail(email) {
|
|
|
1112
1045
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1113
1046
|
}).from(juniorConversationParticipants).innerJoin(
|
|
1114
1047
|
juniorUsers,
|
|
1115
|
-
|
|
1048
|
+
eq(juniorUsers.id, juniorConversationParticipants.userId)
|
|
1116
1049
|
).where(
|
|
1117
|
-
|
|
1118
|
-
|
|
1050
|
+
and(
|
|
1051
|
+
eq(
|
|
1119
1052
|
juniorConversationParticipants.rootConversationId,
|
|
1120
1053
|
juniorConversations.conversationId
|
|
1121
1054
|
),
|
|
1122
|
-
|
|
1055
|
+
eq(juniorUsers.primaryEmailNormalized, email),
|
|
1123
1056
|
isNotNull(juniorConversationParticipants.archivedAt)
|
|
1124
1057
|
)
|
|
1125
1058
|
);
|
|
@@ -1130,14 +1063,14 @@ function conversationNotArchivedForEmail(email) {
|
|
|
1130
1063
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1131
1064
|
}).from(juniorConversationParticipants).innerJoin(
|
|
1132
1065
|
juniorUsers,
|
|
1133
|
-
|
|
1066
|
+
eq(juniorUsers.id, juniorConversationParticipants.userId)
|
|
1134
1067
|
).where(
|
|
1135
|
-
|
|
1136
|
-
|
|
1068
|
+
and(
|
|
1069
|
+
eq(
|
|
1137
1070
|
juniorConversationParticipants.rootConversationId,
|
|
1138
1071
|
juniorConversations.conversationId
|
|
1139
1072
|
),
|
|
1140
|
-
|
|
1073
|
+
eq(juniorUsers.primaryEmailNormalized, email),
|
|
1141
1074
|
isNotNull(juniorConversationParticipants.archivedAt)
|
|
1142
1075
|
)
|
|
1143
1076
|
);
|
|
@@ -1156,8 +1089,8 @@ async function conversationArchiveTimes(db, conversationIds, subject) {
|
|
|
1156
1089
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1157
1090
|
}).from(juniorConversationParticipants);
|
|
1158
1091
|
const rows = "userId" in subject ? await query.where(
|
|
1159
|
-
|
|
1160
|
-
|
|
1092
|
+
and(
|
|
1093
|
+
eq(juniorConversationParticipants.userId, subject.userId),
|
|
1161
1094
|
inArray(juniorConversationParticipants.rootConversationId, [
|
|
1162
1095
|
...conversationIds
|
|
1163
1096
|
]),
|
|
@@ -1165,10 +1098,10 @@ async function conversationArchiveTimes(db, conversationIds, subject) {
|
|
|
1165
1098
|
)
|
|
1166
1099
|
) : await query.innerJoin(
|
|
1167
1100
|
juniorUsers,
|
|
1168
|
-
|
|
1101
|
+
eq(juniorUsers.id, juniorConversationParticipants.userId)
|
|
1169
1102
|
).where(
|
|
1170
|
-
|
|
1171
|
-
|
|
1103
|
+
and(
|
|
1104
|
+
eq(juniorUsers.primaryEmailNormalized, subject.email),
|
|
1172
1105
|
inArray(juniorConversationParticipants.rootConversationId, [
|
|
1173
1106
|
...conversationIds
|
|
1174
1107
|
]),
|
|
@@ -1188,8 +1121,8 @@ async function conversationIdsWithParticipantUser(db, conversationIds, userId) {
|
|
|
1188
1121
|
const rows = await db.select({
|
|
1189
1122
|
rootConversationId: juniorConversationParticipants.rootConversationId
|
|
1190
1123
|
}).from(juniorConversationParticipants).where(
|
|
1191
|
-
|
|
1192
|
-
|
|
1124
|
+
and(
|
|
1125
|
+
eq(juniorConversationParticipants.userId, userId),
|
|
1193
1126
|
inArray(juniorConversationParticipants.rootConversationId, [
|
|
1194
1127
|
...conversationIds
|
|
1195
1128
|
])
|
|
@@ -1218,16 +1151,16 @@ async function readConversationAccessFromSql(db, conversationIds, viewer) {
|
|
|
1218
1151
|
rootUserId: rootIdentity.userId
|
|
1219
1152
|
}).from(juniorConversations).leftJoin(
|
|
1220
1153
|
rootConversation,
|
|
1221
|
-
|
|
1154
|
+
eq2(
|
|
1222
1155
|
rootConversation.conversationId,
|
|
1223
1156
|
juniorConversations.rootConversationId
|
|
1224
1157
|
)
|
|
1225
1158
|
).leftJoin(
|
|
1226
1159
|
rootDestination,
|
|
1227
|
-
|
|
1160
|
+
eq2(rootDestination.id, rootConversation.destinationId)
|
|
1228
1161
|
).leftJoin(
|
|
1229
1162
|
rootIdentity,
|
|
1230
|
-
|
|
1163
|
+
eq2(rootIdentity.id, rootConversation.actorIdentityId)
|
|
1231
1164
|
).where(inArray2(juniorConversations.conversationId, [...conversationIds]));
|
|
1232
1165
|
const membershipConversationIds = /* @__PURE__ */ new Set();
|
|
1233
1166
|
for (const row of rows) {
|
|
@@ -1358,6 +1291,7 @@ export {
|
|
|
1358
1291
|
resolveSlackConversationContextFromThreadId,
|
|
1359
1292
|
formatSlackConversationRedactedLabel,
|
|
1360
1293
|
createApiTurnCancellation,
|
|
1294
|
+
getAuthPausedApiTurnId,
|
|
1361
1295
|
apiTurnIdForMessage,
|
|
1362
1296
|
webActorFromEmail,
|
|
1363
1297
|
recordApiConversationActivity,
|
|
@@ -1373,9 +1307,5 @@ export {
|
|
|
1373
1307
|
conversationNotArchivedForEmail,
|
|
1374
1308
|
viewerConversationMembership,
|
|
1375
1309
|
conversationArchiveTimes,
|
|
1376
|
-
readConversationAccessFromSql
|
|
1377
|
-
createPersonalToken,
|
|
1378
|
-
listPersonalTokens,
|
|
1379
|
-
revokePersonalToken,
|
|
1380
|
-
authenticatePersonalToken
|
|
1310
|
+
readConversationAccessFromSql
|
|
1381
1311
|
};
|