MCPcopy Create free account
hub / github.com/allocnode/oh-my-sage / formatGraphListMarkdown

Function formatGraphListMarkdown

src/mcp/utils.ts:144–176  ·  view source on GitHub ↗
(graphs: Array<{
  name: string;
  id: string;
  enable?: boolean;
  updateTime?: number;
}>)

Source from the content-addressed store, hash-verified

142 }
143 }
144
145 return lines.join("\n");
146}
147
148/**
149 * 处理错误信息
150 */
151export function handleError(error: unknown, context: string): string {
152 const msg = error instanceof Error ? error.message : String(error);
153 if (msg.includes("timeout")) {
154 return `Error: 请求超时。请检查网关连接或网络状态。(${context})`;
155 }
156 if (msg.includes("not connected") || msg.includes("未连接")) {
157 return `Error: 网关未连接。请先调用 mijia_auth 进行认证。(${context})`;
158 }
159 return `Error: ${msg} (${context})`;
160}
161
162const onlineTag = (online?: boolean): string => (online ? "[在线]" : "[离线]");
163const enableTag = (enable?: boolean): string => (enable ? "[启用]" : "[禁用]");
164
165// ==================== 设备 ====================
166
167/**
168 * 格式化设备列表为 Markdown(每台设备一行)
169 */
170export function formatDeviceListMarkdown(devices: Array<{
171 name: string;
172 did: string;
173 modelName?: string;
174 online?: boolean;
175 roomName?: string;
176}>, count: number): string {
177 const lines = [`## 设备列表(${count} 台)`];
178 for (const device of devices) {
179 lines.push(`- ${device.name} (${device.did}) | ${device.roomName || "未分组"} | ${device.modelName || "未知"} | ${onlineTag(device.online)}`);

Callers 1

registerGraphToolsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected