Skip to content

server: clean up static assets handling#24550

Merged
ngxson merged 5 commits into
ggml-org:masterfrom
ngxson:xsn/cleanup_http_assets
Jun 13, 2026
Merged

server: clean up static assets handling#24550
ngxson merged 5 commits into
ggml-org:masterfrom
ngxson:xsn/cleanup_http_assets

Conversation

@ngxson

@ngxson ngxson commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Overview

cont #23871

make the handling code as dry as possible

the internal API is also changed:

struct llama_ui_asset {
    std::string           name;
    const unsigned char * data;
    std::size_t           size;
    std::string           etag;
    std::string           type;
};

const llama_ui_asset * llama_ui_find_asset(const std::string & name);
const std::array<llama_ui_asset, 64> & llama_ui_get_assets();

Changes to post-build

In order to fix problems with dynamic file name (file name with hash - ref: #23871 (comment))

  • Anything under _app/**/* are moved to root
  • Hash in file name is always removed
  • llama-server router is responsible to route the hash version back to the correct asset

Requirements

@aldehir

aldehir commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Looks like we had a similar idea, #24551

@github-actions github-actions Bot added the script Script related label Jun 13, 2026
@ngxson

ngxson commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

Looks like we had a similar idea, #24551

lmao, indeed haha

image

Comment thread scripts/ui-assets.cmake
Comment on lines -353 to -366
# Compute relative path from DIST_DIR to each found file.
# e.g. /path/to/build/tools/ui/dist/_app/immutable/bundle.XXX.js
# -> _app/immutable/bundle.XXX.js
foreach(f ${detected_bundle_js})
string(REPLACE "${DIST_DIR}/" "" rel "${f}")
list(APPEND args "${rel}" "${f}")
endforeach()
foreach(f ${detected_bundle_css})
string(REPLACE "${DIST_DIR}/" "" rel "${f}")
list(APPEND args "${rel}" "${f}")
endforeach()
foreach(f ${detected_workbox})
string(REPLACE "${DIST_DIR}/" "" rel "${f}")
list(APPEND args "${rel}" "${f}")

@ngxson ngxson Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldehir for ref, this is part of the reason why I don't want to have nested file structure; the code looks quite overkill IMO

@aldehir aldehir Jun 13, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's understandable, although in my PR I simply embed each asset by its path relative to the dist dir and serve it up at the appropriate endpoint. Making the nested file paths irrelevant. Either way, I'll create a new PR and build off of yours.

@aldehir aldehir requested a review from a team as a code owner June 13, 2026 04:09
@github-actions github-actions Bot added the devops improvements to build systems and github actions label Jun 13, 2026
@aldehir

aldehir commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Ok, I applied my changes. Although, if we're going to upload an archive and extract, I don't really see the point of the bundle.css/js renaming / path manipulation.

@aldehir

aldehir commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

@allozaur I don't see anything using the PUBLIC_ENDPOINTS in pwa.ts. Can this be safely removed?

Comment on lines -445 to -459
auto serve_bundle = [serve_asset_cached](const httplib::Request & req, httplib::Response & res) {
std::string path = req.path;
std::string name;
const char * mime;
if (path.rfind("/_app/immutable/bundle.", 0) == 0 && path.size() > 22) {
name = path.substr(1); // strip leading /
mime = "application/javascript; charset=utf-8";
} else if (path.rfind("/_app/immutable/assets/bundle.", 0) == 0 && path.size() > 30) {
name = path.substr(1); // strip leading /
mime = "text/css; charset=utf-8";
} else {
res.status = 404;
return false;
}
return serve_asset_cached(name, mime, false)(req, res);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldehir to reply to your point:

I don't really see the point of the bundle.css/js renaming / path manipulation.

that's true in practice, as the general logic is to serve the dist as-is.

however, we already have this logic in the previous version where we remap whatever hash to the same file. I kinda think that this "relax" logic can be a bit safer, just in case things doesn't matched up then it will continue to work. although I could be wrong.

in either way, we probably need to rethink this in a follow-up PR. for now this one I think it's better to make it bug-for-bug compatible

@ngxson

ngxson commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

I'm merging this now to fix the release first, let's fix/discuss the rest via follow-up PRs. thanks!

@ngxson ngxson merged commit 57fe1f0 into ggml-org:master Jun 13, 2026
29 of 30 checks passed
Comment on lines +43 to +47
- name: Create distribution archive
run: |
tar -czf dist.tar.gz -C tools/ui/dist .
sha256sum dist.tar.gz > dist.tar.gz.sha256
mv dist.tar.gz dist.tar.gz.sha256 tools/ui/dist/

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldehir do you think we should clean up the other files and only preserve dist.tar.gz* ?

ref: https://huggingface.co/buckets/ggml-org/llama-ui/tree/latest?sort=uploadedAt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just looking at that. I agree we should clean it up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops improvements to build systems and github actions examples script Script related server/ui server

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants