@tpitre/story-ui 3.1.0 → 3.3.0
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 +25 -72
- package/dist/cli/deploy.d.ts +0 -7
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/deploy.js +10 -421
- package/dist/cli/index.js +0 -29
- package/dist/mcp-server/index.js +20 -66
- package/dist/mcp-server/mcp-stdio-server.js +40 -110
- package/dist/mcp-server/routes/generateStory.d.ts.map +1 -1
- package/dist/mcp-server/routes/generateStory.js +46 -117
- package/dist/mcp-server/routes/generateStoryStream.d.ts.map +1 -1
- package/dist/mcp-server/routes/generateStoryStream.js +30 -72
- package/dist/mcp-server/routes/mcpRemote.d.ts +7 -3
- package/dist/mcp-server/routes/mcpRemote.d.ts.map +1 -1
- package/dist/mcp-server/routes/mcpRemote.js +353 -254
- package/dist/story-generator/generateStory.d.ts.map +1 -1
- package/dist/story-generator/generateStory.js +25 -0
- package/package.json +7 -7
- package/dist/mcp-server/routes/hybridStories.d.ts +0 -18
- package/dist/mcp-server/routes/hybridStories.d.ts.map +0 -1
- package/dist/mcp-server/routes/hybridStories.js +0 -214
- package/dist/mcp-server/routes/memoryStories.d.ts +0 -26
- package/dist/mcp-server/routes/memoryStories.d.ts.map +0 -1
- package/dist/mcp-server/routes/memoryStories.js +0 -147
- package/dist/mcp-server/routes/storySync.d.ts +0 -26
- package/dist/mcp-server/routes/storySync.d.ts.map +0 -1
- package/dist/mcp-server/routes/storySync.js +0 -147
- package/dist/mcp-server/sessionManager.d.ts +0 -50
- package/dist/mcp-server/sessionManager.d.ts.map +0 -1
- package/dist/mcp-server/sessionManager.js +0 -125
- package/dist/story-generator/inMemoryStoryService.d.ts +0 -89
- package/dist/story-generator/inMemoryStoryService.d.ts.map +0 -1
- package/dist/story-generator/inMemoryStoryService.js +0 -128
- package/dist/story-generator/productionGitignoreManager.d.ts +0 -91
- package/dist/story-generator/productionGitignoreManager.d.ts.map +0 -1
- package/dist/story-generator/productionGitignoreManager.js +0 -340
- package/dist/story-generator/storySync.d.ts +0 -68
- package/dist/story-generator/storySync.d.ts.map +0 -1
- package/dist/story-generator/storySync.js +0 -201
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStory.d.ts","sourceRoot":"","sources":["../../story-generator/generateStory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"generateStory.d.ts","sourceRoot":"","sources":["../../story-generator/generateStory.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AA6BtD,wBAAgB,aAAa,CAAC,EAC5B,YAAY,EACZ,QAAQ,EACR,MAAM,EACP,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,aAAa,CAAC;CACvB,UAmBA"}
|
|
@@ -6,7 +6,32 @@ function slugify(str) {
|
|
|
6
6
|
.replace(/[^a-z0-9]+/g, '-')
|
|
7
7
|
.replace(/^-+|-+$/g, '');
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Check if the current working directory is the Story UI package itself.
|
|
11
|
+
* This prevents accidentally generating stories in the package source code.
|
|
12
|
+
*/
|
|
13
|
+
function isStoryUIPackageDirectory() {
|
|
14
|
+
try {
|
|
15
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
16
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
17
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
18
|
+
// Check if this is the story-ui package by name
|
|
19
|
+
if (packageJson.name === '@tpitre/story-ui') {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
9
29
|
export function generateStory({ fileContents, fileName, config }) {
|
|
30
|
+
// SAFEGUARD: Prevent generating stories in the Story UI package directory
|
|
31
|
+
if (isStoryUIPackageDirectory()) {
|
|
32
|
+
throw new Error('Cannot generate stories in the Story UI package directory. ' +
|
|
33
|
+
'Please run story-ui from a project that uses Story UI, not from the story-ui package itself.');
|
|
34
|
+
}
|
|
10
35
|
const outPath = path.join(config.generatedStoriesPath, fileName);
|
|
11
36
|
// Ensure the directory exists
|
|
12
37
|
const dir = path.dirname(outPath);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tpitre/story-ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "AI-powered Storybook story generator with dynamic component discovery",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,9 +36,7 @@
|
|
|
36
36
|
"release:dry-run": "semantic-release --dry-run",
|
|
37
37
|
"commit": "cz",
|
|
38
38
|
"prepare": "husky",
|
|
39
|
-
"story-ui": "story-ui start --port 4001"
|
|
40
|
-
"deploy:edge": "./scripts/deploy-edge.sh",
|
|
41
|
-
"deploy:edge:dry-run": "./scripts/deploy-edge.sh --dry-run"
|
|
39
|
+
"story-ui": "story-ui start --port 4001"
|
|
42
40
|
},
|
|
43
41
|
"keywords": [
|
|
44
42
|
"storybook",
|
|
@@ -76,8 +74,9 @@
|
|
|
76
74
|
"dependencies": {
|
|
77
75
|
"@emotion/react": "^11.14.0",
|
|
78
76
|
"@emotion/styled": "^11.14.1",
|
|
79
|
-
"@modelcontextprotocol/sdk": "^
|
|
77
|
+
"@modelcontextprotocol/sdk": "^1.23.0",
|
|
80
78
|
"@mui/material": "^7.2.0",
|
|
79
|
+
"@types/pg": "^8.15.6",
|
|
81
80
|
"chalk": "^5.3.0",
|
|
82
81
|
"commander": "^11.0.0",
|
|
83
82
|
"cors": "^2.8.5",
|
|
@@ -86,6 +85,7 @@
|
|
|
86
85
|
"glob": "^11.0.3",
|
|
87
86
|
"inquirer": "^9.2.0",
|
|
88
87
|
"node-fetch": "^2.6.7",
|
|
88
|
+
"pg": "^8.16.3",
|
|
89
89
|
"typescript": "^5.8.3",
|
|
90
90
|
"zod": "^3.22.4"
|
|
91
91
|
},
|
|
@@ -105,11 +105,11 @@
|
|
|
105
105
|
"@types/node": "^20.4.2",
|
|
106
106
|
"@types/node-fetch": "^2.6.12",
|
|
107
107
|
"commitizen": "^4.3.1",
|
|
108
|
+
"concurrently": "^8.2.0",
|
|
108
109
|
"cz-conventional-changelog": "^3.3.0",
|
|
109
110
|
"husky": "^9.1.7",
|
|
110
111
|
"semantic-release": "^24.2.0",
|
|
111
|
-
"ts-node": "^10.9.2"
|
|
112
|
-
"concurrently": "^8.2.0"
|
|
112
|
+
"ts-node": "^10.9.2"
|
|
113
113
|
},
|
|
114
114
|
"peerDependencies": {
|
|
115
115
|
"@storybook/react": ">=6.0.0",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
/**
|
|
3
|
-
* Get all stories from both memory and file system
|
|
4
|
-
*/
|
|
5
|
-
export declare function getAllStories(req: Request, res: Response): void;
|
|
6
|
-
/**
|
|
7
|
-
* Get a specific story by ID from memory or file system
|
|
8
|
-
*/
|
|
9
|
-
export declare function getStoryById(req: Request, res: Response): Response<any, Record<string, any>> | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Get story content by ID
|
|
12
|
-
*/
|
|
13
|
-
export declare function getStoryContent(req: Request, res: Response): Response<any, Record<string, any>> | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Delete a story by ID
|
|
16
|
-
*/
|
|
17
|
-
export declare function deleteStory(req: Request, res: Response): Response<any, Record<string, any>> | undefined;
|
|
18
|
-
//# sourceMappingURL=hybridStories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hybridStories.d.ts","sourceRoot":"","sources":["../../../mcp-server/routes/hybridStories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAO5C;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,QA6DxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,kDA0DvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,kDA0C1D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,kDA6CtD"}
|
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { getInMemoryStoryService } from '../../story-generator/inMemoryStoryService.js';
|
|
4
|
-
import { loadUserConfig } from '../../story-generator/configLoader.js';
|
|
5
|
-
import { setupProductionGitignore } from '../../story-generator/productionGitignoreManager.js';
|
|
6
|
-
/**
|
|
7
|
-
* Get all stories from both memory and file system
|
|
8
|
-
*/
|
|
9
|
-
export function getAllStories(req, res) {
|
|
10
|
-
try {
|
|
11
|
-
const config = loadUserConfig();
|
|
12
|
-
const gitignoreManager = setupProductionGitignore(config);
|
|
13
|
-
const storyService = getInMemoryStoryService(config);
|
|
14
|
-
let allStories = [];
|
|
15
|
-
// Get stories from memory
|
|
16
|
-
const memoryStories = storyService.getStoryMetadata();
|
|
17
|
-
allStories = [...memoryStories];
|
|
18
|
-
// In development mode, also check file system
|
|
19
|
-
if (!gitignoreManager.isProductionMode() && config.generatedStoriesPath) {
|
|
20
|
-
try {
|
|
21
|
-
if (fs.existsSync(config.generatedStoriesPath)) {
|
|
22
|
-
const files = fs.readdirSync(config.generatedStoriesPath);
|
|
23
|
-
const fileStories = files
|
|
24
|
-
.filter(file => file.endsWith('.stories.tsx'))
|
|
25
|
-
.map(file => {
|
|
26
|
-
const fileName = file;
|
|
27
|
-
const hash = file.match(/-([a-f0-9]{8})\.stories\.tsx$/)?.[1] || '';
|
|
28
|
-
const storyId = hash ? `story-${hash}` : file.replace('.stories.tsx', '');
|
|
29
|
-
// Try to read the file to get the title
|
|
30
|
-
let title = file.replace('.stories.tsx', '').replace(/-/g, ' ');
|
|
31
|
-
try {
|
|
32
|
-
const filePath = path.join(config.generatedStoriesPath, file);
|
|
33
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
34
|
-
const titleMatch = content.match(/title:\s*['"]([^'"]+)['"]/);
|
|
35
|
-
if (titleMatch) {
|
|
36
|
-
title = titleMatch[1].replace('Generated/', '');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
catch (e) {
|
|
40
|
-
// Use filename as fallback
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
id: storyId,
|
|
44
|
-
fileName,
|
|
45
|
-
title,
|
|
46
|
-
createdAt: fs.statSync(path.join(config.generatedStoriesPath, file)).birthtime,
|
|
47
|
-
storage: 'file-system'
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
// Merge, avoiding duplicates
|
|
51
|
-
const memoryIds = new Set(memoryStories.map(s => s.id));
|
|
52
|
-
const uniqueFileStories = fileStories.filter(s => !memoryIds.has(s.id));
|
|
53
|
-
allStories = [...allStories, ...uniqueFileStories];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
console.error('Error reading file system stories:', error);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
res.json(allStories);
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
console.error('Error in getAllStories:', error);
|
|
64
|
-
res.status(500).json({ error: 'Failed to retrieve stories' });
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Get a specific story by ID from memory or file system
|
|
69
|
-
*/
|
|
70
|
-
export function getStoryById(req, res) {
|
|
71
|
-
try {
|
|
72
|
-
const { id } = req.params;
|
|
73
|
-
const config = loadUserConfig();
|
|
74
|
-
const gitignoreManager = setupProductionGitignore(config);
|
|
75
|
-
const storyService = getInMemoryStoryService(config);
|
|
76
|
-
// First try memory
|
|
77
|
-
const memoryStory = storyService.getStory(id);
|
|
78
|
-
if (memoryStory) {
|
|
79
|
-
return res.json(memoryStory);
|
|
80
|
-
}
|
|
81
|
-
// In development, try file system
|
|
82
|
-
if (!gitignoreManager.isProductionMode() && config.generatedStoriesPath) {
|
|
83
|
-
// Try to find by story ID pattern
|
|
84
|
-
const files = fs.readdirSync(config.generatedStoriesPath);
|
|
85
|
-
// Extract hash from story ID (e.g., "story-abc123" -> "abc123")
|
|
86
|
-
const hashMatch = id.match(/^story-([a-f0-9]{8})$/);
|
|
87
|
-
const hash = hashMatch ? hashMatch[1] : null;
|
|
88
|
-
// Find file by hash or exact match
|
|
89
|
-
const matchingFile = files.find(file => {
|
|
90
|
-
if (hash && file.includes(`-${hash}.stories.tsx`))
|
|
91
|
-
return true;
|
|
92
|
-
if (file === `${id}.stories.tsx`)
|
|
93
|
-
return true;
|
|
94
|
-
if (file === id)
|
|
95
|
-
return true;
|
|
96
|
-
return false;
|
|
97
|
-
});
|
|
98
|
-
if (matchingFile) {
|
|
99
|
-
const filePath = path.join(config.generatedStoriesPath, matchingFile);
|
|
100
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
101
|
-
const stats = fs.statSync(filePath);
|
|
102
|
-
// Extract title from content
|
|
103
|
-
let title = matchingFile.replace('.stories.tsx', '').replace(/-/g, ' ');
|
|
104
|
-
const titleMatch = content.match(/title:\s*['"]([^'"]+)['"]/);
|
|
105
|
-
if (titleMatch) {
|
|
106
|
-
title = titleMatch[1].replace('Generated/', '');
|
|
107
|
-
}
|
|
108
|
-
return res.json({
|
|
109
|
-
id,
|
|
110
|
-
fileName: matchingFile,
|
|
111
|
-
title,
|
|
112
|
-
content,
|
|
113
|
-
createdAt: stats.birthtime,
|
|
114
|
-
storage: 'file-system'
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
res.status(404).json({ error: 'Story not found' });
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
console.error('Error in getStoryById:', error);
|
|
122
|
-
res.status(500).json({ error: 'Failed to retrieve story' });
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Get story content by ID
|
|
127
|
-
*/
|
|
128
|
-
export function getStoryContent(req, res) {
|
|
129
|
-
try {
|
|
130
|
-
const { id } = req.params;
|
|
131
|
-
const config = loadUserConfig();
|
|
132
|
-
const gitignoreManager = setupProductionGitignore(config);
|
|
133
|
-
const storyService = getInMemoryStoryService(config);
|
|
134
|
-
// First try memory
|
|
135
|
-
const content = storyService.getStoryContent(id);
|
|
136
|
-
if (content) {
|
|
137
|
-
res.setHeader('Content-Type', 'text/plain');
|
|
138
|
-
return res.send(content);
|
|
139
|
-
}
|
|
140
|
-
// In development, try file system
|
|
141
|
-
if (!gitignoreManager.isProductionMode() && config.generatedStoriesPath) {
|
|
142
|
-
const files = fs.readdirSync(config.generatedStoriesPath);
|
|
143
|
-
// Extract hash from story ID
|
|
144
|
-
const hashMatch = id.match(/^story-([a-f0-9]{8})$/);
|
|
145
|
-
const hash = hashMatch ? hashMatch[1] : null;
|
|
146
|
-
const matchingFile = files.find(file => {
|
|
147
|
-
if (hash && file.includes(`-${hash}.stories.tsx`))
|
|
148
|
-
return true;
|
|
149
|
-
if (file === `${id}.stories.tsx`)
|
|
150
|
-
return true;
|
|
151
|
-
if (file === id)
|
|
152
|
-
return true;
|
|
153
|
-
return false;
|
|
154
|
-
});
|
|
155
|
-
if (matchingFile) {
|
|
156
|
-
const filePath = path.join(config.generatedStoriesPath, matchingFile);
|
|
157
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
158
|
-
res.setHeader('Content-Type', 'text/plain');
|
|
159
|
-
return res.send(content);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
res.status(404).json({ error: 'Story content not found' });
|
|
163
|
-
}
|
|
164
|
-
catch (error) {
|
|
165
|
-
console.error('Error in getStoryContent:', error);
|
|
166
|
-
res.status(500).json({ error: 'Failed to retrieve story content' });
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Delete a story by ID
|
|
171
|
-
*/
|
|
172
|
-
export function deleteStory(req, res) {
|
|
173
|
-
try {
|
|
174
|
-
const { id } = req.params;
|
|
175
|
-
const config = loadUserConfig();
|
|
176
|
-
const gitignoreManager = setupProductionGitignore(config);
|
|
177
|
-
const storyService = getInMemoryStoryService(config);
|
|
178
|
-
console.log(`🗑️ Attempting to delete story: ${id}`);
|
|
179
|
-
// First try memory
|
|
180
|
-
const memoryDeleted = storyService.deleteStory(id);
|
|
181
|
-
if (memoryDeleted) {
|
|
182
|
-
console.log(`✅ Deleted story from memory: ${id}`);
|
|
183
|
-
return res.json({ success: true, message: 'Story deleted from memory' });
|
|
184
|
-
}
|
|
185
|
-
// In development, try file system
|
|
186
|
-
if (!gitignoreManager.isProductionMode() && config.generatedStoriesPath) {
|
|
187
|
-
const files = fs.readdirSync(config.generatedStoriesPath);
|
|
188
|
-
// Extract hash from story ID
|
|
189
|
-
const hashMatch = id.match(/^story-([a-f0-9]{8})$/);
|
|
190
|
-
const hash = hashMatch ? hashMatch[1] : null;
|
|
191
|
-
const matchingFile = files.find(file => {
|
|
192
|
-
if (hash && file.includes(`-${hash}.stories.tsx`))
|
|
193
|
-
return true;
|
|
194
|
-
if (file === `${id}.stories.tsx`)
|
|
195
|
-
return true;
|
|
196
|
-
if (file === id)
|
|
197
|
-
return true;
|
|
198
|
-
return false;
|
|
199
|
-
});
|
|
200
|
-
if (matchingFile) {
|
|
201
|
-
const filePath = path.join(config.generatedStoriesPath, matchingFile);
|
|
202
|
-
fs.unlinkSync(filePath);
|
|
203
|
-
console.log(`✅ Deleted story file: ${filePath}`);
|
|
204
|
-
return res.json({ success: true, message: 'Story deleted from file system' });
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
console.log(`❌ Story not found: ${id}`);
|
|
208
|
-
res.status(404).json({ error: 'Story not found' });
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
console.error('Error in deleteStory:', error);
|
|
212
|
-
res.status(500).json({ error: 'Failed to delete story' });
|
|
213
|
-
}
|
|
214
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
/**
|
|
3
|
-
* Get all stories metadata
|
|
4
|
-
*/
|
|
5
|
-
export declare function getStoriesMetadata(req: Request, res: Response): void;
|
|
6
|
-
/**
|
|
7
|
-
* Get a specific story by ID
|
|
8
|
-
*/
|
|
9
|
-
export declare function getStoryById(req: Request, res: Response): Response<any, Record<string, any>> | undefined;
|
|
10
|
-
/**
|
|
11
|
-
* Get story content for Storybook integration
|
|
12
|
-
*/
|
|
13
|
-
export declare function getStoryContent(req: Request, res: Response): Response<any, Record<string, any>> | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Delete a story by ID
|
|
16
|
-
*/
|
|
17
|
-
export declare function deleteStory(req: Request, res: Response): Response<any, Record<string, any>> | undefined;
|
|
18
|
-
/**
|
|
19
|
-
* Clear all stories
|
|
20
|
-
*/
|
|
21
|
-
export declare function clearAllStories(req: Request, res: Response): void;
|
|
22
|
-
/**
|
|
23
|
-
* Get memory usage statistics
|
|
24
|
-
*/
|
|
25
|
-
export declare function getMemoryStats(req: Request, res: Response): void;
|
|
26
|
-
//# sourceMappingURL=memoryStories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memoryStories.d.ts","sourceRoot":"","sources":["../../../mcp-server/routes/memoryStories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,QAiB7D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,kDAwBvD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,kDAuB1D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,kDAwBtD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,QAgB1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,QAoBzD"}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { getInMemoryStoryService } from '../../story-generator/inMemoryStoryService.js';
|
|
2
|
-
import { loadUserConfig } from '../../story-generator/configLoader.js';
|
|
3
|
-
/**
|
|
4
|
-
* Get all stories metadata
|
|
5
|
-
*/
|
|
6
|
-
export function getStoriesMetadata(req, res) {
|
|
7
|
-
try {
|
|
8
|
-
const config = loadUserConfig();
|
|
9
|
-
const storyService = getInMemoryStoryService(config);
|
|
10
|
-
const metadata = storyService.getStoryMetadata();
|
|
11
|
-
res.json({
|
|
12
|
-
success: true,
|
|
13
|
-
stories: metadata,
|
|
14
|
-
count: metadata.length
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
res.status(500).json({
|
|
19
|
-
success: false,
|
|
20
|
-
error: 'Failed to retrieve stories metadata'
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Get a specific story by ID
|
|
26
|
-
*/
|
|
27
|
-
export function getStoryById(req, res) {
|
|
28
|
-
try {
|
|
29
|
-
const { id } = req.params;
|
|
30
|
-
const config = loadUserConfig();
|
|
31
|
-
const storyService = getInMemoryStoryService(config);
|
|
32
|
-
const story = storyService.getStory(id);
|
|
33
|
-
if (!story) {
|
|
34
|
-
return res.status(404).json({
|
|
35
|
-
success: false,
|
|
36
|
-
error: 'Story not found'
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
res.json({
|
|
40
|
-
success: true,
|
|
41
|
-
story
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
catch (error) {
|
|
45
|
-
res.status(500).json({
|
|
46
|
-
success: false,
|
|
47
|
-
error: 'Failed to retrieve story'
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Get story content for Storybook integration
|
|
53
|
-
*/
|
|
54
|
-
export function getStoryContent(req, res) {
|
|
55
|
-
try {
|
|
56
|
-
const { id } = req.params;
|
|
57
|
-
const config = loadUserConfig();
|
|
58
|
-
const storyService = getInMemoryStoryService(config);
|
|
59
|
-
const content = storyService.getStoryContent(id);
|
|
60
|
-
if (!content) {
|
|
61
|
-
return res.status(404).json({
|
|
62
|
-
success: false,
|
|
63
|
-
error: 'Story content not found'
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
// Return as TypeScript/JSX content
|
|
67
|
-
res.setHeader('Content-Type', 'text/plain');
|
|
68
|
-
res.send(content);
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
res.status(500).json({
|
|
72
|
-
success: false,
|
|
73
|
-
error: 'Failed to retrieve story content'
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Delete a story by ID
|
|
79
|
-
*/
|
|
80
|
-
export function deleteStory(req, res) {
|
|
81
|
-
try {
|
|
82
|
-
const { id } = req.params;
|
|
83
|
-
const config = loadUserConfig();
|
|
84
|
-
const storyService = getInMemoryStoryService(config);
|
|
85
|
-
const deleted = storyService.deleteStory(id);
|
|
86
|
-
if (!deleted) {
|
|
87
|
-
return res.status(404).json({
|
|
88
|
-
success: false,
|
|
89
|
-
error: 'Story not found'
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
res.json({
|
|
93
|
-
success: true,
|
|
94
|
-
message: 'Story deleted successfully'
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
res.status(500).json({
|
|
99
|
-
success: false,
|
|
100
|
-
error: 'Failed to delete story'
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Clear all stories
|
|
106
|
-
*/
|
|
107
|
-
export function clearAllStories(req, res) {
|
|
108
|
-
try {
|
|
109
|
-
const config = loadUserConfig();
|
|
110
|
-
const storyService = getInMemoryStoryService(config);
|
|
111
|
-
storyService.clearAllStories();
|
|
112
|
-
res.json({
|
|
113
|
-
success: true,
|
|
114
|
-
message: 'All stories cleared successfully'
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
res.status(500).json({
|
|
119
|
-
success: false,
|
|
120
|
-
error: 'Failed to clear stories'
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Get memory usage statistics
|
|
126
|
-
*/
|
|
127
|
-
export function getMemoryStats(req, res) {
|
|
128
|
-
try {
|
|
129
|
-
const config = loadUserConfig();
|
|
130
|
-
const storyService = getInMemoryStoryService(config);
|
|
131
|
-
const stats = storyService.getMemoryStats();
|
|
132
|
-
res.json({
|
|
133
|
-
success: true,
|
|
134
|
-
stats: {
|
|
135
|
-
...stats,
|
|
136
|
-
totalSizeMB: Math.round(stats.totalSizeBytes / 1024 / 1024 * 100) / 100,
|
|
137
|
-
averageSizeKB: Math.round(stats.averageSizeBytes / 1024 * 100) / 100
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
res.status(500).json({
|
|
143
|
-
success: false,
|
|
144
|
-
error: 'Failed to retrieve memory statistics'
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
/**
|
|
3
|
-
* Get all synchronized stories (from both file system and memory)
|
|
4
|
-
*/
|
|
5
|
-
export declare function getSyncedStories(req: Request, res: Response): Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* Delete a story from both file system and memory
|
|
8
|
-
*/
|
|
9
|
-
export declare function deleteSyncedStory(req: Request, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
|
|
10
|
-
/**
|
|
11
|
-
* Clear all stories from both file system and memory
|
|
12
|
-
*/
|
|
13
|
-
export declare function clearAllSyncedStories(req: Request, res: Response): Promise<void>;
|
|
14
|
-
/**
|
|
15
|
-
* Sync chat history with actual stories
|
|
16
|
-
*/
|
|
17
|
-
export declare function syncChatHistory(req: Request, res: Response): Promise<void>;
|
|
18
|
-
/**
|
|
19
|
-
* Validate that a chat session corresponds to an actual story
|
|
20
|
-
*/
|
|
21
|
-
export declare function validateChatSession(req: Request, res: Response): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Get a specific synced story by ID
|
|
24
|
-
*/
|
|
25
|
-
export declare function getSyncedStoryById(req: Request, res: Response): Promise<Response<any, Record<string, any>> | undefined>;
|
|
26
|
-
//# sourceMappingURL=storySync.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storySync.d.ts","sourceRoot":"","sources":["../../../mcp-server/routes/storySync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,iBAyBjE;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,2DAwBlE;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,iBAgBtE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,iBAgBhE;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,iBAkBpE;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,2DAwBnE"}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { getStorySyncService } from '../../story-generator/storySync.js';
|
|
2
|
-
import { loadUserConfig } from '../../story-generator/configLoader.js';
|
|
3
|
-
/**
|
|
4
|
-
* Get all synchronized stories (from both file system and memory)
|
|
5
|
-
*/
|
|
6
|
-
export async function getSyncedStories(req, res) {
|
|
7
|
-
try {
|
|
8
|
-
const config = loadUserConfig();
|
|
9
|
-
const syncService = getStorySyncService(config);
|
|
10
|
-
const stories = await syncService.getAllStories();
|
|
11
|
-
res.json({
|
|
12
|
-
success: true,
|
|
13
|
-
stories: stories.map(story => ({
|
|
14
|
-
id: story.id,
|
|
15
|
-
title: story.title,
|
|
16
|
-
fileName: story.fileName,
|
|
17
|
-
description: story.description,
|
|
18
|
-
createdAt: story.createdAt,
|
|
19
|
-
lastAccessed: story.lastAccessed,
|
|
20
|
-
source: story.source
|
|
21
|
-
})),
|
|
22
|
-
count: stories.length
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
res.status(500).json({
|
|
27
|
-
success: false,
|
|
28
|
-
error: 'Failed to retrieve synchronized stories'
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Delete a story from both file system and memory
|
|
34
|
-
*/
|
|
35
|
-
export async function deleteSyncedStory(req, res) {
|
|
36
|
-
try {
|
|
37
|
-
const { id } = req.params;
|
|
38
|
-
const config = loadUserConfig();
|
|
39
|
-
const syncService = getStorySyncService(config);
|
|
40
|
-
const deleted = await syncService.deleteStory(id);
|
|
41
|
-
if (!deleted) {
|
|
42
|
-
return res.status(404).json({
|
|
43
|
-
success: false,
|
|
44
|
-
error: 'Story not found'
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
res.json({
|
|
48
|
-
success: true,
|
|
49
|
-
message: 'Story deleted successfully from all sources'
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
res.status(500).json({
|
|
54
|
-
success: false,
|
|
55
|
-
error: 'Failed to delete story'
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Clear all stories from both file system and memory
|
|
61
|
-
*/
|
|
62
|
-
export async function clearAllSyncedStories(req, res) {
|
|
63
|
-
try {
|
|
64
|
-
const config = loadUserConfig();
|
|
65
|
-
const syncService = getStorySyncService(config);
|
|
66
|
-
await syncService.clearAllStories();
|
|
67
|
-
res.json({
|
|
68
|
-
success: true,
|
|
69
|
-
message: 'All stories cleared successfully'
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
catch (error) {
|
|
73
|
-
res.status(500).json({
|
|
74
|
-
success: false,
|
|
75
|
-
error: 'Failed to clear stories'
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Sync chat history with actual stories
|
|
81
|
-
*/
|
|
82
|
-
export async function syncChatHistory(req, res) {
|
|
83
|
-
try {
|
|
84
|
-
const config = loadUserConfig();
|
|
85
|
-
const syncService = getStorySyncService(config);
|
|
86
|
-
const syncResult = await syncService.syncChatHistory();
|
|
87
|
-
res.json({
|
|
88
|
-
success: true,
|
|
89
|
-
...syncResult
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
res.status(500).json({
|
|
94
|
-
success: false,
|
|
95
|
-
error: 'Failed to sync chat history'
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Validate that a chat session corresponds to an actual story
|
|
101
|
-
*/
|
|
102
|
-
export async function validateChatSession(req, res) {
|
|
103
|
-
try {
|
|
104
|
-
const { id } = req.params;
|
|
105
|
-
const config = loadUserConfig();
|
|
106
|
-
const syncService = getStorySyncService(config);
|
|
107
|
-
const isValid = await syncService.validateChatSession(id);
|
|
108
|
-
res.json({
|
|
109
|
-
success: true,
|
|
110
|
-
isValid,
|
|
111
|
-
message: isValid ? 'Chat session is valid' : 'Chat session has no corresponding story'
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
catch (error) {
|
|
115
|
-
res.status(500).json({
|
|
116
|
-
success: false,
|
|
117
|
-
error: 'Failed to validate chat session'
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Get a specific synced story by ID
|
|
123
|
-
*/
|
|
124
|
-
export async function getSyncedStoryById(req, res) {
|
|
125
|
-
try {
|
|
126
|
-
const { id } = req.params;
|
|
127
|
-
const config = loadUserConfig();
|
|
128
|
-
const syncService = getStorySyncService(config);
|
|
129
|
-
const story = await syncService.getStory(id);
|
|
130
|
-
if (!story) {
|
|
131
|
-
return res.status(404).json({
|
|
132
|
-
success: false,
|
|
133
|
-
error: 'Story not found'
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
res.json({
|
|
137
|
-
success: true,
|
|
138
|
-
story
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
res.status(500).json({
|
|
143
|
-
success: false,
|
|
144
|
-
error: 'Failed to retrieve story'
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|