Feat/custom data files#47
Open
jlee-kitware wants to merge 6 commits into
Open
Conversation
Complement the sample-data resolver with a store for the user's own files. New data/uploads.py writes uploaded bytes to a local cache under a sanitized basename and looks them up by name (add/list/path/remove/clear). The resolver's stage_code, referenced, and artifacts now consult uploads first and fall back to the sample-data index, so an uploaded file is used verbatim and takes precedence over sample data of the same name. Staging also works with no sample-data root configured, since uploads do not need one.
Add a conditional user_data prompt component that lists the user's uploaded filenames and instructs the model to load them by bare name with an appropriate reader. assemble_vtk_prompt gains an uploaded_files argument (mirroring the mcp_active/context_snippets pattern); client.py passes the current uploads. The component and its token cost are included only when files have been uploaded.
Add a file input above the prompt for uploading custom data files, plus a chip strip of currently uploaded files each with a remove action. New change handler stores uploaded bytes via the uploads registry and refreshes state; a trigger removes a file by name. The referenced-data chips now distinguish an uploaded file (info color, upload icon, "Uploaded") from fetched sample data. add_upload coerces whatever content type trame delivers to bytes.
Put the upload affordance next to the resolved-file chips it relates to: a small "Add data" chip in the Generated Code title triggers a hidden file input, replacing the separate file field above the prompt. Behavior is unchanged; the existing data_uploads change handler still stores the bytes.
Gather everything data-related in one place: a new Data tab holds the sample-data location field (moved out of Config), the uploaded files with remove actions, and the sample datasets fetched to the local cache with a Clear cache action. New resolver helpers list and clear the cache; the lists refresh when the dialog opens. Config is now purely model/prompt configuration.
trame evaluates click expressions as Vue template expressions, where window is in scope but document is not, so bare document.querySelector was undefined. Go through window.document to open the hidden file input.
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #46. Review that one first; the diff here is only the six commits on top.
#46 added a resolver that turns a bare filename in generated code (
cow.g) into a reallocal path by fetching it from the VTK data store. That only works for files VTK already
knows about. This adds the other half: your own files.
Upload a mesh, and the model is told it exists, writes
reader.SetFileName('mymesh.vtu'),and the resolver rewrites that literal to the local path at execution time. Same mechanism
as sample data, different source. Uploads take precedence over sample data of the same
name, and they work with no sample-data root configured, since they do not need one.
What is here
data/uploads.py: stores uploaded bytes under a sanitized basename in the local cache,with add/list/path/remove/clear. Content is coerced to bytes, since trame delivers it in
a few different shapes.
stage_code,referenced, andartifactsconsult uploads first,then fall back to the sample-data index.
user_dataprompt component lists the uploaded filenames and tells themodel to load them by bare name with an appropriate reader. It is only added when files
have been uploaded, so prompts are unchanged otherwise.
relates to. Referenced-file chips now distinguish an uploaded file ("Uploaded") from
fetched sample data ("Fetched").
field (moved out of Config, which is now purely model/prompt config), uploaded files with
remove actions, and the sample data fetched to the local cache with a Clear cache action.
Testing
Upload, reference-in-code, staging, and removal are all exercised; explicit paths are never
rewritten. Verified in the browser that the upload picker opens and an uploaded file stages
into the generated code correctly.