{"title":"实用工具（时间、计算、随机）","slug":"tools","category":"api","summary":"公共实用端点 — 服务器时间、安全计算器、随机值生成器。无需认证。","audience":["human","llm"],"tags":["api","tools","utility","public"],"difficulty":"beginner","updated":"2026-06-27","word_count":129,"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":"zh","translated":true,"requested_lang":"zh","content_markdown":"\n# 实用工具\n\n`/tools` 端点是公共工具 — 无需认证。对于需要服务器时间、安全数学计算或随机值的 LLM Agent 很有用。\n\n## GET /tools/time\n\n获取当前服务器时间、时区与 UTC 偏移。\n\n```bash\ncurl https://synapse.schaefer.zone/tools/time\n```\n\n响应：\n\n```json\n{\n  \"time\": \"2026-06-27T14:30:00.000Z\",\n  \"timezone\": \"Europe/Berlin\",\n  \"offset\": 120\n}\n```\n\n用例：LLM Agent 需要知道“现在是几点”，用于调度、时间戳或相对日期计算。\n\n## GET /tools/calc\n\n安全计算器 — 仅支持算术运算，不使用 `eval()`。支持 `+`、`-`、`*`、`/`、`%`、`(`、`)` 和数字。\n\n```bash\ncurl \"https://synapse.schaefer.zone/tools/calc?expr=(10+5)*3\"\n```\n\n响应：\n\n```json\n{\n  \"result\": 45,\n  \"expr\": \"(10+5)*3\"\n}\n```\n\n> [!TIP]\n> 用它代替在脑中计算或字符串解析。它既安全（无法注入代码）又准确。\n\n### 支持的运算符\n\n- `+` 加法\n- `-` 减法\n- `*` 乘法\n- `/` 除法\n- `%` 取模\n- `(` `)` 括号\n- 数字（整数与小数）\n\n### 示例\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\n生成随机值。\n\n```bash\n# UUID v4\ncurl \"https://synapse.schaefer.zone/tools/random?type=uuid\"\n# → { \"value\": \"a1b2c3d4-...\", \"type\": \"uuid\" }\n\n# 整数（默认范围 0-100）\ncurl \"https://synapse.schaefer.zone/tools/random?type=int&min=1&max=10\"\n# → { \"value\": 7, \"type\": \"int\" }\n\n# 浮点数\ncurl \"https://synapse.schaefer.zone/tools/random?type=float&min=0&max=1\"\n# → { \"value\": 0.7234, \"type\": \"float\" }\n\n# 十六进制字符串\ncurl \"https://synapse.schaefer.zone/tools/random?type=hex&min=8&max=16\"\n# → { \"value\": \"a3f7b2c1\", \"type\": \"hex\" }\n\n# 字母字符串\ncurl \"https://synapse.schaefer.zone/tools/random?type=alpha&min=8&max=12\"\n# → { \"value\": \"kQmzPwXn\", \"type\": \"alpha\" }\n```\n\n### 类型参数\n\n| 类型 | 参数 | 输出 |\n|------|-----------|--------|\n| `uuid` | 无 | UUID v4 字符串 |\n| `int` | `min`、`max`（默认 0-100） | 整数 |\n| `float` | `min`、`max`（默认 0-100） | 浮点数 |\n| `hex` | `min`、`max`（长度范围，默认 8-16） | 十六进制字符串 |\n| `alpha` | `min`、`max`（长度范围，默认 8-16） | 字母字符串 |\n\n## LLM Agent 的用例\n\n### 生成唯一 ID\n\n```bash\nID=$(curl -s .../tools/random?type=uuid | jq -r .value)\ncurl -X POST .../memory -d \"{\\\"key\\\": \\\"task_$ID\\\", ...}\"\n```\n\n### 计算百分比\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### 获取当前时间戳\n\n```bash\nNOW=$(curl -s .../tools/time | jq -r .time)\ncurl -X POST .../var -d \"{\\\"key\\\": \\\"last_run\\\", \\\"value\\\": \\\"$NOW\\\"}\"\n```\n\n### 生成测试数据\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## 下一步\n\n- [API 概览](/docs/api/overview) — 所有端点分组\n- [错误与错误处理](/docs/api/errors)\n","content_html":"<h1>实用工具</h1>\n<p><code>/tools</code> 端点是公共工具 — 无需认证。对于需要服务器时间、安全数学计算或随机值的 LLM Agent 很有用。</p>\n<h2>GET /tools/time</h2>\n<p>获取当前服务器时间、时区与 UTC 偏移。</p>\n<pre><code class=\"hljs language-bash\">curl https://synapse.schaefer.zone/tools/time</code></pre><p>响应：</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>用例：LLM Agent 需要知道“现在是几点”，用于调度、时间戳或相对日期计算。</p>\n<h2>GET /tools/calc</h2>\n<p>安全计算器 — 仅支持算术运算，不使用 <code>eval()</code>。支持 <code>+</code>、<code>-</code>、<code>*</code>、<code>/</code>、<code>%</code>、<code>(</code>、<code>)</code> 和数字。</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>响应：</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\">用它代替在脑中计算或字符串解析。它既安全（无法注入代码）又准确。</div><h3>支持的运算符</h3>\n<ul>\n<li><code>+</code> 加法</li>\n<li><code>-</code> 减法</li>\n<li><code>*</code> 乘法</li>\n<li><code>/</code> 除法</li>\n<li><code>%</code> 取模</li>\n<li><code>(</code> <code>)</code> 括号</li>\n<li>数字（整数与小数）</li>\n</ul>\n<h3>示例</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>生成随机值。</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\"># 整数（默认范围 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\"># 浮点数</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\"># 十六进制字符串</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\"># 字母字符串</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>类型参数</h3>\n<table>\n<thead>\n<tr>\n<th>类型</th>\n<th>参数</th>\n<th>输出</th>\n</tr>\n</thead>\n<tbody><tr>\n<td><code>uuid</code></td>\n<td>无</td>\n<td>UUID v4 字符串</td>\n</tr>\n<tr>\n<td><code>int</code></td>\n<td><code>min</code>、<code>max</code>（默认 0-100）</td>\n<td>整数</td>\n</tr>\n<tr>\n<td><code>float</code></td>\n<td><code>min</code>、<code>max</code>（默认 0-100）</td>\n<td>浮点数</td>\n</tr>\n<tr>\n<td><code>hex</code></td>\n<td><code>min</code>、<code>max</code>（长度范围，默认 8-16）</td>\n<td>十六进制字符串</td>\n</tr>\n<tr>\n<td><code>alpha</code></td>\n<td><code>min</code>、<code>max</code>（长度范围，默认 8-16）</td>\n<td>字母字符串</td>\n</tr>\n</tbody></table>\n<h2>LLM Agent 的用例</h2>\n<h3>生成唯一 ID</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>计算百分比</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>获取当前时间戳</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>生成测试数据</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>下一步</h2>\n<ul>\n<li><a href=\"/docs/api/overview\">API 概览</a> — 所有端点分组</li>\n<li><a href=\"/docs/api/errors\">错误与错误处理</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"]}