@sentry/junior 0.310.0 → 0.312.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{adapter-context-BhKpjpGD.js → adapter-context-BRjEWRy1.js} +2 -2
- package/dist/adapter-iIq7ihf7.js +259 -0
- package/dist/{admin-tgZEZAk2.js → admin-DhInw5K9.js} +1 -2
- package/dist/{agent-runner-D9cvNlQl.js → agent-runner-C9iDurwX.js} +6507 -7721
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +7 -6
- package/dist/api.d.ts +21 -3
- package/dist/api.js +1625 -535
- package/dist/{app-B_7Wn0en.d.ts → app-DRFrC8Mw.d.ts} +14 -10
- package/dist/app.d.ts +2 -2
- package/dist/app.js +454 -994
- package/dist/{background-compaction-queue-BGHqkhkY.js → background-compaction-queue-DrKi7w3d.js} +10 -85
- package/dist/callback-mFlTUWWx.js +75 -0
- package/dist/{catalog-runtime-BxwzbLKY.js → catalog-runtime-D7xapBAX.js} +1 -1
- package/dist/channel-access-CJGfNTdn.js +221 -0
- package/dist/child-message-DcsritGf.js +179 -0
- package/dist/cli/chat.js +18 -19
- package/dist/cli/check.js +23 -29
- package/dist/cli/init.js +1 -7
- package/dist/cli/main.js +3 -7
- package/dist/cli/plugins.js +8 -7
- package/dist/cli/run.d.ts +1 -2
- package/dist/cli/run.js +1 -2
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-Dkt2Le2b.js → config-kXB2Y5tl.js} +294 -28
- package/dist/{continue-in-slack-BWVwePKD.js → continue-in-slack-O6pV5004.js} +7 -7
- package/dist/{conversation-feed-Ci6YD1N-.js → conversation-feed-uNOv_x68.js} +87 -24
- package/dist/{conversation-privacy-C39g8BY4.js → conversation-privacy-L4ja1_W6.js} +1 -1
- package/dist/{conversation-turn-CBlZIH02.js → conversation-turn-CeLbHqdw.js} +56 -49
- package/dist/{credential-sync-vGnrB0BY.js → credential-sync-I8VBGk05.js} +16 -16
- package/dist/{projection-jZSlEAXG.js → credentialed-Cb6E2phL.js} +16268 -16821
- package/dist/{db-B4Hjxr-u.d.ts → db-BbC5stfa.d.ts} +13 -6
- package/dist/{db-CFZggNoy.js → db-LAyyX8tk.js} +1698 -1046
- package/dist/{executor-BPkZDx5-.js → executor-SCub-fAq.js} +552 -181
- package/dist/{html-2r2KmLwi.js → html-BCZ3Xtb_.js} +6 -6
- package/dist/{session-stop-BfY4rhJs.js → ingest-BDf3D50j.js} +2134 -2553
- package/dist/{install-C-oE6C_u.js → install-DCFJFkC0.js} +2 -2
- package/dist/instrumentation.js +4 -4
- package/dist/{lineage-CsvrEFQe.js → lineage-B_m-4TJw.js} +2 -2
- package/dist/{stop-DYzjRf2U.js → list-CN2QA2R9.js} +1656 -685
- package/dist/{logging-D5gkyvnK.js → logging-dQ9ZRGQ8.js} +47 -9
- package/dist/media-CYm1QD8T.js +2356 -0
- package/dist/{message-DwvJ-I3w.js → message-DSXGj1hM.js} +19 -29
- package/dist/{model-input-MAq2881y.js → model-input--TrP9hYV.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-DIF6Li06.js → oauth-callback-server-DHCZC6B4.js} +2 -2
- package/dist/{oauth-relay-DPE-wrwO.js → oauth-relay-pPMGnDZt.js} +1 -1
- package/dist/{registry-BBkWFCl8.js → registry-CZOzddwu.js} +5 -8
- package/dist/{resolve-B38MkHXE.js → resolve-cKOQ14Dh.js} +3 -3
- package/dist/{result-BaqSZcJb.js → result-DcvEOe1r.js} +119 -93
- package/dist/result-event-type-BdIJuZxg.js +48 -0
- package/dist/rule-DAxQY-1h.js +20 -0
- package/dist/{runner-11h8PrHh.js → runner-DBfUW44l.js} +14 -16
- package/dist/{sandbox-egress-signals-CTcACAtJ.js → sandbox-egress-signals-BVF_xAm1.js} +1 -1
- package/dist/{schema-DriSvB40.d.ts → schema-BEHKxr4I.d.ts} +861 -298
- package/dist/{schema-obw5jvR4.js → schema-Bk9Nm2E8.js} +344 -153
- package/dist/{service-account-Bx93N1n1.js → service-account-CVYsFjty.js} +3 -3
- package/dist/{service-account-Zc5bUcIJ.js → service-account-Ts4ulcrV.js} +68 -68
- package/dist/{skills-C8Npu5zO.js → skills-VTnhAJWm.js} +2 -2
- package/dist/{slack-conversation-unfurl-DlRVA02H.js → slack-conversation-unfurl-fuLnF1jE.js} +9 -11
- package/dist/{spawn-CXr58R0x.js → spawn-vxAarlX5.js} +6 -6
- package/dist/start-conversation-CEn2KH1A.js +941 -0
- package/dist/{state-CGrGVeQC.js → state-C1P3_Ywk.js} +4 -4
- package/dist/statuses-_cRJHXK7.js +150 -0
- package/dist/store-DFZaN-Ix.js +492 -0
- package/dist/task-queue-Cx4Lmjyk.js +90 -0
- package/dist/task-runner-CbTwFA6k.js +1432 -0
- package/dist/{thread-context-Dyj1KWaY.js → thread-context-BkAZDTX2.js} +13 -11
- package/dist/thread-state-DhPndWi1.js +5625 -0
- package/dist/{validation-DxVNIxA0.js → validation-nIzMtAVJ.js} +1 -1
- package/dist/{task-queue-CaZffYaH.js → vercel-queue-hW90XzbG.js} +93 -172
- package/dist/{version-Cr7Z71yG.js → version-Brbtz4Qf.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-C6LOZ2d2.js → warmup-BDA5myRK.js} +5832 -4567
- package/dist/web-message-id-C6P83ans.js +10 -0
- package/dist/{worker-CUBtu1Li.js → worker-D63RcaVD.js} +20 -8
- package/migrations/0126_artifact_drop_public.sql +8 -0
- package/migrations/0127_artifact_path.sql +4 -0
- package/migrations/0128_artifact_path_index.sql +1 -0
- package/migrations/0129_review_item_answered_index.sql +1 -0
- package/migrations/0130_review_item_status_index.sql +1 -0
- package/migrations/0131_brief_outcome_status.sql +1 -0
- package/migrations/0132_brief_outcome_status_backfill.sql +7 -0
- package/migrations/0133_brief_created_at_index.sql +1 -0
- package/migrations/0134_slack_person_search_index.sql +1 -0
- package/migrations/0135_code_change_size.sql +3 -0
- package/migrations/0136_merge_conflict_notice_dismiss.sql +16 -0
- package/migrations/0137_inbox_snoozes.sql +27 -0
- package/migrations/0138_code_change_search_index.sql +2 -0
- package/migrations/0139_review_item_owner.sql +22 -0
- package/migrations/0140_review_item_owner_index.sql +1 -0
- package/migrations/0141_memory_core_adoption.sql +89 -0
- package/migrations/0142_memory_core_indexes.sql +17 -0
- package/migrations/0143_todos.sql +14 -0
- package/migrations/0144_inbox_items.sql +32 -0
- package/migrations/0145_todo_changed_by_agent.sql +1 -0
- package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
- package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
- package/migrations/0148_authorization_request_index.sql +1 -0
- package/migrations/0149_conversation_metadata.sql +10 -0
- package/migrations/0150_conversation_metadata_fill.sql +39 -0
- package/migrations/0151_conversation_search_index.sql +1 -0
- package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
- package/migrations/0153_artifact_expiry.sql +1 -0
- package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
- package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
- package/migrations/0156_conversation_kind_lead.sql +6 -0
- package/migrations/0157_conversation_lead_actor_index.sql +1 -0
- package/migrations/meta/0126_snapshot.json +5488 -0
- package/migrations/meta/0127_snapshot.json +5519 -0
- package/migrations/meta/0128_snapshot.json +5519 -0
- package/migrations/meta/0129_snapshot.json +5547 -0
- package/migrations/meta/0130_snapshot.json +5563 -0
- package/migrations/meta/0131_snapshot.json +5569 -0
- package/migrations/meta/0132_snapshot.json +5569 -0
- package/migrations/meta/0133_snapshot.json +5590 -0
- package/migrations/meta/0134_snapshot.json +5606 -0
- package/migrations/meta/0135_snapshot.json +5624 -0
- package/migrations/meta/0136_snapshot.json +5624 -0
- package/migrations/meta/0137_snapshot.json +5864 -0
- package/migrations/meta/0138_snapshot.json +5894 -0
- package/migrations/meta/0139_snapshot.json +5898 -0
- package/migrations/meta/0140_snapshot.json +5919 -0
- package/migrations/meta/0141_snapshot.json +6429 -0
- package/migrations/meta/0142_snapshot.json +6457 -0
- package/migrations/meta/0143_snapshot.json +6434 -0
- package/migrations/meta/0144_snapshot.json +6434 -0
- package/migrations/meta/0145_snapshot.json +6440 -0
- package/migrations/meta/0146_snapshot.json +6446 -0
- package/migrations/meta/0147_snapshot.json +6452 -0
- package/migrations/meta/0148_snapshot.json +6474 -0
- package/migrations/meta/0149_snapshot.json +6490 -0
- package/migrations/meta/0150_snapshot.json +6490 -0
- package/migrations/meta/0151_snapshot.json +6505 -0
- package/migrations/meta/0152_snapshot.json +6505 -0
- package/migrations/meta/0153_snapshot.json +6511 -0
- package/migrations/meta/0154_snapshot.json +6533 -0
- package/migrations/meta/0155_snapshot.json +6511 -0
- package/migrations/meta/0156_snapshot.json +6511 -0
- package/migrations/meta/0157_snapshot.json +6527 -0
- package/migrations/meta/_journal.json +224 -0
- package/package.json +7 -8
- package/skills/design-automation-skill/SKILL.md +108 -0
- package/dist/briefs-DKxkoruh.js +0 -395
- package/dist/conversation-M9KZ5JxF.js +0 -1024
- package/dist/prompt-CaMyeCpA.js +0 -910
- package/dist/schedule-DWxZ3kja.js +0 -1146
- package/dist/store-D4FQ1Nml.js +0 -335
- package/dist/task-runner-Dm7BHbGp.js +0 -287
- package/dist/turn-session-routing-CD0BRCex.js +0 -263
- package/dist/turn-user-message-9IxeEv5v.js +0 -364
- package/dist/users-CaUAYMb3.js +0 -181
- package/dist/viewer-AHldghAD.js +0 -212
- package/dist/web-message-id-BT8Mg8LL.js +0 -418
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { h as logWarn, p as logException } from "./logging-
|
|
1
|
+
import { h as logWarn, p as logException } from "./logging-dQ9ZRGQ8.js";
|
|
2
2
|
import { _ as withScope } from "./sentry-CPbZjomA.js";
|
|
3
|
-
import "./config-
|
|
3
|
+
import "./config-kXB2Y5tl.js";
|
|
4
|
+
import * as z from "zod";
|
|
4
5
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
6
|
+
import { actorSchema, sourceSchema } from "@sentry/junior-plugin-api";
|
|
5
7
|
import { sql } from "drizzle-orm";
|
|
6
8
|
import { bigint, boolean, check, customType, date, doublePrecision, foreignKey, index, integer, jsonb, pgSequence, pgTable, primaryKey, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
|
|
7
|
-
import { embeddingHalfvec, embeddingVector } from "@sentry/junior-plugin-api/embeddings";
|
|
8
9
|
import { Pool as Pool$1, neon } from "@neondatabase/serverless";
|
|
9
10
|
import { drizzle } from "drizzle-orm/neon-serverless";
|
|
10
11
|
import { Agent } from "undici";
|
|
@@ -14,9 +15,9 @@ import { drizzle as drizzle$1 } from "drizzle-orm/node-postgres";
|
|
|
14
15
|
// src/db/schema/timestamps.ts
|
|
15
16
|
const timestamptz = (name) => timestamp(name, { withTimezone: true });
|
|
16
17
|
// src/db/schema/artifacts.ts
|
|
17
|
-
/** Durable metadata for conversation-owned
|
|
18
|
+
/** Durable metadata for conversation-owned artifacts. */
|
|
18
19
|
const juniorArtifacts = pgTable("junior_artifacts", {
|
|
19
|
-
/**
|
|
20
|
+
/** Row identity. A public row serves at `/public/artifacts/<id>.<ext>`. */
|
|
20
21
|
id: text("id").primaryKey(),
|
|
21
22
|
conversationId: text("conversation_id").notNull(),
|
|
22
23
|
sha256: text("sha256").notNull(),
|
|
@@ -24,22 +25,297 @@ const juniorArtifacts = pgTable("junior_artifacts", {
|
|
|
24
25
|
storageKey: text("storage_key").notNull(),
|
|
25
26
|
contentType: text("content_type").notNull(),
|
|
26
27
|
bytes: integer("bytes").notNull(),
|
|
27
|
-
visibility: text("visibility").$type().notNull().default("public"),
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Path under the Sandbox `artifacts/` directory for a live file. Null for
|
|
30
|
+
* a public frozen copy, such as a published image.
|
|
31
31
|
*/
|
|
32
|
-
|
|
32
|
+
path: text("path"),
|
|
33
|
+
visibility: text("visibility").$type().notNull().default("conversation"),
|
|
33
34
|
createdAt: timestamptz("created_at").notNull(),
|
|
34
|
-
/** Set when the artifact
|
|
35
|
-
deleteRequestedAt: timestamptz("delete_requested_at")
|
|
35
|
+
/** Set when the artifact is unpublished or its live file is deleted. */
|
|
36
|
+
deleteRequestedAt: timestamptz("delete_requested_at"),
|
|
37
|
+
/** When a public artifact stops serving. Null serves until unpublished. */
|
|
38
|
+
expiresAt: timestamptz("expires_at")
|
|
36
39
|
}, (table) => [
|
|
37
40
|
check("junior_artifacts_visibility_check", sql`${table.visibility} in ('conversation', 'internal', 'public')`),
|
|
38
|
-
|
|
39
|
-
uniqueIndex("
|
|
41
|
+
check("junior_artifacts_path_visibility_check", sql`(${table.path} is null) = (${table.visibility} = 'public')`),
|
|
42
|
+
uniqueIndex("junior_artifacts_conversation_path_uidx").on(table.conversationId, table.path),
|
|
43
|
+
uniqueIndex("junior_artifacts_permanent_sha_uidx").on(table.conversationId, table.sha256).where(sql`${table.visibility} = 'public' and ${table.expiresAt} is null`),
|
|
40
44
|
index("junior_artifacts_gc_idx").on(table.deleteRequestedAt, table.createdAt),
|
|
41
45
|
index("junior_artifacts_conversation_idx").on(table.conversationId)
|
|
42
46
|
]);
|
|
47
|
+
// src/db/embeddings.ts
|
|
48
|
+
/**
|
|
49
|
+
* Shared parts of the derived embedding indexes. Each owner keeps its own
|
|
50
|
+
* table, so a foreign key still deletes a vector with its source row. These
|
|
51
|
+
* helpers keep the column types, the distance SQL, the batch checks, and the
|
|
52
|
+
* backfill loop the same in every table.
|
|
53
|
+
*/
|
|
54
|
+
function pgvectorColumn(dataType) {
|
|
55
|
+
return customType({
|
|
56
|
+
dataType() {
|
|
57
|
+
return dataType;
|
|
58
|
+
},
|
|
59
|
+
toDriver(value) {
|
|
60
|
+
return JSON.stringify(value);
|
|
61
|
+
},
|
|
62
|
+
fromDriver(value) {
|
|
63
|
+
return value.slice(1, -1).split(",").map(Number);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* pgvector `vector` column without a fixed size, so a new embedding model
|
|
69
|
+
* needs no migration. Each table records the size of each row in its own
|
|
70
|
+
* column.
|
|
71
|
+
*/
|
|
72
|
+
const embeddingVector = pgvectorColumn("vector");
|
|
73
|
+
/**
|
|
74
|
+
* Half-precision `embeddingVector`: 2 bytes per value instead of 4, for
|
|
75
|
+
* tables that hold many vectors.
|
|
76
|
+
*/
|
|
77
|
+
const embeddingHalfvec = pgvectorColumn("halfvec");
|
|
78
|
+
const embeddingResultSchema = z.object({
|
|
79
|
+
costUsd: z.number().finite().nonnegative().optional(),
|
|
80
|
+
dimensions: z.number().int().positive(),
|
|
81
|
+
model: z.string().min(1),
|
|
82
|
+
provider: z.string().min(1),
|
|
83
|
+
vectors: z.array(z.array(z.number().finite()))
|
|
84
|
+
}).strict();
|
|
85
|
+
/**
|
|
86
|
+
* Validate an embedder result: one vector per text, all of the reported
|
|
87
|
+
* size. With `dimensions`, the size must be one that the table accepts. With
|
|
88
|
+
* `expected`, the result must come from that provider and model, because a
|
|
89
|
+
* backfill that finds rows by model would see a row of another model as
|
|
90
|
+
* missing on every run.
|
|
91
|
+
*/
|
|
92
|
+
function parseEmbeddingBatch(raw, args) {
|
|
93
|
+
const result = embeddingResultSchema.parse(raw);
|
|
94
|
+
if (args.dimensions && !args.dimensions.includes(result.dimensions)) throw new Error("Unsupported embedding vector size.");
|
|
95
|
+
if (result.vectors.length !== args.textCount) throw new Error("Embedding provider returned an unexpected vector count.");
|
|
96
|
+
if (result.vectors.some((vector) => vector.length !== result.dimensions)) throw new Error("Embedding provider returned an unexpected vector size.");
|
|
97
|
+
if (args.expected && (result.provider !== args.expected.provider || result.model !== args.expected.model)) throw new Error(`Embedding provider used model ${result.provider}/${result.model}, not ${args.expected.provider}/${args.expected.model}.`);
|
|
98
|
+
return {
|
|
99
|
+
dimensions: result.dimensions,
|
|
100
|
+
model: result.model,
|
|
101
|
+
provider: result.provider,
|
|
102
|
+
vectors: result.vectors
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Embed one text with the embedder's model and return its vector. */
|
|
106
|
+
async function embedText(embedder, input) {
|
|
107
|
+
const batch = parseEmbeddingBatch(await embedder.embedTexts({
|
|
108
|
+
inputType: input.inputType,
|
|
109
|
+
texts: [input.text]
|
|
110
|
+
}), {
|
|
111
|
+
expected: embedder,
|
|
112
|
+
textCount: 1
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
model: batch.model,
|
|
116
|
+
provider: batch.provider,
|
|
117
|
+
vector: batch.vectors[0]
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function vectorSize(query) {
|
|
121
|
+
if (query.length === 0) throw new Error("Embedding vector is empty.");
|
|
122
|
+
return sql.raw(String(query.length));
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Cosine distance from a stored vector to a query vector. Both sides are cast
|
|
126
|
+
* to the query size, the form that an HNSW expression index on that size
|
|
127
|
+
* matches. The cast fails on a stored vector of another size, so filter on the
|
|
128
|
+
* size first, as the index predicate does, or use `guardedCosineDistance`.
|
|
129
|
+
* A caller with another copy of drizzle-orm embeds the result in its own
|
|
130
|
+
* `sql` template to get its own `SQL` type.
|
|
131
|
+
*/
|
|
132
|
+
function cosineDistance(args) {
|
|
133
|
+
const size = vectorSize(args.query);
|
|
134
|
+
const type = sql.raw(args.type);
|
|
135
|
+
return sql`(${args.column}::${type}(${size})) <=> ${JSON.stringify(args.query)}::${type}(${size})`;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* `cosineDistance`, or null for a stored vector of another size. Postgres
|
|
139
|
+
* does not promise to check a WHERE term before it computes an ORDER BY or
|
|
140
|
+
* SELECT expression, and pgvector fails on vectors of two sizes. CASE fixes
|
|
141
|
+
* the order.
|
|
142
|
+
*/
|
|
143
|
+
function guardedCosineDistance(args) {
|
|
144
|
+
return sql`CASE WHEN ${args.dimensions} = ${vectorSize(args.query)} THEN ${cosineDistance(args)} END`;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Embed items that have no current vector, one batch at a time, and store
|
|
148
|
+
* each batch before the next starts. `listMissing` returns the next items in
|
|
149
|
+
* the caller's order, after the last item of the previous page, so each run
|
|
150
|
+
* ends even when a write leaves an item missing. Text that trims to nothing
|
|
151
|
+
* is skipped, because the embedder rejects it. A provider failure stops the
|
|
152
|
+
* run and keeps the batches stored before it, so a later run continues.
|
|
153
|
+
*/
|
|
154
|
+
async function refreshEmbeddings(args) {
|
|
155
|
+
const now = args.now ?? Date.now;
|
|
156
|
+
let after;
|
|
157
|
+
let embedded = 0;
|
|
158
|
+
for (;;) {
|
|
159
|
+
const remaining = (args.maxItems ?? 1e400) - embedded;
|
|
160
|
+
if (remaining <= 0 || args.deadlineMs !== void 0 && now() >= args.deadlineMs) return {
|
|
161
|
+
done: false,
|
|
162
|
+
embedded
|
|
163
|
+
};
|
|
164
|
+
const page = await args.listMissing({
|
|
165
|
+
after,
|
|
166
|
+
limit: Math.min(args.batchSize, remaining)
|
|
167
|
+
});
|
|
168
|
+
after = page.at(-1);
|
|
169
|
+
if (!after) return {
|
|
170
|
+
done: true,
|
|
171
|
+
embedded
|
|
172
|
+
};
|
|
173
|
+
const items = page.filter((item) => item.text.trim() !== "");
|
|
174
|
+
if (items.length === 0) continue;
|
|
175
|
+
const batch = parseEmbeddingBatch(await args.embedder.embedTexts({
|
|
176
|
+
inputType: "document",
|
|
177
|
+
texts: items.map((item) => item.text)
|
|
178
|
+
}), {
|
|
179
|
+
...args.dimensions ? { dimensions: args.dimensions } : void 0,
|
|
180
|
+
expected: args.embedder,
|
|
181
|
+
textCount: items.length
|
|
182
|
+
});
|
|
183
|
+
await args.write(items.map((item, index) => ({
|
|
184
|
+
item,
|
|
185
|
+
vector: batch.vectors[index]
|
|
186
|
+
})), batch);
|
|
187
|
+
embedded += items.length;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// src/db/schema/tsvector.ts
|
|
191
|
+
/** Postgres full-text lexemes. Queries read them only through SQL. */
|
|
192
|
+
const tsvector = customType({ dataType() {
|
|
193
|
+
return "tsvector";
|
|
194
|
+
} });
|
|
195
|
+
// src/chat/memory/types.ts
|
|
196
|
+
const MEMORY_KINDS = [
|
|
197
|
+
"preference",
|
|
198
|
+
"procedure",
|
|
199
|
+
"knowledge"
|
|
200
|
+
];
|
|
201
|
+
const MEMORY_SCOPES = ["private", "public"];
|
|
202
|
+
const MEMORY_SUBJECT_TYPES = [
|
|
203
|
+
"user",
|
|
204
|
+
"conversation",
|
|
205
|
+
"general"
|
|
206
|
+
];
|
|
207
|
+
const MEMORY_SOURCE_PLATFORMS = [
|
|
208
|
+
"slack",
|
|
209
|
+
"local",
|
|
210
|
+
"web"
|
|
211
|
+
];
|
|
212
|
+
const MEMORY_EMBEDDING_METRICS = ["cosine"];
|
|
213
|
+
/** Things that can happen to a stored memory and feed future recall weights. */
|
|
214
|
+
/** `contradicted` and `superseded` record why a memory was retired. */
|
|
215
|
+
const MEMORY_SIGNALS = [
|
|
216
|
+
"duplicate",
|
|
217
|
+
"contradicted",
|
|
218
|
+
"superseded"
|
|
219
|
+
];
|
|
220
|
+
/**
|
|
221
|
+
* Vector sizes the embeddings table can store, so one table can hold vectors
|
|
222
|
+
* from an old and a new model while a model change is in progress. Only 1024
|
|
223
|
+
* has an HNSW index.
|
|
224
|
+
*/
|
|
225
|
+
const MEMORY_EMBEDDING_DIMENSIONS = [1024, 1536];
|
|
226
|
+
const nonEmptyStringSchema = z.string().min(1);
|
|
227
|
+
/** Host data used to set memory access, subject, and source. */
|
|
228
|
+
const memoryRuntimeContextSchema = z.object({
|
|
229
|
+
conversationId: nonEmptyStringSchema.optional(),
|
|
230
|
+
locationId: nonEmptyStringSchema.optional(),
|
|
231
|
+
actor: actorSchema.optional(),
|
|
232
|
+
source: sourceSchema,
|
|
233
|
+
/** User linked to the active Actor. */
|
|
234
|
+
userId: nonEmptyStringSchema.optional()
|
|
235
|
+
}).strict();
|
|
236
|
+
// src/db/schema/memory.ts
|
|
237
|
+
const juniorMemoryMemories = pgTable("junior_memory_memories", {
|
|
238
|
+
id: text("id").primaryKey(),
|
|
239
|
+
scope: text("scope", { enum: MEMORY_SCOPES }).notNull(),
|
|
240
|
+
scopeKey: text("scope_key").notNull(),
|
|
241
|
+
kind: text("type", { enum: MEMORY_KINDS }).notNull(),
|
|
242
|
+
subjectType: text("subject_type", { enum: MEMORY_SUBJECT_TYPES }).notNull(),
|
|
243
|
+
subjectKey: text("subject_key"),
|
|
244
|
+
content: text("content").notNull(),
|
|
245
|
+
searchVector: tsvector("search_vector").generatedAlwaysAs(sql`to_tsvector('english', "content")`),
|
|
246
|
+
sourcePlatform: text("source_platform", { enum: MEMORY_SOURCE_PLATFORMS }).notNull(),
|
|
247
|
+
sourceKey: text("source_key").notNull(),
|
|
248
|
+
/** Location where Junior learned the memory, when known. */
|
|
249
|
+
locationId: text("location_id"),
|
|
250
|
+
/** Conversation where Junior learned the memory, when known. */
|
|
251
|
+
conversationId: text("conversation_id"),
|
|
252
|
+
idempotencyKey: text("idempotency_key"),
|
|
253
|
+
observedAtMs: bigint("observed_at_ms", { mode: "number" }).notNull(),
|
|
254
|
+
createdAtMs: bigint("created_at_ms", { mode: "number" }).notNull(),
|
|
255
|
+
expiresAtMs: bigint("expires_at_ms", { mode: "number" }),
|
|
256
|
+
supersededAtMs: bigint("superseded_at_ms", { mode: "number" }),
|
|
257
|
+
supersededById: text("superseded_by_id"),
|
|
258
|
+
archivedAtMs: bigint("archived_at_ms", { mode: "number" }),
|
|
259
|
+
archiveReason: text("archive_reason")
|
|
260
|
+
}, (table) => [
|
|
261
|
+
index("junior_memory_memories_visible_idx").on(table.scope, table.scopeKey, table.createdAtMs.desc(), table.id).where(sql`${table.archivedAtMs} IS NULL AND ${table.supersededAtMs} IS NULL AND ${table.supersededById} IS NULL`),
|
|
262
|
+
index("junior_memory_memories_expiration_idx").on(table.expiresAtMs).where(sql`${table.archivedAtMs} IS NULL AND ${table.expiresAtMs} IS NOT NULL`),
|
|
263
|
+
index("junior_memory_memories_search_idx").using("gin", table.scope, table.scopeKey, table.searchVector).where(sql`${table.archivedAtMs} IS NULL AND ${table.supersededAtMs} IS NULL AND ${table.supersededById} IS NULL`),
|
|
264
|
+
uniqueIndex("junior_memory_memories_idempotency_idx").on(table.scope, table.scopeKey, table.idempotencyKey).where(sql`${table.idempotencyKey} IS NOT NULL AND ${table.archivedAtMs} IS NULL AND ${table.supersededAtMs} IS NULL AND ${table.supersededById} IS NULL`),
|
|
265
|
+
index("junior_memory_memories_archived_idempotency_idx").on(table.scope, table.scopeKey, table.idempotencyKey).where(sql`${table.idempotencyKey} IS NOT NULL AND ${table.archivedAtMs} IS NOT NULL AND ${table.archiveReason} <> 'expired'`),
|
|
266
|
+
check("junior_memory_memories_scope_check", sql`${table.scope} IN ('private', 'public')`),
|
|
267
|
+
check("junior_memory_memories_kind_check", sql`${table.kind} IN (
|
|
268
|
+
'preference',
|
|
269
|
+
'procedure',
|
|
270
|
+
'knowledge'
|
|
271
|
+
)`),
|
|
272
|
+
check("junior_memory_memories_subject_type_check", sql`${table.subjectType} IN ('user', 'conversation', 'general')`),
|
|
273
|
+
check("junior_memory_memories_subject_key_check", sql`(${table.subjectType} = 'general' AND ${table.subjectKey} IS NULL) OR (${table.subjectType} IN ('user', 'conversation') AND ${table.subjectKey} IS NOT NULL AND length(${table.subjectKey}) > 0)`),
|
|
274
|
+
check("junior_memory_memories_source_platform_check", sql`${table.sourcePlatform} IN ('slack', 'local', 'web')`)
|
|
275
|
+
]);
|
|
276
|
+
const juniorMemoryEmbeddings = pgTable("junior_memory_embeddings", {
|
|
277
|
+
memoryId: text("memory_id").notNull().references(() => juniorMemoryMemories.id, { onDelete: "cascade" }),
|
|
278
|
+
provider: text("provider").notNull(),
|
|
279
|
+
model: text("model").notNull(),
|
|
280
|
+
dimensions: integer("dimensions").notNull(),
|
|
281
|
+
metric: text("metric", { enum: MEMORY_EMBEDDING_METRICS }).notNull(),
|
|
282
|
+
contentHash: text("content_hash").notNull(),
|
|
283
|
+
embedding: embeddingVector("embedding").notNull(),
|
|
284
|
+
createdAtMs: bigint("created_at_ms", { mode: "number" }).notNull()
|
|
285
|
+
}, (table) => [
|
|
286
|
+
primaryKey({ columns: [
|
|
287
|
+
table.memoryId,
|
|
288
|
+
table.provider,
|
|
289
|
+
table.model
|
|
290
|
+
] }),
|
|
291
|
+
index("junior_memory_embeddings_model_idx").on(table.provider, table.model, table.dimensions, table.metric),
|
|
292
|
+
index("junior_memory_embeddings_embedding_1024_hnsw_idx").using("hnsw", sql`(${table.embedding}::vector(1024)) vector_cosine_ops`).with({
|
|
293
|
+
m: 16,
|
|
294
|
+
ef_construction: 64
|
|
295
|
+
}).where(sql`${table.dimensions} = 1024`),
|
|
296
|
+
check("junior_memory_embeddings_metric_check", sql`${table.metric} IN ('cosine')`),
|
|
297
|
+
check("junior_memory_embeddings_dimensions_check", sql`${table.dimensions} IN (${sql.raw(MEMORY_EMBEDDING_DIMENSIONS.join(", "))}) AND vector_dims(${table.embedding}) = ${table.dimensions}`)
|
|
298
|
+
]);
|
|
299
|
+
/**
|
|
300
|
+
* Thin log of signals about stored memories, such as a capture that resolved
|
|
301
|
+
* to an existing memory. Callers count recent rows to weigh memories.
|
|
302
|
+
*/
|
|
303
|
+
const juniorMemorySignals = pgTable("junior_memory_signals", {
|
|
304
|
+
memoryId: text("memory_id").notNull().references(() => juniorMemoryMemories.id, { onDelete: "cascade" }),
|
|
305
|
+
signal: text("signal", { enum: MEMORY_SIGNALS }).notNull(),
|
|
306
|
+
idempotencyKey: text("idempotency_key").notNull(),
|
|
307
|
+
/** Conversation where Junior saw the signal, when known. */
|
|
308
|
+
conversationId: text("conversation_id"),
|
|
309
|
+
observedAtMs: bigint("observed_at_ms", { mode: "number" }).notNull()
|
|
310
|
+
}, (table) => [
|
|
311
|
+
primaryKey({ columns: [
|
|
312
|
+
table.memoryId,
|
|
313
|
+
table.signal,
|
|
314
|
+
table.idempotencyKey
|
|
315
|
+
] }),
|
|
316
|
+
index("junior_memory_signals_observed_idx").on(table.memoryId, table.signal, table.observedAtMs),
|
|
317
|
+
check("junior_memory_signals_signal_check", sql`${table.signal} IN ('duplicate', 'contradicted', 'superseded')`)
|
|
318
|
+
]);
|
|
43
319
|
// src/db/schema/destinations.ts
|
|
44
320
|
const juniorDestinations = pgTable("junior_destinations", {
|
|
45
321
|
id: text("id").primaryKey(),
|
|
@@ -79,6 +355,17 @@ const juniorUsers = pgTable("junior_users", {
|
|
|
79
355
|
updatedAt: timestamptz("updated_at").notNull()
|
|
80
356
|
}, (table) => [uniqueIndex("junior_users_primary_email_normalized_uidx").on(table.primaryEmailNormalized)]);
|
|
81
357
|
// src/db/schema/identities.ts
|
|
358
|
+
/** Words of a Slack person's name and handle, for prefix search. */
|
|
359
|
+
function slackPersonSearchDocument(table) {
|
|
360
|
+
return sql`to_tsvector('simple', coalesce(${table.displayName}, '') || ' ' || coalesce(${table.handle}, ''))`;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Slack people. Literal values, so a prepared query with this predicate
|
|
364
|
+
* can use the partial index.
|
|
365
|
+
*/
|
|
366
|
+
function slackPersonPredicate(table) {
|
|
367
|
+
return sql`${table.provider} = 'slack' AND ${table.kind} = 'user'`;
|
|
368
|
+
}
|
|
82
369
|
const juniorIdentities = pgTable("junior_identities", {
|
|
83
370
|
id: text("id").primaryKey(),
|
|
84
371
|
kind: text("kind").$type().notNull(),
|
|
@@ -100,7 +387,8 @@ const juniorIdentities = pgTable("junior_identities", {
|
|
|
100
387
|
uniqueIndex("junior_identities_provider_subject_uidx").on(table.provider, table.providerTenantId, table.providerSubjectId),
|
|
101
388
|
index("junior_identities_user_idx").on(table.userId),
|
|
102
389
|
index("junior_identities_verified_email_idx").on(table.emailNormalized).where(sql`${table.emailVerified} = true AND ${table.emailNormalized} IS NOT NULL`),
|
|
103
|
-
index("junior_identities_kind_provider_idx").on(table.kind, table.provider)
|
|
390
|
+
index("junior_identities_kind_provider_idx").on(table.kind, table.provider),
|
|
391
|
+
index("junior_identities_slack_person_search_idx").using("gin", slackPersonSearchDocument(table)).where(slackPersonPredicate(table))
|
|
104
392
|
]);
|
|
105
393
|
// src/db/schema/conversations.ts
|
|
106
394
|
const juniorConversations = pgTable("junior_conversations", {
|
|
@@ -119,6 +407,8 @@ const juniorConversations = pgTable("junior_conversations", {
|
|
|
119
407
|
actor: jsonb("actor_json").$type(),
|
|
120
408
|
channelName: text("channel_name"),
|
|
121
409
|
title: text("title"),
|
|
410
|
+
summary: text("summary"),
|
|
411
|
+
metadataThroughSeq: integer("metadata_through_seq"),
|
|
122
412
|
createdAt: timestamptz("created_at").notNull(),
|
|
123
413
|
lastActivityAt: timestamptz("last_activity_at").notNull(),
|
|
124
414
|
/**
|
|
@@ -159,15 +449,17 @@ const juniorConversations = pgTable("junior_conversations", {
|
|
|
159
449
|
metricRunId: text("metric_run_id"),
|
|
160
450
|
detailVersion: integer("detail_version").notNull().default(0)
|
|
161
451
|
}, (table) => [
|
|
162
|
-
check("junior_conversations_kind_check", sql`${table.kind} in ('root', 'automation', 'thread', 'task')`),
|
|
163
|
-
check("junior_conversations_kind_parent_check", sql`${table.kind} is null or ((${table.kind} in ('root', 'automation')) = (${table.parentConversationId} is null))`),
|
|
452
|
+
check("junior_conversations_kind_check", sql`${table.kind} in ('root', 'automation', 'lead', 'thread', 'task')`),
|
|
453
|
+
check("junior_conversations_kind_parent_check", sql`${table.kind} is null or ((${table.kind} in ('root', 'automation', 'lead')) = (${table.parentConversationId} is null))`),
|
|
164
454
|
index("junior_conversations_last_activity_idx").on(table.lastActivityAt.desc(), table.conversationId),
|
|
165
455
|
index("junior_conversations_active_idx").using("btree", sql`coalesce(${table.executionUpdatedAt}, ${table.updatedAt})`, table.conversationId).where(sql`${table.executionStatus} <> 'idle'`),
|
|
166
456
|
index("junior_conversations_destination_activity_idx").on(table.destinationId, table.lastActivityAt.desc()),
|
|
167
457
|
index("junior_conversations_actor_activity_idx").on(table.actorIdentityId, table.lastActivityAt.desc()),
|
|
168
458
|
index("junior_conversations_parent_idx").on(table.parentConversationId),
|
|
169
459
|
index("junior_conversations_forked_from_idx").on(table.forkedFromConversationId),
|
|
170
|
-
index("junior_conversations_root_idx").on(table.rootConversationId)
|
|
460
|
+
index("junior_conversations_root_idx").on(table.rootConversationId),
|
|
461
|
+
uniqueIndex("junior_conversations_lead_actor_idx").on(table.actorIdentityId).where(sql`${table.kind} = 'lead'`),
|
|
462
|
+
index("junior_conversations_search_idx").using("gin", sql`to_tsvector('english', coalesce(${table.title}, '') || ' ' || coalesce(${table.summary}, ''))`)
|
|
171
463
|
]);
|
|
172
464
|
// src/db/schema/attachments.ts
|
|
173
465
|
/**
|
|
@@ -255,6 +547,17 @@ const juniorAttachmentUploads = pgTable("junior_attachment_uploads", {
|
|
|
255
547
|
createdAt: timestamptz("created_at").notNull()
|
|
256
548
|
}, (table) => [index("junior_attachment_uploads_gc_idx").on(table.storageProvider, table.createdAt)]);
|
|
257
549
|
// src/db/schema/code.ts
|
|
550
|
+
/**
|
|
551
|
+
* Words of a repository name, for prefix search. `owner/repo` is one token
|
|
552
|
+
* to the text parser, so the slash becomes a space.
|
|
553
|
+
*/
|
|
554
|
+
function codeRepositorySearchDocument(table) {
|
|
555
|
+
return sql`to_tsvector('simple', translate(${table.name}, '/', ' '))`;
|
|
556
|
+
}
|
|
557
|
+
/** The number and the title words of a code change, for prefix search. */
|
|
558
|
+
function codeChangeSearchDocument(table) {
|
|
559
|
+
return sql`to_tsvector('simple', ${table.number}::text || ' ' || coalesce(${table.title}, ''))`;
|
|
560
|
+
}
|
|
258
561
|
/** Repository known to Junior through an installed code plugin. */
|
|
259
562
|
const juniorCodeRepositories = pgTable("junior_code_repositories", {
|
|
260
563
|
id: uuid("id").primaryKey(),
|
|
@@ -263,12 +566,15 @@ const juniorCodeRepositories = pgTable("junior_code_repositories", {
|
|
|
263
566
|
providerId: text("provider_id").notNull(),
|
|
264
567
|
url: text("url"),
|
|
265
568
|
updatedAt: timestamptz("updated_at").notNull()
|
|
266
|
-
}, (table) => [uniqueIndex("junior_code_repositories_provider_id_idx").on(table.provider, table.providerId)]);
|
|
569
|
+
}, (table) => [uniqueIndex("junior_code_repositories_provider_id_idx").on(table.provider, table.providerId), index("junior_code_repositories_search_idx").using("gin", codeRepositorySearchDocument(table))]);
|
|
267
570
|
/** Latest known state for one code change created by Junior. */
|
|
268
571
|
const juniorCodeChanges = pgTable("junior_code_changes", {
|
|
269
572
|
id: uuid("id").primaryKey(),
|
|
573
|
+
additions: integer("additions"),
|
|
574
|
+
changedFiles: integer("changed_files"),
|
|
270
575
|
closedAt: timestamptz("closed_at"),
|
|
271
576
|
conversationIds: text("conversation_ids").array().notNull().default(sql`ARRAY[]::text[]`),
|
|
577
|
+
deletions: integer("deletions"),
|
|
272
578
|
draft: boolean("draft").notNull().default(false),
|
|
273
579
|
/** Latest push, review, or comment by a person, from the code plugin. */
|
|
274
580
|
lastActivityAt: timestamptz("last_activity_at"),
|
|
@@ -288,6 +594,7 @@ const juniorCodeChanges = pgTable("junior_code_changes", {
|
|
|
288
594
|
index("junior_code_changes_merged_at_idx").on(table.mergedAt),
|
|
289
595
|
index("junior_code_changes_closed_at_idx").on(table.closedAt),
|
|
290
596
|
index("junior_code_changes_repository_state_idx").on(table.repositoryId, table.state, table.updatedAt.desc()),
|
|
597
|
+
index("junior_code_changes_search_idx").using("gin", codeChangeSearchDocument(table)),
|
|
291
598
|
index("junior_code_changes_open_idx").on(table.id).where(sql`${table.state} = 'open'`)
|
|
292
599
|
]);
|
|
293
600
|
// src/db/schema/conversation-annotations.ts
|
|
@@ -365,6 +672,7 @@ const juniorConversationEvents = pgTable("junior_conversation_events", {
|
|
|
365
672
|
index("junior_conversation_events_type_idx").on(table.conversationId, table.type, table.seq),
|
|
366
673
|
index("junior_conversation_events_plugin_report_idx").on(sql`(${table.payload}->>'namespace')`, sql`(${table.payload}->>'name')`, table.createdAt).where(sql`${table.type} = 'structured_event'`),
|
|
367
674
|
index("junior_conversation_events_guardian_review_time_idx").on(table.createdAt).where(sql`${table.type} = 'guardian_action_reviewed'`),
|
|
675
|
+
index("junior_conversation_events_authorization_request_idx").on(table.conversationId, table.createdAt).where(sql`${table.type} = 'authorization_requested'`),
|
|
368
676
|
index("junior_conversation_events_plugin_conversation_idx").on(table.conversationId, sql`(${table.payload}->>'namespace')`, sql`(${table.payload}->>'name')`, table.seq).where(sql`${table.type} = 'structured_event'`),
|
|
369
677
|
index("junior_conversation_events_actor_identity_idx").on(table.actorIdentityId, table.conversationId, table.seq),
|
|
370
678
|
index("junior_conversation_events_author_idx").on(table.conversationId, table.actorIdentityId, table.seq).where(sql`${table.actorIdentityId} is not null`),
|
|
@@ -414,51 +722,26 @@ const juniorConversationMetrics = pgTable("junior_conversation_metrics", {
|
|
|
414
722
|
index("junior_conversation_metrics_occurred_at_metric_idx").on(table.occurredAt, table.metric),
|
|
415
723
|
index("junior_conversation_metrics_turn_metric_occurred_at_idx").on(table.metric, table.occurredAt, table.actorIdentityId, table.conversationId, table.value).where(sql`${table.metric} IN ('duration_ms', 'total_tokens', 'cost_micro_usd')`)
|
|
416
724
|
]);
|
|
417
|
-
// src/db/schema/conversation-briefs.ts
|
|
418
|
-
/** Append-only Brief versions produced for completed Conversation turns. */
|
|
419
|
-
const juniorConversationBriefs = pgTable("junior_conversation_briefs", {
|
|
420
|
-
conversationId: text("conversation_id").notNull(),
|
|
421
|
-
version: integer("version").notNull(),
|
|
422
|
-
turnId: text("turn_id").notNull(),
|
|
423
|
-
throughSeq: integer("through_seq").notNull(),
|
|
424
|
-
content: jsonb("content").$type().notNull(),
|
|
425
|
-
searchText: text("search_text").notNull(),
|
|
426
|
-
modelId: text("model_id").notNull(),
|
|
427
|
-
costMicroUsd: bigint("cost_micro_usd", { mode: "number" }),
|
|
428
|
-
legacyCostUsd: doublePrecision("cost_usd"),
|
|
429
|
-
createdAt: timestamptz("created_at").defaultNow().notNull()
|
|
430
|
-
}, (table) => [
|
|
431
|
-
primaryKey({
|
|
432
|
-
name: "junior_conversation_briefs_conversation_id_version_pk",
|
|
433
|
-
columns: [table.conversationId, table.version]
|
|
434
|
-
}),
|
|
435
|
-
foreignKey({
|
|
436
|
-
name: "junior_conversation_briefs_conversation_id_junior_conversations_conversation_id_fk",
|
|
437
|
-
columns: [table.conversationId],
|
|
438
|
-
foreignColumns: [juniorConversations.conversationId]
|
|
439
|
-
}).onDelete("cascade"),
|
|
440
|
-
uniqueIndex("junior_conversation_briefs_conversation_turn_idx").on(table.conversationId, table.turnId),
|
|
441
|
-
index("junior_conversation_briefs_conversation_version_idx").on(table.conversationId, table.version.desc()),
|
|
442
|
-
index("junior_conversation_briefs_search_idx").using("gin", sql`to_tsvector('english', ${table.searchText})`)
|
|
443
|
-
]);
|
|
444
725
|
// src/db/schema/conversation-embeddings.ts
|
|
445
726
|
/**
|
|
446
|
-
* One embedding per Conversation, for semantic search. Its text is the
|
|
447
|
-
*
|
|
448
|
-
*
|
|
727
|
+
* One embedding per Conversation, for semantic search. Its text is the
|
|
728
|
+
* Conversation metadata. A derived index: the next metadata update replaces
|
|
729
|
+
* the row.
|
|
449
730
|
*/
|
|
450
731
|
const juniorConversationEmbeddings = pgTable("junior_conversation_embeddings", {
|
|
451
732
|
conversationId: text("conversation_id").primaryKey(),
|
|
452
|
-
|
|
733
|
+
legacyBriefVersion: integer("brief_version"),
|
|
734
|
+
/** The `metadata_through_seq` of the embedded Conversation metadata. */
|
|
735
|
+
throughSeq: integer("through_seq"),
|
|
453
736
|
provider: text("provider").notNull(),
|
|
454
737
|
model: text("model").notNull(),
|
|
455
738
|
dimensions: integer("dimensions").notNull(),
|
|
456
739
|
embedding: embeddingVector("embedding").notNull(),
|
|
457
740
|
createdAt: timestamptz("created_at").defaultNow().notNull()
|
|
458
741
|
}, (table) => [foreignKey({
|
|
459
|
-
name: "
|
|
460
|
-
columns: [table.conversationId
|
|
461
|
-
foreignColumns: [
|
|
742
|
+
name: "junior_conversation_embeddings_conversation_fk",
|
|
743
|
+
columns: [table.conversationId],
|
|
744
|
+
foreignColumns: [juniorConversations.conversationId]
|
|
462
745
|
}).onDelete("cascade"), check("junior_conversation_embeddings_dimensions_check", sql`vector_dims(${table.embedding}) = ${table.dimensions}`)]);
|
|
463
746
|
// src/db/schema/conversation-event-embeddings.ts
|
|
464
747
|
/**
|
|
@@ -486,11 +769,6 @@ const juniorConversationEventEmbeddings = pgTable("junior_conversation_event_emb
|
|
|
486
769
|
}).onDelete("cascade"),
|
|
487
770
|
check("junior_conversation_event_embeddings_dimensions_check", sql`vector_dims(${table.embedding}) = ${table.dimensions}`)
|
|
488
771
|
]);
|
|
489
|
-
// src/db/schema/tsvector.ts
|
|
490
|
-
/** Postgres full-text lexemes. Queries read them only through SQL. */
|
|
491
|
-
const tsvector = customType({ dataType() {
|
|
492
|
-
return "tsvector";
|
|
493
|
-
} });
|
|
494
772
|
// src/db/schema/conversation-event-lexemes.ts
|
|
495
773
|
/**
|
|
496
774
|
* Stored full-text lexemes of one searchable Conversation event, for keyword
|
|
@@ -515,6 +793,39 @@ const juniorConversationEventLexemes = pgTable("junior_conversation_event_lexeme
|
|
|
515
793
|
}).onDelete("cascade"),
|
|
516
794
|
index("junior_conversation_event_lexemes_lexemes_idx").using("gin", table.lexemes)
|
|
517
795
|
]);
|
|
796
|
+
// src/db/schema/conversation-briefs.ts
|
|
797
|
+
/**
|
|
798
|
+
* Legacy Brief versions. Conversation metadata replaced Briefs; only purge
|
|
799
|
+
* still deletes rows here.
|
|
800
|
+
* TODO(dcramer): Drop this table after the metadata backfill ships.
|
|
801
|
+
*/
|
|
802
|
+
const juniorConversationBriefs = pgTable("junior_conversation_briefs", {
|
|
803
|
+
conversationId: text("conversation_id").notNull(),
|
|
804
|
+
version: integer("version").notNull(),
|
|
805
|
+
turnId: text("turn_id").notNull(),
|
|
806
|
+
throughSeq: integer("through_seq").notNull(),
|
|
807
|
+
content: jsonb("content").notNull(),
|
|
808
|
+
outcomeStatus: text("outcome_status"),
|
|
809
|
+
searchText: text("search_text").notNull(),
|
|
810
|
+
modelId: text("model_id").notNull(),
|
|
811
|
+
costMicroUsd: bigint("cost_micro_usd", { mode: "number" }),
|
|
812
|
+
legacyCostUsd: doublePrecision("cost_usd"),
|
|
813
|
+
createdAt: timestamptz("created_at").defaultNow().notNull()
|
|
814
|
+
}, (table) => [
|
|
815
|
+
primaryKey({
|
|
816
|
+
name: "junior_conversation_briefs_conversation_id_version_pk",
|
|
817
|
+
columns: [table.conversationId, table.version]
|
|
818
|
+
}),
|
|
819
|
+
foreignKey({
|
|
820
|
+
name: "junior_conversation_briefs_conversation_id_junior_conversations_conversation_id_fk",
|
|
821
|
+
columns: [table.conversationId],
|
|
822
|
+
foreignColumns: [juniorConversations.conversationId]
|
|
823
|
+
}).onDelete("cascade"),
|
|
824
|
+
uniqueIndex("junior_conversation_briefs_conversation_turn_idx").on(table.conversationId, table.turnId),
|
|
825
|
+
index("junior_conversation_briefs_conversation_version_idx").on(table.conversationId, table.version.desc()),
|
|
826
|
+
index("junior_conversation_briefs_created_at_idx").on(table.createdAt, table.conversationId),
|
|
827
|
+
index("junior_conversation_briefs_search_idx").using("gin", sql`to_tsvector('english', ${table.searchText})`)
|
|
828
|
+
]);
|
|
518
829
|
// src/db/schema/conversation-bindings.ts
|
|
519
830
|
/** Provider conversation coordinates bound to Junior's opaque durable conversation id. */
|
|
520
831
|
const juniorConversationBindings = pgTable("junior_conversation_bindings", {
|
|
@@ -637,28 +948,62 @@ const juniorLocationConfigurations = pgTable("junior_location_configurations", {
|
|
|
637
948
|
source: text("source"),
|
|
638
949
|
expiresAt: text("expires_at")
|
|
639
950
|
}, (table) => [primaryKey({ columns: [table.locationId, table.key] })]);
|
|
640
|
-
// src/db/schema/
|
|
951
|
+
// src/db/schema/automation-versions.ts
|
|
952
|
+
/** One saved Automation definition. Lifecycle and scheduler state are not versioned. */
|
|
953
|
+
const juniorAutomationVersions = pgTable("junior_automation_versions", {
|
|
954
|
+
automationId: text("automation_id").notNull(),
|
|
955
|
+
/** Starts at 1 and increases by 1 for each saved definition change. */
|
|
956
|
+
version: integer("version").notNull(),
|
|
957
|
+
createdAtMs: bigint("created_at_ms", { mode: "number" }).notNull(),
|
|
958
|
+
/** Slack principal that saved this definition. Null when unknown. */
|
|
959
|
+
editedBy: jsonb("edited_by"),
|
|
960
|
+
definition: jsonb("definition").notNull()
|
|
961
|
+
}, (table) => [primaryKey({
|
|
962
|
+
name: "junior_automation_versions_pk",
|
|
963
|
+
columns: [table.automationId, table.version]
|
|
964
|
+
}), foreignKey({
|
|
965
|
+
name: "junior_automation_versions_automation_id_fk",
|
|
966
|
+
columns: [table.automationId],
|
|
967
|
+
foreignColumns: [juniorAutomations.id]
|
|
968
|
+
}).onDelete("cascade")]);
|
|
969
|
+
// src/db/schema/automation-runs.ts
|
|
641
970
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
644
|
-
*
|
|
971
|
+
* One dispatch of an Automation, from claim or dispatch to its outcome. A
|
|
972
|
+
* Scheduled automation run id is `<automation id>:<scheduled time>`. An event
|
|
973
|
+
* automation run id is its dispatch id. Automation code sets
|
|
974
|
+
* `conversation_id` when it dispatches the run. A run that was skipped, or
|
|
975
|
+
* that failed before dispatch, has no Conversation.
|
|
976
|
+
*
|
|
977
|
+
* `automation_version` is the Automation version that the run dispatched. It
|
|
978
|
+
* shows which instruction ran and who saved it after the definition changes.
|
|
979
|
+
* It is null before dispatch, and when no saved version matched.
|
|
645
980
|
*/
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
})
|
|
981
|
+
const juniorAutomationRuns = pgTable("junior_automation_runs", {
|
|
982
|
+
id: text("id").primaryKey(),
|
|
983
|
+
automationId: text("automation_id").notNull().references(() => juniorAutomations.id, { onDelete: "cascade" }),
|
|
984
|
+
conversationId: text("conversation_id").unique().references(() => juniorConversations.conversationId),
|
|
985
|
+
status: text("status").$type().notNull(),
|
|
986
|
+
automationVersion: integer("automation_version"),
|
|
987
|
+
scheduledForMs: bigint("scheduled_for_ms", { mode: "number" }),
|
|
988
|
+
attempt: integer("attempt"),
|
|
989
|
+
claimedAtMs: bigint("claimed_at_ms", { mode: "number" }),
|
|
990
|
+
dispatchId: text("dispatch_id"),
|
|
991
|
+
startedAtMs: bigint("started_at_ms", { mode: "number" }),
|
|
992
|
+
completedAtMs: bigint("completed_at_ms", { mode: "number" }),
|
|
993
|
+
errorMessage: text("error_message"),
|
|
994
|
+
resultMessageTs: text("result_message_ts"),
|
|
995
|
+
costMicroUsd: bigint("cost_micro_usd", { mode: "number" })
|
|
996
|
+
}, (table) => [
|
|
997
|
+
foreignKey({
|
|
998
|
+
name: "junior_automation_runs_automation_version_fk",
|
|
999
|
+
columns: [table.automationId, table.automationVersion],
|
|
1000
|
+
foreignColumns: [juniorAutomationVersions.automationId, juniorAutomationVersions.version]
|
|
1001
|
+
}),
|
|
1002
|
+
check("junior_automation_runs_status_check", sql`${table.status} in ('pending', 'running', 'completed', 'failed', 'blocked', 'skipped')`),
|
|
1003
|
+
index("junior_automation_runs_automation_idx").on(table.automationId, table.completedAtMs),
|
|
1004
|
+
index("junior_automation_runs_completed_idx").on(table.completedAtMs),
|
|
1005
|
+
index("junior_automation_runs_incomplete_idx").on(table.automationId, table.scheduledForMs).where(sql`${table.status} in ('pending', 'running')`)
|
|
1006
|
+
]);
|
|
662
1007
|
// src/db/schema/automations.ts
|
|
663
1008
|
/**
|
|
664
1009
|
* One row per Automation of either kind. `record` holds the fields that have
|
|
@@ -696,6 +1041,11 @@ const juniorAutomations = pgTable("junior_automations", {
|
|
|
696
1041
|
* clears it.
|
|
697
1042
|
*/
|
|
698
1043
|
lastRunId: text("last_run_id").references(() => juniorAutomationRuns.id, { onDelete: "set null" }),
|
|
1044
|
+
/**
|
|
1045
|
+
* When core last saw this Automation recover after a person dismissed
|
|
1046
|
+
* its alert. A dismissed alert hides the Automation's alerts until then.
|
|
1047
|
+
*/
|
|
1048
|
+
alertRecoveredAtMs: bigint("alert_recovered_at_ms", { mode: "number" }),
|
|
699
1049
|
namespace: text("namespace"),
|
|
700
1050
|
identifier: text("identifier"),
|
|
701
1051
|
record: jsonb("record").$type().notNull()
|
|
@@ -714,70 +1064,17 @@ const juniorAutomations = pgTable("junior_automations", {
|
|
|
714
1064
|
index("junior_automations_skill_idx").on(table.skill, table.createdAtMs, table.id).where(sql`${table.status} <> 'deleted' AND ${table.skill} IS NOT NULL`),
|
|
715
1065
|
index("junior_automations_match_idx").on(table.namespace, table.identifier, table.createdAtMs, table.id).where(sql`${table.status} <> 'deleted'`)
|
|
716
1066
|
]);
|
|
717
|
-
// src/db/schema/
|
|
718
|
-
/** One saved Automation definition. Lifecycle and scheduler state are not versioned. */
|
|
719
|
-
const juniorAutomationVersions = pgTable("junior_automation_versions", {
|
|
720
|
-
automationId: text("automation_id").notNull(),
|
|
721
|
-
/** Starts at 1 and increases by 1 for each saved definition change. */
|
|
722
|
-
version: integer("version").notNull(),
|
|
723
|
-
createdAtMs: bigint("created_at_ms", { mode: "number" }).notNull(),
|
|
724
|
-
/** Slack principal that saved this definition. Null when unknown. */
|
|
725
|
-
editedBy: jsonb("edited_by"),
|
|
726
|
-
definition: jsonb("definition").notNull()
|
|
727
|
-
}, (table) => [primaryKey({
|
|
728
|
-
name: "junior_automation_versions_pk",
|
|
729
|
-
columns: [table.automationId, table.version]
|
|
730
|
-
}), foreignKey({
|
|
731
|
-
name: "junior_automation_versions_automation_id_fk",
|
|
732
|
-
columns: [table.automationId],
|
|
733
|
-
foreignColumns: [juniorAutomations.id]
|
|
734
|
-
}).onDelete("cascade")]);
|
|
735
|
-
// src/db/schema/automation-runs.ts
|
|
736
|
-
/**
|
|
737
|
-
* One dispatch of an Automation, from claim or dispatch to its outcome. A
|
|
738
|
-
* Scheduled automation run id is `<automation id>:<scheduled time>`. An event
|
|
739
|
-
* automation run id is its dispatch id. Automation code sets
|
|
740
|
-
* `conversation_id` when it dispatches the run. A run that was skipped, or
|
|
741
|
-
* that failed before dispatch, has no Conversation.
|
|
742
|
-
*
|
|
743
|
-
* `automation_version` is the Automation version that the run dispatched. It
|
|
744
|
-
* shows which instruction ran and who saved it after the definition changes.
|
|
745
|
-
* It is null before dispatch, and when no saved version matched.
|
|
746
|
-
*/
|
|
747
|
-
const juniorAutomationRuns = pgTable("junior_automation_runs", {
|
|
748
|
-
id: text("id").primaryKey(),
|
|
749
|
-
automationId: text("automation_id").notNull().references(() => juniorAutomations.id, { onDelete: "cascade" }),
|
|
750
|
-
conversationId: text("conversation_id").unique().references(() => juniorConversations.conversationId),
|
|
751
|
-
status: text("status").$type().notNull(),
|
|
752
|
-
automationVersion: integer("automation_version"),
|
|
753
|
-
scheduledForMs: bigint("scheduled_for_ms", { mode: "number" }),
|
|
754
|
-
attempt: integer("attempt"),
|
|
755
|
-
claimedAtMs: bigint("claimed_at_ms", { mode: "number" }),
|
|
756
|
-
dispatchId: text("dispatch_id"),
|
|
757
|
-
startedAtMs: bigint("started_at_ms", { mode: "number" }),
|
|
758
|
-
completedAtMs: bigint("completed_at_ms", { mode: "number" }),
|
|
759
|
-
errorMessage: text("error_message"),
|
|
760
|
-
resultMessageTs: text("result_message_ts"),
|
|
761
|
-
costMicroUsd: bigint("cost_micro_usd", { mode: "number" })
|
|
762
|
-
}, (table) => [
|
|
763
|
-
foreignKey({
|
|
764
|
-
name: "junior_automation_runs_automation_version_fk",
|
|
765
|
-
columns: [table.automationId, table.automationVersion],
|
|
766
|
-
foreignColumns: [juniorAutomationVersions.automationId, juniorAutomationVersions.version]
|
|
767
|
-
}),
|
|
768
|
-
check("junior_automation_runs_status_check", sql`${table.status} in ('pending', 'running', 'completed', 'failed', 'blocked', 'skipped')`),
|
|
769
|
-
index("junior_automation_runs_automation_idx").on(table.automationId, table.completedAtMs),
|
|
770
|
-
index("junior_automation_runs_completed_idx").on(table.completedAtMs),
|
|
771
|
-
index("junior_automation_runs_incomplete_idx").on(table.automationId, table.scheduledForMs).where(sql`${table.status} in ('pending', 'running')`)
|
|
772
|
-
]);
|
|
773
|
-
// src/db/schema/review-items.ts
|
|
1067
|
+
// src/db/schema/inbox-items.ts
|
|
774
1068
|
/**
|
|
775
|
-
* One
|
|
1069
|
+
* One Inbox item: something that needs a person. An action item stores its
|
|
776
1070
|
* `request`, and
|
|
777
1071
|
* its `answer` after an assignee submits it. `closed_at` is set for `done`
|
|
778
1072
|
* and `dismissed`. `closed_by_user_id` is null when an agent closed it.
|
|
1073
|
+
* `owner_kind` and `owner_id` name its owner. The owner kind decides how the
|
|
1074
|
+
* item gets its visibility and tenant, and where the Inbox stacks it. The id
|
|
1075
|
+
* has no foreign key, because it can name a row of more than one table.
|
|
779
1076
|
*/
|
|
780
|
-
const
|
|
1077
|
+
const juniorInboxItems = pgTable("junior_inbox_items", {
|
|
781
1078
|
id: text("id").primaryKey(),
|
|
782
1079
|
kind: text("kind").$type().notNull(),
|
|
783
1080
|
status: text("status").$type().notNull(),
|
|
@@ -795,8 +1092,10 @@ const juniorReviewItems = pgTable("junior_review_items", {
|
|
|
795
1092
|
subjectId: text("subject_id"),
|
|
796
1093
|
subjectTitle: text("subject_title"),
|
|
797
1094
|
subjectUrl: text("subject_url"),
|
|
798
|
-
/**
|
|
799
|
-
|
|
1095
|
+
/** The parsed subject title of a code change (`InboxItemSubjectTitleParts`). */
|
|
1096
|
+
subjectTitleParts: jsonb("subject_title_parts").$type(),
|
|
1097
|
+
ownerKind: text("owner_kind").$type().notNull().default("conversation"),
|
|
1098
|
+
ownerId: text("owner_id").notNull(),
|
|
800
1099
|
/**
|
|
801
1100
|
* Turn of the agent that added the item, or that last added it again with
|
|
802
1101
|
* its dedupe key. Null for a plugin item, which has no Turn.
|
|
@@ -815,53 +1114,120 @@ const juniorReviewItems = pgTable("junior_review_items", {
|
|
|
815
1114
|
createdAt: timestamptz("created_at").notNull(),
|
|
816
1115
|
updatedAt: timestamptz("updated_at").notNull()
|
|
817
1116
|
}, (table) => [
|
|
818
|
-
check("
|
|
819
|
-
check("
|
|
820
|
-
check("
|
|
821
|
-
check("
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
index("
|
|
825
|
-
index("
|
|
1117
|
+
check("junior_inbox_items_kind_check", sql`(${table.kind} = 'notice' and ${table.request} is null and ${table.answer} is null) or (${table.kind} = 'action' and (${table.request} is not null or ((${table.dedupeKey} like 'plugin:%' or ${table.dedupeKey} like 'automation:%') and ${table.answer} is null)))`),
|
|
1118
|
+
check("junior_inbox_items_owner_check", sql`(${table.ownerKind} = 'conversation' and ${table.dedupeKey} not like 'automation:%') or (${table.ownerKind} = 'automation' and ${table.dedupeKey} like 'automation:%')`),
|
|
1119
|
+
check("junior_inbox_items_status_check", sql`(${table.status} = 'open' and ${table.closedAt} is null) or (${table.status} in ('done', 'dismissed') and ${table.closedAt} is not null)`),
|
|
1120
|
+
check("junior_inbox_items_tenant_check", sql`(${table.provider} is null) = (${table.providerTenantId} is null)`),
|
|
1121
|
+
check("junior_inbox_items_visibility_check", sql`${table.visibility} = 'public' or not ${table.assignedToEveryone}`),
|
|
1122
|
+
uniqueIndex("junior_inbox_items_open_dedupe_uidx").on(sql`coalesce(${table.provider}, '')`, sql`coalesce(${table.providerTenantId}, '')`, table.dedupeKey).where(sql`${table.status} = 'open'`),
|
|
1123
|
+
index("junior_inbox_items_status_idx").on(table.status, table.updatedAt, table.id),
|
|
1124
|
+
index("junior_inbox_items_subject_idx").on(table.subjectId, table.status),
|
|
1125
|
+
index("junior_inbox_items_owner_idx").on(table.ownerKind, table.ownerId),
|
|
1126
|
+
index("junior_inbox_items_open_action_owner_idx").on(table.ownerId).where(sql`${table.status} = 'open' and ${table.kind} = 'action'`),
|
|
1127
|
+
index("junior_inbox_items_automation_idx").on(table.automationId, table.status),
|
|
1128
|
+
index("junior_inbox_items_answered_idx").on(table.ownerId, table.closedByUserId, table.closedAt).where(sql`${table.answer} is not null`)
|
|
826
1129
|
]);
|
|
827
|
-
/** The assigned Users of
|
|
828
|
-
const
|
|
829
|
-
itemId: text("item_id").notNull().references(() =>
|
|
1130
|
+
/** The assigned Users of an Inbox item. Everyone is a flag on the item. */
|
|
1131
|
+
const juniorInboxItemAssignees = pgTable("junior_inbox_item_assignees", {
|
|
1132
|
+
itemId: text("item_id").notNull().references(() => juniorInboxItems.id, { onDelete: "cascade" }),
|
|
830
1133
|
userId: text("user_id").notNull().references(() => juniorUsers.id, { onDelete: "cascade" })
|
|
831
|
-
}, (table) => [primaryKey({ columns: [table.itemId, table.userId] }), index("
|
|
832
|
-
/** The Conversations linked to
|
|
833
|
-
const
|
|
834
|
-
itemId: text("item_id").notNull().references(() =>
|
|
1134
|
+
}, (table) => [primaryKey({ columns: [table.itemId, table.userId] }), index("junior_inbox_item_assignees_user_idx").on(table.userId)]);
|
|
1135
|
+
/** The Conversations linked to an Inbox item. */
|
|
1136
|
+
const juniorInboxItemConversations = pgTable("junior_inbox_item_conversations", {
|
|
1137
|
+
itemId: text("item_id").notNull().references(() => juniorInboxItems.id, { onDelete: "cascade" }),
|
|
835
1138
|
conversationId: text("conversation_id").notNull().references(() => juniorConversations.conversationId, { onDelete: "cascade" })
|
|
836
|
-
}, (table) => [primaryKey({ columns: [table.itemId, table.conversationId] }), index("
|
|
1139
|
+
}, (table) => [primaryKey({ columns: [table.itemId, table.conversationId] }), index("junior_inbox_item_conversations_conversation_idx").on(table.conversationId)]);
|
|
837
1140
|
/**
|
|
838
|
-
* The Slack message that shows
|
|
1141
|
+
* The Slack message that shows an Inbox item in one linked Slack thread.
|
|
839
1142
|
* Junior updates it in place after each change.
|
|
840
1143
|
*/
|
|
841
|
-
const
|
|
842
|
-
itemId: text("item_id").notNull().references(() =>
|
|
1144
|
+
const juniorInboxItemSlackCards = pgTable("junior_inbox_item_slack_cards", {
|
|
1145
|
+
itemId: text("item_id").notNull().references(() => juniorInboxItems.id, { onDelete: "cascade" }),
|
|
843
1146
|
conversationId: text("conversation_id").notNull().references(() => juniorConversations.conversationId, { onDelete: "cascade" }),
|
|
844
1147
|
teamId: text("team_id").notNull(),
|
|
845
1148
|
channelId: text("channel_id").notNull(),
|
|
846
1149
|
messageTs: text("message_ts").notNull()
|
|
847
1150
|
}, (table) => [primaryKey({ columns: [table.itemId, table.conversationId] })]);
|
|
848
|
-
// src/db/schema/
|
|
1151
|
+
// src/db/schema/inbox-snoozes.ts
|
|
1152
|
+
/**
|
|
1153
|
+
* One person's snooze of one Inbox item. A `snoozed` row hides the item
|
|
1154
|
+
* from that person's Inbox until one of its triggers fires. `woken` and
|
|
1155
|
+
* `cancelled` are final. The item's own status says whether it resolved.
|
|
1156
|
+
* A trigger that wakes it records why in `wake_reason`, which only that
|
|
1157
|
+
* person sees, until they open or act on the item.
|
|
1158
|
+
*/
|
|
1159
|
+
const juniorInboxSnoozes = pgTable("junior_inbox_snoozes", {
|
|
1160
|
+
id: text("id").primaryKey(),
|
|
1161
|
+
userId: text("user_id").notNull().references(() => juniorUsers.id, { onDelete: "cascade" }),
|
|
1162
|
+
inboxItemId: text("inbox_item_id").notNull().references(() => juniorInboxItems.id, { onDelete: "cascade" }),
|
|
1163
|
+
state: text("state").$type().notNull(),
|
|
1164
|
+
wakeReason: jsonb("wake_reason").$type(),
|
|
1165
|
+
createdAt: timestamptz("created_at").notNull()
|
|
1166
|
+
}, (table) => [
|
|
1167
|
+
check("junior_inbox_snoozes_state_check", sql`${table.state} in ('snoozed', 'woken', 'cancelled')`),
|
|
1168
|
+
uniqueIndex("junior_inbox_snoozes_snoozed_uidx").on(table.userId, table.inboxItemId).where(sql`${table.state} = 'snoozed'`),
|
|
1169
|
+
index("junior_inbox_snoozes_settled_idx").on(table.createdAt).where(sql`${table.state} <> 'snoozed'`),
|
|
1170
|
+
index("junior_inbox_snoozes_inbox_item_idx").on(table.inboxItemId)
|
|
1171
|
+
]);
|
|
1172
|
+
/**
|
|
1173
|
+
* An Event that ends a snooze. `wake` brings the item back; `resolve`
|
|
1174
|
+
* dismisses the item and cancels the snooze. A snooze's triggers join with
|
|
1175
|
+
* OR: the first to fire wins, and the snooze ignores the rest. Time is a
|
|
1176
|
+
* `timer.fired` Event like any other.
|
|
1177
|
+
*/
|
|
1178
|
+
const juniorInboxSnoozeTriggers = pgTable("junior_inbox_snooze_triggers", {
|
|
1179
|
+
snoozeId: text("snooze_id").notNull().references(() => juniorInboxSnoozes.id, { onDelete: "cascade" }),
|
|
1180
|
+
outcome: text("outcome").$type().notNull(),
|
|
1181
|
+
namespace: text("namespace").notNull(),
|
|
1182
|
+
identifier: text("identifier").notNull(),
|
|
1183
|
+
eventType: text("event_type").notNull(),
|
|
1184
|
+
match: jsonb("match").$type()
|
|
1185
|
+
}, (table) => [
|
|
1186
|
+
check("junior_inbox_snooze_triggers_outcome_check", sql`${table.outcome} in ('wake', 'resolve')`),
|
|
1187
|
+
index("junior_inbox_snooze_triggers_event_idx").on(table.namespace, table.identifier, table.eventType),
|
|
1188
|
+
index("junior_inbox_snooze_triggers_snooze_idx").on(table.snoozeId)
|
|
1189
|
+
]);
|
|
1190
|
+
// src/db/schema/stats.ts
|
|
1191
|
+
/**
|
|
1192
|
+
* Daily named counters used by Junior and loaded plugins.
|
|
1193
|
+
* TODO: store hour keys when dashboard 24h workspace usage needs hourly bars.
|
|
1194
|
+
* `date` is a Postgres date column, so counters stay day-bucketed today.
|
|
1195
|
+
*/
|
|
1196
|
+
const juniorStats = pgTable("junior_stats", {
|
|
1197
|
+
date: date("date", { mode: "string" }).notNull(),
|
|
1198
|
+
namespace: text("namespace").notNull(),
|
|
1199
|
+
metric: text("metric").notNull(),
|
|
1200
|
+
name: text("name").notNull(),
|
|
1201
|
+
count: bigint("value", { mode: "number" }).notNull().default(0),
|
|
1202
|
+
legacyCount: integer("count").notNull().default(0)
|
|
1203
|
+
}, (table) => [primaryKey({
|
|
1204
|
+
name: "junior_stats_date_namespace_metric_name_pk",
|
|
1205
|
+
columns: [
|
|
1206
|
+
table.date,
|
|
1207
|
+
table.namespace,
|
|
1208
|
+
table.metric,
|
|
1209
|
+
table.name
|
|
1210
|
+
]
|
|
1211
|
+
})]);
|
|
1212
|
+
// src/db/schema/todos.ts
|
|
849
1213
|
/**
|
|
850
|
-
* Gives each
|
|
851
|
-
*
|
|
852
|
-
*
|
|
1214
|
+
* Gives each To-do its id and each change its version. One sequence serves
|
|
1215
|
+
* every Conversation, so history that a fork copies from its parent never
|
|
1216
|
+
* shows a version that the fork's own To-dos reuse.
|
|
853
1217
|
*/
|
|
854
|
-
const
|
|
1218
|
+
const juniorTodoVersionSeq = pgSequence("junior_todo_version_seq");
|
|
855
1219
|
/**
|
|
856
|
-
* One
|
|
857
|
-
* assignee: a Conversation (the
|
|
858
|
-
* or a User.
|
|
859
|
-
* `changed_by_user_id` is set when a person made the latest change
|
|
860
|
-
* when the
|
|
861
|
-
*
|
|
862
|
-
*
|
|
1220
|
+
* One To-do: work that a Conversation has not finished. At most one
|
|
1221
|
+
* assignee: a Conversation (the list's own agent or one of its child agents)
|
|
1222
|
+
* or a User. A To-do without one belongs to the list's own agent.
|
|
1223
|
+
* `changed_by_user_id` is set when a person made the latest change.
|
|
1224
|
+
* `changed_by_conversation_id` is set when the assignee child agent closed
|
|
1225
|
+
* it, or core closed it on that child's result. Both are null when the
|
|
1226
|
+
* list's own agent made the latest change. Both User keys block deleting the User, as
|
|
1227
|
+
* Conversation participants do: setting them null would turn a person's
|
|
1228
|
+
* To-do into the agent's and hide an unseen change from `<todo-delta>`.
|
|
863
1229
|
*/
|
|
864
|
-
const
|
|
1230
|
+
const juniorTodos = pgTable("junior_todos", {
|
|
865
1231
|
conversationId: text("conversation_id").notNull(),
|
|
866
1232
|
id: bigint("id", { mode: "number" }).notNull(),
|
|
867
1233
|
title: text("title").notNull(),
|
|
@@ -871,21 +1237,21 @@ const juniorPlanItems = pgTable("junior_plan_items", {
|
|
|
871
1237
|
assigneeUserId: text("assignee_user_id").references(() => juniorUsers.id),
|
|
872
1238
|
version: bigint("version", { mode: "number" }).notNull(),
|
|
873
1239
|
changedByUserId: text("changed_by_user_id").references(() => juniorUsers.id),
|
|
1240
|
+
changedByConversationId: text("changed_by_conversation_id"),
|
|
874
1241
|
createdAt: timestamptz("created_at").notNull(),
|
|
875
1242
|
updatedAt: timestamptz("updated_at").notNull()
|
|
876
1243
|
}, (table) => [
|
|
877
1244
|
primaryKey({
|
|
878
|
-
name: "
|
|
1245
|
+
name: "junior_todos_pk",
|
|
879
1246
|
columns: [table.conversationId, table.id]
|
|
880
1247
|
}),
|
|
881
1248
|
foreignKey({
|
|
882
|
-
name: "
|
|
1249
|
+
name: "junior_todos_conversation_id_fk",
|
|
883
1250
|
columns: [table.conversationId],
|
|
884
1251
|
foreignColumns: [juniorConversations.conversationId]
|
|
885
1252
|
}).onDelete("cascade"),
|
|
886
|
-
check("
|
|
887
|
-
check("
|
|
888
|
-
uniqueIndex("junior_plan_items_in_progress_uidx").on(table.conversationId, sql`coalesce(${table.assigneeConversationId}, ${table.assigneeUserId}, ${table.conversationId})`).where(sql`${table.status} = 'in_progress'`)
|
|
1253
|
+
check("junior_todos_status_check", sql`${table.status} in ('open', 'in_progress', 'done', 'dropped')`),
|
|
1254
|
+
check("junior_todos_assignee_check", sql`${table.assigneeConversationId} is null or ${table.assigneeUserId} is null`)
|
|
889
1255
|
]);
|
|
890
1256
|
// src/db/schema/push-subscriptions.ts
|
|
891
1257
|
/**
|
|
@@ -978,13 +1344,18 @@ const juniorSqlSchema = {
|
|
|
978
1344
|
juniorConversationReadPositions,
|
|
979
1345
|
juniorConversations,
|
|
980
1346
|
juniorLocationConfigurations,
|
|
1347
|
+
juniorMemoryEmbeddings,
|
|
1348
|
+
juniorMemoryMemories,
|
|
1349
|
+
juniorMemorySignals,
|
|
981
1350
|
juniorDestinations,
|
|
982
1351
|
juniorIdentities,
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1352
|
+
juniorInboxSnoozes,
|
|
1353
|
+
juniorInboxSnoozeTriggers,
|
|
1354
|
+
juniorInboxItemAssignees,
|
|
1355
|
+
juniorInboxItemConversations,
|
|
1356
|
+
juniorInboxItemSlackCards,
|
|
1357
|
+
juniorInboxItems,
|
|
1358
|
+
juniorTodos,
|
|
988
1359
|
juniorPushSubscriptions,
|
|
989
1360
|
juniorSnapshots,
|
|
990
1361
|
juniorStats,
|
|
@@ -1486,4 +1857,4 @@ function createJuniorSqlExecutor(args) {
|
|
|
1486
1857
|
statementTimeoutMs
|
|
1487
1858
|
});
|
|
1488
1859
|
}
|
|
1489
|
-
export {
|
|
1860
|
+
export { MEMORY_SCOPES as $, juniorConversationMetrics as A, juniorAttachments as B, juniorConversationParticipants as C, juniorConversationEventEmbeddings as D, juniorConversationEventLexemes as E, codeChangeSearchDocument as F, slackPersonSearchDocument as G, juniorConversations as H, codeRepositorySearchDocument as I, juniorMemoryEmbeddings as J, juniorUsers as K, juniorCodeChanges as L, juniorConversationEvents as M, juniorApiTokens as N, juniorConversationEmbeddings as O, juniorConversationAnnotations as P, MEMORY_KINDS as Q, juniorCodeRepositories as R, juniorConversationReadPositions as S, juniorConversationBriefs as T, juniorIdentities as U, juniorMessageAttachments as V, slackPersonPredicate as W, juniorMemorySignals as X, juniorMemoryMemories as Y, MEMORY_EMBEDDING_DIMENSIONS as Z, juniorAutomationRuns as _, juniorWorkspaces as a, guardedCosineDistance as at, juniorAgentBindings as b, juniorTodos as c, juniorArtifacts as ct, juniorInboxSnoozes as d, MEMORY_SOURCE_PLATFORMS as et, juniorInboxItemAssignees as f, juniorAutomations as g, juniorInboxItems as h, juniorWorkspaceRepos as i, embedText as it, isUserInstruction as j, CONVERSATION_METRICS as k, juniorStats as l, juniorInboxItemSlackCards as m, isPostgresErrorCode as n, memoryRuntimeContextSchema as nt, juniorPushSubscriptions as o, parseEmbeddingBatch as ot, juniorInboxItemConversations as p, juniorDestinations as q, juniorSnapshots as r, cosineDistance as rt, juniorTodoVersionSeq as s, refreshEmbeddings as st, createJuniorSqlExecutor as t, MEMORY_SUBJECT_TYPES as tt, juniorInboxSnoozeTriggers as u, juniorAutomationVersions as v, juniorConversationBindings as w, juniorAgentInvocations as x, juniorLocationConfigurations as y, juniorAttachmentUploads as z };
|