@studyllm/resume-preview 0.0.0-stage → 3.1.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/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +313 -2
- package/build/constants.js +217 -0
- package/build/diagram-service.js +143 -0
- package/build/file-utils.js +350 -0
- package/build/handlers.js +172 -0
- package/build/html-utils.js +20 -0
- package/build/i18n.js +198 -0
- package/build/index.js +171 -0
- package/build/live-server.js +488 -0
- package/build/logger.js +92 -0
- package/build/mermaid-cli.js +48 -0
- package/build/page-renderer.js +152 -0
- package/build/preview/favicon.svg +23 -0
- package/build/preview/gallery.css +217 -0
- package/build/preview/gallery.html +59 -0
- package/build/preview/gallery.js +259 -0
- package/build/preview/i18n/en.json +57 -0
- package/build/preview/i18n/zh-CN.json +57 -0
- package/build/preview/i18n.js +125 -0
- package/build/preview/resume-template.html +13 -0
- package/build/preview/resume.css +214 -0
- package/build/preview/resume.js +393 -0
- package/build/preview/shared.css +529 -0
- package/build/resume-renderer.js +486 -0
- package/build/resume-service.js +117 -0
- package/build/routes.js +335 -0
- package/build/serve.js +46 -0
- package/build/types.js +5 -0
- package/package.json +63 -4
package/build/i18n.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internationalization
|
|
3
|
+
* Single Responsibility: resolve a locale and look up translated strings.
|
|
4
|
+
*
|
|
5
|
+
* Two locale axes live here:
|
|
6
|
+
* - the UI language, resolved per request from the query string or the
|
|
7
|
+
* Accept-Language header;
|
|
8
|
+
* - the resume language, persisted per resume in options.json.
|
|
9
|
+
*
|
|
10
|
+
* The dictionaries are plain JSON files shared by the server and the browser,
|
|
11
|
+
* so a key can never exist on one side only.
|
|
12
|
+
*/
|
|
13
|
+
import { readFile } from "fs/promises";
|
|
14
|
+
import { join, dirname } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
import { SUPPORTED_LOCALES, DEFAULT_UI_LOCALE, FALLBACK_LOCALE, I18N_DIR, I18N_FILE_SUFFIX, LOCALE_LABEL_KEYS, } from "./constants.js";
|
|
17
|
+
import { webLogger } from "./logger.js";
|
|
18
|
+
import { escapeHtml } from "./html-utils.js";
|
|
19
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
20
|
+
const __dirname = dirname(__filename);
|
|
21
|
+
const DICTIONARY_DIR = join(__dirname, "preview", I18N_DIR);
|
|
22
|
+
const rawCache = new Map();
|
|
23
|
+
const mergedCache = new Map();
|
|
24
|
+
export function isSupportedLocale(value) {
|
|
25
|
+
return typeof value === "string" && SUPPORTED_LOCALES.includes(value);
|
|
26
|
+
}
|
|
27
|
+
function isDictionary(value) {
|
|
28
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Loads one dictionary file. A missing or broken file yields an empty
|
|
32
|
+
* dictionary rather than an exception — a missing translation must never
|
|
33
|
+
* take the page down.
|
|
34
|
+
*/
|
|
35
|
+
async function loadRawDictionary(locale) {
|
|
36
|
+
const cached = rawCache.get(locale);
|
|
37
|
+
if (cached)
|
|
38
|
+
return cached;
|
|
39
|
+
let dictionary = {};
|
|
40
|
+
try {
|
|
41
|
+
const content = await readFile(getDictionaryFilePath(locale), "utf-8");
|
|
42
|
+
dictionary = JSON.parse(content);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
webLogger.warn(`Failed to load dictionary for locale: ${locale}`, {
|
|
46
|
+
error: error instanceof Error ? error.message : String(error),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
rawCache.set(locale, dictionary);
|
|
50
|
+
return dictionary;
|
|
51
|
+
}
|
|
52
|
+
function mergeDictionaries(base, overlay) {
|
|
53
|
+
const result = { ...base };
|
|
54
|
+
for (const [key, value] of Object.entries(overlay)) {
|
|
55
|
+
const existing = result[key];
|
|
56
|
+
if (isDictionary(existing) && isDictionary(value)) {
|
|
57
|
+
result[key] = mergeDictionaries(existing, value);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
result[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the dictionary for a locale, with the fallback language merged
|
|
67
|
+
* underneath it. A key missing from the requested language falls back to the
|
|
68
|
+
* fallback language rather than showing the raw key.
|
|
69
|
+
*/
|
|
70
|
+
export async function getDictionary(locale) {
|
|
71
|
+
const cached = mergedCache.get(locale);
|
|
72
|
+
if (cached)
|
|
73
|
+
return cached;
|
|
74
|
+
const fallback = await loadRawDictionary(FALLBACK_LOCALE);
|
|
75
|
+
const overlay = locale === FALLBACK_LOCALE ? {} : await loadRawDictionary(locale);
|
|
76
|
+
const merged = mergeDictionaries(fallback, overlay);
|
|
77
|
+
mergedCache.set(locale, merged);
|
|
78
|
+
return merged;
|
|
79
|
+
}
|
|
80
|
+
function lookup(dictionary, key) {
|
|
81
|
+
let current = dictionary;
|
|
82
|
+
for (const part of key.split(".")) {
|
|
83
|
+
if (!isDictionary(current))
|
|
84
|
+
return undefined;
|
|
85
|
+
current = current[part];
|
|
86
|
+
}
|
|
87
|
+
return typeof current === "string" ? current : undefined;
|
|
88
|
+
}
|
|
89
|
+
function interpolate(template, vars) {
|
|
90
|
+
if (!vars)
|
|
91
|
+
return template;
|
|
92
|
+
return template.replace(/\{(\w+)\}/g, (match, name) => {
|
|
93
|
+
const value = vars[name];
|
|
94
|
+
return value === undefined ? match : String(value);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Looks up a dotted key and substitutes `{placeholders}`.
|
|
99
|
+
* Returns the key itself when the dictionary has no such entry.
|
|
100
|
+
*/
|
|
101
|
+
export function t(dictionary, key, vars) {
|
|
102
|
+
const raw = lookup(dictionary, key);
|
|
103
|
+
if (raw === undefined)
|
|
104
|
+
return key;
|
|
105
|
+
return interpolate(raw, vars);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The value for the `<html lang>` attribute. Falls back to the locale code.
|
|
109
|
+
*/
|
|
110
|
+
export function getHtmlLang(dictionary, locale) {
|
|
111
|
+
return lookup(dictionary, "meta.htmlLang") ?? locale;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Matches a language tag against the supported locales.
|
|
115
|
+
* "en" and "en-US" both resolve to "en"; "zh" resolves to "zh-CN".
|
|
116
|
+
*/
|
|
117
|
+
export function matchLocale(tag) {
|
|
118
|
+
const trimmed = tag.trim();
|
|
119
|
+
if (!trimmed)
|
|
120
|
+
return null;
|
|
121
|
+
if (isSupportedLocale(trimmed))
|
|
122
|
+
return trimmed;
|
|
123
|
+
const prefix = trimmed.split("-")[0].toLowerCase();
|
|
124
|
+
const matched = SUPPORTED_LOCALES.find((locale) => locale.split("-")[0].toLowerCase() === prefix);
|
|
125
|
+
return matched ?? null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parses an Accept-Language header and returns the first supported locale.
|
|
129
|
+
*/
|
|
130
|
+
export function parseAcceptLanguage(header) {
|
|
131
|
+
if (!header)
|
|
132
|
+
return null;
|
|
133
|
+
const candidates = header.split(",").map((part, index) => {
|
|
134
|
+
const [tag, ...params] = part.trim().split(";");
|
|
135
|
+
const qParam = params.find((param) => param.trim().startsWith("q="));
|
|
136
|
+
const parsed = qParam ? Number.parseFloat(qParam.trim().slice(2)) : 1;
|
|
137
|
+
return {
|
|
138
|
+
tag: tag.trim(),
|
|
139
|
+
quality: Number.isFinite(parsed) ? parsed : 0,
|
|
140
|
+
index,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
candidates.sort((a, b) => b.quality - a.quality || a.index - b.index);
|
|
144
|
+
for (const candidate of candidates) {
|
|
145
|
+
const locale = matchLocale(candidate.tag);
|
|
146
|
+
if (locale)
|
|
147
|
+
return locale;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Resolves the UI locale: the query parameter wins, then the header, then
|
|
153
|
+
* the default. An unsupported query value is ignored rather than rejected —
|
|
154
|
+
* a bad query parameter must not turn into an error page.
|
|
155
|
+
*/
|
|
156
|
+
export function resolveLocale(hints = {}) {
|
|
157
|
+
const fromQuery = hints.query ? matchLocale(hints.query) : null;
|
|
158
|
+
if (fromQuery)
|
|
159
|
+
return fromQuery;
|
|
160
|
+
const fromHeader = parseAcceptLanguage(hints.acceptLanguage);
|
|
161
|
+
if (fromHeader)
|
|
162
|
+
return fromHeader;
|
|
163
|
+
return DEFAULT_UI_LOCALE;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The path of a dictionary file. The locale must already be whitelisted —
|
|
167
|
+
* this value is joined into a path and must never carry user input.
|
|
168
|
+
*/
|
|
169
|
+
export function getDictionaryFilePath(locale) {
|
|
170
|
+
return join(DICTIONARY_DIR, `${locale}${I18N_FILE_SUFFIX}`);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Renders the language switcher: one link per supported language, pointing
|
|
174
|
+
* at the current page with the `lang` query parameter replaced.
|
|
175
|
+
*
|
|
176
|
+
* The links work without JavaScript. The client refines them afterwards to
|
|
177
|
+
* keep the other query parameters of the current URL.
|
|
178
|
+
*/
|
|
179
|
+
export function renderLanguageSwitcher(dictionary, locale, path) {
|
|
180
|
+
const groupLabel = escapeHtml(t(dictionary, "common.switchLanguage"));
|
|
181
|
+
const options = SUPPORTED_LOCALES.map((option) => {
|
|
182
|
+
const labelKey = LOCALE_LABEL_KEYS[option] ?? "meta.label";
|
|
183
|
+
const text = escapeHtml(t(dictionary, labelKey));
|
|
184
|
+
const active = option === locale;
|
|
185
|
+
const current = active ? ' aria-current="true"' : "";
|
|
186
|
+
const activeClass = active ? " is-active" : "";
|
|
187
|
+
return `<a class="lang-option${activeClass}" href="${escapeHtml(path)}?lang=${encodeURIComponent(option)}" hreflang="${option}" lang="${option}"${current}>${text}</a>`;
|
|
188
|
+
}).join("");
|
|
189
|
+
return `<div class="lang-switch" role="group" aria-label="${groupLabel}">${options}</div>`;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Clears the dictionary caches. Useful in tests and development.
|
|
193
|
+
*/
|
|
194
|
+
export function clearDictionaryCache() {
|
|
195
|
+
rawCache.clear();
|
|
196
|
+
mergedCache.clear();
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=i18n.js.map
|
package/build/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { readFile } from "fs/promises";
|
|
6
|
+
import { join, dirname } from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
import { handleResumePreview, handleResumeExport } from "./handlers.js";
|
|
9
|
+
import { migrateLegacyAppDir } from "./file-utils.js";
|
|
10
|
+
import { RESUME_TEMPLATES, RESUME_THEMES, RESUME_FORMATS, SUPPORTED_LOCALES, DEFAULT_RESUME_TEMPLATE, DEFAULT_RESUME_THEME, DEFAULT_RESUME_FORMAT, DEFAULT_RESUME_LOCALE, } from "./constants.js";
|
|
11
|
+
import { mcpLogger } from "./logger.js";
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
const packageJson = JSON.parse(await readFile(join(__dirname, "../package.json"), "utf-8"));
|
|
15
|
+
const VERSION = packageJson.version;
|
|
16
|
+
if (process.argv.includes("-v") || process.argv.includes("--version")) {
|
|
17
|
+
console.log(VERSION);
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
const isServeMode = process.argv.includes("--serve");
|
|
21
|
+
// One-time migration of the pre-rename data directory. Runs before anything
|
|
22
|
+
// reads or writes under the app directory.
|
|
23
|
+
await migrateLegacyAppDir();
|
|
24
|
+
if (isServeMode) {
|
|
25
|
+
const { startServeMode } = await import("./serve.js");
|
|
26
|
+
await startServeMode();
|
|
27
|
+
}
|
|
28
|
+
const TOOL_DEFINITIONS = [
|
|
29
|
+
{
|
|
30
|
+
name: "resume_preview",
|
|
31
|
+
description: "Render a resume from structured content and open it in the browser with live reload. " +
|
|
32
|
+
"The content is rendered as an A4 page and the browser refreshes automatically every time " +
|
|
33
|
+
"the content is updated, so you can iterate on the wording without re-exporting. " +
|
|
34
|
+
"All content is rendered as plain text — HTML in the content is escaped, not interpreted. " +
|
|
35
|
+
"The `locale` parameter sets the language of the section headings and of the exported document; " +
|
|
36
|
+
"match it to the language of the job posting. " +
|
|
37
|
+
"Use resume_export to save the result as PDF or HTML. " +
|
|
38
|
+
"IMPORTANT: Automatically use this tool whenever you produce or revise a resume for the user.",
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: "object",
|
|
41
|
+
properties: {
|
|
42
|
+
resume_id: {
|
|
43
|
+
type: "string",
|
|
44
|
+
description: "ID for this resume. May contain Chinese characters; the storage name is derived from it. Use different IDs for multiple resumes.",
|
|
45
|
+
},
|
|
46
|
+
content: {
|
|
47
|
+
description: "The resume content, either as an object or as a JSON string containing the same object. " +
|
|
48
|
+
"Fields: basics {name, title, email, phone, location, links[{label,url}]}, summary, " +
|
|
49
|
+
"experience[{company,title,start,end,location,highlights[]}], " +
|
|
50
|
+
"projects[{name,role,period,highlights[]}], " +
|
|
51
|
+
"education[{school,degree,period,highlights[]}], " +
|
|
52
|
+
"skills[{category,items[]}], extras[{label,items[]}]. " +
|
|
53
|
+
"Only basics.name is required; every other section is omitted when missing.",
|
|
54
|
+
anyOf: [{ type: "object" }, { type: "string" }],
|
|
55
|
+
},
|
|
56
|
+
template: {
|
|
57
|
+
type: "string",
|
|
58
|
+
enum: [...RESUME_TEMPLATES],
|
|
59
|
+
description: `Layout template of the resume (default: ${DEFAULT_RESUME_TEMPLATE})`,
|
|
60
|
+
default: DEFAULT_RESUME_TEMPLATE,
|
|
61
|
+
},
|
|
62
|
+
theme: {
|
|
63
|
+
type: "string",
|
|
64
|
+
enum: [...RESUME_THEMES],
|
|
65
|
+
description: `Color and font theme of the resume (default: ${DEFAULT_RESUME_THEME})`,
|
|
66
|
+
default: DEFAULT_RESUME_THEME,
|
|
67
|
+
},
|
|
68
|
+
locale: {
|
|
69
|
+
type: "string",
|
|
70
|
+
enum: [...SUPPORTED_LOCALES],
|
|
71
|
+
description: `Language of the resume itself — the section headings and the exported document ` +
|
|
72
|
+
`(default: ${DEFAULT_RESUME_LOCALE}). Independent of the language of the browser UI. ` +
|
|
73
|
+
`Omit it to keep the language the resume was last rendered in.`,
|
|
74
|
+
default: DEFAULT_RESUME_LOCALE,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
required: ["resume_id", "content"],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "resume_export",
|
|
82
|
+
description: "Save the current resume to a file path. " +
|
|
83
|
+
"Renders on demand when the artifact does not exist yet, and re-renders " +
|
|
84
|
+
"whenever the content changed since the last export. " +
|
|
85
|
+
"The file extension must match the requested format. " +
|
|
86
|
+
"PDF export requires a Chinese font to be installed on the machine when the " +
|
|
87
|
+
"document contains Chinese characters.",
|
|
88
|
+
inputSchema: {
|
|
89
|
+
type: "object",
|
|
90
|
+
properties: {
|
|
91
|
+
resume_id: {
|
|
92
|
+
type: "string",
|
|
93
|
+
description: "ID of the resume to export. Must match the resume_id used in resume_preview.",
|
|
94
|
+
},
|
|
95
|
+
save_path: {
|
|
96
|
+
type: "string",
|
|
97
|
+
description: "Path to save the resume file (e.g. './docs/resume.pdf'). The extension must match the format.",
|
|
98
|
+
},
|
|
99
|
+
format: {
|
|
100
|
+
type: "string",
|
|
101
|
+
enum: [...RESUME_FORMATS],
|
|
102
|
+
description: `Output format (default: ${DEFAULT_RESUME_FORMAT})`,
|
|
103
|
+
default: DEFAULT_RESUME_FORMAT,
|
|
104
|
+
},
|
|
105
|
+
refresh: {
|
|
106
|
+
type: "boolean",
|
|
107
|
+
description: "Re-render the artifact even if a cached one exists. Use when the content was changed outside of resume_preview.",
|
|
108
|
+
default: false,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
required: ["save_path", "resume_id"],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
const server = new Server({
|
|
116
|
+
name: "resume-preview",
|
|
117
|
+
version: VERSION,
|
|
118
|
+
}, {
|
|
119
|
+
capabilities: {
|
|
120
|
+
tools: {},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
124
|
+
mcpLogger.debug("ListTools request received");
|
|
125
|
+
return { tools: TOOL_DEFINITIONS };
|
|
126
|
+
});
|
|
127
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
128
|
+
const toolName = request.params.name;
|
|
129
|
+
const args = request.params.arguments;
|
|
130
|
+
mcpLogger.info(`CallTool request: ${toolName}`);
|
|
131
|
+
try {
|
|
132
|
+
let result;
|
|
133
|
+
switch (toolName) {
|
|
134
|
+
case "resume_preview":
|
|
135
|
+
result = await handleResumePreview(args);
|
|
136
|
+
mcpLogger.info(`CallTool completed: ${toolName}`);
|
|
137
|
+
return result;
|
|
138
|
+
case "resume_export":
|
|
139
|
+
result = await handleResumeExport(args);
|
|
140
|
+
mcpLogger.info(`CallTool completed: ${toolName}`);
|
|
141
|
+
return result;
|
|
142
|
+
default:
|
|
143
|
+
mcpLogger.error(`Unknown tool: ${toolName}`);
|
|
144
|
+
throw new Error(`Unknown tool: ${toolName}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
mcpLogger.error(`Tool ${toolName} failed`, {
|
|
149
|
+
error: error instanceof Error ? error.message : String(error),
|
|
150
|
+
});
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
async function main() {
|
|
155
|
+
mcpLogger.info("MCP Server starting", { version: VERSION });
|
|
156
|
+
const transport = new StdioServerTransport();
|
|
157
|
+
await server.connect(transport);
|
|
158
|
+
mcpLogger.info("MCP Server connected via stdio");
|
|
159
|
+
console.error("Resume Preview MCP Server running on stdio");
|
|
160
|
+
}
|
|
161
|
+
if (!isServeMode) {
|
|
162
|
+
main().catch((error) => {
|
|
163
|
+
mcpLogger.error("Fatal error during startup", {
|
|
164
|
+
error: error instanceof Error ? error.message : String(error),
|
|
165
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
166
|
+
});
|
|
167
|
+
console.error("Fatal error:", error);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=index.js.map
|