lambda-erp 1.4.24__tar.gz → 1.4.25__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.24 → lambda_erp-1.4.25}/PKG-INFO +1 -1
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/chat.py +174 -14
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/masters.py +35 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/mcp.py +2 -1
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/tool_permissions.py +1 -1
- lambda_erp-1.4.25/api/tool_results.py +110 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/pyproject.toml +1 -1
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/.gitignore +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/LICENSE +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/README.md +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/attachments.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/auth.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/chat_links.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/deps.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/erp_context.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/errors.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/list_values.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/main.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/mentions.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/oauth.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/providers.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/record_notes.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/services.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/document.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/record.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/time_filters.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/api/write_context.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/frontend/README.md +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/database.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/units.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.24 → lambda_erp-1.4.25}/terraform/README.md +0 -0
|
@@ -641,12 +641,14 @@ TOOLS = [
|
|
|
641
641
|
"type": "function",
|
|
642
642
|
"function": {
|
|
643
643
|
"name": "get_document",
|
|
644
|
-
"description": "Load a specific document by its name/ID. Returns the
|
|
644
|
+
"description": "Load a specific document by its name/ID. Returns the document with all fields and its line tables. A table with more than `limit` lines (default 200) comes as a window of it; `_lines` then gives the total per table and has_more, and `offset` reads on.",
|
|
645
645
|
"parameters": {
|
|
646
646
|
"type": "object",
|
|
647
647
|
"properties": {
|
|
648
648
|
"doctype": {"type": "string", "enum": DOCUMENT_SLUGS},
|
|
649
649
|
"name": {"type": "string", "description": "Document name/ID, e.g. 'QTN-0001'"},
|
|
650
|
+
"limit": {"type": "integer", "description": "Maximum lines per line table, default 200, range 1–2000."},
|
|
651
|
+
"offset": {"type": "integer", "description": "Skip this many lines of each line table.", "default": 0},
|
|
650
652
|
},
|
|
651
653
|
"required": ["doctype", "name"],
|
|
652
654
|
},
|
|
@@ -786,7 +788,7 @@ TOOLS = [
|
|
|
786
788
|
"type": "function",
|
|
787
789
|
"function": {
|
|
788
790
|
"name": "search_masters",
|
|
789
|
-
"description": "Search and filter master data (customers, suppliers, items, warehouses, accounts, companies, cost centers). `query` is a case-insensitive free-text lookup with fuzzy fallback for simple misspellings. Use `filters` for deterministic field-aware queries and for combining different values across fields. With time_filter or include_meta=true returns a page object with rows, total, pagination and coverage (default limit 50, max 500; no fuzzy fallback).
|
|
791
|
+
"description": "Search and filter master data (customers, suppliers, items, warehouses, accounts, companies, cost centers). `query` is a case-insensitive free-text lookup with fuzzy fallback for simple misspellings. Use `filters` for deterministic field-aware queries and for combining different values across fields. With time_filter or include_meta=true returns a page object with rows, total, pagination and coverage (default limit 50, max 500; no fuzzy fallback). A simple lookup returns an array of full records when up to 50 match, or when you set `limit` yourself (at most 500). Without a limit, when more than 50 match it returns a page instead: {rows, total, returned, offset, has_more, note} with the first 50 records and only their identifying columns; then narrow the search (a more specific query, or filters such as {\"root_type\": \"Expense\"}, {\"account_type\": \"Bank\"}, {\"is_group\": 0} for accounts, {\"item_group\": ...} for items), page with offset, or name the columns you need in result_fields.",
|
|
790
792
|
"parameters": {
|
|
791
793
|
"type": "object",
|
|
792
794
|
"properties": {
|
|
@@ -806,7 +808,7 @@ TOOLS = [
|
|
|
806
808
|
},
|
|
807
809
|
"order_by": {"type": "string", "description": "Optional real column or registered alias (item_code = name) to sort by. Defaults to the time_filter field when supplied, otherwise name."},
|
|
808
810
|
"order": {"type": "string", "enum": ["asc", "desc"], "description": "Sort direction (default asc).", "default": "asc"},
|
|
809
|
-
"limit": {"type": "integer", "description": "Maximum results
|
|
811
|
+
"limit": {"type": "integer", "description": "Maximum results, range 1–500. Set it and a simple lookup returns a plain array of that many full records; leave it out to get the first 50 with the total and has_more when there are more."},
|
|
810
812
|
"offset": {"type": "integer", "description": "Skip this many matching rows. Use with limit for pagination.", "default": 0},
|
|
811
813
|
"result_fields": {
|
|
812
814
|
"type": "array",
|
|
@@ -833,6 +835,36 @@ TOOLS = [
|
|
|
833
835
|
},
|
|
834
836
|
},
|
|
835
837
|
},
|
|
838
|
+
{
|
|
839
|
+
"type": "function",
|
|
840
|
+
"function": {
|
|
841
|
+
"name": "batch_create_masters",
|
|
842
|
+
"description": (
|
|
843
|
+
"Create MANY master records of the SAME type in ONE call: a chart of accounts, a customer "
|
|
844
|
+
"list, an item list. Use this instead of one create_master per record whenever there are more "
|
|
845
|
+
"than a handful; a whole chart of accounts is one or two calls. `records` is an array of "
|
|
846
|
+
"`data` objects, each exactly as create_master takes it (see create_master and "
|
|
847
|
+
"get_master_fields for the fields). Max 200 per call. Records are created one by one in the "
|
|
848
|
+
"order given: list a parent (group account, parent warehouse) before its children. "
|
|
849
|
+
"Best-effort and per record: one that is refused (already exists, missing field, unknown "
|
|
850
|
+
"parent) does not undo the others. Returns {\"created\", \"failed\", \"results\": "
|
|
851
|
+
"[{\"index\", \"ok\", \"name\", \"error\"?}]}; report the failed ones with their reason and "
|
|
852
|
+
"do not blindly resend records that were created."
|
|
853
|
+
),
|
|
854
|
+
"parameters": {
|
|
855
|
+
"type": "object",
|
|
856
|
+
"properties": {
|
|
857
|
+
"master_type": {"type": "string", "enum": MASTER_TYPES},
|
|
858
|
+
"records": {
|
|
859
|
+
"type": "array",
|
|
860
|
+
"description": "Up to 200 data objects, one per record to create (same shape as create_master's data).",
|
|
861
|
+
"items": {"type": "object"},
|
|
862
|
+
},
|
|
863
|
+
},
|
|
864
|
+
"required": ["master_type", "records"],
|
|
865
|
+
},
|
|
866
|
+
},
|
|
867
|
+
},
|
|
836
868
|
{
|
|
837
869
|
"type": "function",
|
|
838
870
|
"function": {
|
|
@@ -908,10 +940,12 @@ TOOLS = [
|
|
|
908
940
|
"type": "function",
|
|
909
941
|
"function": {
|
|
910
942
|
"name": "get_report",
|
|
911
|
-
"description": "Run a financial or stock report.",
|
|
943
|
+
"description": "Run a financial or stock report. A report with a list of rows returns at most `limit` rows (default 200) plus total_rows and has_more; prefer the report's filters over paging through everything.",
|
|
912
944
|
"parameters": {
|
|
913
945
|
"type": "object",
|
|
914
946
|
"properties": {
|
|
947
|
+
"limit": {"type": "integer", "description": "Maximum rows of a list report, default 200, range 1–2000. The general ledger uses filters.limit / filters.offset instead."},
|
|
948
|
+
"offset": {"type": "integer", "description": "Skip this many rows.", "default": 0},
|
|
915
949
|
"report_type": {"type": "string", "enum": ["trial-balance", "general-ledger", "stock-balance", "stock-availability", "stock-detail", "batch-stock", "batch-movements", "batch-recipients", "batch-changes", "serial-trace", "sales-backlog", "purchase-backlog", "dashboard-summary", "profit-and-loss", "balance-sheet", "ar-aging", "ap-aging"]},
|
|
916
950
|
"filters": {"type": "object", "description": "Optional filters: company, account, from_date, to_date, item_code, warehouse; for batch-stock also batch_no, item_prefix, expiring_before, include_empty; for stock-detail also location, batch_no, item_prefix, item_group, expiring_before, expiring_after, include_empty; batch-movements requires batch_no. For trial-balance / profit-and-loss / balance-sheet you may also pass `presentation_currency` (e.g. \"EUR\") to view the report translated from the company's base currency at the period's closing rate — display only, the ledger stays in base currency.", "default": {}},
|
|
917
951
|
},
|
|
@@ -1663,7 +1697,26 @@ def _handle_get_document_fields(args):
|
|
|
1663
1697
|
|
|
1664
1698
|
@with_record_view_urls("doctype")
|
|
1665
1699
|
def _handle_get_document(args):
|
|
1666
|
-
|
|
1700
|
+
"""One document. A line table longer than `limit` (default 200) is
|
|
1701
|
+
returned as a window of it, with `_lines` saying how many there are: a
|
|
1702
|
+
stock count or a bank statement can have thousands of lines."""
|
|
1703
|
+
from api import tool_results
|
|
1704
|
+
limit, offset, problem = tool_results.page_window(args)
|
|
1705
|
+
if problem:
|
|
1706
|
+
return {"error": problem}
|
|
1707
|
+
doc = services.load_document(args["doctype"], args["name"])
|
|
1708
|
+
if not isinstance(doc, dict):
|
|
1709
|
+
return doc
|
|
1710
|
+
windows = {}
|
|
1711
|
+
for key, value in list(doc.items()):
|
|
1712
|
+
if isinstance(value, list) and (len(value) > limit or (offset and value)):
|
|
1713
|
+
doc[key] = value[offset:offset + limit]
|
|
1714
|
+
windows[key] = {"total": len(value), "offset": offset, "returned": len(doc[key]),
|
|
1715
|
+
"has_more": offset + len(doc[key]) < len(value)}
|
|
1716
|
+
if windows:
|
|
1717
|
+
doc["_lines"] = {**windows, "note": "Not all lines are included. Read on with offset (and limit, up to "
|
|
1718
|
+
f"{tool_results.MAX_ROWS}); totals on the document cover all lines."}
|
|
1719
|
+
return doc
|
|
1667
1720
|
|
|
1668
1721
|
|
|
1669
1722
|
@with_record_view_urls("doctype")
|
|
@@ -1786,6 +1839,44 @@ def _handle_get_master_fields(args):
|
|
|
1786
1839
|
}
|
|
1787
1840
|
|
|
1788
1841
|
|
|
1842
|
+
def _compact_master_columns(db, doctype):
|
|
1843
|
+
"""What identifies a master record in a list: its id, the columns a
|
|
1844
|
+
free-text search looks at, and a few that tell records apart."""
|
|
1845
|
+
columns = db._get_table_columns(doctype)
|
|
1846
|
+
wanted = ["name", *_master_search_columns(db, doctype),
|
|
1847
|
+
"root_type", "account_type", "is_group", "parent_account", "company",
|
|
1848
|
+
"item_group", "stock_uom", "city", "zip_code", "country", "customer", "disabled"]
|
|
1849
|
+
return [column for column in dict.fromkeys(wanted) if column in columns][:9]
|
|
1850
|
+
|
|
1851
|
+
|
|
1852
|
+
def _master_page(master_type, doctype, args, rows, limit, offset, result_fields, search_cols):
|
|
1853
|
+
"""More records match than one answer holds: a page instead of the whole
|
|
1854
|
+
list, with compact rows unless the caller chose the columns."""
|
|
1855
|
+
db = get_db()
|
|
1856
|
+
counted = services.list_master_records(
|
|
1857
|
+
master_type, filters=args.get("filters") or {}, search=(args.get("query") or "").strip() or None,
|
|
1858
|
+
search_fields=search_cols, include_disabled=bool(args.get("include_disabled")), limit=1, offset=0,
|
|
1859
|
+
fields=["name"], with_total=True)
|
|
1860
|
+
total = counted.get("total", len(rows))
|
|
1861
|
+
if total <= len(rows) and not offset:
|
|
1862
|
+
return rows
|
|
1863
|
+
compact = not result_fields
|
|
1864
|
+
if compact:
|
|
1865
|
+
keep = _compact_master_columns(db, doctype)
|
|
1866
|
+
rows = [{column: row.get(column) for column in keep if column in row} for row in rows]
|
|
1867
|
+
more = offset + len(rows) < total
|
|
1868
|
+
return {
|
|
1869
|
+
"rows": rows, "total": total, "returned": len(rows), "offset": offset, "has_more": more,
|
|
1870
|
+
"note": (f"{total} {master_type} records match; {len(rows)} are shown"
|
|
1871
|
+
+ (" with their identifying columns only" if compact else "") + ". "
|
|
1872
|
+
+ ("Narrow the search with a more specific query or with filters "
|
|
1873
|
+
"(see get_master_fields for the columns), or read on with offset="
|
|
1874
|
+
f"{offset + len(rows)}. " if more else "")
|
|
1875
|
+
+ ("For other columns pass result_fields, or read one record by its name."
|
|
1876
|
+
if compact else "")),
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
|
|
1789
1880
|
@with_record_view_urls("master_type", master=True)
|
|
1790
1881
|
def _handle_search_masters(args):
|
|
1791
1882
|
db = get_db()
|
|
@@ -1793,16 +1884,18 @@ def _handle_search_masters(args):
|
|
|
1793
1884
|
master_type = args["master_type"]
|
|
1794
1885
|
query = (args.get("query") or "").strip()
|
|
1795
1886
|
|
|
1796
|
-
#
|
|
1797
|
-
#
|
|
1798
|
-
#
|
|
1887
|
+
# A simple lookup returns at most DEFAULT_PAGE rows unless the caller sets
|
|
1888
|
+
# `limit` (up to MAX_PAGE). Until 1.4.25 it returned every match with every
|
|
1889
|
+
# column: 5000 customers were 2.9 million characters. Coerced to int so the
|
|
1890
|
+
# LIMIT clause below can't be injected.
|
|
1891
|
+
from api import tool_results
|
|
1799
1892
|
_raw_limit = args.get("limit")
|
|
1800
|
-
limit =
|
|
1893
|
+
limit = tool_results.DEFAULT_PAGE
|
|
1801
1894
|
if _raw_limit not in (None, "", 0):
|
|
1802
1895
|
try:
|
|
1803
|
-
limit = max(1, int(_raw_limit))
|
|
1896
|
+
limit = min(tool_results.MAX_PAGE, max(1, int(_raw_limit)))
|
|
1804
1897
|
except (TypeError, ValueError):
|
|
1805
|
-
limit =
|
|
1898
|
+
limit = tool_results.DEFAULT_PAGE
|
|
1806
1899
|
if meta:
|
|
1807
1900
|
limit = args.get("limit", 50)
|
|
1808
1901
|
offset = args.get("offset", 0)
|
|
@@ -1873,7 +1966,12 @@ def _handle_search_masters(args):
|
|
|
1873
1966
|
if meta:
|
|
1874
1967
|
return result
|
|
1875
1968
|
if rows or not query:
|
|
1876
|
-
|
|
1969
|
+
# A caller that set `limit` itself gets its array, as always (now at
|
|
1970
|
+
# most MAX_PAGE rows). So does a search that returned everything.
|
|
1971
|
+
if _raw_limit not in (None, "", 0) or (len(rows) < limit and not offset):
|
|
1972
|
+
return rows
|
|
1973
|
+
return _master_page(master_type, doctype, args, rows, limit, offset, result_fields,
|
|
1974
|
+
search_cols if query else None)
|
|
1877
1975
|
|
|
1878
1976
|
# Preserve the established fuzzy fallback for a simple lookup. A
|
|
1879
1977
|
# deterministic field-filter query must return exactly its literal result;
|
|
@@ -1902,6 +2000,15 @@ def _handle_create_master(args):
|
|
|
1902
2000
|
return result
|
|
1903
2001
|
|
|
1904
2002
|
|
|
2003
|
+
@with_record_view_urls("master_type", master=True)
|
|
2004
|
+
def _handle_batch_create_masters(args):
|
|
2005
|
+
from api.routers.masters import batch_create_master_records
|
|
2006
|
+
try:
|
|
2007
|
+
return batch_create_master_records(args.get("master_type"), args.get("records"))
|
|
2008
|
+
except Exception as exc: # unknown type, empty or oversized batch
|
|
2009
|
+
return {"error": str(getattr(exc, "detail", None) or exc)}
|
|
2010
|
+
|
|
2011
|
+
|
|
1905
2012
|
@with_record_view_urls("master_type", master=True)
|
|
1906
2013
|
def _handle_update_master(args):
|
|
1907
2014
|
master_type = args["master_type"]
|
|
@@ -2000,6 +2107,30 @@ def _handle_retrieve_chat_history(args, session_id=None):
|
|
|
2000
2107
|
|
|
2001
2108
|
|
|
2002
2109
|
def _handle_get_report(args):
|
|
2110
|
+
"""A report. Its list of rows is returned as a window (default 200 rows)
|
|
2111
|
+
with the total, so a stock report over thousands of items stays readable.
|
|
2112
|
+
Totals and summaries of a report always cover all rows. The general
|
|
2113
|
+
ledger pages itself through its own filters."""
|
|
2114
|
+
from api import tool_results
|
|
2115
|
+
result = _run_report(args)
|
|
2116
|
+
if args.get("report_type") == "general-ledger" or not isinstance(result, dict):
|
|
2117
|
+
return result
|
|
2118
|
+
rows = result.get("rows")
|
|
2119
|
+
if not isinstance(rows, list):
|
|
2120
|
+
return result
|
|
2121
|
+
limit, offset, problem = tool_results.page_window(args)
|
|
2122
|
+
if problem:
|
|
2123
|
+
return {"error": problem}
|
|
2124
|
+
if len(rows) <= limit and not offset:
|
|
2125
|
+
return result
|
|
2126
|
+
window = rows[offset:offset + limit]
|
|
2127
|
+
return {**result, "rows": window, "total_rows": len(rows), "offset": offset, "returned": len(window),
|
|
2128
|
+
"has_more": offset + len(window) < len(rows),
|
|
2129
|
+
"note": (f"{len(rows)} rows in all; {len(window)} are included. Narrow the report with its filters "
|
|
2130
|
+
f"(item_code, item_prefix, warehouse, customer, ...) or read on with offset={offset + len(window)}.")}
|
|
2131
|
+
|
|
2132
|
+
|
|
2133
|
+
def _run_report(args):
|
|
2003
2134
|
report_type = args["report_type"]
|
|
2004
2135
|
filters = args.get("filters", {})
|
|
2005
2136
|
db = get_db()
|
|
@@ -2392,7 +2523,8 @@ def _handle_query_dataset(args):
|
|
|
2392
2523
|
measures=measures,
|
|
2393
2524
|
filters=args.get("filters"),
|
|
2394
2525
|
order_by=args.get("order_by") or [],
|
|
2395
|
-
|
|
2526
|
+
# An assistant reads groups, not a table export: 200 unless it asks.
|
|
2527
|
+
limit=args.get("limit") or 200,
|
|
2396
2528
|
)
|
|
2397
2529
|
except HTTPException as e:
|
|
2398
2530
|
return {"error": str(e.detail)}
|
|
@@ -2539,6 +2671,7 @@ TOOL_HANDLERS = {
|
|
|
2539
2671
|
"get_master_fields": _handle_get_master_fields,
|
|
2540
2672
|
"search_masters": _handle_search_masters,
|
|
2541
2673
|
"create_master": _handle_create_master,
|
|
2674
|
+
"batch_create_masters": _handle_batch_create_masters,
|
|
2542
2675
|
"update_master": _handle_update_master,
|
|
2543
2676
|
"get_report": _handle_get_report,
|
|
2544
2677
|
"revalue_currencies": _handle_revalue_currencies,
|
|
@@ -3060,6 +3193,10 @@ For a complete sales return (financial + stock): create and submit both a Credit
|
|
|
3060
3193
|
- On quotations, sales orders, delivery notes and sales / POS invoices, put the bundle's item_code and qty on a line and save: the line is replaced by one line per item of the bundle, which are then ordinary lines. Do not give a bundle line a rate, discount or batch; do not expand a bundle by hand.
|
|
3061
3194
|
- When the user names a set, look for it with list_documents doctype="item-bundle" (or the item) before listing single items yourself.
|
|
3062
3195
|
|
|
3196
|
+
### Entering many records
|
|
3197
|
+
- To enter a list of master records (a chart of accounts, customers, items from a file or a pasted table) use batch_create_masters with up to 200 records per call, not one create_master each. Give parents before their children. Afterwards report how many were created and name each one that was refused with its reason; never resend a list blindly, because the records that were created would be refused as duplicates.
|
|
3198
|
+
- A search that says more records match than it shows (`has_more`) has not shown you everything: narrow it with filters or read on with offset before concluding that something does not exist.
|
|
3199
|
+
|
|
3063
3200
|
### Units of measure (ordering in a pack, stocking in pieces)
|
|
3064
3201
|
- An item is stocked in its `stock_uom`. An **Item Unit** (doctype `item-unit`: item_code, uom, conversion_factor = stock units per unit, e.g. Karton = 100) gives it a further unit. List an item's units with list_documents doctype="item-unit" filtered by item_code.
|
|
3065
3202
|
- To enter a line in such a unit, send `qty` and `rate` in that unit and name it in `uom` (qty 2, uom "Karton", rate 290). On save the line is stored per stock unit (qty 200, rate 2.90) and keeps `order_uom`, `conversion_factor` and `order_qty` (2). Amounts are unchanged: 2 x 290 = 200 x 2.90.
|
|
@@ -3906,11 +4043,27 @@ def _orchestrator_turn(client, messages, tools, max_tokens, *, tool_choice="auto
|
|
|
3906
4043
|
return resp.choices[0].message, getattr(resp, "usage", None)
|
|
3907
4044
|
|
|
3908
4045
|
|
|
4046
|
+
DEMO_MAX_STEPS = 12
|
|
4047
|
+
|
|
4048
|
+
|
|
4049
|
+
def chat_max_steps() -> int:
|
|
4050
|
+
"""How many steps (a model call with the tool calls it asks for) one
|
|
4051
|
+
message may take before the assistant must stop and report. 30 since
|
|
4052
|
+
1.4.25 (12 before): entering a chart of accounts or working through a
|
|
4053
|
+
list ran out of steps mid-task. LAMBDA_ERP_CHAT_MAX_STEPS sets it (1-100).
|
|
4054
|
+
Demo visitors keep 12, whatever is configured."""
|
|
4055
|
+
try:
|
|
4056
|
+
steps = int(os.environ.get("LAMBDA_ERP_CHAT_MAX_STEPS") or 30)
|
|
4057
|
+
except ValueError:
|
|
4058
|
+
steps = 30
|
|
4059
|
+
return max(1, min(100, steps))
|
|
4060
|
+
|
|
4061
|
+
|
|
3909
4062
|
async def run_thinking_loop(
|
|
3910
4063
|
messages: list[dict],
|
|
3911
4064
|
on_event,
|
|
3912
4065
|
session_id: str = None,
|
|
3913
|
-
max_iterations: int =
|
|
4066
|
+
max_iterations: int | None = None,
|
|
3914
4067
|
user_info: dict | None = None,
|
|
3915
4068
|
client_ip: str | None = None,
|
|
3916
4069
|
):
|
|
@@ -3953,9 +4106,13 @@ async def run_thinking_loop(
|
|
|
3953
4106
|
# cost per turn; logged-in managers/admins keep the original cap.
|
|
3954
4107
|
max_completion = demo_max_completion_tokens() if demo_mode else 4096
|
|
3955
4108
|
|
|
4109
|
+
if max_iterations is None:
|
|
4110
|
+
max_iterations = DEMO_MAX_STEPS if demo_mode else chat_max_steps()
|
|
4111
|
+
|
|
3956
4112
|
if demo_mode:
|
|
3957
4113
|
denied = lambda _args: {"error": "Demo mode cannot create, update, or delete master data."}
|
|
3958
4114
|
tool_handlers["create_master"] = denied
|
|
4115
|
+
tool_handlers["batch_create_masters"] = denied
|
|
3959
4116
|
tool_handlers["update_master"] = denied
|
|
3960
4117
|
tool_handlers["delete_master"] = denied
|
|
3961
4118
|
|
|
@@ -4176,6 +4333,9 @@ async def run_thinking_loop(
|
|
|
4176
4333
|
multimodal_block = result.pop("_multimodal_content", None)
|
|
4177
4334
|
page_images = result.pop("_images", None)
|
|
4178
4335
|
|
|
4336
|
+
# No tool result reaches the model larger than a model can read.
|
|
4337
|
+
from api.tool_results import bound_tool_result
|
|
4338
|
+
result = bound_tool_result(fn_name, result)
|
|
4179
4339
|
result_str = json.dumps(result, default=str)
|
|
4180
4340
|
summary = result_str[:500] + "..." if len(result_str) > 500 else result_str
|
|
4181
4341
|
|
|
@@ -429,6 +429,41 @@ def create_master_record(master_type: str, data: dict) -> dict:
|
|
|
429
429
|
return _create_master_record(master_type, data)
|
|
430
430
|
|
|
431
431
|
|
|
432
|
+
BATCH_CREATE_MAX = 200
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
def batch_create_master_records(master_type: str, records: list) -> dict:
|
|
436
|
+
"""Create many master records of ONE type in a single call: a chart of
|
|
437
|
+
accounts, a customer list, an item list.
|
|
438
|
+
|
|
439
|
+
Each record is created on its own, in the order given, exactly as
|
|
440
|
+
create_master_record would (same checks, same hooks), so a record that
|
|
441
|
+
is refused does not undo the others, and a parent listed before its
|
|
442
|
+
children exists when they are created. Returns ``{"created", "failed",
|
|
443
|
+
"results": [{"index", "ok", "name"?, "error"?}]}``.
|
|
444
|
+
"""
|
|
445
|
+
if _get_table(master_type)[0] is None: # before anything is written
|
|
446
|
+
raise ValueError(f"Unknown master type: {master_type}")
|
|
447
|
+
if not isinstance(records, list) or not records:
|
|
448
|
+
raise ValueError("records must be a non-empty array of data objects")
|
|
449
|
+
if len(records) > BATCH_CREATE_MAX:
|
|
450
|
+
raise ValueError(f"Too many records ({len(records)}); max {BATCH_CREATE_MAX} per call")
|
|
451
|
+
results, created = [], 0
|
|
452
|
+
for index, data in enumerate(records):
|
|
453
|
+
if not isinstance(data, dict) or not data:
|
|
454
|
+
results.append({"index": index, "ok": False, "error": "not a data object"})
|
|
455
|
+
continue
|
|
456
|
+
try:
|
|
457
|
+
record = dict(create_master_record(master_type, data))
|
|
458
|
+
results.append({"index": index, "ok": True, "name": record.get("name")})
|
|
459
|
+
created += 1
|
|
460
|
+
except Exception as exc: # noqa: BLE001 — per record; report, don't abort
|
|
461
|
+
detail = getattr(exc, "detail", None)
|
|
462
|
+
results.append({"index": index, "ok": False, "name": data.get("name"),
|
|
463
|
+
"error": str(detail or exc)})
|
|
464
|
+
return {"created": created, "failed": len(results) - created, "results": results}
|
|
465
|
+
|
|
466
|
+
|
|
432
467
|
def _create_master_record(master_type: str, data: dict) -> dict:
|
|
433
468
|
doctype, _ = _get_table(master_type)
|
|
434
469
|
if not doctype:
|
|
@@ -186,7 +186,8 @@ def _handle(msg: dict, user: dict):
|
|
|
186
186
|
params = msg.get("params") or {}
|
|
187
187
|
name = params.get("name")
|
|
188
188
|
try:
|
|
189
|
-
|
|
189
|
+
from api.tool_results import bound_tool_result
|
|
190
|
+
out = bound_tool_result(name, _call(name, params.get("arguments") or {}, user))
|
|
190
191
|
except KeyError:
|
|
191
192
|
return _rpc_error(mid, -32602, f"Unknown tool: {name}")
|
|
192
193
|
except Exception as e: # noqa: BLE001 — surface as an MCP tool error, not a 500
|
|
@@ -29,7 +29,7 @@ TOOL_ROLES = {
|
|
|
29
29
|
"submit_document", "cancel_document", "discard_document", "convert_document",
|
|
30
30
|
), _DOCUMENT_WRITERS),
|
|
31
31
|
**dict.fromkeys((
|
|
32
|
-
"create_master", "update_master", "revalue_currencies",
|
|
32
|
+
"create_master", "batch_create_masters", "update_master", "revalue_currencies",
|
|
33
33
|
"import_bank_statement_attachments", "list_bank_reconciliation_queue",
|
|
34
34
|
"suggest_bank_reconciliation", "reconcile_bank_transaction",
|
|
35
35
|
"undo_bank_reconciliation",
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Keep what a tool hands to an assistant within a size a model can read.
|
|
2
|
+
|
|
3
|
+
The built-in chat and the assistants connected through MCP receive a tool's
|
|
4
|
+
result as JSON text. A result of megabytes (every customer with every
|
|
5
|
+
column) does not fit a model's context at all, and a result of a few hundred
|
|
6
|
+
kilobytes crowds out the conversation. Each list tool pages its own rows;
|
|
7
|
+
this module is the net below them: whatever a tool returns is brought under
|
|
8
|
+
`max_chars()` before it is serialised, and says that it was cut and how to
|
|
9
|
+
get the rest.
|
|
10
|
+
"""
|
|
11
|
+
import json
|
|
12
|
+
import os
|
|
13
|
+
|
|
14
|
+
DEFAULT_MAX_CHARS = 100_000
|
|
15
|
+
# Rows of a master search returned when the caller names no limit.
|
|
16
|
+
DEFAULT_PAGE = 50
|
|
17
|
+
MAX_PAGE = 500
|
|
18
|
+
# Lines of one child table of a document, and rows of a list report.
|
|
19
|
+
DEFAULT_ROWS = 200
|
|
20
|
+
MAX_ROWS = 2000
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# Keys a handler uses to hand pictures or file content to the model.
|
|
24
|
+
PASSED_THROUGH = ("_images", "_multimodal_content")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def max_chars() -> int:
|
|
28
|
+
"""Largest JSON text of one tool result, in characters (about four per
|
|
29
|
+
token). LAMBDA_ERP_TOOL_RESULT_MAX_CHARS overrides the default of 100000."""
|
|
30
|
+
try:
|
|
31
|
+
value = int(os.environ.get("LAMBDA_ERP_TOOL_RESULT_MAX_CHARS") or DEFAULT_MAX_CHARS)
|
|
32
|
+
except ValueError:
|
|
33
|
+
value = DEFAULT_MAX_CHARS
|
|
34
|
+
return max(2_000, value)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _size(value) -> int:
|
|
38
|
+
return len(json.dumps(value, default=str))
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _fit(rows, budget):
|
|
42
|
+
"""The longest prefix of `rows` whose JSON stays within `budget` characters."""
|
|
43
|
+
low, high = 0, len(rows)
|
|
44
|
+
while low < high:
|
|
45
|
+
middle = (low + high + 1) // 2
|
|
46
|
+
if _size(rows[:middle]) <= budget:
|
|
47
|
+
low = middle
|
|
48
|
+
else:
|
|
49
|
+
high = middle - 1
|
|
50
|
+
return low
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def page_window(args, default=DEFAULT_ROWS, maximum=MAX_ROWS):
|
|
54
|
+
"""(limit, offset) from a tool's arguments, or an error message."""
|
|
55
|
+
limit, offset = args.get("limit", default), args.get("offset", 0)
|
|
56
|
+
if limit in (None, ""):
|
|
57
|
+
limit = default
|
|
58
|
+
if offset in (None, ""):
|
|
59
|
+
offset = 0
|
|
60
|
+
if isinstance(limit, bool) or not isinstance(limit, int) or not 1 <= limit <= maximum:
|
|
61
|
+
return None, None, f"limit must be an integer between 1 and {maximum}"
|
|
62
|
+
if isinstance(offset, bool) or not isinstance(offset, int) or offset < 0:
|
|
63
|
+
return None, None, "offset must be a non-negative integer"
|
|
64
|
+
return limit, offset, None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def bound_tool_result(tool, result, limit=None):
|
|
68
|
+
"""`result` as it may be handed to a model: unchanged when it fits, else
|
|
69
|
+
with its largest list cut to what fits and a note saying so. A result
|
|
70
|
+
that is too large without any list to cut becomes an error that names
|
|
71
|
+
its size."""
|
|
72
|
+
budget = limit or max_chars()
|
|
73
|
+
if isinstance(result, dict) and any(key in result for key in PASSED_THROUGH):
|
|
74
|
+
# Images and file content shown to the model take another route and
|
|
75
|
+
# are not part of the JSON text.
|
|
76
|
+
aside = {key: result[key] for key in PASSED_THROUGH if key in result}
|
|
77
|
+
rest = bound_tool_result(tool, {k: v for k, v in result.items() if k not in aside}, limit)
|
|
78
|
+
return {**rest, **aside} if isinstance(rest, dict) else rest
|
|
79
|
+
try:
|
|
80
|
+
size = _size(result)
|
|
81
|
+
except (TypeError, ValueError):
|
|
82
|
+
return result
|
|
83
|
+
if size <= budget:
|
|
84
|
+
return result
|
|
85
|
+
|
|
86
|
+
note = ("The result was cut to fit ({total} {what} in all, the first {kept} are included; the full result was "
|
|
87
|
+
"{size} characters, the limit is {budget}). Narrow the request with filters or a more specific query, "
|
|
88
|
+
"ask for fewer columns where the tool has result_fields, or page with limit and offset.")
|
|
89
|
+
|
|
90
|
+
if isinstance(result, list):
|
|
91
|
+
kept = _fit(result, budget - 600)
|
|
92
|
+
return {"rows": result[:kept], "returned": kept, "total": len(result), "truncated": True,
|
|
93
|
+
"note": note.format(total=len(result), what="rows", kept=kept, size=size, budget=budget)}
|
|
94
|
+
|
|
95
|
+
if isinstance(result, dict):
|
|
96
|
+
lists = {key: value for key, value in result.items() if isinstance(value, list) and len(value) > 1}
|
|
97
|
+
if lists:
|
|
98
|
+
key = max(lists, key=lambda name: _size(lists[name]))
|
|
99
|
+
rest = _size({name: value for name, value in result.items() if name != key})
|
|
100
|
+
if rest + 800 < budget:
|
|
101
|
+
kept = _fit(lists[key], budget - rest - 800)
|
|
102
|
+
cut = dict(result)
|
|
103
|
+
cut[key] = lists[key][:kept]
|
|
104
|
+
cut["_truncated"] = {
|
|
105
|
+
"field": key, "returned": kept, "total": len(lists[key]),
|
|
106
|
+
"note": note.format(total=len(lists[key]), what=f"entries of '{key}'", kept=kept, size=size, budget=budget)}
|
|
107
|
+
return cut
|
|
108
|
+
|
|
109
|
+
return {"error": (f"The result of {tool} is too large to return ({size} characters, the limit is {budget}). "
|
|
110
|
+
"Narrow the request with filters or a more specific query, or ask for fewer columns.")}
|
|
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
|