@llmindset/hf-mcp 0.2.33 → 0.2.35
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/dist/docs-search/docs-semantic-search.js +1 -1
- package/dist/docs-search/docs-semantic-search.js.map +1 -1
- package/dist/hf-api-call.d.ts.map +1 -1
- package/dist/hf-api-call.js +4 -0
- package/dist/hf-api-call.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/api-client.d.ts +19 -0
- package/dist/jobs/api-client.d.ts.map +1 -0
- package/dist/jobs/api-client.js +95 -0
- package/dist/jobs/api-client.js.map +1 -0
- package/dist/jobs/commands/inspect.d.ts +5 -0
- package/dist/jobs/commands/inspect.d.ts.map +1 -0
- package/dist/jobs/commands/inspect.js +21 -0
- package/dist/jobs/commands/inspect.js.map +1 -0
- package/dist/jobs/commands/logs.d.ts +4 -0
- package/dist/jobs/commands/logs.d.ts.map +1 -0
- package/dist/jobs/commands/logs.js +24 -0
- package/dist/jobs/commands/logs.js.map +1 -0
- package/dist/jobs/commands/ps.d.ts +4 -0
- package/dist/jobs/commands/ps.d.ts.map +1 -0
- package/dist/jobs/commands/ps.js +23 -0
- package/dist/jobs/commands/ps.js.map +1 -0
- package/dist/jobs/commands/run.d.ts +5 -0
- package/dist/jobs/commands/run.d.ts.map +1 -0
- package/dist/jobs/commands/run.js +90 -0
- package/dist/jobs/commands/run.js.map +1 -0
- package/dist/jobs/commands/scheduled.d.ts +10 -0
- package/dist/jobs/commands/scheduled.d.ts.map +1 -0
- package/dist/jobs/commands/scheduled.js +112 -0
- package/dist/jobs/commands/scheduled.js.map +1 -0
- package/dist/jobs/commands/utils.d.ts +20 -0
- package/dist/jobs/commands/utils.d.ts.map +1 -0
- package/dist/jobs/commands/utils.js +120 -0
- package/dist/jobs/commands/utils.js.map +1 -0
- package/dist/jobs/formatters.d.ts +6 -0
- package/dist/jobs/formatters.d.ts.map +1 -0
- package/dist/jobs/formatters.js +98 -0
- package/dist/jobs/formatters.js.map +1 -0
- package/dist/jobs/sse-handler.d.ts +12 -0
- package/dist/jobs/sse-handler.d.ts.map +1 -0
- package/dist/jobs/sse-handler.js +80 -0
- package/dist/jobs/sse-handler.js.map +1 -0
- package/dist/jobs/tool.d.ts +35 -0
- package/dist/jobs/tool.d.ts.map +1 -0
- package/dist/jobs/tool.js +333 -0
- package/dist/jobs/tool.js.map +1 -0
- package/dist/jobs/types.d.ts +295 -0
- package/dist/jobs/types.d.ts.map +1 -0
- package/dist/jobs/types.js +95 -0
- package/dist/jobs/types.js.map +1 -0
- package/dist/tool-ids.d.ts +3 -2
- package/dist/tool-ids.d.ts.map +1 -1
- package/dist/tool-ids.js +10 -2
- package/dist/tool-ids.js.map +1 -1
- package/dist/types/tool-result.d.ts +1 -0
- package/dist/types/tool-result.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/docs-search/docs-semantic-search.ts +1 -1
- package/src/hf-api-call.ts +6 -0
- package/src/index.ts +1 -0
- package/src/jobs/api-client.ts +187 -0
- package/src/jobs/commands/inspect.ts +38 -0
- package/src/jobs/commands/logs.ts +36 -0
- package/src/jobs/commands/ps.ts +40 -0
- package/src/jobs/commands/run.ts +135 -0
- package/src/jobs/commands/scheduled.ts +198 -0
- package/src/jobs/commands/utils.ts +191 -0
- package/src/jobs/formatters.ts +149 -0
- package/src/jobs/sse-handler.ts +144 -0
- package/src/jobs/tool.ts +435 -0
- package/src/jobs/types.ts +237 -0
- package/src/tool-ids.ts +11 -1
- package/src/types/tool-result.ts +6 -0
- package/test/jobs/command-translation.spec.ts +331 -0
- package/test/jobs/formatters.spec.ts +267 -0
- package/test/jobs/uv-command.spec.ts +81 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const CPU_FLAVORS = ['cpu-basic', 'cpu-upgrade', 'cpu-performance', 'cpu-xl'];
|
|
3
|
+
export const GPU_FLAVORS = [
|
|
4
|
+
'sprx8',
|
|
5
|
+
'zero-a10g',
|
|
6
|
+
't4-small',
|
|
7
|
+
't4-medium',
|
|
8
|
+
'l4x1',
|
|
9
|
+
'l4x4',
|
|
10
|
+
'l40sx1',
|
|
11
|
+
'l40sx4',
|
|
12
|
+
'l40sx8',
|
|
13
|
+
'a10g-small',
|
|
14
|
+
'a10g-large',
|
|
15
|
+
'a10g-largex2',
|
|
16
|
+
'a10g-largex4',
|
|
17
|
+
'a100-large',
|
|
18
|
+
'h100',
|
|
19
|
+
'h100x8',
|
|
20
|
+
];
|
|
21
|
+
export const SPECIALIZED_FLAVORS = ['inf2x6'];
|
|
22
|
+
export const ALL_FLAVORS = [...CPU_FLAVORS, ...GPU_FLAVORS, ...SPECIALIZED_FLAVORS];
|
|
23
|
+
const commonArgsSchema = z.object({
|
|
24
|
+
namespace: z.string().optional().describe('Target namespace (username or organization). Defaults to current user.'),
|
|
25
|
+
});
|
|
26
|
+
export const runArgsSchema = commonArgsSchema.extend({
|
|
27
|
+
image: z.string().describe('Docker image or HF Space URL (e.g., "python:3.12" or "hf.co/spaces/user/space")'),
|
|
28
|
+
command: z
|
|
29
|
+
.union([z.string(), z.array(z.string())])
|
|
30
|
+
.describe('Command to execute. Array format recommended (e.g., ["python", "script.py"]). ' +
|
|
31
|
+
'String format is parsed with POSIX shell semantics (quotes, escaping). ' +
|
|
32
|
+
'For multiline scripts, use array with newlines in arguments.'),
|
|
33
|
+
flavor: z
|
|
34
|
+
.enum(ALL_FLAVORS)
|
|
35
|
+
.optional()
|
|
36
|
+
.default('cpu-basic')
|
|
37
|
+
.describe(`Hardware flavor. Options: ${ALL_FLAVORS.join(', ')}`),
|
|
38
|
+
env: z.record(z.string()).optional().describe('Environment variables as key-value pairs'),
|
|
39
|
+
secrets: z.record(z.string()).optional().describe('Secret environment variables (encrypted server-side)'),
|
|
40
|
+
timeout: z
|
|
41
|
+
.string()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe('Max duration (e.g., "5m", "2h", "30s"). Default: 30m')
|
|
44
|
+
.default('30m'),
|
|
45
|
+
detach: z
|
|
46
|
+
.boolean()
|
|
47
|
+
.optional()
|
|
48
|
+
.default(true)
|
|
49
|
+
.describe('Run in background and return immediately (default: true)'),
|
|
50
|
+
});
|
|
51
|
+
export const uvArgsSchema = commonArgsSchema.extend({
|
|
52
|
+
script: z
|
|
53
|
+
.string()
|
|
54
|
+
.describe('Python script: local file path, URL, or inline code. UV will handle dependencies automatically.'),
|
|
55
|
+
repo: z.string().optional().describe('Persistent repository name for script storage'),
|
|
56
|
+
with_deps: z.array(z.string()).optional().describe('Additional package dependencies'),
|
|
57
|
+
script_args: z.array(z.string()).optional().describe('Arguments to pass to the script'),
|
|
58
|
+
python: z.string().optional().describe('Python interpreter version (e.g., "3.12")'),
|
|
59
|
+
flavor: z.enum(ALL_FLAVORS).optional().default('cpu-basic').describe('Hardware flavor'),
|
|
60
|
+
env: z.record(z.string()).optional().describe('Environment variables'),
|
|
61
|
+
secrets: z.record(z.string()).optional().describe('Secret environment variables'),
|
|
62
|
+
timeout: z.string().optional().default('30m').describe('Max duration'),
|
|
63
|
+
detach: z.boolean().optional().default(true).describe('Run in background'),
|
|
64
|
+
});
|
|
65
|
+
export const psArgsSchema = commonArgsSchema.extend({
|
|
66
|
+
all: z.boolean().optional().default(false).describe('Show all jobs (default: only running)'),
|
|
67
|
+
status: z.string().optional().describe('Filter by status (e.g., "RUNNING", "COMPLETED")'),
|
|
68
|
+
});
|
|
69
|
+
export const logsArgsSchema = commonArgsSchema.extend({
|
|
70
|
+
job_id: z.string().describe('Job ID to fetch logs from'),
|
|
71
|
+
tail: z.number().optional().default(20).describe('Number of lines to return (default: 20)'),
|
|
72
|
+
});
|
|
73
|
+
export const inspectArgsSchema = commonArgsSchema.extend({
|
|
74
|
+
job_id: z.union([z.string(), z.array(z.string())]).describe('Job ID(s) to inspect'),
|
|
75
|
+
});
|
|
76
|
+
export const cancelArgsSchema = commonArgsSchema.extend({
|
|
77
|
+
job_id: z.string().describe('Job ID to cancel'),
|
|
78
|
+
});
|
|
79
|
+
export const scheduledRunArgsSchema = runArgsSchema.extend({
|
|
80
|
+
schedule: z
|
|
81
|
+
.string()
|
|
82
|
+
.describe('Schedule: cron expression or shorthand (@hourly, @daily, @weekly, @monthly, @yearly)'),
|
|
83
|
+
suspend: z.boolean().optional().default(false).describe('Create in suspended state'),
|
|
84
|
+
});
|
|
85
|
+
export const scheduledUvArgsSchema = uvArgsSchema.extend({
|
|
86
|
+
schedule: z.string().describe('Schedule: cron expression or shorthand'),
|
|
87
|
+
suspend: z.boolean().optional().default(false).describe('Create in suspended state'),
|
|
88
|
+
});
|
|
89
|
+
export const scheduledPsArgsSchema = commonArgsSchema.extend({
|
|
90
|
+
all: z.boolean().optional().default(false).describe('Show all scheduled jobs (default: hide suspended)'),
|
|
91
|
+
});
|
|
92
|
+
export const scheduledJobArgsSchema = commonArgsSchema.extend({
|
|
93
|
+
scheduled_job_id: z.string().describe('Scheduled job ID'),
|
|
94
|
+
});
|
|
95
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/jobs/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,QAAQ,CAAU,CAAC;AAE9F,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,OAAO;IACP,WAAW;IACX,UAAU;IACV,WAAW;IACX,MAAM;IACN,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,cAAc;IACd,YAAY;IACZ,MAAM;IACN,QAAQ;CACC,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAAQ,CAAU,C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,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,2BAA2B,CAAC;CACpF,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC,MAAM,CAAC;IACxD,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;IACvE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,2BAA2B,CAAC;CACpF,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAC5D,GAAG,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,mDAAmD,CAAC;CACxG,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC,MAAM,CAAC;IAC7D,gBAAgB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC;CACzD,CAAC,CAAC"}
|
package/dist/tool-ids.d.ts
CHANGED
|
@@ -15,14 +15,15 @@ export declare const USER_SUMMARY_PROMPT_ID: "User Summary";
|
|
|
15
15
|
export declare const PAPER_SUMMARY_PROMPT_ID: "Paper Summary";
|
|
16
16
|
export declare const MODEL_DETAIL_PROMPT_ID: string;
|
|
17
17
|
export declare const DATASET_DETAIL_PROMPT_ID: string;
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const HF_JOBS_TOOL_ID: "hf_jobs";
|
|
19
|
+
export declare const ALL_BUILTIN_TOOL_IDS: readonly ["space_search", "model_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space", "hf_jobs"];
|
|
19
20
|
export declare const TOOL_ID_GROUPS: {
|
|
20
21
|
readonly search: readonly ["space_search", "model_search", "dataset_search", "paper_search", "hf_doc_search"];
|
|
21
22
|
readonly spaces: readonly ["space_search", "duplicate_space", "space_info", "space_files", "use_space"];
|
|
22
23
|
readonly detail: readonly ["model_details", "dataset_details", "hub_repo_details"];
|
|
23
24
|
readonly docs: readonly ["hf_doc_search", "hf_doc_fetch"];
|
|
24
25
|
readonly hf_api: readonly ["space_search", "model_search", "dataset_search", "paper_search", "hub_repo_details", "hf_doc_search"];
|
|
25
|
-
readonly all: readonly ["space_search", "model_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space"];
|
|
26
|
+
readonly all: readonly ["space_search", "model_search", "model_details", "paper_search", "dataset_search", "dataset_details", "hub_repo_details", "duplicate_space", "space_info", "space_files", "hf_doc_search", "hf_doc_fetch", "use_space", "hf_jobs"];
|
|
26
27
|
};
|
|
27
28
|
export type BuiltinToolId = (typeof ALL_BUILTIN_TOOL_IDS)[number];
|
|
28
29
|
export declare function isValidBuiltinToolId(toolId: string): toolId is BuiltinToolId;
|
package/dist/tool-ids.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-ids.d.ts","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-ids.d.ts","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,oBAAoB,gBAAmC,CAAC;AACrE,eAAO,MAAM,oBAAoB,gBAAgC,CAAC;AAClE,eAAO,MAAM,oBAAoB,iBAAgC,CAAC;AAClE,eAAO,MAAM,oBAAoB,gBAAgC,CAAC;AAClE,eAAO,MAAM,sBAAsB,kBAAkC,CAAC;AACtE,eAAO,MAAM,sBAAsB,mBAAkC,CAAC;AACtE,eAAO,MAAM,mBAAmB,oBAA+B,CAAC;AAChE,eAAO,MAAM,uBAAuB,mBAAmC,CAAC;AACxE,eAAO,MAAM,kBAAkB,cAA8B,CAAC;AAC9D,eAAO,MAAM,mBAAmB,eAA+B,CAAC;AAChE,eAAO,MAAM,iBAAiB,aAA6B,CAAC;AAC5D,eAAO,MAAM,4BAA4B,iBAAmC,CAAC;AAC7E,eAAO,MAAM,iBAAiB,gBAAwB,CAAC;AACvD,eAAO,MAAM,sBAAsB,gBAAkC,CAAC;AACtE,eAAO,MAAM,uBAAuB,iBAAmC,CAAC;AACxE,eAAO,MAAM,sBAAsB,QAAkC,CAAC;AACtE,eAAO,MAAM,wBAAwB,QAAoC,CAAC;AAC1E,eAAO,MAAM,eAAe,WAA2B,CAAC;AAGxD,eAAO,MAAM,oBAAoB,8OAevB,CAAC;AAEX,eAAO,MAAM,cAAc;;;;;;;CA2BjB,CAAC;AAGX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAGlE,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,aAAa,CAE5E"}
|
package/dist/tool-ids.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SEMANTIC_SEARCH_TOOL_CONFIG, MODEL_SEARCH_TOOL_CONFIG, MODEL_DETAIL_TOOL_CONFIG, MODEL_DETAIL_PROMPT_CONFIG, PAPER_SEARCH_TOOL_CONFIG, DATASET_SEARCH_TOOL_CONFIG, DATASET_DETAIL_TOOL_CONFIG, DATASET_DETAIL_PROMPT_CONFIG, HUB_INSPECT_TOOL_CONFIG, DUPLICATE_SPACE_TOOL_CONFIG, SPACE_INFO_TOOL_CONFIG, SPACE_FILES_TOOL_CONFIG, USER_SUMMARY_PROMPT_CONFIG, PAPER_SUMMARY_PROMPT_CONFIG, DOCS_SEMANTIC_SEARCH_CONFIG, DOC_FETCH_CONFIG, USE_SPACE_TOOL_CONFIG, } from './index.js';
|
|
1
|
+
import { SEMANTIC_SEARCH_TOOL_CONFIG, MODEL_SEARCH_TOOL_CONFIG, MODEL_DETAIL_TOOL_CONFIG, MODEL_DETAIL_PROMPT_CONFIG, PAPER_SEARCH_TOOL_CONFIG, DATASET_SEARCH_TOOL_CONFIG, DATASET_DETAIL_TOOL_CONFIG, DATASET_DETAIL_PROMPT_CONFIG, HUB_INSPECT_TOOL_CONFIG, DUPLICATE_SPACE_TOOL_CONFIG, SPACE_INFO_TOOL_CONFIG, SPACE_FILES_TOOL_CONFIG, USER_SUMMARY_PROMPT_CONFIG, PAPER_SUMMARY_PROMPT_CONFIG, DOCS_SEMANTIC_SEARCH_CONFIG, DOC_FETCH_CONFIG, USE_SPACE_TOOL_CONFIG, HF_JOBS_TOOL_CONFIG, } from './index.js';
|
|
2
2
|
export const SPACE_SEARCH_TOOL_ID = SEMANTIC_SEARCH_TOOL_CONFIG.name;
|
|
3
3
|
export const MODEL_SEARCH_TOOL_ID = MODEL_SEARCH_TOOL_CONFIG.name;
|
|
4
4
|
export const MODEL_DETAIL_TOOL_ID = MODEL_DETAIL_TOOL_CONFIG.name;
|
|
@@ -16,6 +16,7 @@ export const USER_SUMMARY_PROMPT_ID = USER_SUMMARY_PROMPT_CONFIG.name;
|
|
|
16
16
|
export const PAPER_SUMMARY_PROMPT_ID = PAPER_SUMMARY_PROMPT_CONFIG.name;
|
|
17
17
|
export const MODEL_DETAIL_PROMPT_ID = MODEL_DETAIL_PROMPT_CONFIG.name;
|
|
18
18
|
export const DATASET_DETAIL_PROMPT_ID = DATASET_DETAIL_PROMPT_CONFIG.name;
|
|
19
|
+
export const HF_JOBS_TOOL_ID = HF_JOBS_TOOL_CONFIG.name;
|
|
19
20
|
export const ALL_BUILTIN_TOOL_IDS = [
|
|
20
21
|
SPACE_SEARCH_TOOL_ID,
|
|
21
22
|
MODEL_SEARCH_TOOL_ID,
|
|
@@ -30,6 +31,7 @@ export const ALL_BUILTIN_TOOL_IDS = [
|
|
|
30
31
|
DOCS_SEMANTIC_SEARCH_TOOL_ID,
|
|
31
32
|
DOC_FETCH_TOOL_ID,
|
|
32
33
|
USE_SPACE_TOOL_ID,
|
|
34
|
+
HF_JOBS_TOOL_ID,
|
|
33
35
|
];
|
|
34
36
|
export const TOOL_ID_GROUPS = {
|
|
35
37
|
search: [
|
|
@@ -39,7 +41,13 @@ export const TOOL_ID_GROUPS = {
|
|
|
39
41
|
PAPER_SEARCH_TOOL_ID,
|
|
40
42
|
DOCS_SEMANTIC_SEARCH_TOOL_ID,
|
|
41
43
|
],
|
|
42
|
-
spaces: [
|
|
44
|
+
spaces: [
|
|
45
|
+
SPACE_SEARCH_TOOL_ID,
|
|
46
|
+
DUPLICATE_SPACE_TOOL_ID,
|
|
47
|
+
SPACE_INFO_TOOL_ID,
|
|
48
|
+
SPACE_FILES_TOOL_ID,
|
|
49
|
+
USE_SPACE_TOOL_ID,
|
|
50
|
+
],
|
|
43
51
|
detail: [MODEL_DETAIL_TOOL_ID, DATASET_DETAIL_TOOL_ID, HUB_INSPECT_TOOL_ID],
|
|
44
52
|
docs: [DOCS_SEMANTIC_SEARCH_TOOL_ID, DOC_FETCH_TOOL_ID],
|
|
45
53
|
hf_api: [
|
package/dist/tool-ids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-ids.js","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,2BAA2B,EAC3B,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC5B,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,EAC3B,2BAA2B,EAC3B,gBAAgB,EAChB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"tool-ids.js","sourceRoot":"","sources":["../src/tool-ids.ts"],"names":[],"mappings":"AAKA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,MAAM,uBAAuB,GAAG,2BAA2B,CAAC,IAAI,CAAC;AACxE,MAAM,CAAC,MAAM,sBAAsB,GAAG,0BAA0B,CAAC,IAAI,CAAC;AACtE,MAAM,CAAC,MAAM,wBAAwB,GAAG,4BAA4B,CAAC,IAAI,CAAC;AAC1E,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC,IAAI,CAAC;AAGxD,MAAM,CAAC,MAAM,oBAAoB,GAAG;IACnC,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,oBAAoB;IACpB,sBAAsB;IACtB,sBAAsB;IACtB,mBAAmB;IACnB,uBAAuB;IACvB,kBAAkB;IAClB,mBAAmB;IACnB,4BAA4B;IAC5B,iBAAiB;IACjB,iBAAiB;IACjB,eAAe;CACN,CAAC;AAEX,MAAM,CAAC,MAAM,cAAc,GAAG;IAC7B,MAAM,EAAE;QACP,oBAAoB;QACpB,oBAAoB;QACpB,sBAAsB;QACtB,oBAAoB;QACpB,4BAA4B;KACnB;IACV,MAAM,EAAE;QACP,oBAAoB;QACpB,uBAAuB;QACvB,kBAAkB;QAClB,mBAAmB;QACnB,iBAAiB;KACR;IACV,MAAM,EAAE,CAAC,oBAAoB,EAAE,sBAAsB,EAAE,mBAAmB,CAAU;IACpF,IAAI,EAAE,CAAC,4BAA4B,EAAE,iBAAiB,CAAU;IAChE,MAAM,EAAE;QACP,oBAAoB;QACpB,oBAAoB;QACpB,sBAAsB;QACtB,oBAAoB;QACpB,mBAAmB;QACnB,4BAA4B;KAEnB;IACV,GAAG,EAAE,CAAC,GAAG,oBAAoB,CAAU;CAC9B,CAAC;AAMX,MAAM,UAAU,oBAAoB,CAAC,MAAc;IAClD,OAAQ,oBAA0C,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-result.d.ts","sourceRoot":"","sources":["../../src/types/tool-result.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IAI1B,SAAS,EAAE,MAAM,CAAC;IAOlB,YAAY,EAAE,MAAM,CAAC;IAQrB,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-result.d.ts","sourceRoot":"","sources":["../../src/types/tool-result.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IAI1B,SAAS,EAAE,MAAM,CAAC;IAOlB,YAAY,EAAE,MAAM,CAAC;IAQrB,aAAa,EAAE,MAAM,CAAC;IAMtB,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@llmindset/hf-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.35",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,14 +23,16 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@huggingface/hub": "^2.
|
|
26
|
+
"@huggingface/hub": "^2.6.12",
|
|
27
27
|
"@mcp-ui/server": "^5.12.0",
|
|
28
|
+
"shell-quote": "^1.8.3",
|
|
28
29
|
"turndown": "^7.2.0",
|
|
29
30
|
"zod": "^3.24.4"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@eslint/js": "^9.25.0",
|
|
33
34
|
"@types/node": "^22.15.18",
|
|
35
|
+
"@types/shell-quote": "^1.7.5",
|
|
34
36
|
"@types/turndown": "^5.0.5",
|
|
35
37
|
"eslint": "^9.25.0",
|
|
36
38
|
"globals": "^16.0.0",
|
|
@@ -10,7 +10,7 @@ import type { ToolResult } from '../types/tool-result.js';
|
|
|
10
10
|
export const DOCS_SEMANTIC_SEARCH_CONFIG = {
|
|
11
11
|
name: 'hf_doc_search',
|
|
12
12
|
description:
|
|
13
|
-
'Search and Discover Hugging Face Product and Library documentation.
|
|
13
|
+
'Search and Discover Hugging Face Product and Library documentation. Send an empty query to discover structure and navigation instructions. ' +
|
|
14
14
|
'You MUST consult this tool for the most up-to-date information when using Hugging Face libraries. Combine with the Product filter to focus results.',
|
|
15
15
|
schema: z.object({
|
|
16
16
|
query: z
|
package/src/hf-api-call.ts
CHANGED
|
@@ -120,6 +120,12 @@ export class HfApiCall<TParams = Record<string, string | undefined>, TResponse =
|
|
|
120
120
|
// Ignore if we can't read the body
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
// Log the error for debugging
|
|
124
|
+
console.error(`[API Error] ${response.status} ${response.statusText}`);
|
|
125
|
+
if (responseBody) {
|
|
126
|
+
console.error('[API Error] Response:', responseBody);
|
|
127
|
+
}
|
|
128
|
+
|
|
123
129
|
throw new HfApiError(
|
|
124
130
|
`API request failed: ${response.status.toString()} ${response.statusText}`,
|
|
125
131
|
response.status,
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ export * from './docs-search/docs-semantic-search.js';
|
|
|
19
19
|
export * from './docs-search/doc-fetch.js';
|
|
20
20
|
export * from './readme-utils.js';
|
|
21
21
|
export * from './use-space.js';
|
|
22
|
+
export * from './jobs/tool.js';
|
|
22
23
|
|
|
23
24
|
// Export shared types
|
|
24
25
|
export * from './types/tool-result.js';
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { HfApiCall } from '../hf-api-call.js';
|
|
2
|
+
import type { JobInfo, JobSpec, ScheduledJobInfo, ScheduledJobSpec } from './types.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Interface for whoami API response
|
|
6
|
+
*/
|
|
7
|
+
interface WhoAmIResponse {
|
|
8
|
+
name: string;
|
|
9
|
+
id: string;
|
|
10
|
+
type: 'user' | 'org';
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* API client for HuggingFace Jobs API
|
|
16
|
+
* Handles all HTTP interactions with the Jobs API endpoints
|
|
17
|
+
*/
|
|
18
|
+
export class JobsApiClient extends HfApiCall {
|
|
19
|
+
private namespaceCache: string | null = null;
|
|
20
|
+
|
|
21
|
+
constructor(hfToken?: string, namespace?: string) {
|
|
22
|
+
// Base URL is the main HF API, we'll construct specific endpoints
|
|
23
|
+
super('https://huggingface.co/api', hfToken);
|
|
24
|
+
// Initialize cache with provided namespace to avoid redundant whoami calls
|
|
25
|
+
this.namespaceCache = namespace || null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the namespace (username or org) for the current user
|
|
30
|
+
* Uses cached value from constructor or /api/whoami-v2 endpoint as fallback
|
|
31
|
+
*/
|
|
32
|
+
async getNamespace(namespace?: string): Promise<string> {
|
|
33
|
+
if (namespace) {
|
|
34
|
+
return namespace;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (this.namespaceCache) {
|
|
38
|
+
return this.namespaceCache;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Fetch from whoami endpoint only if not cached
|
|
42
|
+
const whoami = await this.fetchFromApi<WhoAmIResponse>('https://huggingface.co/api/whoami-v2');
|
|
43
|
+
this.namespaceCache = whoami.name;
|
|
44
|
+
return this.namespaceCache;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Run a job
|
|
49
|
+
* POST /api/jobs/{namespace}
|
|
50
|
+
*/
|
|
51
|
+
async runJob(jobSpec: JobSpec, namespace?: string): Promise<JobInfo> {
|
|
52
|
+
const ns = await this.getNamespace(namespace);
|
|
53
|
+
const url = `https://huggingface.co/api/jobs/${ns}`;
|
|
54
|
+
|
|
55
|
+
// Debug logging (will be visible in server logs)
|
|
56
|
+
|
|
57
|
+
const result = await this.fetchFromApi<JobInfo>(url, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
headers: {
|
|
60
|
+
'Content-Type': 'application/json',
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify(jobSpec),
|
|
63
|
+
});
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* List all jobs for a namespace
|
|
69
|
+
* GET /api/jobs/{namespace}
|
|
70
|
+
*/
|
|
71
|
+
async listJobs(namespace?: string): Promise<JobInfo[]> {
|
|
72
|
+
const ns = await this.getNamespace(namespace);
|
|
73
|
+
const url = `https://huggingface.co/api/jobs/${ns}`;
|
|
74
|
+
|
|
75
|
+
return this.fetchFromApi<JobInfo[]>(url);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get detailed information about a specific job
|
|
80
|
+
* GET /api/jobs/{namespace}/{jobId}
|
|
81
|
+
*/
|
|
82
|
+
async getJob(jobId: string, namespace?: string): Promise<JobInfo> {
|
|
83
|
+
const ns = await this.getNamespace(namespace);
|
|
84
|
+
const url = `https://huggingface.co/api/jobs/${ns}/${jobId}`;
|
|
85
|
+
|
|
86
|
+
return this.fetchFromApi<JobInfo>(url);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Cancel a running job
|
|
91
|
+
* POST /api/jobs/{namespace}/{jobId}/cancel
|
|
92
|
+
*/
|
|
93
|
+
async cancelJob(jobId: string, namespace?: string): Promise<void> {
|
|
94
|
+
const ns = await this.getNamespace(namespace);
|
|
95
|
+
const url = `https://huggingface.co/api/jobs/${ns}/${jobId}/cancel`;
|
|
96
|
+
|
|
97
|
+
await this.fetchFromApi<void>(url, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get logs URL for a job
|
|
104
|
+
* Returns the URL for SSE streaming - caller handles the actual streaming
|
|
105
|
+
*/
|
|
106
|
+
getLogsUrl(jobId: string, namespace: string): string {
|
|
107
|
+
return `https://huggingface.co/api/jobs/${namespace}/${jobId}/logs`;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Create a scheduled job
|
|
112
|
+
* POST /api/scheduled-jobs/{namespace}
|
|
113
|
+
*/
|
|
114
|
+
async createScheduledJob(spec: ScheduledJobSpec, namespace?: string): Promise<ScheduledJobInfo> {
|
|
115
|
+
const ns = await this.getNamespace(namespace);
|
|
116
|
+
const url = `https://huggingface.co/api/scheduled-jobs/${ns}`;
|
|
117
|
+
|
|
118
|
+
return this.fetchFromApi<ScheduledJobInfo>(url, {
|
|
119
|
+
method: 'POST',
|
|
120
|
+
headers: {
|
|
121
|
+
'Content-Type': 'application/json',
|
|
122
|
+
},
|
|
123
|
+
body: JSON.stringify(spec),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* List all scheduled jobs
|
|
129
|
+
* GET /api/scheduled-jobs/{namespace}
|
|
130
|
+
*/
|
|
131
|
+
async listScheduledJobs(namespace?: string): Promise<ScheduledJobInfo[]> {
|
|
132
|
+
const ns = await this.getNamespace(namespace);
|
|
133
|
+
const url = `https://huggingface.co/api/scheduled-jobs/${ns}`;
|
|
134
|
+
|
|
135
|
+
return this.fetchFromApi<ScheduledJobInfo[]>(url);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get details of a scheduled job
|
|
140
|
+
* GET /api/scheduled-jobs/{namespace}/{scheduledJobId}
|
|
141
|
+
*/
|
|
142
|
+
async getScheduledJob(scheduledJobId: string, namespace?: string): Promise<ScheduledJobInfo> {
|
|
143
|
+
const ns = await this.getNamespace(namespace);
|
|
144
|
+
const url = `https://huggingface.co/api/scheduled-jobs/${ns}/${scheduledJobId}`;
|
|
145
|
+
console.error(url);
|
|
146
|
+
return this.fetchFromApi<ScheduledJobInfo>(url);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Delete a scheduled job
|
|
151
|
+
* DELETE /api/scheduled-jobs/{namespace}/{scheduledJobId}
|
|
152
|
+
*/
|
|
153
|
+
async deleteScheduledJob(scheduledJobId: string, namespace?: string): Promise<void> {
|
|
154
|
+
const ns = await this.getNamespace(namespace);
|
|
155
|
+
const url = `https://huggingface.co/api/scheduled-jobs/${ns}/${scheduledJobId}`;
|
|
156
|
+
|
|
157
|
+
await this.fetchFromApi<void>(url, {
|
|
158
|
+
method: 'DELETE',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Suspend a scheduled job
|
|
164
|
+
* POST /api/scheduled-jobs/{namespace}/{scheduledJobId}/suspend
|
|
165
|
+
*/
|
|
166
|
+
async suspendScheduledJob(scheduledJobId: string, namespace?: string): Promise<void> {
|
|
167
|
+
const ns = await this.getNamespace(namespace);
|
|
168
|
+
const url = `https://huggingface.co/api/scheduled-jobs/${ns}/${scheduledJobId}/suspend`;
|
|
169
|
+
|
|
170
|
+
await this.fetchFromApi<void>(url, {
|
|
171
|
+
method: 'POST',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Resume a suspended scheduled job
|
|
177
|
+
* POST /api/scheduled-jobs/{namespace}/{scheduledJobId}/resume
|
|
178
|
+
*/
|
|
179
|
+
async resumeScheduledJob(scheduledJobId: string, namespace?: string): Promise<void> {
|
|
180
|
+
const ns = await this.getNamespace(namespace);
|
|
181
|
+
const url = `https://huggingface.co/api/scheduled-jobs/${ns}/${scheduledJobId}/resume`;
|
|
182
|
+
|
|
183
|
+
await this.fetchFromApi<void>(url, {
|
|
184
|
+
method: 'POST',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { InspectArgs, CancelArgs } from '../types.js';
|
|
2
|
+
import type { JobsApiClient } from '../api-client.js';
|
|
3
|
+
import { formatJobDetails } from '../formatters.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Execute the 'inspect' command
|
|
7
|
+
* Gets detailed information about one or more jobs
|
|
8
|
+
*/
|
|
9
|
+
export async function inspectCommand(args: InspectArgs, client: JobsApiClient): Promise<string> {
|
|
10
|
+
const jobIds = Array.isArray(args.job_id) ? args.job_id : [args.job_id];
|
|
11
|
+
|
|
12
|
+
// Fetch all jobs
|
|
13
|
+
const jobs = await Promise.all(
|
|
14
|
+
jobIds.map(async (id) => {
|
|
15
|
+
try {
|
|
16
|
+
return await client.getJob(id, args.namespace);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
throw new Error(`Failed to fetch job ${id}: ${(error as Error).message}`);
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const formattedDetails = formatJobDetails(jobs);
|
|
24
|
+
|
|
25
|
+
return `**Job Details** (${jobs.length} job${jobs.length > 1 ? 's' : ''}):\n\n${formattedDetails}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Execute the 'cancel' command
|
|
30
|
+
* Cancels a running job
|
|
31
|
+
*/
|
|
32
|
+
export async function cancelCommand(args: CancelArgs, client: JobsApiClient): Promise<string> {
|
|
33
|
+
await client.cancelJob(args.job_id, args.namespace);
|
|
34
|
+
|
|
35
|
+
return `✓ Job ${args.job_id} has been cancelled.
|
|
36
|
+
|
|
37
|
+
To verify: \`hf_jobs("inspect", {"job_id": "${args.job_id}"})\``;
|
|
38
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LogsArgs } from '../types.js';
|
|
2
|
+
import type { JobsApiClient } from '../api-client.js';
|
|
3
|
+
import { fetchJobLogs } from '../sse-handler.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Execute the 'logs' command
|
|
7
|
+
* Fetches logs from a job via SSE
|
|
8
|
+
*/
|
|
9
|
+
export async function logsCommand(args: LogsArgs, client: JobsApiClient, token?: string): Promise<string> {
|
|
10
|
+
// Get namespace for the logs URL
|
|
11
|
+
const namespace = await client.getNamespace(args.namespace);
|
|
12
|
+
const logsUrl = client.getLogsUrl(args.job_id, namespace);
|
|
13
|
+
|
|
14
|
+
// Fetch logs with timeout and line limit
|
|
15
|
+
const result = await fetchJobLogs(logsUrl, {
|
|
16
|
+
token,
|
|
17
|
+
maxDuration: 10000,
|
|
18
|
+
maxLines: args.tail,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (result.logs.length === 0) {
|
|
22
|
+
return `No logs available for job ${args.job_id}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let response = `**Logs for job ${args.job_id}** (last ${args.tail} lines):\n\n${'```'}\n`;
|
|
26
|
+
response += result.logs.join('\n');
|
|
27
|
+
response += `\n${'```'}`;
|
|
28
|
+
|
|
29
|
+
if (result.finished) {
|
|
30
|
+
response += '\n\n✓ Job finished.';
|
|
31
|
+
} else if (result.truncated) {
|
|
32
|
+
response += '\n\n⚠ Log collection stopped after 10 seconds. Job may still be running.';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PsArgs } from '../types.js';
|
|
2
|
+
import type { JobsApiClient } from '../api-client.js';
|
|
3
|
+
import { formatJobsTable } from '../formatters.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Execute the 'ps' command
|
|
7
|
+
* Lists jobs with optional filtering
|
|
8
|
+
*/
|
|
9
|
+
export async function psCommand(args: PsArgs, client: JobsApiClient): Promise<string> {
|
|
10
|
+
// Fetch all jobs from API
|
|
11
|
+
const allJobs = await client.listJobs(args.namespace);
|
|
12
|
+
|
|
13
|
+
// Filter jobs
|
|
14
|
+
let jobs = allJobs;
|
|
15
|
+
|
|
16
|
+
// Default: show only running jobs unless --all is specified
|
|
17
|
+
if (!args.all) {
|
|
18
|
+
jobs = jobs.filter((job) => job.status.stage === 'RUNNING');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Apply status filter if specified
|
|
22
|
+
if (args.status) {
|
|
23
|
+
const statusFilter = args.status.toUpperCase();
|
|
24
|
+
jobs = jobs.filter((job) => job.status.stage.toUpperCase().includes(statusFilter));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Format as markdown table
|
|
28
|
+
const table = formatJobsTable(jobs);
|
|
29
|
+
|
|
30
|
+
if (jobs.length === 0) {
|
|
31
|
+
if (args.all) {
|
|
32
|
+
return 'No jobs found.';
|
|
33
|
+
}
|
|
34
|
+
return 'No running jobs found. Use `{"all": true}` to show all jobs.';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return `**Jobs (${jobs.length} of ${allJobs.length} total):**
|
|
38
|
+
|
|
39
|
+
${table}`;
|
|
40
|
+
}
|