Agent skill
create-file-viewer
Create a custom file viewer for Datagrok file share browser
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/create-file-viewer
SKILL.md
Create File Viewer
Create a custom file viewer that is used by the Datagrok file share browser to display files with specific extensions.
Usage
/create-file-viewer [extensions] [package-path]
Instructions
When this skill is invoked, help the user create a custom file viewer for one or more file extensions.
Step 1: Create the viewer function
Add a function to package.ts (or a separate file imported by it) with the correct annotations. The function must:
- Accept a single
fileinput - Return a
view - Have the
fileViewertag plus afileViewer-<ext>tag for each supported extension
//name: myFileViewer
//tags: fileViewer, fileViewer-xyz, fileViewer-abc
//input: file file
//output: view v
export function myFileViewer(file: DG.FileInfo) {
let view = DG.View.create();
// Read file content and render it
file.readAsString().then((content) => {
let host = ui.div([]);
// Process and display content
host.innerText = content;
view.append(host);
});
return view;
}
Step 2: Handle file content
Choose the appropriate method to read file content:
file.readAsString()- for text-based files (returnsPromise<string>)file.readAsBytes()- for binary files (returnsPromise<Uint8Array>)
Example for binary files:
//tags: fileViewer, fileViewer-mol, fileViewer-sdf, fileViewer-cif
//input: file file
//output: view v
export function structureViewer(file: DG.FileInfo) {
let view = DG.View.create();
let host = ui.div([], 'd4-ngl-viewer');
file
.readAsBytes()
.then(bytes => {
// Process binary content
let blob = new Blob([bytes]);
// Render blob...
});
view.append(host);
return view;
}
Step 3: Build and publish
npm run build
grok publish
Once the package is published, Datagrok automatically uses the viewer when a user selects a file with a matching extension in the file share browser.
Key points
- Each supported extension needs its own tag:
fileViewer-mol,fileViewer-sdf, etc. - The function runs when a user clicks on a file with a matching extension in the file share browser
- The view is displayed in the file preview panel
- Return the view synchronously; load file content asynchronously inside it
- Multiple extensions can be handled by a single function with multiple
fileViewer-<ext>tags
Behavior
- Ask the user which file extension(s) they want to support if not specified
- Determine whether the file is text-based or binary to choose
readAsStringvsreadAsBytes - Create the viewer function with correct tags for all specified extensions
- Add rendering logic appropriate for the file type
- Ensure imports are correct (
import * as DG from 'datagrok-api/dg',import * as ui from 'datagrok-api/ui')
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?