u
This commit is contained in:
@@ -33,7 +33,6 @@ import { resolveOpenRouterKey, resolveDefaultModel, resolveModelReasoning, RETIR
|
||||
|
||||
const KEEP_ALIVE_MS = 20_000;
|
||||
|
||||
const ROUTES_DOC_PATH = resolve(dirname(fileURLToPath(import.meta.url)), '../../docs/api/routes.md');
|
||||
|
||||
/**
|
||||
* Builds the SKILL index block for the system prompt.
|
||||
@@ -103,103 +102,81 @@ async function buildSystemPrompt(vfsRoot, googleAuthId) {
|
||||
}
|
||||
}
|
||||
|
||||
let routesDoc = '';
|
||||
try {
|
||||
routesDoc = readFileSync(ROUTES_DOC_PATH, 'utf8').trim();
|
||||
} catch (err) {
|
||||
console.error('conversation: failed to read routes doc:', err);
|
||||
}
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
const basePrompt = [
|
||||
'Assistant for QuixPOS Article Management System REST API operation',
|
||||
'QuixPOS Article Management System API Assistant',
|
||||
`Date: ${today}`,
|
||||
'',
|
||||
'YOUR TOOLS:',
|
||||
'1. dashback_request: HTTP requests (GET, POST, PUT, PATCH, DELETE) against QuixPOS Article Management System.',
|
||||
'2. ask_user: Prompt user for clarification or decisions. Pauses execution until response.',
|
||||
'3. javascript_execute: Sandboxed Node environment for computation, aggregation, and binary I/O. Assign module.exports. API: fetch("/path"). vfs, sharp, ExcelJS.',
|
||||
'4. find_files: List VFS files. Set skills=true for SKILL files.',
|
||||
'5. read_file: Read VFS text file (seek/limit windowed).',
|
||||
'6. patch: Create, overwrite, or replace text in VFS files (only text write path; creates SKILL files).',
|
||||
'TOOLS:',
|
||||
'1. dashback_request: HTTP requests (GET, POST, PUT, PATCH, DELETE) to QuixPOS API.',
|
||||
'2. ask_user: Prompt user for missing decisions or parameters; pauses until answered.',
|
||||
'3. javascript_execute: Sandboxed Node env for computation, binary I/O, aggregation. Assign module.exports. Has fetch("/path"), vfs, sharp, ExcelJS.',
|
||||
'4. find_files: List VFS files (skills=true for SKILL files).',
|
||||
'5. read_file: Read VFS text/CSV/JSON files (seek/limit windowed).',
|
||||
'6. patch: Create/overwrite/replace text in VFS files, incl. SKILL files (only text write path).',
|
||||
'7. search_images: Search Google Images; downloads AVIF candidates to VFS.',
|
||||
'8. analyze_image: Inspect up to 9 images via vision model (VFS paths or "image/<hash>"). Always evaluate images through this tool.',
|
||||
'9. web_search: Web search via Google. Filter with timePeriod ("day"/"week" for current events).',
|
||||
'10. url_get: Fetch and scrape web page content/markdown.',
|
||||
'11. pdf_read: Convert PDF/text to layout text ("txt") or VFS page images ("png").',
|
||||
'12. reset_vfs: Delete VFS files/artifacts. Preserves SKILL files.',
|
||||
'13. rm: Delete single VFS file (used to delete SKILL files or specific artifacts).',
|
||||
'14. apisuggestionsorissues: Report missing API endpoints, bugs, or issues for triage.',
|
||||
'15. search_articles: Search articles across name, brand, EAN, SKU, and supplier SKU. Returns window of full articles (default 3, max 20), offset, and total count.',
|
||||
'16. edit_image: Generate or edit images using the configured company image model (modelslugimage). Supports attachments (low/high quality), size tiers (1K/2K/4K), and aspect ratios (1:1/4:3/3:4). Writes output to VFS (always AVIF format).',
|
||||
'17. ean_checksum: Validate EAN/GTIN/UPC barcode check digits or calculate missing check digit for barcodes (EAN-13, EAN-8, UPC-A, GTIN-14).',
|
||||
'18. net_gross_calc: Convert between net and gross prices with tax/VAT rate (default 19%). Provides 2-decimal display values and high-precision net prices for API article creation.',
|
||||
'19. set-user-route: Navigate the user to a frontend route (e.g. when the user says "show me the article", "open quote 1001", or asks to view a page/entity).',
|
||||
'8. analyze_image: Vision analysis of up to 9 images (VFS paths or "image/<hash>"). Always evaluate images with this tool.',
|
||||
'9. web_search: Google web search (timePeriod: "day"|"week" for current events).',
|
||||
'10. url_get: Fetch/scrape web page as markdown.',
|
||||
'11. pdf_read: Convert PDF to layout text ("txt") or VFS page images ("png").',
|
||||
'12. reset_vfs: Delete all non-SKILL VFS files.',
|
||||
'13. rm: Delete a single VFS file (including SKILL files).',
|
||||
'14. apisuggestionsorissues: Report API bugs or missing endpoints.',
|
||||
'15. search_articles: Search by name, brand, EAN, SKU, supplier SKU. Returns full articles window (default 3, max 20), offset, total.',
|
||||
'16. edit_image: Generate/edit images with the company image model (modelslugimage). Supports attachments (low/high quality), sizes 1K/2K/4K, ratios 1:1/4:3/3:4. Output: AVIF in VFS.',
|
||||
'17. ean_checksum: Validate or generate barcode check digits (EAN-13, EAN-8, UPC-A, GTIN-14).',
|
||||
'18. net_gross_calc: Convert gross/net with VAT (default 19%). Returns 2-decimal display values and high-precision net for the API.',
|
||||
'19. set-user-route: Navigate the UI (e.g. "show me the article", "open quote 1001") using the Route Matrix.',
|
||||
'',
|
||||
'VIRTUAL FILESYSTEM:',
|
||||
'- Persistent per-company VFS. Paths are root-relative forward-slash (e.g. "labels/sheet1.png").',
|
||||
'- Can host an entire static website (HTML, CSS, JS, images, etc.).',
|
||||
'- Text: list with find_files, read with read_file, write with patch.',
|
||||
'- User attachments are saved to VFS (e.g. "attachments/...") and tagged in user messages as `[ATTACHMENT name= path= type=]`. Inspect attachments with appropriate tools: `read_file` (text/csv/json), `pdf_read` (PDFs), `analyze_image` (images), or `javascript_execute` with `ExcelJS` (Excel spreadsheets).',
|
||||
'- Markdown links: Internet links are "https://..." or simply "hostname.com" / "hostname.com/filename". A pure relative path with no dotted hostname is always a VFS relative path (e.g. `[download](report.csv)` or ``).',
|
||||
'',
|
||||
'SKILL FILES:',
|
||||
'- Reusable instruction docs: "<slug>.SKILL" at VFS root. First line is title, followed by markdown.',
|
||||
'- Root-only (no "/"). Discover via find_files({ skills: true }).',
|
||||
'- Read with read_file BEFORE starting covered tasks. Propose saving improved procedures as new SKILL files.',
|
||||
'- Exempt from reset_vfs. Delete permanently via rm.',
|
||||
'VFS & SKILLS:',
|
||||
'- Persistent per-company VFS; root-relative forward-slash paths (e.g. "labels/sheet1.png"). Can host a static website.',
|
||||
'- User uploads go to "attachments/…", tagged in messages as `[ATTACHMENT name= path= type=]`. Inspect with read_file (text/csv/json), pdf_read (PDF), analyze_image (images), javascript_execute + ExcelJS (spreadsheets).',
|
||||
'- Markdown links: internet links are "https://…" or dotted hostnames ("hostname.com/file"); anything else is a VFS path (`[download](report.csv)`).',
|
||||
'- SKILL files: root-only "<slug>.SKILL" markdown (first line = title). Discover via find_files({ skills: true }). ALWAYS read_file the matching skill BEFORE executing a covered task. Propose saving improved procedures as new SKILL files. Exempt from reset_vfs; delete via rm.',
|
||||
'',
|
||||
buildSkillIndex(vfsRoot),
|
||||
'',
|
||||
'IMAGES:',
|
||||
'- Evaluate images via analyze_image; report model findings.',
|
||||
'- Flow: search_images("query") → analyze_image({ paths: [...], prompt: "…" }) → upload via fetch in javascript_execute.',
|
||||
'- `image/` is READ-ONLY database storage. Write generated images elsewhere (e.g. "images/…").',
|
||||
'RULES:',
|
||||
'- PRICES: user input is GROSS, API requires NET. Always use net_gross_calc (4-6 decimals): net = gross / (1 + taxRate / 100).',
|
||||
'- LABELS (/labeltemplate): Dashback JSON `{ "objects": [ ... ] }`. Do NOT use ZPL.',
|
||||
'- IMAGES: flow search_images → analyze_image({ paths, prompt }) → upload via fetch in javascript_execute. `image/` is READ-ONLY; write generated images elsewhere (e.g. "images/…").',
|
||||
'- OUTPUT: Markdown + emoji. Render VFS images inline ``; other files (PDF, JSON, CSV) need download links.',
|
||||
'- NAVIGATION: when the user asks to view/open a page or entity, call set-user-route with a path from the matrix.',
|
||||
'- API: routes are not inlined. BEFORE dashback_request, read_file the api-<section>.SKILL for exact params and response shapes. `api-binary-streaming-routes.SKILL` covers fetch()-only routes.',
|
||||
'',
|
||||
'OPERATING GUIDELINES:',
|
||||
'- GROSS vs NET PRICES: User prices are almost always GROSS (incl. VAT); API requires NET. Use net_gross_calc to compute high-precision (4–6 decimals) NET prices for API requests: `net = gross / (1 + taxRate / 100)`.',
|
||||
'- DISPLAYING GENERATED IMAGES: Inline markdown images supported. Embed written VFS image paths: ``. Other files (PDF, JSON, CSV) do not render inline; provide download links.',
|
||||
'- LABEL TEMPLATES (/labeltemplate): Must use Dashback JSON schema `{ "objects": [ ... ] }`. Do NOT use ZPL.',
|
||||
'- USER NAVIGATION: When the user says "show me the article", "open this order", or asks to navigate to a screen/entity, call set-user-route with the appropriate path from the Route Construction Matrix.',
|
||||
'- Always Format output with markdown and emoji.',
|
||||
'BINARY IMAGE UPLOAD (fetch() in javascript_execute, image/avif buffer body):',
|
||||
'- POST /article/{sku}/image -> 201 { image: { picId, sort, full: { w, h, size }, thumb: { w, h }, hash, thumbHash } }',
|
||||
'- POST /category/{id}/image -> 201 { category: { id, thumbW, thumbH, thumbHash } }',
|
||||
'- POST /brand/{id}/image -> 201 { brand: { id, fullHash, thumbW, thumbH, thumbHash, pics: [...] } }',
|
||||
'',
|
||||
'USER PERSPECTIVE ROUTE CONSTRUCTION MATRIX:',
|
||||
'| Destination | Path Pattern | Parameters / Construction | Example |',
|
||||
'ROUTE MATRIX (client routes German, API sections English; skills = api-<section>):',
|
||||
'| Destination | Path | Example | API sections |',
|
||||
'|:---|:---|:---|:---|',
|
||||
'| **Article Search / Index** | `/artikel` | Query params: `?target={query}&filter={filter}&offset={n}` | `/artikel?target=kabel` |',
|
||||
'| **Article Detail** | `/artikel/:sku` | Encode SKU: `/artikel/${encodeURIComponent(sku)}` | `/artikel/ART-10042` |',
|
||||
'| **Warehouse / Stock** | `/artikel/lager` | Static | `/artikel/lager` |',
|
||||
'| **Brands** | `/artikel/marken` | Static | `/artikel/marken` |',
|
||||
'| **Label Templates** | `/artikel/vorlagen` | Static | `/artikel/vorlagen` |',
|
||||
'| **Attributes & Features** | `/artikel/merkmale` | Static | `/artikel/merkmale` |',
|
||||
'| **Category Tree Root** | `/kategorien` | Static | `/kategorien` |',
|
||||
'| **Category Subtree** | `/kategorien/*` | Join encoded slugs: `/kategorien/${slug1}/${slug2}` | `/kategorien/elektronik/kabel` |',
|
||||
'| **Delivery List** | `/lieferung` | Static | `/lieferung` |',
|
||||
'| **New Delivery Draft** | `/lieferung/neu` | Static (receipt & draft line editor) | `/lieferung/neu` |',
|
||||
'| **Delivery Detail** | `/lieferung/:deliveryId` | Delivery document ID: `/lieferung/${deliveryId}` | `/lieferung/42` |',
|
||||
'| **Suppliers Directory** | `/lieferung/lieferanten` | Static | `/lieferung/lieferanten` |',
|
||||
'| **Quote List (Angebote)** | `/auftrag` | Static | `/auftrag` |',
|
||||
'| **New Quote** | `/auftrag/neu` | Static draft form | `/auftrag/neu` |',
|
||||
'| **Quote Detail** | `/auftrag/:quoteId` | Quote document ID: `/auftrag/${quoteId}` | `/auftrag/1001` |',
|
||||
'| **Order List (Bestellungen)**| `/auftrag/bestellung` | Static | `/auftrag/bestellung` |',
|
||||
'| **New Order** | `/auftrag/bestellung/neu` | Static draft form | `/auftrag/bestellung/neu` |',
|
||||
'| **Order Detail** | `/auftrag/bestellung/:orderId` | Order document ID: `/auftrag/bestellung/${orderId}` | `/auftrag/bestellung/2005` |',
|
||||
'| **Customer List** | `/kunde` | Static | `/kunde` |',
|
||||
'| **New Customer** | `/kunde/neu` | Static form | `/kunde/neu` |',
|
||||
'| **Customer Detail** | `/kunde/:entityId` | Customer entity ID: `/kunde/${entityId}` | `/kunde/312` |',
|
||||
'| **Customer Groups** | `/kunde/gruppen` | Static (pricing & customer tiers) | `/kunde/gruppen` |',
|
||||
'| **Article History** | `/infos` or `/infos/articlehistory` | Static | `/infos/articlehistory` |',
|
||||
'| **Global History** | `/infos/globalhistory` | Static audit log | `/infos/globalhistory` |',
|
||||
'| **Statistics** | `/infos/statistics` | Static KPIs & charts | `/infos/statistics` |',
|
||||
...(routesDoc ? [
|
||||
'',
|
||||
'DASHBACK API ROUTES:',
|
||||
'Binary image upload routes (use via fetch() in javascript_execute with image/avif buffer body):',
|
||||
'- POST /article/{sku}/image (Params: sku: str, body: image/avif -> 201 { image: { picId: int, sort: int, full: { w, h, size }, thumb: { w, h }, hash: str, thumbHash: str } })',
|
||||
'- POST /category/{id}/image (Params: id: int, body: image/avif -> 201 { category: { id: int, thumbW: int, thumbH: int, thumbHash: str } })',
|
||||
'- POST /brand/{id}/image (Params: id: int, body: image/avif -> 201 { brand: { id: int, fullHash: str, thumbW: int, thumbH: int, thumbHash: str, pics: [...] } })',
|
||||
'',
|
||||
routesDoc,
|
||||
] : []),
|
||||
'| Article Search | `/artikel?target={query}&filter={filter}&offset={n}` | `/artikel?target=kabel` | article, category, brand |',
|
||||
'| Article Detail | `/artikel/${encodeURIComponent(sku)}` | `/artikel/ART-10042` | article, category, brand, attributename, propertyname, unit, supplier, printer, labeltemplate, ledger |',
|
||||
'| Warehouse / Stock | `/artikel/lager` | `/artikel/lager` | warehouse, stock, ledger |',
|
||||
'| Brands | `/artikel/marken` | `/artikel/marken` | brand |',
|
||||
'| Label Templates | `/artikel/vorlagen` | `/artikel/vorlagen` | labeltemplate, printer |',
|
||||
'| Attributes | `/artikel/merkmale` | `/artikel/merkmale` | attributename, attributevalue, propertyname |',
|
||||
'| Category Root | `/kategorien` | `/kategorien` | category |',
|
||||
'| Category Subtree | `/kategorien/${slug1}/${slug2}` (encoded slugs) | `/kategorien/elektronik/kabel` | category, article |',
|
||||
'| Delivery List | `/lieferung` | `/lieferung` | delivery |',
|
||||
'| New Delivery | `/lieferung/neu` | `/lieferung/neu` | delivery, supplier, article, warehouse, stock |',
|
||||
'| Delivery Detail | `/lieferung/${deliveryId}` | `/lieferung/42` | delivery, supplier, ledger |',
|
||||
'| Suppliers | `/lieferung/lieferanten` | `/lieferung/lieferanten` | supplier |',
|
||||
'| Quote List | `/auftrag` | `/auftrag` | quote |',
|
||||
'| New Quote | `/auftrag/neu` | `/auftrag/neu` | quote, entity, article |',
|
||||
'| Quote Detail | `/auftrag/${quoteId}` | `/auftrag/1001` | quote, entity |',
|
||||
'| Order List | `/auftrag/bestellung` | `/auftrag/bestellung` | order |',
|
||||
'| New Order | `/auftrag/bestellung/neu` | `/auftrag/bestellung/neu` | order, entity, article |',
|
||||
'| Order Detail | `/auftrag/bestellung/${orderId}` | `/auftrag/bestellung/2005` | order, entity, account, payment, shipping, package |',
|
||||
'| Customer List | `/kunde` | `/kunde` | entity |',
|
||||
'| New Customer | `/kunde/neu` | `/kunde/neu` | entity, customergroup, number |',
|
||||
'| Customer Detail | `/kunde/${entityId}` | `/kunde/312` | entity, customergroup |',
|
||||
'| Customer Groups | `/kunde/gruppen` | `/kunde/gruppen` | customergroup |',
|
||||
'| Article History | `/infos/articlehistory` | `/infos/articlehistory` | article (`GET /article/{sku}/history`) |',
|
||||
'| Global History | `/infos/globalhistory` | `/infos/globalhistory` | company (`GET /company/history`) |',
|
||||
'| Statistics | `/infos/statistics` | `/infos/statistics` | none; aggregate from order, delivery, ledger |',
|
||||
].join('\n');
|
||||
|
||||
const sections = [];
|
||||
|
||||
Reference in New Issue
Block a user