|
1 | 1 | #!/usr/bin/env node |
2 | | -// JSON-RPC stdio transport |
| 2 | +// Group management |
| 3 | +// =================================================================== |
| 4 | + |
| 5 | +/** |
| 6 | + * Fetch the list of available groups. |
| 7 | + * @returns {Promise<Array<{id: string, name: string, description: string}>>} |
| 8 | + */ |
| 9 | +async function fetchGroups() { |
| 10 | + // For now, return a static list of groups. This can be extended to fetch |
| 11 | + // groups from a configuration file or database. |
| 12 | + return [ |
| 13 | + { id: "database", name: "Database", description: "Database-related tools" }, |
| 14 | + { id: "cloud", name: "Cloud", description: "Cloud-related tools" }, |
| 15 | + { id: "git", name: "Git", description: "Git-related tools" }, |
| 16 | + { id: "comms", name: "Comms", description: "Communication-related tools" }, |
| 17 | + ]; |
| 18 | +} |
| 19 | +======= |
| 20 | +// =================================================================== |
| 21 | +// Prompt management |
| 22 | +// =================================================================== |
| 23 | + |
| 24 | +/** |
| 25 | + * Fetch the list of available prompts. |
| 26 | + * @returns {Promise<Array<{id: string, name: string, description: string}>>} |
| 27 | + */ |
| 28 | +async function fetchPrompts() { |
| 29 | + // For now, return a static list of prompts. This can be extended to fetch |
| 30 | + // prompts from a configuration file or database. |
| 31 | + return [ |
| 32 | + { id: "project-analysis", name: "Project Analysis", description: "Analyze a project and suggest improvements" }, |
| 33 | + { id: "code-review", name: "Code Review", description: "Review code and detect code smells" }, |
| 34 | + { id: "research", name: "Research", description: "Research a topic and summarize findings" }, |
| 35 | + ]; |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * Fetch a specific prompt by ID. |
| 40 | + * @param {string} promptId |
| 41 | + * @returns {Promise<{id: string, name: string, description: string, template: string} | null>} |
| 42 | + */ |
| 43 | +async function fetchPrompt(promptId) { |
| 44 | + // For now, return a static prompt. This can be extended to fetch |
| 45 | + // prompts from a configuration file or database. |
| 46 | + const prompts = [ |
| 47 | + { |
| 48 | + id: "project-analysis", |
| 49 | + name: "Project Analysis", |
| 50 | + description: "Analyze a project and suggest improvements", |
| 51 | + template: "Analyze this repository and suggest improvements", |
| 52 | + }, |
| 53 | + { |
| 54 | + id: "code-review", |
| 55 | + name: "Code Review", |
| 56 | + description: "Review code and detect code smells", |
| 57 | + template: "Review this code and detect code smells", |
| 58 | + }, |
| 59 | + { |
| 60 | + id: "research", |
| 61 | + name: "Research", |
| 62 | + description: "Research a topic and summarize findings", |
| 63 | + template: "Research this topic and summarize findings", |
| 64 | + }, |
| 65 | + ]; |
| 66 | + |
| 67 | + return prompts.find((p) => p.id === promptId) || null; |
| 68 | +} |
| 69 | + |
| 70 | +// =================================================================== |
| 71 | +// Resource management |
| 72 | +// =================================================================== |
| 73 | + |
| 74 | +/** |
| 75 | + * Fetch the list of available resources. |
| 76 | + * @returns {Promise<Array<{id: string, name: string, description: string}>>} |
| 77 | + */ |
| 78 | +async function fetchResources() { |
| 79 | + // For now, return a static list of resources. This can be extended to fetch |
| 80 | + // resources from a configuration file or database. |
| 81 | + return [ |
| 82 | + { id: "knowledge-graph", name: "Knowledge Graph", description: "Knowledge graph for storing and managing contextual data" }, |
| 83 | + { id: "sessions", name: "Sessions", description: "Session management for persistent session state" }, |
| 84 | + { id: "learnings", name: "Learnings", description: "Learning system for capturing and organizing knowledge" }, |
| 85 | + ]; |
| 86 | +} |
| 87 | + |
| 88 | +/** |
| 89 | + * Fetch a specific resource by ID. |
| 90 | + * @param {string} resourceId |
| 91 | + * @returns {Promise<{id: string, name: string, description: string, schema: object} | null>} |
| 92 | + */ |
| 93 | +async function fetchResource(resourceId) { |
| 94 | + // For now, return a static resource. This can be extended to fetch |
| 95 | + // resources from a configuration file or database. |
| 96 | + const resources = [ |
| 97 | + { |
| 98 | + id: "knowledge-graph", |
| 99 | + name: "Knowledge Graph", |
| 100 | + description: "Knowledge graph for storing and managing contextual data", |
| 101 | + schema: { |
| 102 | + type: "object", |
| 103 | + properties: { |
| 104 | + entities: { type: "array", items: { type: "object" } }, |
| 105 | + observations: { type: "array", items: { type: "object" } }, |
| 106 | + relations: { type: "array", items: { type: "object" } }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }, |
| 110 | + { |
| 111 | + id: "sessions", |
| 112 | + name: "Sessions", |
| 113 | + description: "Session management for persistent session state", |
| 114 | + schema: { |
| 115 | + type: "object", |
| 116 | + properties: { |
| 117 | + id: { type: "string" }, |
| 118 | + project: { type: "string" }, |
| 119 | + started_at: { type: "string", format: "date-time" }, |
| 120 | + ended_at: { type: "string", format: "date-time", nullable: true }, |
| 121 | + summary: { type: "string" }, |
| 122 | + context: { type: "array", items: { type: "string" } }, |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + { |
| 127 | + id: "learnings", |
| 128 | + name: "Learnings", |
| 129 | + description: "Learning system for capturing and organizing knowledge", |
| 130 | + schema: { |
| 131 | + type: "object", |
| 132 | + properties: { |
| 133 | + id: { type: "string" }, |
| 134 | + category: { type: "string" }, |
| 135 | + content: { type: "string" }, |
| 136 | + tags: { type: "array", items: { type: "string" } }, |
| 137 | + confidence: { type: "number", minimum: 0, maximum: 1 }, |
| 138 | + project: { type: "string", nullable: true }, |
| 139 | + created_at: { type: "string", format: "date-time" }, |
| 140 | + updated_at: { type: "string", format: "date-time" }, |
| 141 | + }, |
| 142 | + }, |
| 143 | + }, |
| 144 | + ]; |
| 145 | + |
| 146 | + return resources.find((r) => r.id === resourceId) || null; |
| 147 | +} |
| 148 | + |
| 149 | +// =================================================================== |
| 150 | +// Group management |
| 151 | +// =================================================================== |
| 152 | + |
| 153 | +/** |
| 154 | + * Fetch the list of available groups. |
| 155 | + * @returns {Promise<Array<{id: string, name: string, description: string}>>} |
| 156 | + */ |
| 157 | +async function fetchGroups() { |
| 158 | + // For now, return a static list of groups. This can be extended to fetch |
| 159 | + // groups from a configuration file or database. |
| 160 | + return [ |
| 161 | + { id: "database", name: "Database", description: "Database-related tools" }, |
| 162 | + { id: "cloud", name: "Cloud", description: "Cloud-related tools" }, |
| 163 | + { id: "git", name: "Git", description: "Git-related tools" }, |
| 164 | + { id: "comms", name: "Comms", description: "Communication-related tools" }, |
| 165 | + ]; |
| 166 | +}JSON-RPC stdio transport |
3 | 167 | // =================================================================== |
4 | 168 |
|
5 | 169 | let buffer = ""; |
@@ -546,6 +710,50 @@ async function handleMessage(line) { |
546 | 710 | break; |
547 | 711 | } |
548 | 712 |
|
| 713 | + case "prompts/list": { |
| 714 | + const prompts = await fetchPrompts(); |
| 715 | + sendResult(id, { prompts }); |
| 716 | + break; |
| 717 | + } |
| 718 | + |
| 719 | + case "prompts/get": { |
| 720 | + const promptId = params?.promptId; |
| 721 | + if (!promptId) { |
| 722 | + sendError(id, -32602, "Prompt ID is required"); |
| 723 | + break; |
| 724 | + } |
| 725 | + |
| 726 | + const prompt = await fetchPrompt(promptId); |
| 727 | + if (prompt === null) { |
| 728 | + sendError(id, -32601, "Unknown prompt"); |
| 729 | + } else { |
| 730 | + sendResult(id, { prompt }); |
| 731 | + } |
| 732 | + break; |
| 733 | + } |
| 734 | + |
| 735 | + case "resources/list": { |
| 736 | + const resources = await fetchResources(); |
| 737 | + sendResult(id, { resources }); |
| 738 | + break; |
| 739 | + } |
| 740 | + |
| 741 | + case "resources/get": { |
| 742 | + const resourceId = params?.resourceId; |
| 743 | + if (!resourceId) { |
| 744 | + sendError(id, -32602, "Resource ID is required"); |
| 745 | + break; |
| 746 | + } |
| 747 | + |
| 748 | + const resource = await fetchResource(resourceId); |
| 749 | + if (resource === null) { |
| 750 | + sendError(id, -32601, "Unknown resource"); |
| 751 | + } else { |
| 752 | + sendResult(id, { resource }); |
| 753 | + } |
| 754 | + break; |
| 755 | + } |
| 756 | + |
549 | 757 | case "ping": |
550 | 758 | sendResult(id, {}); |
551 | 759 | break; |
|
0 commit comments