@sentry/junior 0.301.0 → 0.303.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-BdVnSuY5.js +43 -0
- package/dist/{admin-CRJHvCGg.js → admin-AfeAdS3J.js} +2 -2
- package/dist/{agent-runner-H4YhvNBj.js → agent-runner-BP8_DLUv.js} +4688 -13870
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -8
- package/dist/api.d.ts +13 -12
- package/dist/api.js +268 -118
- package/dist/{app-HDZglaIu.d.ts → app-Dd9v1mNx.d.ts} +15 -15
- package/dist/app.d.ts +1 -1
- package/dist/app.js +99 -330
- package/dist/{automation-Cva5ZOwW.js → automation-D9MvhOWY.js} +3 -1
- package/dist/{background-compaction-queue-CNrZ3QcU.js → background-compaction-queue-xaE05jxH.js} +97 -206
- package/dist/{briefs-x6Mzwxmg.js → briefs-D8i-dKTp.js} +4 -4
- package/dist/{catalog-runtime-BEY6EGRi.js → catalog-runtime-d1EM6Z0V.js} +2 -2
- package/dist/cli/chat.d.ts +1 -1
- package/dist/cli/chat.js +21 -21
- package/dist/cli/check.js +8 -8
- package/dist/cli/env.d.ts +1 -0
- package/dist/cli/env.js +8 -7
- package/dist/cli/init.js +13 -4
- package/dist/cli/main.js +4 -4
- package/dist/cli/plugins.js +6 -6
- package/dist/cli/snapshot-create.js +7 -5
- package/dist/cli/upgrade.d.ts +2 -2
- package/dist/cli/upgrade.js +5 -5
- package/dist/{config-CmjhyqgB.js → config-oGM7KA9M.js} +44 -63
- package/dist/{connections-CfIRm0xv.js → connections-BlikzEJv.js} +6 -6
- package/dist/{continue-in-slack-DPoABVkB.js → continue-in-slack-BZnYifiG.js} +5 -6
- package/dist/{conversation-BNXfq6Lb.js → conversation-CY1jnBiC.js} +1 -1
- package/dist/{conversation-feed-CfpyFMHP.js → conversation-feed-BZJRk6UV.js} +2 -1
- package/dist/{conversation-privacy-0CM0V2qK.js → conversation-privacy-Cx515ddM.js} +7 -7
- package/dist/{conversation-turn-C0sxyvS-.js → conversation-turn-DAhRdX4m.js} +20 -24
- package/dist/{credential-sync-tEMKZ_8M.js → credential-sync-DfhmWFeo.js} +18 -20
- package/dist/{db-Czra10QW.js → db-C-2tFxk3.js} +326 -17
- package/dist/{db-BdUHQhrC.d.ts → db-DPqcEM9_.d.ts} +25 -25
- package/dist/{executor-D_023K0H.js → executor-NVfS8aQ2.js} +51 -10
- package/dist/{history-IjdmO_r6.js → history-UZ3M2M9r.js} +13 -10
- package/dist/install-CHLrpRZc.js +228 -0
- package/dist/instrumentation.d.ts +4 -4
- package/dist/instrumentation.js +10 -10
- package/dist/{lineage-DmMIE0VL.js → lineage-HGLhd_-N.js} +2 -2
- package/dist/{logging-DcjLDDqi.js → logging-DiyqRLBx.js} +24 -20
- package/dist/{message-C0JY9RJP.js → message-CkCOcbFH.js} +9 -9
- package/dist/{model-input-CBp-p24N.js → model-input-DmoPPtPE.js} +5 -10
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +7 -6
- package/dist/{oauth-callback-server-BRq9QNhU.js → oauth-callback-server-CIf_6YmA.js} +5 -4
- package/dist/{oauth-relay-DRzq73b6.js → oauth-relay-DAmfVmJu.js} +3 -6
- package/dist/{package-discovery-DJhGdS4c.js → package-discovery-x4AvVhMj.js} +1 -1
- package/dist/{plugin-module-Cf5gVPWP.js → plugin-module-Cv2ETe8Y.js} +1 -1
- package/dist/{plugins-BBX07Jzt.js → plugins-Bkk0XRo2.js} +3 -3
- package/dist/{projection-CQNDOi82.js → projection-DBq8tsA5.js} +489 -223
- package/dist/{prompt-DLUB5m72.js → prompt-D2KlJopL.js} +15 -5
- package/dist/{queue-CZyYgPF0.d.ts → queue-CbEHUO0l.d.ts} +1 -1
- package/dist/queue-DFaOscp5.js +115 -0
- package/dist/{registry-Dj377ADs.js → registry-Bu0Z9BEO.js} +37 -37
- package/dist/{resolve-DJkh9Fky.js → resolve-DXuA3G0g.js} +4 -229
- package/dist/{result-C8iIpDl1.js → result-DpiNseDA.js} +11 -16
- package/dist/rolldown-runtime-BKpuH2hG.js +26 -0
- package/dist/{runner-DZqrOy8C.js → runner-iu1heRFv.js} +10 -10
- package/dist/{sandbox-egress-signals-CGwH86S9.js → sandbox-egress-signals-2HFYDcQf.js} +1 -1
- package/dist/{schema-CdZFn7Qd.d.ts → schema-DHMOaRzC.d.ts} +959 -41
- package/dist/{schema-DyHXiQKI.js → schema-DvfX3Gq_.js} +141 -40
- package/dist/{secrets-DebYU866.js → secrets-DHaJ5TTn.js} +4 -4
- package/dist/{sentry-BRTJqumy.js → sentry-CPbZjomA.js} +3 -28
- package/dist/{sentry-route-name-BhwWnfqj.js → sentry-route-name-C6EIzAGP.js} +1 -1
- package/dist/{service-account-suY004dx.js → service-account-BcT5LR7V.js} +271 -20
- package/dist/{service-account-D6jGR4a1.js → service-account-xYkaQTrw.js} +3 -3
- package/dist/{session-stop-BLmfFI3d.js → session-stop-BLLp1IP_.js} +1098 -1110
- package/dist/{skills-CmNG0dHb.js → skills-CNAGH4ju.js} +6 -9
- package/dist/{slack-conversation-unfurl-Bty-DlHe.js → slack-conversation-unfurl-DYnqe5ci.js} +10 -14
- package/dist/{spawn-CNjkpXpk.js → spawn-cGasWW33.js} +7 -7
- package/dist/{state-CEbZuZD6.js → state-CDS6h_Wv.js} +34 -5
- package/dist/{stop-Bjy2-K4H.js → stop-DMMA67yT.js} +896 -196
- package/dist/{store-DmV4CoNr.js → store-Dgs7Oe44.js} +5 -5
- package/dist/{task-queue-AhG1tSXR.js → task-queue-DcF0nhhz.js} +3 -3
- package/dist/{task-runner-BMxZI3o7.js → task-runner-BGXF7Fo7.js} +15 -20
- package/dist/{thread-context-CXLnbg7g.js → thread-context-BPky1KBe.js} +12 -12
- package/dist/{store-Epv6t4vV.js → turn-session-routing-DGvn9MSl.js} +384 -13
- package/dist/{turn-user-message-DsUZi9gn.js → turn-user-message-19CkuUvM.js} +3 -3
- package/dist/{validation-DOz8X9BU.js → validation-lu1DgjNQ.js} +2 -2
- package/dist/vercel.js +1 -1
- package/dist/{version-CGMRmMPK.js → version-Uo3c94Dx.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{viewer-H3EsMWtJ.js → viewer-BPQHMx3-.js} +3 -3
- package/dist/warmup-H8uLvW9e.js +13946 -0
- package/dist/{statuses-Hn-HsOph.js → web-message-id-lNodcCOI.js} +136 -1
- package/dist/{worker-ClphajjD.js → worker-B-pM_-3K.js} +9 -12
- package/migrations/0108_conversation_embeddings.sql +13 -0
- package/migrations/0109_user_preferences.sql +1 -0
- package/migrations/0110_code_change_repository_state_index.sql +1 -0
- package/migrations/meta/0108_snapshot.json +4688 -0
- package/migrations/meta/0109_snapshot.json +4925 -0
- package/migrations/meta/0110_snapshot.json +4952 -0
- package/migrations/meta/_journal.json +22 -1
- package/package.json +16 -17
- package/dist/adapter-CNjGEJO9.js +0 -303
- package/dist/reporting-window-DopzcOHh.js +0 -137
- package/dist/turn-session-routing-BD3-jJl7.js +0 -380
- package/dist/users-BxvYclQg.js +0 -424
- package/dist/warmup-CdU5hR49.js +0 -3715
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as getChatConfig } from "./config-
|
|
3
|
-
import { H as GOOGLE_IDENTITY_PROVIDER, W as normalizeIdentityEmail, h as logWarn } from "./logging-DcjLDDqi.js";
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
+
import { i as getChatConfig } from "./config-oGM7KA9M.js";
|
|
4
3
|
import { a as isSlackUserId, d as parseSlackChannelReferenceId, f as parseSlackTeamId, s as parseActorUserId } from "./actor-D2iXzvlN.js";
|
|
5
|
-
import { C as
|
|
6
|
-
import { c as newConversationEventSchema, h as usageSchema, l as encodeHistoryPayload, o as decodeStoredConversationEvent, r as conversationEventDataSchema, s as historyReplacementSchema } from "./history-
|
|
7
|
-
import {
|
|
4
|
+
import { C as juniorConversationMetrics, D as juniorConversationAnnotations, F as juniorDestinations, M as juniorConversations, N as juniorIdentities, P as juniorUsers, S as CONVERSATION_METRICS, T as juniorConversationEvents, t as createJuniorSqlExecutor, v as juniorConversationParticipants, w as isUserInstruction, y as juniorConversationBindings } from "./executor-NVfS8aQ2.js";
|
|
5
|
+
import { c as newConversationEventSchema, h as usageSchema, l as encodeHistoryPayload, o as decodeStoredConversationEvent, r as conversationEventDataSchema, s as historyReplacementSchema } from "./history-UZ3M2M9r.js";
|
|
6
|
+
import { G as normalizeIdentityEmail, U as GOOGLE_IDENTITY_PROVIDER, h as logWarn } from "./logging-DiyqRLBx.js";
|
|
8
7
|
import * as z from "zod";
|
|
9
8
|
import { randomUUID } from "node:crypto";
|
|
10
9
|
import { and, asc, desc, eq, gt, gte, inArray, isNull, lt, lte, ne, or, sql } from "drizzle-orm";
|
|
11
10
|
import { destinationSchema, locationSchema, sourceSchema } from "@sentry/junior-plugin-api";
|
|
12
11
|
import { alias } from "drizzle-orm/pg-core";
|
|
12
|
+
import { createMemoryState } from "@chat-adapter/state-memory";
|
|
13
|
+
import { createRedisState } from "@chat-adapter/state-redis";
|
|
14
|
+
import { setTimeout } from "node:timers/promises";
|
|
13
15
|
// src/chat/destination.ts
|
|
14
16
|
/** Build Junior's canonical destination from Slack workspace and channel ids. */
|
|
15
17
|
function createSlackDestination(input) {
|
|
@@ -397,6 +399,304 @@ async function claimProviderConversation(executor, args) {
|
|
|
397
399
|
async function bindProviderConversation(executor, args) {
|
|
398
400
|
if (!await claimProviderConversation(executor, args)) throw new Error("Provider conversation is already bound to another conversation");
|
|
399
401
|
}
|
|
402
|
+
// src/chat/state/locks.ts
|
|
403
|
+
const ACTIVE_LOCK_TTL_MS = 9e4;
|
|
404
|
+
const MUTATION_LOCK_TTL_MS = 1e4;
|
|
405
|
+
/**
|
|
406
|
+
* Acquire a lock for long-running work that the queued state adapter should
|
|
407
|
+
* keep alive while the owning invocation is still making progress.
|
|
408
|
+
*/
|
|
409
|
+
async function acquireActiveLock(state, threadId) {
|
|
410
|
+
return await state.acquireLock(threadId, ACTIVE_LOCK_TTL_MS);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Run work under one lock, optionally waiting for the current owner.
|
|
414
|
+
* `keepAlive` is for multi-store mutations that must retain ownership until all
|
|
415
|
+
* side effects finish; callers should still fence each blind write.
|
|
416
|
+
*/
|
|
417
|
+
async function withLock(state, key, run, options = {}) {
|
|
418
|
+
const ttlMs = options.ttlMs ?? 9e4;
|
|
419
|
+
const startedAtMs = Date.now();
|
|
420
|
+
let lock;
|
|
421
|
+
while (true) {
|
|
422
|
+
lock = await state.acquireLock(key, ttlMs);
|
|
423
|
+
if (lock) break;
|
|
424
|
+
if (Date.now() - startedAtMs >= (options.waitMs ?? 0)) return { acquired: false };
|
|
425
|
+
await setTimeout(options.retryMs ?? 25, void 0, { ref: false });
|
|
426
|
+
}
|
|
427
|
+
const heartbeat = options.keepAlive ? setInterval(() => void state.extendLock(lock, ttlMs).catch(() => void 0), Math.max(1, Math.floor(ttlMs / 3))) : void 0;
|
|
428
|
+
heartbeat?.unref();
|
|
429
|
+
try {
|
|
430
|
+
return {
|
|
431
|
+
acquired: true,
|
|
432
|
+
value: await run(lock)
|
|
433
|
+
};
|
|
434
|
+
} finally {
|
|
435
|
+
if (heartbeat) clearInterval(heartbeat);
|
|
436
|
+
await state.releaseLock(lock);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Prove lock ownership immediately before a blind write.
|
|
441
|
+
*
|
|
442
|
+
* Whole-record mutations must stop if their lock expired rather than overwrite
|
|
443
|
+
* state committed by a newer owner.
|
|
444
|
+
*/
|
|
445
|
+
async function fenceLock(state, lock, ttlMs = MUTATION_LOCK_TTL_MS) {
|
|
446
|
+
if (!await state.extendLock(lock, ttlMs)) throw new Error(`Lock ownership was lost before write for ${lock.threadId}`);
|
|
447
|
+
}
|
|
448
|
+
// src/chat/state/adapter.ts
|
|
449
|
+
const ACTIVE_LOCK_HEARTBEAT_MS = 3e4;
|
|
450
|
+
const REDIS_STATE_KEY_PREFIX = "chat-sdk";
|
|
451
|
+
let stateAdapter;
|
|
452
|
+
let redisStateAdapter;
|
|
453
|
+
/** Lazily connect state operations, including queued-adapter lock heartbeats. */
|
|
454
|
+
function createConnectingStateAdapter(base) {
|
|
455
|
+
const connected = async (operation) => {
|
|
456
|
+
await base.connect();
|
|
457
|
+
return await operation();
|
|
458
|
+
};
|
|
459
|
+
return {
|
|
460
|
+
appendToList: (key, value, options) => connected(() => base.appendToList(key, value, options)),
|
|
461
|
+
connect: () => base.connect(),
|
|
462
|
+
disconnect: () => base.disconnect(),
|
|
463
|
+
subscribe: (threadId) => connected(() => base.subscribe(threadId)),
|
|
464
|
+
unsubscribe: (threadId) => connected(() => base.unsubscribe(threadId)),
|
|
465
|
+
isSubscribed: (threadId) => connected(() => base.isSubscribed(threadId)),
|
|
466
|
+
acquireLock: (threadId, ttlMs) => connected(() => base.acquireLock(threadId, ttlMs)),
|
|
467
|
+
releaseLock: (lock) => connected(() => base.releaseLock(lock)),
|
|
468
|
+
extendLock: (lock, ttlMs) => connected(() => base.extendLock(lock, ttlMs)),
|
|
469
|
+
forceReleaseLock: (threadId) => connected(() => base.forceReleaseLock(threadId)),
|
|
470
|
+
enqueue: (threadId, entry, maxSize) => connected(() => base.enqueue(threadId, entry, maxSize)),
|
|
471
|
+
dequeue: (threadId) => connected(() => base.dequeue(threadId)),
|
|
472
|
+
queueDepth: (threadId) => connected(() => base.queueDepth(threadId)),
|
|
473
|
+
get: (key) => connected(() => base.get(key)),
|
|
474
|
+
getList: (key) => connected(() => base.getList(key)),
|
|
475
|
+
set: (key, value, ttlMs) => connected(() => base.set(key, value, ttlMs)),
|
|
476
|
+
setIfNotExists: (key, value, ttlMs) => connected(() => base.setIfNotExists(key, value, ttlMs)),
|
|
477
|
+
delete: (key) => connected(() => base.delete(key))
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function createPrefixedStateAdapter(base, prefix) {
|
|
481
|
+
const prefixed = (value) => `${prefix}:${value}`;
|
|
482
|
+
const unprefixed = (value) => value.startsWith(`${prefix}:`) ? value.slice(prefix.length + 1) : value;
|
|
483
|
+
const prefixLock = (lock) => ({
|
|
484
|
+
...lock,
|
|
485
|
+
threadId: prefixed(lock.threadId)
|
|
486
|
+
});
|
|
487
|
+
const unprefixLock = (lock) => ({
|
|
488
|
+
...lock,
|
|
489
|
+
threadId: unprefixed(lock.threadId)
|
|
490
|
+
});
|
|
491
|
+
return {
|
|
492
|
+
appendToList: (key, value, options) => base.appendToList(prefixed(key), value, options),
|
|
493
|
+
connect: () => base.connect(),
|
|
494
|
+
disconnect: () => base.disconnect(),
|
|
495
|
+
subscribe: (threadId) => base.subscribe(prefixed(threadId)),
|
|
496
|
+
unsubscribe: (threadId) => base.unsubscribe(prefixed(threadId)),
|
|
497
|
+
isSubscribed: (threadId) => base.isSubscribed(prefixed(threadId)),
|
|
498
|
+
acquireLock: async (threadId, ttlMs) => {
|
|
499
|
+
const lock = await base.acquireLock(prefixed(threadId), ttlMs);
|
|
500
|
+
return lock ? unprefixLock(lock) : null;
|
|
501
|
+
},
|
|
502
|
+
releaseLock: (lock) => base.releaseLock(prefixLock(lock)),
|
|
503
|
+
extendLock: async (lock, ttlMs) => {
|
|
504
|
+
const prefixedLock = prefixLock(lock);
|
|
505
|
+
const extended = await base.extendLock(prefixedLock, ttlMs);
|
|
506
|
+
if (extended) lock.expiresAt = prefixedLock.expiresAt;
|
|
507
|
+
return extended;
|
|
508
|
+
},
|
|
509
|
+
forceReleaseLock: (threadId) => base.forceReleaseLock(prefixed(threadId)),
|
|
510
|
+
enqueue: (threadId, entry, maxSize) => base.enqueue(prefixed(threadId), entry, maxSize),
|
|
511
|
+
dequeue: (threadId) => base.dequeue(prefixed(threadId)),
|
|
512
|
+
queueDepth: (threadId) => base.queueDepth(prefixed(threadId)),
|
|
513
|
+
get: (key) => base.get(prefixed(key)),
|
|
514
|
+
getList: (key) => base.getList(prefixed(key)),
|
|
515
|
+
set: (key, value, ttlMs) => base.set(prefixed(key), value, ttlMs),
|
|
516
|
+
setIfNotExists: (key, value, ttlMs) => base.setIfNotExists(prefixed(key), value, ttlMs),
|
|
517
|
+
delete: (key) => base.delete(prefixed(key))
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
function createQueuedStateAdapter(base, options) {
|
|
521
|
+
const heartbeats = /* @__PURE__ */ new Map();
|
|
522
|
+
const shouldHeartbeatLock = (ttlMs) => ttlMs === ACTIVE_LOCK_TTL_MS;
|
|
523
|
+
const heartbeatKey = (lock) => `${lock.threadId}:${lock.token}`;
|
|
524
|
+
const stopHeartbeatByKey = (key) => {
|
|
525
|
+
const heartbeat = heartbeats.get(key);
|
|
526
|
+
if (!heartbeat) return;
|
|
527
|
+
clearInterval(heartbeat.timer);
|
|
528
|
+
heartbeats.delete(key);
|
|
529
|
+
};
|
|
530
|
+
const stopHeartbeat = (lock) => {
|
|
531
|
+
stopHeartbeatByKey(heartbeatKey(lock));
|
|
532
|
+
};
|
|
533
|
+
const stopHeartbeatsForThread = (threadId) => {
|
|
534
|
+
for (const [key, heartbeat] of heartbeats) if (heartbeat.lock.threadId === threadId) stopHeartbeatByKey(key);
|
|
535
|
+
};
|
|
536
|
+
const stopAllHeartbeats = () => {
|
|
537
|
+
for (const key of heartbeats.keys()) stopHeartbeatByKey(key);
|
|
538
|
+
};
|
|
539
|
+
const runHeartbeat = async (key) => {
|
|
540
|
+
const heartbeat = heartbeats.get(key);
|
|
541
|
+
if (!heartbeat || heartbeat.inFlight) return;
|
|
542
|
+
heartbeat.inFlight = true;
|
|
543
|
+
try {
|
|
544
|
+
if (Date.now() - heartbeat.startedAtMs >= options.activeLockMaxAgeMs) {
|
|
545
|
+
stopHeartbeatByKey(key);
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (!await base.extendLock(heartbeat.lock, heartbeat.ttlMs)) {
|
|
549
|
+
stopHeartbeatByKey(key);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
heartbeat.lock.expiresAt = Date.now() + heartbeat.ttlMs;
|
|
553
|
+
} catch {} finally {
|
|
554
|
+
const current = heartbeats.get(key);
|
|
555
|
+
if (current === heartbeat) current.inFlight = false;
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
const startOrUpdateHeartbeat = (lock, ttlMs) => {
|
|
559
|
+
const key = heartbeatKey(lock);
|
|
560
|
+
const existing = heartbeats.get(key);
|
|
561
|
+
if (existing) {
|
|
562
|
+
existing.ttlMs = ttlMs;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const timer = setInterval(() => {
|
|
566
|
+
runHeartbeat(key);
|
|
567
|
+
}, ACTIVE_LOCK_HEARTBEAT_MS);
|
|
568
|
+
timer.unref?.();
|
|
569
|
+
heartbeats.set(key, {
|
|
570
|
+
inFlight: false,
|
|
571
|
+
lock,
|
|
572
|
+
startedAtMs: Date.now(),
|
|
573
|
+
timer,
|
|
574
|
+
ttlMs
|
|
575
|
+
});
|
|
576
|
+
};
|
|
577
|
+
const acquireLock = async (threadId, ttlMs) => {
|
|
578
|
+
const lock = await base.acquireLock(threadId, ttlMs);
|
|
579
|
+
if (lock && shouldHeartbeatLock(ttlMs)) startOrUpdateHeartbeat(lock, ttlMs);
|
|
580
|
+
return lock;
|
|
581
|
+
};
|
|
582
|
+
return {
|
|
583
|
+
appendToList: (key, value, options) => base.appendToList(key, value, options),
|
|
584
|
+
connect: () => base.connect(),
|
|
585
|
+
disconnect: async () => {
|
|
586
|
+
stopAllHeartbeats();
|
|
587
|
+
await base.disconnect();
|
|
588
|
+
},
|
|
589
|
+
subscribe: (threadId) => base.subscribe(threadId),
|
|
590
|
+
unsubscribe: (threadId) => base.unsubscribe(threadId),
|
|
591
|
+
isSubscribed: (threadId) => base.isSubscribed(threadId),
|
|
592
|
+
acquireLock,
|
|
593
|
+
releaseLock: async (lock) => {
|
|
594
|
+
stopHeartbeat(lock);
|
|
595
|
+
await base.releaseLock(lock);
|
|
596
|
+
},
|
|
597
|
+
extendLock: async (lock, ttlMs) => {
|
|
598
|
+
const extended = await base.extendLock(lock, ttlMs);
|
|
599
|
+
if (extended) {
|
|
600
|
+
lock.expiresAt = Date.now() + ttlMs;
|
|
601
|
+
if (shouldHeartbeatLock(ttlMs)) startOrUpdateHeartbeat(lock, ttlMs);
|
|
602
|
+
else stopHeartbeat(lock);
|
|
603
|
+
} else stopHeartbeat(lock);
|
|
604
|
+
return extended;
|
|
605
|
+
},
|
|
606
|
+
forceReleaseLock: async (threadId) => {
|
|
607
|
+
stopHeartbeatsForThread(threadId);
|
|
608
|
+
await base.forceReleaseLock(threadId);
|
|
609
|
+
},
|
|
610
|
+
enqueue: (threadId, entry, maxSize) => base.enqueue(threadId, entry, maxSize),
|
|
611
|
+
dequeue: (threadId) => base.dequeue(threadId),
|
|
612
|
+
queueDepth: (threadId) => base.queueDepth(threadId),
|
|
613
|
+
get: (key) => base.get(key),
|
|
614
|
+
getList: (key) => base.getList(key),
|
|
615
|
+
set: (key, value, ttlMs) => base.set(key, value, ttlMs),
|
|
616
|
+
setIfNotExists: (key, value, ttlMs) => base.setIfNotExists(key, value, ttlMs),
|
|
617
|
+
delete: (key) => base.delete(key)
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
function withOptionalPrefix(base, prefix) {
|
|
621
|
+
return prefix ? createPrefixedStateAdapter(base, prefix) : base;
|
|
622
|
+
}
|
|
623
|
+
function createStateAdapter() {
|
|
624
|
+
const config = getChatConfig();
|
|
625
|
+
const activeLockMaxAgeMs = config.bot.turnTimeoutMs + ACTIVE_LOCK_TTL_MS;
|
|
626
|
+
if (config.state.adapter === "memory") {
|
|
627
|
+
redisStateAdapter = void 0;
|
|
628
|
+
return createQueuedStateAdapter(createConnectingStateAdapter(withOptionalPrefix(createMemoryState(), config.state.keyPrefix)), { activeLockMaxAgeMs });
|
|
629
|
+
}
|
|
630
|
+
if (!config.state.redisUrl) throw new Error("REDIS_URL is required for durable Slack thread state");
|
|
631
|
+
const redisState = createRedisState({
|
|
632
|
+
keyPrefix: REDIS_STATE_KEY_PREFIX,
|
|
633
|
+
url: config.state.redisUrl
|
|
634
|
+
});
|
|
635
|
+
redisStateAdapter = redisState;
|
|
636
|
+
return createQueuedStateAdapter(createConnectingStateAdapter(withOptionalPrefix(redisState, config.state.keyPrefix)), { activeLockMaxAgeMs });
|
|
637
|
+
}
|
|
638
|
+
function getOptionalRedisStateAdapter() {
|
|
639
|
+
getStateAdapter();
|
|
640
|
+
return redisStateAdapter;
|
|
641
|
+
}
|
|
642
|
+
async function getConnectedStateContext() {
|
|
643
|
+
const adapter = getStateAdapter();
|
|
644
|
+
await adapter.connect();
|
|
645
|
+
return {
|
|
646
|
+
redisStateAdapter: getOptionalRedisStateAdapter(),
|
|
647
|
+
stateAdapter: adapter
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
/** Return the Redis adapter only when the caller is using the default state adapter. */
|
|
651
|
+
async function getDefaultRedisStateAdapterFor(adapter) {
|
|
652
|
+
if (adapter !== stateAdapter) return;
|
|
653
|
+
const context = await getConnectedStateContext();
|
|
654
|
+
return context.stateAdapter === adapter ? context.redisStateAdapter : void 0;
|
|
655
|
+
}
|
|
656
|
+
/** The Redis key that the default Redis adapter uses for one state value key. */
|
|
657
|
+
function redisStateKey(key) {
|
|
658
|
+
const prefix = getChatConfig().state.keyPrefix;
|
|
659
|
+
return `${REDIS_STATE_KEY_PREFIX}:cache:${prefix ? `${prefix}:` : ""}${key}`;
|
|
660
|
+
}
|
|
661
|
+
/** Read state values in one Redis round trip. Other adapters read each key. */
|
|
662
|
+
async function getStateValues(state, keys) {
|
|
663
|
+
if (keys.length === 0) return [];
|
|
664
|
+
const redis = await getDefaultRedisStateAdapterFor(state);
|
|
665
|
+
if (!redis) return await Promise.all(keys.map((key) => state.get(key)));
|
|
666
|
+
return (await redis.getClient().mGet(keys.map(redisStateKey))).map((value) => {
|
|
667
|
+
if (value === null) return null;
|
|
668
|
+
try {
|
|
669
|
+
return JSON.parse(value);
|
|
670
|
+
} catch {
|
|
671
|
+
return value;
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
/** Write state values with one TTL in one Redis round trip. */
|
|
676
|
+
async function setStateValues(state, entries, ttlMs) {
|
|
677
|
+
if (entries.length === 0) return;
|
|
678
|
+
const redis = await getDefaultRedisStateAdapterFor(state);
|
|
679
|
+
if (!redis) {
|
|
680
|
+
await Promise.all(entries.map(({ key, value }) => state.set(key, value, ttlMs)));
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
const pipeline = redis.getClient().multi();
|
|
684
|
+
for (const { key, value } of entries) pipeline.set(redisStateKey(key), JSON.stringify(value), { PX: ttlMs });
|
|
685
|
+
await pipeline.execAsPipeline();
|
|
686
|
+
}
|
|
687
|
+
function getStateAdapter() {
|
|
688
|
+
if (!stateAdapter) stateAdapter = createStateAdapter();
|
|
689
|
+
return stateAdapter;
|
|
690
|
+
}
|
|
691
|
+
async function disconnectStateAdapter() {
|
|
692
|
+
if (!stateAdapter) return;
|
|
693
|
+
try {
|
|
694
|
+
await stateAdapter.disconnect();
|
|
695
|
+
} finally {
|
|
696
|
+
stateAdapter = void 0;
|
|
697
|
+
redisStateAdapter = void 0;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
400
700
|
// src/chat/state/cache.ts
|
|
401
701
|
const MAX_CACHE_KEY_LENGTH = 512;
|
|
402
702
|
const LOAD_WAIT_MS = 1e4;
|
|
@@ -1095,6 +1395,15 @@ function turnBehavior(args) {
|
|
|
1095
1395
|
if (!args.personInput) return AGENT_IN_TASK;
|
|
1096
1396
|
throw new Error("A task Conversation cannot have a person's input");
|
|
1097
1397
|
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Return the Turn tools of one Prompt mode. A person's Turn in a Thread also
|
|
1400
|
+
* uses the `conversation` mode with no agent tools, so this is the widest set.
|
|
1401
|
+
*/
|
|
1402
|
+
function promptModeTurnTools(mode) {
|
|
1403
|
+
if (mode === "automation") return AUTOMATION_RUN.tools;
|
|
1404
|
+
if (mode === "child_agent") return AGENT_IN_TASK.tools;
|
|
1405
|
+
return ROOT.tools;
|
|
1406
|
+
}
|
|
1098
1407
|
/** Return whether a Conversation of this kind has no parent. */
|
|
1099
1408
|
function isTopLevelKind(kind) {
|
|
1100
1409
|
return kind === "root" || kind === "automation";
|
|
@@ -1628,14 +1937,14 @@ function isRecord(value) {
|
|
|
1628
1937
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1629
1938
|
}
|
|
1630
1939
|
function readAuthor(meta) {
|
|
1631
|
-
if (!isRecord(meta) || !isRecord(meta
|
|
1632
|
-
const author = meta
|
|
1940
|
+
if (!isRecord(meta) || !isRecord(meta["author"])) return {};
|
|
1941
|
+
const author = meta["author"];
|
|
1633
1942
|
return {
|
|
1634
|
-
...typeof author
|
|
1635
|
-
...typeof author
|
|
1636
|
-
...typeof author
|
|
1637
|
-
...typeof author
|
|
1638
|
-
...typeof author
|
|
1943
|
+
...typeof author["email"] === "string" ? { email: author["email"] } : void 0,
|
|
1944
|
+
...typeof author["fullName"] === "string" ? { fullName: author["fullName"] } : void 0,
|
|
1945
|
+
...typeof author["isBot"] === "boolean" ? { isBot: author["isBot"] } : void 0,
|
|
1946
|
+
...typeof author["userId"] === "string" ? { userId: author["userId"] } : void 0,
|
|
1947
|
+
...typeof author["userName"] === "string" ? { userName: author["userName"] } : void 0
|
|
1639
1948
|
};
|
|
1640
1949
|
}
|
|
1641
1950
|
/** Read the Slack workspace that owns a conversation, when it has one. */
|
|
@@ -1846,7 +2155,7 @@ const HUMAN_INSTRUCTION_PLATFORMS = /* @__PURE__ */ new Set([
|
|
|
1846
2155
|
* mentions and DMs, always address Junior.
|
|
1847
2156
|
*/
|
|
1848
2157
|
function eventAddressesJunior(data) {
|
|
1849
|
-
return data.type === "message" && data.meta?.explicitMention !== false;
|
|
2158
|
+
return data.type === "message" && data.meta?.["explicitMention"] !== false;
|
|
1850
2159
|
}
|
|
1851
2160
|
/**
|
|
1852
2161
|
* Whether one event should restore an archived conversation to the feed.
|
|
@@ -1866,8 +2175,8 @@ function eventUnarchivesConversation(data) {
|
|
|
1866
2175
|
if (data.role !== "user") return false;
|
|
1867
2176
|
const meta = data.meta;
|
|
1868
2177
|
if (!meta) return true;
|
|
1869
|
-
if (typeof meta
|
|
1870
|
-
const author = meta
|
|
2178
|
+
if (typeof meta["eventType"] === "string" && meta["eventType"].length > 0) return false;
|
|
2179
|
+
const author = meta["author"];
|
|
1871
2180
|
if (author && typeof author === "object" && !Array.isArray(author) && author.isBot === true) return false;
|
|
1872
2181
|
return true;
|
|
1873
2182
|
}
|
|
@@ -2264,4 +2573,4 @@ async function closeDb() {
|
|
|
2264
2573
|
current = void 0;
|
|
2265
2574
|
await previous?.db.close();
|
|
2266
2575
|
}
|
|
2267
|
-
export {
|
|
2576
|
+
export { fenceLock as $, setFirstConversationLocation as A, recordGoogleSignIn as B, isPersonInput as C, turnBehavior as D, promptModeTurnTools as E, saveActorAvatar as F, createCache as G, upsertLinkedIdentity as H, deleteProviderIdentityForSlackUser as I, getStateAdapter as J, disconnectStateAdapter as K, deleteProviderIdentityForUser as L, SYSTEM_IDENTITY_ID as M, findActorIdentityId as N, conversationKindFromRow as O, resolveActorIdentityId as P, acquireActiveLock as Q, findUserByVerifiedEmails as R, deliversFinalText as S, postsRunNotices as T, clearCachedUser as U, saveUserTimezone as V, readCachedUserByEmail as W, setStateValues as X, getStateValues as Y, MUTATION_LOCK_TTL_MS as Z, loadConversationSlackTenantIds as _, sameDestination as _t, getConversationStore as a, agentTurnCostUsd as at, createSqlStore as b, hasAnnotationKey as c, hasAgentTurnUsage as ct, eventFromRow as d, conversationDetailTouch as dt, withLock as et, withConversationEventLock as f, nextDetailVersion as ft, setArchivedAt as g, requireSlackDestination as gt, readConversationTrees as h, parseDestination as ht, getConversationMessageSearchStore as i, addAgentTurnUsage as it, startLocationThread as j, locationFromRow as k, treeHasAnnotationKey as l, resolveRootConversationId as lt, conversationDescendants as m, createSlackDestination as mt, db_exports as n, getConversationIdByProviderConversation as nt, getDb as o, agentTurnTotalTokens as ot, conversationAncestors as p, touchConversationDetail as pt, getDefaultRedisStateAdapterFor as q, getConversationEventStore as r, parseSessionSource as rt, getSqlExecutor as s, agentTurnUsageSchema as st, closeDb as t, claimProviderConversation as tt, createSqlConversationEventStore as u, rootConversationIsArchived as ut, lastMessageAtSql as v, isTopLevelKind as w, withConversationMutationLock as x, userMessageQueries as y, readUserTimezone as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./schema-
|
|
1
|
+
import "./schema-DHMOaRzC.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import "drizzle-orm";
|
|
4
4
|
import { Destination, Source, locationSchema } from "@sentry/junior-plugin-api";
|
|
@@ -67,11 +67,11 @@ interface ConversationRunMetrics {
|
|
|
67
67
|
usage?: AgentTurnUsage;
|
|
68
68
|
}
|
|
69
69
|
interface ConversationExecution {
|
|
70
|
-
lastCheckpointAtMs?: number;
|
|
71
|
-
lastEnqueuedAtMs?: number;
|
|
72
|
-
runId?: string;
|
|
70
|
+
lastCheckpointAtMs?: number | undefined;
|
|
71
|
+
lastEnqueuedAtMs?: number | undefined;
|
|
72
|
+
runId?: string | undefined;
|
|
73
73
|
status: ConversationStatus;
|
|
74
|
-
updatedAtMs?: number;
|
|
74
|
+
updatedAtMs?: number | undefined;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Durable Conversation owned by Junior.
|
|
@@ -86,10 +86,10 @@ interface ConversationExecution {
|
|
|
86
86
|
* Their field TODOs state when each legacy copy can be removed.
|
|
87
87
|
*/
|
|
88
88
|
interface Conversation {
|
|
89
|
-
channelName?: string;
|
|
89
|
+
channelName?: string | undefined;
|
|
90
90
|
conversationId: string;
|
|
91
91
|
createdAtMs: number;
|
|
92
|
-
destination?: Destination;
|
|
92
|
+
destination?: Destination | undefined;
|
|
93
93
|
execution: ConversationExecution;
|
|
94
94
|
/** Metrics of the latest Run that wrote metrics. */
|
|
95
95
|
executionMetrics?: ConversationRunMetrics & {
|
|
@@ -107,27 +107,27 @@ interface Conversation {
|
|
|
107
107
|
archivedAtMs?: number;
|
|
108
108
|
/** Optional provider coordinates associated with this Conversation. */
|
|
109
109
|
location?: Location;
|
|
110
|
-
actor?: StoredSlackActor;
|
|
110
|
+
actor?: StoredSlackActor | undefined;
|
|
111
111
|
schemaVersion: 1;
|
|
112
|
-
source?: ConversationSource;
|
|
112
|
+
source?: ConversationSource | undefined;
|
|
113
113
|
/**
|
|
114
114
|
* Structured inbound Source locator for this conversation session.
|
|
115
115
|
* Session-stable (threaded Slack keeps threadTs; channel-level turns omit
|
|
116
116
|
* it; never stores per-message ts). Set-once.
|
|
117
117
|
*/
|
|
118
118
|
sessionSource?: SessionSource;
|
|
119
|
-
title?: string;
|
|
119
|
+
title?: string | undefined;
|
|
120
120
|
updatedAtMs: number;
|
|
121
121
|
/**
|
|
122
122
|
* When retention purged this conversation's content. Set means messages and
|
|
123
123
|
* events were deleted wholesale; reporting presents the transcript as expired
|
|
124
124
|
* rather than privacy-redacted (`../../../../../policies/data-redaction.md`).
|
|
125
125
|
*/
|
|
126
|
-
transcriptPurgedAtMs?: number;
|
|
126
|
+
transcriptPurgedAtMs?: number | undefined;
|
|
127
127
|
/** When a person stopped this Conversation. Unset when it is not stopped. */
|
|
128
|
-
stoppedAtMs?: number;
|
|
128
|
+
stoppedAtMs?: number | undefined;
|
|
129
129
|
/** Set while a root's Event Turn replies stay out of its Location. */
|
|
130
|
-
deliveryPausedAtMs?: number;
|
|
130
|
+
deliveryPausedAtMs?: number | undefined;
|
|
131
131
|
/** Confirmed Conversation visibility. Undefined means no confirmation exists. */
|
|
132
132
|
visibility?: ConversationPrivacy;
|
|
133
133
|
}
|
|
@@ -212,12 +212,12 @@ interface ConversationStore {
|
|
|
212
212
|
} | undefined>;
|
|
213
213
|
recordActivity(args: {
|
|
214
214
|
activityAtMs?: number;
|
|
215
|
-
channelName?: string;
|
|
215
|
+
channelName?: string | undefined;
|
|
216
216
|
conversationId: string;
|
|
217
|
-
destination?: Destination;
|
|
217
|
+
destination?: Destination | undefined;
|
|
218
218
|
nowMs?: number;
|
|
219
|
-
actor?: StoredSlackActor;
|
|
220
|
-
source?: ConversationSource;
|
|
219
|
+
actor?: StoredSlackActor | undefined;
|
|
220
|
+
source?: ConversationSource | undefined;
|
|
221
221
|
/** Source normalized to a stable session locator; set-once when absent. */
|
|
222
222
|
sessionSource?: Source;
|
|
223
223
|
title?: string;
|
|
@@ -231,7 +231,7 @@ interface ConversationStore {
|
|
|
231
231
|
* replaces the visibility of the shared Destination row. Omit it for saved
|
|
232
232
|
* values, such as visibility captured when an Automation was created.
|
|
233
233
|
*/
|
|
234
|
-
visibility?: ConversationPrivacy;
|
|
234
|
+
visibility?: ConversationPrivacy | undefined;
|
|
235
235
|
}): Promise<void>;
|
|
236
236
|
/**
|
|
237
237
|
* Store execution state and one Run's metrics.
|
|
@@ -239,25 +239,25 @@ interface ConversationStore {
|
|
|
239
239
|
*/
|
|
240
240
|
recordExecution(args: {
|
|
241
241
|
/** Identity of the Turn Actor. Its metric rows record it. */
|
|
242
|
-
actorIdentityId?: string;
|
|
243
|
-
channelName?: string;
|
|
242
|
+
actorIdentityId?: string | undefined;
|
|
243
|
+
channelName?: string | undefined;
|
|
244
244
|
conversationId: string;
|
|
245
245
|
/** When this Run started. */
|
|
246
246
|
createdAtMs: number;
|
|
247
|
-
destination?: Destination;
|
|
247
|
+
destination?: Destination | undefined;
|
|
248
248
|
execution: ConversationExecution;
|
|
249
249
|
lastActivityAtMs: number;
|
|
250
250
|
metrics: ConversationRunMetrics | null;
|
|
251
|
-
actor?: StoredSlackActor;
|
|
252
|
-
source?: ConversationSource;
|
|
253
|
-
title?: string;
|
|
251
|
+
actor?: StoredSlackActor | undefined;
|
|
252
|
+
source?: ConversationSource | undefined;
|
|
253
|
+
title?: string | undefined;
|
|
254
254
|
updatedAtMs: number;
|
|
255
255
|
/**
|
|
256
256
|
* Current visibility from its owner, such as a Slack event channel type. It
|
|
257
257
|
* replaces the visibility of the shared Destination row. Omit it for saved
|
|
258
258
|
* values, such as visibility captured when an Automation was created.
|
|
259
259
|
*/
|
|
260
|
-
visibility?: ConversationPrivacy;
|
|
260
|
+
visibility?: ConversationPrivacy | undefined;
|
|
261
261
|
}): Promise<void>;
|
|
262
262
|
listByActivity(args?: {
|
|
263
263
|
limit?: number;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./
|
|
3
|
-
import
|
|
1
|
+
import { h as logWarn, p as logException } from "./logging-DiyqRLBx.js";
|
|
2
|
+
import { _ as withScope } from "./sentry-CPbZjomA.js";
|
|
3
|
+
import "./config-oGM7KA9M.js";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
5
|
import { sql } from "drizzle-orm";
|
|
6
|
-
import { bigint, boolean, check, date, doublePrecision, foreignKey, index, integer, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
7
|
-
import { Pool, neon } from "@neondatabase/serverless";
|
|
6
|
+
import { bigint, boolean, check, customType, date, doublePrecision, foreignKey, index, integer, jsonb, pgTable, primaryKey, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
7
|
+
import { Pool as Pool$1, neon } from "@neondatabase/serverless";
|
|
8
8
|
import { drizzle } from "drizzle-orm/neon-serverless";
|
|
9
9
|
import { Agent } from "undici";
|
|
10
10
|
import { readMigrationFiles } from "drizzle-orm/migrator";
|
|
@@ -62,6 +62,11 @@ const juniorUsers = pgTable("junior_users", {
|
|
|
62
62
|
autoArchiveDefault: boolean("auto_archive_default").notNull().default(false),
|
|
63
63
|
/** Hours done work and the conversation stay quiet before auto-archive. */
|
|
64
64
|
autoArchiveGraceHours: integer("auto_archive_grace_hours").notNull().default(24),
|
|
65
|
+
/**
|
|
66
|
+
* Small per-user choices, such as an experiment opt-in, that can come
|
|
67
|
+
* and go without a migration. `api/user-settings.ts` owns the keys.
|
|
68
|
+
*/
|
|
69
|
+
preferences: jsonb("preferences").$type().notNull().default({}),
|
|
65
70
|
createdAt: timestamptz("created_at").notNull(),
|
|
66
71
|
updatedAt: timestamptz("updated_at").notNull()
|
|
67
72
|
}, (table) => [uniqueIndex("junior_users_primary_email_normalized_uidx").on(table.primaryEmailNormalized)]);
|
|
@@ -241,6 +246,7 @@ const juniorCodeChanges = pgTable("junior_code_changes", {
|
|
|
241
246
|
index("junior_code_changes_opened_at_idx").on(table.openedAt),
|
|
242
247
|
index("junior_code_changes_merged_at_idx").on(table.mergedAt),
|
|
243
248
|
index("junior_code_changes_closed_at_idx").on(table.closedAt),
|
|
249
|
+
index("junior_code_changes_repository_state_idx").on(table.repositoryId, table.state, table.updatedAt.desc()),
|
|
244
250
|
index("junior_code_changes_open_idx").on(table.id).where(sql`${table.state} = 'open'`)
|
|
245
251
|
]);
|
|
246
252
|
// src/db/schema/conversation-annotations.ts
|
|
@@ -392,6 +398,40 @@ const juniorConversationBriefs = pgTable("junior_conversation_briefs", {
|
|
|
392
398
|
index("junior_conversation_briefs_conversation_version_idx").on(table.conversationId, table.version.desc()),
|
|
393
399
|
index("junior_conversation_briefs_search_idx").using("gin", sql`to_tsvector('english', ${table.searchText})`)
|
|
394
400
|
]);
|
|
401
|
+
// src/db/schema/conversation-embeddings.ts
|
|
402
|
+
/**
|
|
403
|
+
* pgvector column without a fixed size, so a change of embedding model needs
|
|
404
|
+
* no migration. The dimensions column records the size of each row.
|
|
405
|
+
*/
|
|
406
|
+
const vector = customType({
|
|
407
|
+
dataType() {
|
|
408
|
+
return "vector";
|
|
409
|
+
},
|
|
410
|
+
toDriver(value) {
|
|
411
|
+
return JSON.stringify(value);
|
|
412
|
+
},
|
|
413
|
+
fromDriver(value) {
|
|
414
|
+
return value.slice(1, -1).split(",").map(Number);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
/**
|
|
418
|
+
* One embedding per Conversation, for semantic search. Its text is the latest
|
|
419
|
+
* Brief. A derived index: the next Brief replaces the row, and deleting that
|
|
420
|
+
* Brief row deletes it.
|
|
421
|
+
*/
|
|
422
|
+
const juniorConversationEmbeddings = pgTable("junior_conversation_embeddings", {
|
|
423
|
+
conversationId: text("conversation_id").primaryKey(),
|
|
424
|
+
briefVersion: integer("brief_version").notNull(),
|
|
425
|
+
provider: text("provider").notNull(),
|
|
426
|
+
model: text("model").notNull(),
|
|
427
|
+
dimensions: integer("dimensions").notNull(),
|
|
428
|
+
embedding: vector("embedding").notNull(),
|
|
429
|
+
createdAt: timestamptz("created_at").defaultNow().notNull()
|
|
430
|
+
}, (table) => [foreignKey({
|
|
431
|
+
name: "junior_conversation_embeddings_brief_fk",
|
|
432
|
+
columns: [table.conversationId, table.briefVersion],
|
|
433
|
+
foreignColumns: [juniorConversationBriefs.conversationId, juniorConversationBriefs.version]
|
|
434
|
+
}).onDelete("cascade"), check("junior_conversation_embeddings_dimensions_check", sql`vector_dims(${table.embedding}) = ${table.dimensions}`)]);
|
|
395
435
|
// src/db/schema/conversation-bindings.ts
|
|
396
436
|
/** Provider conversation coordinates bound to Junior's opaque durable conversation id. */
|
|
397
437
|
const juniorConversationBindings = pgTable("junior_conversation_bindings", {
|
|
@@ -792,6 +832,7 @@ const juniorSqlSchema = {
|
|
|
792
832
|
juniorAgentInvocations,
|
|
793
833
|
juniorConversationEvents,
|
|
794
834
|
juniorConversationMetrics,
|
|
835
|
+
juniorConversationEmbeddings,
|
|
795
836
|
juniorConversationBriefs,
|
|
796
837
|
juniorConversationBindings,
|
|
797
838
|
juniorConversationParticipants,
|
|
@@ -953,7 +994,7 @@ function warnWebSocketFailure(name, error, failure) {
|
|
|
953
994
|
* proxy's cached backend connection, so the batch skips that handshake. The
|
|
954
995
|
* warm path stays on WebSocket. `connect()` and transactions are unchanged.
|
|
955
996
|
*/
|
|
956
|
-
var OverflowPool = class extends Pool {
|
|
997
|
+
var OverflowPool = class extends Pool$1 {
|
|
957
998
|
pendingAcquires = 0;
|
|
958
999
|
webSocketOnly = new AsyncLocalStorage();
|
|
959
1000
|
sql;
|
|
@@ -1025,7 +1066,7 @@ var OverflowPool = class extends Pool {
|
|
|
1025
1066
|
this.connect((error, client) => {
|
|
1026
1067
|
this.pendingAcquires--;
|
|
1027
1068
|
if (client) resolve(client);
|
|
1028
|
-
else reject(error);
|
|
1069
|
+
else reject(error ?? /* @__PURE__ */ new Error("pg pool returned no client"));
|
|
1029
1070
|
});
|
|
1030
1071
|
});
|
|
1031
1072
|
}
|
|
@@ -1165,7 +1206,7 @@ function createNeonJuniorSqlExecutor(args) {
|
|
|
1165
1206
|
return new NeonExecutor(pool, dispatcher);
|
|
1166
1207
|
}
|
|
1167
1208
|
// src/db/postgres.ts
|
|
1168
|
-
const { Pool
|
|
1209
|
+
const { Pool } = pg;
|
|
1169
1210
|
var PostgresExecutor = class {
|
|
1170
1211
|
transactionClient = new AsyncLocalStorage();
|
|
1171
1212
|
savepointId = 0;
|
|
@@ -1272,7 +1313,7 @@ var PostgresExecutor = class {
|
|
|
1272
1313
|
};
|
|
1273
1314
|
/** Create the shared Node Postgres-backed Junior SQL executor. */
|
|
1274
1315
|
function createPostgresJuniorSqlExecutor(args) {
|
|
1275
|
-
const pool = new Pool
|
|
1316
|
+
const pool = new Pool({
|
|
1276
1317
|
application_name: args.applicationName,
|
|
1277
1318
|
connectionString: args.connectionString,
|
|
1278
1319
|
max: 3,
|
|
@@ -1299,4 +1340,4 @@ function createJuniorSqlExecutor(args) {
|
|
|
1299
1340
|
statementTimeoutMs
|
|
1300
1341
|
});
|
|
1301
1342
|
}
|
|
1302
|
-
export {
|
|
1343
|
+
export { juniorAttachmentUploads as A, juniorConversationMetrics as C, juniorConversationAnnotations as D, juniorApiTokens as E, juniorDestinations as F, juniorArtifacts as I, juniorConversations as M, juniorIdentities as N, juniorCodeChanges as O, juniorUsers as P, CONVERSATION_METRICS as S, juniorConversationEvents as T, juniorConversationReadPositions as _, juniorPushSubscriptions as a, juniorConversationEmbeddings as b, juniorReviewItemSlackCards as c, juniorAutomationVersions as d, juniorAutomations as f, juniorAgentInvocations as g, juniorAgentBindings as h, juniorWorkspaces as i, juniorAttachments as j, juniorCodeRepositories as k, juniorReviewItems as l, juniorLocationConfigurations as m, juniorSnapshots as n, juniorReviewItemAssignees as o, juniorStats as p, juniorWorkspaceRepos as r, juniorReviewItemConversations as s, createJuniorSqlExecutor as t, juniorAutomationRuns as u, juniorConversationParticipants as v, isUserInstruction as w, juniorConversationBriefs as x, juniorConversationBindings as y };
|