|
5 | 5 | type CreateCardOutput, |
6 | 6 | } from '../types/tools.js'; |
7 | 7 | import { toCourseElo, NameSpacer } from '@vue-skuilder/common'; |
| 8 | +import { allCourseWare } from '@vue-skuilder/courseware'; |
8 | 9 | import { |
9 | 10 | MCP_AGENT_AUTHOR, |
10 | 11 | handleToolError, |
@@ -44,10 +45,39 @@ export async function handleCreateCard( |
44 | 45 | throw new Error(errorMsg); |
45 | 46 | } |
46 | 47 |
|
| 48 | + // Get the complete DataShape definition from course config |
| 49 | + const matchingDataShape = courseConfig.dataShapes.find( |
| 50 | + (ds) => ds.name === validatedInput.datashape |
| 51 | + ); |
| 52 | + if (!matchingDataShape) { |
| 53 | + const errorMsg = `DataShape not found in course configuration: ${validatedInput.datashape}`; |
| 54 | + logToolWarning(TOOL_NAME, errorMsg); |
| 55 | + throw new Error(errorMsg); |
| 56 | + } |
| 57 | + |
| 58 | + // Get runtime DataShape definition from courseware |
| 59 | + const runtimeDataShape = allCourseWare |
| 60 | + .allDataShapesRaw() |
| 61 | + .find((ds) => ds.name === shapeDescriptor.dataShape); |
| 62 | + |
| 63 | + if (!runtimeDataShape) { |
| 64 | + const errorMsg = `Runtime DataShape not found in courseware: ${shapeDescriptor.dataShape}`; |
| 65 | + logToolWarning(TOOL_NAME, errorMsg); |
| 66 | + throw new Error(errorMsg); |
| 67 | + } |
| 68 | + |
| 69 | + logToolStart( |
| 70 | + TOOL_NAME, |
| 71 | + `Using runtime DataShape with ${runtimeDataShape.fields.length} fields` |
| 72 | + ); |
| 73 | + |
| 74 | + // Use complete DataShape with field definitions from courseware |
| 75 | + const dataShape = runtimeDataShape; |
| 76 | + |
47 | 77 | // Create the card via courseDB |
48 | 78 | const result = await courseDB.addNote( |
49 | 79 | shapeDescriptor.course, // Use courseware name, not courseID |
50 | | - { name: shapeDescriptor.dataShape as any, fields: [] }, |
| 80 | + dataShape, |
51 | 81 | validatedInput.data, |
52 | 82 | MCP_AGENT_AUTHOR, |
53 | 83 | validatedInput.tags || [], |
|
0 commit comments