Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

8.1 KB
Raw Blame
// Code generated by templ - DO NOT EDIT.

// templ: version: v0.3.1100

package app

//lint:file-ignore SA4006 This context is only used if a nested component is present.

import "github.com/a-h/templ"
import templruntime "github.com/a-h/templ/runtime"

func VectorTools(bucket, arn, policy string) templ.Component {
	return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
		templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
		if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
			return templ_7745c5c3_CtxErr
		}
		templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
		if !templ_7745c5c3_IsBuffer {
			defer func() {
				templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
				if templ_7745c5c3_Err == nil {
					templ_7745c5c3_Err = templ_7745c5c3_BufErr
				}
			}()
		}
		ctx = templ.InitializeContext(ctx)
		ctx = templ.ClearChildren(ctx)
		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"card shadow mb-4\" id=\"vectorTools\" data-bucket=\"")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		var templ_7745c5c3_Var2 string
		templ_7745c5c3_Var2, templ_7745c5c3_Err = templruntime.NewAttributeExpression(bucket).Resolve(ctx)
		if templ_7745c5c3_Err != nil {
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `weed/admin/view/app/vector_tools.templ`, Line: 5, Col: 68}
		}
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var2)
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "\" data-arn=\"")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		var templ_7745c5c3_Var3 string
		templ_7745c5c3_Var3, templ_7745c5c3_Err = templruntime.NewAttributeExpression(arn).Resolve(ctx)
		if templ_7745c5c3_Err != nil {
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `weed/admin/view/app/vector_tools.templ`, Line: 5, Col: 85}
		}
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"><div class=\"card-header\">Manage Indexes, Policies and Vectors</div><div class=\"card-body\"><form id=\"vectorIndexForm\" class=\"row g-2 mb-3\"><div class=\"col\"><label for=\"vectorIndexName\" class=\"form-label\">Index name</label><input id=\"vectorIndexName\" class=\"form-control\" required></div><div class=\"col\"><label for=\"vectorDimension\" class=\"form-label\">Dimension</label><input id=\"vectorDimension\" class=\"form-control\" type=\"number\" min=\"1\" max=\"4096\" required></div><div class=\"col\"><label for=\"vectorDistance\" class=\"form-label\">Distance</label><select id=\"vectorDistance\" class=\"form-select\"><option value=\"cosine\">Cosine</option><option value=\"euclidean\">Euclidean</option></select></div><div class=\"col-auto align-self-end\"><button class=\"btn btn-primary\" type=\"submit\">Create Index</button></div></form><form id=\"vectorPolicyForm\" class=\"mb-3\"><label for=\"vectorPolicy\" class=\"form-label\">Bucket policy</label><textarea id=\"vectorPolicy\" class=\"form-control font-monospace\" rows=\"5\">")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		var templ_7745c5c3_Var4 string
		templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(policy)
		if templ_7745c5c3_Err != nil {
			return templ.Error{Err: templ_7745c5c3_Err, FileName: `weed/admin/view/app/vector_tools.templ`, Line: 15, Col: 151}
		}
		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</textarea> <button class=\"btn btn-outline-primary mt-2\" type=\"submit\">Save Policy</button> <button class=\"btn btn-outline-danger mt-2\" type=\"button\" id=\"vectorDeletePolicy\">Delete Policy</button></form><form id=\"vectorOperationForm\"><label for=\"vectorOperation\" class=\"form-label\">Vector and tagging operations</label> <select id=\"vectorOperation\" class=\"form-select mb-2\"><option>QueryVectors</option><option>PutVectors</option><option>GetVectors</option><option>ListVectors</option><option>DeleteVectors</option><option>ListTagsForResource</option><option>TagResource</option><option>UntagResource</option></select> <label for=\"vectorRequest\" class=\"form-label\">Request JSON</label><textarea id=\"vectorRequest\" class=\"form-control font-monospace\" rows=\"7\" required></textarea> <button class=\"btn btn-outline-primary mt-2\" type=\"submit\">Run</button></form><pre id=\"vectorResult\" class=\"mt-3 mb-0\" role=\"status\"></pre></div></div><script>\n document.addEventListener('DOMContentLoaded', () => {\n  const root = document.getElementById('vectorTools');\n  const bucket = root.dataset.bucket;\n  const output = document.getElementById('vectorResult');\n  const run = async (operation, request) => {\n   output.textContent = 'Running…';\n   const response = await fetch(s3tBasePath('/api/s3vectors/operations'), {method:'POST', headers:s3tWriteHeaders({'Content-Type':'application/json'}), body:JSON.stringify({operation,request})});\n   const result = await response.json();\n   output.textContent = JSON.stringify(result,null,2);\n   if (!response.ok) throw new Error(result.error || 'Operation failed');\n   return result;\n  };\n  const submit = (id, action) => document.getElementById(id).addEventListener('submit', async event => {\n   event.preventDefault();\n   const buttons = event.target.querySelectorAll('button');\n   buttons.forEach(button => button.disabled = true);\n   try { await action(); } catch(error) {output.textContent=error.message;} finally {buttons.forEach(button => button.disabled = false);}\n  });\n  submit('vectorIndexForm', async () => {\n   await run('CreateIndex',{vectorBucketName:bucket,indexName:document.getElementById('vectorIndexName').value,dimension:Number(document.getElementById('vectorDimension').value),distanceMetric:document.getElementById('vectorDistance').value,dataType:'float32'});\n   location.reload();\n  });\n  submit('vectorPolicyForm', async () => {\n   const policy=document.getElementById('vectorPolicy').value;\n   JSON.parse(policy);\n   await run('PutVectorBucketPolicy',{vectorBucketName:bucket,policy});\n   location.reload();\n  });\n  document.getElementById('vectorDeletePolicy').addEventListener('click',async () => {\n   if (!confirm('Delete this bucket policy?')) return;\n   const controls=document.getElementById('vectorPolicyForm').querySelectorAll('button,textarea');\n   controls.forEach(control => control.disabled=true);\n   try {await run('DeleteVectorBucketPolicy',{vectorBucketName:bucket});location.reload();} catch(error) {output.textContent=error.message;} finally {controls.forEach(control => control.disabled=false);}\n  });\n  const operation=document.getElementById('vectorOperation');\n  const request=document.getElementById('vectorRequest');\n  const example=() => {\n   const op=operation.value;\n   let value={vectorBucketName:bucket,indexName:document.getElementById('vectorIndexName').value || 'my-index'};\n   if (op==='QueryVectors') Object.assign(value,{queryVector:{float32:[0.1,0.2,0.3]},topK:5,returnDistance:true});\n   if (op==='PutVectors') value.vectors=[{key:'example',data:{float32:[0.1,0.2,0.3]}}];\n   if (op==='GetVectors' || op==='DeleteVectors') value.keys=['example'];\n   if (op.includes('Tag') || op==='UntagResource') {\n    value={resourceArn:root.dataset.arn};\n    if (op==='TagResource') value.tags={environment:'development'};\n    if (op==='UntagResource') value.tagKeys=['environment'];\n   }\n   request.value=JSON.stringify(value,null,2);\n  };\n  operation.addEventListener('change',example);\n  example();\n  submit('vectorOperationForm',()=>run(operation.value,JSON.parse(request.value)));\n });\n </script>")
		if templ_7745c5c3_Err != nil {
			return templ_7745c5c3_Err
		}
		return nil
	})
}

var _ = templruntime.GeneratedTemplate