chore: vendor sglang v0.5.10 snapshot

This commit is contained in:
2026-04-24 12:29:36 +00:00
parent 78f0d15221
commit bded08301f
4308 changed files with 1200894 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
[package]
name = "wasm-guest-logging"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
wit-bindgen = { version = "0.21", features = ["macros"] }

View File

@@ -0,0 +1,53 @@
# WASM Logging Example for sgl-model-gateway
This example demonstrates logging and tracing middleware for sgl-model-gateway using the WebAssembly Component Model.
## Overview
This middleware provides:
- **Request Tracking** - Adds tracking headers (`x-request-id`, `x-wasm-processed`, `x-processed-at`, `x-api-route`)
- **Status Code Conversion** - Converts `500` errors to `503`
## Quick Start
### Build and Deploy
```bash
# Build
cd examples/wasm-guest-logging
./build.sh
# Deploy (replace file_path with actual path)
curl -X POST http://localhost:3000/wasm \
-H "Content-Type: application/json" \
-d '{
"modules": [{
"name": "logging-middleware",
"file_path": "/absolute/path/to/wasm_guest_logging.component.wasm",
"module_type": "Middleware",
"attach_points": [{"Middleware": "OnRequest"}, {"Middleware": "OnResponse"}]
}]
}'
```
### Customization
Modify `on_request` or `on_response` functions in `src/lib.rs` to add custom tracking headers or status code conversions.
## Testing
```bash
# Check tracking headers
curl -v http://localhost:3000/v1/models 2>&1 | \
grep -E "(x-request-id|x-wasm-processed|x-processed-at)"
# Test status code conversion (requires endpoint returning 500)
curl -v http://localhost:3000/some-endpoint 2>&1 | grep -E "(< HTTP|500|503)"
```
## Troubleshooting
- Verify module attached to both `OnRequest` and `OnResponse` phases
- Check router logs for execution errors
- Ensure module built successfully

View File

@@ -0,0 +1,77 @@
#!/bin/bash
# Build script for WASM guest logging example
# This script simplifies the build process for the WASM middleware component
set -e
echo "Building WASM guest logging example..."
# Check if we're in the right directory
if [ ! -f "Cargo.toml" ]; then
echo "Error: Cargo.toml not found. Please run this script from the wasm-guest-logging directory."
exit 1
fi
# Check for required tools
command -v cargo >/dev/null 2>&1 || { echo "Error: cargo is required but not installed. Aborting." >&2; exit 1; }
# Check and install wasm32-wasip2 target
echo "Checking for wasm32-wasip2 target..."
if ! rustup target list --installed | grep -q "wasm32-wasip2"; then
echo "wasm32-wasip2 target not found. Installing..."
rustup target add wasm32-wasip2
echo "✓ wasm32-wasip2 target installed"
else
echo "✓ wasm32-wasip2 target already installed"
fi
# Check for wasm-tools
if ! command -v wasm-tools >/dev/null 2>&1; then
echo "Error: wasm-tools is required but not installed."
echo "Install it with: cargo install wasm-tools"
exit 1
fi
# Build with cargo (wit-bindgen uses cargo, not wasm-pack)
echo "Running cargo build..."
cargo build --target wasm32-wasip2 --release
# Output locations
WASM_MODULE="target/wasm32-wasip2/release/wasm_guest_logging.wasm"
WASM_COMPONENT="target/wasm32-wasip2/release/wasm_guest_logging.component.wasm"
if [ ! -f "$WASM_MODULE" ]; then
echo "Error: Build failed - WASM module not found"
exit 1
fi
# Check if the file is already a component
echo "Checking WASM file format..."
if wasm-tools print "$WASM_MODULE" 2>/dev/null | grep -q "^(\s*component"; then
echo "✓ WASM file is already in component format"
# Copy to component path for consistency
cp "$WASM_MODULE" "$WASM_COMPONENT"
else
# Wrap the WASM module into a component format
echo "Wrapping WASM module into component format..."
wasm-tools component new "$WASM_MODULE" -o "$WASM_COMPONENT"
if [ ! -f "$WASM_COMPONENT" ]; then
echo "Error: Failed to create component file"
exit 1
fi
fi
if [ -f "$WASM_COMPONENT" ]; then
echo ""
echo "✓ Build successful!"
echo " WASM module: $WASM_MODULE"
echo " WASM component: $WASM_COMPONENT"
echo ""
echo "Next steps:"
echo "1. Use the component file ($WASM_COMPONENT) when adding the module"
echo "2. Prepare the module configuration (see README.md for JSON format)"
echo "3. Use the API endpoint to add the module (see README.md for details)"
else
echo "Error: Component file not found"
exit 1
fi

View File

@@ -0,0 +1,88 @@
//! WASM Guest Logging Example for sgl-model-gateway
//!
//! This example demonstrates logging and tracing middleware
//! for sgl-model-gateway using the WebAssembly Component Model.
//!
//! Features:
//! - Request tracking and tracing headers
//! - Response status code conversion
wit_bindgen::generate!({
path: "../../../src/wasm/interface",
world: "sgl-model-gateway",
});
use exports::sgl::model_gateway::{
middleware_on_request::Guest as OnRequestGuest,
middleware_on_response::Guest as OnResponseGuest,
};
use sgl::model_gateway::middleware_types::{Action, Header, ModifyAction, Request, Response};
/// Main middleware implementation
struct Middleware;
// Helper function to create header
fn create_header(name: &str, value: &str) -> Header {
Header {
name: name.to_string(),
value: value.to_string(),
}
}
// Implement on-request interface
impl OnRequestGuest for Middleware {
fn on_request(req: Request) -> Action {
let mut modify_action = ModifyAction {
status: None,
headers_set: vec![],
headers_add: vec![],
headers_remove: vec![],
body_replace: None,
};
// Request Logging and Tracing
// Add tracing headers with request ID
modify_action
.headers_add
.push(create_header("x-request-id", &req.request_id));
modify_action
.headers_add
.push(create_header("x-wasm-processed", "true"));
modify_action.headers_add.push(create_header(
"x-processed-at",
&req.now_epoch_ms.to_string(),
));
// Add custom header for API requests
if req.path.starts_with("/api") || req.path.starts_with("/v1") {
modify_action
.headers_add
.push(create_header("x-api-route", "true"));
}
Action::Modify(modify_action)
}
}
// Implement on-response interface
impl OnResponseGuest for Middleware {
fn on_response(resp: Response) -> Action {
// Status code conversion: Convert 500 to 503 for better client handling
if resp.status == 500 {
let modify_action = ModifyAction {
status: Some(503),
headers_set: vec![],
headers_add: vec![],
headers_remove: vec![],
body_replace: None,
};
Action::Modify(modify_action)
} else {
// No modification needed
Action::Continue
}
}
}
// Export the component
export!(Middleware);