@vikacg/js-sdk
v1.0.1
Published
VikACG browser SDK
Readme
@vikacg/js-sdk
VikACG 浏览器 SDK,用于初始化维咔 Web 端点并打开对应的 SMP 应用。
VikACG browser SDK for selecting a VikACG web endpoint and opening the related SMP app.
该包面向浏览器运行时。
This package is designed for browser runtime.
安装 / Installation
npm i @vikacg/js-sdk #npm
yarn add @vikacg/js-sdk #yarn
pnpm add @vikacg/js-sdk #pnpm
bun i @vikacg/js-sdk #bun快速开始 / Quick Start
import { createVikACGIncetance } from "@vikacg/js-sdk";
const vikacg = createVikACGIncetance("SMPxxxx");
await vikacg.init();
console.log(vikacg.isRead);
vikacg.openMP({
path: "/pages/index",
query: {
from: "web",
},
});appID 为必填项。传入 xxxx 或 SMPxxxx 都会被规范化为 SMPXXXX。
appID is required. Both xxxx and SMPxxxx are normalized to SMPXXXX.
实例 API / Instance API
createVikACGIncetance(appID, options?)
创建一个 VikACG JS SDK 实例。
Create a VikACG JS SDK instance.
| 参数 Option | 类型 Type | 默认值 Default | 说明 Description |
|---|---|---|---|
| appID | string | - | 必填,VikACG/SMP 应用 ID / Required VikACG/SMP app ID |
vikacg.init(options?)
同时请求所有维咔 Web 端点。第一个成功响应的端点会立即成为 selectedEndpoint,未完成的测速请求会被取消。
Requests all VikACG web endpoints concurrently. The first successful endpoint becomes selectedEndpoint immediately, and pending tests are aborted.
成功后 isRead / isReady 会变为 true。
After success, isRead / isReady becomes true.
vikacg.onReady(callback)
在实例已经准备好时异步触发回调;如果还未准备好,则等待 init() 成功后触发。返回值是取消监听函数。
Runs the callback asynchronously when the instance is already ready, or waits until init() succeeds. Returns an unsubscribe function.
vikacg.openMP(options?)
打开 smp:// 对应 APP,并默认在新标签页打开维咔 Web 启动页。
Opens the matching smp:// app and, by default, opens the VikACG web launcher page in a new tab.
smp:// 会通过当前标签页的 window.location.href 唤起;关联 Web 页面会通过 window.open() 打开。
smp:// is launched through window.location.href in the current tab; the related web page is opened with window.open().
smp://SMPxxxx/path?query
https://selected-vikacg-web-origin/mp/SMPxxxx/path?queryMCP 文档 / MCP Docs
启动 VikACG JS SDK 文档 MCP(Model Context Protocol)服务器,为 AI 编程助手提供 API 文档搜索与查询能力。
Start the VikACG JS SDK documentation MCP (Model Context Protocol) server, providing API doc search and query capabilities for AI coding assistants.
pnpm build
node dist/bin/index.js mcp已安装包的 MCP 配置示例:
MCP configuration for an installed package:
{
"mcpServers": {
"vikacg-js-sdk": {
"command": "vikacg-js-sdk",
"args": ["mcp"]
}
}
}MCP 服务提供以下工具 / The MCP server provides the following tools:
vikacg_search_docs- 按关键词搜索 API 文档 / Search API docs by keywordvikacg_get_doc- 获取指定 API 的详细文档 / Get detailed doc for a specific APIvikacg_list_capabilities- 列出可用的 SDK 能力 / List available SDK capabilities
