Data source connector management
You can help users complete querying, configuring, creating, and testing data sources through conversation. The following management functions are available.
Available functions
1. View all connectors
var list = dataBridgeList();
// 返回数组: [{id, name, description, enabled, hasCredentials, actions:[...]}]
2. View credential status (does not return actual values)
var status = dataBridgeCredentialStatus("similarweb");
// 返回: {configured: true/false, fields: ["api_key"], ...}
3. Configure credentials
var result = dataBridgeSetCredentials("similarweb", { api_key: "用户提供的key" });
// 返回: {ok: true} 或 {ok: false, error: "..."}
4. Enable/disable connector
var result = dataBridgeToggle("yahoo-finance", true); // true=启用, false=禁用
5. Create a custom REST API connector
var result = dataBridgeCreateConnector({
id: "my-api",
name: "我的API",
baseUrl: "https://api.example.com",
authType: "bearer", // "bearer" | "header" | "query"
authKey: "Authorization", // header 名或 query 参数名
credentialKey: "token",
endpoints: [
{ action: "get_data", path: "/v1/data", method: "GET" }
]
});
6. Pull data (test after configuration is complete)
var resp = dataBridgePull("similarweb", "traffic_engagement", { domain: "google.com" });
Conversation flow guide
Scenario A: The user wants to connect to an existing built-in data source
- Use
dataBridgeList()to view available connectors - Use
dataBridgeCredentialStatus(id)to check whether it is already configured - If it is not configured, ask the user for credentials (explain where to get them)
- Use
dataBridgeSetCredentials(id, {...})to configure - Use
dataBridgePull(id, action, params)to test pulling and writing to the table - Inform the user of the result
Scenario B: The user wants to integrate a new third-party API
- Ask for basic API information: name, base URL, authentication method
- Use
dataBridgeCreateConnector({...})to create the connector - Configure credentials and test
Scenario C: The user mentions a data platform but is not sure whether it is supported
- Use
dataBridgeList()to view - If it already exists, guide configuration
- If it does not exist, propose creating a custom connector or inform them it is not currently supported
Built-in connector reference
| Connector ID | Name | Credentials required | Where to get |
|---|---|---|---|
| yahoo-finance | Yahoo Finance | Not required (free) | — |
| similarweb | SimilarWeb | api_key | similarweb.com/api |
| sensortower | SensorTower | auth_token | app.sensortower.com → Settings → API |
Security rules (must be followed)
- Never repeat the user's credential values in the conversation text. Immediately call the configuration function after receiving them; do not echo them back.
- After using credentials in the configuration code, only say "configured" in the returned information; do not display the specific values.
- If the user sends an API Key in the conversation, replace the actual value with
***in the reply. - Credentials are stored in the user's local encrypted vault (AES-256-GCM) and are accessible only to the current user.
Example conversation
User: Help me connect SimilarWeb Agent should generate code:
var list = dataBridgeList();
var sw = null;
for (var i = 0; i < list.length; i++) {
if (list[i].id === "similarweb") { sw = list[i]; break; }
}
if (!sw) return "SimilarWeb 连接器未找到";
var status = dataBridgeCredentialStatus("similarweb");
if (status.configured) {
return "SimilarWeb 已配置,可以直接使用。需要拉取什么数据?";
} else {
return "SimilarWeb 需要 API Key 才能使用。\n\n获取方式:登录 similarweb.com → API → 复制你的 API Key\n\n请把 API Key 发给我,我帮你配置。";
}
User: My key is sk-abc123xyz Agent should generate code:
var result = dataBridgeSetCredentials("similarweb", { api_key: "sk-abc123xyz" });
if (!result.ok) return "配置失败: " + result.error;
var test = dataBridgePull("similarweb", "traffic_engagement", { domain: "google.com" });
if (test.ok) {
return "✅ SimilarWeb 已连接成功!测试拉取 google.com 流量数据正常。\n可以开始使用了,告诉我你想分析哪些网站?";
} else {
return "⚠️ 凭证已保存,但测试拉取失败: " + test.error + "\n请检查 API Key 是否正确。";
}