langgraph-runtime-pg 0.11.1__py3-none-any.whl

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.
@@ -0,0 +1,331 @@
1
+ """initial schema
2
+
3
+ Revision ID: 001_initial
4
+ Revises:
5
+ Create Date: 2026-07-25 21:48:52.124561
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from collections.abc import Sequence
11
+
12
+ import sqlalchemy as sa
13
+ from alembic import op
14
+ from sqlalchemy.dialects import postgresql
15
+
16
+ revision: str = "001_initial"
17
+ down_revision: str | Sequence[str] | None = None
18
+ branch_labels: str | Sequence[str] | None = None
19
+ depends_on: str | Sequence[str] | None = None
20
+
21
+
22
+ def upgrade() -> None:
23
+ # ### commands auto generated by Alembic - please adjust! ###
24
+ op.create_table(
25
+ "assistant_versions",
26
+ sa.Column("assistant_id", sa.UUID(), nullable=False),
27
+ sa.Column("version", sa.Integer(), nullable=False),
28
+ sa.Column("graph_id", sa.String(length=256), nullable=False),
29
+ sa.Column(
30
+ "config",
31
+ postgresql.JSONB(astext_type=sa.Text()),
32
+ server_default=sa.text("'{}'::jsonb"),
33
+ nullable=False,
34
+ ),
35
+ sa.Column(
36
+ "context",
37
+ postgresql.JSONB(astext_type=sa.Text()),
38
+ server_default=sa.text("'{}'::jsonb"),
39
+ nullable=False,
40
+ ),
41
+ sa.Column(
42
+ "metadata",
43
+ postgresql.JSONB(astext_type=sa.Text()),
44
+ server_default=sa.text("'{}'::jsonb"),
45
+ nullable=False,
46
+ ),
47
+ sa.Column("name", sa.String(length=512), nullable=False),
48
+ sa.Column("description", sa.Text(), nullable=True),
49
+ sa.Column(
50
+ "created_at",
51
+ sa.DateTime(timezone=True),
52
+ server_default=sa.text("now()"),
53
+ nullable=False,
54
+ ),
55
+ sa.PrimaryKeyConstraint("assistant_id", "version"),
56
+ )
57
+ op.create_table(
58
+ "assistants",
59
+ sa.Column("assistant_id", sa.UUID(), nullable=False),
60
+ sa.Column("graph_id", sa.String(length=256), nullable=False),
61
+ sa.Column("name", sa.String(length=512), nullable=False),
62
+ sa.Column("description", sa.Text(), nullable=True),
63
+ sa.Column(
64
+ "config",
65
+ postgresql.JSONB(astext_type=sa.Text()),
66
+ server_default=sa.text("'{}'::jsonb"),
67
+ nullable=False,
68
+ ),
69
+ sa.Column(
70
+ "context",
71
+ postgresql.JSONB(astext_type=sa.Text()),
72
+ server_default=sa.text("'{}'::jsonb"),
73
+ nullable=False,
74
+ ),
75
+ sa.Column(
76
+ "metadata",
77
+ postgresql.JSONB(astext_type=sa.Text()),
78
+ server_default=sa.text("'{}'::jsonb"),
79
+ nullable=False,
80
+ ),
81
+ sa.Column("version", sa.Integer(), nullable=False),
82
+ sa.Column(
83
+ "created_at",
84
+ sa.DateTime(timezone=True),
85
+ server_default=sa.text("now()"),
86
+ nullable=False,
87
+ ),
88
+ sa.Column(
89
+ "updated_at",
90
+ sa.DateTime(timezone=True),
91
+ server_default=sa.text("now()"),
92
+ nullable=False,
93
+ ),
94
+ sa.PrimaryKeyConstraint("assistant_id"),
95
+ )
96
+ op.create_index("ix_assistants_created_at", "assistants", ["created_at"], unique=False)
97
+ op.create_index("ix_assistants_graph_id", "assistants", ["graph_id"], unique=False)
98
+ op.create_index(
99
+ "ix_assistants_metadata_gin",
100
+ "assistants",
101
+ ["metadata"],
102
+ unique=False,
103
+ postgresql_using="gin",
104
+ postgresql_ops={"metadata": "jsonb_path_ops"},
105
+ )
106
+ op.create_table(
107
+ "crons",
108
+ sa.Column("cron_id", sa.UUID(), nullable=False),
109
+ sa.Column("assistant_id", sa.UUID(), nullable=False),
110
+ sa.Column("thread_id", sa.UUID(), nullable=True),
111
+ sa.Column("schedule", sa.String(length=128), nullable=False),
112
+ sa.Column(
113
+ "payload",
114
+ postgresql.JSONB(astext_type=sa.Text()),
115
+ server_default=sa.text("'{}'::jsonb"),
116
+ nullable=False,
117
+ ),
118
+ sa.Column(
119
+ "metadata",
120
+ postgresql.JSONB(astext_type=sa.Text()),
121
+ server_default=sa.text("'{}'::jsonb"),
122
+ nullable=False,
123
+ ),
124
+ sa.Column("next_run_date", sa.DateTime(timezone=True), nullable=True),
125
+ sa.Column("end_time", sa.DateTime(timezone=True), nullable=True),
126
+ sa.Column("user_id", sa.String(length=256), nullable=True),
127
+ sa.Column("timezone", sa.String(length=64), nullable=True),
128
+ sa.Column("on_run_completed", sa.String(length=16), nullable=True),
129
+ sa.Column("enabled", sa.Boolean(), server_default=sa.text("true"), nullable=False),
130
+ sa.Column(
131
+ "created_at",
132
+ sa.DateTime(timezone=True),
133
+ server_default=sa.text("now()"),
134
+ nullable=False,
135
+ ),
136
+ sa.Column(
137
+ "updated_at",
138
+ sa.DateTime(timezone=True),
139
+ server_default=sa.text("now()"),
140
+ nullable=False,
141
+ ),
142
+ sa.PrimaryKeyConstraint("cron_id"),
143
+ )
144
+ op.create_index("ix_crons_assistant_id", "crons", ["assistant_id"], unique=False)
145
+ op.create_index(
146
+ "ix_crons_enabled_next_run", "crons", ["enabled", "next_run_date"], unique=False
147
+ )
148
+ op.create_index(
149
+ "ix_crons_metadata_gin",
150
+ "crons",
151
+ ["metadata"],
152
+ unique=False,
153
+ postgresql_using="gin",
154
+ postgresql_ops={"metadata": "jsonb_path_ops"},
155
+ )
156
+ op.create_index("ix_crons_thread_id", "crons", ["thread_id"], unique=False)
157
+ op.create_table(
158
+ "retry_counters",
159
+ sa.Column("run_id", sa.UUID(), nullable=False),
160
+ sa.Column("count", sa.Integer(), nullable=False),
161
+ sa.PrimaryKeyConstraint("run_id"),
162
+ )
163
+ op.create_table(
164
+ "runs",
165
+ sa.Column("run_id", sa.UUID(), nullable=False),
166
+ sa.Column("thread_id", sa.UUID(), nullable=True),
167
+ sa.Column("assistant_id", sa.UUID(), nullable=False),
168
+ sa.Column("status", sa.String(length=32), nullable=False),
169
+ sa.Column(
170
+ "metadata",
171
+ postgresql.JSONB(astext_type=sa.Text()),
172
+ server_default=sa.text("'{}'::jsonb"),
173
+ nullable=False,
174
+ ),
175
+ sa.Column(
176
+ "kwargs",
177
+ postgresql.JSONB(astext_type=sa.Text()),
178
+ server_default=sa.text("'{}'::jsonb"),
179
+ nullable=False,
180
+ ),
181
+ sa.Column("multitask_strategy", sa.String(length=32), nullable=True),
182
+ sa.Column(
183
+ "created_at",
184
+ sa.DateTime(timezone=True),
185
+ server_default=sa.text("now()"),
186
+ nullable=False,
187
+ ),
188
+ sa.Column(
189
+ "updated_at",
190
+ sa.DateTime(timezone=True),
191
+ server_default=sa.text("now()"),
192
+ nullable=False,
193
+ ),
194
+ sa.PrimaryKeyConstraint("run_id"),
195
+ )
196
+ op.create_index("ix_runs_assistant_id_status", "runs", ["assistant_id", "status"], unique=False)
197
+ op.create_index("ix_runs_status_created_at", "runs", ["status", "created_at"], unique=False)
198
+ op.create_index(
199
+ "ix_runs_thread_id_created_at", "runs", ["thread_id", "created_at"], unique=False
200
+ )
201
+ op.create_index("ix_runs_thread_id_status", "runs", ["thread_id", "status"], unique=False)
202
+ op.create_index(
203
+ "uq_runs_one_running_per_thread",
204
+ "runs",
205
+ ["thread_id"],
206
+ unique=True,
207
+ postgresql_where=sa.text("status = 'running' AND thread_id IS NOT NULL"),
208
+ )
209
+ op.create_table(
210
+ "store_items",
211
+ sa.Column("prefix", sa.Text(), nullable=False),
212
+ sa.Column("key", sa.Text(), nullable=False),
213
+ sa.Column(
214
+ "value",
215
+ postgresql.JSONB(astext_type=sa.Text()),
216
+ server_default=sa.text("'{}'::jsonb"),
217
+ nullable=False,
218
+ ),
219
+ sa.Column(
220
+ "created_at",
221
+ sa.DateTime(timezone=True),
222
+ server_default=sa.text("now()"),
223
+ nullable=False,
224
+ ),
225
+ sa.Column(
226
+ "updated_at",
227
+ sa.DateTime(timezone=True),
228
+ server_default=sa.text("now()"),
229
+ nullable=False,
230
+ ),
231
+ sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True),
232
+ sa.PrimaryKeyConstraint("prefix", "key"),
233
+ )
234
+ op.create_table(
235
+ "threads",
236
+ sa.Column("thread_id", sa.UUID(), nullable=False),
237
+ sa.Column("status", sa.String(length=32), nullable=False),
238
+ sa.Column(
239
+ "metadata",
240
+ postgresql.JSONB(astext_type=sa.Text()),
241
+ server_default=sa.text("'{}'::jsonb"),
242
+ nullable=False,
243
+ ),
244
+ sa.Column(
245
+ "config",
246
+ postgresql.JSONB(astext_type=sa.Text()),
247
+ server_default=sa.text("'{}'::jsonb"),
248
+ nullable=False,
249
+ ),
250
+ sa.Column("values", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
251
+ sa.Column(
252
+ "interrupts",
253
+ postgresql.JSONB(astext_type=sa.Text()),
254
+ server_default=sa.text("'{}'::jsonb"),
255
+ nullable=False,
256
+ ),
257
+ sa.Column("error", postgresql.JSONB(astext_type=sa.Text()), nullable=True),
258
+ sa.Column(
259
+ "created_at",
260
+ sa.DateTime(timezone=True),
261
+ server_default=sa.text("now()"),
262
+ nullable=False,
263
+ ),
264
+ sa.Column(
265
+ "updated_at",
266
+ sa.DateTime(timezone=True),
267
+ server_default=sa.text("now()"),
268
+ nullable=False,
269
+ ),
270
+ sa.Column("state_updated_at", sa.DateTime(timezone=True), nullable=True),
271
+ sa.PrimaryKeyConstraint("thread_id"),
272
+ )
273
+ op.create_index(
274
+ "ix_threads_metadata_gin",
275
+ "threads",
276
+ ["metadata"],
277
+ unique=False,
278
+ postgresql_using="gin",
279
+ postgresql_ops={"metadata": "jsonb_path_ops"},
280
+ )
281
+ op.create_index(
282
+ "ix_threads_status_updated_at", "threads", ["status", "updated_at"], unique=False
283
+ )
284
+ op.create_index("ix_threads_updated_at", "threads", ["updated_at"], unique=False)
285
+ # ### end Alembic commands ###
286
+
287
+
288
+ def downgrade() -> None:
289
+ # ### commands auto generated by Alembic - please adjust! ###
290
+ op.drop_index("ix_threads_updated_at", table_name="threads")
291
+ op.drop_index("ix_threads_status_updated_at", table_name="threads")
292
+ op.drop_index(
293
+ "ix_threads_metadata_gin",
294
+ table_name="threads",
295
+ postgresql_using="gin",
296
+ postgresql_ops={"metadata": "jsonb_path_ops"},
297
+ )
298
+ op.drop_table("threads")
299
+ op.drop_table("store_items")
300
+ op.drop_index(
301
+ "uq_runs_one_running_per_thread",
302
+ table_name="runs",
303
+ postgresql_where=sa.text("status = 'running' AND thread_id IS NOT NULL"),
304
+ )
305
+ op.drop_index("ix_runs_thread_id_status", table_name="runs")
306
+ op.drop_index("ix_runs_thread_id_created_at", table_name="runs")
307
+ op.drop_index("ix_runs_status_created_at", table_name="runs")
308
+ op.drop_index("ix_runs_assistant_id_status", table_name="runs")
309
+ op.drop_table("runs")
310
+ op.drop_table("retry_counters")
311
+ op.drop_index("ix_crons_thread_id", table_name="crons")
312
+ op.drop_index(
313
+ "ix_crons_metadata_gin",
314
+ table_name="crons",
315
+ postgresql_using="gin",
316
+ postgresql_ops={"metadata": "jsonb_path_ops"},
317
+ )
318
+ op.drop_index("ix_crons_enabled_next_run", table_name="crons")
319
+ op.drop_index("ix_crons_assistant_id", table_name="crons")
320
+ op.drop_table("crons")
321
+ op.drop_index(
322
+ "ix_assistants_metadata_gin",
323
+ table_name="assistants",
324
+ postgresql_using="gin",
325
+ postgresql_ops={"metadata": "jsonb_path_ops"},
326
+ )
327
+ op.drop_index("ix_assistants_graph_id", table_name="assistants")
328
+ op.drop_index("ix_assistants_created_at", table_name="assistants")
329
+ op.drop_table("assistants")
330
+ op.drop_table("assistant_versions")
331
+ # ### end Alembic commands ###
@@ -0,0 +1 @@
1
+ """Alembic revision modules."""
@@ -0,0 +1,196 @@
1
+ """SQLAlchemy ORM models; schema DDL is applied via Alembic."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import uuid
6
+ from datetime import datetime
7
+
8
+ from sqlalchemy import DateTime, Index, Integer, String, Text, text
9
+ from sqlalchemy.dialects.postgresql import JSONB, UUID as PG_UUID
10
+ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
11
+
12
+
13
+ class Base(DeclarativeBase):
14
+ pass
15
+
16
+
17
+ class AssistantRow(Base):
18
+ __tablename__ = "assistants"
19
+ __table_args__ = (
20
+ Index("ix_assistants_graph_id", "graph_id"),
21
+ Index("ix_assistants_created_at", "created_at"),
22
+ Index(
23
+ "ix_assistants_metadata_gin",
24
+ "metadata",
25
+ postgresql_using="gin",
26
+ postgresql_ops={"metadata": "jsonb_path_ops"},
27
+ ),
28
+ )
29
+
30
+ assistant_id: Mapped[uuid.UUID] = mapped_column(
31
+ PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
32
+ )
33
+ graph_id: Mapped[str] = mapped_column(String(256), nullable=False)
34
+ name: Mapped[str] = mapped_column(String(512), nullable=False, default="")
35
+ description: Mapped[str | None] = mapped_column(Text, nullable=True)
36
+ config: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
37
+ context: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
38
+ metadata_: Mapped[dict] = mapped_column(
39
+ "metadata", JSONB, nullable=False, server_default=text("'{}'::jsonb")
40
+ )
41
+ version: Mapped[int] = mapped_column(Integer, nullable=False, default=1)
42
+ created_at: Mapped[datetime] = mapped_column(
43
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
44
+ )
45
+ updated_at: Mapped[datetime] = mapped_column(
46
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
47
+ )
48
+
49
+
50
+ class AssistantVersionRow(Base):
51
+ __tablename__ = "assistant_versions"
52
+
53
+ assistant_id: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True), primary_key=True)
54
+ version: Mapped[int] = mapped_column(Integer, primary_key=True)
55
+ graph_id: Mapped[str] = mapped_column(String(256), nullable=False)
56
+ config: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
57
+ context: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
58
+ metadata_: Mapped[dict] = mapped_column(
59
+ "metadata", JSONB, nullable=False, server_default=text("'{}'::jsonb")
60
+ )
61
+ name: Mapped[str] = mapped_column(String(512), nullable=False, default="")
62
+ description: Mapped[str | None] = mapped_column(Text, nullable=True)
63
+ created_at: Mapped[datetime] = mapped_column(
64
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
65
+ )
66
+
67
+
68
+ class ThreadRow(Base):
69
+ __tablename__ = "threads"
70
+ __table_args__ = (
71
+ Index("ix_threads_status_updated_at", "status", "updated_at"),
72
+ Index("ix_threads_updated_at", "updated_at"),
73
+ Index(
74
+ "ix_threads_metadata_gin",
75
+ "metadata",
76
+ postgresql_using="gin",
77
+ postgresql_ops={"metadata": "jsonb_path_ops"},
78
+ ),
79
+ )
80
+
81
+ thread_id: Mapped[uuid.UUID] = mapped_column(
82
+ PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
83
+ )
84
+ status: Mapped[str] = mapped_column(String(32), nullable=False, default="idle")
85
+ metadata_: Mapped[dict] = mapped_column(
86
+ "metadata", JSONB, nullable=False, server_default=text("'{}'::jsonb")
87
+ )
88
+ config: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
89
+ values_: Mapped[dict | None] = mapped_column("values", JSONB, nullable=True)
90
+ interrupts: Mapped[dict] = mapped_column(
91
+ JSONB, nullable=False, server_default=text("'{}'::jsonb")
92
+ )
93
+ error: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
94
+ created_at: Mapped[datetime] = mapped_column(
95
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
96
+ )
97
+ updated_at: Mapped[datetime] = mapped_column(
98
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
99
+ )
100
+ state_updated_at: Mapped[datetime | None] = mapped_column(
101
+ DateTime(timezone=True), nullable=True
102
+ )
103
+
104
+
105
+ class RunRow(Base):
106
+ __tablename__ = "runs"
107
+ __table_args__ = (
108
+ Index("ix_runs_status_created_at", "status", "created_at"),
109
+ Index("ix_runs_thread_id_status", "thread_id", "status"),
110
+ Index("ix_runs_thread_id_created_at", "thread_id", "created_at"),
111
+ Index("ix_runs_assistant_id_status", "assistant_id", "status"),
112
+ Index(
113
+ "uq_runs_one_running_per_thread",
114
+ "thread_id",
115
+ unique=True,
116
+ postgresql_where=text("status = 'running' AND thread_id IS NOT NULL"),
117
+ ),
118
+ )
119
+
120
+ run_id: Mapped[uuid.UUID] = mapped_column(
121
+ PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
122
+ )
123
+ thread_id: Mapped[uuid.UUID | None] = mapped_column(PG_UUID(as_uuid=True), nullable=True)
124
+ assistant_id: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True), nullable=False)
125
+ status: Mapped[str] = mapped_column(String(32), nullable=False, default="pending")
126
+ metadata_: Mapped[dict] = mapped_column(
127
+ "metadata", JSONB, nullable=False, server_default=text("'{}'::jsonb")
128
+ )
129
+ kwargs: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
130
+ multitask_strategy: Mapped[str | None] = mapped_column(String(32), nullable=True)
131
+ created_at: Mapped[datetime] = mapped_column(
132
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
133
+ )
134
+ updated_at: Mapped[datetime] = mapped_column(
135
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
136
+ )
137
+
138
+
139
+ class CronRow(Base):
140
+ __tablename__ = "crons"
141
+ __table_args__ = (
142
+ Index("ix_crons_enabled_next_run", "enabled", "next_run_date"),
143
+ Index("ix_crons_assistant_id", "assistant_id"),
144
+ Index("ix_crons_thread_id", "thread_id"),
145
+ Index(
146
+ "ix_crons_metadata_gin",
147
+ "metadata",
148
+ postgresql_using="gin",
149
+ postgresql_ops={"metadata": "jsonb_path_ops"},
150
+ ),
151
+ )
152
+
153
+ cron_id: Mapped[uuid.UUID] = mapped_column(
154
+ PG_UUID(as_uuid=True), primary_key=True, default=uuid.uuid4
155
+ )
156
+ assistant_id: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True), nullable=False)
157
+ thread_id: Mapped[uuid.UUID | None] = mapped_column(PG_UUID(as_uuid=True), nullable=True)
158
+ schedule: Mapped[str] = mapped_column(String(128), nullable=False)
159
+ payload: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
160
+ metadata_: Mapped[dict] = mapped_column(
161
+ "metadata", JSONB, nullable=False, server_default=text("'{}'::jsonb")
162
+ )
163
+ next_run_date: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
164
+ end_time: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
165
+ user_id: Mapped[str | None] = mapped_column(String(256), nullable=True)
166
+ timezone: Mapped[str | None] = mapped_column(String(64), nullable=True)
167
+ on_run_completed: Mapped[str | None] = mapped_column(String(16), nullable=True)
168
+ enabled: Mapped[bool] = mapped_column(nullable=False, default=True, server_default=text("true"))
169
+ created_at: Mapped[datetime] = mapped_column(
170
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
171
+ )
172
+ updated_at: Mapped[datetime] = mapped_column(
173
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
174
+ )
175
+
176
+
177
+ class StoreItemRow(Base):
178
+ __tablename__ = "store_items"
179
+
180
+ prefix: Mapped[str] = mapped_column(Text, primary_key=True)
181
+ key: Mapped[str] = mapped_column(Text, primary_key=True)
182
+ value: Mapped[dict] = mapped_column(JSONB, nullable=False, server_default=text("'{}'::jsonb"))
183
+ created_at: Mapped[datetime] = mapped_column(
184
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
185
+ )
186
+ updated_at: Mapped[datetime] = mapped_column(
187
+ DateTime(timezone=True), nullable=False, server_default=text("now()")
188
+ )
189
+ expires_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
190
+
191
+
192
+ class RetryCounterRow(Base):
193
+ __tablename__ = "retry_counters"
194
+
195
+ run_id: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True), primary_key=True)
196
+ count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)