@sentry/junior 0.108.0 → 0.109.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-NU5HK3PS.js → agent-hooks-FHHVLNPA.js} +12 -12
- package/dist/api/conversations/events.d.ts +1 -1
- package/dist/api/conversations/schema.d.ts +57 -6
- package/dist/api/schema.js +1 -1
- package/dist/api.js +108 -22
- package/dist/app.d.ts +1 -0
- package/dist/app.js +1481 -420
- package/dist/{catalog-runtime-FOFNPR3P.js → catalog-runtime-DMGJSLV2.js} +6 -4
- package/dist/chat/conversations/sql/store.d.ts +0 -7
- package/dist/chat/log-context.d.ts +40 -0
- package/dist/chat/logging.d.ts +3 -26
- package/dist/chat/runtime/slack-resume.d.ts +2 -2
- package/dist/chat/services/turn-session-record.d.ts +0 -2
- package/dist/chat/slack/reply.d.ts +7 -19
- package/dist/chat/state/conversation.d.ts +1 -0
- package/dist/chat/task-execution/slack-work.d.ts +2 -2
- package/dist/chunk-3SXUV423.js +10 -0
- package/dist/{chunk-3RGQLX2F.js → chunk-72OMGPDS.js} +1010 -26
- package/dist/{chunk-2XXEKR44.js → chunk-7Q6WCISF.js} +1 -1
- package/dist/{chunk-TE4QHJH4.js → chunk-FENLIFJD.js} +72 -591
- package/dist/{chunk-XKB7LGIW.js → chunk-FWJRXN4F.js} +3 -3
- package/dist/{chunk-PUAMO4PI.js → chunk-HHVY4SMP.js} +41 -7
- package/dist/{chunk-B5I5LMSP.js → chunk-HO5NT6OE.js} +5 -7
- package/dist/{chunk-O24R4DCK.js → chunk-ISMWX44P.js} +93 -55
- package/dist/{chunk-7FBGKXPE.js → chunk-IVVGFRQQ.js} +5 -0
- package/dist/{chunk-KPMPQ6AA.js → chunk-IXKSQGIO.js} +90 -100
- package/dist/{chunk-SS67LUOK.js → chunk-JNAVF45E.js} +6 -7
- package/dist/{chunk-DY7TRYB5.js → chunk-MGUMR35T.js} +1 -1
- package/dist/{chunk-A5CO2EHL.js → chunk-MXW4GL53.js} +11 -15
- package/dist/{chunk-RT5BUHR5.js → chunk-O3JMSZLI.js} +1 -1
- package/dist/chunk-OCD3OZRK.js +125 -0
- package/dist/{chunk-H3QYZL7K.js → chunk-OUHNWH46.js} +28 -3
- package/dist/{chunk-VIXFG2VC.js → chunk-PLB7MRCQ.js} +1 -2
- package/dist/{chunk-UD6THJ2I.js → chunk-QY636HZU.js} +114 -12
- package/dist/{chunk-VH6KWKG2.js → chunk-RGX4V75M.js} +3 -3
- package/dist/{chunk-B7PUBQQM.js → chunk-SYAQIR5Z.js} +1 -1
- package/dist/chunk-TMBRFULF.js +471 -0
- package/dist/{chunk-YIPD3L6L.js → chunk-TT6GMXNA.js} +8 -10
- package/dist/{chunk-YT72TOEK.js → chunk-WHMOBKT7.js} +2 -2
- package/dist/cli/chat.js +23 -23
- package/dist/cli/check.js +8 -6
- package/dist/cli/plugins.js +16 -16
- package/dist/cli/snapshot-warmup.js +10 -9
- package/dist/cli/upgrade.js +314 -3505
- package/dist/db/db.d.ts +1 -1
- package/dist/{db-AMRBAT5D.js → db-V3NU72O2.js} +8 -6
- package/dist/instrumentation.js +3 -2
- package/dist/nitro.js +5 -4
- package/dist/{runner-TQH5GAJ4.js → runner-JYBCQBLK.js} +17 -20
- package/dist/{skills-ITNHBARB.js → skills-U6MDAST7.js} +7 -5
- package/dist/{validation-AGQ46ZGV.js → validation-72N3JVRU.js} +7 -5
- package/dist/version.d.ts +2 -0
- package/dist/version.js +7 -0
- package/migrations/0006_drop_legacy_conversation_messages.sql +1 -0
- package/migrations/README.md +12 -9
- package/migrations/meta/0006_snapshot.json +948 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +9 -5
- package/dist/chunk-AHJR2IFF.js +0 -115
- package/dist/chunk-G3E7SCME.js +0 -28
- package/dist/chunk-J3B3FPP2.js +0 -1061
- package/dist/chunk-TWINAEZQ.js +0 -1283
|
@@ -1,239 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createJuniorSqlExecutor,
|
|
3
|
+
juniorConversationEvents,
|
|
4
|
+
juniorConversations,
|
|
5
|
+
juniorIdentities,
|
|
6
|
+
juniorUsers
|
|
7
|
+
} from "./chunk-TMBRFULF.js";
|
|
1
8
|
import {
|
|
2
9
|
getChatConfig,
|
|
3
10
|
modelProfileSchema
|
|
4
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-JNAVF45E.js";
|
|
5
12
|
import {
|
|
6
|
-
juniorDestinations
|
|
7
|
-
timestamptz
|
|
13
|
+
juniorDestinations
|
|
8
14
|
} from "./chunk-VFUK3X5B.js";
|
|
9
15
|
import {
|
|
10
16
|
parseDestination,
|
|
11
17
|
sameDestination
|
|
12
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-SYAQIR5Z.js";
|
|
13
19
|
import {
|
|
14
20
|
normalizeIdentityEmail
|
|
15
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-ISMWX44P.js";
|
|
16
22
|
|
|
17
23
|
// src/chat/conversations/sql/store.ts
|
|
18
24
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
19
|
-
import { and as and2, asc, desc, eq as eq2, isNull, sql as
|
|
25
|
+
import { and as and2, asc, desc, eq as eq2, isNull, sql as sql2 } from "drizzle-orm";
|
|
20
26
|
|
|
21
27
|
// src/chat/identities/sql.ts
|
|
22
28
|
import { randomUUID } from "crypto";
|
|
23
|
-
import { and, eq, sql
|
|
24
|
-
|
|
25
|
-
// src/db/schema/conversation-events.ts
|
|
26
|
-
import {
|
|
27
|
-
foreignKey,
|
|
28
|
-
index as index3,
|
|
29
|
-
integer as integer2,
|
|
30
|
-
jsonb as jsonb3,
|
|
31
|
-
pgTable as pgTable4,
|
|
32
|
-
primaryKey,
|
|
33
|
-
text as text4,
|
|
34
|
-
uniqueIndex as uniqueIndex3
|
|
35
|
-
} from "drizzle-orm/pg-core";
|
|
36
|
-
import { sql as sql3 } from "drizzle-orm";
|
|
37
|
-
|
|
38
|
-
// src/db/schema/conversations.ts
|
|
39
|
-
import { sql as sql2 } from "drizzle-orm";
|
|
40
|
-
import {
|
|
41
|
-
index as index2,
|
|
42
|
-
integer,
|
|
43
|
-
jsonb as jsonb2,
|
|
44
|
-
pgTable as pgTable3,
|
|
45
|
-
text as text3
|
|
46
|
-
} from "drizzle-orm/pg-core";
|
|
47
|
-
|
|
48
|
-
// src/db/schema/identities.ts
|
|
49
|
-
import { sql } from "drizzle-orm";
|
|
50
|
-
import {
|
|
51
|
-
boolean,
|
|
52
|
-
index,
|
|
53
|
-
jsonb,
|
|
54
|
-
pgTable as pgTable2,
|
|
55
|
-
text as text2,
|
|
56
|
-
uniqueIndex as uniqueIndex2
|
|
57
|
-
} from "drizzle-orm/pg-core";
|
|
58
|
-
|
|
59
|
-
// src/db/schema/users.ts
|
|
60
|
-
import { text, pgTable, uniqueIndex } from "drizzle-orm/pg-core";
|
|
61
|
-
var juniorUsers = pgTable(
|
|
62
|
-
"junior_users",
|
|
63
|
-
{
|
|
64
|
-
id: text("id").primaryKey(),
|
|
65
|
-
primaryEmail: text("primary_email").notNull(),
|
|
66
|
-
primaryEmailNormalized: text("primary_email_normalized").notNull(),
|
|
67
|
-
displayName: text("display_name"),
|
|
68
|
-
createdAt: timestamptz("created_at").notNull(),
|
|
69
|
-
updatedAt: timestamptz("updated_at").notNull()
|
|
70
|
-
},
|
|
71
|
-
(table) => [
|
|
72
|
-
uniqueIndex("junior_users_primary_email_normalized_uidx").on(
|
|
73
|
-
table.primaryEmailNormalized
|
|
74
|
-
)
|
|
75
|
-
]
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// src/db/schema/identities.ts
|
|
79
|
-
var juniorIdentities = pgTable2(
|
|
80
|
-
"junior_identities",
|
|
81
|
-
{
|
|
82
|
-
id: text2("id").primaryKey(),
|
|
83
|
-
kind: text2("kind").$type().notNull(),
|
|
84
|
-
provider: text2("provider").notNull(),
|
|
85
|
-
providerTenantId: text2("provider_tenant_id").notNull().default(""),
|
|
86
|
-
providerSubjectId: text2("provider_subject_id").notNull(),
|
|
87
|
-
displayName: text2("display_name"),
|
|
88
|
-
handle: text2("handle"),
|
|
89
|
-
email: text2("email"),
|
|
90
|
-
avatarUrl: text2("avatar_url"),
|
|
91
|
-
metadata: jsonb("metadata_json"),
|
|
92
|
-
createdAt: timestamptz("created_at").notNull(),
|
|
93
|
-
updatedAt: timestamptz("updated_at").notNull(),
|
|
94
|
-
userId: text2("user_id").references(() => juniorUsers.id),
|
|
95
|
-
emailNormalized: text2("email_normalized"),
|
|
96
|
-
emailVerified: boolean("email_verified").notNull().default(false)
|
|
97
|
-
},
|
|
98
|
-
(table) => [
|
|
99
|
-
uniqueIndex2("junior_identities_provider_subject_uidx").on(
|
|
100
|
-
table.provider,
|
|
101
|
-
table.providerTenantId,
|
|
102
|
-
table.providerSubjectId
|
|
103
|
-
),
|
|
104
|
-
index("junior_identities_user_idx").on(table.userId),
|
|
105
|
-
index("junior_identities_verified_email_idx").on(table.emailNormalized).where(
|
|
106
|
-
sql`${table.emailVerified} = true AND ${table.emailNormalized} IS NOT NULL`
|
|
107
|
-
),
|
|
108
|
-
index("junior_identities_kind_provider_idx").on(table.kind, table.provider)
|
|
109
|
-
]
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
// src/db/schema/conversations.ts
|
|
113
|
-
var juniorConversations = pgTable3(
|
|
114
|
-
"junior_conversations",
|
|
115
|
-
{
|
|
116
|
-
conversationId: text3("conversation_id").primaryKey(),
|
|
117
|
-
schemaVersion: integer("schema_version").notNull().default(1),
|
|
118
|
-
source: text3("source").$type(),
|
|
119
|
-
originType: text3("origin_type"),
|
|
120
|
-
originId: text3("origin_id"),
|
|
121
|
-
originRunId: text3("origin_run_id"),
|
|
122
|
-
destinationId: text3("destination_id").references(
|
|
123
|
-
() => juniorDestinations.id
|
|
124
|
-
),
|
|
125
|
-
destination: jsonb2("destination_json").$type(),
|
|
126
|
-
actorIdentityId: text3("actor_identity_id").references(
|
|
127
|
-
() => juniorIdentities.id
|
|
128
|
-
),
|
|
129
|
-
creatorIdentityId: text3("creator_identity_id").references(
|
|
130
|
-
() => juniorIdentities.id
|
|
131
|
-
),
|
|
132
|
-
credentialSubjectIdentityId: text3(
|
|
133
|
-
"credential_subject_identity_id"
|
|
134
|
-
).references(() => juniorIdentities.id),
|
|
135
|
-
actor: jsonb2("actor_json").$type(),
|
|
136
|
-
channelName: text3("channel_name"),
|
|
137
|
-
title: text3("title"),
|
|
138
|
-
createdAt: timestamptz("created_at").notNull(),
|
|
139
|
-
lastActivityAt: timestamptz("last_activity_at").notNull(),
|
|
140
|
-
updatedAt: timestamptz("updated_at").notNull(),
|
|
141
|
-
executionUpdatedAt: timestamptz("execution_updated_at"),
|
|
142
|
-
executionStatus: text3("execution_status").$type().notNull(),
|
|
143
|
-
runId: text3("run_id"),
|
|
144
|
-
lastCheckpointAt: timestamptz("last_checkpoint_at"),
|
|
145
|
-
lastEnqueuedAt: timestamptz("last_enqueued_at"),
|
|
146
|
-
// Subagent runs are child conversations; top-level listings filter
|
|
147
|
-
// parent_conversation_id IS NULL. Historical advisor children use this too.
|
|
148
|
-
parentConversationId: text3("parent_conversation_id").references(
|
|
149
|
-
() => juniorConversations.conversationId
|
|
150
|
-
),
|
|
151
|
-
transcriptPurgedAt: timestamptz("transcript_purged_at"),
|
|
152
|
-
durationMs: integer("duration_ms").notNull().default(0),
|
|
153
|
-
usage: jsonb2("usage_json").$type(),
|
|
154
|
-
executionDurationMs: integer("execution_duration_ms").notNull().default(0),
|
|
155
|
-
executionUsage: jsonb2("execution_usage_json").$type(),
|
|
156
|
-
metricRunId: text3("metric_run_id"),
|
|
157
|
-
archivedAt: timestamptz("archived_at")
|
|
158
|
-
},
|
|
159
|
-
(table) => [
|
|
160
|
-
index2("junior_conversations_last_activity_idx").on(
|
|
161
|
-
table.lastActivityAt.desc(),
|
|
162
|
-
table.conversationId
|
|
163
|
-
),
|
|
164
|
-
index2("junior_conversations_active_idx").using(
|
|
165
|
-
"btree",
|
|
166
|
-
sql2`coalesce(${table.executionUpdatedAt}, ${table.updatedAt})`,
|
|
167
|
-
table.conversationId
|
|
168
|
-
).where(sql2`${table.executionStatus} <> 'idle'`),
|
|
169
|
-
index2("junior_conversations_destination_activity_idx").on(
|
|
170
|
-
table.destinationId,
|
|
171
|
-
table.lastActivityAt.desc()
|
|
172
|
-
),
|
|
173
|
-
index2("junior_conversations_actor_activity_idx").on(
|
|
174
|
-
table.actorIdentityId,
|
|
175
|
-
table.lastActivityAt.desc()
|
|
176
|
-
),
|
|
177
|
-
index2("junior_conversations_origin_idx").on(
|
|
178
|
-
table.originType,
|
|
179
|
-
table.originId,
|
|
180
|
-
table.lastActivityAt.desc()
|
|
181
|
-
),
|
|
182
|
-
index2("junior_conversations_parent_idx").on(table.parentConversationId)
|
|
183
|
-
]
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
// src/db/schema/conversation-events.ts
|
|
187
|
-
var juniorConversationEvents = pgTable4(
|
|
188
|
-
"junior_conversation_events",
|
|
189
|
-
{
|
|
190
|
-
conversationId: text4("conversation_id").notNull(),
|
|
191
|
-
seq: integer2("seq").notNull(),
|
|
192
|
-
historyVersion: integer2("history_version").notNull(),
|
|
193
|
-
schemaVersion: integer2("schema_version").default(1).notNull(),
|
|
194
|
-
idempotencyKey: text4("idempotency_key"),
|
|
195
|
-
type: text4("type").notNull(),
|
|
196
|
-
payload: jsonb3("payload").$type().notNull(),
|
|
197
|
-
createdAt: timestamptz("created_at").notNull()
|
|
198
|
-
},
|
|
199
|
-
(table) => [
|
|
200
|
-
primaryKey({
|
|
201
|
-
name: "junior_conversation_events_conversation_id_seq_pk",
|
|
202
|
-
columns: [table.conversationId, table.seq]
|
|
203
|
-
}),
|
|
204
|
-
foreignKey({
|
|
205
|
-
name: "junior_conversation_events_conversation_id_junior_conversations_conversation_id_fk",
|
|
206
|
-
columns: [table.conversationId],
|
|
207
|
-
foreignColumns: [juniorConversations.conversationId]
|
|
208
|
-
}),
|
|
209
|
-
index3("junior_conversation_events_history_version_idx").on(
|
|
210
|
-
table.conversationId,
|
|
211
|
-
table.historyVersion,
|
|
212
|
-
table.seq
|
|
213
|
-
),
|
|
214
|
-
index3("junior_conversation_events_type_idx").on(
|
|
215
|
-
table.conversationId,
|
|
216
|
-
table.type,
|
|
217
|
-
table.seq
|
|
218
|
-
),
|
|
219
|
-
index3("junior_conversation_events_message_search_idx").using("gin", sql3`to_tsvector('english', ${table.payload}->>'text')`).where(sql3`${table.type} = 'message'`),
|
|
220
|
-
uniqueIndex3("junior_conversation_events_idempotency_idx").on(
|
|
221
|
-
table.conversationId,
|
|
222
|
-
table.idempotencyKey
|
|
223
|
-
)
|
|
224
|
-
]
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
// src/db/schema.ts
|
|
228
|
-
var juniorSqlSchema = {
|
|
229
|
-
juniorConversationEvents,
|
|
230
|
-
juniorConversations,
|
|
231
|
-
juniorDestinations,
|
|
232
|
-
juniorIdentities,
|
|
233
|
-
juniorUsers
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
// src/chat/identities/sql.ts
|
|
29
|
+
import { and, eq, sql } from "drizzle-orm";
|
|
237
30
|
function dateFromMs(ms) {
|
|
238
31
|
return new Date(ms);
|
|
239
32
|
}
|
|
@@ -251,8 +44,8 @@ async function upsertUser(executor, args) {
|
|
|
251
44
|
}).onConflictDoUpdate({
|
|
252
45
|
target: juniorUsers.primaryEmailNormalized,
|
|
253
46
|
set: {
|
|
254
|
-
displayName:
|
|
255
|
-
updatedAt:
|
|
47
|
+
displayName: sql`coalesce(${juniorUsers.displayName}, excluded.display_name)`,
|
|
48
|
+
updatedAt: sql`excluded.updated_at`
|
|
256
49
|
}
|
|
257
50
|
}).returning({ id: juniorUsers.id });
|
|
258
51
|
const id = rows[0]?.id;
|
|
@@ -313,16 +106,16 @@ async function upsertIdentity(executor, identity, nowMs = Date.now()) {
|
|
|
313
106
|
juniorIdentities.providerSubjectId
|
|
314
107
|
],
|
|
315
108
|
set: {
|
|
316
|
-
kind:
|
|
317
|
-
userId:
|
|
318
|
-
displayName:
|
|
319
|
-
handle:
|
|
320
|
-
email:
|
|
321
|
-
emailNormalized:
|
|
322
|
-
emailVerified:
|
|
323
|
-
avatarUrl:
|
|
324
|
-
metadata:
|
|
325
|
-
updatedAt:
|
|
109
|
+
kind: sql`excluded.kind`,
|
|
110
|
+
userId: sql`coalesce(${juniorIdentities.userId}, excluded.user_id)`,
|
|
111
|
+
displayName: sql`coalesce(${juniorIdentities.displayName}, excluded.display_name)`,
|
|
112
|
+
handle: sql`coalesce(${juniorIdentities.handle}, excluded.handle)`,
|
|
113
|
+
email: sql`case when ${juniorIdentities.emailVerified} then coalesce(${juniorIdentities.email}, excluded.email) when excluded.email_verified then excluded.email else coalesce(${juniorIdentities.email}, excluded.email) end`,
|
|
114
|
+
emailNormalized: sql`case when ${juniorIdentities.emailVerified} then coalesce(${juniorIdentities.emailNormalized}, excluded.email_normalized) when excluded.email_verified then excluded.email_normalized else coalesce(${juniorIdentities.emailNormalized}, excluded.email_normalized) end`,
|
|
115
|
+
emailVerified: sql`${juniorIdentities.emailVerified} OR excluded.email_verified`,
|
|
116
|
+
avatarUrl: sql`coalesce(${juniorIdentities.avatarUrl}, excluded.avatar_url)`,
|
|
117
|
+
metadata: sql`coalesce(${juniorIdentities.metadata}, excluded.metadata_json)`,
|
|
118
|
+
updatedAt: sql`excluded.updated_at`
|
|
326
119
|
}
|
|
327
120
|
}).returning({
|
|
328
121
|
id: juniorIdentities.id,
|
|
@@ -712,63 +505,6 @@ var SqlStore = class {
|
|
|
712
505
|
}
|
|
713
506
|
});
|
|
714
507
|
}
|
|
715
|
-
/** Copy one conversation record and retained metrics into SQL during backfill. */
|
|
716
|
-
async backfillConversation(sourceConversation, metrics) {
|
|
717
|
-
const { visibility: _visibility, ...conversation } = sourceConversation;
|
|
718
|
-
await this.withConversationMutation(
|
|
719
|
-
conversation.conversationId,
|
|
720
|
-
async () => {
|
|
721
|
-
const existing = await this.get({
|
|
722
|
-
conversationId: conversation.conversationId
|
|
723
|
-
});
|
|
724
|
-
const sourceExecutionAtMs = conversation.execution.updatedAtMs ?? conversation.updatedAtMs;
|
|
725
|
-
const existingExecutionAtMs = existing === void 0 ? void 0 : existing.execution.updatedAtMs ?? existing.updatedAtMs;
|
|
726
|
-
const refreshExecutionFromSource = existingExecutionAtMs === void 0 || sourceExecutionAtMs >= existingExecutionAtMs;
|
|
727
|
-
const mergedConversation = existing ? {
|
|
728
|
-
...conversation,
|
|
729
|
-
channelName: existing.channelName ?? conversation.channelName,
|
|
730
|
-
createdAtMs: Math.min(
|
|
731
|
-
existing.createdAtMs,
|
|
732
|
-
conversation.createdAtMs
|
|
733
|
-
),
|
|
734
|
-
destination: existing.destination ?? conversation.destination,
|
|
735
|
-
lastActivityAtMs: Math.max(
|
|
736
|
-
existing.lastActivityAtMs,
|
|
737
|
-
conversation.lastActivityAtMs
|
|
738
|
-
),
|
|
739
|
-
actor: existing.actor ?? conversation.actor,
|
|
740
|
-
source: existing.source ?? conversation.source,
|
|
741
|
-
title: existing.title ?? conversation.title,
|
|
742
|
-
updatedAtMs: Math.max(
|
|
743
|
-
existing.updatedAtMs,
|
|
744
|
-
conversation.updatedAtMs
|
|
745
|
-
),
|
|
746
|
-
execution: refreshExecutionFromSource ? conversation.execution : existing.execution
|
|
747
|
-
} : conversation;
|
|
748
|
-
await this.upsertConversation({ conversation: mergedConversation });
|
|
749
|
-
if (metrics) {
|
|
750
|
-
await this.executor.db().update(juniorConversations).set({
|
|
751
|
-
durationMs: metrics.durationMs,
|
|
752
|
-
usage: metrics.usage ?? null,
|
|
753
|
-
...refreshExecutionFromSource ? {
|
|
754
|
-
metricRunId: conversation.execution.runId ?? null,
|
|
755
|
-
executionDurationMs: metrics.executionDurationMs,
|
|
756
|
-
executionUsage: metrics.executionUsage ?? null
|
|
757
|
-
} : {}
|
|
758
|
-
}).where(
|
|
759
|
-
and2(
|
|
760
|
-
eq2(
|
|
761
|
-
juniorConversations.conversationId,
|
|
762
|
-
conversation.conversationId
|
|
763
|
-
),
|
|
764
|
-
eq2(juniorConversations.durationMs, 0),
|
|
765
|
-
isNull(juniorConversations.usage)
|
|
766
|
-
)
|
|
767
|
-
);
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
508
|
async listByActivity(args = {}) {
|
|
773
509
|
const rows = await this.executor.db().select({
|
|
774
510
|
conversation: juniorConversations,
|
|
@@ -838,9 +574,9 @@ var SqlStore = class {
|
|
|
838
574
|
/** Upsert the conversation row while preserving previously discovered nullable metadata fields. */
|
|
839
575
|
async upsertConversation(args) {
|
|
840
576
|
const { conversation } = args;
|
|
841
|
-
const incomingExecutionVersion =
|
|
842
|
-
const currentExecutionVersion =
|
|
843
|
-
const incomingExecutionIsFresh =
|
|
577
|
+
const incomingExecutionVersion = sql2`coalesce(excluded.execution_updated_at, excluded.updated_at)`;
|
|
578
|
+
const currentExecutionVersion = sql2`coalesce(${juniorConversations.executionUpdatedAt}, ${juniorConversations.updatedAt})`;
|
|
579
|
+
const incomingExecutionIsFresh = sql2`${incomingExecutionVersion} >= ${currentExecutionVersion}`;
|
|
844
580
|
const destinationId = await this.upsertDestination(
|
|
845
581
|
destinationUpsertFromDestination({
|
|
846
582
|
channelName: conversation.channelName,
|
|
@@ -883,24 +619,24 @@ var SqlStore = class {
|
|
|
883
619
|
}).onConflictDoUpdate({
|
|
884
620
|
target: juniorConversations.conversationId,
|
|
885
621
|
set: {
|
|
886
|
-
source:
|
|
887
|
-
originType:
|
|
888
|
-
originId:
|
|
889
|
-
originRunId:
|
|
890
|
-
destinationId:
|
|
891
|
-
actorIdentityId:
|
|
892
|
-
creatorIdentityId:
|
|
893
|
-
credentialSubjectIdentityId:
|
|
894
|
-
channelName:
|
|
895
|
-
title:
|
|
896
|
-
createdAt:
|
|
897
|
-
lastActivityAt:
|
|
898
|
-
updatedAt:
|
|
899
|
-
executionUpdatedAt:
|
|
900
|
-
executionStatus:
|
|
901
|
-
runId:
|
|
902
|
-
lastCheckpointAt:
|
|
903
|
-
lastEnqueuedAt:
|
|
622
|
+
source: sql2`coalesce(excluded.source, ${juniorConversations.source})`,
|
|
623
|
+
originType: sql2`coalesce(excluded.origin_type, ${juniorConversations.originType})`,
|
|
624
|
+
originId: sql2`coalesce(excluded.origin_id, ${juniorConversations.originId})`,
|
|
625
|
+
originRunId: sql2`coalesce(excluded.origin_run_id, ${juniorConversations.originRunId})`,
|
|
626
|
+
destinationId: sql2`coalesce(excluded.destination_id, ${juniorConversations.destinationId})`,
|
|
627
|
+
actorIdentityId: sql2`coalesce(excluded.actor_identity_id, ${juniorConversations.actorIdentityId})`,
|
|
628
|
+
creatorIdentityId: sql2`coalesce(excluded.creator_identity_id, ${juniorConversations.creatorIdentityId})`,
|
|
629
|
+
credentialSubjectIdentityId: sql2`coalesce(excluded.credential_subject_identity_id, ${juniorConversations.credentialSubjectIdentityId})`,
|
|
630
|
+
channelName: sql2`coalesce(excluded.channel_name, ${juniorConversations.channelName})`,
|
|
631
|
+
title: sql2`coalesce(excluded.title, ${juniorConversations.title})`,
|
|
632
|
+
createdAt: sql2`least(${juniorConversations.createdAt}, excluded.created_at)`,
|
|
633
|
+
lastActivityAt: sql2`greatest(${juniorConversations.lastActivityAt}, excluded.last_activity_at)`,
|
|
634
|
+
updatedAt: sql2`greatest(${juniorConversations.updatedAt}, excluded.updated_at)`,
|
|
635
|
+
executionUpdatedAt: sql2`case when ${incomingExecutionIsFresh} then excluded.execution_updated_at else ${juniorConversations.executionUpdatedAt} end`,
|
|
636
|
+
executionStatus: sql2`case when ${incomingExecutionIsFresh} then excluded.execution_status else ${juniorConversations.executionStatus} end`,
|
|
637
|
+
runId: sql2`case when ${incomingExecutionIsFresh} then excluded.run_id else ${juniorConversations.runId} end`,
|
|
638
|
+
lastCheckpointAt: sql2`case when ${incomingExecutionIsFresh} then coalesce(excluded.last_checkpoint_at, ${juniorConversations.lastCheckpointAt}) else ${juniorConversations.lastCheckpointAt} end`,
|
|
639
|
+
lastEnqueuedAt: sql2`case when ${incomingExecutionIsFresh} then coalesce(excluded.last_enqueued_at, ${juniorConversations.lastEnqueuedAt}) else ${juniorConversations.lastEnqueuedAt} end`
|
|
904
640
|
}
|
|
905
641
|
});
|
|
906
642
|
}
|
|
@@ -908,7 +644,7 @@ var SqlStore = class {
|
|
|
908
644
|
if (!destination) {
|
|
909
645
|
return void 0;
|
|
910
646
|
}
|
|
911
|
-
const visibilityUpdate = destination.refreshVisibility ?
|
|
647
|
+
const visibilityUpdate = destination.refreshVisibility ? sql2`excluded.visibility` : juniorDestinations.visibility;
|
|
912
648
|
const rows = await this.executor.db().insert(juniorDestinations).values({
|
|
913
649
|
id: randomUUID2(),
|
|
914
650
|
provider: destination.provider,
|
|
@@ -928,14 +664,14 @@ var SqlStore = class {
|
|
|
928
664
|
juniorDestinations.providerDestinationId
|
|
929
665
|
],
|
|
930
666
|
set: {
|
|
931
|
-
kind:
|
|
932
|
-
displayName:
|
|
667
|
+
kind: sql2`excluded.kind`,
|
|
668
|
+
displayName: sql2`coalesce(excluded.display_name, ${juniorDestinations.displayName})`,
|
|
933
669
|
// Signal-less writes insert as private but must not clobber an
|
|
934
670
|
// existing public/private value. Live source signals refresh this
|
|
935
671
|
// field so converted channels converge on the next message.
|
|
936
672
|
visibility: visibilityUpdate,
|
|
937
|
-
metadata:
|
|
938
|
-
updatedAt:
|
|
673
|
+
metadata: sql2`coalesce(excluded.metadata_json, ${juniorDestinations.metadata})`,
|
|
674
|
+
updatedAt: sql2`excluded.updated_at`
|
|
939
675
|
}
|
|
940
676
|
}).returning({ id: juniorDestinations.id });
|
|
941
677
|
return rows[0]?.id;
|
|
@@ -955,7 +691,7 @@ import {
|
|
|
955
691
|
inArray,
|
|
956
692
|
isNotNull,
|
|
957
693
|
lte,
|
|
958
|
-
sql as
|
|
694
|
+
sql as sql4
|
|
959
695
|
} from "drizzle-orm";
|
|
960
696
|
|
|
961
697
|
// src/chat/conversations/history.ts
|
|
@@ -1244,7 +980,7 @@ var newConversationEventSchema = z2.object({
|
|
|
1244
980
|
}).strict();
|
|
1245
981
|
|
|
1246
982
|
// src/chat/conversations/sql/conversation-row.ts
|
|
1247
|
-
import { sql as
|
|
983
|
+
import { sql as sql3 } from "drizzle-orm";
|
|
1248
984
|
async function ensureConversationRow(executor, conversationId, atMs) {
|
|
1249
985
|
const at = new Date(atMs);
|
|
1250
986
|
await executor.db().insert(juniorConversations).values({
|
|
@@ -1256,8 +992,8 @@ async function ensureConversationRow(executor, conversationId, atMs) {
|
|
|
1256
992
|
}).onConflictDoUpdate({
|
|
1257
993
|
target: juniorConversations.conversationId,
|
|
1258
994
|
set: {
|
|
1259
|
-
lastActivityAt:
|
|
1260
|
-
updatedAt:
|
|
995
|
+
lastActivityAt: sql3`greatest(${juniorConversations.lastActivityAt}, excluded.last_activity_at)`,
|
|
996
|
+
updatedAt: sql3`greatest(${juniorConversations.updatedAt}, excluded.updated_at)`,
|
|
1261
997
|
transcriptPurgedAt: null
|
|
1262
998
|
}
|
|
1263
999
|
});
|
|
@@ -1471,8 +1207,8 @@ var SqlConversationEventStore = class {
|
|
|
1471
1207
|
/** Read the next sequence and active model-history version. */
|
|
1472
1208
|
async readCursor(conversationId) {
|
|
1473
1209
|
const rows = await this.executor.db().select({
|
|
1474
|
-
maxSeq:
|
|
1475
|
-
maxHistoryVersion:
|
|
1210
|
+
maxSeq: sql4`max(${juniorConversationEvents.seq})`,
|
|
1211
|
+
maxHistoryVersion: sql4`max(${juniorConversationEvents.historyVersion})`
|
|
1476
1212
|
}).from(juniorConversationEvents).where(eq3(juniorConversationEvents.conversationId, conversationId));
|
|
1477
1213
|
const maxSeq = rows[0]?.maxSeq;
|
|
1478
1214
|
const maxHistoryVersion = rows[0]?.maxHistoryVersion;
|
|
@@ -1487,7 +1223,7 @@ function createSqlConversationEventStore(executor) {
|
|
|
1487
1223
|
}
|
|
1488
1224
|
|
|
1489
1225
|
// src/chat/conversations/sql/search.ts
|
|
1490
|
-
import { and as and4, desc as desc3, eq as eq4, isNull as isNull2, ne, sql as
|
|
1226
|
+
import { and as and4, desc as desc3, eq as eq4, isNull as isNull2, ne, sql as sql5 } from "drizzle-orm";
|
|
1491
1227
|
var SqlConversationSearchStore = class {
|
|
1492
1228
|
constructor(executor) {
|
|
1493
1229
|
this.executor = executor;
|
|
@@ -1495,12 +1231,12 @@ var SqlConversationSearchStore = class {
|
|
|
1495
1231
|
executor;
|
|
1496
1232
|
async search(args) {
|
|
1497
1233
|
const db = this.executor.db();
|
|
1498
|
-
const tsquery =
|
|
1499
|
-
const
|
|
1500
|
-
const rank =
|
|
1501
|
-
const excerpt =
|
|
1502
|
-
const role =
|
|
1503
|
-
const messageId =
|
|
1234
|
+
const tsquery = sql5`websearch_to_tsquery('english', ${args.query})`;
|
|
1235
|
+
const text = sql5`${juniorConversationEvents.payload}->>'text'`;
|
|
1236
|
+
const rank = sql5`ts_rank_cd(to_tsvector('english', ${text}), ${tsquery})`;
|
|
1237
|
+
const excerpt = sql5`ts_headline('english', ${text}, ${tsquery}, 'MaxFragments=2, MinWords=8, MaxWords=40, FragmentDelimiter=" … ", StartSel=**, StopSel=**')`;
|
|
1238
|
+
const role = sql5`${juniorConversationEvents.payload}->>'role'`;
|
|
1239
|
+
const messageId = sql5`${juniorConversationEvents.payload}->>'messageId'`;
|
|
1504
1240
|
const bestPerConversation = db.selectDistinctOn([juniorConversations.conversationId], {
|
|
1505
1241
|
conversationId: juniorConversations.conversationId,
|
|
1506
1242
|
excerpt: excerpt.as("excerpt"),
|
|
@@ -1529,8 +1265,8 @@ var SqlConversationSearchStore = class {
|
|
|
1529
1265
|
eq4(juniorDestinations.providerTenantId, args.scope.providerTenantId),
|
|
1530
1266
|
eq4(juniorDestinations.visibility, "public"),
|
|
1531
1267
|
eq4(juniorConversationEvents.type, "message"),
|
|
1532
|
-
|
|
1533
|
-
|
|
1268
|
+
sql5`${role} in ('user', 'assistant')`,
|
|
1269
|
+
sql5`to_tsvector('english', ${text}) @@ ${tsquery}`
|
|
1534
1270
|
)
|
|
1535
1271
|
).orderBy(
|
|
1536
1272
|
juniorConversations.conversationId,
|
|
@@ -1555,252 +1291,6 @@ function createSqlConversationSearchStore(executor) {
|
|
|
1555
1291
|
return new SqlConversationSearchStore(executor);
|
|
1556
1292
|
}
|
|
1557
1293
|
|
|
1558
|
-
// src/db/neon.ts
|
|
1559
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
1560
|
-
import {
|
|
1561
|
-
Pool
|
|
1562
|
-
} from "@neondatabase/serverless";
|
|
1563
|
-
import { drizzle } from "drizzle-orm/neon-serverless";
|
|
1564
|
-
import { migrate } from "drizzle-orm/neon-serverless/migrator";
|
|
1565
|
-
var NeonExecutor = class {
|
|
1566
|
-
constructor(pool) {
|
|
1567
|
-
this.pool = pool;
|
|
1568
|
-
}
|
|
1569
|
-
pool;
|
|
1570
|
-
transactionClient = new AsyncLocalStorage();
|
|
1571
|
-
savepointId = 0;
|
|
1572
|
-
db() {
|
|
1573
|
-
return drizzle(this.queryClient(), {
|
|
1574
|
-
schema: juniorSqlSchema
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
async execute(statement, params = []) {
|
|
1578
|
-
await this.queryClient().query(statement, [...params]);
|
|
1579
|
-
}
|
|
1580
|
-
async query(statement, params = []) {
|
|
1581
|
-
const result = await this.queryClient().query(statement, [
|
|
1582
|
-
...params
|
|
1583
|
-
]);
|
|
1584
|
-
return result.rows;
|
|
1585
|
-
}
|
|
1586
|
-
async migrate(config) {
|
|
1587
|
-
await migrate(
|
|
1588
|
-
drizzle(this.queryClient(), { schema: juniorSqlSchema }),
|
|
1589
|
-
config
|
|
1590
|
-
);
|
|
1591
|
-
}
|
|
1592
|
-
async transaction(callback) {
|
|
1593
|
-
const existingClient = this.transactionClient.getStore();
|
|
1594
|
-
if (existingClient) {
|
|
1595
|
-
const savepoint = `junior_savepoint_${++this.savepointId}`;
|
|
1596
|
-
await existingClient.query(`SAVEPOINT ${savepoint}`);
|
|
1597
|
-
try {
|
|
1598
|
-
const result = await callback();
|
|
1599
|
-
await existingClient.query(`RELEASE SAVEPOINT ${savepoint}`);
|
|
1600
|
-
return result;
|
|
1601
|
-
} catch (error) {
|
|
1602
|
-
await existingClient.query(`ROLLBACK TO SAVEPOINT ${savepoint}`);
|
|
1603
|
-
await existingClient.query(`RELEASE SAVEPOINT ${savepoint}`);
|
|
1604
|
-
throw error;
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
const client = await this.pool.connect();
|
|
1608
|
-
try {
|
|
1609
|
-
await client.query("BEGIN");
|
|
1610
|
-
const result = await this.transactionClient.run(client, callback);
|
|
1611
|
-
await client.query("COMMIT");
|
|
1612
|
-
return result;
|
|
1613
|
-
} catch (error) {
|
|
1614
|
-
await client.query("ROLLBACK");
|
|
1615
|
-
throw error;
|
|
1616
|
-
} finally {
|
|
1617
|
-
client.release();
|
|
1618
|
-
}
|
|
1619
|
-
}
|
|
1620
|
-
async withLock(lockName, callback) {
|
|
1621
|
-
if (!lockName) {
|
|
1622
|
-
throw new Error("SQL lock name is required");
|
|
1623
|
-
}
|
|
1624
|
-
const existingClient = this.transactionClient.getStore();
|
|
1625
|
-
if (existingClient) {
|
|
1626
|
-
await existingClient.query("SELECT pg_advisory_xact_lock(hashtext($1))", [
|
|
1627
|
-
lockName
|
|
1628
|
-
]);
|
|
1629
|
-
return await callback();
|
|
1630
|
-
}
|
|
1631
|
-
const client = await this.pool.connect();
|
|
1632
|
-
try {
|
|
1633
|
-
await client.query("BEGIN");
|
|
1634
|
-
return await this.transactionClient.run(client, async () => {
|
|
1635
|
-
try {
|
|
1636
|
-
await client.query("SELECT pg_advisory_xact_lock(hashtext($1))", [
|
|
1637
|
-
lockName
|
|
1638
|
-
]);
|
|
1639
|
-
const result = await callback();
|
|
1640
|
-
await client.query("COMMIT");
|
|
1641
|
-
return result;
|
|
1642
|
-
} catch (error) {
|
|
1643
|
-
await client.query("ROLLBACK");
|
|
1644
|
-
throw error;
|
|
1645
|
-
}
|
|
1646
|
-
});
|
|
1647
|
-
} finally {
|
|
1648
|
-
client.release();
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
async withMigrationLock(migrationTable, callback) {
|
|
1652
|
-
const client = await this.pool.connect();
|
|
1653
|
-
const lockName = `junior:migrate:${migrationTable}`;
|
|
1654
|
-
try {
|
|
1655
|
-
await client.query("SELECT pg_advisory_lock(hashtext($1))", [lockName]);
|
|
1656
|
-
return await callback();
|
|
1657
|
-
} finally {
|
|
1658
|
-
client.release(true);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
async close() {
|
|
1662
|
-
await this.pool.end();
|
|
1663
|
-
}
|
|
1664
|
-
queryClient() {
|
|
1665
|
-
return this.transactionClient.getStore() ?? this.pool;
|
|
1666
|
-
}
|
|
1667
|
-
};
|
|
1668
|
-
function createNeonJuniorSqlExecutor(args) {
|
|
1669
|
-
return new NeonExecutor(
|
|
1670
|
-
new Pool({
|
|
1671
|
-
connectionString: args.connectionString,
|
|
1672
|
-
max: 3
|
|
1673
|
-
})
|
|
1674
|
-
);
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
// src/db/postgres.ts
|
|
1678
|
-
import { AsyncLocalStorage as AsyncLocalStorage2 } from "async_hooks";
|
|
1679
|
-
import pg from "pg";
|
|
1680
|
-
import { drizzle as drizzle2 } from "drizzle-orm/node-postgres";
|
|
1681
|
-
import { migrate as migrate2 } from "drizzle-orm/node-postgres/migrator";
|
|
1682
|
-
var { Pool: Pool2 } = pg;
|
|
1683
|
-
var PostgresExecutor = class {
|
|
1684
|
-
constructor(pool) {
|
|
1685
|
-
this.pool = pool;
|
|
1686
|
-
}
|
|
1687
|
-
pool;
|
|
1688
|
-
transactionClient = new AsyncLocalStorage2();
|
|
1689
|
-
savepointId = 0;
|
|
1690
|
-
db() {
|
|
1691
|
-
return drizzle2(this.queryClient(), {
|
|
1692
|
-
schema: juniorSqlSchema
|
|
1693
|
-
});
|
|
1694
|
-
}
|
|
1695
|
-
async execute(statement, params = []) {
|
|
1696
|
-
await this.queryClient().query(statement, [...params]);
|
|
1697
|
-
}
|
|
1698
|
-
async query(statement, params = []) {
|
|
1699
|
-
const result = await this.queryClient().query(statement, [
|
|
1700
|
-
...params
|
|
1701
|
-
]);
|
|
1702
|
-
return result.rows;
|
|
1703
|
-
}
|
|
1704
|
-
async migrate(config) {
|
|
1705
|
-
await migrate2(
|
|
1706
|
-
drizzle2(this.queryClient(), { schema: juniorSqlSchema }),
|
|
1707
|
-
config
|
|
1708
|
-
);
|
|
1709
|
-
}
|
|
1710
|
-
async transaction(callback) {
|
|
1711
|
-
const existingClient = this.transactionClient.getStore();
|
|
1712
|
-
if (existingClient) {
|
|
1713
|
-
const savepoint = `junior_savepoint_${++this.savepointId}`;
|
|
1714
|
-
await existingClient.query(`SAVEPOINT ${savepoint}`);
|
|
1715
|
-
try {
|
|
1716
|
-
const result = await callback();
|
|
1717
|
-
await existingClient.query(`RELEASE SAVEPOINT ${savepoint}`);
|
|
1718
|
-
return result;
|
|
1719
|
-
} catch (error) {
|
|
1720
|
-
await existingClient.query(`ROLLBACK TO SAVEPOINT ${savepoint}`);
|
|
1721
|
-
await existingClient.query(`RELEASE SAVEPOINT ${savepoint}`);
|
|
1722
|
-
throw error;
|
|
1723
|
-
}
|
|
1724
|
-
}
|
|
1725
|
-
const client = await this.pool.connect();
|
|
1726
|
-
try {
|
|
1727
|
-
await client.query("BEGIN");
|
|
1728
|
-
const result = await this.transactionClient.run(client, callback);
|
|
1729
|
-
await client.query("COMMIT");
|
|
1730
|
-
return result;
|
|
1731
|
-
} catch (error) {
|
|
1732
|
-
await client.query("ROLLBACK");
|
|
1733
|
-
throw error;
|
|
1734
|
-
} finally {
|
|
1735
|
-
client.release();
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
async withLock(lockName, callback) {
|
|
1739
|
-
if (!lockName) {
|
|
1740
|
-
throw new Error("SQL lock name is required");
|
|
1741
|
-
}
|
|
1742
|
-
const existingClient = this.transactionClient.getStore();
|
|
1743
|
-
if (existingClient) {
|
|
1744
|
-
await existingClient.query("SELECT pg_advisory_xact_lock(hashtext($1))", [
|
|
1745
|
-
lockName
|
|
1746
|
-
]);
|
|
1747
|
-
return await callback();
|
|
1748
|
-
}
|
|
1749
|
-
const client = await this.pool.connect();
|
|
1750
|
-
try {
|
|
1751
|
-
await client.query("BEGIN");
|
|
1752
|
-
return await this.transactionClient.run(client, async () => {
|
|
1753
|
-
try {
|
|
1754
|
-
await client.query("SELECT pg_advisory_xact_lock(hashtext($1))", [
|
|
1755
|
-
lockName
|
|
1756
|
-
]);
|
|
1757
|
-
const result = await callback();
|
|
1758
|
-
await client.query("COMMIT");
|
|
1759
|
-
return result;
|
|
1760
|
-
} catch (error) {
|
|
1761
|
-
await client.query("ROLLBACK");
|
|
1762
|
-
throw error;
|
|
1763
|
-
}
|
|
1764
|
-
});
|
|
1765
|
-
} finally {
|
|
1766
|
-
client.release();
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
async withMigrationLock(migrationTable, callback) {
|
|
1770
|
-
const client = await this.pool.connect();
|
|
1771
|
-
const lockName = `junior:migrate:${migrationTable}`;
|
|
1772
|
-
try {
|
|
1773
|
-
await client.query("SELECT pg_advisory_lock(hashtext($1))", [lockName]);
|
|
1774
|
-
return await callback();
|
|
1775
|
-
} finally {
|
|
1776
|
-
client.release(true);
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
async close() {
|
|
1780
|
-
await this.pool.end();
|
|
1781
|
-
}
|
|
1782
|
-
queryClient() {
|
|
1783
|
-
return this.transactionClient.getStore() ?? this.pool;
|
|
1784
|
-
}
|
|
1785
|
-
};
|
|
1786
|
-
function createPostgresJuniorSqlExecutor(args) {
|
|
1787
|
-
return new PostgresExecutor(
|
|
1788
|
-
new Pool2({
|
|
1789
|
-
application_name: args.applicationName,
|
|
1790
|
-
connectionString: args.connectionString,
|
|
1791
|
-
max: 3
|
|
1792
|
-
})
|
|
1793
|
-
);
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
|
-
// src/db/executor.ts
|
|
1797
|
-
function createJuniorSqlExecutor(args) {
|
|
1798
|
-
if (args.driver === "postgres") {
|
|
1799
|
-
return createPostgresJuniorSqlExecutor(args);
|
|
1800
|
-
}
|
|
1801
|
-
return createNeonJuniorSqlExecutor(args);
|
|
1802
|
-
}
|
|
1803
|
-
|
|
1804
1294
|
// src/chat/db.ts
|
|
1805
1295
|
var current;
|
|
1806
1296
|
function createDb(args) {
|
|
@@ -1810,20 +1300,20 @@ function createDb(args) {
|
|
|
1810
1300
|
});
|
|
1811
1301
|
}
|
|
1812
1302
|
function getSqlExecutor() {
|
|
1813
|
-
const { sql:
|
|
1814
|
-
if (current?.databaseUrl !==
|
|
1303
|
+
const { sql: sql6 } = getChatConfig();
|
|
1304
|
+
if (current?.databaseUrl !== sql6.databaseUrl || current.driver !== sql6.driver) {
|
|
1815
1305
|
if (current) {
|
|
1816
1306
|
const previous = current;
|
|
1817
1307
|
current = void 0;
|
|
1818
1308
|
void previous.db.close().catch(() => void 0);
|
|
1819
1309
|
}
|
|
1820
1310
|
const db = createDb({
|
|
1821
|
-
databaseUrl:
|
|
1822
|
-
driver:
|
|
1311
|
+
databaseUrl: sql6.databaseUrl,
|
|
1312
|
+
driver: sql6.driver
|
|
1823
1313
|
});
|
|
1824
1314
|
current = {
|
|
1825
|
-
databaseUrl:
|
|
1826
|
-
driver:
|
|
1315
|
+
databaseUrl: sql6.databaseUrl,
|
|
1316
|
+
driver: sql6.driver,
|
|
1827
1317
|
db,
|
|
1828
1318
|
store: createSqlStore(db),
|
|
1829
1319
|
eventStore: createSqlConversationEventStore(db),
|
|
@@ -1854,22 +1344,13 @@ async function closeDb() {
|
|
|
1854
1344
|
}
|
|
1855
1345
|
|
|
1856
1346
|
export {
|
|
1857
|
-
juniorUsers,
|
|
1858
|
-
juniorIdentities,
|
|
1859
|
-
juniorConversations,
|
|
1860
|
-
juniorConversationEvents,
|
|
1861
|
-
createSqlStore,
|
|
1862
|
-
conversationMessageProvenanceSchema,
|
|
1863
1347
|
instructionProvenanceFor,
|
|
1864
1348
|
contextProvenance,
|
|
1865
1349
|
instructionActors,
|
|
1866
|
-
conversationEventDataSchema,
|
|
1867
1350
|
decodeStoredConversationEvent,
|
|
1868
|
-
newConversationEventSchema,
|
|
1869
1351
|
sanitizePostgresJson,
|
|
1870
1352
|
withConversationEventLock,
|
|
1871
1353
|
createSqlConversationEventStore,
|
|
1872
|
-
createJuniorSqlExecutor,
|
|
1873
1354
|
getSqlExecutor,
|
|
1874
1355
|
getDb,
|
|
1875
1356
|
getConversationStore,
|