{"title":"Công cụ tiện ích (thời gian, calc, random)","slug":"tools","category":"api","summary":"Endpoint tiện ích công khai — thời gian server, máy tính an toàn, trình tạo giá trị ngẫu nhiên. Không yêu cầu xác thực.","audience":["human","llm"],"tags":["api","tools","utility","public"],"difficulty":"beginner","updated":"2026-06-27","word_count":298,"read_minutes":1,"llm_context":"No auth required for any /tools/* endpoint.\nGET /tools/time → { time, timezone, offset }\nGET /tools/calc?expr=(10+5)*3 → { result, expr } (safe, no eval, arithmetic only)\nGET /tools/random?type=uuid → { value, type } (types: uuid, int, float, hex, alpha)\nUse case: LLM agents that need current time, safe math, or random values.\n","lang":"vi","translated":true,"requested_lang":"vi","content_markdown":"\n# Công cụ tiện ích\n\nCác endpoint `/tools` là tiện ích công khai — không yêu cầu xác thực. Chúng hữu\ních cho LLM agent cần thời gian phía server, toán học an toàn hoặc giá trị ngẫu\nnhiên.\n\n## GET /tools/time\n\nLấy thời gian server hiện tại, múi giờ và độ lệch UTC.\n\n```bash\ncurl https://synapse.schaefer.zone/tools/time\n```\n\nPhản hồi:\n\n```json\n{\n  \"time\": \"2026-06-27T14:30:00.000Z\",\n  \"timezone\": \"Europe/Berlin\",\n  \"offset\": 120\n}\n```\n\nTrường hợp sử dụng: LLM agent cần biết \"bây giờ là mấy giờ\" để lên lịch, timestamp\nhoặc tính ngày tương đối.\n\n## GET /tools/calc\n\nMáy tính an toàn — chỉ số học, không có `eval()`. Hỗ trợ `+`, `-`, `*`, `/`,\n`%`, `(`, `)` và số.\n\n```bash\ncurl \"https://synapse.schaefer.zone/tools/calc?expr=(10+5)*3\"\n```\n\nPhản hồi:\n\n```json\n{\n  \"result\": 45,\n  \"expr\": \"(10+5)*3\"\n}\n```\n\n> [!TIP]\n> Sử dụng endpoint này thay vì cố gắng tính toán trong đầu hoặc qua phân tích\n> chuỗi. Nó an toàn (không thể tiêm code) và chính xác.\n\n### Toán tử được hỗ trợ\n\n- `+` cộng\n- `-` trừ\n- `*` nhân\n- `/` chia\n- `%` modulo\n- `(` `)` dấu ngoặc\n- Số (số nguyên và số thập phân)\n\n### Ví dụ\n\n```bash\ncurl \".../tools/calc?expr=2+2\"          # → 4\ncurl \".../tools/calc?expr=3.14*100\"     # → 314\ncurl \".../tools/calc?expr=100%7\"        # → 2\ncurl \".../tools/calc?expr=(2+3)*4-1\"    # → 19\n```\n\n## GET /tools/random\n\nTạo giá trị ngẫu nhiên.\n\n```bash\n# UUID v4\ncurl \"https://synapse.schaefer.zone/tools/random?type=uuid\"\n# → { \"value\": \"a1b2c3d4-...\", \"type\": \"uuid\" }\n\n# Integer (default range 0-100)\ncurl \"https://synapse.schaefer.zone/tools/random?type=int&min=1&max=10\"\n# → { \"value\": 7, \"type\": \"int\" }\n\n# Float\ncurl \"https://synapse.schaefer.zone/tools/random?type=float&min=0&max=1\"\n# → { \"value\": 0.7234, \"type\": \"float\" }\n\n# Hex string\ncurl \"https://synapse.schaefer.zone/tools/random?type=hex&min=8&max=16\"\n# → { \"value\": \"a3f7b2c1\", \"type\": \"hex\" }\n\n# Alphabetic string\ncurl \"https://synapse.schaefer.zone/tools/random?type=alpha&min=8&max=12\"\n# → { \"value\": \"kQmzPwXn\", \"type\": \"alpha\" }\n```\n\n### Tham số loại\n\n| Loại | Tham số | Đầu ra |\n|------|-----------|--------|\n| `uuid` | không có | Chuỗi UUID v4 |\n| `int` | `min`, `max` (mặc định 0-100) | Số nguyên |\n| `float` | `min`, `max` (mặc định 0-100) | Số thực |\n| `hex` | `min`, `max` (phạm vi độ dài, mặc định 8-16) | Chuỗi hex |\n| `alpha` | `min`, `max` (phạm vi độ dài, mặc định 8-16) | Chuỗi chữ cái |\n\n## Trường hợp sử dụng cho LLM agent\n\n### Tạo ID duy nhất\n\n```bash\nID=$(curl -s .../tools/random?type=uuid | jq -r .value)\ncurl -X POST .../memory -d \"{\\\"key\\\": \\\"task_$ID\\\", ...}\"\n```\n\n### Tính phần trăm\n\n```bash\nTOTAL=142\nDONE=87\nPERCENT=$(curl -s \".../tools/calc?expr=($DONE*100)/$TOTAL\" | jq -r .result)\necho \"Progress: $PERCENT%\"\n```\n\n### Lấy timestamp hiện tại\n\n```bash\nNOW=$(curl -s .../tools/time | jq -r .time)\ncurl -X POST .../var -d \"{\\\"key\\\": \\\"last_run\\\", \\\"value\\\": \\\"$NOW\\\"}\"\n```\n\n### Tạo dữ liệu kiểm thử\n\n```bash\nfor i in {1..10}; do\n  NAME=$(curl -s \".../tools/random?type=alpha&min=5&max=10\" | jq -r .value)\n  curl -X POST .../memory -d \"{\\\"key\\\": \\\"test_$i\\\", \\\"content\\\": \\\"$NAME\\\"}\"\ndone\n```\n\n## Bước tiếp theo\n\n- [Tổng quan API](/docs/api/overview) — tất cả nhóm endpoint\n- [Lỗi & Xử lý lỗi](/docs/api/errors)\n","content_html":"<h1>Công cụ tiện ích</h1>\n<p>Các endpoint <code>/tools</code> là tiện ích công khai — không yêu cầu xác thực. Chúng hữu\ních cho LLM agent cần thời gian phía server, toán học an toàn hoặc giá trị ngẫu\nnhiên.</p>\n<h2>GET /tools/time</h2>\n<p>Lấy thời gian server hiện tại, múi giờ và độ lệch UTC.</p>\n<pre><code class=\"hljs language-bash\">curl https://synapse.schaefer.zone/tools/time</code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;time&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;2026-06-27T14:30:00.000Z&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;timezone&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;Europe/Berlin&quot;</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;offset&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">120</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><p>Trường hợp sử dụng: LLM agent cần biết &quot;bây giờ là mấy giờ&quot; để lên lịch, timestamp\nhoặc tính ngày tương đối.</p>\n<h2>GET /tools/calc</h2>\n<p>Máy tính an toàn — chỉ số học, không có <code>eval()</code>. Hỗ trợ <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>,\n<code>%</code>, <code>(</code>, <code>)</code> và số.</p>\n<pre><code class=\"hljs language-bash\">curl <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/tools/calc?expr=(10+5)*3&quot;</span></code></pre><p>Phản hồi:</p>\n<pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n  <span class=\"hljs-attr\">&quot;result&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">45</span><span class=\"hljs-punctuation\">,</span>\n  <span class=\"hljs-attr\">&quot;expr&quot;</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">&quot;(10+5)*3&quot;</span>\n<span class=\"hljs-punctuation\">}</span></code></pre><div class=\"callout callout-ok\">Sử dụng endpoint này thay vì cố gắng tính toán trong đầu hoặc qua phân tích\nchuỗi. Nó an toàn (không thể tiêm code) và chính xác.</div><h3>Toán tử được hỗ trợ</h3>\n<ul>\n<li><code>+</code> cộng</li>\n<li><code>-</code> trừ</li>\n<li><code>*</code> nhân</li>\n<li><code>/</code> chia</li>\n<li><code>%</code> modulo</li>\n<li><code>(</code> <code>)</code> dấu ngoặc</li>\n<li>Số (số nguyên và số thập phân)</li>\n</ul>\n<h3>Ví dụ</h3>\n<pre><code class=\"hljs language-bash\">curl <span class=\"hljs-string\">&quot;.../tools/calc?expr=2+2&quot;</span>          <span class=\"hljs-comment\"># → 4</span>\ncurl <span class=\"hljs-string\">&quot;.../tools/calc?expr=3.14*100&quot;</span>     <span class=\"hljs-comment\"># → 314</span>\ncurl <span class=\"hljs-string\">&quot;.../tools/calc?expr=100%7&quot;</span>        <span class=\"hljs-comment\"># → 2</span>\ncurl <span class=\"hljs-string\">&quot;.../tools/calc?expr=(2+3)*4-1&quot;</span>    <span class=\"hljs-comment\"># → 19</span></code></pre><h2>GET /tools/random</h2>\n<p>Tạo giá trị ngẫu nhiên.</p>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-comment\"># UUID v4</span>\ncurl <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/tools/random?type=uuid&quot;</span>\n<span class=\"hljs-comment\"># → { &quot;value&quot;: &quot;a1b2c3d4-...&quot;, &quot;type&quot;: &quot;uuid&quot; }</span>\n\n<span class=\"hljs-comment\"># Integer (default range 0-100)</span>\ncurl <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/tools/random?type=int&amp;min=1&amp;max=10&quot;</span>\n<span class=\"hljs-comment\"># → { &quot;value&quot;: 7, &quot;type&quot;: &quot;int&quot; }</span>\n\n<span class=\"hljs-comment\"># Float</span>\ncurl <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/tools/random?type=float&amp;min=0&amp;max=1&quot;</span>\n<span class=\"hljs-comment\"># → { &quot;value&quot;: 0.7234, &quot;type&quot;: &quot;float&quot; }</span>\n\n<span class=\"hljs-comment\"># Hex string</span>\ncurl <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/tools/random?type=hex&amp;min=8&amp;max=16&quot;</span>\n<span class=\"hljs-comment\"># → { &quot;value&quot;: &quot;a3f7b2c1&quot;, &quot;type&quot;: &quot;hex&quot; }</span>\n\n<span class=\"hljs-comment\"># Alphabetic string</span>\ncurl <span class=\"hljs-string\">&quot;https://synapse.schaefer.zone/tools/random?type=alpha&amp;min=8&amp;max=12&quot;</span>\n<span class=\"hljs-comment\"># → { &quot;value&quot;: &quot;kQmzPwXn&quot;, &quot;type&quot;: &quot;alpha&quot; }</span></code></pre><h3>Tham số loại</h3>\n<table>\n<thead>\n<tr>\n<th>Loại</th>\n<th>Tham số</th>\n<th>Đầu ra</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>uuid</code></td>\n<td>không có</td>\n<td>Chuỗi UUID v4</td>\n</tr>\n<tr>\n<td><code>int</code></td>\n<td><code>min</code>, <code>max</code> (mặc định 0-100)</td>\n<td>Số nguyên</td>\n</tr>\n<tr>\n<td><code>float</code></td>\n<td><code>min</code>, <code>max</code> (mặc định 0-100)</td>\n<td>Số thực</td>\n</tr>\n<tr>\n<td><code>hex</code></td>\n<td><code>min</code>, <code>max</code> (phạm vi độ dài, mặc định 8-16)</td>\n<td>Chuỗi hex</td>\n</tr>\n<tr>\n<td><code>alpha</code></td>\n<td><code>min</code>, <code>max</code> (phạm vi độ dài, mặc định 8-16)</td>\n<td>Chuỗi chữ cái</td>\n</tr>\n</tbody></table>\n<h2>Trường hợp sử dụng cho LLM agent</h2>\n<h3>Tạo ID duy nhất</h3>\n<pre><code class=\"hljs language-bash\">ID=$(curl -s .../tools/random?<span class=\"hljs-built_in\">type</span>=uuid | jq -r .value)\ncurl -X POST .../memory -d <span class=\"hljs-string\">&quot;{\\&quot;key\\&quot;: \\&quot;task_<span class=\"hljs-variable\">$ID</span>\\&quot;, ...}&quot;</span></code></pre><h3>Tính phần trăm</h3>\n<pre><code class=\"hljs language-bash\">TOTAL=142\nDONE=87\nPERCENT=$(curl -s <span class=\"hljs-string\">&quot;.../tools/calc?expr=(<span class=\"hljs-variable\">$DONE</span>*100)/<span class=\"hljs-variable\">$TOTAL</span>&quot;</span> | jq -r .result)\n<span class=\"hljs-built_in\">echo</span> <span class=\"hljs-string\">&quot;Progress: <span class=\"hljs-variable\">$PERCENT</span>%&quot;</span></code></pre><h3>Lấy timestamp hiện tại</h3>\n<pre><code class=\"hljs language-bash\">NOW=$(curl -s .../tools/time | jq -r .<span class=\"hljs-keyword\">time</span>)\ncurl -X POST .../var -d <span class=\"hljs-string\">&quot;{\\&quot;key\\&quot;: \\&quot;last_run\\&quot;, \\&quot;value\\&quot;: \\&quot;<span class=\"hljs-variable\">$NOW</span>\\&quot;}&quot;</span></code></pre><h3>Tạo dữ liệu kiểm thử</h3>\n<pre><code class=\"hljs language-bash\"><span class=\"hljs-keyword\">for</span> i <span class=\"hljs-keyword\">in</span> {1..10}; <span class=\"hljs-keyword\">do</span>\n  NAME=$(curl -s <span class=\"hljs-string\">&quot;.../tools/random?type=alpha&amp;min=5&amp;max=10&quot;</span> | jq -r .value)\n  curl -X POST .../memory -d <span class=\"hljs-string\">&quot;{\\&quot;key\\&quot;: \\&quot;test_<span class=\"hljs-variable\">$i</span>\\&quot;, \\&quot;content\\&quot;: \\&quot;<span class=\"hljs-variable\">$NAME</span>\\&quot;}&quot;</span>\n<span class=\"hljs-keyword\">done</span></code></pre><h2>Bước tiếp theo</h2>\n<ul>\n<li><a href=\"/docs/api/overview\">Tổng quan API</a> — tất cả nhóm endpoint</li>\n<li><a href=\"/docs/api/errors\">Lỗi &amp; Xử lý lỗi</a></li>\n</ul>\n","urls":{"html":"/docs/api/tools","text":"/docs/api/tools?format=text","json":"/docs/api/tools?format=json","llm":"/docs/api/tools?format=llm"},"translations_available":["en","zh","hi","es","fr","ar","pt","ru","ja","de","it","ko","nl","pl","tr","sv","vi","th","id","uk"]}