@nimblebrain/synapse 0.1.0 → 0.1.2

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.
Files changed (39) hide show
  1. package/dist/chunk-42N5BB5O.cjs +118 -0
  2. package/dist/chunk-42N5BB5O.cjs.map +1 -0
  3. package/dist/{chunk-AW3YIXLE.cjs → chunk-HLT5UBJF.cjs} +2 -116
  4. package/dist/chunk-HLT5UBJF.cjs.map +1 -0
  5. package/dist/{chunk-M4I222LB.js → chunk-JKHGWDZI.js} +3 -114
  6. package/dist/chunk-JKHGWDZI.js.map +1 -0
  7. package/dist/chunk-YWX3D24J.js +114 -0
  8. package/dist/chunk-YWX3D24J.js.map +1 -0
  9. package/dist/codegen/cli.cjs +58 -47
  10. package/dist/codegen/cli.cjs.map +1 -1
  11. package/dist/codegen/cli.js +58 -47
  12. package/dist/codegen/cli.js.map +1 -1
  13. package/dist/codegen/index.cjs +9 -8
  14. package/dist/codegen/index.js +2 -1
  15. package/dist/schema-reader-776246MJ.js +3 -0
  16. package/dist/schema-reader-776246MJ.js.map +1 -0
  17. package/dist/schema-reader-B6LTGBMJ.cjs +20 -0
  18. package/dist/schema-reader-B6LTGBMJ.cjs.map +1 -0
  19. package/dist/server-RUCX2TIB.js +204 -0
  20. package/dist/server-RUCX2TIB.js.map +1 -0
  21. package/dist/server-SEI7XI3B.cjs +206 -0
  22. package/dist/server-SEI7XI3B.cjs.map +1 -0
  23. package/dist/type-generator-MZ4X4DE5.js +3 -0
  24. package/dist/type-generator-MZ4X4DE5.js.map +1 -0
  25. package/dist/type-generator-UA3L4OIA.cjs +12 -0
  26. package/dist/type-generator-UA3L4OIA.cjs.map +1 -0
  27. package/dist/vite/index.cjs +248 -18
  28. package/dist/vite/index.cjs.map +1 -1
  29. package/dist/vite/index.d.cts +26 -12
  30. package/dist/vite/index.d.ts +26 -12
  31. package/dist/vite/index.js +248 -18
  32. package/dist/vite/index.js.map +1 -1
  33. package/dist/writer-NDK4U6C5.cjs +14 -0
  34. package/dist/writer-NDK4U6C5.cjs.map +1 -0
  35. package/dist/writer-ZNBXYUYC.js +12 -0
  36. package/dist/writer-ZNBXYUYC.js.map +1 -0
  37. package/package.json +13 -10
  38. package/dist/chunk-AW3YIXLE.cjs.map +0 -1
  39. package/dist/chunk-M4I222LB.js.map +0 -1
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+
6
+ // src/codegen/schema-reader.ts
7
+ function readFromManifest(manifestPath) {
8
+ if (!fs.existsSync(manifestPath)) {
9
+ throw new Error(`Manifest not found: ${manifestPath}`);
10
+ }
11
+ const raw = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
12
+ const tools = raw.tools ?? [];
13
+ if (!Array.isArray(tools)) {
14
+ return [];
15
+ }
16
+ return tools.map((t) => ({
17
+ name: t.name,
18
+ description: t.description,
19
+ inputSchema: t.inputSchema ?? {},
20
+ outputSchema: t.outputSchema
21
+ }));
22
+ }
23
+ async function readFromServer(url) {
24
+ const response = await fetch(url, {
25
+ method: "POST",
26
+ headers: { "Content-Type": "application/json" },
27
+ body: JSON.stringify({
28
+ jsonrpc: "2.0",
29
+ method: "tools/list",
30
+ id: "codegen-1",
31
+ params: {}
32
+ })
33
+ });
34
+ if (!response.ok) {
35
+ throw new Error(`Server responded with ${response.status}: ${response.statusText}`);
36
+ }
37
+ const result = await response.json();
38
+ if (result.error) {
39
+ throw new Error(`Server error: ${result.error.message}`);
40
+ }
41
+ const tools = result.result?.tools ?? [];
42
+ return tools.map((t) => ({
43
+ name: t.name,
44
+ description: t.description,
45
+ inputSchema: t.inputSchema ?? {},
46
+ outputSchema: t.outputSchema
47
+ }));
48
+ }
49
+ function readFromSchemaDir(dirPath) {
50
+ if (!fs.existsSync(dirPath)) {
51
+ throw new Error(`Schema directory not found: ${dirPath}`);
52
+ }
53
+ const files = fs.readdirSync(dirPath).filter((f) => f.endsWith(".schema.json"));
54
+ const tools = [];
55
+ for (const file of files) {
56
+ const schema = JSON.parse(fs.readFileSync(path.join(dirPath, file), "utf-8"));
57
+ const entityName = path.basename(file, ".schema.json");
58
+ tools.push(
59
+ {
60
+ name: `create_${entityName}`,
61
+ description: `Create a new ${entityName}`,
62
+ inputSchema: schema,
63
+ outputSchema: schema
64
+ },
65
+ {
66
+ name: `read_${entityName}`,
67
+ description: `Read a ${entityName} by ID`,
68
+ inputSchema: {
69
+ type: "object",
70
+ properties: { id: { type: "string" } },
71
+ required: ["id"]
72
+ },
73
+ outputSchema: schema
74
+ },
75
+ {
76
+ name: `update_${entityName}`,
77
+ description: `Update an existing ${entityName}`,
78
+ inputSchema: schema,
79
+ outputSchema: schema
80
+ },
81
+ {
82
+ name: `delete_${entityName}`,
83
+ description: `Delete a ${entityName} by ID`,
84
+ inputSchema: {
85
+ type: "object",
86
+ properties: { id: { type: "string" } },
87
+ required: ["id"]
88
+ }
89
+ },
90
+ {
91
+ name: `list_${entityName}s`,
92
+ description: `List all ${entityName}s`,
93
+ inputSchema: {
94
+ type: "object",
95
+ properties: {
96
+ filter: { type: "string" },
97
+ limit: { type: "number" }
98
+ }
99
+ },
100
+ outputSchema: {
101
+ type: "object",
102
+ properties: {
103
+ items: { type: "array", items: schema },
104
+ total: { type: "number" }
105
+ },
106
+ required: ["items", "total"]
107
+ }
108
+ }
109
+ );
110
+ }
111
+ return tools;
112
+ }
113
+
114
+ exports.readFromManifest = readFromManifest;
115
+ exports.readFromSchemaDir = readFromSchemaDir;
116
+ exports.readFromServer = readFromServer;
117
+ //# sourceMappingURL=chunk-42N5BB5O.cjs.map
118
+ //# sourceMappingURL=chunk-42N5BB5O.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/codegen/schema-reader.ts"],"names":["existsSync","readFileSync","readdirSync","join","basename"],"mappings":";;;;;;AAQO,SAAS,iBAAiB,YAAA,EAAwC;AACvE,EAAA,IAAI,CAACA,aAAA,CAAW,YAAY,CAAA,EAAG;AAC7B,IAA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EAAE,IAAA,EAAM,QAAA;AAAS,WAC1B;AAAA,UACA,QAAA,EAAU,CAAC,OAAA,EAAS,OAAO;AAAA;AAC7B;AACF,KACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT","file":"chunk-42N5BB5O.cjs","sourcesContent":["import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport type { ToolDefinition } from \"../types.js\";\n\n/**\n * Read tool definitions from a manifest.json file.\n * Extracts tools from the MCP standard `tools` array.\n */\nexport function readFromManifest(manifestPath: string): ToolDefinition[] {\n if (!existsSync(manifestPath)) {\n throw new Error(`Manifest not found: ${manifestPath}`);\n }\n\n const raw = JSON.parse(readFileSync(manifestPath, \"utf-8\"));\n const tools = raw.tools ?? [];\n\n if (!Array.isArray(tools)) {\n return [];\n }\n\n return tools.map((t: any) => ({\n name: t.name as string,\n description: t.description as string | undefined,\n inputSchema: (t.inputSchema ?? {}) as Record<string, unknown>,\n outputSchema: t.outputSchema as Record<string, unknown> | undefined,\n }));\n}\n\n/**\n * Read tool definitions from a running MCP server via tools/list.\n * Connects to the server's HTTP endpoint and calls the JSON-RPC method.\n */\nexport async function readFromServer(url: string): Promise<ToolDefinition[]> {\n const response = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n method: \"tools/list\",\n id: \"codegen-1\",\n params: {},\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Server responded with ${response.status}: ${response.statusText}`);\n }\n\n const result = await response.json();\n if (result.error) {\n throw new Error(`Server error: ${result.error.message}`);\n }\n\n const tools = result.result?.tools ?? [];\n return tools.map((t: any) => ({\n name: t.name as string,\n description: t.description as string | undefined,\n inputSchema: (t.inputSchema ?? {}) as Record<string, unknown>,\n outputSchema: t.outputSchema as Record<string, unknown> | undefined,\n }));\n}\n\n/**\n * Read entity schemas from a directory and generate CRUD tool definitions.\n * Each .schema.json file becomes create/read/update/delete/list tools.\n */\nexport function readFromSchemaDir(dirPath: string): ToolDefinition[] {\n if (!existsSync(dirPath)) {\n throw new Error(`Schema directory not found: ${dirPath}`);\n }\n\n const files = readdirSync(dirPath).filter((f: string) => f.endsWith(\".schema.json\"));\n const tools: ToolDefinition[] = [];\n\n for (const file of files) {\n const schema = JSON.parse(readFileSync(join(dirPath, file), \"utf-8\"));\n const entityName = basename(file, \".schema.json\");\n\n tools.push(\n {\n name: `create_${entityName}`,\n description: `Create a new ${entityName}`,\n inputSchema: schema,\n outputSchema: schema,\n },\n {\n name: `read_${entityName}`,\n description: `Read a ${entityName} by ID`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\" } },\n required: [\"id\"],\n },\n outputSchema: schema,\n },\n {\n name: `update_${entityName}`,\n description: `Update an existing ${entityName}`,\n inputSchema: schema,\n outputSchema: schema,\n },\n {\n name: `delete_${entityName}`,\n description: `Delete a ${entityName} by ID`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\" } },\n required: [\"id\"],\n },\n },\n {\n name: `list_${entityName}s`,\n description: `List all ${entityName}s`,\n inputSchema: {\n type: \"object\",\n properties: {\n filter: { type: \"string\" },\n limit: { type: \"number\" },\n },\n },\n outputSchema: {\n type: \"object\",\n properties: {\n items: { type: \"array\", items: schema },\n total: { type: \"number\" },\n },\n required: [\"items\", \"total\"],\n },\n },\n );\n }\n\n return tools;\n}\n"]}
@@ -1,116 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var fs = require('fs');
4
- var path = require('path');
5
-
6
- // src/codegen/schema-reader.ts
7
- function readFromManifest(manifestPath) {
8
- if (!fs.existsSync(manifestPath)) {
9
- throw new Error(`Manifest not found: ${manifestPath}`);
10
- }
11
- const raw = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
12
- const tools = raw.tools ?? [];
13
- if (!Array.isArray(tools)) {
14
- return [];
15
- }
16
- return tools.map((t) => ({
17
- name: t.name,
18
- description: t.description,
19
- inputSchema: t.inputSchema ?? {},
20
- outputSchema: t.outputSchema
21
- }));
22
- }
23
- async function readFromServer(url) {
24
- const response = await fetch(url, {
25
- method: "POST",
26
- headers: { "Content-Type": "application/json" },
27
- body: JSON.stringify({
28
- jsonrpc: "2.0",
29
- method: "tools/list",
30
- id: "codegen-1",
31
- params: {}
32
- })
33
- });
34
- if (!response.ok) {
35
- throw new Error(`Server responded with ${response.status}: ${response.statusText}`);
36
- }
37
- const result = await response.json();
38
- if (result.error) {
39
- throw new Error(`Server error: ${result.error.message}`);
40
- }
41
- const tools = result.result?.tools ?? [];
42
- return tools.map((t) => ({
43
- name: t.name,
44
- description: t.description,
45
- inputSchema: t.inputSchema ?? {},
46
- outputSchema: t.outputSchema
47
- }));
48
- }
49
- function readFromSchemaDir(dirPath) {
50
- if (!fs.existsSync(dirPath)) {
51
- throw new Error(`Schema directory not found: ${dirPath}`);
52
- }
53
- const files = fs.readdirSync(dirPath).filter((f) => f.endsWith(".schema.json"));
54
- const tools = [];
55
- for (const file of files) {
56
- const schema = JSON.parse(fs.readFileSync(path.join(dirPath, file), "utf-8"));
57
- const entityName = path.basename(file, ".schema.json");
58
- tools.push(
59
- {
60
- name: `create_${entityName}`,
61
- description: `Create a new ${entityName}`,
62
- inputSchema: schema,
63
- outputSchema: schema
64
- },
65
- {
66
- name: `read_${entityName}`,
67
- description: `Read a ${entityName} by ID`,
68
- inputSchema: {
69
- type: "object",
70
- properties: { id: { type: "string" } },
71
- required: ["id"]
72
- },
73
- outputSchema: schema
74
- },
75
- {
76
- name: `update_${entityName}`,
77
- description: `Update an existing ${entityName}`,
78
- inputSchema: schema,
79
- outputSchema: schema
80
- },
81
- {
82
- name: `delete_${entityName}`,
83
- description: `Delete a ${entityName} by ID`,
84
- inputSchema: {
85
- type: "object",
86
- properties: { id: { type: "string" } },
87
- required: ["id"]
88
- }
89
- },
90
- {
91
- name: `list_${entityName}s`,
92
- description: `List all ${entityName}s`,
93
- inputSchema: {
94
- type: "object",
95
- properties: {
96
- filter: { type: "string" },
97
- limit: { type: "number" }
98
- }
99
- },
100
- outputSchema: {
101
- type: "object",
102
- properties: {
103
- items: { type: "array", items: schema },
104
- total: { type: "number" }
105
- },
106
- required: ["items", "total"]
107
- }
108
- }
109
- );
110
- }
111
- return tools;
112
- }
113
-
114
3
  // src/codegen/type-generator.ts
115
4
  function generateTypes(tools, appName) {
116
5
  const lines = [];
@@ -241,8 +130,5 @@ function toPascalCase(str) {
241
130
  }
242
131
 
243
132
  exports.generateTypes = generateTypes;
244
- exports.readFromManifest = readFromManifest;
245
- exports.readFromSchemaDir = readFromSchemaDir;
246
- exports.readFromServer = readFromServer;
247
- //# sourceMappingURL=chunk-AW3YIXLE.cjs.map
248
- //# sourceMappingURL=chunk-AW3YIXLE.cjs.map
133
+ //# sourceMappingURL=chunk-HLT5UBJF.cjs.map
134
+ //# sourceMappingURL=chunk-HLT5UBJF.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/codegen/type-generator.ts"],"names":[],"mappings":";;;AAKO,SAAS,aAAA,CAAc,OAAyB,OAAA,EAAyB;AAC9E,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,MAAM,OAAA,GAAU,CAAA,EAAG,YAAA,CAAa,OAAO,CAAC,CAAA,OAAA,CAAA;AAExC,EAAA,KAAA,CAAM,KAAK,KAAK,CAAA;AAChB,EAAA,KAAA,CAAM,KAAK,CAAA,iDAAA,CAAmD,CAAA;AAC9D,EAAA,KAAA,CAAM,IAAA,CAAK,CAAA,WAAA,EAAc,OAAO,CAAA,CAAE,CAAA;AAClC,EAAA,KAAA,CAAM,KAAK,CAAA,EAAA,CAAI,CAAA;AACf,EAAA,KAAA,CAAM,IAAA;AAAA,IACJ,CAAA,0FAAA;AAAA,GACF;AACA,EAAA,KAAA,CAAM,KAAK,CAAA,GAAA,CAAK,CAAA;AAChB,EAAA,KAAA,CAAM,KAAK,EAAE,CAAA;AAEb,EAAA,MAAM,aAAuB,EAAC;AAE9B,EAAA,KAAA,MAAW,QAAQ,KAAA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A,OAAO,yBAAA;AAAA,IACT;AAAA,IACA;AACE,MAAA,OAAO,SAAA;AAAA;AAEb;AAEA,SAAS,cAAc,CAAA,EAAmB;AACxC,EAAA,QAAQ,CAAA;AAAG,IACT,KAAK,QAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT,KAAK,QAAA;AAAA,IACL,KAAK,SAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAA,OAAO,SAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT;AACE,MAAA,OAAO,SAAA;AAAA;AAEb;AAEA,SAAS,aAAa,GAAA,EAAqB;AACzC,EAAA,OAAO,GAAA,CACJ,MAAM,QAAQ,CAAA,CACd,OAAO,OAAO,CAAA,CACd,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,IAAA,CAAK,MAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,EAAE,CAAA;AACZ","file":"chunk-HLT5UBJF.cjs","sourcesContent":["import type { ToolDefinition } from \"../types.js\";\n\n/**\n * Generate TypeScript interfaces from tool definitions.\n */\nexport function generateTypes(tools: ToolDefinition[], appName: string): string {\n const lines: string[] = [];\n const mapName = `${toPascalCase(appName)}ToolMap`;\n\n lines.push(\"/**\");\n lines.push(` * Auto-generated by @nimblebrain/synapse codegen`);\n lines.push(` * Source: ${appName}`);\n lines.push(` *`);\n lines.push(\n ` * DO NOT EDIT — regenerate with: npx synapse codegen --from-manifest ./manifest.json`,\n );\n lines.push(` */`);\n lines.push(\"\");\n\n const mapEntries: string[] = [];\n\n for (const tool of tools) {\n const baseName = toPascalCase(tool.name);\n\n // Input type\n const inputName = `${baseName}Input`;\n lines.push(schemaToInterface(inputName, tool.inputSchema));\n lines.push(\"\");\n\n // Output type\n let outputName = \"unknown\";\n if (tool.outputSchema) {\n outputName = `${baseName}Output`;\n lines.push(schemaToInterface(outputName, tool.outputSchema));\n lines.push(\"\");\n }\n\n mapEntries.push(` ${tool.name}: { input: ${inputName}; output: ${outputName} };`);\n }\n\n // Tool map\n lines.push(`/** Tool type map for typed useCallTool */`);\n lines.push(`export interface ${mapName} {`);\n for (const entry of mapEntries) {\n lines.push(entry);\n }\n lines.push(`}`);\n lines.push(\"\");\n\n return lines.join(\"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// JSON Schema -> TypeScript conversion\n// ---------------------------------------------------------------------------\n\nfunction schemaToInterface(name: string, schema: Record<string, unknown>): string {\n const type = schemaToType(schema, name);\n\n // If the schema is an object, generate a named interface\n if (schema.type === \"object\" || schema.properties) {\n return generateInterface(name, schema);\n }\n\n // Otherwise, generate a type alias\n return `export type ${name} = ${type};`;\n}\n\nfunction generateInterface(name: string, schema: Record<string, unknown>): string {\n const lines: string[] = [];\n lines.push(`export interface ${name} {`);\n\n const props = (schema.properties ?? {}) as Record<string, Record<string, unknown>>;\n const required = new Set((schema.required ?? []) as string[]);\n\n for (const [key, propSchema] of Object.entries(props)) {\n const isRequired = required.has(key);\n const type = schemaToType(propSchema, name + toPascalCase(key));\n const desc = propSchema.description;\n if (desc) {\n lines.push(` /** ${desc} */`);\n }\n lines.push(` ${key}${isRequired ? \"\" : \"?\"}: ${type};`);\n }\n\n lines.push(`}`);\n return lines.join(\"\\n\");\n}\n\nfunction schemaToType(schema: Record<string, unknown>, context: string): string {\n // Handle enum\n if (schema.enum && Array.isArray(schema.enum)) {\n return (schema.enum as unknown[])\n .map((v) => (typeof v === \"string\" ? `\"${v}\"` : String(v)))\n .join(\" | \");\n }\n\n // Handle oneOf / anyOf\n if (schema.oneOf && Array.isArray(schema.oneOf)) {\n return (schema.oneOf as Record<string, unknown>[])\n .map((s, i) => schemaToType(s, `${context}Option${i}`))\n .join(\" | \");\n }\n if (schema.anyOf && Array.isArray(schema.anyOf)) {\n return (schema.anyOf as Record<string, unknown>[])\n .map((s, i) => schemaToType(s, `${context}Option${i}`))\n .join(\" | \");\n }\n\n // Handle allOf (intersection)\n if (schema.allOf && Array.isArray(schema.allOf)) {\n return (schema.allOf as Record<string, unknown>[])\n .map((s, i) => schemaToType(s, `${context}Part${i}`))\n .join(\" & \");\n }\n\n // Handle type-based conversion\n const type = schema.type as string | string[] | undefined;\n\n if (Array.isArray(type)) {\n // Multi-type (e.g., [\"string\", \"null\"])\n return type.map((t) => primitiveType(t)).join(\" | \");\n }\n\n switch (type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"array\": {\n const items = schema.items as Record<string, unknown> | undefined;\n if (items) {\n return `${schemaToType(items, `${context}Item`)}[]`;\n }\n return \"unknown[]\";\n }\n case \"object\": {\n if (schema.properties) {\n // Inline object — generate property types\n const props = schema.properties as Record<string, Record<string, unknown>>;\n const required = new Set((schema.required ?? []) as string[]);\n const fields = Object.entries(props)\n .map(([key, propSchema]) => {\n const t = schemaToType(propSchema, context + toPascalCase(key));\n return `${key}${required.has(key) ? \"\" : \"?\"}: ${t}`;\n })\n .join(\"; \");\n return `{ ${fields} }`;\n }\n return \"Record<string, unknown>\";\n }\n default:\n return \"unknown\";\n }\n}\n\nfunction primitiveType(t: string): string {\n switch (t) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n default:\n return \"unknown\";\n }\n}\n\nfunction toPascalCase(str: string): string {\n return str\n .split(/[-_@/]/)\n .filter(Boolean)\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(\"\");\n}\n"]}
@@ -1,114 +1,3 @@
1
- import { existsSync, readFileSync, readdirSync } from 'fs';
2
- import { join, basename } from 'path';
3
-
4
- // src/codegen/schema-reader.ts
5
- function readFromManifest(manifestPath) {
6
- if (!existsSync(manifestPath)) {
7
- throw new Error(`Manifest not found: ${manifestPath}`);
8
- }
9
- const raw = JSON.parse(readFileSync(manifestPath, "utf-8"));
10
- const tools = raw.tools ?? [];
11
- if (!Array.isArray(tools)) {
12
- return [];
13
- }
14
- return tools.map((t) => ({
15
- name: t.name,
16
- description: t.description,
17
- inputSchema: t.inputSchema ?? {},
18
- outputSchema: t.outputSchema
19
- }));
20
- }
21
- async function readFromServer(url) {
22
- const response = await fetch(url, {
23
- method: "POST",
24
- headers: { "Content-Type": "application/json" },
25
- body: JSON.stringify({
26
- jsonrpc: "2.0",
27
- method: "tools/list",
28
- id: "codegen-1",
29
- params: {}
30
- })
31
- });
32
- if (!response.ok) {
33
- throw new Error(`Server responded with ${response.status}: ${response.statusText}`);
34
- }
35
- const result = await response.json();
36
- if (result.error) {
37
- throw new Error(`Server error: ${result.error.message}`);
38
- }
39
- const tools = result.result?.tools ?? [];
40
- return tools.map((t) => ({
41
- name: t.name,
42
- description: t.description,
43
- inputSchema: t.inputSchema ?? {},
44
- outputSchema: t.outputSchema
45
- }));
46
- }
47
- function readFromSchemaDir(dirPath) {
48
- if (!existsSync(dirPath)) {
49
- throw new Error(`Schema directory not found: ${dirPath}`);
50
- }
51
- const files = readdirSync(dirPath).filter((f) => f.endsWith(".schema.json"));
52
- const tools = [];
53
- for (const file of files) {
54
- const schema = JSON.parse(readFileSync(join(dirPath, file), "utf-8"));
55
- const entityName = basename(file, ".schema.json");
56
- tools.push(
57
- {
58
- name: `create_${entityName}`,
59
- description: `Create a new ${entityName}`,
60
- inputSchema: schema,
61
- outputSchema: schema
62
- },
63
- {
64
- name: `read_${entityName}`,
65
- description: `Read a ${entityName} by ID`,
66
- inputSchema: {
67
- type: "object",
68
- properties: { id: { type: "string" } },
69
- required: ["id"]
70
- },
71
- outputSchema: schema
72
- },
73
- {
74
- name: `update_${entityName}`,
75
- description: `Update an existing ${entityName}`,
76
- inputSchema: schema,
77
- outputSchema: schema
78
- },
79
- {
80
- name: `delete_${entityName}`,
81
- description: `Delete a ${entityName} by ID`,
82
- inputSchema: {
83
- type: "object",
84
- properties: { id: { type: "string" } },
85
- required: ["id"]
86
- }
87
- },
88
- {
89
- name: `list_${entityName}s`,
90
- description: `List all ${entityName}s`,
91
- inputSchema: {
92
- type: "object",
93
- properties: {
94
- filter: { type: "string" },
95
- limit: { type: "number" }
96
- }
97
- },
98
- outputSchema: {
99
- type: "object",
100
- properties: {
101
- items: { type: "array", items: schema },
102
- total: { type: "number" }
103
- },
104
- required: ["items", "total"]
105
- }
106
- }
107
- );
108
- }
109
- return tools;
110
- }
111
-
112
1
  // src/codegen/type-generator.ts
113
2
  function generateTypes(tools, appName) {
114
3
  const lines = [];
@@ -238,6 +127,6 @@ function toPascalCase(str) {
238
127
  return str.split(/[-_@/]/).filter(Boolean).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
239
128
  }
240
129
 
241
- export { generateTypes, readFromManifest, readFromSchemaDir, readFromServer };
242
- //# sourceMappingURL=chunk-M4I222LB.js.map
243
- //# sourceMappingURL=chunk-M4I222LB.js.map
130
+ export { generateTypes };
131
+ //# sourceMappingURL=chunk-JKHGWDZI.js.map
132
+ //# sourceMappingURL=chunk-JKHGWDZI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/codegen/type-generator.ts"],"names":[],"mappings":";AAKO,SAAS,aAAA,CAAc,OAAyB,OAAA,EAAyB;AAC9E,EAAA,MAAM,QAAkB,EAAC;AACzB,EAAA,MAAM,OAAA,GAAU,CAAA,EAAG,YAAA,CAAa,OAAO,CAAC,CAAA,OAAA,CAAA;AAExC,EAAA,KAAA,CAAM,KAAK,KAAK,CAAA;AAChB,EAAA,KAAA,CAAM,KAAK,CAAA,iDAAA,CAAmD,CAAA;AAC9D,EAAA,KAAA,CAAM,IAAA,CAAK,CAAA,WAAA,EAAc,OAAO,CAAA,CAAE,CAAA;AAClC,EAAA,KAAA,CAAM,KAAK,CAAA,EAAA,CAAI,CAAA;AACf,EAAA,KAAA,CAAM,IAAA;AAAA,IACJ,CAAA,0FAAA;AAAA,GACF;AACA,EAAA,KAAA,CAAM,KAAK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C,CAAA,CAAA;AAAA,QACpD,CAAC,CAAA,CACA,IAAA,CAAK,IAAI,CAAA;AACZ,QAAA,OAAO,KAAK,MAAM,CAAA,EAAA,CAAA;AAAA,MACpB;AACA,MAAA,OAAO,yBAAA;AAAA,IACT;AAAA,IACA;AACE,MAAA,OAAO,SAAA;AAAA;AAEb;AAEA,SAAS,cAAc,CAAA,EAAmB;AACxC,EAAA,QAAQ,CAAA;AAAG,IACT,KAAK,QAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT,KAAK,QAAA;AAAA,IACL,KAAK,SAAA;AACH,MAAA,OAAO,QAAA;AAAA,IACT,KAAK,SAAA;AACH,MAAA,OAAO,SAAA;AAAA,IACT,KAAK,MAAA;AACH,MAAA,OAAO,MAAA;AAAA,IACT;AACE,MAAA,OAAO,SAAA;AAAA;AAEb;AAEA,SAAS,aAAa,GAAA,EAAqB;AACzC,EAAA,OAAO,GAAA,CACJ,MAAM,QAAQ,CAAA,CACd,OAAO,OAAO,CAAA,CACd,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,IAAA,CAAK,MAAM,CAAC,CAAC,CAAA,CAC1D,IAAA,CAAK,EAAE,CAAA;AACZ","file":"chunk-JKHGWDZI.js","sourcesContent":["import type { ToolDefinition } from \"../types.js\";\n\n/**\n * Generate TypeScript interfaces from tool definitions.\n */\nexport function generateTypes(tools: ToolDefinition[], appName: string): string {\n const lines: string[] = [];\n const mapName = `${toPascalCase(appName)}ToolMap`;\n\n lines.push(\"/**\");\n lines.push(` * Auto-generated by @nimblebrain/synapse codegen`);\n lines.push(` * Source: ${appName}`);\n lines.push(` *`);\n lines.push(\n ` * DO NOT EDIT — regenerate with: npx synapse codegen --from-manifest ./manifest.json`,\n );\n lines.push(` */`);\n lines.push(\"\");\n\n const mapEntries: string[] = [];\n\n for (const tool of tools) {\n const baseName = toPascalCase(tool.name);\n\n // Input type\n const inputName = `${baseName}Input`;\n lines.push(schemaToInterface(inputName, tool.inputSchema));\n lines.push(\"\");\n\n // Output type\n let outputName = \"unknown\";\n if (tool.outputSchema) {\n outputName = `${baseName}Output`;\n lines.push(schemaToInterface(outputName, tool.outputSchema));\n lines.push(\"\");\n }\n\n mapEntries.push(` ${tool.name}: { input: ${inputName}; output: ${outputName} };`);\n }\n\n // Tool map\n lines.push(`/** Tool type map for typed useCallTool */`);\n lines.push(`export interface ${mapName} {`);\n for (const entry of mapEntries) {\n lines.push(entry);\n }\n lines.push(`}`);\n lines.push(\"\");\n\n return lines.join(\"\\n\");\n}\n\n// ---------------------------------------------------------------------------\n// JSON Schema -> TypeScript conversion\n// ---------------------------------------------------------------------------\n\nfunction schemaToInterface(name: string, schema: Record<string, unknown>): string {\n const type = schemaToType(schema, name);\n\n // If the schema is an object, generate a named interface\n if (schema.type === \"object\" || schema.properties) {\n return generateInterface(name, schema);\n }\n\n // Otherwise, generate a type alias\n return `export type ${name} = ${type};`;\n}\n\nfunction generateInterface(name: string, schema: Record<string, unknown>): string {\n const lines: string[] = [];\n lines.push(`export interface ${name} {`);\n\n const props = (schema.properties ?? {}) as Record<string, Record<string, unknown>>;\n const required = new Set((schema.required ?? []) as string[]);\n\n for (const [key, propSchema] of Object.entries(props)) {\n const isRequired = required.has(key);\n const type = schemaToType(propSchema, name + toPascalCase(key));\n const desc = propSchema.description;\n if (desc) {\n lines.push(` /** ${desc} */`);\n }\n lines.push(` ${key}${isRequired ? \"\" : \"?\"}: ${type};`);\n }\n\n lines.push(`}`);\n return lines.join(\"\\n\");\n}\n\nfunction schemaToType(schema: Record<string, unknown>, context: string): string {\n // Handle enum\n if (schema.enum && Array.isArray(schema.enum)) {\n return (schema.enum as unknown[])\n .map((v) => (typeof v === \"string\" ? `\"${v}\"` : String(v)))\n .join(\" | \");\n }\n\n // Handle oneOf / anyOf\n if (schema.oneOf && Array.isArray(schema.oneOf)) {\n return (schema.oneOf as Record<string, unknown>[])\n .map((s, i) => schemaToType(s, `${context}Option${i}`))\n .join(\" | \");\n }\n if (schema.anyOf && Array.isArray(schema.anyOf)) {\n return (schema.anyOf as Record<string, unknown>[])\n .map((s, i) => schemaToType(s, `${context}Option${i}`))\n .join(\" | \");\n }\n\n // Handle allOf (intersection)\n if (schema.allOf && Array.isArray(schema.allOf)) {\n return (schema.allOf as Record<string, unknown>[])\n .map((s, i) => schemaToType(s, `${context}Part${i}`))\n .join(\" & \");\n }\n\n // Handle type-based conversion\n const type = schema.type as string | string[] | undefined;\n\n if (Array.isArray(type)) {\n // Multi-type (e.g., [\"string\", \"null\"])\n return type.map((t) => primitiveType(t)).join(\" | \");\n }\n\n switch (type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"array\": {\n const items = schema.items as Record<string, unknown> | undefined;\n if (items) {\n return `${schemaToType(items, `${context}Item`)}[]`;\n }\n return \"unknown[]\";\n }\n case \"object\": {\n if (schema.properties) {\n // Inline object — generate property types\n const props = schema.properties as Record<string, Record<string, unknown>>;\n const required = new Set((schema.required ?? []) as string[]);\n const fields = Object.entries(props)\n .map(([key, propSchema]) => {\n const t = schemaToType(propSchema, context + toPascalCase(key));\n return `${key}${required.has(key) ? \"\" : \"?\"}: ${t}`;\n })\n .join(\"; \");\n return `{ ${fields} }`;\n }\n return \"Record<string, unknown>\";\n }\n default:\n return \"unknown\";\n }\n}\n\nfunction primitiveType(t: string): string {\n switch (t) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n default:\n return \"unknown\";\n }\n}\n\nfunction toPascalCase(str: string): string {\n return str\n .split(/[-_@/]/)\n .filter(Boolean)\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1))\n .join(\"\");\n}\n"]}
@@ -0,0 +1,114 @@
1
+ import { existsSync, readFileSync, readdirSync } from 'fs';
2
+ import { join, basename } from 'path';
3
+
4
+ // src/codegen/schema-reader.ts
5
+ function readFromManifest(manifestPath) {
6
+ if (!existsSync(manifestPath)) {
7
+ throw new Error(`Manifest not found: ${manifestPath}`);
8
+ }
9
+ const raw = JSON.parse(readFileSync(manifestPath, "utf-8"));
10
+ const tools = raw.tools ?? [];
11
+ if (!Array.isArray(tools)) {
12
+ return [];
13
+ }
14
+ return tools.map((t) => ({
15
+ name: t.name,
16
+ description: t.description,
17
+ inputSchema: t.inputSchema ?? {},
18
+ outputSchema: t.outputSchema
19
+ }));
20
+ }
21
+ async function readFromServer(url) {
22
+ const response = await fetch(url, {
23
+ method: "POST",
24
+ headers: { "Content-Type": "application/json" },
25
+ body: JSON.stringify({
26
+ jsonrpc: "2.0",
27
+ method: "tools/list",
28
+ id: "codegen-1",
29
+ params: {}
30
+ })
31
+ });
32
+ if (!response.ok) {
33
+ throw new Error(`Server responded with ${response.status}: ${response.statusText}`);
34
+ }
35
+ const result = await response.json();
36
+ if (result.error) {
37
+ throw new Error(`Server error: ${result.error.message}`);
38
+ }
39
+ const tools = result.result?.tools ?? [];
40
+ return tools.map((t) => ({
41
+ name: t.name,
42
+ description: t.description,
43
+ inputSchema: t.inputSchema ?? {},
44
+ outputSchema: t.outputSchema
45
+ }));
46
+ }
47
+ function readFromSchemaDir(dirPath) {
48
+ if (!existsSync(dirPath)) {
49
+ throw new Error(`Schema directory not found: ${dirPath}`);
50
+ }
51
+ const files = readdirSync(dirPath).filter((f) => f.endsWith(".schema.json"));
52
+ const tools = [];
53
+ for (const file of files) {
54
+ const schema = JSON.parse(readFileSync(join(dirPath, file), "utf-8"));
55
+ const entityName = basename(file, ".schema.json");
56
+ tools.push(
57
+ {
58
+ name: `create_${entityName}`,
59
+ description: `Create a new ${entityName}`,
60
+ inputSchema: schema,
61
+ outputSchema: schema
62
+ },
63
+ {
64
+ name: `read_${entityName}`,
65
+ description: `Read a ${entityName} by ID`,
66
+ inputSchema: {
67
+ type: "object",
68
+ properties: { id: { type: "string" } },
69
+ required: ["id"]
70
+ },
71
+ outputSchema: schema
72
+ },
73
+ {
74
+ name: `update_${entityName}`,
75
+ description: `Update an existing ${entityName}`,
76
+ inputSchema: schema,
77
+ outputSchema: schema
78
+ },
79
+ {
80
+ name: `delete_${entityName}`,
81
+ description: `Delete a ${entityName} by ID`,
82
+ inputSchema: {
83
+ type: "object",
84
+ properties: { id: { type: "string" } },
85
+ required: ["id"]
86
+ }
87
+ },
88
+ {
89
+ name: `list_${entityName}s`,
90
+ description: `List all ${entityName}s`,
91
+ inputSchema: {
92
+ type: "object",
93
+ properties: {
94
+ filter: { type: "string" },
95
+ limit: { type: "number" }
96
+ }
97
+ },
98
+ outputSchema: {
99
+ type: "object",
100
+ properties: {
101
+ items: { type: "array", items: schema },
102
+ total: { type: "number" }
103
+ },
104
+ required: ["items", "total"]
105
+ }
106
+ }
107
+ );
108
+ }
109
+ return tools;
110
+ }
111
+
112
+ export { readFromManifest, readFromSchemaDir, readFromServer };
113
+ //# sourceMappingURL=chunk-YWX3D24J.js.map
114
+ //# sourceMappingURL=chunk-YWX3D24J.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/codegen/schema-reader.ts"],"names":[],"mappings":";;;;AAQO,SAAS,iBAAiB,YAAA,EAAwC;AACvE,EAAA,IAAI,CAAC,UAAA,CAAW,YAAY,CAAA,EAAG;AAC7B,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,oBAAA,EAAuB,YAAY,CAAA,CAAE,CAAA;AAAA,EACvD;AAEA,EAAA,MAAM,MAAM,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,YAAA,EAAc,OAAO,CAAC,CAAA;AAC1D,EAAA,MAAM,KAAA,GAAQ,GAAA,CAAI,KAAA,IAAS,EAAC;AAE5B,EAAA,IAAI,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACzB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,CAAA,MA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,QAC7C,WAAA,EAAa,MAAA;AAAA,QACb,YAAA,EAAc;AAAA,OAChB;AAAA,MACA;AAAA,QACE,IAAA,EAAM,UAAU,UAAU,CAAA,CAAA;AAAA,QAC1B,WAAA,EAAa,YAAY,UAAU,CAAA,MAAA,CAAA;AAAA,QACnC,WAAA,EAAa;AAAA,UACX,IAAA,EAAM,QAAA;AAAA,UACN,YAAY,EAAE,EAAA,EAAI,EAAE,IAAA,EAAM,UAAS,EAAE;AAAA,UACrC,QAAA,EAAU,CAAC,IAAI;AAAA;AACjB,OACF;AAAA,MACA;AAAA,QACE,IAAA,EAAM,QAAQ,UAAU,CAAA,CAAA,CAAA;AAAA,QACxB,WAAA,EAAa,YAAY,UAAU,CAAA,CAAA,CAAA;AAAA,QACnC,WAAA,EAAa;AAAA,UACX,IAAA,EAAM,QAAA;AAAA,UACN,UAAA,EAAY;AAAA,YACV,MAAA,EAAQ,EAAE,IAAA,EAAM,QAAA,EAAS;AAAA,YACzB,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA;AAAS;AAC1B,SACF;AAAA,QACA,YAAA,EAAc;AAAA,UACZ,IAAA,EAAM,QAAA;AAAA,UACN,UAAA,EAAY;AAAA,YACV,KAAA,EAAO,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,MAAA,EAAO;AAAA,YACtC,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA;AAAS,WAC1B;AAAA,UACA,QAAA,EAAU,CAAC,OAAA,EAAS,OAAO;AAAA;AAC7B;AACF,KACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT","file":"chunk-YWX3D24J.js","sourcesContent":["import { existsSync, readdirSync, readFileSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport type { ToolDefinition } from \"../types.js\";\n\n/**\n * Read tool definitions from a manifest.json file.\n * Extracts tools from the MCP standard `tools` array.\n */\nexport function readFromManifest(manifestPath: string): ToolDefinition[] {\n if (!existsSync(manifestPath)) {\n throw new Error(`Manifest not found: ${manifestPath}`);\n }\n\n const raw = JSON.parse(readFileSync(manifestPath, \"utf-8\"));\n const tools = raw.tools ?? [];\n\n if (!Array.isArray(tools)) {\n return [];\n }\n\n return tools.map((t: any) => ({\n name: t.name as string,\n description: t.description as string | undefined,\n inputSchema: (t.inputSchema ?? {}) as Record<string, unknown>,\n outputSchema: t.outputSchema as Record<string, unknown> | undefined,\n }));\n}\n\n/**\n * Read tool definitions from a running MCP server via tools/list.\n * Connects to the server's HTTP endpoint and calls the JSON-RPC method.\n */\nexport async function readFromServer(url: string): Promise<ToolDefinition[]> {\n const response = await fetch(url, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({\n jsonrpc: \"2.0\",\n method: \"tools/list\",\n id: \"codegen-1\",\n params: {},\n }),\n });\n\n if (!response.ok) {\n throw new Error(`Server responded with ${response.status}: ${response.statusText}`);\n }\n\n const result = await response.json();\n if (result.error) {\n throw new Error(`Server error: ${result.error.message}`);\n }\n\n const tools = result.result?.tools ?? [];\n return tools.map((t: any) => ({\n name: t.name as string,\n description: t.description as string | undefined,\n inputSchema: (t.inputSchema ?? {}) as Record<string, unknown>,\n outputSchema: t.outputSchema as Record<string, unknown> | undefined,\n }));\n}\n\n/**\n * Read entity schemas from a directory and generate CRUD tool definitions.\n * Each .schema.json file becomes create/read/update/delete/list tools.\n */\nexport function readFromSchemaDir(dirPath: string): ToolDefinition[] {\n if (!existsSync(dirPath)) {\n throw new Error(`Schema directory not found: ${dirPath}`);\n }\n\n const files = readdirSync(dirPath).filter((f: string) => f.endsWith(\".schema.json\"));\n const tools: ToolDefinition[] = [];\n\n for (const file of files) {\n const schema = JSON.parse(readFileSync(join(dirPath, file), \"utf-8\"));\n const entityName = basename(file, \".schema.json\");\n\n tools.push(\n {\n name: `create_${entityName}`,\n description: `Create a new ${entityName}`,\n inputSchema: schema,\n outputSchema: schema,\n },\n {\n name: `read_${entityName}`,\n description: `Read a ${entityName} by ID`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\" } },\n required: [\"id\"],\n },\n outputSchema: schema,\n },\n {\n name: `update_${entityName}`,\n description: `Update an existing ${entityName}`,\n inputSchema: schema,\n outputSchema: schema,\n },\n {\n name: `delete_${entityName}`,\n description: `Delete a ${entityName} by ID`,\n inputSchema: {\n type: \"object\",\n properties: { id: { type: \"string\" } },\n required: [\"id\"],\n },\n },\n {\n name: `list_${entityName}s`,\n description: `List all ${entityName}s`,\n inputSchema: {\n type: \"object\",\n properties: {\n filter: { type: \"string\" },\n limit: { type: \"number\" },\n },\n },\n outputSchema: {\n type: \"object\",\n properties: {\n items: { type: \"array\", items: schema },\n total: { type: \"number\" },\n },\n required: [\"items\", \"total\"],\n },\n },\n );\n }\n\n return tools;\n}\n"]}