@sentry/junior 0.74.0 → 0.75.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-2HEB4C3Q.js +33 -0
- package/dist/api-reference.d.ts +1 -1
- package/dist/app.js +5211 -5316
- package/dist/build/copy-build-content.d.ts +1 -1
- package/dist/chat/agent-dispatch/context.d.ts +2 -3
- package/dist/chat/agent-dispatch/types.d.ts +2 -1
- package/dist/chat/config.d.ts +2 -0
- package/dist/chat/conversations/configured.d.ts +2 -0
- package/dist/chat/credentials/subject.d.ts +3 -3
- package/dist/chat/plugins/agent-hooks.d.ts +13 -13
- package/dist/chat/plugins/credential-hooks.d.ts +6 -6
- package/dist/chat/plugins/db.d.ts +31 -0
- package/dist/chat/plugins/logging.d.ts +2 -2
- package/dist/chat/plugins/package-discovery.d.ts +2 -1
- package/dist/chat/plugins/registry.d.ts +4 -0
- package/dist/chat/plugins/state.d.ts +3 -5
- package/dist/chat/plugins/types.d.ts +1 -0
- package/dist/chat/plugins/validation.d.ts +5 -0
- package/dist/chat/prompt.d.ts +11 -1
- package/dist/chat/respond.d.ts +10 -1
- package/dist/chat/runtime/slack-runtime.d.ts +6 -1
- package/dist/chat/sandbox/egress-credentials.d.ts +8 -8
- package/dist/chat/sandbox/sandbox.d.ts +2 -2
- package/dist/chat/sql/db.d.ts +3 -0
- package/dist/chat/sql/executor.d.ts +7 -0
- package/dist/chat/sql/neon.d.ts +2 -4
- package/dist/chat/sql/postgres.d.ts +6 -0
- package/dist/chat/task-execution/state.d.ts +7 -2
- package/dist/chat/task-execution/worker.d.ts +1 -1
- package/dist/chat/tools/agent-tools.d.ts +2 -2
- package/dist/chat/tools/types.d.ts +3 -0
- package/dist/{chunk-7Q5YOUUT.js → chunk-2RWFUS5F.js} +47 -10
- package/dist/{chunk-YRDS7VKO.js → chunk-62FUNJYS.js} +3 -54
- package/dist/{chunk-M4FLLXXD.js → chunk-74HO27II.js} +1 -1
- package/dist/chunk-BNJIEFQC.js +115 -0
- package/dist/{chunk-YOHFWWBV.js → chunk-C3AM4Z4J.js} +1 -103
- package/dist/chunk-D7NFH5GD.js +570 -0
- package/dist/chunk-EE6PJWY4.js +130 -0
- package/dist/{chunk-CYUI7JU5.js → chunk-EIYL7I4S.js} +1 -1
- package/dist/{chunk-GM7HTXYC.js → chunk-FCZO7LAR.js} +13 -2
- package/dist/{chunk-2LUZA3LY.js → chunk-JEELK46E.js} +5 -5
- package/dist/chunk-MCMROINU.js +12 -0
- package/dist/chunk-NPVUAXUE.js +694 -0
- package/dist/{chunk-OR6NQJ5E.js → chunk-OJODNL2P.js} +3 -3
- package/dist/{chunk-3BYAPS6B.js → chunk-OK4KKR7B.js} +1 -11
- package/dist/chunk-OZSPLAQ4.js +71 -0
- package/dist/{chunk-KVZL5NZS.js → chunk-Q3XNY442.js} +17 -7
- package/dist/{chunk-SQGMG7OD.js → chunk-TQ74BATR.js} +100 -58
- package/dist/{chunk-JL2SLRAT.js → chunk-UJ7OTHPO.js} +76 -312
- package/dist/{chunk-HYHKTFG2.js → chunk-VNTLUFTY.js} +80 -843
- package/dist/chunk-WBZ4M5N5.js +59 -0
- package/dist/{chunk-6UP2Z2RZ.js → chunk-XJHDZUGD.js} +7 -7
- package/dist/chunk-Y2CM7HXH.js +111 -0
- package/dist/{chunk-F6HWCPOC.js → chunk-ZNNTSPNF.js} +1 -1
- package/dist/cli/chat.js +52 -2
- package/dist/cli/check.js +6 -5
- package/dist/cli/snapshot-warmup.js +10 -9
- package/dist/cli/upgrade.js +256 -16
- package/dist/db-A3ILH67H.js +20 -0
- package/dist/handlers/sandbox-egress-route.d.ts +4 -0
- package/dist/handlers/slack-webhook.d.ts +4 -0
- package/dist/handlers/webhooks.d.ts +6 -13
- package/dist/nitro.js +34 -89
- package/dist/plugin-module.d.ts +21 -0
- package/dist/plugins-OMJKLRJ2.js +13 -0
- package/dist/plugins.d.ts +6 -4
- package/dist/registry-NLZFIW23.js +46 -0
- package/dist/reporting/conversations.d.ts +3 -3
- package/dist/reporting.d.ts +6 -5
- package/dist/reporting.js +23 -17
- package/dist/{runner-27NP2TEO.js → runner-LUQZ5G67.js} +18 -13
- package/dist/validation-VMCPP3YO.js +15 -0
- package/package.json +11 -9
|
@@ -1,276 +1,31 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseDestination,
|
|
3
3
|
sameDestination
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WBZ4M5N5.js";
|
|
5
|
+
import {
|
|
6
|
+
juniorConversations,
|
|
7
|
+
juniorDestinations,
|
|
8
|
+
juniorIdentities
|
|
9
|
+
} from "./chunk-D7NFH5GD.js";
|
|
5
10
|
import {
|
|
6
11
|
getDefaultRedisStateAdapterFor,
|
|
7
12
|
getStateAdapter
|
|
8
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ZNNTSPNF.js";
|
|
9
14
|
import {
|
|
10
15
|
getChatConfig
|
|
11
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-FCZO7LAR.js";
|
|
12
17
|
import {
|
|
13
18
|
parseStoredSlackRequester
|
|
14
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-EIYL7I4S.js";
|
|
15
20
|
import {
|
|
16
21
|
isRecord,
|
|
17
22
|
toOptionalNumber,
|
|
18
23
|
toOptionalString
|
|
19
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-OK4KKR7B.js";
|
|
20
25
|
|
|
21
26
|
// src/chat/state/ttl.ts
|
|
22
27
|
var JUNIOR_THREAD_STATE_TTL_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
23
28
|
|
|
24
|
-
// src/chat/sql/neon.ts
|
|
25
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
26
|
-
import {
|
|
27
|
-
Pool
|
|
28
|
-
} from "@neondatabase/serverless";
|
|
29
|
-
import { drizzle } from "drizzle-orm/neon-serverless";
|
|
30
|
-
|
|
31
|
-
// src/chat/conversations/sql/schema/conversations.ts
|
|
32
|
-
import { sql } from "drizzle-orm";
|
|
33
|
-
import { index as index3, integer, jsonb as jsonb3, pgTable as pgTable3, text as text3 } from "drizzle-orm/pg-core";
|
|
34
|
-
|
|
35
|
-
// src/chat/conversations/sql/schema/destinations.ts
|
|
36
|
-
import { index, jsonb, pgTable, text, uniqueIndex } from "drizzle-orm/pg-core";
|
|
37
|
-
|
|
38
|
-
// src/chat/conversations/sql/schema/timestamps.ts
|
|
39
|
-
import { timestamp } from "drizzle-orm/pg-core";
|
|
40
|
-
var timestamptz = (name) => timestamp(name, { withTimezone: true });
|
|
41
|
-
|
|
42
|
-
// src/chat/conversations/sql/schema/destinations.ts
|
|
43
|
-
var juniorDestinations = pgTable(
|
|
44
|
-
"junior_destinations",
|
|
45
|
-
{
|
|
46
|
-
id: text("id").primaryKey(),
|
|
47
|
-
provider: text("provider").notNull(),
|
|
48
|
-
providerTenantId: text("provider_tenant_id").notNull().default(""),
|
|
49
|
-
providerDestinationId: text("provider_destination_id").notNull(),
|
|
50
|
-
kind: text("kind").$type().notNull(),
|
|
51
|
-
parentDestinationId: text("parent_destination_id"),
|
|
52
|
-
displayName: text("display_name"),
|
|
53
|
-
visibility: text("visibility").$type().notNull().default("unknown"),
|
|
54
|
-
metadata: jsonb("metadata_json"),
|
|
55
|
-
createdAt: timestamptz("created_at").notNull(),
|
|
56
|
-
updatedAt: timestamptz("updated_at").notNull()
|
|
57
|
-
},
|
|
58
|
-
(table) => [
|
|
59
|
-
uniqueIndex("junior_destinations_provider_destination_uidx").on(
|
|
60
|
-
table.provider,
|
|
61
|
-
table.providerTenantId,
|
|
62
|
-
table.providerDestinationId
|
|
63
|
-
),
|
|
64
|
-
index("junior_destinations_provider_kind_idx").on(
|
|
65
|
-
table.provider,
|
|
66
|
-
table.kind
|
|
67
|
-
)
|
|
68
|
-
]
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
// src/chat/conversations/sql/schema/identities.ts
|
|
72
|
-
import { index as index2, jsonb as jsonb2, pgTable as pgTable2, text as text2, uniqueIndex as uniqueIndex2 } from "drizzle-orm/pg-core";
|
|
73
|
-
var juniorIdentities = pgTable2(
|
|
74
|
-
"junior_identities",
|
|
75
|
-
{
|
|
76
|
-
id: text2("id").primaryKey(),
|
|
77
|
-
kind: text2("kind").$type().notNull(),
|
|
78
|
-
provider: text2("provider").notNull(),
|
|
79
|
-
providerTenantId: text2("provider_tenant_id").notNull().default(""),
|
|
80
|
-
providerSubjectId: text2("provider_subject_id").notNull(),
|
|
81
|
-
displayName: text2("display_name"),
|
|
82
|
-
handle: text2("handle"),
|
|
83
|
-
email: text2("email"),
|
|
84
|
-
avatarUrl: text2("avatar_url"),
|
|
85
|
-
metadata: jsonb2("metadata_json"),
|
|
86
|
-
createdAt: timestamptz("created_at").notNull(),
|
|
87
|
-
updatedAt: timestamptz("updated_at").notNull()
|
|
88
|
-
},
|
|
89
|
-
(table) => [
|
|
90
|
-
uniqueIndex2("junior_identities_provider_subject_uidx").on(
|
|
91
|
-
table.provider,
|
|
92
|
-
table.providerTenantId,
|
|
93
|
-
table.providerSubjectId
|
|
94
|
-
),
|
|
95
|
-
index2("junior_identities_kind_provider_idx").on(table.kind, table.provider)
|
|
96
|
-
]
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
// src/chat/conversations/sql/schema/conversations.ts
|
|
100
|
-
var juniorConversations = pgTable3(
|
|
101
|
-
"junior_conversations",
|
|
102
|
-
{
|
|
103
|
-
conversationId: text3("conversation_id").primaryKey(),
|
|
104
|
-
schemaVersion: integer("schema_version").notNull().default(1),
|
|
105
|
-
source: text3("source").$type(),
|
|
106
|
-
originType: text3("origin_type"),
|
|
107
|
-
originId: text3("origin_id"),
|
|
108
|
-
originRunId: text3("origin_run_id"),
|
|
109
|
-
destinationId: text3("destination_id").references(
|
|
110
|
-
() => juniorDestinations.id
|
|
111
|
-
),
|
|
112
|
-
destination: jsonb3("destination_json").$type(),
|
|
113
|
-
actorIdentityId: text3("actor_identity_id").references(
|
|
114
|
-
() => juniorIdentities.id
|
|
115
|
-
),
|
|
116
|
-
requesterIdentityId: text3("requester_identity_id").references(
|
|
117
|
-
() => juniorIdentities.id
|
|
118
|
-
),
|
|
119
|
-
creatorIdentityId: text3("creator_identity_id").references(
|
|
120
|
-
() => juniorIdentities.id
|
|
121
|
-
),
|
|
122
|
-
credentialSubjectIdentityId: text3(
|
|
123
|
-
"credential_subject_identity_id"
|
|
124
|
-
).references(() => juniorIdentities.id),
|
|
125
|
-
requester: jsonb3("requester_json").$type(),
|
|
126
|
-
channelName: text3("channel_name"),
|
|
127
|
-
title: text3("title"),
|
|
128
|
-
createdAt: timestamptz("created_at").notNull(),
|
|
129
|
-
lastActivityAt: timestamptz("last_activity_at").notNull(),
|
|
130
|
-
updatedAt: timestamptz("updated_at").notNull(),
|
|
131
|
-
executionUpdatedAt: timestamptz("execution_updated_at"),
|
|
132
|
-
executionStatus: text3("execution_status").$type().notNull(),
|
|
133
|
-
runId: text3("run_id"),
|
|
134
|
-
lastCheckpointAt: timestamptz("last_checkpoint_at"),
|
|
135
|
-
lastEnqueuedAt: timestamptz("last_enqueued_at")
|
|
136
|
-
},
|
|
137
|
-
(table) => [
|
|
138
|
-
index3("junior_conversations_last_activity_idx").on(
|
|
139
|
-
table.lastActivityAt.desc(),
|
|
140
|
-
table.conversationId
|
|
141
|
-
),
|
|
142
|
-
index3("junior_conversations_active_idx").using(
|
|
143
|
-
"btree",
|
|
144
|
-
sql`coalesce(${table.executionUpdatedAt}, ${table.updatedAt})`,
|
|
145
|
-
table.conversationId
|
|
146
|
-
).where(sql`${table.executionStatus} <> 'idle'`),
|
|
147
|
-
index3("junior_conversations_destination_activity_idx").on(
|
|
148
|
-
table.destinationId,
|
|
149
|
-
table.lastActivityAt.desc()
|
|
150
|
-
),
|
|
151
|
-
index3("junior_conversations_actor_activity_idx").on(
|
|
152
|
-
table.actorIdentityId,
|
|
153
|
-
table.lastActivityAt.desc()
|
|
154
|
-
),
|
|
155
|
-
index3("junior_conversations_requester_activity_idx").on(
|
|
156
|
-
table.requesterIdentityId,
|
|
157
|
-
table.lastActivityAt.desc()
|
|
158
|
-
),
|
|
159
|
-
index3("junior_conversations_origin_idx").on(
|
|
160
|
-
table.originType,
|
|
161
|
-
table.originId,
|
|
162
|
-
table.lastActivityAt.desc()
|
|
163
|
-
)
|
|
164
|
-
]
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
// src/chat/conversations/sql/schema/migrations.ts
|
|
168
|
-
import { pgTable as pgTable4, text as text4 } from "drizzle-orm/pg-core";
|
|
169
|
-
var juniorSchemaMigrations = pgTable4("junior_schema_migrations", {
|
|
170
|
-
id: text4("id").primaryKey(),
|
|
171
|
-
checksum: text4("checksum").notNull(),
|
|
172
|
-
appliedAt: timestamptz("applied_at").notNull().defaultNow()
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// src/chat/conversations/sql/schema.ts
|
|
176
|
-
var schema = {
|
|
177
|
-
juniorConversations,
|
|
178
|
-
juniorDestinations,
|
|
179
|
-
juniorIdentities,
|
|
180
|
-
juniorSchemaMigrations
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
// src/chat/sql/schema.ts
|
|
184
|
-
var juniorSqlSchema = {
|
|
185
|
-
...schema
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// src/chat/sql/neon.ts
|
|
189
|
-
var NeonExecutor = class {
|
|
190
|
-
constructor(pool) {
|
|
191
|
-
this.pool = pool;
|
|
192
|
-
}
|
|
193
|
-
pool;
|
|
194
|
-
transactionClient = new AsyncLocalStorage();
|
|
195
|
-
db() {
|
|
196
|
-
return drizzle(this.queryClient(), {
|
|
197
|
-
schema: juniorSqlSchema
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
async execute(statement, params = []) {
|
|
201
|
-
await this.queryClient().query(statement, [...params]);
|
|
202
|
-
}
|
|
203
|
-
async query(statement, params = []) {
|
|
204
|
-
const result = await this.queryClient().query(statement, [
|
|
205
|
-
...params
|
|
206
|
-
]);
|
|
207
|
-
return result.rows;
|
|
208
|
-
}
|
|
209
|
-
async transaction(callback) {
|
|
210
|
-
const existingClient = this.transactionClient.getStore();
|
|
211
|
-
if (existingClient) {
|
|
212
|
-
return await callback();
|
|
213
|
-
}
|
|
214
|
-
const client = await this.pool.connect();
|
|
215
|
-
try {
|
|
216
|
-
await client.query("BEGIN");
|
|
217
|
-
const result = await this.transactionClient.run(client, callback);
|
|
218
|
-
await client.query("COMMIT");
|
|
219
|
-
return result;
|
|
220
|
-
} catch (error) {
|
|
221
|
-
await client.query("ROLLBACK");
|
|
222
|
-
throw error;
|
|
223
|
-
} finally {
|
|
224
|
-
client.release();
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
async withLock(lockName, callback) {
|
|
228
|
-
if (!lockName) {
|
|
229
|
-
throw new Error("SQL lock name is required");
|
|
230
|
-
}
|
|
231
|
-
const existingClient = this.transactionClient.getStore();
|
|
232
|
-
if (existingClient) {
|
|
233
|
-
await existingClient.query("SELECT pg_advisory_xact_lock(hashtext($1))", [
|
|
234
|
-
lockName
|
|
235
|
-
]);
|
|
236
|
-
return await callback();
|
|
237
|
-
}
|
|
238
|
-
const client = await this.pool.connect();
|
|
239
|
-
try {
|
|
240
|
-
await client.query("BEGIN");
|
|
241
|
-
return await this.transactionClient.run(client, async () => {
|
|
242
|
-
try {
|
|
243
|
-
await client.query("SELECT pg_advisory_xact_lock(hashtext($1))", [
|
|
244
|
-
lockName
|
|
245
|
-
]);
|
|
246
|
-
const result = await callback();
|
|
247
|
-
await client.query("COMMIT");
|
|
248
|
-
return result;
|
|
249
|
-
} catch (error) {
|
|
250
|
-
await client.query("ROLLBACK");
|
|
251
|
-
throw error;
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
} finally {
|
|
255
|
-
client.release();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
async close() {
|
|
259
|
-
await this.pool.end();
|
|
260
|
-
}
|
|
261
|
-
queryClient() {
|
|
262
|
-
return this.transactionClient.getStore() ?? this.pool;
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
function createNeonJuniorSqlExecutor(args) {
|
|
266
|
-
return new NeonExecutor(
|
|
267
|
-
new Pool({
|
|
268
|
-
connectionString: args.connectionString,
|
|
269
|
-
max: 3
|
|
270
|
-
})
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
29
|
// src/chat/task-execution/state.ts
|
|
275
30
|
import { randomUUID } from "crypto";
|
|
276
31
|
var CONVERSATION_PREFIX = "junior:conversation";
|
|
@@ -339,12 +94,12 @@ function normalizeInput(value) {
|
|
|
339
94
|
if (!isRecord(value)) {
|
|
340
95
|
return void 0;
|
|
341
96
|
}
|
|
342
|
-
const
|
|
343
|
-
if (!
|
|
97
|
+
const text = toOptionalString(value.text);
|
|
98
|
+
if (!text) {
|
|
344
99
|
return void 0;
|
|
345
100
|
}
|
|
346
101
|
return {
|
|
347
|
-
text
|
|
102
|
+
text,
|
|
348
103
|
authorId: toOptionalString(value.authorId),
|
|
349
104
|
attachments: Array.isArray(value.attachments) ? [...value.attachments] : void 0,
|
|
350
105
|
metadata: normalizeMetadata(value.metadata)
|
|
@@ -589,9 +344,9 @@ function parseRedisIndexEntries(values) {
|
|
|
589
344
|
return [];
|
|
590
345
|
}
|
|
591
346
|
const entries = [];
|
|
592
|
-
for (let
|
|
593
|
-
const conversationId = toOptionalString(values[
|
|
594
|
-
const score = typeof values[
|
|
347
|
+
for (let index = 0; index < values.length; index += 2) {
|
|
348
|
+
const conversationId = toOptionalString(values[index]);
|
|
349
|
+
const score = typeof values[index + 1] === "number" ? values[index + 1] : Number(values[index + 1]);
|
|
595
350
|
if (!conversationId || !Number.isFinite(score)) {
|
|
596
351
|
continue;
|
|
597
352
|
}
|
|
@@ -728,16 +483,16 @@ async function getConversationIndexStore(state) {
|
|
|
728
483
|
return emulatedConversationIndexStore(state);
|
|
729
484
|
}
|
|
730
485
|
async function upsertIndexEntry(args) {
|
|
731
|
-
const
|
|
732
|
-
await
|
|
486
|
+
const index = await getConversationIndexStore(args.state);
|
|
487
|
+
await index.upsert({
|
|
733
488
|
conversationId: args.conversationId,
|
|
734
489
|
indexKey: args.indexKey,
|
|
735
490
|
score: args.score
|
|
736
491
|
});
|
|
737
492
|
}
|
|
738
493
|
async function removeIndexEntry(args) {
|
|
739
|
-
const
|
|
740
|
-
await
|
|
494
|
+
const index = await getConversationIndexStore(args.state);
|
|
495
|
+
await index.remove({
|
|
741
496
|
conversationId: args.conversationId,
|
|
742
497
|
indexKey: args.indexKey
|
|
743
498
|
});
|
|
@@ -1088,7 +843,20 @@ async function drainConversationMailbox(args) {
|
|
|
1088
843
|
if (pending.length === 0) {
|
|
1089
844
|
return [];
|
|
1090
845
|
}
|
|
1091
|
-
await args.inject(pending);
|
|
846
|
+
const acknowledgedIds = await args.inject(pending);
|
|
847
|
+
const offeredIds = new Set(
|
|
848
|
+
pending.map((message) => message.inboundMessageId)
|
|
849
|
+
);
|
|
850
|
+
for (const inboundMessageId of acknowledgedIds ?? []) {
|
|
851
|
+
if (!offeredIds.has(inboundMessageId)) {
|
|
852
|
+
throw new Error(
|
|
853
|
+
`Conversation mailbox acknowledgement is not pending for ${args.conversationId}`
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
const drainedIds = new Set(
|
|
858
|
+
acknowledgedIds ?? pending.map((message) => message.inboundMessageId)
|
|
859
|
+
);
|
|
1092
860
|
await withConversationMutation(args, async (state) => {
|
|
1093
861
|
const current = await readConversation(state, args.conversationId);
|
|
1094
862
|
if (!current || current.execution.lease?.token !== args.leaseToken) {
|
|
@@ -1096,9 +864,6 @@ async function drainConversationMailbox(args) {
|
|
|
1096
864
|
`Conversation lease is not held for ${args.conversationId}`
|
|
1097
865
|
);
|
|
1098
866
|
}
|
|
1099
|
-
const drainedIds = new Set(
|
|
1100
|
-
pending.map((message) => message.inboundMessageId)
|
|
1101
|
-
);
|
|
1102
867
|
const pendingMessages2 = current.execution.pendingMessages.filter(
|
|
1103
868
|
(message) => !drainedIds.has(message.inboundMessageId)
|
|
1104
869
|
);
|
|
@@ -1115,7 +880,7 @@ async function drainConversationMailbox(args) {
|
|
|
1115
880
|
)
|
|
1116
881
|
);
|
|
1117
882
|
});
|
|
1118
|
-
return pending;
|
|
883
|
+
return pending.filter((message) => drainedIds.has(message.inboundMessageId));
|
|
1119
884
|
}
|
|
1120
885
|
async function markConversationMessagesInjected(args) {
|
|
1121
886
|
const nowMs = args.nowMs ?? now();
|
|
@@ -1254,8 +1019,8 @@ async function removeActiveConversation(args) {
|
|
|
1254
1019
|
}
|
|
1255
1020
|
async function listActiveConversationIds(args = {}) {
|
|
1256
1021
|
const state = await getConnectedState(args.state);
|
|
1257
|
-
const
|
|
1258
|
-
const entries = await
|
|
1022
|
+
const index = await getConversationIndexStore(state);
|
|
1023
|
+
const entries = await index.list({
|
|
1259
1024
|
indexKey: CONVERSATION_ACTIVE_INDEX_KEY,
|
|
1260
1025
|
limit: args.limit,
|
|
1261
1026
|
order: "asc",
|
|
@@ -1265,8 +1030,8 @@ async function listActiveConversationIds(args = {}) {
|
|
|
1265
1030
|
}
|
|
1266
1031
|
async function listConversationsByActivity(args = {}) {
|
|
1267
1032
|
const state = await getConnectedState(args.state);
|
|
1268
|
-
const
|
|
1269
|
-
const entries = await
|
|
1033
|
+
const index = await getConversationIndexStore(state);
|
|
1034
|
+
const entries = await index.list({
|
|
1270
1035
|
indexKey: CONVERSATION_BY_ACTIVITY_INDEX_KEY,
|
|
1271
1036
|
limit: args.limit ?? CONVERSATION_ACTIVITY_INDEX_MAX_LENGTH,
|
|
1272
1037
|
offset: args.offset,
|
|
@@ -1306,7 +1071,7 @@ function createStateConversationStore(state) {
|
|
|
1306
1071
|
|
|
1307
1072
|
// src/chat/conversations/sql/store.ts
|
|
1308
1073
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1309
|
-
import { asc, desc, eq, sql
|
|
1074
|
+
import { asc, desc, eq, sql } from "drizzle-orm";
|
|
1310
1075
|
|
|
1311
1076
|
// src/chat/conversations/sql/migrations.ts
|
|
1312
1077
|
import { createHash } from "crypto";
|
|
@@ -1803,9 +1568,9 @@ var SqlStore = class {
|
|
|
1803
1568
|
/** Upsert the conversation row while preserving previously discovered nullable metadata fields. */
|
|
1804
1569
|
async upsertConversation(args) {
|
|
1805
1570
|
const { conversation } = args;
|
|
1806
|
-
const incomingExecutionVersion =
|
|
1807
|
-
const currentExecutionVersion =
|
|
1808
|
-
const incomingExecutionIsFresh =
|
|
1571
|
+
const incomingExecutionVersion = sql`coalesce(excluded.execution_updated_at, excluded.updated_at)`;
|
|
1572
|
+
const currentExecutionVersion = sql`coalesce(${juniorConversations.executionUpdatedAt}, ${juniorConversations.updatedAt})`;
|
|
1573
|
+
const incomingExecutionIsFresh = sql`${incomingExecutionVersion} >= ${currentExecutionVersion}`;
|
|
1809
1574
|
const destinationId = await this.upsertDestination(
|
|
1810
1575
|
destinationUpsertFromDestination({
|
|
1811
1576
|
channelName: conversation.channelName,
|
|
@@ -1849,27 +1614,27 @@ var SqlStore = class {
|
|
|
1849
1614
|
}).onConflictDoUpdate({
|
|
1850
1615
|
target: juniorConversations.conversationId,
|
|
1851
1616
|
set: {
|
|
1852
|
-
source:
|
|
1853
|
-
originType:
|
|
1854
|
-
originId:
|
|
1855
|
-
originRunId:
|
|
1856
|
-
destinationId:
|
|
1857
|
-
destination:
|
|
1858
|
-
actorIdentityId:
|
|
1859
|
-
requesterIdentityId:
|
|
1860
|
-
creatorIdentityId:
|
|
1861
|
-
credentialSubjectIdentityId:
|
|
1862
|
-
requester:
|
|
1863
|
-
channelName:
|
|
1864
|
-
title:
|
|
1865
|
-
createdAt:
|
|
1866
|
-
lastActivityAt:
|
|
1867
|
-
updatedAt:
|
|
1868
|
-
executionUpdatedAt:
|
|
1869
|
-
executionStatus:
|
|
1870
|
-
runId:
|
|
1871
|
-
lastCheckpointAt:
|
|
1872
|
-
lastEnqueuedAt:
|
|
1617
|
+
source: sql`coalesce(excluded.source, ${juniorConversations.source})`,
|
|
1618
|
+
originType: sql`coalesce(excluded.origin_type, ${juniorConversations.originType})`,
|
|
1619
|
+
originId: sql`coalesce(excluded.origin_id, ${juniorConversations.originId})`,
|
|
1620
|
+
originRunId: sql`coalesce(excluded.origin_run_id, ${juniorConversations.originRunId})`,
|
|
1621
|
+
destinationId: sql`coalesce(excluded.destination_id, ${juniorConversations.destinationId})`,
|
|
1622
|
+
destination: sql`coalesce(excluded.destination_json, ${juniorConversations.destination})`,
|
|
1623
|
+
actorIdentityId: sql`coalesce(excluded.actor_identity_id, ${juniorConversations.actorIdentityId})`,
|
|
1624
|
+
requesterIdentityId: sql`coalesce(excluded.requester_identity_id, ${juniorConversations.requesterIdentityId})`,
|
|
1625
|
+
creatorIdentityId: sql`coalesce(excluded.creator_identity_id, ${juniorConversations.creatorIdentityId})`,
|
|
1626
|
+
credentialSubjectIdentityId: sql`coalesce(excluded.credential_subject_identity_id, ${juniorConversations.credentialSubjectIdentityId})`,
|
|
1627
|
+
requester: sql`coalesce(excluded.requester_json, ${juniorConversations.requester})`,
|
|
1628
|
+
channelName: sql`coalesce(excluded.channel_name, ${juniorConversations.channelName})`,
|
|
1629
|
+
title: sql`coalesce(excluded.title, ${juniorConversations.title})`,
|
|
1630
|
+
createdAt: sql`least(${juniorConversations.createdAt}, excluded.created_at)`,
|
|
1631
|
+
lastActivityAt: sql`greatest(${juniorConversations.lastActivityAt}, excluded.last_activity_at)`,
|
|
1632
|
+
updatedAt: sql`greatest(${juniorConversations.updatedAt}, excluded.updated_at)`,
|
|
1633
|
+
executionUpdatedAt: sql`case when ${incomingExecutionIsFresh} then excluded.execution_updated_at else ${juniorConversations.executionUpdatedAt} end`,
|
|
1634
|
+
executionStatus: sql`case when ${incomingExecutionIsFresh} then excluded.execution_status else ${juniorConversations.executionStatus} end`,
|
|
1635
|
+
runId: sql`case when ${incomingExecutionIsFresh} then excluded.run_id else ${juniorConversations.runId} end`,
|
|
1636
|
+
lastCheckpointAt: sql`case when ${incomingExecutionIsFresh} then excluded.last_checkpoint_at else ${juniorConversations.lastCheckpointAt} end`,
|
|
1637
|
+
lastEnqueuedAt: sql`case when ${incomingExecutionIsFresh} then excluded.last_enqueued_at else ${juniorConversations.lastEnqueuedAt} end`
|
|
1873
1638
|
}
|
|
1874
1639
|
});
|
|
1875
1640
|
}
|
|
@@ -1897,13 +1662,13 @@ var SqlStore = class {
|
|
|
1897
1662
|
juniorIdentities.providerSubjectId
|
|
1898
1663
|
],
|
|
1899
1664
|
set: {
|
|
1900
|
-
kind:
|
|
1901
|
-
displayName:
|
|
1902
|
-
handle:
|
|
1903
|
-
email:
|
|
1904
|
-
avatarUrl:
|
|
1905
|
-
metadata:
|
|
1906
|
-
updatedAt:
|
|
1665
|
+
kind: sql`excluded.kind`,
|
|
1666
|
+
displayName: sql`coalesce(excluded.display_name, ${juniorIdentities.displayName})`,
|
|
1667
|
+
handle: sql`coalesce(excluded.handle, ${juniorIdentities.handle})`,
|
|
1668
|
+
email: sql`coalesce(excluded.email, ${juniorIdentities.email})`,
|
|
1669
|
+
avatarUrl: sql`coalesce(excluded.avatar_url, ${juniorIdentities.avatarUrl})`,
|
|
1670
|
+
metadata: sql`coalesce(excluded.metadata_json, ${juniorIdentities.metadata})`,
|
|
1671
|
+
updatedAt: sql`excluded.updated_at`
|
|
1907
1672
|
}
|
|
1908
1673
|
}).returning({ id: juniorIdentities.id });
|
|
1909
1674
|
return rows[0]?.id;
|
|
@@ -1931,11 +1696,11 @@ var SqlStore = class {
|
|
|
1931
1696
|
juniorDestinations.providerDestinationId
|
|
1932
1697
|
],
|
|
1933
1698
|
set: {
|
|
1934
|
-
kind:
|
|
1935
|
-
displayName:
|
|
1936
|
-
visibility:
|
|
1937
|
-
metadata:
|
|
1938
|
-
updatedAt:
|
|
1699
|
+
kind: sql`excluded.kind`,
|
|
1700
|
+
displayName: sql`coalesce(excluded.display_name, ${juniorDestinations.displayName})`,
|
|
1701
|
+
visibility: sql`excluded.visibility`,
|
|
1702
|
+
metadata: sql`coalesce(excluded.metadata_json, ${juniorDestinations.metadata})`,
|
|
1703
|
+
updatedAt: sql`excluded.updated_at`
|
|
1939
1704
|
}
|
|
1940
1705
|
}).returning({ id: juniorDestinations.id });
|
|
1941
1706
|
return rows[0]?.id;
|
|
@@ -1947,7 +1712,6 @@ function createSqlStore(executor) {
|
|
|
1947
1712
|
|
|
1948
1713
|
export {
|
|
1949
1714
|
JUNIOR_THREAD_STATE_TTL_MS,
|
|
1950
|
-
createNeonJuniorSqlExecutor,
|
|
1951
1715
|
CONVERSATION_WORK_CHECK_IN_INTERVAL_MS,
|
|
1952
1716
|
CONVERSATION_WORK_STALE_ENQUEUE_MS,
|
|
1953
1717
|
getConversation,
|