pi-nocturne-memory 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extensions/index.ts +30 -5
- package/package.json +1 -1
- package/config.json +0 -3
package/extensions/index.ts
CHANGED
|
@@ -8,21 +8,37 @@ import { homedir } from "node:os";
|
|
|
8
8
|
const CONFIG_PATH = join(homedir(), ".pi", "agent", "extensions", "pi-nocturne-memory", "config.json");
|
|
9
9
|
|
|
10
10
|
function loadConfig(): { mcpUrl?: string; mcpAuth?: string } {
|
|
11
|
+
const env = process.env;
|
|
12
|
+
const result: { mcpUrl?: string; mcpAuth?: string } = {};
|
|
13
|
+
|
|
14
|
+
// Config file takes priority
|
|
11
15
|
try {
|
|
12
|
-
|
|
16
|
+
const fileConfig = JSON.parse(readFileSync(CONFIG_PATH, "utf8"));
|
|
17
|
+
result.mcpUrl = fileConfig.mcpUrl;
|
|
18
|
+
result.mcpAuth = fileConfig.mcpAuth;
|
|
13
19
|
} catch {
|
|
14
|
-
|
|
20
|
+
// use defaults
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Env vars as fallback
|
|
24
|
+
if (!result.mcpUrl && env.NOCTURNE_MCP_URL) {
|
|
25
|
+
result.mcpUrl = env.NOCTURNE_MCP_URL;
|
|
26
|
+
}
|
|
27
|
+
if (!result.mcpAuth && env.NOCTURNE_MCP_AUTH) {
|
|
28
|
+
result.mcpAuth = env.NOCTURNE_MCP_AUTH;
|
|
15
29
|
}
|
|
30
|
+
|
|
31
|
+
return result;
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
const config = loadConfig();
|
|
19
35
|
const MCP_URL = config.mcpUrl;
|
|
20
36
|
const MCP_AUTH = config.mcpAuth;
|
|
21
37
|
if (!MCP_URL) {
|
|
22
|
-
throw new Error("mcpUrl is required in config.json");
|
|
38
|
+
throw new Error("mcpUrl is required (set in config.json or NOCTURNE_MCP_URL env)");
|
|
23
39
|
}
|
|
24
40
|
if (!MCP_AUTH) {
|
|
25
|
-
throw new Error("mcpAuth is required in config.json");
|
|
41
|
+
throw new Error("mcpAuth is required (set in config.json or NOCTURNE_MCP_AUTH env)");
|
|
26
42
|
}
|
|
27
43
|
|
|
28
44
|
const BOOT_URIS = ["system://boot", "system://recent/5", "system://glossary"];
|
|
@@ -72,6 +88,11 @@ async function callMCP(method: string, params: Record<string, unknown>): Promise
|
|
|
72
88
|
body: JSON.stringify({ jsonrpc: "2.0", id: method + Date.now(), method, params }),
|
|
73
89
|
});
|
|
74
90
|
|
|
91
|
+
if (!resp.ok) {
|
|
92
|
+
const body = await resp.text().catch(() => "<unreadable>");
|
|
93
|
+
return { error: { code: resp.status, message: `HTTP ${resp.status}: ${body.slice(0, 200)}` } };
|
|
94
|
+
}
|
|
95
|
+
|
|
75
96
|
// Check for new session ID in response
|
|
76
97
|
const newSid = resp.headers.get("mcp-session-id");
|
|
77
98
|
if (newSid) {
|
|
@@ -113,6 +134,9 @@ async function callMCP(method: string, params: Record<string, unknown>): Promise
|
|
|
113
134
|
}
|
|
114
135
|
|
|
115
136
|
function extractText(data: any): string {
|
|
137
|
+
if (data?.error) {
|
|
138
|
+
return `Error: ${data.error.message ?? JSON.stringify(data.error)}`;
|
|
139
|
+
}
|
|
116
140
|
return data?.result?.content?.[0]?.text ?? "";
|
|
117
141
|
}
|
|
118
142
|
|
|
@@ -175,7 +199,8 @@ export default function (pi: ExtensionAPI): void {
|
|
|
175
199
|
|
|
176
200
|
async execute(_toolCallId, params) {
|
|
177
201
|
const data = await callMCP("tools/call", { name: "read_memory", arguments: { uri: params.uri } });
|
|
178
|
-
|
|
202
|
+
const text = extractText(data);
|
|
203
|
+
return { content: [{ type: "text", text: text || "No content" }] };
|
|
179
204
|
},
|
|
180
205
|
|
|
181
206
|
renderCall(args, theme) {
|
package/package.json
CHANGED
package/config.json
DELETED