@sentry/junior 0.305.0 → 0.307.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-B69WPn6b.js} +2 -2
- package/dist/{admin-CoDt35ny.js → admin-nCJXMgkp.js} +2 -2
- package/dist/{agent-runner-C5d6rY5g.js → agent-runner-DdFcxAxG.js} +463 -303
- 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 +437 -310
- package/dist/{app-Cs157Zc5.d.ts → app-EZur8cVC.d.ts} +12 -3
- package/dist/app.d.ts +2 -2
- package/dist/app.js +532 -439
- package/dist/background-compaction-queue-BhEe4UfU.js +231 -0
- package/dist/{briefs-BRdznF7c.js → briefs-Dl9lxi7J.js} +3 -3
- package/dist/{catalog-runtime-J52Tej47.js → catalog-runtime-OXrv2Ewn.js} +1 -1
- package/dist/cli/chat.d.ts +1 -1
- package/dist/cli/chat.js +17 -16
- package/dist/cli/check.js +58 -48
- package/dist/cli/main.js +3 -3
- package/dist/cli/plugins.d.ts +1 -1
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +2 -2
- package/dist/cli/upgrade.js +3 -8
- package/dist/{config-CBZp0udd.js → config-362yMSIz.js} +183 -49
- package/dist/{connections-BYmuJ6Vm.js → connections-BJv3EjmB.js} +10 -8
- package/dist/{continue-in-slack-Cvot6S38.js → continue-in-slack-CFEevC7z.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-Tjj5P2W6.js} +1 -1
- package/dist/{conversation-turn-CI8WDpnK.js → conversation-turn-DU0_WDAr.js} +26 -72
- package/dist/{credential-sync-COqnZ1Dx.js → credential-sync-D6aFARKE.js} +28 -27
- package/dist/{db-DU84dCVu.js → db-Bcbd9zQc.js} +226 -18
- package/dist/{db-zbN5ZV_o.d.ts → db-C41UgdBj.d.ts} +1 -1
- package/dist/{executor-CFyrgOu1.js → executor-DBMBrpNV.js} +137 -33
- package/dist/{history-m2-ceTTX.js → history-N7IVbUom.js} +5 -1
- package/dist/{install-CQ76CfRw.js → install-CgoAbzfF.js} +2 -2
- package/dist/instrumentation.js +2 -2
- package/dist/{lineage-DLd2UxVP.js → lineage-CsZDmz3e.js} +2 -2
- package/dist/{logging-BPNTQVFu.js → logging-CHCuQ5iz.js} +1 -1
- package/dist/{message-BWJLeQ5e.js → message-B8vCbZZB.js} +8 -8
- package/dist/{model-input-DoM9Ht-d.js → model-input-Xluiy-1W.js} +3 -3
- package/dist/nitro.d.ts +2 -2
- package/dist/nitro.js +3 -4
- package/dist/{oauth-callback-server-DeHbnAQl.js → oauth-callback-server-BUuNvfvu.js} +2 -2
- package/dist/{oauth-relay-DAmfVmJu.js → oauth-relay-DGAZzg9m.js} +1 -1
- package/dist/{plugins-B_0Cr0MO.d.ts → plugins-fBrz8PCV.d.ts} +2 -0
- package/dist/{projection-CcFBVFUo.js → projection-xPpvqexa.js} +13423 -11432
- package/dist/{prompt-C5LREK2p.js → prompt-D8u4jFs_.js} +15 -7
- package/dist/{registry-BjZZqKqi.js → registry-D20hG3r6.js} +19 -9
- package/dist/{resolve-CeJgXuH1.js → resolve-BhCySRCW.js} +3 -3
- package/dist/{result-icDrueyB.js → result-DddO63S9.js} +13 -11
- package/dist/{runner-nVfMkMMB.js → runner-DQR9vYce.js} +13 -15
- package/dist/{sandbox-egress-signals-H9vQ5qRf.js → sandbox-egress-signals-DFlNUOnK.js} +1 -1
- package/dist/{automation-CuA3yEcD.js → schedule-BG1tEbRF.js} +380 -8
- package/dist/{schema-CKcu-IK6.d.ts → schema-CRXcj4fj.d.ts} +420 -143
- package/dist/{schema-Bx0Mlo32.js → schema-D4jdesIu.js} +62 -8
- package/dist/{service-account-DU5865XA.js → service-account-Bv5QwrEq.js} +8 -6
- package/dist/{service-account-Dw06p3zm.js → service-account-CNfycv0z.js} +3 -3
- package/dist/{session-stop-uotLtp4g.js → session-stop-BDdwyZaa.js} +878 -171
- package/dist/{skills-Bex1EaO5.js → skills-63i1Bcv1.js} +32 -28
- package/dist/{slack-conversation-unfurl-EPG3riWF.js → slack-conversation-unfurl-DtpBUlUu.js} +10 -9
- package/dist/{spawn-CoD3vDuS.js → spawn-mwimEY9_.js} +6 -6
- package/dist/{state-nCR4Muhn.js → state-BBn9L6gC.js} +4 -4
- package/dist/{stop-BFVd0P0m.js → stop-Da-Ug7tg.js} +172 -239
- package/dist/{store-Ca6G962n.js → store-CdWg2r2L.js} +5 -5
- package/dist/{background-compaction-queue-BTqMIfTA.js → task-queue-BcjAYWyB.js} +164 -180
- package/dist/{task-runner-xsOPIxCZ.js → task-runner-CoXmMlsW.js} +13 -11
- package/dist/{thread-context-BOvZhsKK.js → thread-context-ZPGqOjW7.js} +8 -91
- package/dist/turn-session-routing-DFYak28Q.js +263 -0
- package/dist/{turn-user-message-BrhuyYrH.js → turn-user-message-B1S8nOnG.js} +3 -3
- package/dist/users-DDbENg-I.js +181 -0
- package/dist/{validation-BnY9K5WB.js → validation-fl21ps-k.js} +1 -1
- package/dist/{version-qROlRQGF.js → version-DCdMMx_0.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-CxUiOraX.js → viewer-DN_xzVKj.js} +3 -3
- package/dist/{warmup--Gkz7iB-.js → warmup-CxhEhm71.js} +842 -532
- package/dist/{web-message-id-lNodcCOI.js → web-message-id-BT8Mg8LL.js} +16 -1
- package/dist/{worker-DJ8d9fmD.js → worker-Btb1SB5h.js} +8 -7
- package/migrations/0114_plan_items.sql +22 -0
- package/migrations/0115_automation_creator_slack_index.sql +1 -0
- package/migrations/0116_conversation_event_search.sql +25 -0
- package/migrations/0117_automation_last_run.sql +46 -0
- package/migrations/0118_automation_last_run_index.sql +1 -0
- package/migrations/0119_money_micro_usd.sql +29 -0
- package/migrations/0120_conversation_cost_micro_usd.sql +8 -0
- package/migrations/meta/0114_snapshot.json +5203 -0
- package/migrations/meta/0115_snapshot.json +5225 -0
- package/migrations/meta/0116_snapshot.json +5388 -0
- package/migrations/meta/0117_snapshot.json +5413 -0
- package/migrations/meta/0118_snapshot.json +5428 -0
- package/migrations/meta/0119_snapshot.json +5441 -0
- package/migrations/meta/0120_snapshot.json +5441 -0
- package/migrations/meta/_journal.json +49 -0
- package/package.json +10 -9
- package/dist/queue-B2AAL3ym.js +0 -115
- package/dist/schedule-cP0AACm1.js +0 -344
- package/dist/secrets-DHaJ5TTn.js +0 -18
- package/dist/task-queue-BLPZU6kC.js +0 -89
- package/dist/turn-session-routing-2bW2qfeb.js +0 -1792
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
-
import { i as getChatConfig } from "./config-
|
|
2
|
+
import { i as getChatConfig } from "./config-362yMSIz.js";
|
|
3
3
|
import { a as isSlackUserId, d as parseSlackChannelReferenceId, f as parseSlackTeamId, s as parseActorUserId } from "./actor-D2iXzvlN.js";
|
|
4
|
-
import {
|
|
5
|
-
import { c as newConversationEventSchema, h as usageSchema, l as encodeHistoryPayload, o as decodeStoredConversationEvent, r as conversationEventDataSchema, s as historyReplacementSchema } from "./history-
|
|
6
|
-
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER, h as logWarn } from "./logging-
|
|
4
|
+
import { A as juniorConversationEvents, B as juniorUsers, D as CONVERSATION_METRICS, I as juniorAttachments, L as juniorMessageAttachments, M as juniorConversationAnnotations, O as juniorConversationMetrics, R as juniorConversations, S as juniorConversationBindings, V as juniorDestinations, k as isUserInstruction, p as juniorAutomationRuns, t as createJuniorSqlExecutor, x as juniorConversationParticipants, z as juniorIdentities } from "./executor-DBMBrpNV.js";
|
|
5
|
+
import { c as newConversationEventSchema, h as usageSchema, l as encodeHistoryPayload, o as decodeStoredConversationEvent, r as conversationEventDataSchema, s as historyReplacementSchema } from "./history-N7IVbUom.js";
|
|
6
|
+
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER, h as logWarn } from "./logging-CHCuQ5iz.js";
|
|
7
7
|
import * as z from "zod";
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
9
|
import { and, asc, desc, eq, gt, gte, inArray, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
@@ -222,6 +222,132 @@ function addAgentTurnUsage(...usages) {
|
|
|
222
222
|
};
|
|
223
223
|
return hasAgentTurnUsage(result) ? result : void 0;
|
|
224
224
|
}
|
|
225
|
+
// src/api/conversations/aggregate.ts
|
|
226
|
+
function usageTokenValue(source, field) {
|
|
227
|
+
return sql`CASE
|
|
228
|
+
WHEN ${source.usage}->>${field} IS NOT NULL
|
|
229
|
+
THEN (${source.usage}->>${field})::double precision
|
|
230
|
+
ELSE NULL
|
|
231
|
+
END`;
|
|
232
|
+
}
|
|
233
|
+
function tokenValue(source) {
|
|
234
|
+
return sql`
|
|
235
|
+
CASE
|
|
236
|
+
WHEN COALESCE(
|
|
237
|
+
${source.usage}->>'inputTokens',
|
|
238
|
+
${source.usage}->>'outputTokens',
|
|
239
|
+
${source.usage}->>'cachedInputTokens',
|
|
240
|
+
${source.usage}->>'cacheCreationTokens'
|
|
241
|
+
) IS NOT NULL
|
|
242
|
+
THEN COALESCE((${source.usage}->>'inputTokens')::double precision, 0)
|
|
243
|
+
+ COALESCE((${source.usage}->>'outputTokens')::double precision, 0)
|
|
244
|
+
+ COALESCE((${source.usage}->>'cachedInputTokens')::double precision, 0)
|
|
245
|
+
+ COALESCE((${source.usage}->>'cacheCreationTokens')::double precision, 0)
|
|
246
|
+
WHEN ${source.usage}->>'totalTokens' IS NOT NULL
|
|
247
|
+
THEN (${source.usage}->>'totalTokens')::double precision
|
|
248
|
+
ELSE NULL
|
|
249
|
+
END
|
|
250
|
+
`;
|
|
251
|
+
}
|
|
252
|
+
function costValue(source) {
|
|
253
|
+
return conversationUsageCostExpr(source.usage);
|
|
254
|
+
}
|
|
255
|
+
/** Read one conversation row's usage cost as a SQL expression. */
|
|
256
|
+
function conversationUsageCostExpr(usage) {
|
|
257
|
+
return sql`
|
|
258
|
+
CASE
|
|
259
|
+
WHEN ${usage}->'cost'->>'total' IS NOT NULL
|
|
260
|
+
THEN (${usage}->'cost'->>'total')::double precision
|
|
261
|
+
WHEN COALESCE(
|
|
262
|
+
${usage}->'cost'->>'input',
|
|
263
|
+
${usage}->'cost'->>'output',
|
|
264
|
+
${usage}->'cost'->>'cacheRead',
|
|
265
|
+
${usage}->'cost'->>'cacheWrite'
|
|
266
|
+
) IS NOT NULL
|
|
267
|
+
THEN COALESCE((${usage}->'cost'->>'input')::double precision, 0)
|
|
268
|
+
+ COALESCE((${usage}->'cost'->>'output')::double precision, 0)
|
|
269
|
+
+ COALESCE((${usage}->'cost'->>'cacheRead')::double precision, 0)
|
|
270
|
+
+ COALESCE((${usage}->'cost'->>'cacheWrite')::double precision, 0)
|
|
271
|
+
ELSE NULL
|
|
272
|
+
END
|
|
273
|
+
`;
|
|
274
|
+
}
|
|
275
|
+
/** Select complete conversation metrics inside the database instead of materializing source rows. */
|
|
276
|
+
function conversationAggregateColumns(sources) {
|
|
277
|
+
const metrics = sources?.metrics ?? juniorConversations;
|
|
278
|
+
const roots = sources?.roots ?? juniorConversations;
|
|
279
|
+
const conversationCount = sources ? sql`COUNT(DISTINCT ${roots.conversationId})` : sql`COUNT(*)`;
|
|
280
|
+
return {
|
|
281
|
+
active: sql`${conversationCount} FILTER (
|
|
282
|
+
WHERE ${roots.executionStatus} NOT IN ('idle', 'failed')
|
|
283
|
+
)::integer`,
|
|
284
|
+
conversations: sql`${conversationCount}::integer`,
|
|
285
|
+
cachedInputTokens: sql`SUM(${usageTokenValue(metrics, "cachedInputTokens")})::double precision`,
|
|
286
|
+
cacheCreationTokens: sql`SUM(${usageTokenValue(metrics, "cacheCreationTokens")})::double precision`,
|
|
287
|
+
costUsd: sql`SUM(${costValue(metrics)})::double precision`,
|
|
288
|
+
durationMs: sql`COALESCE(SUM(${metrics.durationMs}), 0)::double precision`,
|
|
289
|
+
failed: sql`${conversationCount} FILTER (
|
|
290
|
+
WHERE ${roots.executionStatus} = 'failed' AND ${roots.stoppedAt} IS NULL
|
|
291
|
+
)::integer`,
|
|
292
|
+
inputTokens: sql`SUM(${usageTokenValue(metrics, "inputTokens")})::double precision`,
|
|
293
|
+
tokens: sql`SUM(${tokenValue(metrics)})::double precision`
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
/** Select the complete first/last activity range for a grouped conversation aggregate. */
|
|
297
|
+
function conversationRangeColumns() {
|
|
298
|
+
return {
|
|
299
|
+
firstSeenAt: sql`MIN(${juniorConversations.createdAt})`.mapWith(juniorConversations.createdAt),
|
|
300
|
+
lastSeenAt: sql`MAX(${juniorConversations.lastActivityAt})`.mapWith(juniorConversations.lastActivityAt)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
// src/db/micro-usd.ts
|
|
304
|
+
/**
|
|
305
|
+
* Postgres stores every money value as whole micro-USD, in a `bigint` column
|
|
306
|
+
* or an integer metric value named `*_micro_usd`. Integer sums are exact and
|
|
307
|
+
* do not depend on row order. Round once where a USD amount is stored, and
|
|
308
|
+
* convert to USD once where the API returns it. `pnpm money-units:check`
|
|
309
|
+
* keeps money scales in this file.
|
|
310
|
+
*/
|
|
311
|
+
const MICRO_USD_PER_USD = 1e6;
|
|
312
|
+
/** Round a USD amount to whole micro-USD for storage. */
|
|
313
|
+
function usdToMicroUsd(usd) {
|
|
314
|
+
return Math.round(usd * MICRO_USD_PER_USD);
|
|
315
|
+
}
|
|
316
|
+
/** Convert stored micro-USD to USD for an API response. */
|
|
317
|
+
function microUsdToUsd(microUsd) {
|
|
318
|
+
return microUsd / MICRO_USD_PER_USD;
|
|
319
|
+
}
|
|
320
|
+
/** SQL that rounds a USD amount to whole micro-USD. */
|
|
321
|
+
function usdToMicroUsdSql(usd) {
|
|
322
|
+
return sql`round(${usd} * 1000000)::bigint`;
|
|
323
|
+
}
|
|
324
|
+
/** SQL that converts micro-USD to USD, for usage JSON in USD. */
|
|
325
|
+
function microUsdToUsdSql(microUsd) {
|
|
326
|
+
return sql`(${microUsd}) / 1000000.0::double precision`;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* SQL that reads a micro-USD value or sum as an exact integer. Postgres
|
|
330
|
+
* returns `bigint` as text, so this maps it to a number.
|
|
331
|
+
*/
|
|
332
|
+
function microUsdSql(microUsd) {
|
|
333
|
+
return sql`(${microUsd})::bigint`.mapWith(Number);
|
|
334
|
+
}
|
|
335
|
+
// src/chat/automations/run-cost.ts
|
|
336
|
+
/**
|
|
337
|
+
* SQL for a Conversation's usage cost in whole micro-USD, the unit of a run's
|
|
338
|
+
* `cost_micro_usd`.
|
|
339
|
+
*/
|
|
340
|
+
function costMicroUsdExpr(usage) {
|
|
341
|
+
return usdToMicroUsdSql(conversationUsageCostExpr(usage));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* SQL that reads the cost of one Conversation, for the `cost_micro_usd` of its
|
|
345
|
+
* run. Set it in each run write that links a run to its Conversation, because
|
|
346
|
+
* the Conversation can record usage before its run row exists.
|
|
347
|
+
*/
|
|
348
|
+
function conversationCostOf(conversationId) {
|
|
349
|
+
return sql`(select ${costMicroUsdExpr(juniorConversations.usage)} from ${juniorConversations} where ${juniorConversations.conversationId} = ${conversationId})`;
|
|
350
|
+
}
|
|
225
351
|
// src/chat/conversations/metrics.ts
|
|
226
352
|
function finite(value) {
|
|
227
353
|
return value !== void 0 && Number.isFinite(value) && value >= 0 ? value : void 0;
|
|
@@ -229,6 +355,7 @@ function finite(value) {
|
|
|
229
355
|
/** Convert one Run summary to metric rows. */
|
|
230
356
|
function conversationMetricValues(args) {
|
|
231
357
|
const usage = args.usage;
|
|
358
|
+
const costUsd = agentTurnCostUsd(usage);
|
|
232
359
|
return {
|
|
233
360
|
duration_ms: Math.max(0, args.durationMs),
|
|
234
361
|
total_tokens: agentTurnTotalTokens(usage),
|
|
@@ -237,7 +364,7 @@ function conversationMetricValues(args) {
|
|
|
237
364
|
cached_input_tokens: finite(usage?.cachedInputTokens),
|
|
238
365
|
cache_creation_tokens: finite(usage?.cacheCreationTokens),
|
|
239
366
|
reasoning_tokens: finite(usage?.reasoningTokens),
|
|
240
|
-
|
|
367
|
+
cost_micro_usd: costUsd === void 0 ? void 0 : usdToMicroUsd(costUsd)
|
|
241
368
|
};
|
|
242
369
|
}
|
|
243
370
|
/**
|
|
@@ -260,12 +387,12 @@ async function readConversationRunMetrics(executor, args) {
|
|
|
260
387
|
cacheCreationTokens: values.get("cache_creation_tokens")
|
|
261
388
|
};
|
|
262
389
|
const hasComponents = Object.values(components).some((value) => value !== void 0);
|
|
263
|
-
const
|
|
390
|
+
const costMicroUsd = values.get("cost_micro_usd");
|
|
264
391
|
const usage = Object.fromEntries(Object.entries({
|
|
265
392
|
...components,
|
|
266
393
|
reasoningTokens: values.get("reasoning_tokens"),
|
|
267
394
|
totalTokens: hasComponents ? void 0 : values.get("total_tokens"),
|
|
268
|
-
cost:
|
|
395
|
+
cost: costMicroUsd === void 0 ? void 0 : { total: microUsdToUsd(costMicroUsd) }
|
|
269
396
|
}).filter(([, value]) => value !== void 0));
|
|
270
397
|
return {
|
|
271
398
|
durationMs,
|
|
@@ -313,9 +440,10 @@ async function replaceConversationMetrics(executor, args) {
|
|
|
313
440
|
or ${metric("cached_input_tokens")} is not null
|
|
314
441
|
or ${metric("cache_creation_tokens")} is not null
|
|
315
442
|
`;
|
|
316
|
-
const cost = sql`case when ${metric("
|
|
317
|
-
else jsonb_build_object('total', ${metric("
|
|
318
|
-
|
|
443
|
+
const cost = sql`case when ${metric("cost_micro_usd")} is null then null
|
|
444
|
+
else jsonb_build_object('total', ${microUsdToUsdSql(metric("cost_micro_usd"))}) end`;
|
|
445
|
+
const db = executor.db();
|
|
446
|
+
const usageUpdate = db.$with("conversation_usage_update").as(db.update(juniorConversations).set({
|
|
319
447
|
durationMs: sql`coalesce(${metric("duration_ms")}, 0)`,
|
|
320
448
|
usage: sql`case
|
|
321
449
|
when ${totalTokens} is not null
|
|
@@ -337,7 +465,8 @@ async function replaceConversationMetrics(executor, args) {
|
|
|
337
465
|
))
|
|
338
466
|
end`,
|
|
339
467
|
detailVersion: nextDetailVersion
|
|
340
|
-
}).where(eq(juniorConversations.conversationId, args.conversationId));
|
|
468
|
+
}).where(eq(juniorConversations.conversationId, args.conversationId)).returning({ costMicroUsd: costMicroUsdExpr(juniorConversations.usage).as("cost_micro_usd") }));
|
|
469
|
+
await db.with(usageUpdate).update(juniorAutomationRuns).set({ costMicroUsd: sql`(select ${usageUpdate.costMicroUsd} from ${usageUpdate})` }).where(eq(juniorAutomationRuns.conversationId, args.conversationId));
|
|
341
470
|
}
|
|
342
471
|
// src/chat/source.ts
|
|
343
472
|
/**
|
|
@@ -971,6 +1100,17 @@ async function saveUserTimezone(db, userId, timezone, nowMs) {
|
|
|
971
1100
|
updatedAt: dateFromMs$1(nowMs)
|
|
972
1101
|
}).where(and(eq(juniorUsers.id, userId), sql`${juniorUsers.timezone} is distinct from ${timezone}`));
|
|
973
1102
|
}
|
|
1103
|
+
/** Return the Slack user most recently linked to a Junior user. */
|
|
1104
|
+
async function linkedSlackUser(db, userId) {
|
|
1105
|
+
const row = (await db.select({
|
|
1106
|
+
teamId: juniorIdentities.providerTenantId,
|
|
1107
|
+
slackUserId: juniorIdentities.providerSubjectId
|
|
1108
|
+
}).from(juniorIdentities).where(and(eq(juniorIdentities.userId, userId), eq(juniorIdentities.kind, "user"), eq(juniorIdentities.provider, "slack"))).orderBy(desc(juniorIdentities.updatedAt)).limit(1))[0];
|
|
1109
|
+
return row?.teamId ? {
|
|
1110
|
+
teamId: row.teamId,
|
|
1111
|
+
userId: row.slackUserId
|
|
1112
|
+
} : void 0;
|
|
1113
|
+
}
|
|
974
1114
|
/** Persist one provider identity observation and link verified emails to users. */
|
|
975
1115
|
async function upsertIdentity(executor, identity, nowMs = Date.now()) {
|
|
976
1116
|
return await upsertIdentityRecord(executor, identity, void 0, nowMs);
|
|
@@ -997,6 +1137,45 @@ async function findUserByVerifiedEmails(executor, emails) {
|
|
|
997
1137
|
}).from(juniorUsers).where(inArray(juniorUsers.primaryEmailNormalized, Array.from(normalized))).limit(2);
|
|
998
1138
|
return rows.length === 1 ? rows[0] : void 0;
|
|
999
1139
|
}
|
|
1140
|
+
const linkedSlackIdentity = alias(juniorIdentities, "linked_slack_identity");
|
|
1141
|
+
const linkedSlackUserColumns = {
|
|
1142
|
+
displayName: juniorUsers.displayName,
|
|
1143
|
+
email: juniorUsers.primaryEmail,
|
|
1144
|
+
slackUserId: linkedSlackIdentity.providerSubjectId,
|
|
1145
|
+
userId: juniorUsers.id
|
|
1146
|
+
};
|
|
1147
|
+
function singleLinkedSlackUser(rows) {
|
|
1148
|
+
const [row] = rows;
|
|
1149
|
+
if (rows.length !== 1 || !row) return void 0;
|
|
1150
|
+
return {
|
|
1151
|
+
slackUserId: row.slackUserId,
|
|
1152
|
+
user: {
|
|
1153
|
+
id: row.userId,
|
|
1154
|
+
email: row.email,
|
|
1155
|
+
...row.displayName ? { displayName: row.displayName } : void 0
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Find the one Slack user in a workspace who is linked to an exact provider
|
|
1161
|
+
* Identity, and the User behind both.
|
|
1162
|
+
*
|
|
1163
|
+
* Only the provider account id from an account-linking flow matches. Handles,
|
|
1164
|
+
* emails, and display names never match. Return undefined when no Slack user
|
|
1165
|
+
* or more than one Slack user matches.
|
|
1166
|
+
*/
|
|
1167
|
+
async function findLinkedSlackUser(executor, args) {
|
|
1168
|
+
return singleLinkedSlackUser(await executor.db().select(linkedSlackUserColumns).from(juniorIdentities).innerJoin(linkedSlackIdentity, and(eq(linkedSlackIdentity.userId, juniorIdentities.userId), eq(linkedSlackIdentity.kind, "user"), eq(linkedSlackIdentity.provider, "slack"), eq(linkedSlackIdentity.providerTenantId, args.slackTeamId))).innerJoin(juniorUsers, eq(juniorUsers.id, juniorIdentities.userId)).where(and(eq(juniorIdentities.kind, "user"), eq(juniorIdentities.provider, args.provider), eq(juniorIdentities.providerTenantId, ""), eq(juniorIdentities.providerSubjectId, args.providerSubjectId))).limit(2));
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Find the one Slack user in a workspace whose User has this primary email.
|
|
1172
|
+
*
|
|
1173
|
+
* The caller must have verified that the person sent from this address.
|
|
1174
|
+
* Return undefined when no Slack user or more than one Slack user matches.
|
|
1175
|
+
*/
|
|
1176
|
+
async function findSlackUserByPrimaryEmail(executor, args) {
|
|
1177
|
+
return singleLinkedSlackUser(await executor.db().select(linkedSlackUserColumns).from(juniorUsers).innerJoin(linkedSlackIdentity, eq(linkedSlackIdentity.userId, juniorUsers.id)).where(and(eq(juniorUsers.primaryEmailNormalized, args.normalizedEmail), eq(linkedSlackIdentity.kind, "user"), eq(linkedSlackIdentity.provider, "slack"), eq(linkedSlackIdentity.providerTenantId, args.slackTeamId))).limit(2));
|
|
1178
|
+
}
|
|
1000
1179
|
/** Remove one exact provider identity owned by a workspace Slack user. */
|
|
1001
1180
|
async function deleteProviderIdentityForSlackUser(executor, slackTeamId, slackUserId, provider, providerSubjectId) {
|
|
1002
1181
|
const userId = (await executor.db().select({ userId: juniorIdentities.userId }).from(juniorIdentities).where(and(eq(juniorIdentities.kind, "user"), eq(juniorIdentities.provider, "slack"), eq(juniorIdentities.providerTenantId, slackTeamId), eq(juniorIdentities.providerSubjectId, slackUserId))).limit(1))[0]?.userId;
|
|
@@ -1333,6 +1512,8 @@ function conversationKindFromRow(row) {
|
|
|
1333
1512
|
const ROOT = {
|
|
1334
1513
|
delivery: "location",
|
|
1335
1514
|
promptMode: "conversation",
|
|
1515
|
+
idleNeedsPendingWork: false,
|
|
1516
|
+
waitsForSignIn: true,
|
|
1336
1517
|
gated: false,
|
|
1337
1518
|
failureNotice: "none",
|
|
1338
1519
|
sessionTasks: true,
|
|
@@ -1348,15 +1529,19 @@ const ROOT = {
|
|
|
1348
1529
|
};
|
|
1349
1530
|
const PERSON_IN_THREAD = {
|
|
1350
1531
|
...ROOT,
|
|
1532
|
+
promptMode: "thread",
|
|
1533
|
+
sender: "person",
|
|
1351
1534
|
sessionTasks: false,
|
|
1352
1535
|
tools: {
|
|
1353
1536
|
...ROOT.tools,
|
|
1354
1537
|
agents: "none"
|
|
1355
1538
|
}
|
|
1356
1539
|
};
|
|
1357
|
-
const
|
|
1540
|
+
const CHILD_AGENT_TURN = {
|
|
1358
1541
|
delivery: "conversation",
|
|
1359
1542
|
promptMode: "child_agent",
|
|
1543
|
+
idleNeedsPendingWork: false,
|
|
1544
|
+
waitsForSignIn: false,
|
|
1360
1545
|
gated: true,
|
|
1361
1546
|
failureNotice: "none",
|
|
1362
1547
|
sessionTasks: false,
|
|
@@ -1370,14 +1555,28 @@ const AGENT_IN_THREAD = {
|
|
|
1370
1555
|
noReply: true
|
|
1371
1556
|
}
|
|
1372
1557
|
};
|
|
1558
|
+
const AGENT_IN_THREAD = {
|
|
1559
|
+
...CHILD_AGENT_TURN,
|
|
1560
|
+
promptMode: "thread",
|
|
1561
|
+
sender: "agent"
|
|
1562
|
+
};
|
|
1563
|
+
const THREAD_TOOLS = {
|
|
1564
|
+
...AGENT_IN_THREAD.tools,
|
|
1565
|
+
reviewDesk: PERSON_IN_THREAD.tools.reviewDesk,
|
|
1566
|
+
subscriptions: PERSON_IN_THREAD.tools.subscriptions,
|
|
1567
|
+
userCustomization: PERSON_IN_THREAD.tools.userCustomization
|
|
1568
|
+
};
|
|
1373
1569
|
const AGENT_IN_TASK = {
|
|
1374
|
-
...
|
|
1570
|
+
...CHILD_AGENT_TURN,
|
|
1375
1571
|
missingAnswerError: "No reply was sent.",
|
|
1376
1572
|
failureNotice: "parent"
|
|
1377
1573
|
};
|
|
1378
1574
|
const AUTOMATION_RUN = {
|
|
1379
1575
|
delivery: "conversation",
|
|
1380
1576
|
promptMode: "automation",
|
|
1577
|
+
sender: "automation",
|
|
1578
|
+
idleNeedsPendingWork: true,
|
|
1579
|
+
waitsForSignIn: true,
|
|
1381
1580
|
gated: true,
|
|
1382
1581
|
failureNotice: "none",
|
|
1383
1582
|
sessionTasks: true,
|
|
@@ -1387,21 +1586,28 @@ const AUTOMATION_RUN = {
|
|
|
1387
1586
|
reportBlocked: "automation"
|
|
1388
1587
|
}
|
|
1389
1588
|
};
|
|
1589
|
+
const PERSON_IN_AUTOMATION = {
|
|
1590
|
+
...ROOT,
|
|
1591
|
+
promptMode: "automation",
|
|
1592
|
+
sender: "person"
|
|
1593
|
+
};
|
|
1390
1594
|
/** Return the behavior of one Turn. */
|
|
1391
1595
|
function turnBehavior(args) {
|
|
1392
1596
|
if (args.kind === "root") return ROOT;
|
|
1393
|
-
if (args.kind === "automation") return args.personInput ?
|
|
1597
|
+
if (args.kind === "automation") return args.personInput ? PERSON_IN_AUTOMATION : AUTOMATION_RUN;
|
|
1394
1598
|
if (args.kind === "thread") return args.personInput ? PERSON_IN_THREAD : AGENT_IN_THREAD;
|
|
1395
1599
|
if (!args.personInput) return AGENT_IN_TASK;
|
|
1396
1600
|
throw new Error("A task Conversation cannot have a person's input");
|
|
1397
1601
|
}
|
|
1398
1602
|
/**
|
|
1399
|
-
* Return the Turn
|
|
1400
|
-
*
|
|
1603
|
+
* Return the tools that every Turn of one Prompt mode lists. A Turn of a mode
|
|
1604
|
+
* with two senders can list more than its own tools. The listed tools that it
|
|
1605
|
+
* cannot use are disabled.
|
|
1401
1606
|
*/
|
|
1402
1607
|
function promptModeTurnTools(mode) {
|
|
1403
1608
|
if (mode === "automation") return AUTOMATION_RUN.tools;
|
|
1404
1609
|
if (mode === "child_agent") return AGENT_IN_TASK.tools;
|
|
1610
|
+
if (mode === "thread") return THREAD_TOOLS;
|
|
1405
1611
|
return ROOT.tools;
|
|
1406
1612
|
}
|
|
1407
1613
|
/** Return whether a Conversation of this kind has no parent. */
|
|
@@ -2432,7 +2638,8 @@ var SqlConversationEventStore = class {
|
|
|
2432
2638
|
/**
|
|
2433
2639
|
* Add the authors of Turn input messages to the conversation.
|
|
2434
2640
|
* Only people who start a Turn join it. Thread context, such as backfilled
|
|
2435
|
-
* or skipped messages,
|
|
2641
|
+
* or skipped messages, and Event Messages keep their author without
|
|
2642
|
+
* membership.
|
|
2436
2643
|
*/
|
|
2437
2644
|
async recordTurnInputParticipants(conversationId, inputMessageIds) {
|
|
2438
2645
|
const rows = await this.executor.db().select().from(juniorConversationEvents).where(and(eq(juniorConversationEvents.conversationId, conversationId), eq(juniorConversationEvents.type, "message"), inArray(sql`${juniorConversationEvents.payload}->>'messageId'`, [...inputMessageIds])));
|
|
@@ -2441,6 +2648,7 @@ var SqlConversationEventStore = class {
|
|
|
2441
2648
|
for (const row of rows) {
|
|
2442
2649
|
const { data } = eventFromRow(row);
|
|
2443
2650
|
if (!row.actorIdentityId || data.type !== "message") continue;
|
|
2651
|
+
if (data.meta?.["eventType"]) continue;
|
|
2444
2652
|
const unarchives = eventUnarchivesConversation(data);
|
|
2445
2653
|
const isPerson = await recordConversationParticipant(this.executor, {
|
|
2446
2654
|
actorIdentityId: row.actorIdentityId,
|
|
@@ -2736,4 +2944,4 @@ async function closeDb() {
|
|
|
2736
2944
|
current = void 0;
|
|
2737
2945
|
await previous?.db.close();
|
|
2738
2946
|
}
|
|
2739
|
-
export {
|
|
2947
|
+
export { getStateAdapter as $, conversationKindFromRow as A, findLinkedSlackUser as B, withConversationMutationLock as C, conversationDetailTouch as Ct, postsRunNotices as D, parseDestination as Dt, isTopLevelKind as E, createSlackDestination as Et, findActorIdentityId as F, recordGoogleSignIn as G, findUserByVerifiedEmails as H, resolveActorIdentityId as I, clearCachedUser as J, saveUserTimezone as K, saveActorAvatar as L, setFirstConversationLocation as M, startLocationThread as N, promptModeTurnTools as O, requireSlackDestination as Ot, SYSTEM_IDENTITY_ID as P, getDefaultRedisStateAdapterFor as Q, deleteProviderIdentityForSlackUser as R, createSqlStore as S, rootConversationIsArchived as St, isPersonInput as T, touchConversationDetail as Tt, linkedSlackUser as U, findSlackUserByPrimaryEmail as V, readUserTimezone as W, createCache as X, readCachedUserByEmail as Y, disconnectStateAdapter as Z, readConversationTrees as _, agentTurnCostUsd as _t, getConversationStore as a, withLock as at, lastMessageAtSql as b, hasAgentTurnUsage as bt, hasAnnotationKey as c, parseSessionSource as ct, eventFromRow as d, microUsdToUsd as dt, getStateValues as et, copyMessageLinks as f, usdToMicroUsd as ft, conversationDescendants as g, addAgentTurnUsage as gt, conversationAncestors as h, conversationUsageCostExpr as ht, getConversationMessageSearchStore as i, fenceLock as it, locationFromRow as j, turnBehavior as k, sameDestination as kt, treeHasAnnotationKey as l, conversationCostOf as lt, withConversationEventLock as m, conversationRangeColumns as mt, db_exports as n, MUTATION_LOCK_TTL_MS as nt, getDb as o, claimProviderConversation as ot, deleteMessageLinks as p, conversationAggregateColumns as pt, upsertLinkedIdentity as q, getConversationEventStore as r, acquireActiveLock as rt, getSqlExecutor as s, getConversationIdByProviderConversation as st, closeDb as t, setStateValues as tt, createSqlConversationEventStore as u, microUsdSql as ut, setArchivedAt as v, agentTurnTotalTokens as vt, deliversFinalText as w, nextDetailVersion as wt, userMessageQueries as x, resolveRootConversationId as xt, loadConversationSlackTenantIds as y, agentTurnUsageSchema as yt, deleteProviderIdentityForUser as z };
|