@roam-research/roam-tools-core 0.5.1 → 0.6.1
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/README.md +23 -8
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/operations/blocks.d.ts +21 -22
- package/dist/operations/blocks.d.ts.map +1 -1
- package/dist/operations/datalog.d.ts +2 -3
- package/dist/operations/datalog.d.ts.map +1 -1
- package/dist/operations/files.d.ts +6 -7
- package/dist/operations/files.d.ts.map +1 -1
- package/dist/operations/navigation.d.ts +9 -10
- package/dist/operations/navigation.d.ts.map +1 -1
- package/dist/operations/pages.d.ts +10 -11
- package/dist/operations/pages.d.ts.map +1 -1
- package/dist/operations/query.d.ts +10 -11
- package/dist/operations/query.d.ts.map +1 -1
- package/dist/operations/search.d.ts +7 -8
- package/dist/operations/search.d.ts.map +1 -1
- package/dist/tools.d.ts +37 -4
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +47 -52
- package/dist/types.d.ts +17 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -0
- package/package.json +7 -10
- package/dist/client.d.ts +0 -34
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -275
- package/dist/connect.d.ts +0 -10
- package/dist/connect.d.ts.map +0 -1
- package/dist/connect.js +0 -475
- package/dist/graph-resolver.d.ts +0 -54
- package/dist/graph-resolver.d.ts.map +0 -1
- package/dist/graph-resolver.js +0 -339
- package/dist/operations/graphs.d.ts +0 -26
- package/dist/operations/graphs.d.ts.map +0 -1
- package/dist/operations/graphs.js +0 -213
- package/dist/roam-api.d.ts +0 -32
- package/dist/roam-api.d.ts.map +0 -1
- package/dist/roam-api.js +0 -50
package/dist/tools.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { RoamError } from "./types.js";
|
|
3
|
-
import { RoamClient } from "./client.js";
|
|
4
|
-
import { resolveGraph, getPort, updateGraphTokenStatus } from "./graph-resolver.js";
|
|
5
3
|
import { CreatePageSchema, GetPageSchema, DeletePageSchema, UpdatePageSchema, GetGuidelinesSchema, createPage, getPage, deletePage, updatePage, getGuidelines, } from "./operations/pages.js";
|
|
6
4
|
import { CreateBlockSchema, GetBlockSchema, UpdateBlockSchema, DeleteBlockSchema, MoveBlockSchema, GetBacklinksSchema, AddCommentSchema, GetCommentsSchema, createBlock, getBlock, updateBlock, deleteBlock, moveBlock, getBacklinks, addComment, getComments, } from "./operations/blocks.js";
|
|
7
5
|
import { SearchSchema, SearchTemplatesSchema, search, searchTemplates, } from "./operations/search.js";
|
|
@@ -9,7 +7,6 @@ import { QuerySchema, query } from "./operations/query.js";
|
|
|
9
7
|
import { DatalogQuerySchema, datalogQuery } from "./operations/datalog.js";
|
|
10
8
|
import { GetOpenWindowsSchema, GetSelectionSchema, OpenMainWindowSchema, OpenSidebarSchema, getOpenWindows, getSelection, openMainWindow, openSidebar, } from "./operations/navigation.js";
|
|
11
9
|
import { FileGetSchema, FileUploadSchema, FileDeleteSchema, getFile, uploadFile, deleteFile, } from "./operations/files.js";
|
|
12
|
-
import { ListGraphsSchema, SetupNewGraphSchema, listGraphs, setupNewGraph, } from "./operations/graphs.js";
|
|
13
10
|
// Common schema for graph parameter (used by most tools)
|
|
14
11
|
const GraphSchema = z.object({
|
|
15
12
|
graph: z
|
|
@@ -22,7 +19,7 @@ function withGraph(schema) {
|
|
|
22
19
|
return schema.extend(GraphSchema.shape);
|
|
23
20
|
}
|
|
24
21
|
// Helper to create tool with graph parameter
|
|
25
|
-
function defineTool(name, description, schema, action) {
|
|
22
|
+
export function defineTool(name, description, schema, action) {
|
|
26
23
|
return {
|
|
27
24
|
name,
|
|
28
25
|
description,
|
|
@@ -32,7 +29,7 @@ function defineTool(name, description, schema, action) {
|
|
|
32
29
|
};
|
|
33
30
|
}
|
|
34
31
|
// Helper to create standalone tool (no graph parameter, handles its own resolution)
|
|
35
|
-
function defineStandaloneTool(name, description, schema, action) {
|
|
32
|
+
export function defineStandaloneTool(name, description, schema, action) {
|
|
36
33
|
return {
|
|
37
34
|
name,
|
|
38
35
|
description,
|
|
@@ -41,15 +38,10 @@ function defineStandaloneTool(name, description, schema, action) {
|
|
|
41
38
|
type: "standalone",
|
|
42
39
|
};
|
|
43
40
|
}
|
|
44
|
-
// Graph Management Tools (standalone - handle their own resolution)
|
|
45
|
-
const graphManagementTools = [
|
|
46
|
-
defineStandaloneTool("list_graphs", "List all configured graphs with their nicknames. Also provides setup instructions for connecting additional graphs.", ListGraphsSchema, listGraphs),
|
|
47
|
-
defineStandaloneTool("setup_new_graph", "Set up a new Roam graph for access, or list available graphs. Call without arguments to see which graphs are available in Roam Desktop. Call with graph and nickname to connect a specific graph — ask the user what they'd like to call the graph before choosing a nickname. The user will see an approval dialog in Roam desktop app and must approve the token request. If the graph is already configured, returns the existing configuration without making changes.", SetupNewGraphSchema, setupNewGraph),
|
|
48
|
-
];
|
|
49
41
|
// Note appended to all client tool descriptions
|
|
50
42
|
const GUIDELINES_NOTE = "\n\nNote: Call get_graph_guidelines first when starting to work with a graph.";
|
|
51
|
-
//
|
|
52
|
-
const
|
|
43
|
+
// Data Tools (require graph/client; reusable across local + hosted MCP transports)
|
|
44
|
+
export const dataTools = [
|
|
53
45
|
defineTool("get_graph_guidelines", "IMPORTANT: Call this tool first when starting to work with a graph, before performing any other operations. Returns user-defined instructions and preferences for AI agents. The user may have specified naming conventions, preferred structures, or constraints that should guide your behavior. After receiving the response, follow the nextSteps field — it contains orientation actions you should take before proceeding.", GetGuidelinesSchema, getGuidelines),
|
|
54
46
|
defineTool("create_page", "Create a new page in Roam, optionally with markdown content." + GUIDELINES_NOTE, CreatePageSchema, createPage),
|
|
55
47
|
defineTool("create_block", "Create blocks from markdown content. Target by parentUid, pageTitle, or dailyNotePage (page created if needed). Use nestUnder to insert under a specific child block. Supports nested bulleted lists via markdown indentation." +
|
|
@@ -78,6 +70,10 @@ const contentTools = [
|
|
|
78
70
|
GUIDELINES_NOTE, GetBlockSchema, getBlock),
|
|
79
71
|
defineTool("get_backlinks", "Get paginated backlinks (linked references) for a page or block, formatted as markdown. Returns total count and results with optional breadcrumb paths." +
|
|
80
72
|
GUIDELINES_NOTE, GetBacklinksSchema, getBacklinks),
|
|
73
|
+
];
|
|
74
|
+
// Desktop UI Tools (require local Roam Desktop — file ops + window/selection introspection;
|
|
75
|
+
// hosted MCP omits these because the parameters/effects assume a local environment).
|
|
76
|
+
export const desktopUiTools = [
|
|
81
77
|
defineTool("get_open_windows", "Get the current view in the main window and all open sidebar windows." + GUIDELINES_NOTE, GetOpenWindowsSchema, getOpenWindows),
|
|
82
78
|
defineTool("get_selection", "Get the currently focused block and any multi-selected blocks." + GUIDELINES_NOTE, GetSelectionSchema, getSelection),
|
|
83
79
|
defineTool("open_main_window", "Navigate to a page or block in the main window." + GUIDELINES_NOTE, OpenMainWindowSchema, openMainWindow),
|
|
@@ -87,7 +83,12 @@ const contentTools = [
|
|
|
87
83
|
GUIDELINES_NOTE, FileUploadSchema, uploadFile),
|
|
88
84
|
defineTool("file_delete", "Delete a file hosted on Roam." + GUIDELINES_NOTE, FileDeleteSchema, deleteFile),
|
|
89
85
|
];
|
|
90
|
-
|
|
86
|
+
// Backwards-compatible aggregate of all client tools.
|
|
87
|
+
export const contentTools = [...dataTools, ...desktopUiTools];
|
|
88
|
+
// All client tools available in core. Local standalone tools (list_graphs,
|
|
89
|
+
// setup_new_graph) live in @roam-research/roam-tools-local since they touch
|
|
90
|
+
// ~/.roam-tools.json and the Roam Desktop API.
|
|
91
|
+
export const tools = [...dataTools, ...desktopUiTools];
|
|
91
92
|
export function findTool(name) {
|
|
92
93
|
return tools.find((t) => t.name === name);
|
|
93
94
|
}
|
|
@@ -167,46 +168,40 @@ function roamErrorResult(error) {
|
|
|
167
168
|
isError: true,
|
|
168
169
|
};
|
|
169
170
|
}
|
|
170
|
-
export async function routeToolCall(toolName, args) {
|
|
171
|
+
export async function routeToolCall(toolName, args, options) {
|
|
171
172
|
const tool = findTool(toolName);
|
|
172
173
|
if (!tool) {
|
|
173
174
|
throw new Error(`Unknown tool: ${toolName}`);
|
|
174
175
|
}
|
|
176
|
+
// Core only registers client tools. Standalone tools live in
|
|
177
|
+
// @roam-research/roam-tools-local; route them through that wrapper.
|
|
178
|
+
if (tool.type !== "client") {
|
|
179
|
+
throw new Error(`Tool ${toolName}: core's routeToolCall only handles client tools. ` +
|
|
180
|
+
`Standalone tools live in @roam-research/roam-tools-local.`);
|
|
181
|
+
}
|
|
175
182
|
// Validate and parse args with Zod
|
|
176
183
|
const parsed = tool.schema.safeParse(args);
|
|
177
184
|
if (!parsed.success) {
|
|
178
185
|
throw new Error(`Invalid arguments: ${parsed.error.message}`);
|
|
179
186
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
return await tool.action(parsed.data);
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
if (error instanceof RoamError) {
|
|
187
|
-
return roamErrorResult(error);
|
|
188
|
-
}
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// Handle client tools (require graph resolution)
|
|
187
|
+
const tokenInfoMode = options.tokenInfoMode ?? "skip";
|
|
188
|
+
const updateTokenStatus = options.onTokenStatusUpdate;
|
|
193
189
|
try {
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (tool.name === "get_graph_guidelines") {
|
|
190
|
+
const { graph: graphArg, ...restArgs } = parsed.data;
|
|
191
|
+
const graph = await options.resolveGraph(graphArg);
|
|
192
|
+
const client = await options.createClient(graph);
|
|
193
|
+
// Special handling for get_graph_guidelines: sync token info in parallel.
|
|
194
|
+
// Only fires in local-sync mode AND when the client implements getTokenInfo.
|
|
195
|
+
// Bind early so TS narrows the optional method through the truthy check.
|
|
196
|
+
const getTokenInfoFn = client.getTokenInfo?.bind(client);
|
|
197
|
+
if (tool.name === "get_graph_guidelines" && tokenInfoMode === "local-sync" && getTokenInfoFn) {
|
|
198
|
+
// In local-sync mode, the resolver is expected to return ResolvedGraph
|
|
199
|
+
// (with lastKnownTokenStatus). If a custom resolver omits the field,
|
|
200
|
+
// the read returns undefined and behavior is identical.
|
|
201
|
+
const resolvedGraph = graph;
|
|
207
202
|
const [actionSettled, tokenInfoSettled] = await Promise.allSettled([
|
|
208
203
|
tool.action(client, restArgs),
|
|
209
|
-
|
|
204
|
+
getTokenInfoFn(),
|
|
210
205
|
]);
|
|
211
206
|
// getTokenInfo() never throws, so always fulfilled
|
|
212
207
|
const tokenInfoResult = tokenInfoSettled.status === "fulfilled"
|
|
@@ -214,9 +209,9 @@ export async function routeToolCall(toolName, args) {
|
|
|
214
209
|
: { status: "unknown" };
|
|
215
210
|
// Handle revoked token FIRST (before examining action result)
|
|
216
211
|
if (tokenInfoResult.status === "revoked") {
|
|
217
|
-
if (resolvedGraph.lastKnownTokenStatus !== "revoked") {
|
|
212
|
+
if (updateTokenStatus && resolvedGraph.lastKnownTokenStatus !== "revoked") {
|
|
218
213
|
try {
|
|
219
|
-
await
|
|
214
|
+
await updateTokenStatus(resolvedGraph.nickname, {
|
|
220
215
|
lastKnownTokenStatus: "revoked",
|
|
221
216
|
});
|
|
222
217
|
}
|
|
@@ -238,17 +233,17 @@ export async function routeToolCall(toolName, args) {
|
|
|
238
233
|
const result = actionSettled.value;
|
|
239
234
|
if (tokenInfoResult.status === "active") {
|
|
240
235
|
const info = tokenInfoResult.info;
|
|
241
|
-
// Validate access level before writing to prevent
|
|
236
|
+
// Validate access level before writing to prevent status corruption
|
|
242
237
|
const validLevels = ["read-only", "read-append", "full"];
|
|
243
238
|
const level = validLevels.includes(info.grantedAccessLevel)
|
|
244
239
|
? info.grantedAccessLevel
|
|
245
240
|
: undefined;
|
|
246
|
-
// Only write
|
|
241
|
+
// Only write if something actually changed
|
|
247
242
|
const accessLevelChanged = level && resolvedGraph.accessLevel !== level;
|
|
248
243
|
const tokenStatusChanged = resolvedGraph.lastKnownTokenStatus !== "active";
|
|
249
|
-
if (accessLevelChanged || tokenStatusChanged) {
|
|
244
|
+
if (updateTokenStatus && (accessLevelChanged || tokenStatusChanged)) {
|
|
250
245
|
try {
|
|
251
|
-
await
|
|
246
|
+
await updateTokenStatus(resolvedGraph.nickname, {
|
|
252
247
|
...(accessLevelChanged ? { accessLevel: level } : {}),
|
|
253
248
|
lastKnownTokenStatus: "active",
|
|
254
249
|
});
|
|
@@ -264,9 +259,9 @@ export async function routeToolCall(toolName, args) {
|
|
|
264
259
|
return result;
|
|
265
260
|
}
|
|
266
261
|
// status === "unknown" — action succeeded, so token isn't revoked; clear stale status
|
|
267
|
-
if (resolvedGraph.lastKnownTokenStatus !== "active") {
|
|
262
|
+
if (updateTokenStatus && resolvedGraph.lastKnownTokenStatus !== "active") {
|
|
268
263
|
try {
|
|
269
|
-
await
|
|
264
|
+
await updateTokenStatus(resolvedGraph.nickname, { lastKnownTokenStatus: "active" });
|
|
270
265
|
}
|
|
271
266
|
catch {
|
|
272
267
|
// best-effort status update
|
|
@@ -277,11 +272,11 @@ export async function routeToolCall(toolName, args) {
|
|
|
277
272
|
}
|
|
278
273
|
return result;
|
|
279
274
|
}
|
|
280
|
-
// Normal flow for all other tools
|
|
275
|
+
// Normal flow for all other tools (and get_graph_guidelines when token-info
|
|
276
|
+
// sync is skipped or unavailable). Graph-name prefix runs in both modes.
|
|
281
277
|
const result = await tool.action(client, restArgs);
|
|
282
|
-
// Prepend graph info to successful responses
|
|
283
278
|
if (!result.isError) {
|
|
284
|
-
return prependGraphInfo(result,
|
|
279
|
+
return prependGraphInfo(result, graph.nickname);
|
|
285
280
|
}
|
|
286
281
|
return result;
|
|
287
282
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -14,8 +14,8 @@ export declare const GraphConfigSchema: z.ZodObject<{
|
|
|
14
14
|
accessLevel: z.ZodOptional<z.ZodEnum<["read-only", "read-append", "full"]>>;
|
|
15
15
|
lastKnownTokenStatus: z.ZodOptional<z.ZodEnum<["active", "revoked"]>>;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
|
-
type: "hosted" | "offline";
|
|
18
17
|
name: string;
|
|
18
|
+
type: "hosted" | "offline";
|
|
19
19
|
token: string;
|
|
20
20
|
nickname: string;
|
|
21
21
|
accessLevel?: "read-only" | "read-append" | "full" | undefined;
|
|
@@ -39,8 +39,8 @@ export declare const RoamMcpConfigSchema: z.ZodObject<{
|
|
|
39
39
|
accessLevel: z.ZodOptional<z.ZodEnum<["read-only", "read-append", "full"]>>;
|
|
40
40
|
lastKnownTokenStatus: z.ZodOptional<z.ZodEnum<["active", "revoked"]>>;
|
|
41
41
|
}, "strip", z.ZodTypeAny, {
|
|
42
|
-
type: "hosted" | "offline";
|
|
43
42
|
name: string;
|
|
43
|
+
type: "hosted" | "offline";
|
|
44
44
|
token: string;
|
|
45
45
|
nickname: string;
|
|
46
46
|
accessLevel?: "read-only" | "read-append" | "full" | undefined;
|
|
@@ -55,8 +55,8 @@ export declare const RoamMcpConfigSchema: z.ZodObject<{
|
|
|
55
55
|
}>, "many">;
|
|
56
56
|
}, "strip", z.ZodTypeAny, {
|
|
57
57
|
graphs: {
|
|
58
|
-
type: "hosted" | "offline";
|
|
59
58
|
name: string;
|
|
59
|
+
type: "hosted" | "offline";
|
|
60
60
|
token: string;
|
|
61
61
|
nickname: string;
|
|
62
62
|
accessLevel?: "read-only" | "read-append" | "full" | undefined;
|
|
@@ -75,12 +75,15 @@ export declare const RoamMcpConfigSchema: z.ZodObject<{
|
|
|
75
75
|
version?: number | undefined;
|
|
76
76
|
}>;
|
|
77
77
|
export type RoamMcpConfig = z.infer<typeof RoamMcpConfigSchema>;
|
|
78
|
-
export interface
|
|
78
|
+
export interface ToolGraph {
|
|
79
79
|
name: string;
|
|
80
80
|
type: GraphType;
|
|
81
|
-
token: string;
|
|
82
81
|
nickname: string;
|
|
83
82
|
accessLevel?: AccessLevel;
|
|
83
|
+
token?: string;
|
|
84
|
+
}
|
|
85
|
+
export interface ResolvedGraph extends ToolGraph {
|
|
86
|
+
token: string;
|
|
84
87
|
lastKnownTokenStatus?: "active" | "revoked";
|
|
85
88
|
}
|
|
86
89
|
export declare const ErrorCodes: {
|
|
@@ -104,6 +107,12 @@ export declare const ErrorCodes: {
|
|
|
104
107
|
readonly GRAPH_NOT_SELECTED: "GRAPH_NOT_SELECTED";
|
|
105
108
|
readonly CONNECTION_FAILED: "CONNECTION_FAILED";
|
|
106
109
|
readonly CONFIG_TOO_NEW: "CONFIG_TOO_NEW";
|
|
110
|
+
readonly MISSING_AUTH: "MISSING_AUTH";
|
|
111
|
+
readonly INSUFFICIENT_PERMISSION: "INSUFFICIENT_PERMISSION";
|
|
112
|
+
readonly NOT_IMPLEMENTED: "NOT_IMPLEMENTED";
|
|
113
|
+
readonly GRAPH_UNSUPPORTED: "GRAPH_UNSUPPORTED";
|
|
114
|
+
readonly ACTION_NOT_AVAILABLE: "ACTION_NOT_AVAILABLE";
|
|
115
|
+
readonly PEER_NOT_READY: "PEER_NOT_READY";
|
|
107
116
|
};
|
|
108
117
|
export type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
109
118
|
export declare class RoamError extends Error {
|
|
@@ -277,10 +286,8 @@ export type TokenInfoResult = {
|
|
|
277
286
|
} | {
|
|
278
287
|
status: "unknown";
|
|
279
288
|
};
|
|
280
|
-
export interface
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
token: string;
|
|
284
|
-
port?: number;
|
|
289
|
+
export interface RoamActionClient {
|
|
290
|
+
call<T = unknown>(action: string, args?: unknown[]): Promise<RoamResponse<T>>;
|
|
291
|
+
getTokenInfo?(): Promise<TokenInfoResult>;
|
|
285
292
|
}
|
|
286
293
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,CAGzD;AAGD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,CAE1E;AAGD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,CAE3D;AAOD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,SAAS,CAAC;AAG7C,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,aAAa,GAAG,MAAM,CAAC;AAM/D,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;EAsB5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,wBAAgB,UAAU,CAAC,KAAK,EAA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AAI,EAAE,iBAAiB,CAAA;CAAE,GAC7C;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAO1B,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,YAAY,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CAC3C"}
|
package/dist/types.js
CHANGED
|
@@ -71,6 +71,15 @@ export const ErrorCodes = {
|
|
|
71
71
|
GRAPH_NOT_SELECTED: "GRAPH_NOT_SELECTED",
|
|
72
72
|
CONNECTION_FAILED: "CONNECTION_FAILED",
|
|
73
73
|
CONFIG_TOO_NEW: "CONFIG_TOO_NEW",
|
|
74
|
+
// Cloud-transport codes — emitted by RoamCloudClient (relemma/functions_v2)
|
|
75
|
+
// against the AWS Clojure backend at proxy.api.roamresearch.com. Local does
|
|
76
|
+
// not emit these today.
|
|
77
|
+
MISSING_AUTH: "MISSING_AUTH", // 401 — WorkOS auth gate failed (no token, malformed token, or signature/issuer/audience invalid). Same agent semantics as MISSING_TOKEN; distinct for operational telemetry across transports.
|
|
78
|
+
INSUFFICIENT_PERMISSION: "INSUFFICIENT_PERMISSION", // 403 — Picker grant existed in RTDB but Roam-side graph access has been revoked since (firebase.graph/readable? or writeable? returned false). Distinct from TOKEN_NOT_FOUND ("never authorized"): INSUFFICIENT_PERMISSION = "ask user to re-grant"; TOKEN_NOT_FOUND = "pick a different graph or grant fresh access".
|
|
79
|
+
NOT_IMPLEMENTED: "NOT_IMPLEMENTED", // 501 — Action recognized in dispatch but handler not yet wired (Phase 3 backlog). Distinct from ACTION_NOT_AVAILABLE: NOT_IMPLEMENTED implies "will work eventually"; ACTION_NOT_AVAILABLE implies "not available on this transport, period".
|
|
80
|
+
GRAPH_UNSUPPORTED: "GRAPH_UNSUPPORTED", // 400 — Encrypted graph rejection (backend can't decrypt). Agent should not retry; instruct user the graph type isn't supported via cloud transport.
|
|
81
|
+
ACTION_NOT_AVAILABLE: "ACTION_NOT_AVAILABLE", // 501 — Action symbol absent from cloud's dispatch entirely (typo OR action like file.upload that's local-only and intentionally not on cloud). Same agent semantics as UNKNOWN_ACTION (which is local-API 404); distinct for operational telemetry across transports.
|
|
82
|
+
PEER_NOT_READY: "PEER_NOT_READY", // 503 — Backend peer instance starting up. Always retryable; reads use exponential backoff (200/400/800ms × 3 attempts) before surfacing; writes throw immediately (non-idempotent).
|
|
74
83
|
};
|
|
75
84
|
// Custom error class with error code and optional context
|
|
76
85
|
export class RoamError extends Error {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roam-research/roam-tools-core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "Transport-agnostic core for Roam Research MCP and CLI tools",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/Roam-Research/roam-tools.git",
|
|
@@ -15,11 +15,6 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"development": "./src/index.ts",
|
|
17
17
|
"import": "./dist/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./connect": {
|
|
20
|
-
"types": "./dist/connect.d.ts",
|
|
21
|
-
"development": "./src/connect.ts",
|
|
22
|
-
"import": "./dist/connect.js"
|
|
23
18
|
}
|
|
24
19
|
},
|
|
25
20
|
"files": [
|
|
@@ -33,12 +28,14 @@
|
|
|
33
28
|
"node": ">=18"
|
|
34
29
|
},
|
|
35
30
|
"scripts": {
|
|
36
|
-
"prepublishOnly": "npm run --prefix ../.. build"
|
|
31
|
+
"prepublishOnly": "npm run --prefix ../.. build",
|
|
32
|
+
"test": "vitest run"
|
|
37
33
|
},
|
|
38
34
|
"dependencies": {
|
|
39
|
-
"@inquirer/prompts": "^8.2.0",
|
|
40
35
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
41
|
-
"open": "^11.0.0",
|
|
42
36
|
"zod": "^3.25.76"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vitest": "^2.1.0"
|
|
43
40
|
}
|
|
44
41
|
}
|
package/dist/client.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { RoamResponse, RoamClientConfig, TokenInfoResult } from "./types.js";
|
|
2
|
-
export declare class RoamClient {
|
|
3
|
-
private graphName;
|
|
4
|
-
private graphType;
|
|
5
|
-
private token;
|
|
6
|
-
private port;
|
|
7
|
-
constructor(config: RoamClientConfig);
|
|
8
|
-
private getPort;
|
|
9
|
-
private openRoamDeepLink;
|
|
10
|
-
private sleep;
|
|
11
|
-
private isConnectionError;
|
|
12
|
-
private isVersionMismatch;
|
|
13
|
-
private handleVersionMismatch;
|
|
14
|
-
/**
|
|
15
|
-
* Get user-friendly guidance for authentication errors
|
|
16
|
-
*/
|
|
17
|
-
private getAuthErrorGuidance;
|
|
18
|
-
/**
|
|
19
|
-
* Get user-friendly guidance for permission errors
|
|
20
|
-
*/
|
|
21
|
-
private getPermissionErrorGuidance;
|
|
22
|
-
/**
|
|
23
|
-
* Handle API error responses based on HTTP status and error code
|
|
24
|
-
*/
|
|
25
|
-
private handleApiError;
|
|
26
|
-
private checkResponse;
|
|
27
|
-
/**
|
|
28
|
-
* Query the token info endpoint for current permissions.
|
|
29
|
-
* Best-effort: returns "unknown" on any failure except confirmed revocation.
|
|
30
|
-
*/
|
|
31
|
-
getTokenInfo(): Promise<TokenInfoResult>;
|
|
32
|
-
call<T = unknown>(action: string, args?: unknown[]): Promise<RoamResponse<T>>;
|
|
33
|
-
}
|
|
34
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAGhB,eAAe,EAEhB,MAAM,YAAY,CAAC;AAGpB,qBAAa,UAAU;IACrB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,IAAI,CAAuB;gBAEvB,MAAM,EAAE,gBAAgB;YAoBtB,OAAO;YAeP,gBAAgB;YAKhB,KAAK;IAInB,OAAO,CAAC,iBAAiB;IAuBzB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,qBAAqB;IAwB7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAgC5B;;OAEG;IACH,OAAO,CAAC,0BAA0B;IAiBlC;;OAEG;IACH,OAAO,CAAC,cAAc;IAsCtB,OAAO,CAAC,aAAa;IAMrB;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC;IAsCxC,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,OAAO,EAAO,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;CAuExF"}
|