Eidos

node tools

By: Mayne

Install Latest (v0.0.1)

Node operation related tools. When enabled, the LLM can call `getNodeContent` and `updateNodeContent`.

export const commands = [
    {
        name: "getNodeContent",
        description: "Retrieve the content of a node based on the provided nodeId and nodeType.",
        inputJSONSchema: {
            type: "object",
            properties: {
                nodeId: {
                    type: "string",
                    description: "The ID of the node to retrieve content from.",
                },
                nodeType: {
                    type: "string",
                    description: "The type of the node to retrieve content from (e.g., 'doc', 'ext__myType').",
                },
            },
            required: ["nodeId", "nodeType"],
        },
        outputJSONSchema: {
            type: "object",
            properties: {
                content: {
                    type: ["string", "null"],
                    description: "The content of the node, or null if not found or not applicable.",
                },
                error: {
                    type: ["string", "null"],
                    description: "An error message if an error occurs, otherwise null.",
                },
            },
            required: ["content", "error"],
        },
        asTableAction: false,
        asTool: true,
    },
    {
        name: "updateNodeContent",
        description: "Update the content of a node based on the provided nodeId and nodeType.",
        inputJSONSchema: {
            type: "object",
            properties: {
                nodeId: {
                    type: "string",
                    description: "The ID of the node to update content for.",
                },
                nodeType: {
                    type: "string",
                    description: "The type of the node to update content for (e.g., 'doc', 'ext__myType').",
                },
                content: {
                    type: "string",
                    description: "The content to update.",
                },
            },
            required: ["nodeId", "nodeType", "content"],
        },
        outputJSONSchema: {
            type: "object",
            properties: {
                success: {
                    type: "boolean",
                    description: "Whether the update was successful.",
                },
                error: {
                    type: ["string", "null"],
                    description: "An error message if an error occurs, otherwise null.",
                },
            },
            required: ["success", "error"],
        },
        asTableAction: false,
        asTool: true,
    },
];

export async function getNodeContent(
    input: Input<{
        nodeId: string;
        nodeType: string;
    }>,
    context: Context
): Promise<{ content: string | null; error: string | null }> {
    // @ts-ignore Eidos environment provides input.payload
    const { nodeId, nodeType } = input;

    if (!nodeId || !nodeType) {
        const errorMessage = "Both nodeId and nodeType parameters are required.";
        // @ts-ignore eidos is a global object
        eidos.currentSpace.notify({
            title: "Failed to Retrieve Node Content",
            description: errorMessage,
        });
        return { content: null, error: errorMessage };
    }

    let content: string | null | undefined = null; // Allow undefined for later handling

    try {
        if (nodeType === "doc") {
            // @ts-ignore eidos is a global object
            content = await eidos.currentSpace.doc.getMarkdown(nodeId);
        } else if (nodeType.startsWith("ext__")) {
            // @ts-ignore eidos is a global object
            content = await eidos.currentSpace.extNode.getText(nodeId);
        } else {
            const errorMessage = `Unsupported node type '${nodeType}'.`;
            // @ts-ignore eidos is a global object
            eidos.currentSpace.notify({
                title: "Node Content Retrieval Warning",
                description: errorMessage,
            });
            return { content: null, error: errorMessage };
        }

        // API may return undefined; normalize to null to match Promise return type
        if (content === undefined) {
            return { content: null, error: null };
        }

        return { content, error: null };

    } catch (e: any) {
        let errorMessage = "An unknown error occurred while retrieving node content.";
        if (e instanceof Error) {
            errorMessage = `Error retrieving node content: ${e.message}`;
        } else if (typeof e === 'string') {
            errorMessage = `Error retrieving node content: ${e}`;
        }

        // @ts-ignore eidos is a global object
        eidos.currentSpace.notify({
            title: "Node Content Retrieval Error",
            description: errorMessage,
        });
        return { content: null, error: errorMessage };
    }
}

export async function updateNodeContent(
    input: Input<{
        nodeId: string;
        nodeType: string;
        content: string;
    }>,
    context: Context
): Promise<{ success: boolean; error: string | null }> {
    const { nodeId, nodeType, content } = input;

    if (!nodeId || !nodeType || !content) {
        const errorMessage = "nodeId, nodeType, and content parameters are required.";
        eidos.currentSpace.notify({
            title: "Failed to Update Node Content",
            description: errorMessage,
        });
        return { success: false, error: errorMessage };
    }

    try {
        if (nodeType === "doc") {
            await eidos.currentSpace.doc.createOrUpdateWithMarkdown(nodeId, content);
        } else if (nodeType.startsWith("ext__")) {
            await eidos.currentSpace.extNode.setText(nodeId, content);
        } else {
            const errorMessage = `Unsupported node type '${nodeType}'.`;
            eidos.currentSpace.notify({
                title: "Node Content Update Warning",
                description: errorMessage,
            });
            return { success: false, error: errorMessage };
        }

        return { success: true, error: null };
    } catch (e: any) {
        let errorMessage = "An unknown error occurred while updating node content.";
        if (e instanceof Error) {
            errorMessage = `Error updating node content: ${e.message}`;
        } else if (typeof e === "string") {
            errorMessage = `Error updating node content: ${e}`;
        }

        eidos.currentSpace.notify({
            title: "Node Content Update Error",
            description: errorMessage,
        });
        return { success: false, error: errorMessage };
    }
}

Information

Author
Mayne
Type
script
Latest Version
0.0.1
Last Updated
06/08/2025
Published
06/08/2025

Version History

  • v0.0.1 06/08/2025