@sentry/junior 0.131.0 → 0.133.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-M5V454P5.js → agent-hooks-5BUIXVIX.js} +9 -9
- package/dist/api/conversations/list.d.ts +13 -2
- package/dist/api/schema/task.d.ts +0 -3
- package/dist/api/schema.js +1 -1
- package/dist/api.js +24 -23
- package/dist/app.js +84 -37
- package/dist/{catalog-runtime-PI2IFWZ5.js → catalog-runtime-VGB3DWXZ.js} +5 -5
- package/dist/chat/config.d.ts +2 -0
- package/dist/chat/conversations/location.d.ts +10 -0
- package/dist/chat/conversations/projection.d.ts +3 -1
- package/dist/chat/conversations/sql/bindings.d.ts +13 -0
- package/dist/chat/conversations/sql/location.d.ts +9 -0
- package/dist/chat/conversations/sql/store.d.ts +3 -0
- package/dist/chat/conversations/store.d.ts +17 -0
- package/dist/chat/runtime/reply-executor.d.ts +1 -0
- package/dist/chat/runtime/slack-runtime.d.ts +2 -0
- package/dist/chat/scheduled-tasks/tool-support.d.ts +2 -5
- package/dist/chat/scheduled-tasks/tools/create.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/delete.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/list.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/run-now.d.ts +2 -2
- package/dist/chat/scheduled-tasks/tools/update.d.ts +3 -3
- package/dist/chat/scheduled-tasks/types.d.ts +1 -1
- package/dist/chat/slack/dispatch-turn.d.ts +1 -0
- package/dist/chat/slack/reply.d.ts +1 -1
- package/dist/{chunk-UYYSD255.js → chunk-5ZAZHLIW.js} +1 -1
- package/dist/{chunk-JKHK3LM2.js → chunk-AH5HTUYX.js} +1 -1
- package/dist/{chunk-HZ5EVSPV.js → chunk-ECUILEUX.js} +24 -15
- package/dist/{chunk-HSPYTFMD.js → chunk-EJRJWBKG.js} +1 -1
- package/dist/{chunk-TD2A27ET.js → chunk-FX6BLEDP.js} +1 -1
- package/dist/{chunk-7Y2OKB5K.js → chunk-HJ4KDO4N.js} +1 -1
- package/dist/{chunk-DRFI6CW3.js → chunk-HTGXUNEC.js} +7 -7
- package/dist/{chunk-SVX4JDOR.js → chunk-IKO5LFIU.js} +1 -1
- package/dist/{chunk-J4I2GVGH.js → chunk-IVTHTAVK.js} +2 -2
- package/dist/{chunk-APUL3Y63.js → chunk-JLN4XSPR.js} +1 -1
- package/dist/{chunk-ZMIO64MA.js → chunk-LDRO4OQ4.js} +19 -3
- package/dist/{chunk-5ONXE2GF.js → chunk-LNYNTR27.js} +305 -235
- package/dist/{chunk-BVKP37NE.js → chunk-QVEXYYFM.js} +1 -1
- package/dist/{chunk-KB2M27DL.js → chunk-QWGZ273D.js} +78 -36
- package/dist/{chunk-TRKWWIB3.js → chunk-T5FPIBU2.js} +21 -21
- package/dist/{chunk-XXGCQCFJ.js → chunk-TBVS7GBE.js} +4 -4
- package/dist/{chunk-XMDY52DJ.js → chunk-TLN54TOQ.js} +1 -1
- package/dist/{chunk-VMPL77IK.js → chunk-TU7P77FI.js} +36 -24
- package/dist/{chunk-NGJEC4MF.js → chunk-V365UVCU.js} +2 -2
- package/dist/{chunk-KWYCUXJX.js → chunk-VL7OYSHD.js} +1 -1
- package/dist/{chunk-D6ZMP3FC.js → chunk-VQA25AL4.js} +6 -6
- package/dist/{chunk-MLIJGLW5.js → chunk-WHEMUEXT.js} +5 -5
- package/dist/{chunk-7X62XOC4.js → chunk-XTQGVNM3.js} +54 -19
- package/dist/cli/chat.js +24 -24
- package/dist/cli/check.js +6 -6
- package/dist/cli/init.js +1 -0
- package/dist/cli/plugins.js +12 -12
- package/dist/cli/snapshot-create.js +9 -9
- package/dist/cli/upgrade.js +9 -8
- package/dist/db/executor.d.ts +2 -1
- package/dist/db/neon.d.ts +1 -0
- package/dist/db/postgres.d.ts +1 -0
- package/dist/db/schema/conversation-bindings.d.ts +110 -0
- package/dist/db/schema.d.ts +111 -1
- package/dist/{db-5P6K3ZCM.js → db-RICMPUFT.js} +7 -7
- package/dist/instrumentation.js +4 -4
- package/dist/nitro.js +2 -2
- package/dist/{oauth-callback-server-RIMCKQZX.js → oauth-callback-server-YFVS4SAX.js} +17 -17
- package/dist/{runner-CAD3BVML.js → runner-A3LVGZR6.js} +11 -11
- package/dist/{skills-WVPCTBUT.js → skills-P7Q6Z6PN.js} +6 -6
- package/dist/{validation-GLEXIFFI.js → validation-RYHOWBET.js} +6 -6
- package/dist/version.js +1 -1
- package/migrations/0017_drop_paused_scheduled_tasks.sql +19 -0
- package/migrations/0018_curvy_excalibur.sql +12 -0
- package/migrations/meta/0017_snapshot.json +1666 -0
- package/migrations/meta/0018_snapshot.json +1756 -0
- package/migrations/meta/_journal.json +15 -1
- package/package.json +5 -5
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createJuniorSqlExecutor,
|
|
3
|
+
juniorConversationBindings,
|
|
3
4
|
juniorConversationEvents,
|
|
4
5
|
juniorConversations,
|
|
5
6
|
juniorIdentities,
|
|
6
7
|
juniorUsers
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-QWGZ273D.js";
|
|
8
9
|
import {
|
|
9
10
|
TURN_REASONING_LEVELS,
|
|
10
11
|
getChatConfig,
|
|
11
12
|
modelProfileSchema
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-LDRO4OQ4.js";
|
|
13
14
|
import {
|
|
14
15
|
juniorDestinations
|
|
15
16
|
} from "./chunk-VFUK3X5B.js";
|
|
@@ -19,11 +20,11 @@ import {
|
|
|
19
20
|
} from "./chunk-F3B2YJ76.js";
|
|
20
21
|
import {
|
|
21
22
|
normalizeIdentityEmail
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-EJRJWBKG.js";
|
|
23
24
|
|
|
24
25
|
// src/chat/conversations/sql/store.ts
|
|
25
26
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
26
|
-
import { and as
|
|
27
|
+
import { and as and3, asc, desc, eq as eq3, isNull, sql as sql2 } from "drizzle-orm";
|
|
27
28
|
|
|
28
29
|
// src/chat/destination.ts
|
|
29
30
|
import {
|
|
@@ -197,6 +198,68 @@ function parseSessionSource(value) {
|
|
|
197
198
|
return parsed.success ? normalizeSessionSource(parsed.data) : void 0;
|
|
198
199
|
}
|
|
199
200
|
|
|
201
|
+
// src/chat/conversations/sql/bindings.ts
|
|
202
|
+
import { and as and2, eq as eq2 } from "drizzle-orm";
|
|
203
|
+
async function getConversationIdByProviderConversation(executor, args) {
|
|
204
|
+
const rows = await executor.db().select({ conversationId: juniorConversationBindings.conversationId }).from(juniorConversationBindings).where(
|
|
205
|
+
and2(
|
|
206
|
+
eq2(juniorConversationBindings.provider, args.provider),
|
|
207
|
+
eq2(juniorConversationBindings.providerTenantId, args.providerTenantId),
|
|
208
|
+
eq2(
|
|
209
|
+
juniorConversationBindings.providerDestinationId,
|
|
210
|
+
args.providerDestinationId
|
|
211
|
+
),
|
|
212
|
+
eq2(
|
|
213
|
+
juniorConversationBindings.providerConversationId,
|
|
214
|
+
args.providerConversationId
|
|
215
|
+
)
|
|
216
|
+
)
|
|
217
|
+
).limit(1);
|
|
218
|
+
return rows[0]?.conversationId;
|
|
219
|
+
}
|
|
220
|
+
async function bindProviderConversation(executor, args) {
|
|
221
|
+
const rows = await executor.db().insert(juniorConversationBindings).values({ ...args, createdAt: /* @__PURE__ */ new Date() }).onConflictDoNothing().returning({ conversationId: juniorConversationBindings.conversationId });
|
|
222
|
+
const boundConversationId = rows[0]?.conversationId ?? await getConversationIdByProviderConversation(executor, args);
|
|
223
|
+
if (boundConversationId !== args.conversationId) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
"Provider conversation is already bound to another conversation"
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/chat/conversations/location.ts
|
|
231
|
+
import { nonBlankStringSchema } from "@sentry/junior-plugin-api";
|
|
232
|
+
import { z } from "zod";
|
|
233
|
+
var locationSchema = z.object({
|
|
234
|
+
/** Junior-owned stable identity for this location. */
|
|
235
|
+
id: nonBlankStringSchema,
|
|
236
|
+
/** Provider namespace that owns the provider and tenant identifiers. */
|
|
237
|
+
provider: nonBlankStringSchema,
|
|
238
|
+
/** Optional provider-native workspace, account, or tenant scope. */
|
|
239
|
+
tenantId: nonBlankStringSchema.optional(),
|
|
240
|
+
/** Provider-native identifier for the container within its tenant scope. */
|
|
241
|
+
providerId: nonBlankStringSchema
|
|
242
|
+
}).strict();
|
|
243
|
+
|
|
244
|
+
// src/chat/conversations/sql/location.ts
|
|
245
|
+
function locationFromRow(row) {
|
|
246
|
+
if (!row || row.provider === "local") {
|
|
247
|
+
return void 0;
|
|
248
|
+
}
|
|
249
|
+
return locationSchema.parse({
|
|
250
|
+
id: row.id,
|
|
251
|
+
provider: row.provider,
|
|
252
|
+
...row.providerTenantId ? { tenantId: row.providerTenantId } : {},
|
|
253
|
+
providerId: row.providerDestinationId
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function privacyFromLocationRow(row) {
|
|
257
|
+
if (!row) {
|
|
258
|
+
return void 0;
|
|
259
|
+
}
|
|
260
|
+
return row.visibility === "public" ? "public" : "private";
|
|
261
|
+
}
|
|
262
|
+
|
|
200
263
|
// src/chat/conversations/sql/store.ts
|
|
201
264
|
var CONVERSATION_MUTATION_LOCK_PREFIX = "junior_conversation";
|
|
202
265
|
function now() {
|
|
@@ -315,12 +378,6 @@ function executionStatusFromValue(value) {
|
|
|
315
378
|
}
|
|
316
379
|
throw new Error("Conversation record execution status is invalid");
|
|
317
380
|
}
|
|
318
|
-
function privacyFromRow(row) {
|
|
319
|
-
if (row.destination === null) {
|
|
320
|
-
return void 0;
|
|
321
|
-
}
|
|
322
|
-
return row.destination.visibility === "public" ? "public" : "private";
|
|
323
|
-
}
|
|
324
381
|
function actorFromIdentityRow(identity, userDisplayName) {
|
|
325
382
|
if (!identity) {
|
|
326
383
|
return void 0;
|
|
@@ -351,7 +408,7 @@ function destinationFromRow(destination) {
|
|
|
351
408
|
}
|
|
352
409
|
function conversationFromRow(readRow) {
|
|
353
410
|
const row = readRow.conversation;
|
|
354
|
-
const visibility =
|
|
411
|
+
const visibility = privacyFromLocationRow(readRow.destination);
|
|
355
412
|
if (row.schemaVersion !== 1) {
|
|
356
413
|
throw new Error("Conversation record schema version is invalid");
|
|
357
414
|
}
|
|
@@ -384,6 +441,7 @@ function conversationFromRow(readRow) {
|
|
|
384
441
|
...row.runId ? { runId: row.runId } : {},
|
|
385
442
|
updatedAtMs: msFromDate(row.executionUpdatedAt) ?? requiredMsFromDate(row.updatedAt)
|
|
386
443
|
};
|
|
444
|
+
const location = locationFromRow(readRow.destination);
|
|
387
445
|
return {
|
|
388
446
|
schemaVersion: 1,
|
|
389
447
|
conversationId: row.conversationId,
|
|
@@ -397,6 +455,7 @@ function conversationFromRow(readRow) {
|
|
|
397
455
|
}
|
|
398
456
|
} : {},
|
|
399
457
|
...destination ? { destination } : {},
|
|
458
|
+
...location ? { location } : {},
|
|
400
459
|
...actor ? { actor } : {},
|
|
401
460
|
...msFromDate(row.archivedAt) !== void 0 ? { archivedAtMs: msFromDate(row.archivedAt) } : {},
|
|
402
461
|
...row.channelName ? { channelName: row.channelName } : {},
|
|
@@ -487,6 +546,12 @@ var SqlStore = class {
|
|
|
487
546
|
this.executor = executor;
|
|
488
547
|
}
|
|
489
548
|
executor;
|
|
549
|
+
async getConversationIdByProviderConversation(args) {
|
|
550
|
+
return await getConversationIdByProviderConversation(this.executor, args);
|
|
551
|
+
}
|
|
552
|
+
async bindProviderConversation(args) {
|
|
553
|
+
await bindProviderConversation(this.executor, args);
|
|
554
|
+
}
|
|
490
555
|
async get(args) {
|
|
491
556
|
const row = await this.readConversationRow(args.conversationId);
|
|
492
557
|
if (!row) {
|
|
@@ -580,7 +645,7 @@ var SqlStore = class {
|
|
|
580
645
|
metricRunId: args.execution.runId ?? null,
|
|
581
646
|
executionDurationMs: args.metrics.durationMs,
|
|
582
647
|
executionUsage: args.metrics.usage ?? (sameRun ? row?.executionUsage ?? null : null)
|
|
583
|
-
}).where(
|
|
648
|
+
}).where(eq3(juniorConversations.conversationId, args.conversationId));
|
|
584
649
|
}
|
|
585
650
|
});
|
|
586
651
|
}
|
|
@@ -592,11 +657,11 @@ var SqlStore = class {
|
|
|
592
657
|
actorUserDisplayName: juniorUsers.displayName
|
|
593
658
|
}).from(juniorConversations).leftJoin(
|
|
594
659
|
juniorDestinations,
|
|
595
|
-
|
|
660
|
+
eq3(juniorDestinations.id, juniorConversations.destinationId)
|
|
596
661
|
).leftJoin(
|
|
597
662
|
juniorIdentities,
|
|
598
|
-
|
|
599
|
-
).leftJoin(juniorUsers,
|
|
663
|
+
eq3(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
664
|
+
).leftJoin(juniorUsers, eq3(juniorUsers.id, juniorIdentities.userId)).where(isNull(juniorConversations.parentConversationId)).orderBy(
|
|
600
665
|
desc(juniorConversations.lastActivityAt),
|
|
601
666
|
asc(juniorConversations.conversationId)
|
|
602
667
|
).limit(Math.max(0, args.limit ?? 1e4)).offset(Math.max(0, args.offset ?? 0));
|
|
@@ -610,13 +675,13 @@ var SqlStore = class {
|
|
|
610
675
|
const rows = await this.executor.db().select({
|
|
611
676
|
visibility: juniorDestinations.visibility
|
|
612
677
|
}).from(juniorDestinations).where(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
678
|
+
and3(
|
|
679
|
+
eq3(juniorDestinations.provider, args.provider),
|
|
680
|
+
eq3(
|
|
616
681
|
juniorDestinations.providerTenantId,
|
|
617
682
|
tenantId2(args.providerTenantId)
|
|
618
683
|
),
|
|
619
|
-
|
|
684
|
+
eq3(
|
|
620
685
|
juniorDestinations.providerDestinationId,
|
|
621
686
|
args.providerDestinationId
|
|
622
687
|
)
|
|
@@ -646,11 +711,11 @@ var SqlStore = class {
|
|
|
646
711
|
actorUserDisplayName: juniorUsers.displayName
|
|
647
712
|
}).from(juniorConversations).leftJoin(
|
|
648
713
|
juniorDestinations,
|
|
649
|
-
|
|
714
|
+
eq3(juniorDestinations.id, juniorConversations.destinationId)
|
|
650
715
|
).leftJoin(
|
|
651
716
|
juniorIdentities,
|
|
652
|
-
|
|
653
|
-
).leftJoin(juniorUsers,
|
|
717
|
+
eq3(juniorIdentities.id, juniorConversations.actorIdentityId)
|
|
718
|
+
).leftJoin(juniorUsers, eq3(juniorUsers.id, juniorIdentities.userId)).where(eq3(juniorConversations.conversationId, conversationId));
|
|
654
719
|
return rows[0];
|
|
655
720
|
}
|
|
656
721
|
/** Upsert the conversation row while preserving previously discovered nullable metadata fields. */
|
|
@@ -779,10 +844,10 @@ function createSqlStore(executor) {
|
|
|
779
844
|
|
|
780
845
|
// src/chat/conversations/sql/history.ts
|
|
781
846
|
import {
|
|
782
|
-
and as
|
|
847
|
+
and as and4,
|
|
783
848
|
asc as asc2,
|
|
784
849
|
desc as desc2,
|
|
785
|
-
eq as
|
|
850
|
+
eq as eq4,
|
|
786
851
|
gt,
|
|
787
852
|
gte,
|
|
788
853
|
inArray,
|
|
@@ -793,16 +858,16 @@ import {
|
|
|
793
858
|
} from "drizzle-orm";
|
|
794
859
|
|
|
795
860
|
// src/chat/conversations/history.ts
|
|
796
|
-
import { z as
|
|
861
|
+
import { z as z3 } from "zod";
|
|
797
862
|
|
|
798
863
|
// src/chat/conversations/provenance.ts
|
|
799
864
|
import { actorSchema } from "@sentry/junior-plugin-api";
|
|
800
|
-
import { z } from "zod";
|
|
801
|
-
var conversationMessageAuthoritySchema =
|
|
802
|
-
|
|
803
|
-
|
|
865
|
+
import { z as z2 } from "zod";
|
|
866
|
+
var conversationMessageAuthoritySchema = z2.union([
|
|
867
|
+
z2.literal("instruction"),
|
|
868
|
+
z2.literal("context")
|
|
804
869
|
]);
|
|
805
|
-
var conversationMessageProvenanceSchema =
|
|
870
|
+
var conversationMessageProvenanceSchema = z2.object({
|
|
806
871
|
authority: conversationMessageAuthoritySchema,
|
|
807
872
|
actor: actorSchema.optional()
|
|
808
873
|
}).strict();
|
|
@@ -845,214 +910,214 @@ var handoffModelProfileSchema = modelProfileSchema.refine(
|
|
|
845
910
|
(profile) => profile !== "standard",
|
|
846
911
|
"handoff profile must not be standard"
|
|
847
912
|
);
|
|
848
|
-
var userMessageEventDataSchema =
|
|
849
|
-
type:
|
|
850
|
-
role:
|
|
913
|
+
var userMessageEventDataSchema = z3.object({
|
|
914
|
+
type: z3.literal("user_message"),
|
|
915
|
+
role: z3.never().optional(),
|
|
851
916
|
provenance: conversationMessageProvenanceSchema
|
|
852
917
|
}).passthrough();
|
|
853
|
-
var assistantMessageEventDataSchema =
|
|
854
|
-
type:
|
|
855
|
-
role:
|
|
918
|
+
var assistantMessageEventDataSchema = z3.object({
|
|
919
|
+
type: z3.literal("assistant_message"),
|
|
920
|
+
role: z3.never().optional()
|
|
856
921
|
}).passthrough();
|
|
857
|
-
var toolResultEventDataSchema =
|
|
858
|
-
type:
|
|
859
|
-
role:
|
|
922
|
+
var toolResultEventDataSchema = z3.object({
|
|
923
|
+
type: z3.literal("tool_result"),
|
|
924
|
+
role: z3.never().optional()
|
|
860
925
|
}).passthrough();
|
|
861
|
-
var agentHistoryItemSchema =
|
|
926
|
+
var agentHistoryItemSchema = z3.discriminatedUnion("type", [
|
|
862
927
|
userMessageEventDataSchema,
|
|
863
928
|
assistantMessageEventDataSchema,
|
|
864
929
|
toolResultEventDataSchema
|
|
865
930
|
]);
|
|
866
|
-
var nativeReplacementHistoryItemSchema =
|
|
931
|
+
var nativeReplacementHistoryItemSchema = z3.object({
|
|
867
932
|
item: agentHistoryItemSchema,
|
|
868
933
|
// Preserve the copied item's position when a turn resumes. Synthetic
|
|
869
934
|
// summary and handoff items have no source event.
|
|
870
|
-
sourceEventSeq:
|
|
935
|
+
sourceEventSeq: z3.number().int().nonnegative().optional()
|
|
871
936
|
}).strict();
|
|
872
|
-
var replacementHistorySchema =
|
|
873
|
-
var compactionDetailsSchema =
|
|
874
|
-
reason:
|
|
875
|
-
estimatedInputTokens:
|
|
876
|
-
replacementInputTokens:
|
|
877
|
-
triggerTokens:
|
|
878
|
-
inputLimitTokens:
|
|
879
|
-
inputMessageCount:
|
|
880
|
-
retainedMessageCount:
|
|
881
|
-
summaryChars:
|
|
937
|
+
var replacementHistorySchema = z3.array(nativeReplacementHistoryItemSchema);
|
|
938
|
+
var compactionDetailsSchema = z3.object({
|
|
939
|
+
reason: z3.literal("capacity"),
|
|
940
|
+
estimatedInputTokens: z3.number().int().nonnegative(),
|
|
941
|
+
replacementInputTokens: z3.number().int().nonnegative().optional(),
|
|
942
|
+
triggerTokens: z3.number().int().nonnegative(),
|
|
943
|
+
inputLimitTokens: z3.number().int().positive(),
|
|
944
|
+
inputMessageCount: z3.number().int().nonnegative(),
|
|
945
|
+
retainedMessageCount: z3.number().int().nonnegative(),
|
|
946
|
+
summaryChars: z3.number().int().nonnegative()
|
|
882
947
|
}).strict();
|
|
883
|
-
var historyReplacementEventDataSchema =
|
|
884
|
-
|
|
885
|
-
type:
|
|
948
|
+
var historyReplacementEventDataSchema = z3.discriminatedUnion("type", [
|
|
949
|
+
z3.object({
|
|
950
|
+
type: z3.literal("handoff"),
|
|
886
951
|
modelProfile: handoffModelProfileSchema,
|
|
887
|
-
modelId:
|
|
888
|
-
reasoningLevel:
|
|
889
|
-
triggeringToolCallId:
|
|
890
|
-
summary:
|
|
952
|
+
modelId: z3.string().min(1),
|
|
953
|
+
reasoningLevel: z3.string().min(1).optional(),
|
|
954
|
+
triggeringToolCallId: z3.string().min(1).optional(),
|
|
955
|
+
summary: z3.string().min(1).optional(),
|
|
891
956
|
replacementHistory: replacementHistorySchema
|
|
892
957
|
}).strict(),
|
|
893
|
-
|
|
894
|
-
type:
|
|
958
|
+
z3.object({
|
|
959
|
+
type: z3.literal("compaction"),
|
|
895
960
|
modelProfile: modelProfileSchema,
|
|
896
|
-
modelId:
|
|
961
|
+
modelId: z3.string().min(1),
|
|
897
962
|
details: compactionDetailsSchema.optional(),
|
|
898
|
-
summary:
|
|
963
|
+
summary: z3.string().min(1).optional(),
|
|
899
964
|
replacementHistory: replacementHistorySchema
|
|
900
965
|
}).strict()
|
|
901
966
|
]);
|
|
902
|
-
var historyReplacementSchema =
|
|
967
|
+
var historyReplacementSchema = z3.object({
|
|
903
968
|
data: historyReplacementEventDataSchema,
|
|
904
|
-
createdAtMs:
|
|
969
|
+
createdAtMs: z3.number().finite()
|
|
905
970
|
}).strict();
|
|
906
|
-
var mcpProviderConnectedEventDataSchema =
|
|
907
|
-
type:
|
|
908
|
-
provider:
|
|
971
|
+
var mcpProviderConnectedEventDataSchema = z3.object({
|
|
972
|
+
type: z3.literal("mcp_provider_connected"),
|
|
973
|
+
provider: z3.string().min(1)
|
|
909
974
|
}).strict();
|
|
910
|
-
var authorizationKindSchema =
|
|
911
|
-
|
|
912
|
-
|
|
975
|
+
var authorizationKindSchema = z3.union([
|
|
976
|
+
z3.literal("plugin"),
|
|
977
|
+
z3.literal("mcp")
|
|
913
978
|
]);
|
|
914
|
-
var authorizationRequestedEventDataSchema =
|
|
915
|
-
type:
|
|
979
|
+
var authorizationRequestedEventDataSchema = z3.object({
|
|
980
|
+
type: z3.literal("authorization_requested"),
|
|
916
981
|
kind: authorizationKindSchema,
|
|
917
|
-
provider:
|
|
918
|
-
actorId:
|
|
919
|
-
authorizationId:
|
|
920
|
-
delivery:
|
|
921
|
-
|
|
922
|
-
|
|
982
|
+
provider: z3.string().min(1),
|
|
983
|
+
actorId: z3.string().min(1),
|
|
984
|
+
authorizationId: z3.string().min(1),
|
|
985
|
+
delivery: z3.union([
|
|
986
|
+
z3.literal("private_link_sent"),
|
|
987
|
+
z3.literal("private_link_reused")
|
|
923
988
|
])
|
|
924
989
|
}).strict();
|
|
925
|
-
var authorizationCompletedEventDataSchema =
|
|
926
|
-
type:
|
|
990
|
+
var authorizationCompletedEventDataSchema = z3.object({
|
|
991
|
+
type: z3.literal("authorization_completed"),
|
|
927
992
|
kind: authorizationKindSchema,
|
|
928
|
-
provider:
|
|
929
|
-
actorId:
|
|
930
|
-
authorizationId:
|
|
993
|
+
provider: z3.string().min(1),
|
|
994
|
+
actorId: z3.string().min(1),
|
|
995
|
+
authorizationId: z3.string().min(1)
|
|
931
996
|
}).strict();
|
|
932
|
-
var toolExecutionStartedEventDataSchema =
|
|
933
|
-
type:
|
|
934
|
-
toolCallId:
|
|
935
|
-
toolName:
|
|
997
|
+
var toolExecutionStartedEventDataSchema = z3.object({
|
|
998
|
+
type: z3.literal("tool_execution_started"),
|
|
999
|
+
toolCallId: z3.string().min(1),
|
|
1000
|
+
toolName: z3.string().min(1)
|
|
936
1001
|
}).strict();
|
|
937
|
-
var guardianActionReviewedEventDataSchema =
|
|
938
|
-
type:
|
|
939
|
-
turnId:
|
|
940
|
-
toolCallId:
|
|
941
|
-
toolName:
|
|
942
|
-
costUsd:
|
|
943
|
-
decision:
|
|
944
|
-
riskLevel:
|
|
945
|
-
userAuthorization:
|
|
1002
|
+
var guardianActionReviewedEventDataSchema = z3.object({
|
|
1003
|
+
type: z3.literal("guardian_action_reviewed"),
|
|
1004
|
+
turnId: z3.string().min(1),
|
|
1005
|
+
toolCallId: z3.string().min(1),
|
|
1006
|
+
toolName: z3.string().min(1),
|
|
1007
|
+
costUsd: z3.number().finite().nonnegative().optional(),
|
|
1008
|
+
decision: z3.enum(["allow", "ask", "deny"]),
|
|
1009
|
+
riskLevel: z3.enum(["low", "medium", "high", "critical"]),
|
|
1010
|
+
userAuthorization: z3.enum(["high", "medium", "low", "unknown"])
|
|
946
1011
|
}).strict();
|
|
947
|
-
var conversationMessageRoleSchema =
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
1012
|
+
var conversationMessageRoleSchema = z3.union([
|
|
1013
|
+
z3.literal("user"),
|
|
1014
|
+
z3.literal("assistant"),
|
|
1015
|
+
z3.literal("system")
|
|
951
1016
|
]);
|
|
952
|
-
var messageEventDataSchema =
|
|
953
|
-
type:
|
|
954
|
-
messageId:
|
|
1017
|
+
var messageEventDataSchema = z3.object({
|
|
1018
|
+
type: z3.literal("message"),
|
|
1019
|
+
messageId: z3.string().min(1),
|
|
955
1020
|
role: conversationMessageRoleSchema,
|
|
956
|
-
text:
|
|
957
|
-
authorIdentityId:
|
|
958
|
-
meta:
|
|
1021
|
+
text: z3.string(),
|
|
1022
|
+
authorIdentityId: z3.string().min(1).optional(),
|
|
1023
|
+
meta: z3.record(z3.string(), z3.unknown()).optional()
|
|
959
1024
|
}).strict();
|
|
960
1025
|
var messageUpdatedEventDataSchema = messageEventDataSchema.extend({
|
|
961
|
-
type:
|
|
1026
|
+
type: z3.literal("message_updated")
|
|
962
1027
|
});
|
|
963
|
-
var messageHandledEventDataSchema =
|
|
964
|
-
type:
|
|
965
|
-
messageId:
|
|
1028
|
+
var messageHandledEventDataSchema = z3.object({
|
|
1029
|
+
type: z3.literal("message_handled"),
|
|
1030
|
+
messageId: z3.string().min(1)
|
|
966
1031
|
}).strict();
|
|
967
|
-
var messagesSummarizedEventDataSchema =
|
|
968
|
-
type:
|
|
969
|
-
historyFromSeq:
|
|
970
|
-
compactions:
|
|
971
|
-
|
|
972
|
-
coveredMessageCount:
|
|
973
|
-
createdAtMs:
|
|
974
|
-
id:
|
|
975
|
-
summary:
|
|
1032
|
+
var messagesSummarizedEventDataSchema = z3.object({
|
|
1033
|
+
type: z3.literal("messages_summarized"),
|
|
1034
|
+
historyFromSeq: z3.number().int().nonnegative(),
|
|
1035
|
+
compactions: z3.array(
|
|
1036
|
+
z3.object({
|
|
1037
|
+
coveredMessageCount: z3.number().int().nonnegative(),
|
|
1038
|
+
createdAtMs: z3.number(),
|
|
1039
|
+
id: z3.string().min(1),
|
|
1040
|
+
summary: z3.string()
|
|
976
1041
|
}).strict()
|
|
977
1042
|
)
|
|
978
1043
|
}).strict();
|
|
979
|
-
var conversationTurnSurfaceSchema =
|
|
1044
|
+
var conversationTurnSurfaceSchema = z3.enum([
|
|
980
1045
|
"slack",
|
|
981
1046
|
"api",
|
|
982
1047
|
"scheduler",
|
|
983
1048
|
"internal"
|
|
984
1049
|
]);
|
|
985
|
-
var conversationTurnFailureCodeSchema =
|
|
1050
|
+
var conversationTurnFailureCodeSchema = z3.enum([
|
|
986
1051
|
"agent_run_failed",
|
|
987
1052
|
"delivery_failed",
|
|
988
1053
|
"model_execution_failed",
|
|
989
1054
|
"persistence_failed"
|
|
990
1055
|
]);
|
|
991
|
-
var turnStartedEventDataSchema =
|
|
992
|
-
type:
|
|
993
|
-
turnId:
|
|
994
|
-
inputMessageIds:
|
|
1056
|
+
var turnStartedEventDataSchema = z3.object({
|
|
1057
|
+
type: z3.literal("turn_started"),
|
|
1058
|
+
turnId: z3.string().min(1),
|
|
1059
|
+
inputMessageIds: z3.array(z3.string().min(1)).min(1),
|
|
995
1060
|
surface: conversationTurnSurfaceSchema
|
|
996
1061
|
}).strict().refine(
|
|
997
1062
|
(data) => new Set(data.inputMessageIds).size === data.inputMessageIds.length,
|
|
998
1063
|
"turn input message ids must be unique"
|
|
999
1064
|
);
|
|
1000
|
-
var turnRoutedEventDataSchema =
|
|
1001
|
-
type:
|
|
1002
|
-
turnId:
|
|
1065
|
+
var turnRoutedEventDataSchema = z3.object({
|
|
1066
|
+
type: z3.literal("turn_routed"),
|
|
1067
|
+
turnId: z3.string().min(1),
|
|
1003
1068
|
modelProfile: modelProfileSchema,
|
|
1004
|
-
modelId:
|
|
1005
|
-
reasoningLevel:
|
|
1006
|
-
confidence:
|
|
1007
|
-
source:
|
|
1069
|
+
modelId: z3.string().min(1),
|
|
1070
|
+
reasoningLevel: z3.enum(TURN_REASONING_LEVELS),
|
|
1071
|
+
confidence: z3.number().min(0).max(1).optional(),
|
|
1072
|
+
source: z3.enum(["configured", "inherited", "router"])
|
|
1008
1073
|
}).strict();
|
|
1009
|
-
var turnContextEventDataSchema =
|
|
1010
|
-
type:
|
|
1011
|
-
turnId:
|
|
1012
|
-
pluginName:
|
|
1013
|
-
kind:
|
|
1014
|
-
version:
|
|
1015
|
-
content:
|
|
1074
|
+
var turnContextEventDataSchema = z3.object({
|
|
1075
|
+
type: z3.literal("turn_context"),
|
|
1076
|
+
turnId: z3.string().min(1),
|
|
1077
|
+
pluginName: z3.string().min(1),
|
|
1078
|
+
kind: z3.string().min(1).max(64),
|
|
1079
|
+
version: z3.number().int().positive(),
|
|
1080
|
+
content: z3.record(z3.string(), z3.unknown())
|
|
1016
1081
|
}).strict();
|
|
1017
|
-
var structuredConversationEventDataSchema =
|
|
1018
|
-
type:
|
|
1019
|
-
namespace:
|
|
1020
|
-
name:
|
|
1021
|
-
version:
|
|
1022
|
-
turnId:
|
|
1023
|
-
content:
|
|
1082
|
+
var structuredConversationEventDataSchema = z3.object({
|
|
1083
|
+
type: z3.literal("structured_event"),
|
|
1084
|
+
namespace: z3.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
1085
|
+
name: z3.string().regex(/^[a-z][a-z0-9_]*$/),
|
|
1086
|
+
version: z3.number().int().positive(),
|
|
1087
|
+
turnId: z3.string().min(1).optional(),
|
|
1088
|
+
content: z3.record(z3.string(), z3.unknown())
|
|
1024
1089
|
}).strict();
|
|
1025
|
-
var turnCompletedEventDataSchema =
|
|
1026
|
-
type:
|
|
1027
|
-
turnId:
|
|
1028
|
-
outcome:
|
|
1090
|
+
var turnCompletedEventDataSchema = z3.object({
|
|
1091
|
+
type: z3.literal("turn_completed"),
|
|
1092
|
+
turnId: z3.string().min(1),
|
|
1093
|
+
outcome: z3.enum(["success", "no_reply"])
|
|
1029
1094
|
}).strict();
|
|
1030
|
-
var turnFailedEventDataSchema =
|
|
1031
|
-
type:
|
|
1032
|
-
turnId:
|
|
1095
|
+
var turnFailedEventDataSchema = z3.object({
|
|
1096
|
+
type: z3.literal("turn_failed"),
|
|
1097
|
+
turnId: z3.string().min(1),
|
|
1033
1098
|
failureCode: conversationTurnFailureCodeSchema,
|
|
1034
|
-
eventId:
|
|
1099
|
+
eventId: z3.string().regex(/^[a-f0-9]{32}$/i).optional()
|
|
1035
1100
|
}).strict();
|
|
1036
|
-
var subagentStartedEventDataSchema =
|
|
1037
|
-
type:
|
|
1038
|
-
subagentInvocationId:
|
|
1039
|
-
subagentKind:
|
|
1040
|
-
modelId:
|
|
1041
|
-
parentToolCallId:
|
|
1042
|
-
reasoningLevel:
|
|
1043
|
-
childConversationId:
|
|
1101
|
+
var subagentStartedEventDataSchema = z3.object({
|
|
1102
|
+
type: z3.literal("subagent_started"),
|
|
1103
|
+
subagentInvocationId: z3.string().min(1),
|
|
1104
|
+
subagentKind: z3.string().min(1),
|
|
1105
|
+
modelId: z3.string().min(1).optional(),
|
|
1106
|
+
parentToolCallId: z3.string().min(1).optional(),
|
|
1107
|
+
reasoningLevel: z3.string().min(1).optional(),
|
|
1108
|
+
childConversationId: z3.string().min(1)
|
|
1044
1109
|
}).strict();
|
|
1045
|
-
var subagentEndedEventDataSchema =
|
|
1046
|
-
type:
|
|
1047
|
-
subagentInvocationId:
|
|
1048
|
-
outcome:
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1110
|
+
var subagentEndedEventDataSchema = z3.object({
|
|
1111
|
+
type: z3.literal("subagent_ended"),
|
|
1112
|
+
subagentInvocationId: z3.string().min(1),
|
|
1113
|
+
outcome: z3.union([
|
|
1114
|
+
z3.literal("success"),
|
|
1115
|
+
z3.literal("error"),
|
|
1116
|
+
z3.literal("aborted")
|
|
1052
1117
|
]),
|
|
1053
|
-
errorCode:
|
|
1118
|
+
errorCode: z3.string().min(1).optional()
|
|
1054
1119
|
}).strict();
|
|
1055
|
-
var appendableConversationEventDataSchema =
|
|
1120
|
+
var appendableConversationEventDataSchema = z3.union([
|
|
1056
1121
|
messageEventDataSchema,
|
|
1057
1122
|
messageUpdatedEventDataSchema,
|
|
1058
1123
|
agentHistoryItemSchema,
|
|
@@ -1072,7 +1137,7 @@ var appendableConversationEventDataSchema = z2.union([
|
|
|
1072
1137
|
subagentStartedEventDataSchema,
|
|
1073
1138
|
subagentEndedEventDataSchema
|
|
1074
1139
|
]);
|
|
1075
|
-
var conversationEventDataSchema =
|
|
1140
|
+
var conversationEventDataSchema = z3.union([
|
|
1076
1141
|
appendableConversationEventDataSchema,
|
|
1077
1142
|
historyReplacementEventDataSchema
|
|
1078
1143
|
]);
|
|
@@ -1100,22 +1165,22 @@ var KNOWN_CONVERSATION_EVENT_TYPES = [
|
|
|
1100
1165
|
"handoff",
|
|
1101
1166
|
"compaction"
|
|
1102
1167
|
];
|
|
1103
|
-
var knownConversationEventTypeSchema =
|
|
1104
|
-
var unknownConversationEventDataSchema =
|
|
1105
|
-
type:
|
|
1106
|
-
originalType:
|
|
1107
|
-
payload:
|
|
1168
|
+
var knownConversationEventTypeSchema = z3.enum(KNOWN_CONVERSATION_EVENT_TYPES);
|
|
1169
|
+
var unknownConversationEventDataSchema = z3.object({
|
|
1170
|
+
type: z3.literal("unknown"),
|
|
1171
|
+
originalType: z3.string().min(1),
|
|
1172
|
+
payload: z3.unknown()
|
|
1108
1173
|
}).strict();
|
|
1109
|
-
var conversationEventEnvelopeSchema =
|
|
1110
|
-
schemaVersion:
|
|
1111
|
-
seq:
|
|
1112
|
-
historyVersion:
|
|
1113
|
-
idempotencyKey:
|
|
1114
|
-
createdAtMs:
|
|
1174
|
+
var conversationEventEnvelopeSchema = z3.object({
|
|
1175
|
+
schemaVersion: z3.number().int().nonnegative(),
|
|
1176
|
+
seq: z3.number().int().nonnegative(),
|
|
1177
|
+
historyVersion: z3.number().int().nonnegative(),
|
|
1178
|
+
idempotencyKey: z3.string().min(1).optional(),
|
|
1179
|
+
createdAtMs: z3.number().finite()
|
|
1115
1180
|
}).strict();
|
|
1116
|
-
var conversationEventSchema =
|
|
1181
|
+
var conversationEventSchema = z3.union([
|
|
1117
1182
|
conversationEventEnvelopeSchema.extend({
|
|
1118
|
-
schemaVersion:
|
|
1183
|
+
schemaVersion: z3.literal(1),
|
|
1119
1184
|
data: conversationEventDataSchema
|
|
1120
1185
|
}),
|
|
1121
1186
|
conversationEventEnvelopeSchema.extend({
|
|
@@ -1123,8 +1188,8 @@ var conversationEventSchema = z2.union([
|
|
|
1123
1188
|
})
|
|
1124
1189
|
]);
|
|
1125
1190
|
var storedConversationEventSchema = conversationEventEnvelopeSchema.extend({
|
|
1126
|
-
type:
|
|
1127
|
-
payload:
|
|
1191
|
+
type: z3.string().min(1),
|
|
1192
|
+
payload: z3.unknown()
|
|
1128
1193
|
});
|
|
1129
1194
|
function decodeStoredConversationEvent(value) {
|
|
1130
1195
|
const stored = storedConversationEventSchema.parse(value);
|
|
@@ -1139,10 +1204,10 @@ function decodeStoredConversationEvent(value) {
|
|
|
1139
1204
|
data: { type: "unknown", originalType: type, payload }
|
|
1140
1205
|
});
|
|
1141
1206
|
}
|
|
1142
|
-
var newConversationEventSchema =
|
|
1207
|
+
var newConversationEventSchema = z3.object({
|
|
1143
1208
|
data: appendableConversationEventDataSchema,
|
|
1144
|
-
idempotencyKey:
|
|
1145
|
-
createdAtMs:
|
|
1209
|
+
idempotencyKey: z3.string().min(1).optional(),
|
|
1210
|
+
createdAtMs: z3.number().finite()
|
|
1146
1211
|
}).strict();
|
|
1147
1212
|
|
|
1148
1213
|
// src/chat/conversations/sql/conversation-row.ts
|
|
@@ -1258,8 +1323,8 @@ var SqlConversationEventStore = class {
|
|
|
1258
1323
|
const existingKeys = parsed.map((event) => event.idempotencyKey).filter((key) => key !== void 0);
|
|
1259
1324
|
const persistedKeys = existingKeys.length === 0 ? /* @__PURE__ */ new Set() : new Set(
|
|
1260
1325
|
(await this.executor.db().select({ key: juniorConversationEvents.idempotencyKey }).from(juniorConversationEvents).where(
|
|
1261
|
-
|
|
1262
|
-
|
|
1326
|
+
and4(
|
|
1327
|
+
eq4(
|
|
1263
1328
|
juniorConversationEvents.conversationId,
|
|
1264
1329
|
conversationId
|
|
1265
1330
|
),
|
|
@@ -1291,8 +1356,8 @@ var SqlConversationEventStore = class {
|
|
|
1291
1356
|
);
|
|
1292
1357
|
if (options.activity !== "preserve") {
|
|
1293
1358
|
await this.executor.db().update(juniorConversations).set({ archivedAt: null }).where(
|
|
1294
|
-
|
|
1295
|
-
|
|
1359
|
+
and4(
|
|
1360
|
+
eq4(juniorConversations.conversationId, conversationId),
|
|
1296
1361
|
isNotNull(juniorConversations.archivedAt)
|
|
1297
1362
|
)
|
|
1298
1363
|
);
|
|
@@ -1311,8 +1376,8 @@ var SqlConversationEventStore = class {
|
|
|
1311
1376
|
await withConversationEventLock(this.executor, conversationId, async () => {
|
|
1312
1377
|
await ensureConversationRow(this.executor, conversationId, Date.now());
|
|
1313
1378
|
await this.executor.db().update(juniorConversations).set({ archivedAt: null }).where(
|
|
1314
|
-
|
|
1315
|
-
|
|
1379
|
+
and4(
|
|
1380
|
+
eq4(juniorConversations.conversationId, conversationId),
|
|
1316
1381
|
isNotNull(juniorConversations.archivedAt)
|
|
1317
1382
|
)
|
|
1318
1383
|
);
|
|
@@ -1334,34 +1399,34 @@ var SqlConversationEventStore = class {
|
|
|
1334
1399
|
return [];
|
|
1335
1400
|
}
|
|
1336
1401
|
const rows = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1402
|
+
and4(
|
|
1403
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1404
|
+
eq4(juniorConversationEvents.historyVersion, cursor.maxHistoryVersion)
|
|
1340
1405
|
)
|
|
1341
1406
|
).orderBy(asc2(juniorConversationEvents.seq));
|
|
1342
1407
|
return rows.map(eventFromRow);
|
|
1343
1408
|
}
|
|
1344
1409
|
async loadByIdempotencyKey(conversationId, idempotencyKey) {
|
|
1345
1410
|
const [row] = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1411
|
+
and4(
|
|
1412
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1413
|
+
eq4(juniorConversationEvents.idempotencyKey, idempotencyKey)
|
|
1349
1414
|
)
|
|
1350
1415
|
).limit(1);
|
|
1351
1416
|
return row ? eventFromRow(row) : void 0;
|
|
1352
1417
|
}
|
|
1353
1418
|
async loadHistoryContaining(conversationId, seq, throughSeq) {
|
|
1354
1419
|
const [boundary] = await this.executor.db().select({ historyVersion: juniorConversationEvents.historyVersion }).from(juniorConversationEvents).where(
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1420
|
+
and4(
|
|
1421
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1422
|
+
eq4(juniorConversationEvents.seq, seq)
|
|
1358
1423
|
)
|
|
1359
1424
|
).limit(1);
|
|
1360
1425
|
if (!boundary) return void 0;
|
|
1361
1426
|
const rows = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1427
|
+
and4(
|
|
1428
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1429
|
+
eq4(juniorConversationEvents.historyVersion, boundary.historyVersion),
|
|
1365
1430
|
throughSeq === void 0 ? void 0 : lte(juniorConversationEvents.seq, throughSeq)
|
|
1366
1431
|
)
|
|
1367
1432
|
).orderBy(asc2(juniorConversationEvents.seq));
|
|
@@ -1369,9 +1434,9 @@ var SqlConversationEventStore = class {
|
|
|
1369
1434
|
}
|
|
1370
1435
|
async loadLatestInstruction(conversationId) {
|
|
1371
1436
|
const [row] = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1437
|
+
and4(
|
|
1438
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1439
|
+
eq4(juniorConversationEvents.type, "user_message"),
|
|
1375
1440
|
sql4`${juniorConversationEvents.payload}->'provenance'->>'authority' = 'instruction'`
|
|
1376
1441
|
)
|
|
1377
1442
|
).orderBy(desc2(juniorConversationEvents.seq)).limit(1);
|
|
@@ -1379,16 +1444,16 @@ var SqlConversationEventStore = class {
|
|
|
1379
1444
|
}
|
|
1380
1445
|
async loadMessageHistory(conversationId) {
|
|
1381
1446
|
const [compactionRow] = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1447
|
+
and4(
|
|
1448
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1449
|
+
eq4(juniorConversationEvents.type, "messages_summarized")
|
|
1385
1450
|
)
|
|
1386
1451
|
).orderBy(desc2(juniorConversationEvents.seq)).limit(1);
|
|
1387
1452
|
const compaction = compactionRow ? messagesSummarizedEventFromRow(compactionRow) : void 0;
|
|
1388
1453
|
const historyFromSeq = compaction?.data.historyFromSeq ?? 0;
|
|
1389
1454
|
const rows = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1390
|
-
|
|
1391
|
-
|
|
1455
|
+
and4(
|
|
1456
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1392
1457
|
inArray(juniorConversationEvents.type, messageHistoryEventTypes),
|
|
1393
1458
|
gte(juniorConversationEvents.seq, historyFromSeq)
|
|
1394
1459
|
)
|
|
@@ -1396,7 +1461,7 @@ var SqlConversationEventStore = class {
|
|
|
1396
1461
|
return { events: rows.map(eventFromRow), compaction, historyFromSeq };
|
|
1397
1462
|
}
|
|
1398
1463
|
async loadHistory(conversationId) {
|
|
1399
|
-
const rows = await this.executor.db().select().from(juniorConversationEvents).where(
|
|
1464
|
+
const rows = await this.executor.db().select().from(juniorConversationEvents).where(eq4(juniorConversationEvents.conversationId, conversationId)).orderBy(asc2(juniorConversationEvents.seq));
|
|
1400
1465
|
return rows.map(eventFromRow);
|
|
1401
1466
|
}
|
|
1402
1467
|
async query(conversationId, query) {
|
|
@@ -1407,8 +1472,8 @@ var SqlConversationEventStore = class {
|
|
|
1407
1472
|
return { events: [], hasOlder: false, hasNewer: false };
|
|
1408
1473
|
}
|
|
1409
1474
|
const typeFilter = query.types && query.types.length > 0 ? inArray(juniorConversationEvents.type, [...query.types]) : void 0;
|
|
1410
|
-
const bounds =
|
|
1411
|
-
|
|
1475
|
+
const bounds = and4(
|
|
1476
|
+
eq4(juniorConversationEvents.conversationId, conversationId),
|
|
1412
1477
|
query.afterSeq === void 0 ? void 0 : gt(juniorConversationEvents.seq, query.afterSeq),
|
|
1413
1478
|
query.beforeSeq === void 0 ? void 0 : lt(juniorConversationEvents.seq, query.beforeSeq),
|
|
1414
1479
|
typeFilter
|
|
@@ -1445,8 +1510,8 @@ var SqlConversationEventStore = class {
|
|
|
1445
1510
|
return false;
|
|
1446
1511
|
}
|
|
1447
1512
|
const [row] = await this.executor.db().select({ seq: juniorConversationEvents.seq }).from(juniorConversationEvents).where(
|
|
1448
|
-
|
|
1449
|
-
|
|
1513
|
+
and4(
|
|
1514
|
+
eq4(juniorConversationEvents.conversationId, args.conversationId),
|
|
1450
1515
|
args.afterSeq === void 0 ? void 0 : gt(juniorConversationEvents.seq, args.afterSeq),
|
|
1451
1516
|
args.beforeSeq === void 0 ? void 0 : lt(juniorConversationEvents.seq, args.beforeSeq),
|
|
1452
1517
|
args.typeFilter
|
|
@@ -1459,7 +1524,7 @@ var SqlConversationEventStore = class {
|
|
|
1459
1524
|
const rows = await this.executor.db().select({
|
|
1460
1525
|
maxSeq: sql4`max(${juniorConversationEvents.seq})`,
|
|
1461
1526
|
maxHistoryVersion: sql4`max(${juniorConversationEvents.historyVersion})`
|
|
1462
|
-
}).from(juniorConversationEvents).where(
|
|
1527
|
+
}).from(juniorConversationEvents).where(eq4(juniorConversationEvents.conversationId, conversationId));
|
|
1463
1528
|
const maxSeq = rows[0]?.maxSeq;
|
|
1464
1529
|
const maxHistoryVersion = rows[0]?.maxHistoryVersion;
|
|
1465
1530
|
return {
|
|
@@ -1473,7 +1538,7 @@ function createSqlConversationEventStore(executor) {
|
|
|
1473
1538
|
}
|
|
1474
1539
|
|
|
1475
1540
|
// src/chat/conversations/sql/search.ts
|
|
1476
|
-
import { and as
|
|
1541
|
+
import { and as and5, desc as desc3, eq as eq5, isNull as isNull2, ne, sql as sql5 } from "drizzle-orm";
|
|
1477
1542
|
var SqlConversationSearchStore = class {
|
|
1478
1543
|
constructor(executor) {
|
|
1479
1544
|
this.executor = executor;
|
|
@@ -1498,23 +1563,23 @@ var SqlConversationSearchStore = class {
|
|
|
1498
1563
|
role: role.as("role")
|
|
1499
1564
|
}).from(juniorConversationEvents).innerJoin(
|
|
1500
1565
|
juniorConversations,
|
|
1501
|
-
|
|
1566
|
+
eq5(
|
|
1502
1567
|
juniorConversations.conversationId,
|
|
1503
1568
|
juniorConversationEvents.conversationId
|
|
1504
1569
|
)
|
|
1505
1570
|
).innerJoin(
|
|
1506
1571
|
juniorDestinations,
|
|
1507
|
-
|
|
1572
|
+
eq5(juniorDestinations.id, juniorConversations.destinationId)
|
|
1508
1573
|
).where(
|
|
1509
|
-
|
|
1510
|
-
|
|
1574
|
+
and5(
|
|
1575
|
+
eq5(juniorConversations.source, "slack"),
|
|
1511
1576
|
isNull2(juniorConversations.parentConversationId),
|
|
1512
1577
|
isNull2(juniorConversations.transcriptPurgedAt),
|
|
1513
1578
|
ne(juniorConversations.conversationId, args.currentConversationId),
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1579
|
+
eq5(juniorDestinations.provider, args.scope.provider),
|
|
1580
|
+
eq5(juniorDestinations.providerTenantId, args.scope.providerTenantId),
|
|
1581
|
+
eq5(juniorDestinations.visibility, "public"),
|
|
1582
|
+
eq5(juniorConversationEvents.type, "message"),
|
|
1518
1583
|
sql5`${role} in ('user', 'assistant')`,
|
|
1519
1584
|
sql5`to_tsvector('english', ${text}) @@ ${tsquery}`
|
|
1520
1585
|
)
|
|
@@ -1546,12 +1611,13 @@ var current;
|
|
|
1546
1611
|
function createDb(args) {
|
|
1547
1612
|
return createJuniorSqlExecutor({
|
|
1548
1613
|
connectionString: args.databaseUrl,
|
|
1549
|
-
driver: args.driver
|
|
1614
|
+
driver: args.driver,
|
|
1615
|
+
statementTimeoutMs: args.statementTimeoutMs
|
|
1550
1616
|
});
|
|
1551
1617
|
}
|
|
1552
1618
|
function getSqlExecutor() {
|
|
1553
1619
|
const { sql: sql6 } = getChatConfig();
|
|
1554
|
-
if (current?.databaseUrl !== sql6.databaseUrl || current.driver !== sql6.driver) {
|
|
1620
|
+
if (current?.databaseUrl !== sql6.databaseUrl || current.driver !== sql6.driver || current.statementTimeoutMs !== sql6.statementTimeoutMs) {
|
|
1555
1621
|
if (current) {
|
|
1556
1622
|
const previous = current;
|
|
1557
1623
|
current = void 0;
|
|
@@ -1559,11 +1625,13 @@ function getSqlExecutor() {
|
|
|
1559
1625
|
}
|
|
1560
1626
|
const db = createDb({
|
|
1561
1627
|
databaseUrl: sql6.databaseUrl,
|
|
1562
|
-
driver: sql6.driver
|
|
1628
|
+
driver: sql6.driver,
|
|
1629
|
+
statementTimeoutMs: sql6.statementTimeoutMs
|
|
1563
1630
|
});
|
|
1564
1631
|
current = {
|
|
1565
1632
|
databaseUrl: sql6.databaseUrl,
|
|
1566
1633
|
driver: sql6.driver,
|
|
1634
|
+
statementTimeoutMs: sql6.statementTimeoutMs,
|
|
1567
1635
|
db,
|
|
1568
1636
|
store: createSqlStore(db),
|
|
1569
1637
|
eventStore: createSqlConversationEventStore(db),
|
|
@@ -1599,6 +1667,8 @@ export {
|
|
|
1599
1667
|
requireSlackDestination,
|
|
1600
1668
|
sameDestination,
|
|
1601
1669
|
parseSessionSource,
|
|
1670
|
+
bindProviderConversation,
|
|
1671
|
+
locationFromRow,
|
|
1602
1672
|
instructionProvenanceFor,
|
|
1603
1673
|
contextProvenance,
|
|
1604
1674
|
sameActorIdentity,
|