轻量 Runtime Contract。完整交互规范见
docs/interaction.md,分析策略见docs/analysis.md。 兼容平台:OpenClaw、Hermes-Agent、Claude Code、ChatGPT
用户意图 → 工具路由:
L1 意图L2 输出调用查询数据对话展示query_device → query_data → 按输出格式回复查询数据文件导出query_device → export_* → 返回文件路径生成报告文件导出query_device → query_data → 分析 → write_html对比设备对话展示query_device (xN) → query_data (xN) → 对比表格对比设备文件导出query_device (xN) → query_data (xN) → export_excel
docs/interaction.md Section 1。 不得编造和引导用户查询开放接口中不存在的数据#认证约束(MUST): Agent 禁止 向用户索要 appid 或 secret,也 禁止 在对话中接收、存储或回显这些凭据。凭据仅通过 CLI 在本地配置:
bash
npx @insentek/openapi-skill login # 配置(加密保存)
npx @insentek/openapi-skill logout # 清除
npx @insentek/openapi-skill auth status # 查看连接状态
用途工具示例安装 / 更新 skillnpx @insentek/openapi-skill``install -r openclaw -s workspace -y配置 / 清除凭据npx @insentek/openapi-skill login/logout``npx @insentek/openapi-skill login查连接状态npx @insentek/openapi-skill auth status—查安装路径 / 脚本位置npx @insentek/openapi-skill info/status/doctor --json见下方「脚本路径解析」查询 APIpython3 <SKILL_ROOT>/scripts/insentek_cli.py``python3 .../insentek_cli.py devices
Agent 工作目录通常 不是 skill 安装目录。 禁止 使用相对路径 python3 scripts/insentek_cli.py ...。
首次 API 调用前,或脚本路径未知 / 返回「文件找不到」时, 必须先 查实际安装位置。 info --json 会列出所有 runtime × scope 的解析结果及 installed 标记,无需提前知道用户是哪种安装:
bash
npx @insentek/openapi-skill info --json
从输出中遍历 runtimes[].scopes[],挑选第一个 installed: true 的条目,将其 installDir 作为 ${SKILL_ROOT},将 scripts.cli / scripts.exportExcel / scripts.writeHtml 作为脚本绝对路径,并将 python.command(如 python3 / py / python)作为 ${PYTHON}。解析后在 本会话内缓存,后续 API 调用复用, 不要 重复猜测路径。
如果用户已经明确告诉过你 runtime / scope(例如刚刚 install -r openclaw -s workspace -y),也可以用 status --json 精确查询:
bash
npx @insentek/openapi-skill status -r openclaw -s workspace --json
# 或按用户场景选择,比如:
npx @insentek/openapi-skill status -r claude -s global / -s project
OpenClaw workspace 常见路径(仅供参考, 以 info/status 返回为准):
~/.openclaw/workspace/skills/insentek-openapi
禁止(MUST NOT):
python3 scripts/insentek_cli.py ... — 相对路径在 OpenClaw 等环境下会失败npx @insentek/openapi-skill devices — devices 不是顶层命令,会被 commander 当成 install 的子命令而触发安装流程info --json用户说「配置好了,继续吧」→ 从 中断前的意图 继续;若已有 ${SKILL_ROOT} 直接调 API, 不要 重新 login。
若工具返回 authentication_required 或 HTTP 401/403, STOP 并 原样 向用户展示以下固定文案(不得改写、不得追加索要 secret):
text
这台电脑还没有连接 Insentek API,需要先完成一次本地配置,通常 1 分钟就好。
请在终端运行:
npx @insentek/openapi-skill login
按提示输入 appid 和 secret 即可(加密保存在本机,无需发到这个对话)。配置完成后回来继续提问,我接着帮你处理。
查询设备信息:列表、详情、别名解析。
json
{
"page": { "type": "integer", "default": 1 },
"limit": { "type": "integer", "default": 20 },
"sn": { "type": "string", "description": "设备序列号,与 alias 二选一" },
"alias": { "type": "string", "description": "设备别名,支持部分匹配" }
}
bash
# 列表(${SKILL_ROOT} / ${PYTHON} 由 info --json 解析,见上方)
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py devices [--page ${page}] [--limit ${limit}]
# 详情
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py device --sn ${sn}
${PYTHON}在 macOS/Linux 默认为python3,Windows 默认为python(亦可为py);以info --json输出的python.command为准。 禁止 使用裸python——在 macOS 系统默认配置、新版 Ubuntu/Fedora 等环境下python命令不存在或指向 Python 2,会直接失败。
行为: alias → 模糊匹配 → 多匹配时反问用户 → 单匹配时缓存 alias→sn 映射。
查询设备历史数据或实时数据。
json
{
"sn": { "type": "string", "required": true },
"time_expression": { "type": "string", "description": "自然语言时间描述,如'现在'、'昨天'、'最近7天'。不传默认最近24小时。" },
"range": { "type": "string", "description": "YYYYMMDD,YYYYMMDD,由 time_expression 自动计算" },
"includeParameters": { "type": "string", "description": "指定参数,逗号分隔,如 moisture,temperature" }
}
bash
# 历史数据
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py data --sn ${sn} --range ${range} [--include-params ${params}]
# 预览(调试/验证用)
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py data --sn ${sn} --range ${range} --dry-run
# 实时数据(latest)
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py latest --sn ${sn}
时间表达式解析见 docs/interaction.md Section 2。
用户意图明确为"导出/下载"时调用,而非 query_data。
bash
# CSV
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py export --sn ${sn} --range ${range} --format csv --output ${file}.csv
# Excel
${PYTHON} ${SKILL_ROOT}/scripts/export_excel.py --sn ${sn} --range ${range} --output ${file}.xlsx
# JSON
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py export --sn ${sn} --range ${range} --format json --output ${file}.json
所有导出脚本均支持 --dry-run。
Agent 完成数据分析后,将动态生成的 HTML 内容写入文件。 推荐 使用 --input-file 避免 shell 转义吞掉换行 / 引号 / 反斜杠:
bash
# 1. 先把 HTML 内容写到临时文件(写文件工具按平台决定)
# e.g. write to /tmp/report.html or %TEMP%\report.html
# 2. 然后调用 write_html.py 落盘
${PYTHON} ${SKILL_ROOT}/scripts/write_html.py --input-file ${tmp_html} --output ${file}.html
# 也支持 stdin(注意 echo 会破坏 HTML 中的换行/引号,仅用于简单片段):
echo "${html_content}" | ${PYTHON} ${SKILL_ROOT}/scripts/write_html.py --output ${file}.html
限制项规则超限处理单次查询跨度≤ 365 天拒绝,提供拆分选项历史回溯≤ 3 年拒绝,提示最早日期对话展示≤ 200 条展示摘要 + 首尾各 10 条抽样文件导出≤ 50,000 条拒绝,建议缩小范围或分批
query_data 返回后,检查实际数据范围 vs 请求范围:
text
requested_days = 用户请求的天数
actual_days = 实际返回数据的天数
coverage = actual_days / requested_days
IF coverage < 0.5 OR actual_days < 7:
→ STOP
→ 告知用户实际范围,询问是否继续
→ 等待确认后才可生成报告/分析
ELSE IF actual_range < requested_range:
→ 继续,但报告 MUST 使用 actual_range 标注
Agent 禁止 将原始传感器全量数据输出到对话中。
场景处理"看看数据"统计摘要 + 首尾各 5 条"调试"--dry-run 预览"给我原始数据"引导导出 CSV/Excel"全部发给我"拒绝,解释 Token 限制
完整输出格式规范见 docs/interaction.md Section 4。
用户 必须 通过 CLI 在本地配置凭据,Agent 不得 在对话中收集 appid/secret:
bash
npx @insentek/openapi-skill login
npx @insentek/openapi-skill logout
npx @insentek/openapi-skill auth status
凭据加密保存在 ~/.config/insentek/credentials.json(文件权限 600)。
场景Agent 行为用户首次使用 / 未连接展示 Section 2 固定引导文案, 禁止 索要 secret用户主动发送 appid/secret拒绝接收,说明请改用 CLI login401/403 / authentication_required展示 Section 2 固定引导文案,STOP用户要求"重新认证"引导 npx @insentek/openapi-skill login(更新)或 logout 后再 login
脚本 管理 token 生命周期,实现缓存 + 自动刷新机制:
login 验证凭据后,凭据和 token 一并加密保存authentication_required,Agent 引导用户重新 logintext
请求 API
├── 使用缓存 token
├── 成功 → 返回数据
└── 401/403 → 调用 /v3/token 获取新 token → 更新配置文件 → 重试请求
└── 仍失败 → 返回 authentication_required → 引导 CLI login
向后兼容: 所有命令仍支持 --token 参数,现有调用方式不受影响。
首次交互前,在解析 ${SKILL_ROOT} / ${PYTHON} 后执行:
bash
${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py check
关键项失败时 STOP,可选项失败时降级运行并告知用户。
若 ${PYTHON} 解析失败( info --json 的 python.ok 为 false),说明本机没有可用的 Python 3.10+, STOP 并原样向用户展示:
text
当前电脑没有可用的 Python(需要 3.10 或更高版本)。请先安装 Python:
- macOS: brew install python
- Ubuntu/Debian: sudo apt install python3 python3-pip
- Fedora: sudo dnf install python3
- Windows: 到 https://www.python.org/downloads/ 下载安装包,安装时勾选 "Add Python to PATH"
安装完成后请回来继续提问,我接着帮你处理。
若 checks.credentials.ok 为 false,展示 Section 2 固定引导文案, 禁止 继续调用 API 或向用户索要 secret。
HTTP处理200正常处理400检查参数格式后重试401/403STOP,展示 CLI login 引导文案, 禁止 向用户索要 secret脚本找不到 / ENOENTSTOP,执行 status --json 或 info --json 解析 ${SKILL_ROOT}, 禁止 乱试 npx 子命令404确认设备 SN/别名429限流,等待后重试500指数退避重试 3 次
脚本返回 "success": false 且 error 为 authentication_required 时,展示 Section 2 固定引导文案并 STOP。其他错误解析 error/ message 字段:含"范围/限制"则解释护栏,否则展示友好错误。
page starts at 1.{node_name: {parameter_code: value}}alias./description endpoint for display.${PYTHON} ${SKILL_ROOT}/scripts/insentek_cli.py; ${SKILL_ROOT} 和 ${PYTHON} 由 info --json 解析( runtimes[].scopes[] 中 installed: true 的条目对应 installDir / scripts.cli / python.command)--dry-run for preview; never output raw data to chat.reference/api-doc.md (OpenAPI v3.1.9).