Skip to content

Commit c8ef5a4

Browse files
committed
chore: format
1 parent 53583f8 commit c8ef5a4

92 files changed

Lines changed: 3563 additions & 682 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/open_webui/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ async def lifespan(app: FastAPI):
650650
asyncio.create_task(periodic_session_pool_cleanup())
651651

652652
from open_webui.utils.automations import automation_worker_loop
653+
653654
asyncio.create_task(automation_worker_loop(app))
654655

655656
if app.state.config.ENABLE_BASE_MODELS_CACHE:

backend/open_webui/migrations/versions/b7c8d9e0f1a2_add_last_read_at_to_chat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Create Date: 2026-04-01 04:00:00.000000
66
77
"""
8+
89
from alembic import op
910
import sqlalchemy as sa
1011

backend/open_webui/migrations/versions/d4e5f6a7b8c9_add_automation_tables.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,51 @@
1010
from alembic import op
1111
import sqlalchemy as sa
1212

13-
revision: str = "d4e5f6a7b8c9"
14-
down_revision: Union[str, None] = "a3dd5bedd151"
13+
revision: str = 'd4e5f6a7b8c9'
14+
down_revision: Union[str, None] = 'a3dd5bedd151'
1515
branch_labels = None
1616
depends_on = None
1717

1818

1919
def upgrade():
2020
op.create_table(
21-
"automation",
22-
sa.Column("id", sa.Text(), primary_key=True),
23-
sa.Column("user_id", sa.Text(), nullable=False),
24-
sa.Column("name", sa.Text(), nullable=False),
25-
sa.Column("data", sa.JSON(), nullable=False),
26-
sa.Column("meta", sa.JSON(), nullable=True),
21+
'automation',
22+
sa.Column('id', sa.Text(), primary_key=True),
23+
sa.Column('user_id', sa.Text(), nullable=False),
24+
sa.Column('name', sa.Text(), nullable=False),
25+
sa.Column('data', sa.JSON(), nullable=False),
26+
sa.Column('meta', sa.JSON(), nullable=True),
2727
sa.Column(
28-
"is_active",
28+
'is_active',
2929
sa.Boolean(),
3030
nullable=False,
31-
server_default=sa.text("1"),
31+
server_default=sa.text('1'),
3232
),
33-
sa.Column("last_run_at", sa.BigInteger(), nullable=True),
34-
sa.Column("next_run_at", sa.BigInteger(), nullable=True),
35-
sa.Column("created_at", sa.BigInteger(), nullable=False),
36-
sa.Column("updated_at", sa.BigInteger(), nullable=False),
33+
sa.Column('last_run_at', sa.BigInteger(), nullable=True),
34+
sa.Column('next_run_at', sa.BigInteger(), nullable=True),
35+
sa.Column('created_at', sa.BigInteger(), nullable=False),
36+
sa.Column('updated_at', sa.BigInteger(), nullable=False),
3737
)
38-
op.create_index("ix_automation_next_run", "automation", ["next_run_at"])
38+
op.create_index('ix_automation_next_run', 'automation', ['next_run_at'])
3939

4040
op.create_table(
41-
"automation_run",
42-
sa.Column("id", sa.Text(), primary_key=True),
43-
sa.Column("automation_id", sa.Text(), nullable=False),
44-
sa.Column("chat_id", sa.Text(), nullable=True),
45-
sa.Column("status", sa.Text(), nullable=False),
46-
sa.Column("error", sa.Text(), nullable=True),
47-
sa.Column("created_at", sa.BigInteger(), nullable=False),
41+
'automation_run',
42+
sa.Column('id', sa.Text(), primary_key=True),
43+
sa.Column('automation_id', sa.Text(), nullable=False),
44+
sa.Column('chat_id', sa.Text(), nullable=True),
45+
sa.Column('status', sa.Text(), nullable=False),
46+
sa.Column('error', sa.Text(), nullable=True),
47+
sa.Column('created_at', sa.BigInteger(), nullable=False),
4848
)
4949
op.create_index(
50-
"ix_automation_run_automation_id",
51-
"automation_run",
52-
["automation_id"],
50+
'ix_automation_run_automation_id',
51+
'automation_run',
52+
['automation_id'],
5353
)
5454

5555

5656
def downgrade():
57-
op.drop_index("ix_automation_run_automation_id")
58-
op.drop_table("automation_run")
59-
op.drop_index("ix_automation_next_run")
60-
op.drop_table("automation")
57+
op.drop_index('ix_automation_run_automation_id')
58+
op.drop_table('automation_run')
59+
op.drop_index('ix_automation_next_run')
60+
op.drop_table('automation')

backend/open_webui/models/automations.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
class Automation(Base):
21-
__tablename__ = "automation"
21+
__tablename__ = 'automation'
2222

2323
id = Column(Text, primary_key=True)
2424
user_id = Column(Text, nullable=False)
@@ -32,13 +32,11 @@ class Automation(Base):
3232
created_at = Column(BigInteger, nullable=False)
3333
updated_at = Column(BigInteger, nullable=False)
3434

35-
__table_args__ = (
36-
Index("ix_automation_next_run", "next_run_at"),
37-
)
35+
__table_args__ = (Index('ix_automation_next_run', 'next_run_at'),)
3836

3937

4038
class AutomationRun(Base):
41-
__tablename__ = "automation_run"
39+
__tablename__ = 'automation_run'
4240

4341
id = Column(Text, primary_key=True)
4442
automation_id = Column(Text, nullable=False)
@@ -47,9 +45,7 @@ class AutomationRun(Base):
4745
error = Column(Text, nullable=True)
4846
created_at = Column(BigInteger, nullable=False)
4947

50-
__table_args__ = (
51-
Index("ix_automation_run_automation_id", "automation_id"),
52-
)
48+
__table_args__ = (Index('ix_automation_run_automation_id', 'automation_id'),)
5349

5450

5551
####################
@@ -119,7 +115,6 @@ class AutomationListResponse(BaseModel):
119115

120116

121117
class AutomationTable:
122-
123118
def insert(
124119
self,
125120
user_id: str,
@@ -145,9 +140,7 @@ def insert(
145140
db.refresh(row)
146141
return AutomationModel.model_validate(row)
147142

148-
def get_by_id(
149-
self, id: str, db: Optional[Session] = None
150-
) -> Optional[AutomationModel]:
143+
def get_by_id(self, id: str, db: Optional[Session] = None) -> Optional[AutomationModel]:
151144
with get_db_context(db) as db:
152145
row = db.get(Automation, id)
153146
return AutomationModel.model_validate(row) if row else None
@@ -242,9 +235,7 @@ def delete(self, id: str, db: Optional[Session] = None) -> bool:
242235
db.commit()
243236
return True
244237

245-
def claim_due(
246-
self, now_ns: int, limit: int = 10, db: Optional[Session] = None
247-
) -> list[AutomationModel]:
238+
def claim_due(self, now_ns: int, limit: int = 10, db: Optional[Session] = None) -> list[AutomationModel]:
248239
"""
249240
Atomically claim due automations for execution.
250241
@@ -263,7 +254,7 @@ def claim_due(
263254
.limit(limit)
264255
)
265256

266-
if db.bind.dialect.name == "postgresql":
257+
if db.bind.dialect.name == 'postgresql':
267258
stmt = stmt.with_for_update(skip_locked=True)
268259

269260
rows = db.execute(stmt).scalars().all()
@@ -272,7 +263,7 @@ def claim_due(
272263

273264
for row in rows:
274265
row.last_run_at = now_ns
275-
row.next_run_at = next_run_ns(row.data.get("rrule", ""))
266+
row.next_run_at = next_run_ns(row.data.get('rrule', ''))
276267

277268
db.commit()
278269

@@ -285,7 +276,6 @@ def claim_due(
285276

286277

287278
class AutomationRunTable:
288-
289279
def insert(
290280
self,
291281
automation_id: str,
@@ -308,9 +298,7 @@ def insert(
308298
db.refresh(row)
309299
return AutomationRunModel.model_validate(row)
310300

311-
def get_latest(
312-
self, automation_id: str, db: Optional[Session] = None
313-
) -> Optional[AutomationRunModel]:
301+
def get_latest(self, automation_id: str, db: Optional[Session] = None) -> Optional[AutomationRunModel]:
314302
with get_db_context(db) as db:
315303
row = (
316304
db.query(AutomationRun)
@@ -338,15 +326,9 @@ def get_by_automation(
338326
)
339327
return [AutomationRunModel.model_validate(r) for r in rows]
340328

341-
def delete_by_automation(
342-
self, automation_id: str, db: Optional[Session] = None
343-
) -> int:
329+
def delete_by_automation(self, automation_id: str, db: Optional[Session] = None) -> int:
344330
with get_db_context(db) as db:
345-
count = (
346-
db.query(AutomationRun)
347-
.filter_by(automation_id=automation_id)
348-
.delete()
349-
)
331+
count = db.query(AutomationRun).filter_by(automation_id=automation_id).delete()
350332
db.commit()
351333
return count
352334

backend/open_webui/models/chats.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,7 @@ def update_chat_by_id(self, id: str, chat: dict, db: Optional[Session] = None) -
402402
except Exception:
403403
return None
404404

405-
def update_chat_last_read_at_by_id(
406-
self, id: str, user_id: str, db: Optional[Session] = None
407-
) -> bool:
405+
def update_chat_last_read_at_by_id(self, id: str, user_id: str, db: Optional[Session] = None) -> bool:
408406
try:
409407
with get_db_context(db) as db:
410408
chat = db.get(Chat, id)

backend/open_webui/routers/automations.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def check_automation_access(automation, user):
6060
)
6161

6262

63-
def enrich_automation(
64-
automation: AutomationModel, db: Session, tz: str = None
65-
) -> AutomationResponse:
63+
def enrich_automation(automation: AutomationModel, db: Session, tz: str = None) -> AutomationResponse:
6664
last_run = AutomationRuns.get_latest(automation.id, db=db)
6765
return AutomationResponse(
6866
**automation.model_dump(),
@@ -100,10 +98,7 @@ async def get_automation_items(
10098
)
10199

102100
return {
103-
'items': [
104-
enrich_automation(item, db, tz=user.timezone)
105-
for item in result.items
106-
],
101+
'items': [enrich_automation(item, db, tz=user.timezone) for item in result.items],
107102
'total': result.total,
108103
}
109104

@@ -139,9 +134,7 @@ async def create_new_automation(
139134
)
140135

141136
tz = user.timezone
142-
automation = Automations.insert(
143-
user.id, form_data, next_run_ns(form_data.data.rrule, tz=tz), db=db
144-
)
137+
automation = Automations.insert(user.id, form_data, next_run_ns(form_data.data.rrule, tz=tz), db=db)
145138
return enrich_automation(automation, db, tz=tz)
146139

147140

@@ -198,9 +191,7 @@ async def update_automation_by_id(
198191
)
199192

200193
tz = user.timezone
201-
updated = Automations.update_by_id(
202-
id, form_data, next_run_ns(form_data.data.rrule, tz=tz), db=db
203-
)
194+
updated = Automations.update_by_id(id, form_data, next_run_ns(form_data.data.rrule, tz=tz), db=db)
204195
return enrich_automation(updated, db, tz=tz)
205196

206197

@@ -219,9 +210,7 @@ async def toggle_automation_by_id(
219210
check_automations_permission(request, user)
220211
automation = Automations.get_by_id(id, db=db)
221212
check_automation_access(automation, user)
222-
toggled = Automations.toggle(
223-
id, next_run_ns(automation.data['rrule'], tz=user.timezone), db=db
224-
)
213+
toggled = Automations.toggle(id, next_run_ns(automation.data['rrule'], tz=user.timezone), db=db)
225214
return enrich_automation(toggled, db, tz=user.timezone)
226215

227216

@@ -281,6 +270,3 @@ async def get_automation_runs(
281270
automation = Automations.get_by_id(id, db=db)
282271
check_automation_access(automation, user)
283272
return AutomationRuns.get_by_automation(id, skip=skip, limit=limit, db=db)
284-
285-
286-

backend/open_webui/socket/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,7 @@ async def chat_events(sid, data):
501501
event_type = event_data.get('type')
502502

503503
if event_type == 'last_read_at':
504-
await asyncio.to_thread(
505-
Chats.update_chat_last_read_at_by_id,
506-
data['chat_id'], user['id']
507-
)
504+
await asyncio.to_thread(Chats.update_chat_last_read_at_by_id, data['chat_id'], user['id'])
508505

509506

510507
def normalize_document_id(document_id: str) -> str:

backend/open_webui/tools/builtin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,9 +2339,9 @@ async def view_skill(
23392339

23402340

23412341
class TaskItem(BaseModel):
2342-
id: Optional[str] = Field(None, description="Unique identifier for the task. Auto-generated if omitted.")
2343-
content: Optional[str] = Field(None, description="Task description. Aliases: title, name, description.")
2344-
status: Literal['pending', 'in_progress', 'completed', 'cancelled'] = Field('pending', description="Task status.")
2342+
id: Optional[str] = Field(None, description='Unique identifier for the task. Auto-generated if omitted.')
2343+
content: Optional[str] = Field(None, description='Task description. Aliases: title, name, description.')
2344+
status: Literal['pending', 'in_progress', 'completed', 'cancelled'] = Field('pending', description='Task status.')
23452345

23462346

23472347
async def tasks(

0 commit comments

Comments
 (0)