{"id":50553629,"url":"https://github.com/piexian/astrbot_plugin_kimi_datasource_api","last_synced_at":"2026-06-04T05:04:03.868Z","repository":{"id":360884828,"uuid":"1251941433","full_name":"piexian/astrbot_plugin_kimi_datasource_api","owner":"piexian","description":"为 AstrBot LLM 提供 Kimi datasource 专业数据库工具。通过自然语言即可完成查询与分析，无需手动调用接口。","archived":false,"fork":false,"pushed_at":"2026-05-28T08:14:40.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-05-28T10:15:04.567Z","etag":null,"topics":["astrbot-plugin","kimi-code"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/piexian.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-28T03:35:07.000Z","updated_at":"2026-05-28T08:14:44.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/piexian/astrbot_plugin_kimi_datasource_api","commit_stats":null,"previous_names":["piexian/astrbot_plugin_kimi_datasource_api"],"tags_count":null,"template":false,"template_full_name":"Soulter/helloworld","purl":"pkg:github/piexian/astrbot_plugin_kimi_datasource_api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piexian%2Fastrbot_plugin_kimi_datasource_api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piexian%2Fastrbot_plugin_kimi_datasource_api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piexian%2Fastrbot_plugin_kimi_datasource_api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piexian%2Fastrbot_plugin_kimi_datasource_api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piexian","download_url":"https://codeload.github.com/piexian/astrbot_plugin_kimi_datasource_api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piexian%2Fastrbot_plugin_kimi_datasource_api/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33890052,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-04T02:00:06.755Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["astrbot-plugin","kimi-code"],"created_at":"2026-06-04T05:04:02.833Z","updated_at":"2026-06-04T05:04:03.861Z","avatar_url":"https://github.com/piexian.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kimi Datasource API (astrbot_plugin_kimi_datasource_api)\n\n为 AstrBot LLM 提供 Kimi datasource 专业数据库工具。\n\n## 环境要求\n\n| 依赖 | 版本要求 | 说明 |\n|------|----------|------|\n| Python | \u003e= 3.10 | |\n| AstrBot | \u003e= v4.9.2 | 指令、插件 KV 与 LLM Tool |\n| aiohttp | \u003e= 3.9 | HTTP 客户端 |\n\n**平台支持**: 可能是全平台？\n\n## 功能\n\n- `kimi help` 指令 - 查看 Kimi datasource 指令帮助\n- `kimi login [账号ID]` 指令 - 管理员发起 Kimi Code OAuth device-code 登录\n- `kimi import-local [账号ID]` 指令 - 管理员导入本机已登录的 Kimi Code 凭证（Linux / macOS / Windows）\n- `kimi status` 指令 - 查看全部账号状态、token 过期时间和脱敏 token\n- `kimi refresh [账号ID]` 指令 - 管理员强制刷新指定账号，未指定时刷新全部有效账号\n- `kimi logout \u003c账号ID|--all\u003e` 指令 - 管理员删除指定或全部 Kimi OAuth 账号\n- 多 OAuth 轮转 - LLM Tool 调用时在有效账号间轮转，失效账号自动跳过\n- 内置 Skill (`kimi-datasource`) - 引导模型优先使用 datasource 工具查询财经、宏观、企业和学术数据\n- LLM Tool (`query_stock`) - 查询最多 3 个股票代码的实时价格、技术指标、开盘/收盘摘要\n- LLM Tool (`get_data_source_desc`) - 获取 Kimi datasource 的当前 API 文档\n- LLM Tool (`call_data_source_tool`) - 按 datasource 文档调用具体 API\n- LLM Tool (`moonshot_search`) - 通过 Kimi Code Moonshot search 使用 Kimi OAuth 执行网页检索\n- LLM Tool (`moonshot_fetch`) - 通过 Kimi Code Moonshot fetch 抓取 URL 正文，远端失败时本地兜底\n- 自动 refresh - tool 调用前自动检查并刷新即将过期的 access token\n- 响应文件落盘 - 将上游 `response.files` 安全保存到插件数据目录\n\n## 安装\n\n### 两种方式\n\n1. 在 AstrBot 插件市场搜索 `Kimi Datasource API` 点击安装\n2. 在插件界面右下角点击加号选择从链接安装，输入本仓库地址\n\n## 配置\n\n### OAuth 登录设置\n\n| 配置项 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `oauth_host` | string | 否 | Kimi OAuth 服务地址（默认: https://auth.kimi.com） |\n| `login_timeout_seconds` | int | 否 | 设备码登录总等待时间（默认: 900 秒） |\n\n### 连接设置\n\n| 配置项 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `request_timeout_seconds` | int | 否 | 单次 OAuth / datasource HTTP 请求超时（默认: 30 秒） |\n| `proxy` | string | 否 | HTTP 代理地址（例如: http://127.0.0.1:7890） |\n\n### Datasource 设置\n\n| 配置项 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `api_url` | string | 否 | Kimi datasource API endpoint（默认: https://api.kimi.com/coding/v1/tools） |\n| `response_parse_mode` | string | 否 | 响应解析模式：`official` / `legacy_zip`（默认: official） |\n| `save_response_files` | bool | 否 | 保存上游 `response.files` 到插件数据目录（默认: true） |\n\n### 账号设置\n\n| 配置项 | 类型 | 必填 | 说明 |\n|--------|------|------|------|\n| `account_ids` | list | 否 | 已登录账号 ID。登录成功后自动追加；从列表删除 ID 并保存配置后，插件会删除对应 OAuth 账号。 |\n\n## 使用\n\n### 登录\n\n管理员发送。命令前缀取决于 AstrBot 的 `wake_prefix` 配置，下面按常见默认前缀 `/` 举例：\n\n```text\n/kimi login\n/kimi login my-account\n/kimi import-local\n/kimi import-local local-kimi\n```\n\n插件会返回 Kimi 授权链接、备用验证码和剩余时间。用户在浏览器完成授权后无需再发消息，插件会后台轮询并自动保存凭证。未指定账号 ID 时会自动分配 `account-N`。\n\n如果运行 AstrBot 的同一系统用户已经登录过 Kimi Code，可以直接执行 `kimi import-local [账号ID]` 导入本地凭证。未指定账号 ID 时默认写入 `local-kimi-code`。\n\n`kimi import-local` 会按顺序检查这些位置：\n\n- `KIMI_CODE_HOME` 或 `KIMI_HOME` 指向的目录\n- Linux: `~/.kimi-code`\n- macOS: `~/Library/Application Support/kimi-code`、`~/Library/Application Support/Kimi Code`\n- Windows: `%APPDATA%\\kimi-code`、`%APPDATA%\\Kimi Code`、`%LOCALAPPDATA%\\kimi-code`、`%LOCALAPPDATA%\\Kimi Code`、`%USERPROFILE%\\.kimi-code`\n\n每个目录下都期待存在 `credentials/kimi-code.json`，如果同目录下存在 `device_id` 也会一并导入。\n\n登录期间可发送：\n\n```text\ncancel\n状态\n```\n\n重复执行 `kimi login` 会返回当前待授权链接；需要重新发起时使用：\n\n```text\n/kimi login --restart\n```\n\n### 状态、刷新和退出\n\n```text\n/kimi help\n/kimi status\n/kimi import-local local-kimi\n/kimi refresh\n/kimi refresh my-account\n/kimi logout my-account\n/kimi logout --all\n```\n\n状态输出只显示脱敏 token。登录成功后，配置文件的 `account_settings.account_ids` 会展示已登录账号 ID；在配置列表里删除某个 ID 并保存后，插件会在初始化、指令执行或工具调用前同步删除对应 KV 凭证。\n\n### 多账号轮转\n\n多个账号登录后，LLM Tool 调用会按账号 ID 轮转选择有效账号。某个账号 refresh 失败或 datasource 返回 401/403 时会标记为 `revoked` 并跳过，继续尝试下一个有效账号。\n\n### 内置 Skill\n\n插件随包提供只读 Skill：`kimi-datasource`。用于提示模型在下列场景优先调用本插件的 datasource tools，而不是直接泛化联网搜索：\n\n- 股票、财报、估值指标、公司分部、股价历史、期权和持仓\n- World Bank 宏观经济与社会指标\n- 天眼查企业工商、股东、司法风险、知识产权和经营数据\n- arXiv / Scholar 论文检索和作者信息\n\n### LLM Tool\n\n插件会注册三个 datasource 工具和两个 Kimi 网页工具；是否允许模型调用工具由 AstrBot 内部工具控制负责。\nMoonshot 网页工具复用同一套 OAuth 账号池和设备头。\n\n| 工具名 | 用途 |\n|--------|------|\n| `query_stock` | 查询实时股票数据，最多 3 个 ticker |\n| `get_data_source_desc` | 调用具体 datasource API 前获取当前 API 文档 |\n| `call_data_source_tool` | 按文档调用具体 datasource API |\n| `moonshot_search` | 调用 Kimi Code Moonshot search，支持结果数量和页面内容抓取开关 |\n| `moonshot_fetch` | 调用 Kimi Code Moonshot fetch 抓取 URL 正文，远端失败时回落到本地抓取 |\n\n典型流程是先调用 `get_data_source_desc` 获取数据源文档，再调用 `call_data_source_tool`。\n网页检索和 URL 正文展开直接调用 `moonshot_search` / `moonshot_fetch`。\n\n\n## 项目结构\n\n```text\nastrbot_plugin_kimi_datasource_api/\n├── main.py              # 插件入口\n├── oauth.py             # 登录流程\n├── datasource.py        # datasource API\n├── moonshot.py          # Kimi search / fetch\n├── storage.py           # 插件 KV 凭证结构、设备 ID 与脱敏\n├── identity.py          # 设备身份头\n├── schemas.py           # 工具 schema\n├── sessions.py          # 待登录会话状态\n├── tool_defs.py         # llm工具\n├── skills/\n│   └── kimi-datasource/\n│       └── SKILL.md     # 指导模型优先使用 datasource\n├── metadata.yaml        # 插件元数据\n├── _conf_schema.json    # 配置项\n├── CHANGELOG.md         # 版本日志\n└── README.md\n```\n\n## 相关链接\n\n- [AstrBot](https://docs.astrbot.app/)\n- [AstrBot 插件开发文档](https://docs.astrbot.app/dev/star/plugin-new.html)\n- [Kimi Code](https://github.com/MoonshotAI/kimi-code)\n\n## 许可\n\nAGPL-3.0 License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiexian%2Fastrbot_plugin_kimi_datasource_api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiexian%2Fastrbot_plugin_kimi_datasource_api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiexian%2Fastrbot_plugin_kimi_datasource_api/lists"}