@m6d/cortex-server 1.7.0 → 2.0.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/README.md +8 -3
- package/contracts/README.md +23 -0
- package/contracts/graph/embed.ts +50 -0
- package/{src → contracts}/graph/helpers.ts +4 -10
- package/{src → contracts}/graph/neo4j.ts +14 -27
- package/contracts/graph/schema.ts +65 -0
- package/{src → contracts}/graph/types.ts +2 -29
- package/contracts/graph.ts +36 -0
- package/contracts/runtime.ts +208 -0
- package/contracts/wire.ts +143 -0
- package/dist/contracts/graph/embed.d.ts +22 -0
- package/dist/{src → contracts}/graph/helpers.d.ts +14 -12
- package/dist/{src → contracts}/graph/neo4j.d.ts +5 -5
- package/dist/contracts/graph/schema.d.ts +62 -0
- package/dist/{src → contracts}/graph/types.d.ts +1 -1
- package/dist/contracts/graph.d.ts +14 -0
- package/dist/contracts/runtime.d.ts +278 -0
- package/dist/contracts/wire.d.ts +120 -0
- package/dist/index.d.ts +1 -1
- package/dist/src/lib/adapters/database/index.d.ts +61 -0
- package/dist/src/lib/adapters/database/message-content.d.ts +30 -0
- package/dist/src/lib/adapters/database/mssql/attachments.d.ts +100 -0
- package/dist/src/lib/adapters/database/mssql/client.d.ts +8 -0
- package/dist/src/lib/adapters/database/mssql/index.d.ts +194 -0
- package/dist/src/lib/adapters/database/mssql/llm-requests.d.ts +17 -0
- package/dist/src/lib/adapters/database/mssql/messages.d.ts +37 -0
- package/dist/src/lib/adapters/database/mssql/threads.d.ts +50 -0
- package/dist/src/lib/adapters/database/postgres/attachments.d.ts +113 -0
- package/dist/src/lib/adapters/database/postgres/client.d.ts +8 -0
- package/dist/src/lib/adapters/database/postgres/index.d.ts +207 -0
- package/dist/src/lib/adapters/database/postgres/llm-requests.d.ts +17 -0
- package/dist/src/lib/adapters/database/postgres/messages.d.ts +37 -0
- package/dist/src/lib/adapters/database/postgres/threads.d.ts +50 -0
- package/{src/adapters/storage.ts → dist/src/lib/adapters/storage/index.d.ts} +1 -1
- package/dist/src/{adapters → lib/adapters/storage}/minio.d.ts +1 -1
- package/dist/src/lib/ai/active-runs.d.ts +63 -0
- package/dist/src/lib/ai/attachments.d.ts +30 -0
- package/dist/src/lib/ai/backend-url.d.ts +16 -0
- package/dist/src/lib/ai/cc-runtime.d.ts +61 -0
- package/dist/src/lib/ai/commit-gate.d.ts +21 -0
- package/dist/src/{ai → lib/ai}/context/builder.d.ts +6 -7
- package/dist/src/lib/ai/context/compression-middleware.d.ts +15 -0
- package/dist/src/lib/ai/context/compressor.d.ts +7 -0
- package/dist/src/lib/ai/context/intra-turn-compressor.d.ts +24 -0
- package/dist/src/lib/ai/context/optimize-thread-context.d.ts +9 -0
- package/dist/src/lib/ai/context/summarizer.d.ts +5 -0
- package/dist/src/{ai → lib/ai}/context/token-estimator.d.ts +5 -8
- package/dist/src/{ai → lib/ai}/context/types.d.ts +2 -0
- package/dist/src/{ai → lib/ai}/fetch.d.ts +1 -1
- package/dist/src/lib/ai/finish-turn.d.ts +23 -0
- package/dist/src/lib/ai/helpers.d.ts +38 -0
- package/dist/src/lib/ai/index.d.ts +7 -0
- package/dist/src/lib/ai/inspector.d.ts +41 -0
- package/dist/src/lib/ai/interceptors/request-interceptor.d.ts +13 -0
- package/dist/src/{ai → lib/ai}/prompt.d.ts +5 -4
- package/dist/src/lib/ai/redis-runs.d.ts +41 -0
- package/dist/src/lib/ai/redis-stream-log.d.ts +39 -0
- package/dist/src/lib/ai/tools/execute-code.tool.d.ts +18 -0
- package/dist/src/lib/ai/tools/query-graph.tool.d.ts +13 -0
- package/dist/src/lib/ai/tools/read-attachment.tool.d.ts +21 -0
- package/dist/src/lib/ai/tools/search-common.d.ts +17 -0
- package/dist/src/lib/ai/tools/search-knowledge.tool.d.ts +15 -0
- package/dist/src/lib/ai/tools/search-services.tool.d.ts +12 -0
- package/dist/src/lib/ai/tools/search-tools.tool.d.ts +12 -0
- package/dist/src/lib/ai/turn-tools.d.ts +39 -0
- package/dist/src/lib/ai/vision/rasterize-pdf.d.ts +26 -0
- package/dist/src/lib/ai/vision/rasterize-pdf.worker.d.ts +1 -0
- package/dist/src/lib/ai/vision/vision-reader.d.ts +45 -0
- package/dist/src/lib/cc/client.d.ts +183 -0
- package/dist/src/lib/cc/config-cache.d.ts +20 -0
- package/dist/src/lib/cc/format.d.ts +23 -0
- package/dist/src/lib/cc/registry.d.ts +34 -0
- package/dist/src/lib/cc/types.d.ts +27 -0
- package/dist/src/lib/config.d.ts +170 -0
- package/dist/src/lib/db/drizzle.config.mssql.d.ts +2 -0
- package/dist/src/lib/db/drizzle.config.pg.d.ts +2 -0
- package/dist/src/lib/db/migrate.d.ts +7 -0
- package/dist/src/{db/schema.d.ts → lib/db/schema.mssql.d.ts} +236 -24
- package/dist/src/lib/db/schema.pg.d.ts +546 -0
- package/dist/src/{factory.d.ts → lib/factory.d.ts} +2 -12
- package/dist/src/lib/graph/index.d.ts +10 -0
- package/dist/src/{graph → lib/graph}/resolver.d.ts +2 -3
- package/dist/src/{index.d.ts → lib/index.d.ts} +3 -4
- package/dist/src/lib/redis.d.ts +19 -0
- package/dist/src/{routes → lib/routes}/chat.d.ts +1 -1
- package/dist/src/{routes → lib/routes}/files.d.ts +1 -1
- package/dist/src/lib/routes/owned-thread.d.ts +17 -0
- package/dist/src/{routes → lib/routes}/threads.d.ts +1 -1
- package/dist/src/{routes → lib/routes}/ws.d.ts +1 -1
- package/dist/src/lib/types.d.ts +58 -0
- package/dist/src/{ws → lib/ws}/connections.d.ts +2 -1
- package/index.ts +1 -1
- package/package.json +35 -15
- package/src/lib/adapters/database/index.ts +78 -0
- package/src/lib/adapters/database/message-content.ts +39 -0
- package/src/lib/adapters/database/mssql/attachments.ts +90 -0
- package/src/lib/adapters/database/mssql/client.ts +11 -0
- package/src/lib/adapters/database/mssql/index.ts +23 -0
- package/src/lib/adapters/database/mssql/llm-requests.ts +43 -0
- package/src/lib/adapters/database/mssql/messages.ts +92 -0
- package/src/lib/adapters/database/mssql/threads.ts +83 -0
- package/src/lib/adapters/database/postgres/attachments.ts +88 -0
- package/src/lib/adapters/database/postgres/client.ts +11 -0
- package/src/lib/adapters/database/postgres/index.ts +23 -0
- package/src/lib/adapters/database/postgres/llm-requests.ts +45 -0
- package/src/lib/adapters/database/postgres/messages.ts +92 -0
- package/src/lib/adapters/database/postgres/threads.ts +84 -0
- package/{dist/src/adapters/storage.d.ts → src/lib/adapters/storage/index.ts} +1 -1
- package/src/{adapters → lib/adapters/storage}/minio.ts +7 -6
- package/src/lib/ai/active-runs.ts +157 -0
- package/src/lib/ai/attachments.ts +144 -0
- package/src/lib/ai/backend-url.ts +27 -0
- package/src/lib/ai/cc-runtime.ts +63 -0
- package/src/lib/ai/commit-gate.ts +116 -0
- package/src/{ai → lib/ai}/context/builder.ts +12 -14
- package/src/lib/ai/context/compression-middleware.ts +44 -0
- package/src/lib/ai/context/compressor.ts +267 -0
- package/src/lib/ai/context/intra-turn-compressor.ts +181 -0
- package/src/lib/ai/context/optimize-thread-context.ts +50 -0
- package/src/lib/ai/context/summarizer.ts +48 -0
- package/src/lib/ai/context/token-estimator.ts +65 -0
- package/src/{ai → lib/ai}/context/types.ts +4 -1
- package/src/{ai → lib/ai}/fetch.ts +10 -5
- package/src/lib/ai/finish-turn.ts +75 -0
- package/src/lib/ai/helpers.ts +100 -0
- package/src/lib/ai/index.ts +408 -0
- package/src/lib/ai/inspector.ts +112 -0
- package/src/lib/ai/interceptors/request-interceptor.ts +89 -0
- package/src/lib/ai/prompt.ts +355 -0
- package/src/lib/ai/redis-runs.ts +167 -0
- package/src/lib/ai/redis-stream-log.ts +219 -0
- package/src/lib/ai/tools/execute-code.tool.ts +267 -0
- package/src/{ai → lib/ai}/tools/query-graph.tool.ts +7 -8
- package/src/lib/ai/tools/read-attachment.tool.ts +59 -0
- package/src/lib/ai/tools/search-common.ts +15 -0
- package/src/lib/ai/tools/search-knowledge.tool.ts +33 -0
- package/src/lib/ai/tools/search-services.tool.ts +31 -0
- package/src/lib/ai/tools/search-tools.tool.ts +29 -0
- package/src/lib/ai/turn-tools.ts +154 -0
- package/src/lib/ai/vision/rasterize-pdf.ts +69 -0
- package/src/lib/ai/vision/rasterize-pdf.worker.ts +81 -0
- package/src/lib/ai/vision/vision-reader.ts +130 -0
- package/src/{auth → lib/auth}/middleware.ts +12 -3
- package/src/lib/cc/client.ts +273 -0
- package/src/lib/cc/config-cache.ts +32 -0
- package/src/lib/cc/format.ts +96 -0
- package/src/lib/cc/registry.ts +62 -0
- package/src/lib/cc/types.ts +44 -0
- package/src/lib/config.ts +212 -0
- package/src/lib/db/drizzle.config.mssql.ts +9 -0
- package/src/lib/db/drizzle.config.pg.ts +9 -0
- package/src/lib/db/migrate.ts +56 -0
- package/src/{db/migrations/20260309012148_cloudy_maria_hill → lib/db/migrations/mssql/20260326231647_nice_speedball}/migration.sql +12 -0
- package/src/{db/migrations/20260309012148_cloudy_maria_hill → lib/db/migrations/mssql/20260326231647_nice_speedball}/snapshot.json +106 -1
- package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/migration.sql +20 -0
- package/src/lib/db/migrations/mssql/20260729092726_talented_wilson_fisk/snapshot.json +497 -0
- package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/migration.sql +1 -0
- package/src/lib/db/migrations/mssql/20260801003652_perpetual_blue_shield/snapshot.json +516 -0
- package/src/lib/db/migrations/mssql/20260812174642_user_id_text/migration.sql +2 -0
- package/src/lib/db/migrations/mssql/20260812174642_user_id_text/snapshot.json +516 -0
- package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/migration.sql +53 -0
- package/src/lib/db/migrations/pg/20260801084117_thick_ben_grimm/snapshot.json +584 -0
- package/src/lib/db/migrations/pg/20260812174622_user_id_text/migration.sql +2 -0
- package/src/lib/db/migrations/pg/20260812174622_user_id_text/snapshot.json +584 -0
- package/src/lib/db/schema.mssql.ts +94 -0
- package/src/lib/db/schema.pg.ts +95 -0
- package/src/lib/factory.ts +127 -0
- package/src/lib/graph/index.ts +19 -0
- package/src/lib/graph/resolver.ts +387 -0
- package/src/{index.ts → lib/index.ts} +13 -5
- package/src/lib/redis.ts +44 -0
- package/src/lib/routes/chat.ts +115 -0
- package/src/lib/routes/files.ts +129 -0
- package/src/lib/routes/owned-thread.ts +17 -0
- package/src/{routes → lib/routes}/threads.ts +22 -31
- package/src/{routes → lib/routes}/ws.ts +9 -3
- package/src/lib/types.ts +76 -0
- package/src/{ws → lib/ws}/connections.ts +9 -1
- package/tsconfig.json +48 -0
- package/dist/src/adapters/database.d.ts +0 -30
- package/dist/src/adapters/mssql.d.ts +0 -3
- package/dist/src/ai/active-streams.d.ts +0 -14
- package/dist/src/ai/context/compressor.d.ts +0 -7
- package/dist/src/ai/context/index.d.ts +0 -15
- package/dist/src/ai/context/summarizer.d.ts +0 -5
- package/dist/src/ai/helpers.d.ts +0 -5
- package/dist/src/ai/index.d.ts +0 -4
- package/dist/src/ai/interceptors/request-interceptor.d.ts +0 -12
- package/dist/src/ai/tools/call-endpoint.tool.d.ts +0 -7
- package/dist/src/ai/tools/capture-files.tool.d.ts +0 -6
- package/dist/src/ai/tools/execute-code.tool.d.ts +0 -4
- package/dist/src/ai/tools/query-graph.tool.d.ts +0 -5
- package/dist/src/cli/extract-endpoints.d.ts +0 -6
- package/dist/src/config.d.ts +0 -165
- package/dist/src/db/migrate.d.ts +0 -1
- package/dist/src/graph/expand-domains.d.ts +0 -2
- package/dist/src/graph/generate-cypher.d.ts +0 -22
- package/dist/src/graph/index.d.ts +0 -11
- package/dist/src/graph/seed.d.ts +0 -19
- package/dist/src/graph/validate.d.ts +0 -2
- package/dist/src/routes/index.d.ts +0 -4
- package/dist/src/types.d.ts +0 -74
- package/dist/src/ws/events.d.ts +0 -39
- package/dist/src/ws/index.d.ts +0 -3
- package/dist/src/ws/notify.d.ts +0 -2
- package/src/adapters/database.ts +0 -29
- package/src/adapters/mssql.ts +0 -195
- package/src/ai/active-streams.ts +0 -123
- package/src/ai/context/compressor.ts +0 -47
- package/src/ai/context/index.ts +0 -75
- package/src/ai/context/summarizer.ts +0 -50
- package/src/ai/context/token-estimator.ts +0 -60
- package/src/ai/helpers.ts +0 -32
- package/src/ai/index.ts +0 -277
- package/src/ai/interceptors/request-interceptor.ts +0 -61
- package/src/ai/prompt.ts +0 -126
- package/src/ai/tools/call-endpoint.tool.ts +0 -89
- package/src/ai/tools/capture-files.tool.ts +0 -20
- package/src/ai/tools/execute-code.tool.ts +0 -153
- package/src/cli/extract-endpoints.ts +0 -550
- package/src/config.ts +0 -182
- package/src/db/migrate.ts +0 -21
- package/src/db/migrations/20260315000000_add_context_meta/migration.sql +0 -1
- package/src/db/schema.ts +0 -70
- package/src/factory.ts +0 -171
- package/src/graph/expand-domains.ts +0 -276
- package/src/graph/generate-cypher.ts +0 -192
- package/src/graph/index.ts +0 -47
- package/src/graph/resolver.ts +0 -357
- package/src/graph/seed.ts +0 -162
- package/src/graph/validate.ts +0 -78
- package/src/routes/chat.ts +0 -86
- package/src/routes/files.ts +0 -100
- package/src/routes/index.ts +0 -4
- package/src/types.ts +0 -74
- package/src/ws/events.ts +0 -39
- package/src/ws/index.ts +0 -11
- package/src/ws/notify.ts +0 -9
- /package/dist/src/{auth → lib/auth}/middleware.d.ts +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { MessagePart } from "@tanstack/ai";
|
|
2
|
+
import type { ResolvedCortexAgentConfig } from "./config";
|
|
3
|
+
import type { InferSelectModel } from "drizzle-orm";
|
|
4
|
+
import type { attachments, messages, threads } from "./db/schema.mssql";
|
|
5
|
+
export type { CortexMessage, MessageMetadata, ThreadSummary, TokenUsage, } from "../../contracts/wire";
|
|
6
|
+
import type { CortexMessage } from "../../contracts/wire";
|
|
7
|
+
/** A message as cortex persists and serves it: SDK parts plus cortex's envelope. */
|
|
8
|
+
export type ChatMessage = CortexMessage<MessagePart>;
|
|
9
|
+
export type Thread = InferSelectModel<typeof threads>;
|
|
10
|
+
export type StoredMessage = InferSelectModel<typeof messages>;
|
|
11
|
+
export type Attachment = InferSelectModel<typeof attachments>;
|
|
12
|
+
export type NewAttachment = typeof attachments.$inferInsert;
|
|
13
|
+
export type AppEnv = {
|
|
14
|
+
Bindings: {};
|
|
15
|
+
Variables: {
|
|
16
|
+
user: {
|
|
17
|
+
id: string;
|
|
18
|
+
token: string;
|
|
19
|
+
} | undefined;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
export type AuthedAppEnv = {
|
|
23
|
+
Bindings: {};
|
|
24
|
+
Variables: {
|
|
25
|
+
user: {
|
|
26
|
+
id: string;
|
|
27
|
+
token: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export type CortexAppEnv = {
|
|
32
|
+
Bindings: {};
|
|
33
|
+
Variables: {
|
|
34
|
+
user: {
|
|
35
|
+
id: string;
|
|
36
|
+
token: string;
|
|
37
|
+
};
|
|
38
|
+
agentConfig: ResolvedCortexAgentConfig;
|
|
39
|
+
agentId: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** Maps a stored row to the wire shape. Dates become ISO strings — the same bytes
|
|
43
|
+
* `JSON.stringify` would have produced, but now the type says so. */
|
|
44
|
+
export declare function toThreadSummary(thread: Thread, isRunning: boolean): {
|
|
45
|
+
id: string;
|
|
46
|
+
title: string | undefined;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
updatedAt: string;
|
|
49
|
+
isRunning: boolean;
|
|
50
|
+
};
|
|
51
|
+
export declare function toAttachmentSummary(attachment: Attachment): {
|
|
52
|
+
id: string;
|
|
53
|
+
filename: string;
|
|
54
|
+
contentType: string;
|
|
55
|
+
sizeBytes: number;
|
|
56
|
+
status: "pending" | "described" | "failed" | "skipped";
|
|
57
|
+
description: string | undefined;
|
|
58
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { WSContext } from "hono/ws";
|
|
2
|
+
import type { WsEvent } from "../../../contracts/wire";
|
|
2
3
|
export declare function addConnection(userId: string, agentId: string, ws: WSContext): void;
|
|
3
4
|
export declare function removeConnection(userId: string, agentId: string, ws: WSContext): void;
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function notify(userId: string, agentId: string, event: WsEvent): void;
|
package/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
1
|
+
export * from "./src/lib/index";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m6d/cortex-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Reusable AI agent chat server library for Hono + Bun",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,38 +16,58 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
18
|
"src",
|
|
19
|
+
"contracts",
|
|
19
20
|
"index.ts",
|
|
20
|
-
"README.md"
|
|
21
|
+
"README.md",
|
|
22
|
+
"tsconfig.json",
|
|
23
|
+
"!src/**/*.test.ts",
|
|
24
|
+
"!src/**/*.mock.ts"
|
|
21
25
|
],
|
|
22
26
|
"scripts": {
|
|
23
|
-
"build": "tsc -p tsconfig.build.json",
|
|
24
|
-
"
|
|
25
|
-
"db:
|
|
27
|
+
"build": "bun run vendor && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && rm -rf contracts",
|
|
28
|
+
"check": "tsc --noEmit",
|
|
29
|
+
"db:generate:mssql": "drizzle-kit generate --config=src/lib/db/drizzle.config.mssql.ts",
|
|
30
|
+
"db:generate:pg": "drizzle-kit generate --config=src/lib/db/drizzle.config.pg.ts",
|
|
31
|
+
"db:migrate:mssql": "drizzle-kit migrate --config=src/lib/db/drizzle.config.mssql.ts",
|
|
32
|
+
"db:migrate:pg": "drizzle-kit migrate --config=src/lib/db/drizzle.config.pg.ts",
|
|
33
|
+
"prepack": "bun run vendor",
|
|
34
|
+
"postpack": "rm -rf contracts",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"vendor": "rm -rf contracts && cp -R ../../internal/contracts contracts && rm contracts/package.json contracts/tsconfig.json"
|
|
26
37
|
},
|
|
27
38
|
"dependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"drizzle-orm": "
|
|
39
|
+
"@hono/zod-validator": "^0.9.0",
|
|
40
|
+
"@hyzyla/pdfium": "^2.1.13",
|
|
41
|
+
"drizzle-orm": "1.0.0-beta.15-859cf75",
|
|
42
|
+
"ioredis": "^5.9.2",
|
|
43
|
+
"jpeg-js": "^0.4.4",
|
|
31
44
|
"minio": "^8.0.7",
|
|
32
45
|
"mssql": "^12.2.0",
|
|
46
|
+
"pg": "^8.16.3",
|
|
33
47
|
"quickjs-emscripten": "^0.32.0"
|
|
34
48
|
},
|
|
35
49
|
"devDependencies": {
|
|
36
|
-
"@ai
|
|
50
|
+
"@tanstack/ai": "^0.43.1",
|
|
51
|
+
"@tanstack/ai-openai": "^0.18.0",
|
|
37
52
|
"@types/bun": "latest",
|
|
38
53
|
"@types/minio": "^7.1.1",
|
|
39
54
|
"@types/mssql": "^9.1.5",
|
|
40
|
-
"
|
|
41
|
-
"drizzle-kit": "
|
|
55
|
+
"@types/pg": "^8.15.6",
|
|
56
|
+
"drizzle-kit": "1.0.0-beta.15-859cf75",
|
|
42
57
|
"hono": "^4.12.3",
|
|
43
|
-
"
|
|
58
|
+
"jose": "^6.1.3",
|
|
59
|
+
"openai": "^6",
|
|
60
|
+
"tsc-alias": "^1.9.1",
|
|
61
|
+
"typescript": "~5.9.3",
|
|
62
|
+
"zod": "^4.3.6"
|
|
44
63
|
},
|
|
45
64
|
"peerDependencies": {
|
|
46
|
-
"@ai
|
|
47
|
-
"ai": "^
|
|
65
|
+
"@tanstack/ai": "^0.43.1",
|
|
66
|
+
"@tanstack/ai-openai": "^0.18.0",
|
|
48
67
|
"hono": "^4.12.3",
|
|
49
68
|
"jose": "^6.1.3",
|
|
50
|
-
"
|
|
69
|
+
"openai": "^6",
|
|
70
|
+
"zod": "^4.1.8"
|
|
51
71
|
},
|
|
52
72
|
"engines": {
|
|
53
73
|
"bun": ">=1.0.0"
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Attachment,
|
|
3
|
+
ChatMessage,
|
|
4
|
+
NewAttachment,
|
|
5
|
+
StoredMessage,
|
|
6
|
+
Thread,
|
|
7
|
+
TokenUsage,
|
|
8
|
+
} from "@/types";
|
|
9
|
+
import type { ThreadContextMeta } from "@/ai/context/types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The persistence contract, implemented once per dialect under `mssql/` and
|
|
13
|
+
* `postgres/`.
|
|
14
|
+
*
|
|
15
|
+
* Those two trees are near-identical on purpose. Drizzle types its query
|
|
16
|
+
* builders per dialect, so a shared body is not expressible — `.top`/`.limit`,
|
|
17
|
+
* `.output`/`.returning` and the row-lock hint differ down in the query, not at
|
|
18
|
+
* a seam that could be factored out. What is *not* SQL lives in
|
|
19
|
+
* `message-content.ts` instead, so the rules the two must agree on are stated
|
|
20
|
+
* once.
|
|
21
|
+
*
|
|
22
|
+
* Drift is guarded rather than prevented: `db/schema.parity.test.ts` asserts the
|
|
23
|
+
* two schemas still infer the same rows, and the adapter tests beside this file
|
|
24
|
+
* run against both implementations. The `code-duplication` suppressions in
|
|
25
|
+
* `postgres/` record the same decision for fallow.
|
|
26
|
+
*/
|
|
27
|
+
export type DatabaseAdapter = {
|
|
28
|
+
threads: {
|
|
29
|
+
list(userId: string, agentId: string): Promise<Thread[]>;
|
|
30
|
+
getById(userId: string, threadId: string): Promise<Thread | null>;
|
|
31
|
+
create(userId: string, agentId: string): Promise<Thread>;
|
|
32
|
+
delete(userId: string, threadId: string): Promise<void>;
|
|
33
|
+
touch(threadId: string): Promise<Thread>;
|
|
34
|
+
updateTitle(threadId: string, title: string): Promise<void>;
|
|
35
|
+
updateSession(threadId: string, session: Record<string, unknown>): Promise<void>;
|
|
36
|
+
updateContextMeta(threadId: string, meta: ThreadContextMeta): Promise<void>;
|
|
37
|
+
};
|
|
38
|
+
messages: {
|
|
39
|
+
list(userId: string, threadId: string, opts?: { limit?: number }): Promise<StoredMessage[]>;
|
|
40
|
+
upsert(
|
|
41
|
+
threadId: string,
|
|
42
|
+
messages: ChatMessage[],
|
|
43
|
+
options?: { replaceAttachments?: boolean },
|
|
44
|
+
): Promise<void>;
|
|
45
|
+
};
|
|
46
|
+
llmRequests: {
|
|
47
|
+
insert(
|
|
48
|
+
requests: {
|
|
49
|
+
messageId: string;
|
|
50
|
+
stepNumber: number;
|
|
51
|
+
prompt: string;
|
|
52
|
+
output: string | null;
|
|
53
|
+
tokenUsage: TokenUsage | null;
|
|
54
|
+
}[],
|
|
55
|
+
): Promise<void>;
|
|
56
|
+
listByMessageId(messageId: string): Promise<
|
|
57
|
+
{
|
|
58
|
+
id: string;
|
|
59
|
+
prompt: string;
|
|
60
|
+
output: string | null;
|
|
61
|
+
tokenUsage: TokenUsage | null;
|
|
62
|
+
}[]
|
|
63
|
+
>;
|
|
64
|
+
};
|
|
65
|
+
attachments: {
|
|
66
|
+
createPending(row: NewAttachment, limit: number): Promise<Attachment | undefined>;
|
|
67
|
+
getById(id: string, userId: string): Promise<Attachment | undefined>;
|
|
68
|
+
listByThread(threadId: string, userId: string): Promise<Attachment[]>;
|
|
69
|
+
claimForMessage(threadId: string, userId: string, messageId: string): Promise<Attachment[]>;
|
|
70
|
+
setDescription(
|
|
71
|
+
id: string,
|
|
72
|
+
userId: string,
|
|
73
|
+
status: Attachment["status"],
|
|
74
|
+
description?: string,
|
|
75
|
+
): Promise<void>;
|
|
76
|
+
remove(id: string, userId: string): Promise<Attachment | undefined>;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ChatMessage } from "@/types";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The parts of `messages.upsert` that are decisions rather than SQL. Each
|
|
5
|
+
* dialect writes its own queries, but they must agree on what gets written —
|
|
6
|
+
* so the rules live here and neither repository restates them.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Denormalized alongside the JSON content so the column is searchable. */
|
|
10
|
+
export function textOf(message: ChatMessage) {
|
|
11
|
+
return message.parts.find((part) => part.type === "text")?.content;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Attachments are the server's to assign: a caller may name them but never
|
|
16
|
+
* establish them. Only a turn that has just claimed them may carry them in.
|
|
17
|
+
*/
|
|
18
|
+
export function withOwnedAttachments(messages: ChatMessage[], replaceAttachments?: boolean) {
|
|
19
|
+
if (replaceAttachments) return messages;
|
|
20
|
+
|
|
21
|
+
return messages.map((message) => {
|
|
22
|
+
if (!message.metadata) return message;
|
|
23
|
+
|
|
24
|
+
const { attachments: _, ...metadata } = message.metadata;
|
|
25
|
+
return { ...message, metadata };
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The envelope is the server's — usage, model id and the attachments it claimed
|
|
31
|
+
* are facts no caller carries in full, so an update only contributes the fields
|
|
32
|
+
* it actually set. Attachments were already stripped from anything that must
|
|
33
|
+
* not replace them.
|
|
34
|
+
*/
|
|
35
|
+
export function mergeStoredContent(existing: ChatMessage, incoming: ChatMessage) {
|
|
36
|
+
return existing.metadata
|
|
37
|
+
? { ...incoming, metadata: { ...existing.metadata, ...incoming.metadata } }
|
|
38
|
+
: incoming;
|
|
39
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// fallow-ignore-file duplicate-export -- mssql twin of the postgres repository, same factory name by design
|
|
2
|
+
import { and, asc, count, eq, isNull, or, sql } from "drizzle-orm";
|
|
3
|
+
import { attachments, threads } from "@/db/schema.mssql";
|
|
4
|
+
import type { DatabaseAdapter } from "@/adapters/database/index";
|
|
5
|
+
import type { MssqlDb } from "./client";
|
|
6
|
+
|
|
7
|
+
export function createAttachmentsRepository(db: MssqlDb) {
|
|
8
|
+
return {
|
|
9
|
+
async createPending(row, limit) {
|
|
10
|
+
return await db.transaction(async function (tx) {
|
|
11
|
+
await tx.execute(
|
|
12
|
+
sql`SELECT 1 FROM ${threads} WITH (UPDLOCK, HOLDLOCK) WHERE ${threads.id} = ${row.threadId}`,
|
|
13
|
+
);
|
|
14
|
+
const pending = await tx
|
|
15
|
+
.select({ value: count() })
|
|
16
|
+
.from(attachments)
|
|
17
|
+
.where(
|
|
18
|
+
and(
|
|
19
|
+
eq(attachments.threadId, row.threadId),
|
|
20
|
+
eq(attachments.userId, row.userId),
|
|
21
|
+
isNull(attachments.messageId),
|
|
22
|
+
),
|
|
23
|
+
)
|
|
24
|
+
.execute()
|
|
25
|
+
.then((rows) => rows[0]!.value);
|
|
26
|
+
if (pending >= limit) return undefined;
|
|
27
|
+
|
|
28
|
+
return await tx
|
|
29
|
+
.insert(attachments)
|
|
30
|
+
.output()
|
|
31
|
+
.values(row)
|
|
32
|
+
.execute()
|
|
33
|
+
.then((rows) => rows[0]!);
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
async getById(id, userId) {
|
|
38
|
+
return await db
|
|
39
|
+
.select()
|
|
40
|
+
.top(1)
|
|
41
|
+
.from(attachments)
|
|
42
|
+
.where(and(eq(attachments.id, id), eq(attachments.userId, userId)))
|
|
43
|
+
.execute()
|
|
44
|
+
.then((rows) => rows[0]);
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
async listByThread(threadId, userId) {
|
|
48
|
+
return await db
|
|
49
|
+
.select()
|
|
50
|
+
.from(attachments)
|
|
51
|
+
.where(and(eq(attachments.threadId, threadId), eq(attachments.userId, userId)))
|
|
52
|
+
.orderBy(asc(attachments.createdAt), asc(attachments.id))
|
|
53
|
+
.execute();
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async claimForMessage(threadId, userId, messageId) {
|
|
57
|
+
// ponytail: retries only this message's pending rows; add claim timestamps for cross-message recovery.
|
|
58
|
+
return await db
|
|
59
|
+
.update(attachments)
|
|
60
|
+
.set({ messageId })
|
|
61
|
+
.where(
|
|
62
|
+
and(
|
|
63
|
+
eq(attachments.threadId, threadId),
|
|
64
|
+
eq(attachments.userId, userId),
|
|
65
|
+
eq(attachments.status, "pending"),
|
|
66
|
+
or(isNull(attachments.messageId), eq(attachments.messageId, messageId)),
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
.output()
|
|
70
|
+
.execute();
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
async setDescription(id, userId, status, description) {
|
|
74
|
+
await db
|
|
75
|
+
.update(attachments)
|
|
76
|
+
.set(description === undefined ? { status } : { status, description })
|
|
77
|
+
.where(and(eq(attachments.id, id), eq(attachments.userId, userId)))
|
|
78
|
+
.execute();
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
async remove(id, userId) {
|
|
82
|
+
return await db
|
|
83
|
+
.delete(attachments)
|
|
84
|
+
.where(and(eq(attachments.id, id), eq(attachments.userId, userId)))
|
|
85
|
+
.output()
|
|
86
|
+
.execute()
|
|
87
|
+
.then((rows) => rows[0]);
|
|
88
|
+
},
|
|
89
|
+
} satisfies DatabaseAdapter["attachments"];
|
|
90
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { drizzle } from "drizzle-orm/node-mssql";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Global snake_case mapping means schema columns are never spelled out twice —
|
|
5
|
+
* the TypeScript name is the source of truth and Drizzle derives the column.
|
|
6
|
+
*/
|
|
7
|
+
export function createMssqlDb(connectionString: string) {
|
|
8
|
+
return drizzle(connectionString, { casing: "snake_case" });
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type MssqlDb = ReturnType<typeof createMssqlDb>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DatabaseAdapter } from "@/adapters/database/index";
|
|
2
|
+
import type { StorageAdapter } from "@/adapters/storage/index";
|
|
3
|
+
import { createMssqlDb } from "./client";
|
|
4
|
+
import { createThreadsRepository } from "./threads";
|
|
5
|
+
import { createMessagesRepository } from "./messages";
|
|
6
|
+
import { createLlmRequestsRepository } from "./llm-requests";
|
|
7
|
+
import { createAttachmentsRepository } from "./attachments";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The MSSQL implementation of the database contract. One repository per table;
|
|
11
|
+
* only threads takes storage, because deleting a thread is the one operation
|
|
12
|
+
* that also has to reach into object storage.
|
|
13
|
+
*/
|
|
14
|
+
export function createMssqlAdapter(connectionString: string, storage?: StorageAdapter) {
|
|
15
|
+
const db = createMssqlDb(connectionString);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
threads: createThreadsRepository(db, storage),
|
|
19
|
+
messages: createMessagesRepository(db),
|
|
20
|
+
llmRequests: createLlmRequestsRepository(db),
|
|
21
|
+
attachments: createAttachmentsRepository(db),
|
|
22
|
+
} satisfies DatabaseAdapter;
|
|
23
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { asc, eq, type InferInsertModel } from "drizzle-orm";
|
|
2
|
+
import { llmRequests } from "@/db/schema.mssql";
|
|
3
|
+
import type { DatabaseAdapter } from "@/adapters/database/index";
|
|
4
|
+
import type { MssqlDb } from "./client";
|
|
5
|
+
|
|
6
|
+
export function createLlmRequestsRepository(db: MssqlDb) {
|
|
7
|
+
return {
|
|
8
|
+
async insert(requests) {
|
|
9
|
+
if (!requests.length) return;
|
|
10
|
+
|
|
11
|
+
await db
|
|
12
|
+
.insert(llmRequests)
|
|
13
|
+
.values(
|
|
14
|
+
requests.map(
|
|
15
|
+
(r) =>
|
|
16
|
+
({
|
|
17
|
+
messageId: r.messageId,
|
|
18
|
+
stepNumber: r.stepNumber,
|
|
19
|
+
prompt: r.prompt,
|
|
20
|
+
output: r.output,
|
|
21
|
+
tokenUsage: r.tokenUsage,
|
|
22
|
+
}) satisfies InferInsertModel<typeof llmRequests>,
|
|
23
|
+
),
|
|
24
|
+
)
|
|
25
|
+
.execute();
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
/** Ordered by step so the inspector replays a turn in the order it ran. */
|
|
29
|
+
async listByMessageId(messageId) {
|
|
30
|
+
return await db
|
|
31
|
+
.select({
|
|
32
|
+
id: llmRequests.id,
|
|
33
|
+
prompt: llmRequests.prompt,
|
|
34
|
+
output: llmRequests.output,
|
|
35
|
+
tokenUsage: llmRequests.tokenUsage,
|
|
36
|
+
})
|
|
37
|
+
.from(llmRequests)
|
|
38
|
+
.where(eq(llmRequests.messageId, messageId))
|
|
39
|
+
.orderBy(asc(llmRequests.stepNumber))
|
|
40
|
+
.execute();
|
|
41
|
+
},
|
|
42
|
+
} satisfies DatabaseAdapter["llmRequests"];
|
|
43
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// fallow-ignore-file duplicate-export -- mssql twin of the postgres repository, same factory name by design
|
|
2
|
+
import { and, desc, eq, getColumns, inArray, type InferInsertModel } from "drizzle-orm";
|
|
3
|
+
import { threads, messages } from "@/db/schema.mssql";
|
|
4
|
+
import type { ChatMessage } from "@/types";
|
|
5
|
+
import type { DatabaseAdapter } from "@/adapters/database/index";
|
|
6
|
+
import {
|
|
7
|
+
mergeStoredContent,
|
|
8
|
+
textOf,
|
|
9
|
+
withOwnedAttachments,
|
|
10
|
+
} from "@/adapters/database/message-content";
|
|
11
|
+
import type { MssqlDb } from "./client";
|
|
12
|
+
|
|
13
|
+
const DEFAULT_MESSAGE_LIMIT = 100;
|
|
14
|
+
|
|
15
|
+
export function createMessagesRepository(db: MssqlDb) {
|
|
16
|
+
return {
|
|
17
|
+
/**
|
|
18
|
+
* Fetches the newest N and reverses, so a limit keeps the most recent
|
|
19
|
+
* messages while callers still receive them oldest-first.
|
|
20
|
+
*/
|
|
21
|
+
async list(userId, threadId, opts) {
|
|
22
|
+
return await db
|
|
23
|
+
.select(getColumns(messages))
|
|
24
|
+
.from(messages)
|
|
25
|
+
.innerJoin(threads, eq(threads.id, messages.threadId))
|
|
26
|
+
.where(and(eq(threads.userId, userId), eq(threads.id, threadId)))
|
|
27
|
+
.orderBy(desc(messages.createdAt), desc(messages.ordinal))
|
|
28
|
+
.offset(0)
|
|
29
|
+
.fetch(opts?.limit ?? DEFAULT_MESSAGE_LIMIT)
|
|
30
|
+
.then((x) => x.reverse());
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Ids are client-generated, so a turn mixes new messages with edits to
|
|
35
|
+
* ones already stored. Splitting on existence lets the new ones go in as
|
|
36
|
+
* a single insert; the rest are updated individually.
|
|
37
|
+
*/
|
|
38
|
+
async upsert(
|
|
39
|
+
threadId: string,
|
|
40
|
+
messagesToUpsert: ChatMessage[],
|
|
41
|
+
options?: { replaceAttachments?: boolean },
|
|
42
|
+
) {
|
|
43
|
+
const incomingMessages = withOwnedAttachments(
|
|
44
|
+
messagesToUpsert,
|
|
45
|
+
options?.replaceAttachments,
|
|
46
|
+
);
|
|
47
|
+
const existingMessages = await db
|
|
48
|
+
.select({ id: messages.id, content: messages.content })
|
|
49
|
+
.from(messages)
|
|
50
|
+
.where(
|
|
51
|
+
inArray(
|
|
52
|
+
messages.id,
|
|
53
|
+
incomingMessages.map((x) => x.id),
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
.execute();
|
|
57
|
+
const existingById = new Map(
|
|
58
|
+
existingMessages.map((message) => [message.id, message.content]),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const newMessages = incomingMessages.filter((x) => !existingById.has(x.id));
|
|
62
|
+
if (newMessages.length) {
|
|
63
|
+
await db
|
|
64
|
+
.insert(messages)
|
|
65
|
+
.values(
|
|
66
|
+
newMessages.map(
|
|
67
|
+
(x, ordinal) =>
|
|
68
|
+
({
|
|
69
|
+
id: x.id,
|
|
70
|
+
role: x.role,
|
|
71
|
+
threadId,
|
|
72
|
+
content: x,
|
|
73
|
+
text: textOf(x),
|
|
74
|
+
ordinal,
|
|
75
|
+
}) satisfies InferInsertModel<typeof messages>,
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
.execute();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const message of incomingMessages.filter((x) => existingById.has(x.id))) {
|
|
82
|
+
const content = mergeStoredContent(existingById.get(message.id)!, message);
|
|
83
|
+
|
|
84
|
+
await db
|
|
85
|
+
.update(messages)
|
|
86
|
+
.set({ content, text: textOf(content) })
|
|
87
|
+
.where(eq(messages.id, message.id))
|
|
88
|
+
.execute();
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
} satisfies DatabaseAdapter["messages"];
|
|
92
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { and, desc, eq } from "drizzle-orm";
|
|
2
|
+
import { attachments, threads } from "@/db/schema.mssql";
|
|
3
|
+
import type { Thread } from "@/types";
|
|
4
|
+
import type { ThreadContextMeta } from "@/ai/context/types";
|
|
5
|
+
import type { DatabaseAdapter } from "@/adapters/database/index";
|
|
6
|
+
import type { MssqlDb } from "./client";
|
|
7
|
+
import type { StorageAdapter } from "@/adapters/storage/index";
|
|
8
|
+
|
|
9
|
+
export function createThreadsRepository(db: MssqlDb, storage?: StorageAdapter) {
|
|
10
|
+
return {
|
|
11
|
+
async list(userId, agentId) {
|
|
12
|
+
return await db
|
|
13
|
+
.select()
|
|
14
|
+
.from(threads)
|
|
15
|
+
.where(and(eq(threads.userId, userId), eq(threads.agentId, agentId)))
|
|
16
|
+
.orderBy(desc(threads.updatedAt), desc(threads.createdAt));
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
async getById(userId, threadId) {
|
|
20
|
+
const result = await db
|
|
21
|
+
.select()
|
|
22
|
+
.top(1)
|
|
23
|
+
.from(threads)
|
|
24
|
+
.where(and(eq(threads.id, threadId), eq(threads.userId, userId)))
|
|
25
|
+
.execute();
|
|
26
|
+
return result.length ? (result[0] as Thread) : null;
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
async create(userId, agentId) {
|
|
30
|
+
const result = await db.insert(threads).output().values({ userId, agentId }).execute();
|
|
31
|
+
return result[0] as Thread;
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/** Object storage has no foreign keys, so attachment paths must be swept before row cascade. */
|
|
35
|
+
async delete(userId, threadId) {
|
|
36
|
+
const attachmentPaths = await db
|
|
37
|
+
.select({ storageKey: attachments.storageKey })
|
|
38
|
+
.from(attachments)
|
|
39
|
+
.where(and(eq(attachments.threadId, threadId), eq(attachments.userId, userId)))
|
|
40
|
+
.execute()
|
|
41
|
+
.then((rows) => rows.map((row) => row.storageKey));
|
|
42
|
+
|
|
43
|
+
if (storage && attachmentPaths.length) {
|
|
44
|
+
await storage.delete(attachmentPaths);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Avoid SQL Server error 547 from the NO ACTION attachments.message_id constraint.
|
|
48
|
+
await db.delete(attachments).where(eq(attachments.threadId, threadId)).execute();
|
|
49
|
+
|
|
50
|
+
await db
|
|
51
|
+
.delete(threads)
|
|
52
|
+
.where(and(eq(threads.id, threadId), eq(threads.userId, userId)))
|
|
53
|
+
.execute();
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async touch(threadId) {
|
|
57
|
+
const result = await db
|
|
58
|
+
.update(threads)
|
|
59
|
+
.set({ updatedAt: new Date() })
|
|
60
|
+
.where(eq(threads.id, threadId))
|
|
61
|
+
.output()
|
|
62
|
+
.execute();
|
|
63
|
+
|
|
64
|
+
return result[0] as Thread;
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
async updateTitle(threadId, title) {
|
|
68
|
+
await db.update(threads).set({ title }).where(eq(threads.id, threadId)).execute();
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
async updateSession(threadId, session) {
|
|
72
|
+
await db.update(threads).set({ session }).where(eq(threads.id, threadId)).execute();
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async updateContextMeta(threadId, meta: ThreadContextMeta) {
|
|
76
|
+
await db
|
|
77
|
+
.update(threads)
|
|
78
|
+
.set({ contextMeta: meta })
|
|
79
|
+
.where(eq(threads.id, threadId))
|
|
80
|
+
.execute();
|
|
81
|
+
},
|
|
82
|
+
} satisfies DatabaseAdapter["threads"];
|
|
83
|
+
}
|