@thoughtminers/agent-runtime-postgres 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 thoughtminers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @thoughtminers/agent-runtime-postgres
2
+
3
+ Postgres `ConversationStore` for `@thoughtminers/agent-runtime-core`, layered over **your**
4
+ Prisma client — the adapter never owns a `PrismaClient`, a connection pool, or
5
+ a migration pipeline.
6
+
7
+ ## Setup
8
+
9
+ 1. Copy the two models from [`prisma/schema.prisma`](prisma/schema.prisma) into
10
+ your application's schema (`simple_agent_messages` + `simple_agent_messages_llm`).
11
+ 2. Run your usual migration (`prisma migrate dev` / your deploy flow).
12
+ 3. Hand the adapter your generated client:
13
+
14
+ ```ts
15
+ import { PrismaClient } from '@prisma/client';
16
+ import { createPostgresStore } from '@thoughtminers/agent-runtime-postgres';
17
+
18
+ const prisma = new PrismaClient();
19
+ const store = createPostgresStore(prisma);
20
+ ```
21
+
22
+ `SimpleAgentDb` is a structural interface over the two model delegates, so any
23
+ client generated from the reference models satisfies it.
24
+
25
+ ## Guarantees
26
+
27
+ - `appendMessage` is idempotent on `(conversation_id, external_message_id)` —
28
+ the unique index + a P2002 catch make concurrent duplicate deliveries
29
+ converge on one row (race-tested).
30
+ - The trace table is append-only; only the `interrupted` flag is ever updated.
31
+
32
+ ## Integration test
33
+
34
+ ```bash
35
+ docker compose up -d
36
+ DATABASE_URL=postgresql://postgres:postgres@localhost:5439/simple_agent pnpm exec prisma db push
37
+ DATABASE_URL=postgresql://postgres:postgres@localhost:5439/simple_agent pnpm test
38
+ ```
39
+
40
+ Without `DATABASE_URL` the integration test skips; a fake-delegate conformance
41
+ test (no DB) always runs.
@@ -0,0 +1,98 @@
1
+ import type { ConversationStore } from '@thoughtminers/agent-runtime-core';
2
+ /**
3
+ * Postgres ConversationStore over the CONSUMER'S Prisma client — this adapter
4
+ * never owns a PrismaClient (no second connection pool, your migrations).
5
+ * Copy the models from ../prisma/schema.prisma into your schema, run your
6
+ * migration, then:
7
+ *
8
+ * const store = createPostgresStore(prisma);
9
+ *
10
+ * `SimpleAgentDb` is structural: any object exposing the two generated model
11
+ * delegates satisfies it.
12
+ */
13
+ export interface MessageRow {
14
+ id: string;
15
+ conversationId: string;
16
+ role: string;
17
+ content: string;
18
+ externalMessageId: string | null;
19
+ interrupted: boolean;
20
+ createdAt: Date;
21
+ }
22
+ export interface TraceRow {
23
+ id: string;
24
+ conversationId: string;
25
+ runId: string;
26
+ role: string;
27
+ content: string | null;
28
+ toolCalls: unknown;
29
+ model: string | null;
30
+ usage: unknown;
31
+ latencyMs: number | null;
32
+ interrupted: boolean;
33
+ createdAt: Date;
34
+ }
35
+ export interface SimpleAgentDb {
36
+ simpleAgentMessage: {
37
+ findFirst(args: {
38
+ where: {
39
+ conversationId: string;
40
+ externalMessageId: string;
41
+ };
42
+ }): Promise<MessageRow | null>;
43
+ findMany(args: {
44
+ where: {
45
+ conversationId: string;
46
+ };
47
+ orderBy: {
48
+ createdAt: 'asc';
49
+ };
50
+ take?: number;
51
+ }): Promise<MessageRow[]>;
52
+ create(args: {
53
+ data: {
54
+ id: string;
55
+ conversationId: string;
56
+ role: string;
57
+ content: string;
58
+ externalMessageId: string | null;
59
+ interrupted: boolean;
60
+ };
61
+ }): Promise<MessageRow>;
62
+ };
63
+ simpleAgentTrace: {
64
+ findMany(args: {
65
+ where: {
66
+ conversationId: string;
67
+ };
68
+ orderBy: {
69
+ createdAt: 'asc';
70
+ };
71
+ take?: number;
72
+ }): Promise<TraceRow[]>;
73
+ create(args: {
74
+ data: {
75
+ id: string;
76
+ conversationId: string;
77
+ runId: string;
78
+ role: string;
79
+ content: string | null;
80
+ toolCalls?: unknown;
81
+ model: string | null;
82
+ usage?: unknown;
83
+ latencyMs: number | null;
84
+ interrupted: boolean;
85
+ };
86
+ }): Promise<TraceRow>;
87
+ updateMany(args: {
88
+ where: {
89
+ runId: string;
90
+ };
91
+ data: {
92
+ interrupted: boolean;
93
+ };
94
+ }): Promise<unknown>;
95
+ };
96
+ }
97
+ export declare const createPostgresStore: (db: SimpleAgentDb) => ConversationStore;
98
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAKlB,MAAM,mCAAmC,CAAC;AAE3C;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,WAAW,EAA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AAE;QAChB,QAAQ,CAAC,IAAI,EAAE;YACb,KAAK,EAAE;gBAAE,cAAc,EAAE,MAAM,CAAA;aAAE,CAAC;YAClC,OAAO,EAAE;gBAAE,SAAS,EAAE,KAAK,CAAA;aAAE,CAAC;YAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;SACf,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACxB,MAAM,CAAC,IAAI,EAAE;YACX,IAAI,EAAE;gBACJ,EAAE,EAAE,MAAM,CAAC;gBACX,cAAc,EAAE,MAAM,CAAC;gBACvB,KAAK,EAAE,MAAM,CAAC;gBACd,IAAI,EAAE,MAAM,CAAC;gBACb,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;gBACvB,SAAS,CAAC,EAAE,OAAO,CAAC;gBACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;gBACrB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAChB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;gBACzB,WAAW,EAAE,OAAO,CAAC;aACtB,CAAC;SACH,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;QACtB,UAAU,CAAC,IAAI,EAAE;YACf,KAAK,EAAE;gBAAE,KAAK,EAAE,MAAM,CAAA;aAAE,CAAC;YACzB,IAAI,EAAE;gBAAE,WAAW,EAAE,OAAO,CAAA;aAAE,CAAC;SAChC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;KACtB,CAAC;CACH;AA6BD,eAAO,MAAM,mBAAmB,GAAI,IAAI,aAAa,KAAG,iBA2EtD,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,98 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ const isUniqueViolation = (err) => typeof err === 'object' && err !== null && err.code === 'P2002';
3
+ const toMessageRecord = (row) => ({
4
+ id: row.id,
5
+ conversationId: row.conversationId,
6
+ role: row.role,
7
+ content: row.content,
8
+ externalMessageId: row.externalMessageId,
9
+ interrupted: row.interrupted,
10
+ createdAt: row.createdAt,
11
+ });
12
+ const toTraceRecord = (row) => ({
13
+ id: row.id,
14
+ conversationId: row.conversationId,
15
+ runId: row.runId,
16
+ role: row.role,
17
+ content: row.content,
18
+ toolCalls: (row.toolCalls ?? null),
19
+ model: row.model,
20
+ usage: (row.usage ?? null),
21
+ latencyMs: row.latencyMs,
22
+ interrupted: row.interrupted,
23
+ createdAt: row.createdAt,
24
+ });
25
+ export const createPostgresStore = (db) => ({
26
+ seen: async (conversationId, externalMessageId) => (await db.simpleAgentMessage.findFirst({ where: { conversationId, externalMessageId } })) !==
27
+ null,
28
+ appendMessage: async (msg) => {
29
+ try {
30
+ const row = await db.simpleAgentMessage.create({
31
+ data: {
32
+ id: randomUUID(),
33
+ conversationId: msg.conversationId,
34
+ role: msg.role,
35
+ content: msg.content,
36
+ externalMessageId: msg.externalMessageId,
37
+ interrupted: msg.interrupted ?? false,
38
+ },
39
+ });
40
+ return toMessageRecord(row);
41
+ }
42
+ catch (err) {
43
+ // Idempotency: the (conversationId, externalMessageId) unique index
44
+ // fired — a concurrent or repeated delivery. Return the existing row.
45
+ if (isUniqueViolation(err) && msg.externalMessageId !== null) {
46
+ const existing = await db.simpleAgentMessage.findFirst({
47
+ where: {
48
+ conversationId: msg.conversationId,
49
+ externalMessageId: msg.externalMessageId,
50
+ },
51
+ });
52
+ if (existing)
53
+ return toMessageRecord(existing);
54
+ }
55
+ throw err;
56
+ }
57
+ },
58
+ appendTrace: async (row) => {
59
+ const created = await db.simpleAgentTrace.create({
60
+ data: {
61
+ id: randomUUID(),
62
+ conversationId: row.conversationId,
63
+ runId: row.runId,
64
+ role: row.role,
65
+ content: row.content,
66
+ // Omit null JSON columns so they default to SQL NULL.
67
+ ...(row.toolCalls !== null ? { toolCalls: row.toolCalls } : {}),
68
+ model: row.model,
69
+ ...(row.usage !== null ? { usage: row.usage } : {}),
70
+ latencyMs: row.latencyMs,
71
+ interrupted: row.interrupted ?? false,
72
+ },
73
+ });
74
+ return toTraceRecord(created);
75
+ },
76
+ loadHistory: async (conversationId, opts) => {
77
+ const [messages, trace] = await Promise.all([
78
+ db.simpleAgentMessage.findMany({
79
+ where: { conversationId },
80
+ orderBy: { createdAt: 'asc' },
81
+ ...(opts?.limit !== undefined ? { take: opts.limit } : {}),
82
+ }),
83
+ db.simpleAgentTrace.findMany({
84
+ where: { conversationId },
85
+ orderBy: { createdAt: 'asc' },
86
+ ...(opts?.limit !== undefined ? { take: opts.limit * 4 } : {}),
87
+ }),
88
+ ]);
89
+ return {
90
+ messages: messages.map(toMessageRecord),
91
+ trace: trace.map(toTraceRecord),
92
+ };
93
+ },
94
+ markRunInterrupted: async (runId) => {
95
+ await db.simpleAgentTrace.updateMany({ where: { runId }, data: { interrupted: true } });
96
+ },
97
+ });
98
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA6FzC,MAAM,iBAAiB,GAAG,CAAC,GAAY,EAAW,EAAE,CAClD,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,IAAK,GAA0B,CAAC,IAAI,KAAK,OAAO,CAAC;AAE1F,MAAM,eAAe,GAAG,CAAC,GAAe,EAAiB,EAAE,CAAC,CAAC;IAC3D,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,cAAc,EAAE,GAAG,CAAC,cAAc;IAClC,IAAI,EAAE,GAAG,CAAC,IAA6B;IACvC,OAAO,EAAE,GAAG,CAAC,OAAO;IACpB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;IACxC,WAAW,EAAE,GAAG,CAAC,WAAW;IAC5B,SAAS,EAAE,GAAG,CAAC,SAAS;CACzB,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,CAAC,GAAa,EAAe,EAAE,CAAC,CAAC;IACrD,EAAE,EAAE,GAAG,CAAC,EAAE;IACV,cAAc,EAAE,GAA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,EAAE,IAAI,EAAE,EAAE;QAC1C,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC1C,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC;gBAC7B,KAAK,EAAE,EAAE,cAAc,EAAE;gBACzB,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;gBAC7B,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3D,CAAC;YACF,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC;gBAC3B,KAAK,EAAE,EAAE,cAAc,EAAE;gBACzB,OAAO,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;gBAC7B,GAAG,CAAC,IAAI,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC/D,CAAC;SACH,CAAC,CAAC;QACH,OAAO;YACL,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC;YACvC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC;SAChC,CAAC;IACJ,CAAC;IAED,kBAAkB,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QAClC,MAAM,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC1F,CAAC;CACF,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@thoughtminers/agent-runtime-postgres",
3
+ "version": "0.1.0",
4
+ "description": "Postgres/Prisma ConversationStore adapter for @thoughtminers/agent-runtime-core (structural interface over your Prisma client).",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/thoughtminers/agent-runtime-core.git",
9
+ "directory": "packages/store-postgres"
10
+ },
11
+ "homepage": "https://github.com/thoughtminers/agent-runtime-core#readme",
12
+ "bugs": "https://github.com/thoughtminers/agent-runtime-core/issues",
13
+ "type": "module",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "prisma"
23
+ ],
24
+ "engines": {
25
+ "node": ">=24"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {
31
+ "@thoughtminers/agent-runtime-core": "0.1.0"
32
+ },
33
+ "peerDependencies": {
34
+ "@prisma/client": ">=6"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@prisma/client": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "devDependencies": {
42
+ "@prisma/client": "^7.9.1",
43
+ "@types/node": "^24.0.0",
44
+ "prisma": "^7.9.1",
45
+ "typescript": "^5.8.0"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc --build",
49
+ "test": "node --test 'test/**/*.test.ts'"
50
+ }
51
+ }
@@ -0,0 +1,53 @@
1
+ // Reference schema for @simple-agent/store-postgres.
2
+ //
3
+ // COPY the two models below into your application's Prisma schema (or drop
4
+ // this file into your prisma/schema folder). The adapter takes YOUR generated
5
+ // client — it never owns a PrismaClient or a migration pipeline.
6
+ //
7
+ // The datasource/generator blocks exist so this file also works standalone
8
+ // for the adapter's own integration tests.
9
+
10
+ datasource db {
11
+ provider = "postgresql"
12
+ url = env("DATABASE_URL")
13
+ }
14
+
15
+ generator client {
16
+ provider = "prisma-client-js"
17
+ }
18
+
19
+ // User-facing transcript — what the human saw.
20
+ model SimpleAgentMessage {
21
+ id String @id
22
+ conversationId String @map("conversation_id")
23
+ role String @db.VarChar(16) // user | assistant
24
+ content String
25
+ externalMessageId String? @map("external_message_id") // idempotency key
26
+ interrupted Boolean @default(false)
27
+ createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
28
+
29
+ @@unique([conversationId, externalMessageId])
30
+ @@index([conversationId, createdAt])
31
+ @@map("simple_agent_messages")
32
+ }
33
+
34
+ // Append-only raw agent trace — what the model actually did. The wire payload
35
+ // is reconstructed at replay time (per-tool compaction policies applied);
36
+ // rows are never mutated except the interrupted flag.
37
+ model SimpleAgentTrace {
38
+ id String @id
39
+ conversationId String @map("conversation_id")
40
+ runId String @map("run_id") // groups all rows of one agent run
41
+ role String @db.VarChar(16) // user | assistant
42
+ content String?
43
+ toolCalls Json? @map("tool_calls") // ToolCallEntry[]: call + result together
44
+ model String? @db.VarChar(128)
45
+ usage Json? // { inputTokens, outputTokens, cache* }
46
+ latencyMs Int? @map("latency_ms")
47
+ interrupted Boolean @default(false)
48
+ createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
49
+
50
+ @@index([conversationId, createdAt])
51
+ @@index([runId])
52
+ @@map("simple_agent_messages_llm")
53
+ }