# Utility Tools endpoint `/tools` เป็น public utility — ไม่ต้องยืนยันตัวตน มีประโยชน์สำหรับ LLM agent ที่ต้องการเวลาฝั่งเซิร์ฟเวอร์, คณิตศาสตร์ปลอดภัย หรือค่าสุ่ม ## GET /tools/time ดึงเวลาเซิร์ฟเวอร์ปัจจุบัน, timezone และ UTC offset ```bash curl https://synapse.schaefer.zone/tools/time ``` Response: ```json { "time": "2026-06-27T14:30:00.000Z", "timezone": "Europe/Berlin", "offset": 120 } ``` กรณีใช้งาน: LLM agent ที่ต้องรู้ "กี่โมงแล้ว" สำหรับการตั้งเวลา, timestamp หรือการคำนวณวันที่เชิงสัมพันธ์ ## GET /tools/calc เครื่องคิดเลขปลอดภัย — arithmetic เท่านั้น ไม่มี `eval()` รองรับ `+`, `-`, `*`, `/`, `%`, `(`, `)` และตัวเลข ```bash curl "https://synapse.schaefer.zone/tools/calc?expr=(10+5)*3" ``` Response: ```json { "result": 45, "expr": "(10+5)*3" } ``` > [!TIP] > ใช้สิ่งนี้แทนการคำนวณในใจหรือผ่าน string parsing ปลอดภัย (ไม่มี code injection ได้) และแม่นยำ ### ตัวดำเนินการที่รองรับ - `+` การบวก - `-` การลบ - `*` การคูณ - `/` การหาร - `%` modulo - `(` `)` วงเล็บ - ตัวเลข (จำนวนเต็มและทศนิยม) ### ตัวอย่าง ```bash curl ".../tools/calc?expr=2+2" # → 4 curl ".../tools/calc?expr=3.14*100" # → 314 curl ".../tools/calc?expr=100%7" # → 2 curl ".../tools/calc?expr=(2+3)*4-1" # → 19 ``` ## GET /tools/random สร้างค่าสุ่ม ```bash # UUID v4 curl "https://synapse.schaefer.zone/tools/random?type=uuid" # → { "value": "a1b2c3d4-...", "type": "uuid" } # Integer (default range 0-100) curl "https://synapse.schaefer.zone/tools/random?type=int&min=1&max=10" # → { "value": 7, "type": "int" } # Float curl "https://synapse.schaefer.zone/tools/random?type=float&min=0&max=1" # → { "value": 0.7234, "type": "float" } # Hex string curl "https://synapse.schaefer.zone/tools/random?type=hex&min=8&max=16" # → { "value": "a3f7b2c1", "type": "hex" } # Alphabetic string curl "https://synapse.schaefer.zone/tools/random?type=alpha&min=8&max=12" # → { "value": "kQmzPwXn", "type": "alpha" } ``` ### พารามิเตอร์ประเภท | Type | Parameters | Output | |------|-----------|--------| | `uuid` | none | UUID v4 string | | `int` | `min`, `max` (default 0-100) | Integer | | `float` | `min`, `max` (default 0-100) | Float | | `hex` | `min`, `max` (length range, default 8-16) | Hex string | | `alpha` | `min`, `max` (length range, default 8-16) | Alphabetic string | ## กรณีใช้งานสำหรับ LLM Agent ### สร้าง ID ที่ไม่ซ้ำ ```bash ID=$(curl -s .../tools/random?type=uuid | jq -r .value) curl -X POST .../memory -d "{\"key\": \"task_$ID\", ...}" ``` ### คำนวณเปอร์เซ็นต์ ```bash TOTAL=142 DONE=87 PERCENT=$(curl -s ".../tools/calc?expr=($DONE*100)/$TOTAL" | jq -r .result) echo "Progress: $PERCENT%" ``` ### ดึง timestamp ปัจจุบัน ```bash NOW=$(curl -s .../tools/time | jq -r .time) curl -X POST .../var -d "{\"key\": \"last_run\", \"value\": \"$NOW\"}" ``` ### สร้างข้อมูลทดสอบ ```bash for i in {1..10}; do NAME=$(curl -s ".../tools/random?type=alpha&min=5&max=10" | jq -r .value) curl -X POST .../memory -d "{\"key\": \"test_$i\", \"content\": \"$NAME\"}" done ``` ## ขั้นตอนถัดไป - [API Overview](/docs/api/overview) — กลุ่ม endpoint ทั้งหมด - [Errors & Error Handling](/docs/api/errors)