lambda-erp 1.4.25__tar.gz → 1.4.27__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.
Files changed (140) hide show
  1. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/PKG-INFO +4 -4
  2. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/README.md +3 -3
  3. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/attachments.py +41 -36
  4. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/chat.py +20 -14
  5. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/providers.py +18 -3
  6. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/database.py +6 -0
  7. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/pyproject.toml +1 -1
  8. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/.gitignore +0 -0
  9. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/LICENSE +0 -0
  10. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/__init__.py +0 -0
  11. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/auth.py +0 -0
  12. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/bootstrap.py +0 -0
  13. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/chat_links.py +0 -0
  14. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/demo_limits.py +0 -0
  15. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/deps.py +0 -0
  16. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/erp_context.py +0 -0
  17. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/errors.py +0 -0
  18. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/list_values.py +0 -0
  19. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/llm_provider.py +0 -0
  20. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/main.py +0 -0
  21. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/mcp_oauth.py +0 -0
  22. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/mentions.py +0 -0
  23. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/menu_layout.py +0 -0
  24. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/oauth.py +0 -0
  25. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf.py +0 -0
  26. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf_contract.py +0 -0
  27. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf_exports.py +0 -0
  28. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf_fonts.py +0 -0
  29. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf_pages.py +0 -0
  30. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf_profiles.py +0 -0
  31. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pdf_templates.py +0 -0
  32. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/pricing_actions.py +0 -0
  33. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/record_attachments.py +0 -0
  34. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/record_notes.py +0 -0
  35. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/remarks_md.py +0 -0
  36. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/__init__.py +0 -0
  37. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/accounting.py +0 -0
  38. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/actions.py +0 -0
  39. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/admin.py +0 -0
  40. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/analytics.py +0 -0
  41. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/availability.py +0 -0
  42. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/bank_reconciliation.py +0 -0
  43. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/bank_statements.py +0 -0
  44. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/chat_api.py +0 -0
  45. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/documents.py +0 -0
  46. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/masters.py +0 -0
  47. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/mcp.py +0 -0
  48. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/pdf_templates.py +0 -0
  49. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/proposals.py +0 -0
  50. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/reports.py +0 -0
  51. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/routers/setup.py +0 -0
  52. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/services.py +0 -0
  53. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/stock_actions.py +0 -0
  54. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/_proposal_totals.html +0 -0
  55. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/_record_base.html +0 -0
  56. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/delivery_note.html +0 -0
  57. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/document.html +0 -0
  58. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/proposal.html +0 -0
  59. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/record.html +0 -0
  60. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/templates/reservation.html +0 -0
  61. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/time_filters.py +0 -0
  62. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/tool_permissions.py +0 -0
  63. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/tool_results.py +0 -0
  64. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/api/write_context.py +0 -0
  65. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/docs/agents/README.md +0 -0
  66. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/frontend/LICENSE +0 -0
  67. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/frontend/README.md +0 -0
  68. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/frontend/src/api/client.ts +0 -0
  69. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/__init__.py +0 -0
  70. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/__init__.py +0 -0
  71. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_account.py +0 -0
  72. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_reconciliation.py +0 -0
  73. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_statement_import.py +0 -0
  74. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_transaction.py +0 -0
  75. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/budget.py +0 -0
  76. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/camt.py +0 -0
  77. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/chart_of_accounts.py +0 -0
  78. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/general_ledger.py +0 -0
  79. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/journal_entry.py +0 -0
  80. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/payment_entry.py +0 -0
  81. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/pos_invoice.py +0 -0
  82. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/purchase_invoice.py +0 -0
  83. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/revaluation.py +0 -0
  84. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/sales_invoice.py +0 -0
  85. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/settlement.py +0 -0
  86. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/__init__.py +0 -0
  87. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/engine.py +0 -0
  88. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/pack.py +0 -0
  89. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
  90. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/ch.py +0 -0
  91. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
  92. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
  93. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
  94. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/generic.py +0 -0
  95. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/profiles.py +0 -0
  96. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/spine.py +0 -0
  97. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/accounting/subscription.py +0 -0
  98. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/addresses.py +0 -0
  99. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/assets/__init__.py +0 -0
  100. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/assets/asset.py +0 -0
  101. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/assets/lifecycle.py +0 -0
  102. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/assets/reservation.py +0 -0
  103. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/backlog.py +0 -0
  104. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/bundles.py +0 -0
  105. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/buying/__init__.py +0 -0
  106. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/buying/purchase_order.py +0 -0
  107. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/__init__.py +0 -0
  108. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/currency.py +0 -0
  109. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/defaults.py +0 -0
  110. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/item_price.py +0 -0
  111. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/item_prices.py +0 -0
  112. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/price_resolution.py +0 -0
  113. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/pricing_rule.py +0 -0
  114. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/tax_defaults.py +0 -0
  115. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/controllers/taxes_and_totals.py +0 -0
  116. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/exceptions.py +0 -0
  117. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/hooks.py +0 -0
  118. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/master_integrity.py +0 -0
  119. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/model.py +0 -0
  120. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/permissions.py +0 -0
  121. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/selling/__init__.py +0 -0
  122. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/selling/proposal.py +0 -0
  123. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/selling/quotation.py +0 -0
  124. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/selling/sales_order.py +0 -0
  125. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/simulation.py +0 -0
  126. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/__init__.py +0 -0
  127. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/consignment.py +0 -0
  128. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/delivery_note.py +0 -0
  129. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/purchase_receipt.py +0 -0
  130. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/reservation.py +0 -0
  131. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/serial.py +0 -0
  132. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/stock_count.py +0 -0
  133. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/stock_entry.py +0 -0
  134. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/stock/stock_ledger.py +0 -0
  135. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/timestamps.py +0 -0
  136. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/units.py +0 -0
  137. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/utils.py +0 -0
  138. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/validation.py +0 -0
  139. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/lambda_erp/workflow.py +0 -0
  140. {lambda_erp-1.4.25 → lambda_erp-1.4.27}/terraform/README.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lambda-erp
3
- Version: 1.4.25
3
+ Version: 1.4.27
4
4
  Summary: Core ERP logic - accounting, sales, purchasing, inventory
5
5
  Author: TORUS INVESTMENTS AG
6
6
  License-Expression: Apache-2.0
@@ -265,8 +265,8 @@ Open `http://localhost:5173`. Vite proxies `/api/*` to the backend.
265
265
 
266
266
  ```
267
267
  OPENAI_API_KEY=sk-...
268
- LAMBDA_ERP_CHAT_MODEL=gpt-6.1-sol # optional chat override; default shown
269
- LAMBDA_ERP_REPORT_MODEL=gpt-6.1-sol # optional specialist override; default shown
268
+ LAMBDA_ERP_CHAT_MODEL=gpt-6.2-sol # optional chat override; default shown
269
+ LAMBDA_ERP_REPORT_MODEL=gpt-6.2-sol # optional specialist override; default shown
270
270
  LAMBDA_ERP_TITLE_MODEL=gpt-6-luna # optional chat-title override; default shown
271
271
  LAMBDA_ERP_ADMIN_EMAIL=admin@example.com # optional, seeds the admin at boot
272
272
  LAMBDA_ERP_ADMIN_PASSWORD=... # optional, required with the line above
@@ -274,7 +274,7 @@ LAMBDA_ERP_ADMIN_NAME=Administrator # optional, display name for the seed
274
274
  ```
275
275
 
276
276
  Chat, chat titles and custom-report specification generation share
277
- `OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.1 Sol,
277
+ `OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.2 Sol,
278
278
  titles to GPT-6 Luna; see [docs/llm-pricing.md](docs/llm-pricing.md) for prices.
279
279
 
280
280
  **Seeded admin.** By default the first person to register becomes the admin. Set `LAMBDA_ERP_ADMIN_EMAIL` + `LAMBDA_ERP_ADMIN_PASSWORD` to instead provision that admin automatically at startup — useful when the database is recreated on every deploy, so a redeployed instance can't be claimed by whoever visits first. It's create-if-missing and idempotent (an existing account with that email is promoted to an enabled admin; its password is left untouched), and the password is only ever read from the environment.
@@ -235,8 +235,8 @@ Open `http://localhost:5173`. Vite proxies `/api/*` to the backend.
235
235
 
236
236
  ```
237
237
  OPENAI_API_KEY=sk-...
238
- LAMBDA_ERP_CHAT_MODEL=gpt-6.1-sol # optional chat override; default shown
239
- LAMBDA_ERP_REPORT_MODEL=gpt-6.1-sol # optional specialist override; default shown
238
+ LAMBDA_ERP_CHAT_MODEL=gpt-6.2-sol # optional chat override; default shown
239
+ LAMBDA_ERP_REPORT_MODEL=gpt-6.2-sol # optional specialist override; default shown
240
240
  LAMBDA_ERP_TITLE_MODEL=gpt-6-luna # optional chat-title override; default shown
241
241
  LAMBDA_ERP_ADMIN_EMAIL=admin@example.com # optional, seeds the admin at boot
242
242
  LAMBDA_ERP_ADMIN_PASSWORD=... # optional, required with the line above
@@ -244,7 +244,7 @@ LAMBDA_ERP_ADMIN_NAME=Administrator # optional, display name for the seed
244
244
  ```
245
245
 
246
246
  Chat, chat titles and custom-report specification generation share
247
- `OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.1 Sol,
247
+ `OPENAI_API_KEY`. The chat and the report specialist default to GPT-6.2 Sol,
248
248
  titles to GPT-6 Luna; see [docs/llm-pricing.md](docs/llm-pricing.md) for prices.
249
249
 
250
250
  **Seeded admin.** By default the first person to register becomes the admin. Set `LAMBDA_ERP_ADMIN_EMAIL` + `LAMBDA_ERP_ADMIN_PASSWORD` to instead provision that admin automatically at startup — useful when the database is recreated on every deploy, so a redeployed instance can't be claimed by whoever visits first. It's create-if-missing and idempotent (an existing account with that email is promoted to an enabled admin; its password is left untouched), and the password is only ever read from the environment.
@@ -1,10 +1,9 @@
1
- """Chat attachment upload/download. Files stored on the local filesystem."""
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
- # Where uploaded files are stored. Must be a WRITABLE path — a package-relative
200
- # location (e.g. next to this module) resolves under site-packages when the
201
- # package is pip-installed in a container, which is read-only for the non-root
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
- upload_dir = _ensure_upload_dir(user_id)
301
- file_path = os.path.join(upload_dir, f"{att_id}.{ext}")
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
- with open(file_path, "wb") as f:
304
- f.write(data)
305
-
306
- db.sql(
307
- 'INSERT INTO "Chat Attachment" (id, session_id, user_id, filename, mime_type, size_bytes, file_path, created_at) '
308
- 'VALUES (?, ?, ?, ?, ?, ?, ?, ?)',
309
- [att_id, session_id, user_id, file.filename or f"file.{ext}", mime, len(data), file_path, now()],
310
- )
311
- db.conn.commit()
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
- if not os.path.isfile(row["file_path"]):
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
- try:
380
- with open(row["file_path"], "rb") as f:
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"])
@@ -162,14 +162,16 @@ def get_session(session_id: str) -> dict | None:
162
162
 
163
163
 
164
164
  def can_access_session(session: dict | None, user: dict | None) -> bool:
165
+ """Whether `user` may open, write into, rename or delete a chat: only
166
+ its owner, admins included. A chat holds whatever its owner typed; until
167
+ 1.4.26 an admin could open and write into anyone's chat by its address."""
165
168
  if not session or not user:
166
169
  return False
167
170
  stamp = get_db().sql('SELECT access_stamp FROM "Chat Session" WHERE id = ?', [session.get("id")])
168
171
  if not stamp or not _session_readable(dict(stamp[0]), user.get("restrictions")):
169
172
  return False
170
- if user.get("role") == "admin":
171
- return True
172
- return session.get("user_id") == user.get("name")
173
+ owner = session.get("user_id")
174
+ return bool(owner) and owner == user.get("name")
173
175
 
174
176
 
175
177
  # A session runs one agent turn at a time. The claim lives on the session row,
@@ -2245,6 +2247,9 @@ def _handle_retrieve_chat_attachment(args, session_id: str | None = None, user_i
2245
2247
  from api.attachments import get_attachments_by_ids, build_multimodal_content
2246
2248
  atts = get_attachments_by_ids([attachment_id], user_id)
2247
2249
  if not atts:
2250
+ if get_db().sql('SELECT id FROM "Chat Attachment" WHERE id = ? AND session_id = ? AND user_id = ?',
2251
+ [attachment_id, session_id, user_id]):
2252
+ return {"error": "The attachment is listed in this chat, but its stored file is missing."}
2248
2253
  return {"error": "Attachment not found or access denied."}
2249
2254
  att = atts[0]
2250
2255
  return {
@@ -3391,14 +3396,14 @@ Users can attach PDFs and images (receipts, bills, contracts, screenshots) to th
3391
3396
  # ---------------------------------------------------------------------------
3392
3397
  # OpenAI report-spec specialist
3393
3398
  #
3394
- # GPT-6.1 Sol acts as the planner/orchestrator. When it decides a report needs
3399
+ # GPT-6.2 Sol acts as the planner/orchestrator. When it decides a report needs
3395
3400
  # a custom analytics view it calls the create/update custom analytics tools.
3396
- # Those handlers make a separate, narrowly prompted GPT-6.1 Sol call for the bounded
3401
+ # Those handlers make a separate, narrowly prompted GPT-6.2 Sol call for the bounded
3397
3402
  # declarative report spec. Both roles use the same provider and key (api/llm_provider.py).
3398
3403
  # ---------------------------------------------------------------------------
3399
3404
 
3400
3405
 
3401
- REPORT_SPECIALIST_MODEL = "gpt-6.1-sol"
3406
+ REPORT_SPECIALIST_MODEL = "gpt-6.2-sol"
3402
3407
 
3403
3408
 
3404
3409
  def _report_specialist_model() -> str:
@@ -3825,11 +3830,12 @@ async def generate_title(
3825
3830
  # Reasoning loop
3826
3831
  # ---------------------------------------------------------------------------
3827
3832
 
3828
- # GPT-6.1 Sol requires Responses for function tools and does not support
3833
+ # GPT-6.2 Sol (default since core 1.4.26; GPT-6.1 Sol before) requires
3834
+ # Responses for function tools and does not support
3829
3835
  # reasoning effort "none", including tool-free wrap-ups after the step limit.
3830
3836
  # LAMBDA_ERP_CHAT_MODEL overrides it per deployment (e.g. to trial a cheaper
3831
3837
  # model on dev); see docs/llm-pricing.md.
3832
- ORCHESTRATOR_MODEL = "gpt-6.1-sol"
3838
+ ORCHESTRATOR_MODEL = "gpt-6.2-sol"
3833
3839
 
3834
3840
 
3835
3841
  def _chat_model() -> str:
@@ -3850,9 +3856,9 @@ def _chat_model() -> str:
3850
3856
  # ---------------------------------------------------------------------------
3851
3857
 
3852
3858
  def _use_responses_api() -> bool:
3853
- # A legacy deployment flag must not route a GPT-6.1 model into an
3859
+ # A legacy deployment flag must not route a GPT-6.1 / 6.2 model into an
3854
3860
  # unsupported API.
3855
- if _chat_model().startswith("gpt-6.1-"):
3861
+ if _chat_model().startswith(("gpt-6.1-", "gpt-6.2-")):
3856
3862
  return True
3857
3863
  # Default: the Responses API (needed for Office attachments + native
3858
3864
  # reasoning). Set ERP_CHAT_API=chat to fall back to Chat Completions.
@@ -4016,7 +4022,7 @@ def _shim_usage_from_responses(usage):
4016
4022
 
4017
4023
  def _orchestrator_turn(client, messages, tools, max_tokens, *, tool_choice="auto"):
4018
4024
  """One orchestrator LLM turn. Returns (message, usage) shaped like Chat
4019
- Completions. GPT-6.1 models always use Responses; others honor ERP_CHAT_API.
4025
+ Completions. GPT-6.1 and 6.2 models always use Responses; others honor ERP_CHAT_API.
4020
4026
  Blocking — call via asyncio.to_thread."""
4021
4027
  if _use_responses_api():
4022
4028
  instructions, input_items = _responses_request_from_chat(messages)
@@ -4069,11 +4075,11 @@ async def run_thinking_loop(
4069
4075
  ):
4070
4076
  """Run the agentic reasoning loop.
4071
4077
 
4072
- The orchestrator and the report specialist use GPT-6.1 Sol.
4078
+ The orchestrator and the report specialist use GPT-6.2 Sol.
4073
4079
  When GPT decides to call
4074
4080
  `create_custom_analytics_report` or `update_custom_analytics_report`
4075
4081
  with an intent/feedback hint, the tool handler itself delegates the
4076
- declarative-spec step to a separate narrowly prompted GPT-6.1 Sol call. We emit an
4082
+ declarative-spec step to a separate narrowly prompted GPT-6.2 Sol call. We emit an
4077
4083
  `llm_provider` event around that delegation so the UI can surface it.
4078
4084
  """
4079
4085
  if not llm_configured():
@@ -4288,7 +4294,7 @@ async def run_thinking_loop(
4288
4294
  principal_ref[0] = refresh_auth_principal(principal_ref[0])
4289
4295
  live_role = principal_ref[0].get("role") if principal_ref[0] else None
4290
4296
 
4291
- # If the orchestrator is delegating report-spec generation to GPT-6.1 Sol,
4297
+ # If the orchestrator is delegating report-spec generation to GPT-6.2 Sol,
4292
4298
  # surface the handoff in the UI.
4293
4299
  will_delegate_to_report_specialist = (
4294
4300
  tool_allowed(fn_name, live_role)
@@ -19,7 +19,22 @@ from typing import Any, Optional
19
19
  # ---------------------------------------------------------------------------
20
20
 
21
21
  OPENAI_PRICING: dict[str, dict[str, Any]] = {
22
- # The models available to us, Standard tier, verified 2026-10-30. Above
22
+ "gpt-6.2-astra": {
23
+ "tiered": True,
24
+ "tiers": [
25
+ {"max_input_tokens": 272_000, "input": 8.00, "cached_input": 0.40, "cache_write": 10.00, "cache_write_12h": 20.00, "output": 40.00},
26
+ {"max_input_tokens": None, "input": 16.00, "cached_input": 0.80, "cache_write": 20.00, "cache_write_12h": 40.00, "output": 60.00},
27
+ ],
28
+ },
29
+ "gpt-6.2-sol": {
30
+ "tiered": True,
31
+ "tiers": [
32
+ {"max_input_tokens": 272_000, "input": 2.00, "cached_input": 0.10, "cache_write": 2.50, "cache_write_12h": 5.00, "output": 10.00},
33
+ {"max_input_tokens": None, "input": 4.00, "cached_input": 0.20, "cache_write": 5.00, "cache_write_12h": 10.00, "output": 15.00},
34
+ ],
35
+ },
36
+ # The models available to us, Standard tier, verified 2026-10-30 (the
37
+ # GPT-6.2 models 2026-11-18, developers.openai.com/api/docs/pricing). Above
23
38
  # 272K input tokens the higher rates apply to the entire request
24
39
  # (including cache hits). cache_write is the 30-minute retention rate,
25
40
  # cache_write_12h the 12-hour one.
@@ -62,14 +77,14 @@ TRANSCRIBE_PRICING: dict[str, dict[str, float]] = {
62
77
 
63
78
 
64
79
  # ---------------------------------------------------------------------------
65
- # Rate lookup — unknown model IDs are estimated at the gpt-6.1-sol rates.
80
+ # Rate lookup — unknown model IDs are estimated at the gpt-6.2-sol rates.
66
81
  # Register a model explicitly before using it; this fallback is not a price cap.
67
82
  # ---------------------------------------------------------------------------
68
83
 
69
84
  def get_openai_rates(model: str, input_tokens: int = 0) -> dict[str, float]:
70
85
  entry = OPENAI_PRICING.get(model)
71
86
  if entry is None:
72
- entry = OPENAI_PRICING["gpt-6.1-sol"]
87
+ entry = OPENAI_PRICING["gpt-6.2-sol"]
73
88
  if entry.get("tiered"):
74
89
  for tier in entry["tiers"]:
75
90
  cap = tier.get("max_input_tokens")
@@ -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,10 @@ 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
+
3782
3787
  Database.MIGRATIONS = [
3783
3788
  (1, "chat_message_session_id", _m001_chat_message_session_id),
3784
3789
  (2, "chat_session_user_id", _m002_chat_session_user_id),
@@ -3848,6 +3853,7 @@ Database.MIGRATIONS = [
3848
3853
  (66, "attachment_sensitivity", _m066_attachment_sensitivity),
3849
3854
  (67, "item_units", _m067_item_units),
3850
3855
  (68, "units_completed", _m068_units_completed),
3856
+ (69, "chat_attachment_data", _m069_chat_attachment_data),
3851
3857
  ]
3852
3858
 
3853
3859
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lambda-erp"
3
- version = "1.4.25"
3
+ version = "1.4.27"
4
4
  description = "Core ERP logic - accounting, sales, purchasing, inventory"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
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