lambda-erp 1.4.26__tar.gz → 1.4.28__tar.gz
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.
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/PKG-INFO +1 -1
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/attachments.py +41 -36
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/chat.py +16 -6
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/frontend/src/api/client.ts +5 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/database.py +11 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/pyproject.toml +1 -1
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/.gitignore +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/LICENSE +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/README.md +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/auth.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/chat_links.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/deps.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/erp_context.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/errors.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/list_values.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/main.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/mentions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/oauth.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/providers.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/record_notes.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/services.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/document.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/record.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/time_filters.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/tool_results.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/api/write_context.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/frontend/README.md +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/units.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.28}/terraform/README.md +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
"""Chat attachment upload/download. Files
|
|
1
|
+
"""Chat attachment upload/download. Files follow the chat database unless a deployment configures upload storage."""
|
|
2
2
|
|
|
3
3
|
import base64
|
|
4
4
|
import io
|
|
5
5
|
import logging
|
|
6
6
|
import os
|
|
7
|
-
import tempfile
|
|
8
7
|
import time
|
|
9
8
|
import uuid
|
|
10
9
|
from typing import Optional
|
|
@@ -196,17 +195,9 @@ def spreadsheet_row_warning(data: bytes, mime: str, filename: str) -> Optional[s
|
|
|
196
195
|
"Split the file or ask about a specific range.")
|
|
197
196
|
return None
|
|
198
197
|
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
|
|
202
|
-
# app user, so every upload 500s with "[Errno 13] Permission denied". Default to
|
|
203
|
-
# the OS temp dir (always writable; chat attachments are session-scoped and
|
|
204
|
-
# get_attachments_by_ids tolerates a missing file). Deployments that need the
|
|
205
|
-
# files to survive a restart set LAMBDA_ERP_UPLOAD_DIR to a mounted volume.
|
|
206
|
-
UPLOAD_ROOT = (
|
|
207
|
-
os.environ.get("LAMBDA_ERP_UPLOAD_DIR")
|
|
208
|
-
or os.path.join(tempfile.gettempdir(), "lambda-erp-uploads")
|
|
209
|
-
)
|
|
198
|
+
# Explicitly configured volumes retain their existing filesystem storage mode.
|
|
199
|
+
# Otherwise keep the bytes in the same database transaction as their metadata.
|
|
200
|
+
UPLOAD_ROOT = os.environ.get("LAMBDA_ERP_UPLOAD_DIR")
|
|
210
201
|
|
|
211
202
|
|
|
212
203
|
def _ensure_upload_dir(user_id: str) -> str:
|
|
@@ -297,18 +288,27 @@ async def upload_attachment(
|
|
|
297
288
|
att_id = uuid.uuid4().hex
|
|
298
289
|
ext = _safe_ext(file.filename or "", mime)
|
|
299
290
|
user_id = user["name"]
|
|
300
|
-
|
|
301
|
-
|
|
291
|
+
file_path = ""
|
|
292
|
+
if UPLOAD_ROOT:
|
|
293
|
+
upload_dir = _ensure_upload_dir(user_id)
|
|
294
|
+
file_path = os.path.join(upload_dir, f"{att_id}.{ext}")
|
|
302
295
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
296
|
+
try:
|
|
297
|
+
if file_path:
|
|
298
|
+
with open(file_path, "wb") as f:
|
|
299
|
+
f.write(data)
|
|
300
|
+
db.sql(
|
|
301
|
+
'INSERT INTO "Chat Attachment" (id, session_id, user_id, filename, mime_type, size_bytes, file_path, data, created_at) '
|
|
302
|
+
'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
|
303
|
+
[att_id, session_id, user_id, file.filename or f"file.{ext}", mime, len(data), file_path,
|
|
304
|
+
None if file_path else data, now()],
|
|
305
|
+
)
|
|
306
|
+
db.conn.commit()
|
|
307
|
+
except Exception:
|
|
308
|
+
db.conn.rollback()
|
|
309
|
+
if file_path and os.path.isfile(file_path):
|
|
310
|
+
os.remove(file_path)
|
|
311
|
+
raise
|
|
312
312
|
|
|
313
313
|
resp = {
|
|
314
314
|
"id": att_id,
|
|
@@ -325,6 +325,16 @@ async def upload_attachment(
|
|
|
325
325
|
return resp
|
|
326
326
|
|
|
327
327
|
|
|
328
|
+
def _attachment_bytes(row: dict) -> bytes | None:
|
|
329
|
+
if row["data"] is not None:
|
|
330
|
+
return bytes(row["data"])
|
|
331
|
+
try:
|
|
332
|
+
with open(row["file_path"], "rb") as f:
|
|
333
|
+
return f.read()
|
|
334
|
+
except FileNotFoundError:
|
|
335
|
+
return None
|
|
336
|
+
|
|
337
|
+
|
|
328
338
|
@router.get("/attachments/{attachment_id}")
|
|
329
339
|
def download_attachment(
|
|
330
340
|
attachment_id: str,
|
|
@@ -333,7 +343,7 @@ def download_attachment(
|
|
|
333
343
|
"""Download a chat attachment. Scoped to the owning user."""
|
|
334
344
|
db = get_db()
|
|
335
345
|
rows = db.sql(
|
|
336
|
-
'SELECT filename, mime_type, file_path, user_id FROM "Chat Attachment" WHERE id = ?',
|
|
346
|
+
'SELECT filename, mime_type, file_path, data, user_id FROM "Chat Attachment" WHERE id = ?',
|
|
337
347
|
[attachment_id],
|
|
338
348
|
)
|
|
339
349
|
if not rows:
|
|
@@ -344,12 +354,10 @@ def download_attachment(
|
|
|
344
354
|
if row["user_id"] != user["name"] and user.get("role") != "admin":
|
|
345
355
|
raise HTTPException(status_code=403, detail="Not authorized")
|
|
346
356
|
|
|
347
|
-
|
|
357
|
+
data = _attachment_bytes(row)
|
|
358
|
+
if data is None:
|
|
348
359
|
raise HTTPException(status_code=404, detail="File missing on disk")
|
|
349
360
|
|
|
350
|
-
with open(row["file_path"], "rb") as f:
|
|
351
|
-
data = f.read()
|
|
352
|
-
|
|
353
361
|
return Response(
|
|
354
362
|
content=data,
|
|
355
363
|
media_type=row["mime_type"],
|
|
@@ -369,16 +377,15 @@ def get_attachments_by_ids(attachment_ids: list[str], user_id: str) -> list[dict
|
|
|
369
377
|
db = get_db()
|
|
370
378
|
placeholders = ",".join(["?"] * len(attachment_ids))
|
|
371
379
|
rows = db.sql(
|
|
372
|
-
f'SELECT id, filename, mime_type, file_path, size_bytes, '
|
|
380
|
+
f'SELECT id, filename, mime_type, file_path, data, size_bytes, '
|
|
373
381
|
f'openai_file_id, openai_file_expires_at FROM "Chat Attachment" '
|
|
374
382
|
f'WHERE id IN ({placeholders}) AND user_id = ?',
|
|
375
383
|
list(attachment_ids) + [user_id],
|
|
376
384
|
)
|
|
377
385
|
result = []
|
|
378
386
|
for row in rows:
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
data = f.read()
|
|
387
|
+
data = _attachment_bytes(row)
|
|
388
|
+
if data is not None:
|
|
382
389
|
result.append({
|
|
383
390
|
"id": row["id"],
|
|
384
391
|
"filename": row["filename"],
|
|
@@ -388,8 +395,6 @@ def get_attachments_by_ids(attachment_ids: list[str], user_id: str) -> list[dict
|
|
|
388
395
|
"openai_file_expires_at": row.get("openai_file_expires_at"),
|
|
389
396
|
"data": data,
|
|
390
397
|
})
|
|
391
|
-
except FileNotFoundError:
|
|
392
|
-
continue
|
|
393
398
|
return result
|
|
394
399
|
|
|
395
400
|
|
|
@@ -474,7 +479,7 @@ def list_session_attachments(session_id: str, user_id: str) -> list[dict]:
|
|
|
474
479
|
def delete_session_attachments(session_id: str) -> None:
|
|
475
480
|
"""Delete all attachments (DB + files) for a session. Used on chat clear/delete."""
|
|
476
481
|
db = get_db()
|
|
477
|
-
rows = db.sql('SELECT file_path FROM "Chat Attachment" WHERE session_id = ?', [session_id])
|
|
482
|
+
rows = db.sql('SELECT file_path FROM "Chat Attachment" WHERE session_id = ? AND length(file_path) > 0', [session_id])
|
|
478
483
|
for r in rows:
|
|
479
484
|
try:
|
|
480
485
|
os.remove(r["file_path"])
|
|
@@ -255,9 +255,15 @@ def delete_session(session_id: str):
|
|
|
255
255
|
db.conn.commit()
|
|
256
256
|
|
|
257
257
|
|
|
258
|
-
def update_session_title(session_id: str, title: str):
|
|
258
|
+
def update_session_title(session_id: str, title: str, *, generated: bool = False):
|
|
259
259
|
db = get_db()
|
|
260
|
-
|
|
260
|
+
if generated:
|
|
261
|
+
# A first-turn title can finish after an operator has already renamed the chat.
|
|
262
|
+
db.sql('''UPDATE "Chat Session" SET title = ?, updated_at = CURRENT_TIMESTAMP
|
|
263
|
+
WHERE id = ? AND title_is_manual = 0 AND title = ?''', [title, session_id, "New Chat"])
|
|
264
|
+
else:
|
|
265
|
+
db.sql('''UPDATE "Chat Session" SET title = ?, title_is_manual = 1, updated_at = CURRENT_TIMESTAMP
|
|
266
|
+
WHERE id = ?''', [title, session_id])
|
|
261
267
|
db.conn.commit()
|
|
262
268
|
|
|
263
269
|
|
|
@@ -557,9 +563,10 @@ def api_rename_session(session_id: str, data: dict, user: dict = _Depends(get_cu
|
|
|
557
563
|
session = get_session(session_id)
|
|
558
564
|
if not can_access_session(session, user):
|
|
559
565
|
return {"detail": "Session not found"}
|
|
560
|
-
title = data.get("title"
|
|
561
|
-
if title:
|
|
562
|
-
|
|
566
|
+
title = data.get("title")
|
|
567
|
+
if not isinstance(title, str) or not title.strip():
|
|
568
|
+
raise HTTPException(status_code=422, detail="A chat name is required.")
|
|
569
|
+
update_session_title(session_id, title.strip())
|
|
563
570
|
return {"ok": True}
|
|
564
571
|
|
|
565
572
|
|
|
@@ -2247,6 +2254,9 @@ def _handle_retrieve_chat_attachment(args, session_id: str | None = None, user_i
|
|
|
2247
2254
|
from api.attachments import get_attachments_by_ids, build_multimodal_content
|
|
2248
2255
|
atts = get_attachments_by_ids([attachment_id], user_id)
|
|
2249
2256
|
if not atts:
|
|
2257
|
+
if get_db().sql('SELECT id FROM "Chat Attachment" WHERE id = ? AND session_id = ? AND user_id = ?',
|
|
2258
|
+
[attachment_id, session_id, user_id]):
|
|
2259
|
+
return {"error": "The attachment is listed in this chat, but its stored file is missing."}
|
|
2250
2260
|
return {"error": "Attachment not found or access denied."}
|
|
2251
2261
|
att = atts[0]
|
|
2252
2262
|
return {
|
|
@@ -3808,7 +3818,7 @@ async def generate_title(
|
|
|
3808
3818
|
|
|
3809
3819
|
title = (response.output_text or "").strip().strip('"\'')[:120]
|
|
3810
3820
|
if title:
|
|
3811
|
-
update_session_title(session_id, title)
|
|
3821
|
+
update_session_title(session_id, title, generated=True)
|
|
3812
3822
|
print(f"[chat_title] model={title_model} session_id={session_id} "
|
|
3813
3823
|
f"ms={int((time.monotonic() - started) * 1000)}", flush=True)
|
|
3814
3824
|
else:
|
|
@@ -380,6 +380,11 @@ export const api = {
|
|
|
380
380
|
{ method: "POST" },
|
|
381
381
|
),
|
|
382
382
|
|
|
383
|
+
renameChatSession: (id: string, title: string) =>
|
|
384
|
+
request<{ ok?: boolean; detail?: string }>(`/chat/sessions/${encodeURIComponent(id)}/title`, {
|
|
385
|
+
method: "PUT", body: JSON.stringify({ title }),
|
|
386
|
+
}),
|
|
387
|
+
|
|
383
388
|
getChatSession: (id: string) =>
|
|
384
389
|
request<{ id: string; title: string; created_at: string; updated_at: string; last_message_at?: string | null; detail?: string }>(
|
|
385
390
|
`/chat/sessions/${encodeURIComponent(id)}`,
|
|
@@ -1624,6 +1624,7 @@ class Database:
|
|
|
1624
1624
|
mime_type TEXT NOT NULL,
|
|
1625
1625
|
size_bytes INTEGER NOT NULL,
|
|
1626
1626
|
file_path TEXT NOT NULL,
|
|
1627
|
+
data BLOB,
|
|
1627
1628
|
openai_file_id TEXT,
|
|
1628
1629
|
openai_file_expires_at INTEGER,
|
|
1629
1630
|
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
@@ -3779,6 +3780,14 @@ def _m042_record_notes(db: "Database") -> None:
|
|
|
3779
3780
|
db.conn.commit()
|
|
3780
3781
|
|
|
3781
3782
|
|
|
3783
|
+
def _m069_chat_attachment_data(db: "Database") -> None:
|
|
3784
|
+
db._add_column_if_missing("Chat Attachment", "data", "BLOB")
|
|
3785
|
+
|
|
3786
|
+
|
|
3787
|
+
def _m070_chat_manual_title(db: "Database") -> None:
|
|
3788
|
+
db.ensure_column("Chat Session", "title_is_manual", "INTEGER NOT NULL DEFAULT 0")
|
|
3789
|
+
|
|
3790
|
+
|
|
3782
3791
|
Database.MIGRATIONS = [
|
|
3783
3792
|
(1, "chat_message_session_id", _m001_chat_message_session_id),
|
|
3784
3793
|
(2, "chat_session_user_id", _m002_chat_session_user_id),
|
|
@@ -3848,6 +3857,8 @@ Database.MIGRATIONS = [
|
|
|
3848
3857
|
(66, "attachment_sensitivity", _m066_attachment_sensitivity),
|
|
3849
3858
|
(67, "item_units", _m067_item_units),
|
|
3850
3859
|
(68, "units_completed", _m068_units_completed),
|
|
3860
|
+
(69, "chat_attachment_data", _m069_chat_attachment_data),
|
|
3861
|
+
(70, "chat_manual_title", _m070_chat_manual_title),
|
|
3851
3862
|
]
|
|
3852
3863
|
|
|
3853
3864
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|