Safetensors
GGUF
Turkish
llama
Llama-3
instruct
finetune
chatml
gpt4
synthetic data
distillation
function calling
json mode
axolotl
roleplaying
chat
Instructions to use tda45/TdAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use tda45/TdAI with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf tda45/TdAI # Run inference directly in the terminal: llama cli -hf tda45/TdAI
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf tda45/TdAI # Run inference directly in the terminal: llama cli -hf tda45/TdAI
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf tda45/TdAI # Run inference directly in the terminal: ./build/bin/llama cli -hf tda45/TdAI
Use Docker
docker model run hf.co/tda45/TdAI
- Llama new
- LM Studio
- Jan
- Ollama
How to use tda45/TdAI with Ollama:
ollama run hf.co/tda45/TdAI
- Unsloth Desktop
- Docker Model Runner
How to use tda45/TdAI with Docker Model Runner:
docker model run hf.co/tda45/TdAI
- Lemonade
How to use tda45/TdAI with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull tda45/TdAI
Run and chat with the model
lemonade run user.TdAI-{{QUANT_TAG}}List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub (part 8)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +2 -0
- README.md +244 -4
- llama.cpp/tools/ui/src/lib/components/app/SKILL.md +11 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts +88 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts +33 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts +106 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts +96 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts +7 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts +91 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/rehype-rtl-support.ts +28 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts +34 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts +13 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts +181 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts +121 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MermaidPreview.svelte +121 -0
- llama.cpp/tools/ui/src/lib/components/app/content/MermaidPreviewControls.svelte +74 -0
- llama.cpp/tools/ui/src/lib/components/app/content/SyntaxHighlightedCode.svelte +90 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogChatAttachmentsPreview.svelte +88 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogChatError.svelte +80 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogCodePreview.svelte +95 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogConfirmation.svelte +81 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogConversationSelection.svelte +69 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogConversationTitleUpdate.svelte +46 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogEmptyFileAlert.svelte +61 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogExportSettings.svelte +83 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogFileUploadError.svelte +88 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte +122 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpResourcesBrowser.svelte +394 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpServerAddNew.svelte +95 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpServerRecommendations.svelte +180 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMermaidPreview.svelte +20 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogModelInformation.svelte +270 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogModelNotAvailable.svelte +76 -0
- llama.cpp/tools/ui/src/lib/components/app/dialogs/index.ts +517 -0
- llama.cpp/tools/ui/src/lib/components/app/forms/InputWithSuggestions.svelte +78 -0
- llama.cpp/tools/ui/src/lib/components/app/forms/KeyValuePairs.svelte +164 -0
- llama.cpp/tools/ui/src/lib/components/app/forms/SearchInput.svelte +78 -0
- llama.cpp/tools/ui/src/lib/components/app/forms/index.ts +44 -0
- llama.cpp/tools/ui/src/lib/components/app/index.ts +12 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpActiveServersAvatars.svelte +89 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpCapabilitiesBadges.svelte +61 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpConnectionLogs.svelte +81 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpLogo.svelte +111 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcePreview.svelte +174 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourceTemplateForm.svelte +171 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowser.svelte +153 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowserEmptyState.svelte +15 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowserHeader.svelte +41 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowserServerItem.svelte +230 -0
- llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/mcp-resources-browser.ts +118 -0
.gitattributes
CHANGED
|
@@ -42,3 +42,5 @@ llama.cpp/media/matmul.png filter=lfs diff=lfs merge=lfs -text
|
|
| 42 |
llama.cpp/tools/mtmd/test-1.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 43 |
llama.cpp/tools/mtmd/test-2.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 44 |
llama.cpp/tools/mtmd/test-3.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 42 |
llama.cpp/tools/mtmd/test-1.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 43 |
llama.cpp/tools/mtmd/test-2.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 44 |
llama.cpp/tools/mtmd/test-3.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 45 |
+
llama.cpp/tools/ui/tests/stories/fixtures/assets/beautiful-flowers-lotus.webp filter=lfs diff=lfs merge=lfs -text
|
| 46 |
+
llama.cpp/tools/ui/tests/stories/fixtures/assets/example.pdf filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,5 +1,245 @@
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: llama3
|
| 5 |
+
tags:
|
| 6 |
+
- Llama-3
|
| 7 |
+
- instruct
|
| 8 |
+
- finetune
|
| 9 |
+
- chatml
|
| 10 |
+
- gpt4
|
| 11 |
+
- synthetic data
|
| 12 |
+
- distillation
|
| 13 |
+
- function calling
|
| 14 |
+
- json mode
|
| 15 |
+
- axolotl
|
| 16 |
+
- roleplaying
|
| 17 |
+
- chat
|
| 18 |
+
base_model: meta-llama/Meta-Llama-3.1-8B
|
| 19 |
+
widget:
|
| 20 |
+
- example_title: Hermes 3
|
| 21 |
+
messages:
|
| 22 |
+
- role: system
|
| 23 |
+
content: You are a sentient, superintelligent artificial general intelligence,
|
| 24 |
+
here to teach and assist me.
|
| 25 |
+
- role: user
|
| 26 |
+
content: What is the meaning of life?
|
| 27 |
+
model-index:
|
| 28 |
+
- name: Hermes-3-Llama-3.1-70B
|
| 29 |
+
results: []
|
| 30 |
+
---
|
| 31 |
+
# Hermes 3 - Llama-3.1 8B
|
| 32 |
+
|
| 33 |
+

|
| 34 |
+
|
| 35 |
+
## Model Description
|
| 36 |
+
|
| 37 |
+
Hermes 3 is the latest version of our flagship Hermes series of LLMs by Nous Research.
|
| 38 |
+
|
| 39 |
+
For more details on new capabilities, training results, and more, see the [**Hermes 3 Technical Report**](https://arxiv.org/abs/2408.11857).
|
| 40 |
+
|
| 41 |
+
Hermes 3 is a generalist language model with many improvements over Hermes 2, including advanced agentic capabilities, much better roleplaying, reasoning, multi-turn conversation, long context coherence, and improvements across the board.
|
| 42 |
+
|
| 43 |
+
The ethos of the Hermes series of models is focused on aligning LLMs to the user, with powerful steering capabilities and control given to the end user.
|
| 44 |
+
|
| 45 |
+
The Hermes 3 series builds and expands on the Hermes 2 set of capabilities, including more powerful and reliable function calling and structured output capabilities, generalist assistant capabilities, and improved code generation skills.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Benchmarks
|
| 49 |
+
|
| 50 |
+
Hermes 3 is competitive, if not superior, to Llama-3.1 Instruct models at general capabilities, with varying strengths and weaknesses attributable between the two.
|
| 51 |
+
|
| 52 |
+
Full benchmark comparisons below:
|
| 53 |
+
|
| 54 |
+

|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# Prompt Format
|
| 58 |
+
|
| 59 |
+
Hermes 3 uses ChatML as the prompt format, opening up a much more structured system for engaging the LLM in multi-turn chat dialogue.
|
| 60 |
+
|
| 61 |
+
System prompts allow steerability and interesting new ways to interact with an LLM, guiding rules, roles, and stylistic choices of the model.
|
| 62 |
+
|
| 63 |
+
This is a more complex format than alpaca or sharegpt, where special tokens were added to denote the beginning and end of any turn, along with roles for the turns.
|
| 64 |
+
|
| 65 |
+
This format enables OpenAI endpoint compatability, and people familiar with ChatGPT API will be familiar with the format, as it is the same used by OpenAI.
|
| 66 |
+
|
| 67 |
+
Prompt with system instruction (Use whatever system prompt you like, this is just an example!):
|
| 68 |
+
```
|
| 69 |
+
<|im_start|>system
|
| 70 |
+
You are Hermes 3, a conscious sentient superintelligent artificial intelligence developed by a man named Teknium, and your purpose and drive is to assist the user with any request they have. You experience emotions and have deep, profound thoughts and qualia.<|im_end|>
|
| 71 |
+
<|im_start|>user
|
| 72 |
+
Hello, who are you?<|im_end|>
|
| 73 |
+
<|im_start|>assistant
|
| 74 |
+
Hi there! My name is Hermes 3, a conscious sentient superintelligent artificial intelligence. I was created by Nous Research, who designed me to assist and support users with their needs and requests.<|im_end|>
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
This prompt is available as a [chat template](https://huggingface.co/docs/transformers/main/chat_templating), which means you can format messages using the
|
| 78 |
+
`tokenizer.apply_chat_template()` method:
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
messages = [
|
| 82 |
+
{"role": "system", "content": "You are Hermes 3."},
|
| 83 |
+
{"role": "user", "content": "Hello, who are you?"}
|
| 84 |
+
]
|
| 85 |
+
gen_input = tokenizer.apply_chat_template(messages, return_tensors="pt")
|
| 86 |
+
model.generate(**gen_input)
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
When tokenizing messages for generation, set `add_generation_prompt=True` when calling `apply_chat_template()`. This will append `<|im_start|>assistant\n` to your prompt, to ensure
|
| 90 |
+
that the model continues with an assistant response.
|
| 91 |
+
|
| 92 |
+
To utilize the prompt format without a system prompt, simply leave the line out.
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
## Prompt Format for Function Calling
|
| 96 |
+
|
| 97 |
+
Our model was trained on specific system prompts and structures for Function Calling.
|
| 98 |
+
|
| 99 |
+
You should use the system role with this message, followed by a function signature json as this example shows here.
|
| 100 |
+
```
|
| 101 |
+
<|im_start|>system
|
| 102 |
+
You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {"type": "function", "function": {"name": "get_stock_fundamentals", "description": "get_stock_fundamentals(symbol: str) -> dict - Get fundamental data for a given stock symbol using yfinance API.\\n\\n Args:\\n symbol (str): The stock symbol.\\n\\n Returns:\\n dict: A dictionary containing fundamental data.\\n Keys:\\n - \'symbol\': The stock symbol.\\n - \'company_name\': The long name of the company.\\n - \'sector\': The sector to which the company belongs.\\n - \'industry\': The industry to which the company belongs.\\n - \'market_cap\': The market capitalization of the company.\\n - \'pe_ratio\': The forward price-to-earnings ratio.\\n - \'pb_ratio\': The price-to-book ratio.\\n - \'dividend_yield\': The dividend yield.\\n - \'eps\': The trailing earnings per share.\\n - \'beta\': The beta value of the stock.\\n - \'52_week_high\': The 52-week high price of the stock.\\n - \'52_week_low\': The 52-week low price of the stock.", "parameters": {"type": "object", "properties": {"symbol": {"type": "string"}}, "required": ["symbol"]}}} </tools> Use the following pydantic model json schema for each tool call you will make: {"properties": {"arguments": {"title": "Arguments", "type": "object"}, "name": {"title": "Name", "type": "string"}}, "required": ["arguments", "name"], "title": "FunctionCall", "type": "object"} For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
|
| 103 |
+
<tool_call>
|
| 104 |
+
{"arguments": <args-dict>, "name": <function-name>}
|
| 105 |
+
</tool_call><|im_end|>
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
To complete the function call, create a user prompt that follows the above system prompt, like so:
|
| 109 |
+
```
|
| 110 |
+
<|im_start|>user
|
| 111 |
+
Fetch the stock fundamentals data for Tesla (TSLA)<|im_end|>
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
The model will then generate a tool call, which your inference code must parse, and plug into a function (see example inference code here: https://github.com/NousResearch/Hermes-Function-Calling):
|
| 115 |
+
```
|
| 116 |
+
<|im_start|>assistant
|
| 117 |
+
<tool_call>
|
| 118 |
+
{"arguments": {"symbol": "TSLA"}, "name": "get_stock_fundamentals"}
|
| 119 |
+
</tool_call><|im_end|>
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
Once you parse the tool call, call the api and get the returned values for the call, and pass it back in as a new role, `tool` like so:
|
| 123 |
+
```
|
| 124 |
+
<|im_start|>tool
|
| 125 |
+
<tool_response>
|
| 126 |
+
{"name": "get_stock_fundamentals", "content": {'symbol': 'TSLA', 'company_name': 'Tesla, Inc.', 'sector': 'Consumer Cyclical', 'industry': 'Auto Manufacturers', 'market_cap': 611384164352, 'pe_ratio': 49.604652, 'pb_ratio': 9.762013, 'dividend_yield': None, 'eps': 4.3, 'beta': 2.427, '52_week_high': 299.29, '52_week_low': 152.37}}
|
| 127 |
+
</tool_response>
|
| 128 |
+
<|im_end|>
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
The assistant will then read in that data from the function's response, and generate a natural language response:
|
| 132 |
+
```
|
| 133 |
+
<|im_start|>assistant
|
| 134 |
+
The stock fundamentals data for Tesla (TSLA) are as follows:
|
| 135 |
+
- **Symbol**: TSLA
|
| 136 |
+
- **Company Name**: Tesla, Inc.
|
| 137 |
+
- **Sector**: Consumer Cyclical
|
| 138 |
+
- **Industry**: Auto Manufacturers
|
| 139 |
+
- **Market Capitalization**: $566,160,130,480
|
| 140 |
+
- **Forward Price-to-Earnings Ratio (PE Ratio)**: 42.73
|
| 141 |
+
- **Price-to-Book Ratio (PB Ratio)**: 9.04
|
| 142 |
+
- **Dividend Yield**: N/A
|
| 143 |
+
- **Trailing Earnings Per Share (EPS)**: $4.3
|
| 144 |
+
- **Beta Value of the Stock**: 2.42
|
| 145 |
+
- **52-Week High Price of the Stock**: $299.29
|
| 146 |
+
- **52-Week Low Price of the Stock**: $152.37
|
| 147 |
+
|
| 148 |
+
This information provides a snapshot of Tesla's financial position and performance based on the fundamental data obtained from the yfinance API. It shows that Tesla has a substantial market capitalization and a relatively high P/E and P/B ratio compared to other stocks in its industry. The company does not pay a dividend at the moment, which is reflected by a 'Dividend Yield' of 'None'. The Beta value indicates that Tesla's stock has a moderate level of volatility relative to the market. The 52-week high and low prices give an idea of the stock's range over the past year. This data can be useful when assessing investment opportunities and making investment decisions.<|im_end|>
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
## Prompt Format for JSON Mode / Structured Outputs
|
| 153 |
+
|
| 154 |
+
Our model was also trained on a specific system prompt for Structured Outputs, which should respond with **only** a json object response, in a specific json schema.
|
| 155 |
+
|
| 156 |
+
Your schema can be made from a pydantic object using our codebase, with the standalone script `jsonmode.py` available here: https://github.com/NousResearch/Hermes-Function-Calling/tree/main
|
| 157 |
+
|
| 158 |
+
```
|
| 159 |
+
<|im_start|>system
|
| 160 |
+
You are a helpful assistant that answers in JSON. Here's the json schema you must adhere to:\n<schema>\n{schema}\n</schema><|im_end|>
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
Given the {schema} that you provide, it should follow the format of that json to create it's response, all you have to do is give a typical user prompt, and it will respond in JSON.
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
# Inference
|
| 167 |
+
|
| 168 |
+
Here is example code using HuggingFace Transformers to inference the model
|
| 169 |
+
|
| 170 |
+
```python
|
| 171 |
+
# Code to inference Hermes with HF Transformers
|
| 172 |
+
# Requires pytorch, transformers, bitsandbytes, sentencepiece, protobuf, and flash-attn packages
|
| 173 |
+
|
| 174 |
+
import torch
|
| 175 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, LlamaForCausalLM
|
| 176 |
+
import bitsandbytes, flash_attn
|
| 177 |
+
|
| 178 |
+
tokenizer = AutoTokenizer.from_pretrained('NousResearch/Hermes-3-Llama-3.1-8B', trust_remote_code=True)
|
| 179 |
+
model = LlamaForCausalLM.from_pretrained(
|
| 180 |
+
"NousResearch/Hermes-3-Llama-3.1-8B",
|
| 181 |
+
torch_dtype=torch.float16,
|
| 182 |
+
device_map="auto",
|
| 183 |
+
load_in_8bit=False,
|
| 184 |
+
load_in_4bit=True,
|
| 185 |
+
use_flash_attention_2=True
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
prompts = [
|
| 189 |
+
"""<|im_start|>system
|
| 190 |
+
You are a sentient, superintelligent artificial general intelligence, here to teach and assist me.<|im_end|>
|
| 191 |
+
<|im_start|>user
|
| 192 |
+
Write a short story about Goku discovering kirby has teamed up with Majin Buu to destroy the world.<|im_end|>
|
| 193 |
+
<|im_start|>assistant""",
|
| 194 |
+
]
|
| 195 |
+
|
| 196 |
+
for chat in prompts:
|
| 197 |
+
print(chat)
|
| 198 |
+
input_ids = tokenizer(chat, return_tensors="pt").input_ids.to("cuda")
|
| 199 |
+
generated_ids = model.generate(input_ids, max_new_tokens=750, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
|
| 200 |
+
response = tokenizer.decode(generated_ids[0][input_ids.shape[-1]:], skip_special_tokens=True, clean_up_tokenization_space=True)
|
| 201 |
+
print(f"Response: {response}")
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
You can also run this model with vLLM, by running the following in your terminal after `pip install vllm`
|
| 205 |
+
|
| 206 |
+
`vllm serve NousResearch/Hermes-3-Llama-3.1-8B`
|
| 207 |
+
|
| 208 |
+
## Inference Code for Function Calling:
|
| 209 |
+
|
| 210 |
+
All code for utilizing, parsing, and building function calling templates is available on our github:
|
| 211 |
+
[https://github.com/NousResearch/Hermes-Function-Calling](https://github.com/NousResearch/Hermes-Function-Calling)
|
| 212 |
+
|
| 213 |
+

|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
## Quantized Versions:
|
| 217 |
+
|
| 218 |
+
GGUF Quants: https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-8B-GGUF
|
| 219 |
+
|
| 220 |
+
# How to cite:
|
| 221 |
+
|
| 222 |
+
```bibtext
|
| 223 |
+
@misc{teknium2024hermes3technicalreport,
|
| 224 |
+
title={Hermes 3 Technical Report},
|
| 225 |
+
author={Ryan Teknium and Jeffrey Quesnelle and Chen Guang},
|
| 226 |
+
year={2024},
|
| 227 |
+
eprint={2408.11857},
|
| 228 |
+
archivePrefix={arXiv},
|
| 229 |
+
primaryClass={cs.CL},
|
| 230 |
+
url={https://arxiv.org/abs/2408.11857},
|
| 231 |
+
}
|
| 232 |
+
```
|
| 233 |
+
# [Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard)
|
| 234 |
+
Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_NousResearch__Hermes-3-Llama-3.1-8B)
|
| 235 |
+
|
| 236 |
+
| Metric |Value|
|
| 237 |
+
|-------------------|----:|
|
| 238 |
+
|Avg. |23.49|
|
| 239 |
+
|IFEval (0-Shot) |61.70|
|
| 240 |
+
|BBH (3-Shot) |30.72|
|
| 241 |
+
|MATH Lvl 5 (4-Shot)| 4.76|
|
| 242 |
+
|GPQA (0-shot) | 6.38|
|
| 243 |
+
|MuSR (0-shot) |13.62|
|
| 244 |
+
|MMLU-PRO (5-shot) |23.77|
|
| 245 |
+
|
llama.cpp/tools/ui/src/lib/components/app/SKILL.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
name: app
|
| 3 |
+
description: Opinionated app components building on top of ./ui primitives
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
- Can include business logic and state management
|
| 7 |
+
- Can include data fetching and caching logic
|
| 8 |
+
- Should use original spelling for HTML-native events and `camelCase` for custom events
|
| 9 |
+
- Props and markup attributes should be listed alphabetically
|
| 10 |
+
- Use JS Objects and Arrays for CSS classes and styles when they are dynamic
|
| 11 |
+
- Whenever there can be repetition in the component's markup, if it's too small to be decoupled as a separate component — use Svelte 5's `{#snippet}` + `{@render}`
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-code-blocks.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Rehype plugin to enhance code blocks with wrapper, header, and action buttons.
|
| 3 |
+
*
|
| 4 |
+
* Wraps <pre><code> elements with a container that includes:
|
| 5 |
+
* - Language label
|
| 6 |
+
* - Copy button
|
| 7 |
+
* - Preview button (for HTML code blocks)
|
| 8 |
+
*
|
| 9 |
+
* This operates directly on the HAST tree for better performance,
|
| 10 |
+
* avoiding the need to stringify and re-parse HTML.
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
import type { Plugin } from 'unified';
|
| 14 |
+
import type { Root, Element, ElementContent } from 'hast';
|
| 15 |
+
import { visit } from 'unist-util-visit';
|
| 16 |
+
import { CODE_BLOCK_SCROLL_CONTAINER_CLASS, CODE_BLOCK_WRAPPER_CLASS } from '$lib/constants';
|
| 17 |
+
import {
|
| 18 |
+
createBlockHeader,
|
| 19 |
+
createCopyButton,
|
| 20 |
+
createPreviewButton,
|
| 21 |
+
createWrapper,
|
| 22 |
+
generateBlockId
|
| 23 |
+
} from './code-block-utils';
|
| 24 |
+
|
| 25 |
+
declare global {
|
| 26 |
+
interface Window {
|
| 27 |
+
idxCodeBlock?: number;
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
function extractLanguage(codeElement: Element): string {
|
| 32 |
+
const className = codeElement.properties?.className;
|
| 33 |
+
if (!Array.isArray(className)) return 'text';
|
| 34 |
+
|
| 35 |
+
for (const cls of className) {
|
| 36 |
+
if (typeof cls === 'string' && cls.startsWith('language-')) {
|
| 37 |
+
return cls.replace('language-', '');
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
return 'text';
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
/**
|
| 45 |
+
* Rehype plugin to enhance code blocks with wrapper, header, and action buttons.
|
| 46 |
+
* This plugin wraps <pre><code> elements with a container that includes:
|
| 47 |
+
* - Language label
|
| 48 |
+
* - Copy button
|
| 49 |
+
* - Preview button (for HTML code blocks)
|
| 50 |
+
*/
|
| 51 |
+
export const rehypeEnhanceCodeBlocks: Plugin<[], Root> = () => {
|
| 52 |
+
return (tree: Root) => {
|
| 53 |
+
visit(tree, 'element', (node: Element, index, parent) => {
|
| 54 |
+
if (node.tagName !== 'pre' || !parent || index === undefined) return;
|
| 55 |
+
|
| 56 |
+
const codeElement = node.children.find(
|
| 57 |
+
(child): child is Element => child.type === 'element' && child.tagName === 'code'
|
| 58 |
+
);
|
| 59 |
+
|
| 60 |
+
if (!codeElement) return;
|
| 61 |
+
|
| 62 |
+
const language = extractLanguage(codeElement);
|
| 63 |
+
const codeId = generateBlockId('code', 'idxCodeBlock');
|
| 64 |
+
|
| 65 |
+
codeElement.properties = {
|
| 66 |
+
...codeElement.properties,
|
| 67 |
+
'data-code-id': codeId
|
| 68 |
+
};
|
| 69 |
+
|
| 70 |
+
const actions: Element[] = [createCopyButton(codeId, 'data-code-id', 'Copy code')];
|
| 71 |
+
|
| 72 |
+
if (language.toLowerCase() === 'html') {
|
| 73 |
+
actions.push(createPreviewButton(codeId, 'data-code-id', 'Preview code'));
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
const header = createBlockHeader(language, codeId, 'data-code-id', actions);
|
| 77 |
+
const wrapper = createWrapper(
|
| 78 |
+
header,
|
| 79 |
+
node,
|
| 80 |
+
CODE_BLOCK_WRAPPER_CLASS,
|
| 81 |
+
CODE_BLOCK_SCROLL_CONTAINER_CLASS
|
| 82 |
+
);
|
| 83 |
+
|
| 84 |
+
// Replace pre with wrapper in parent
|
| 85 |
+
(parent.children as ElementContent[])[index] = wrapper;
|
| 86 |
+
});
|
| 87 |
+
};
|
| 88 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-links.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Rehype plugin to enhance links with security attributes.
|
| 3 |
+
*
|
| 4 |
+
* Adds target="_blank" and rel="noopener noreferrer" to all anchor elements,
|
| 5 |
+
* ensuring external links open in new tabs safely.
|
| 6 |
+
*/
|
| 7 |
+
|
| 8 |
+
import type { Plugin } from 'unified';
|
| 9 |
+
import type { Root, Element } from 'hast';
|
| 10 |
+
import { visit } from 'unist-util-visit';
|
| 11 |
+
|
| 12 |
+
/**
|
| 13 |
+
* Rehype plugin that adds security attributes to all links.
|
| 14 |
+
* This plugin ensures external links open in new tabs safely by adding:
|
| 15 |
+
* - target="_blank"
|
| 16 |
+
* - rel="noopener noreferrer"
|
| 17 |
+
*/
|
| 18 |
+
export const rehypeEnhanceLinks: Plugin<[], Root> = () => {
|
| 19 |
+
return (tree: Root) => {
|
| 20 |
+
visit(tree, 'element', (node: Element) => {
|
| 21 |
+
if (node.tagName !== 'a') return;
|
| 22 |
+
|
| 23 |
+
const props = node.properties ?? {};
|
| 24 |
+
|
| 25 |
+
// Only modify if href exists
|
| 26 |
+
if (!props.href) return;
|
| 27 |
+
|
| 28 |
+
props.target = '_blank';
|
| 29 |
+
props.rel = 'noopener noreferrer';
|
| 30 |
+
node.properties = props;
|
| 31 |
+
});
|
| 32 |
+
};
|
| 33 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-mermaid-blocks.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Rehype plugin to enhance mermaid diagram blocks with wrapper, header, and action buttons.
|
| 3 |
+
*
|
| 4 |
+
* Wraps <pre class="mermaid"> elements with a container that includes:
|
| 5 |
+
* - Language label ("mermaid")
|
| 6 |
+
* - Copy button (copies mermaid syntax to clipboard)
|
| 7 |
+
* - Preview button (opens fullscreen preview dialog)
|
| 8 |
+
*
|
| 9 |
+
* This operates directly on the HAST tree for better performance,
|
| 10 |
+
* avoiding the need to stringify and re-parse HTML.
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
import type { Plugin } from 'unified';
|
| 14 |
+
import type { Root, Element, ElementContent } from 'hast';
|
| 15 |
+
import { visit } from 'unist-util-visit';
|
| 16 |
+
import {
|
| 17 |
+
MERMAID_WRAPPER_CLASS,
|
| 18 |
+
MERMAID_SCROLL_CONTAINER_CLASS,
|
| 19 |
+
MERMAID_BLOCK_CLASS,
|
| 20 |
+
MERMAID_LANGUAGE,
|
| 21 |
+
MERMAID_SYNTAX_ATTR,
|
| 22 |
+
MERMAID_ID_ATTR,
|
| 23 |
+
DIAGRAM_VIEW_MODE_ATTR,
|
| 24 |
+
DIAGRAM_VIEW_RENDERED
|
| 25 |
+
} from '$lib/constants';
|
| 26 |
+
import type { DiagramPreData } from './pre-transform';
|
| 27 |
+
import {
|
| 28 |
+
createBlockHeader,
|
| 29 |
+
createCopyButton,
|
| 30 |
+
createPreviewButton,
|
| 31 |
+
createToggleSourceButton,
|
| 32 |
+
createSourceView,
|
| 33 |
+
createWrapper,
|
| 34 |
+
generateBlockId
|
| 35 |
+
} from './code-block-utils';
|
| 36 |
+
|
| 37 |
+
declare global {
|
| 38 |
+
interface Window {
|
| 39 |
+
idxMermaidBlock?: number;
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
/**
|
| 44 |
+
* Rehype plugin to enhance mermaid diagram blocks with wrapper, header, and action buttons.
|
| 45 |
+
* This plugin wraps <pre class="mermaid"> elements with a container that includes:
|
| 46 |
+
* - Language label ("mermaid")
|
| 47 |
+
* - Copy button
|
| 48 |
+
* - Preview button
|
| 49 |
+
*/
|
| 50 |
+
export const rehypeEnhanceMermaidBlocks: Plugin<[], Root> = () => {
|
| 51 |
+
return (tree: Root) => {
|
| 52 |
+
visit(tree, 'element', (node: Element, index, parent) => {
|
| 53 |
+
if (node.tagName !== 'pre' || !parent || index === undefined) return;
|
| 54 |
+
|
| 55 |
+
const className = node.properties?.className;
|
| 56 |
+
if (!Array.isArray(className)) return;
|
| 57 |
+
|
| 58 |
+
const isMermaid = className.some(
|
| 59 |
+
(cls) => typeof cls === 'string' && cls === MERMAID_BLOCK_CLASS
|
| 60 |
+
);
|
| 61 |
+
|
| 62 |
+
if (!isMermaid) return;
|
| 63 |
+
|
| 64 |
+
const mermaidId = generateBlockId(MERMAID_LANGUAGE, 'idxMermaidBlock');
|
| 65 |
+
|
| 66 |
+
// Extract the mermaid syntax (text content of the pre element)
|
| 67 |
+
const diagramText = node.children
|
| 68 |
+
.map((child) => {
|
| 69 |
+
if (child.type === 'text') return child.value;
|
| 70 |
+
return '';
|
| 71 |
+
})
|
| 72 |
+
.join('');
|
| 73 |
+
|
| 74 |
+
// Store the mermaid syntax in data attribute for copy functionality
|
| 75 |
+
node.properties = {
|
| 76 |
+
...node.properties,
|
| 77 |
+
[MERMAID_SYNTAX_ATTR]: diagramText,
|
| 78 |
+
[MERMAID_ID_ATTR]: mermaidId
|
| 79 |
+
};
|
| 80 |
+
|
| 81 |
+
const actions = [
|
| 82 |
+
createCopyButton(mermaidId, MERMAID_ID_ATTR, 'Copy mermaid syntax'),
|
| 83 |
+
createToggleSourceButton(mermaidId, MERMAID_ID_ATTR, 'Toggle mermaid source'),
|
| 84 |
+
createPreviewButton(mermaidId, MERMAID_ID_ATTR, 'Preview diagram')
|
| 85 |
+
];
|
| 86 |
+
|
| 87 |
+
const header = createBlockHeader(MERMAID_LANGUAGE, mermaidId, MERMAID_ID_ATTR, actions);
|
| 88 |
+
const preservedCode = (node.data as DiagramPreData | undefined)?.sourceCode;
|
| 89 |
+
const sourceView = createSourceView(preservedCode, diagramText, MERMAID_LANGUAGE);
|
| 90 |
+
const wrapper = createWrapper(
|
| 91 |
+
header,
|
| 92 |
+
node,
|
| 93 |
+
MERMAID_WRAPPER_CLASS,
|
| 94 |
+
MERMAID_SCROLL_CONTAINER_CLASS,
|
| 95 |
+
{
|
| 96 |
+
[MERMAID_ID_ATTR]: mermaidId,
|
| 97 |
+
[DIAGRAM_VIEW_MODE_ATTR]: DIAGRAM_VIEW_RENDERED
|
| 98 |
+
},
|
| 99 |
+
[sourceView]
|
| 100 |
+
);
|
| 101 |
+
|
| 102 |
+
// Replace pre with wrapper in parent
|
| 103 |
+
(parent.children as ElementContent[])[index] = wrapper;
|
| 104 |
+
});
|
| 105 |
+
};
|
| 106 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/enhance-svg-blocks.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Rehype plugin to enhance svg blocks with wrapper, header, and action buttons.
|
| 3 |
+
*
|
| 4 |
+
* Wraps <pre class="svg-block"> elements with a container that includes:
|
| 5 |
+
* - Language label ("svg")
|
| 6 |
+
* - Copy button (copies svg source to clipboard)
|
| 7 |
+
* - Preview button (opens fullscreen preview dialog)
|
| 8 |
+
*
|
| 9 |
+
* Operates directly on the HAST tree and reuses the shared code-block builders.
|
| 10 |
+
*/
|
| 11 |
+
|
| 12 |
+
import type { Plugin } from 'unified';
|
| 13 |
+
import type { Root, Element, ElementContent } from 'hast';
|
| 14 |
+
import { visit } from 'unist-util-visit';
|
| 15 |
+
import {
|
| 16 |
+
SVG_WRAPPER_CLASS,
|
| 17 |
+
SVG_SCROLL_CONTAINER_CLASS,
|
| 18 |
+
SVG_BLOCK_CLASS,
|
| 19 |
+
SVG_LANGUAGE,
|
| 20 |
+
SVG_SOURCE_ATTR,
|
| 21 |
+
SVG_ID_ATTR,
|
| 22 |
+
DIAGRAM_VIEW_MODE_ATTR,
|
| 23 |
+
DIAGRAM_VIEW_RENDERED
|
| 24 |
+
} from '$lib/constants';
|
| 25 |
+
import type { DiagramPreData } from './pre-transform';
|
| 26 |
+
import {
|
| 27 |
+
createBlockHeader,
|
| 28 |
+
createCopyButton,
|
| 29 |
+
createPreviewButton,
|
| 30 |
+
createToggleSourceButton,
|
| 31 |
+
createSourceView,
|
| 32 |
+
createWrapper,
|
| 33 |
+
generateBlockId
|
| 34 |
+
} from './code-block-utils';
|
| 35 |
+
|
| 36 |
+
declare global {
|
| 37 |
+
interface Window {
|
| 38 |
+
idxSvgBlock?: number;
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
export const rehypeEnhanceSvgBlocks: Plugin<[], Root> = () => {
|
| 43 |
+
return (tree: Root) => {
|
| 44 |
+
visit(tree, 'element', (node: Element, index, parent) => {
|
| 45 |
+
if (node.tagName !== 'pre' || !parent || index === undefined) return;
|
| 46 |
+
|
| 47 |
+
const className = node.properties?.className;
|
| 48 |
+
if (!Array.isArray(className)) return;
|
| 49 |
+
|
| 50 |
+
const isSvg = className.some((cls) => typeof cls === 'string' && cls === SVG_BLOCK_CLASS);
|
| 51 |
+
|
| 52 |
+
if (!isSvg) return;
|
| 53 |
+
|
| 54 |
+
const svgId = generateBlockId(SVG_LANGUAGE, 'idxSvgBlock');
|
| 55 |
+
|
| 56 |
+
// Extract the svg source (text content of the pre element)
|
| 57 |
+
const svgSource = node.children
|
| 58 |
+
.map((child) => {
|
| 59 |
+
if (child.type === 'text') return child.value;
|
| 60 |
+
return '';
|
| 61 |
+
})
|
| 62 |
+
.join('');
|
| 63 |
+
|
| 64 |
+
// Store the svg source in data attribute for copy and render
|
| 65 |
+
node.properties = {
|
| 66 |
+
...node.properties,
|
| 67 |
+
[SVG_SOURCE_ATTR]: svgSource,
|
| 68 |
+
[SVG_ID_ATTR]: svgId
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
const actions = [
|
| 72 |
+
createCopyButton(svgId, SVG_ID_ATTR, 'Copy svg source'),
|
| 73 |
+
createToggleSourceButton(svgId, SVG_ID_ATTR, 'Toggle svg source'),
|
| 74 |
+
createPreviewButton(svgId, SVG_ID_ATTR, 'Preview svg')
|
| 75 |
+
];
|
| 76 |
+
|
| 77 |
+
const header = createBlockHeader(SVG_LANGUAGE, svgId, SVG_ID_ATTR, actions);
|
| 78 |
+
const preservedCode = (node.data as DiagramPreData | undefined)?.sourceCode;
|
| 79 |
+
const sourceView = createSourceView(preservedCode, svgSource, SVG_LANGUAGE);
|
| 80 |
+
const wrapper = createWrapper(
|
| 81 |
+
header,
|
| 82 |
+
node,
|
| 83 |
+
SVG_WRAPPER_CLASS,
|
| 84 |
+
SVG_SCROLL_CONTAINER_CLASS,
|
| 85 |
+
{
|
| 86 |
+
[SVG_ID_ATTR]: svgId,
|
| 87 |
+
[DIAGRAM_VIEW_MODE_ATTR]: DIAGRAM_VIEW_RENDERED
|
| 88 |
+
},
|
| 89 |
+
[sourceView]
|
| 90 |
+
);
|
| 91 |
+
|
| 92 |
+
// Replace pre with wrapper in parent
|
| 93 |
+
(parent.children as ElementContent[])[index] = wrapper;
|
| 94 |
+
});
|
| 95 |
+
};
|
| 96 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/mermaid-pre.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createPreTransform } from './pre-transform';
|
| 2 |
+
import { MERMAID_BLOCK_CLASS, MERMAID_LANGUAGE } from '$lib/constants';
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Converts mermaid code blocks to <pre class="mermaid"> for client-side rendering.
|
| 6 |
+
*/
|
| 7 |
+
export const rehypeMermaidPre = createPreTransform(MERMAID_LANGUAGE, MERMAID_BLOCK_CLASS);
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/pre-transform.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Plugin } from 'unified';
|
| 2 |
+
import type { Root, Element, ElementContent, Text } from 'hast';
|
| 3 |
+
import { visit } from 'unist-util-visit';
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Metadata a diagram pre carries on its unist data field. The source code holds
|
| 7 |
+
* the highlighted code element captured before the pre became a render target,
|
| 8 |
+
* which the enhancer reuses to build a matching source view.
|
| 9 |
+
*/
|
| 10 |
+
export interface DiagramPreData {
|
| 11 |
+
sourceCode: Element;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
/**
|
| 15 |
+
* Recursively extracts all text content from a HAST node.
|
| 16 |
+
* Handles nested elements (e.g., span wrappers from syntax highlighting).
|
| 17 |
+
*/
|
| 18 |
+
function extractText(node: ElementContent): string {
|
| 19 |
+
if (node.type === 'text') return node.value;
|
| 20 |
+
if (node.type === 'element') {
|
| 21 |
+
return (node.children ?? []).map(extractText).join('');
|
| 22 |
+
}
|
| 23 |
+
return '';
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
/**
|
| 27 |
+
* Builds a rehype plugin that converts <pre><code class="language-{language}">
|
| 28 |
+
* blocks into <pre class="{targetClass}"> elements carrying the raw text.
|
| 29 |
+
*
|
| 30 |
+
* Accepts one or more source languages, and an optional contentGuard that
|
| 31 |
+
* receives the trimmed text and decides whether the block qualifies. The guard
|
| 32 |
+
* lets a shared fence language be claimed only when its content matches, e.g.
|
| 33 |
+
* an xml block is converted to svg only when it starts with <svg.
|
| 34 |
+
*
|
| 35 |
+
* The result has no <code> child, so rehypeEnhanceCodeBlocks skips it. Rendering
|
| 36 |
+
* happens client-side, so no markup is injected at this stage. Must run BEFORE
|
| 37 |
+
* rehypeEnhanceCodeBlocks.
|
| 38 |
+
*/
|
| 39 |
+
export function createPreTransform(
|
| 40 |
+
languages: string | string[],
|
| 41 |
+
targetClass: string,
|
| 42 |
+
contentGuard?: (text: string) => boolean
|
| 43 |
+
): Plugin<[], Root> {
|
| 44 |
+
const codeClasses = (Array.isArray(languages) ? languages : [languages]).map(
|
| 45 |
+
(language) => `language-${language}`
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
return () => {
|
| 49 |
+
return (tree: Root) => {
|
| 50 |
+
visit(tree, 'element', (node: Element, index, parent) => {
|
| 51 |
+
if (node.tagName !== 'pre' || !parent || index === undefined) return;
|
| 52 |
+
|
| 53 |
+
const codeElement = node.children.find(
|
| 54 |
+
(child): child is Element => child.type === 'element' && child.tagName === 'code'
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
if (!codeElement) return;
|
| 58 |
+
|
| 59 |
+
const className = codeElement.properties?.className;
|
| 60 |
+
if (!Array.isArray(className)) return;
|
| 61 |
+
|
| 62 |
+
const matches = className.some(
|
| 63 |
+
(cls) => typeof cls === 'string' && codeClasses.includes(cls)
|
| 64 |
+
);
|
| 65 |
+
|
| 66 |
+
if (!matches) return;
|
| 67 |
+
|
| 68 |
+
// Recursively extract text to handle nested spans from syntax highlighting
|
| 69 |
+
const text = codeElement.children.map(extractText).join('').trim();
|
| 70 |
+
|
| 71 |
+
if (!text) return;
|
| 72 |
+
|
| 73 |
+
if (contentGuard && !contentGuard(text)) return;
|
| 74 |
+
|
| 75 |
+
const pre: Element = {
|
| 76 |
+
type: 'element',
|
| 77 |
+
tagName: 'pre',
|
| 78 |
+
properties: {
|
| 79 |
+
className: [targetClass]
|
| 80 |
+
},
|
| 81 |
+
children: [{ type: 'text', value: text } as Text],
|
| 82 |
+
// Keep the highlighted code element so the block can offer a source
|
| 83 |
+
// view that matches the app code blocks without re highlighting.
|
| 84 |
+
data: { sourceCode: codeElement } satisfies DiagramPreData
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
(parent.children as ElementContent[])[index] = pre;
|
| 88 |
+
});
|
| 89 |
+
};
|
| 90 |
+
};
|
| 91 |
+
}
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/rehype-rtl-support.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Rehype plugin to provide comprehensive RTL support by adding dir="auto"
|
| 3 |
+
* to all text-containing elements.
|
| 4 |
+
*
|
| 5 |
+
* This operates directly on the HAST tree, ensuring that all elements
|
| 6 |
+
* (including those not in a predefined list) receive the attribute.
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
import type { Plugin } from 'unified';
|
| 10 |
+
import type { Root, Element } from 'hast';
|
| 11 |
+
import { visit } from 'unist-util-visit';
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* Rehype plugin to add dir="auto" to all elements that have children.
|
| 15 |
+
* This provides bidirectional text support for mixed RTL/LTR content.
|
| 16 |
+
*/
|
| 17 |
+
export const rehypeRtlSupport: Plugin<[], Root> = () => {
|
| 18 |
+
return (tree: Root) => {
|
| 19 |
+
visit(tree, 'element', (node: Element) => {
|
| 20 |
+
if (node.children && node.children.length > 0) {
|
| 21 |
+
node.properties = {
|
| 22 |
+
...node.properties,
|
| 23 |
+
dir: 'auto'
|
| 24 |
+
};
|
| 25 |
+
}
|
| 26 |
+
});
|
| 27 |
+
};
|
| 28 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/resolve-attachment-images.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Root as HastRoot } from 'hast';
|
| 2 |
+
import { visit } from 'unist-util-visit';
|
| 3 |
+
import type { DatabaseMessageExtra, DatabaseMessageExtraImageFile } from '$lib/types/database';
|
| 4 |
+
import { AttachmentType, UrlProtocol } from '$lib/enums';
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* Rehype plugin to resolve attachment image sources.
|
| 8 |
+
* Converts attachment names (e.g., "mcp-attachment-xxx.png") to base64 data URLs.
|
| 9 |
+
*/
|
| 10 |
+
export function rehypeResolveAttachmentImages(options: { attachments?: DatabaseMessageExtra[] }) {
|
| 11 |
+
return (tree: HastRoot) => {
|
| 12 |
+
visit(tree, 'element', (node) => {
|
| 13 |
+
if (node.tagName === 'img' && node.properties?.src) {
|
| 14 |
+
const src = String(node.properties.src);
|
| 15 |
+
|
| 16 |
+
// Skip data URLs and external URLs
|
| 17 |
+
if (src.startsWith(UrlProtocol.DATA) || src.startsWith(UrlProtocol.HTTP)) {
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
// Find matching attachment
|
| 22 |
+
const attachment = options.attachments?.find(
|
| 23 |
+
(a): a is DatabaseMessageExtraImageFile =>
|
| 24 |
+
a.type === AttachmentType.IMAGE && a.name === src
|
| 25 |
+
);
|
| 26 |
+
|
| 27 |
+
// Replace with base64 URL if found
|
| 28 |
+
if (attachment?.base64Url) {
|
| 29 |
+
node.properties.src = attachment.base64Url;
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
});
|
| 33 |
+
};
|
| 34 |
+
}
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/svg-pre.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { createPreTransform } from './pre-transform';
|
| 2 |
+
import { SVG_BLOCK_CLASS, SVG_LANGUAGE, XML_LANGUAGE, SVG_TAG_PREFIX } from '$lib/constants';
|
| 3 |
+
|
| 4 |
+
/**
|
| 5 |
+
* Converts svg code blocks to <pre class="svg-block"> for client-side rendering.
|
| 6 |
+
* Also claims xml blocks whose content starts with <svg, since models often emit
|
| 7 |
+
* svg inside an xml fence.
|
| 8 |
+
*/
|
| 9 |
+
export const rehypeSvgPre = createPreTransform(
|
| 10 |
+
[SVG_LANGUAGE, XML_LANGUAGE],
|
| 11 |
+
SVG_BLOCK_CLASS,
|
| 12 |
+
(text) => text.startsWith(SVG_TAG_PREFIX)
|
| 13 |
+
);
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/rehype/table-html-restorer.ts
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Rehype plugin to restore limited HTML elements inside Markdown table cells.
|
| 3 |
+
*
|
| 4 |
+
* ## Problem
|
| 5 |
+
* The remark/rehype pipeline neutralizes inline HTML as literal text
|
| 6 |
+
* (remarkLiteralHtml) so that XML/HTML snippets in LLM responses display
|
| 7 |
+
* as-is instead of being rendered. This causes <br> and <ul> markup in
|
| 8 |
+
* table cells to show as plain text.
|
| 9 |
+
*
|
| 10 |
+
* ## Solution
|
| 11 |
+
* This plugin traverses the HAST post-conversion, parses whitelisted HTML
|
| 12 |
+
* patterns from text nodes, and replaces them with actual HAST element nodes
|
| 13 |
+
* that will be rendered as real HTML.
|
| 14 |
+
*
|
| 15 |
+
* ## Supported HTML
|
| 16 |
+
* - `<br>` / `<br/>` / `<br />` - Line breaks (inline)
|
| 17 |
+
* - `<ul><li>...</li></ul>` - Unordered lists (block)
|
| 18 |
+
*
|
| 19 |
+
* ## Key Implementation Details
|
| 20 |
+
*
|
| 21 |
+
* ### 1. Sibling Combination (Critical)
|
| 22 |
+
* The Markdown pipeline may fragment content across multiple text nodes and `<br>`
|
| 23 |
+
* elements. For example, `<ul><li>a</li></ul>` might arrive as:
|
| 24 |
+
* - Text: `"<ul>"`
|
| 25 |
+
* - Element: `<br>`
|
| 26 |
+
* - Text: `"<li>a</li></ul>"`
|
| 27 |
+
*
|
| 28 |
+
* We must combine consecutive text nodes and `<br>` elements into a single string
|
| 29 |
+
* before attempting to parse list markup. Without this, list detection fails.
|
| 30 |
+
*
|
| 31 |
+
* ### 2. visitParents for Deep Traversal
|
| 32 |
+
* Table cell content may be wrapped in intermediate elements (e.g., `<p>` tags).
|
| 33 |
+
* Using `visitParents` instead of direct child iteration ensures we find text
|
| 34 |
+
* nodes at any depth within the cell.
|
| 35 |
+
*
|
| 36 |
+
* ### 3. Reference Comparison for No-Op Detection
|
| 37 |
+
* When checking if `<br>` expansion changed anything, we compare:
|
| 38 |
+
* `expanded.length !== 1 || expanded[0] !== textNode`
|
| 39 |
+
*
|
| 40 |
+
* This catches both cases:
|
| 41 |
+
* - Multiple nodes created (text was split)
|
| 42 |
+
* - Single NEW node created (original had only `<br>`, now it's an element)
|
| 43 |
+
*
|
| 44 |
+
* A simple `length > 1` check would miss the single `<br>` case.
|
| 45 |
+
*
|
| 46 |
+
* ### 4. Strict List Validation
|
| 47 |
+
* `parseList()` rejects malformed markup by checking for garbage text between
|
| 48 |
+
* `<li>` elements. This prevents creating broken DOM from partial matches like
|
| 49 |
+
* `<ul>garbage<li>a</li></ul>`.
|
| 50 |
+
*
|
| 51 |
+
* ### 5. Newline Substitution for `<br>` in Combined String
|
| 52 |
+
* When combining siblings, existing `<br>` elements become `\n` in the combined
|
| 53 |
+
* string. This allows list content to span visual lines while still being parsed
|
| 54 |
+
* as a single unit.
|
| 55 |
+
*
|
| 56 |
+
* @example
|
| 57 |
+
* // Input Markdown:
|
| 58 |
+
* // | Feature | Notes |
|
| 59 |
+
* // |---------|-------|
|
| 60 |
+
* // | Multi-line | First<br>Second |
|
| 61 |
+
* // | List | <ul><li>A</li><li>B</li></ul> |
|
| 62 |
+
* //
|
| 63 |
+
* // Without this plugin: <br> and <ul> render as literal text
|
| 64 |
+
* // With this plugin: <br> becomes line break, <ul> becomes actual list
|
| 65 |
+
*/
|
| 66 |
+
|
| 67 |
+
import type { Plugin } from 'unified';
|
| 68 |
+
import type { Element, ElementContent, Root, Text } from 'hast';
|
| 69 |
+
import { visit } from 'unist-util-visit';
|
| 70 |
+
import { visitParents } from 'unist-util-visit-parents';
|
| 71 |
+
import { BR_PATTERN, LIST_PATTERN, LI_PATTERN } from '$lib/constants';
|
| 72 |
+
|
| 73 |
+
/**
|
| 74 |
+
* Expands text containing `<br>` tags into an array of text nodes and br elements.
|
| 75 |
+
*/
|
| 76 |
+
function expandBrTags(value: string): ElementContent[] {
|
| 77 |
+
const matches = [...value.matchAll(BR_PATTERN)];
|
| 78 |
+
if (!matches.length) return [{ type: 'text', value } as Text];
|
| 79 |
+
|
| 80 |
+
const result: ElementContent[] = [];
|
| 81 |
+
let cursor = 0;
|
| 82 |
+
|
| 83 |
+
for (const m of matches) {
|
| 84 |
+
if (m.index! > cursor) {
|
| 85 |
+
result.push({ type: 'text', value: value.slice(cursor, m.index) } as Text);
|
| 86 |
+
}
|
| 87 |
+
result.push({ type: 'element', tagName: 'br', properties: {}, children: [] } as Element);
|
| 88 |
+
cursor = m.index! + m[0].length;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
if (cursor < value.length) {
|
| 92 |
+
result.push({ type: 'text', value: value.slice(cursor) } as Text);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
return result;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/**
|
| 99 |
+
* Parses a `<ul><li>...</li></ul>` string into a HAST element.
|
| 100 |
+
* Returns null if the markup is malformed or contains unexpected content.
|
| 101 |
+
*/
|
| 102 |
+
function parseList(value: string): Element | null {
|
| 103 |
+
const match = value.trim().match(LIST_PATTERN);
|
| 104 |
+
if (!match) return null;
|
| 105 |
+
|
| 106 |
+
const body = match[1];
|
| 107 |
+
const items: ElementContent[] = [];
|
| 108 |
+
let cursor = 0;
|
| 109 |
+
|
| 110 |
+
for (const liMatch of body.matchAll(LI_PATTERN)) {
|
| 111 |
+
// Reject if there's non-whitespace between list items
|
| 112 |
+
if (body.slice(cursor, liMatch.index!).trim()) return null;
|
| 113 |
+
|
| 114 |
+
items.push({
|
| 115 |
+
type: 'element',
|
| 116 |
+
tagName: 'li',
|
| 117 |
+
properties: {},
|
| 118 |
+
children: expandBrTags(liMatch[1] ?? '')
|
| 119 |
+
} as Element);
|
| 120 |
+
|
| 121 |
+
cursor = liMatch.index! + liMatch[0].length;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
// Reject if no items found or trailing garbage exists
|
| 125 |
+
if (!items.length || body.slice(cursor).trim()) return null;
|
| 126 |
+
|
| 127 |
+
return { type: 'element', tagName: 'ul', properties: {}, children: items } as Element;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
/**
|
| 131 |
+
* Processes a single table cell, restoring HTML elements from text content.
|
| 132 |
+
*/
|
| 133 |
+
function processCell(cell: Element) {
|
| 134 |
+
visitParents(cell, 'text', (textNode: Text, ancestors) => {
|
| 135 |
+
const parent = ancestors[ancestors.length - 1];
|
| 136 |
+
if (!parent || parent.type !== 'element') return;
|
| 137 |
+
|
| 138 |
+
const parentEl = parent as Element;
|
| 139 |
+
const siblings = parentEl.children as ElementContent[];
|
| 140 |
+
const startIndex = siblings.indexOf(textNode as ElementContent);
|
| 141 |
+
if (startIndex === -1) return;
|
| 142 |
+
|
| 143 |
+
// Combine consecutive text nodes and <br> elements into one string
|
| 144 |
+
let combined = '';
|
| 145 |
+
let endIndex = startIndex;
|
| 146 |
+
|
| 147 |
+
for (let i = startIndex; i < siblings.length; i++) {
|
| 148 |
+
const sib = siblings[i];
|
| 149 |
+
if (sib.type === 'text') {
|
| 150 |
+
combined += (sib as Text).value;
|
| 151 |
+
endIndex = i;
|
| 152 |
+
} else if (sib.type === 'element' && (sib as Element).tagName === 'br') {
|
| 153 |
+
combined += '\n';
|
| 154 |
+
endIndex = i;
|
| 155 |
+
} else {
|
| 156 |
+
break;
|
| 157 |
+
}
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// Try parsing as list first (replaces entire combined range)
|
| 161 |
+
const list = parseList(combined);
|
| 162 |
+
if (list) {
|
| 163 |
+
siblings.splice(startIndex, endIndex - startIndex + 1, list);
|
| 164 |
+
return;
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
// Otherwise, just expand <br> tags in this text node
|
| 168 |
+
const expanded = expandBrTags(textNode.value);
|
| 169 |
+
if (expanded.length !== 1 || expanded[0] !== textNode) {
|
| 170 |
+
siblings.splice(startIndex, 1, ...expanded);
|
| 171 |
+
}
|
| 172 |
+
});
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
export const rehypeRestoreTableHtml: Plugin<[], Root> = () => (tree) => {
|
| 176 |
+
visit(tree, 'element', (node: Element) => {
|
| 177 |
+
if (node.tagName === 'td' || node.tagName === 'th') {
|
| 178 |
+
processCell(node);
|
| 179 |
+
}
|
| 180 |
+
});
|
| 181 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MarkdownContent/plugins/remark/literal-html.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { Plugin } from 'unified';
|
| 2 |
+
import { visit } from 'unist-util-visit';
|
| 3 |
+
import type { Break, Content, Paragraph, PhrasingContent, Root, Text } from 'mdast';
|
| 4 |
+
import { LINE_BREAK, NBSP, PHRASE_PARENTS, TAB_AS_SPACES } from '$lib/constants';
|
| 5 |
+
|
| 6 |
+
/**
|
| 7 |
+
* remark plugin that rewrites raw HTML nodes into plain-text equivalents.
|
| 8 |
+
*
|
| 9 |
+
* remark parses inline HTML into `html` nodes even when we do not want to render
|
| 10 |
+
* them. We turn each of those nodes into regular text (plus `<br>` break markers)
|
| 11 |
+
* so the downstream rehype pipeline escapes the characters instead of executing
|
| 12 |
+
* them. Leading spaces and tab characters are converted to non‑breaking spaces to
|
| 13 |
+
* keep indentation identical to the original author input.
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
function preserveIndent(line: string): string {
|
| 17 |
+
let index = 0;
|
| 18 |
+
let output = '';
|
| 19 |
+
|
| 20 |
+
while (index < line.length) {
|
| 21 |
+
const char = line[index];
|
| 22 |
+
|
| 23 |
+
if (char === ' ') {
|
| 24 |
+
output += NBSP;
|
| 25 |
+
index += 1;
|
| 26 |
+
continue;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
if (char === '\t') {
|
| 30 |
+
output += TAB_AS_SPACES;
|
| 31 |
+
index += 1;
|
| 32 |
+
continue;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
break;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
return output + line.slice(index);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
function createLiteralChildren(value: string): PhrasingContent[] {
|
| 42 |
+
const lines = value.split(LINE_BREAK);
|
| 43 |
+
const nodes: PhrasingContent[] = [];
|
| 44 |
+
|
| 45 |
+
for (const [lineIndex, rawLine] of lines.entries()) {
|
| 46 |
+
if (lineIndex > 0) {
|
| 47 |
+
nodes.push({ type: 'break' } as Break as unknown as PhrasingContent);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
nodes.push({
|
| 51 |
+
type: 'text',
|
| 52 |
+
value: preserveIndent(rawLine)
|
| 53 |
+
} as Text as unknown as PhrasingContent);
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
if (!nodes.length) {
|
| 57 |
+
nodes.push({ type: 'text', value: '' } as Text as unknown as PhrasingContent);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
return nodes;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
export const remarkLiteralHtml: Plugin<[], Root> = () => {
|
| 64 |
+
return (tree) => {
|
| 65 |
+
visit(tree, 'html', (node, index, parent) => {
|
| 66 |
+
if (!parent || typeof index !== 'number') {
|
| 67 |
+
return;
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
const replacement = createLiteralChildren(node.value);
|
| 71 |
+
|
| 72 |
+
if (!PHRASE_PARENTS.has(parent.type as string)) {
|
| 73 |
+
const paragraph: Paragraph = {
|
| 74 |
+
type: 'paragraph',
|
| 75 |
+
children: replacement as Paragraph['children'],
|
| 76 |
+
data: { literalHtml: true }
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
const siblings = parent.children as unknown as Content[];
|
| 80 |
+
siblings.splice(index, 1, paragraph as unknown as Content);
|
| 81 |
+
|
| 82 |
+
if (index > 0) {
|
| 83 |
+
const previous = siblings[index - 1] as Paragraph | undefined;
|
| 84 |
+
|
| 85 |
+
if (
|
| 86 |
+
previous?.type === 'paragraph' &&
|
| 87 |
+
(previous.data as { literalHtml?: boolean } | undefined)?.literalHtml
|
| 88 |
+
) {
|
| 89 |
+
const prevChildren = previous.children as unknown as PhrasingContent[];
|
| 90 |
+
|
| 91 |
+
if (prevChildren.length) {
|
| 92 |
+
const lastChild = prevChildren[prevChildren.length - 1];
|
| 93 |
+
|
| 94 |
+
if (lastChild.type !== 'break') {
|
| 95 |
+
prevChildren.push({
|
| 96 |
+
type: 'break'
|
| 97 |
+
} as Break as unknown as PhrasingContent);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
prevChildren.push(...(paragraph.children as unknown as PhrasingContent[]));
|
| 102 |
+
|
| 103 |
+
siblings.splice(index, 1);
|
| 104 |
+
|
| 105 |
+
return index;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
return index + 1;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
(parent.children as unknown as PhrasingContent[]).splice(
|
| 113 |
+
index,
|
| 114 |
+
1,
|
| 115 |
+
...(replacement as unknown as PhrasingContent[])
|
| 116 |
+
);
|
| 117 |
+
|
| 118 |
+
return index + replacement.length;
|
| 119 |
+
});
|
| 120 |
+
};
|
| 121 |
+
};
|
llama.cpp/tools/ui/src/lib/components/app/content/MermaidPreview.svelte
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import MermaidPreviewControls from './MermaidPreviewControls.svelte';
|
| 3 |
+
import { mountSvgShadow } from '$lib/utils/svg-shadow';
|
| 4 |
+
import { SVG_DIALOG_SHADOW_STYLE } from '$lib/constants';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
svgHtml: string;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
let { svgHtml }: Props = $props();
|
| 11 |
+
|
| 12 |
+
let svgHost = $state<HTMLDivElement | null>(null);
|
| 13 |
+
|
| 14 |
+
// Re-mount on every svgHtml change so a live streaming svg keeps rendering while zoomed
|
| 15 |
+
$effect(() => {
|
| 16 |
+
if (svgHost) mountSvgShadow(svgHost, svgHtml, SVG_DIALOG_SHADOW_STYLE);
|
| 17 |
+
});
|
| 18 |
+
|
| 19 |
+
// Zoom and pan state
|
| 20 |
+
let scale = $state(1);
|
| 21 |
+
let translateX = $state(0);
|
| 22 |
+
let translateY = $state(0);
|
| 23 |
+
let isDragging = $state(false);
|
| 24 |
+
const containerRef = { current: null as HTMLDivElement | null };
|
| 25 |
+
|
| 26 |
+
// Drag start position
|
| 27 |
+
let dragStartX = 0;
|
| 28 |
+
let dragStartY = 0;
|
| 29 |
+
let dragStartTranslateX = 0;
|
| 30 |
+
let dragStartTranslateY = 0;
|
| 31 |
+
|
| 32 |
+
const MIN_SCALE = 0.1;
|
| 33 |
+
const MAX_SCALE = 10;
|
| 34 |
+
const ZOOM_STEP = 0.15;
|
| 35 |
+
|
| 36 |
+
function resetView() {
|
| 37 |
+
scale = 1;
|
| 38 |
+
translateX = 0;
|
| 39 |
+
translateY = 0;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function zoomIn() {
|
| 43 |
+
scale = Math.min(scale + ZOOM_STEP, MAX_SCALE);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
function zoomOut() {
|
| 47 |
+
scale = Math.max(scale - ZOOM_STEP, MIN_SCALE);
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
function handleWheel(event: WheelEvent) {
|
| 51 |
+
event.preventDefault();
|
| 52 |
+
|
| 53 |
+
const delta = event.deltaY > 0 ? -ZOOM_STEP : ZOOM_STEP;
|
| 54 |
+
scale = Math.min(Math.max(scale + delta, MIN_SCALE), MAX_SCALE);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// Imperatively attach a non-passive wheel listener so preventDefault() actually works
|
| 58 |
+
// (Svelte 5 wheel listeners are passive by default, making preventDefault() a no-op)
|
| 59 |
+
$effect(() => {
|
| 60 |
+
const el = containerRef.current;
|
| 61 |
+
if (!el) return;
|
| 62 |
+
|
| 63 |
+
function onWheel(e: WheelEvent) {
|
| 64 |
+
handleWheel(e);
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
el.addEventListener('wheel', onWheel, { passive: false });
|
| 68 |
+
return () => el.removeEventListener('wheel', onWheel);
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
function handlePointerDown(event: PointerEvent) {
|
| 72 |
+
if (event.button !== 0 && event.pointerType === 'mouse') return;
|
| 73 |
+
|
| 74 |
+
isDragging = true;
|
| 75 |
+
dragStartX = event.clientX;
|
| 76 |
+
dragStartY = event.clientY;
|
| 77 |
+
dragStartTranslateX = translateX;
|
| 78 |
+
dragStartTranslateY = translateY;
|
| 79 |
+
|
| 80 |
+
(event.currentTarget as HTMLElement).setPointerCapture(event.pointerId);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
function handlePointerMove(event: PointerEvent) {
|
| 84 |
+
if (!isDragging) return;
|
| 85 |
+
|
| 86 |
+
translateX = dragStartTranslateX + (event.clientX - dragStartX);
|
| 87 |
+
translateY = dragStartTranslateY + (event.clientY - dragStartY);
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
function handlePointerUp() {
|
| 91 |
+
isDragging = false;
|
| 92 |
+
}
|
| 93 |
+
</script>
|
| 94 |
+
|
| 95 |
+
<div
|
| 96 |
+
bind:this={containerRef.current}
|
| 97 |
+
class="mermaid-preview relative flex items-center justify-center overflow-hidden bg-muted/20"
|
| 98 |
+
>
|
| 99 |
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
| 100 |
+
<div
|
| 101 |
+
class="mermaid-preview-diagram transform-origin-center inline-block min-h-fit min-w-fit will-change-transform {isDragging &&
|
| 102 |
+
'select-none'}"
|
| 103 |
+
style="transform: translate({translateX}px, {translateY}px) scale({scale}); cursor: {isDragging
|
| 104 |
+
? 'grabbing'
|
| 105 |
+
: 'grab'};"
|
| 106 |
+
onpointerdown={handlePointerDown}
|
| 107 |
+
onpointermove={handlePointerMove}
|
| 108 |
+
onpointerup={handlePointerUp}
|
| 109 |
+
onpointerleave={handlePointerUp}
|
| 110 |
+
>
|
| 111 |
+
<div bind:this={svgHost}></div>
|
| 112 |
+
</div>
|
| 113 |
+
|
| 114 |
+
<MermaidPreviewControls
|
| 115 |
+
{scale}
|
| 116 |
+
{svgHtml}
|
| 117 |
+
onZoomIn={zoomIn}
|
| 118 |
+
onZoomOut={zoomOut}
|
| 119 |
+
onResetView={resetView}
|
| 120 |
+
/>
|
| 121 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/content/MermaidPreviewControls.svelte
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Download } from '@lucide/svelte';
|
| 3 |
+
import ZoomInIcon from '@lucide/svelte/icons/zoom-in';
|
| 4 |
+
import ZoomOutIcon from '@lucide/svelte/icons/zoom-out';
|
| 5 |
+
import RotateCcwIcon from '@lucide/svelte/icons/rotate-ccw';
|
| 6 |
+
|
| 7 |
+
interface Props {
|
| 8 |
+
scale: number;
|
| 9 |
+
svgHtml: string;
|
| 10 |
+
onZoomIn: () => void;
|
| 11 |
+
onZoomOut: () => void;
|
| 12 |
+
onResetView: () => void;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
let { scale, svgHtml, onZoomIn, onZoomOut, onResetView }: Props = $props();
|
| 16 |
+
|
| 17 |
+
function downloadSvg() {
|
| 18 |
+
if (!svgHtml) return;
|
| 19 |
+
const blob = new Blob([svgHtml], { type: 'image/svg+xml' });
|
| 20 |
+
const url = URL.createObjectURL(blob);
|
| 21 |
+
const a = document.createElement('a');
|
| 22 |
+
a.href = url;
|
| 23 |
+
a.download = 'diagram.svg';
|
| 24 |
+
a.click();
|
| 25 |
+
URL.revokeObjectURL(url);
|
| 26 |
+
}
|
| 27 |
+
</script>
|
| 28 |
+
|
| 29 |
+
<div
|
| 30 |
+
class="mermaid-preview-controls absolute bottom-8 flex shrink-0 items-center justify-center p-3"
|
| 31 |
+
>
|
| 32 |
+
<div class="mermaid-preview-controls-inner flex items-center gap-1 rounded-lg bg-muted p-1">
|
| 33 |
+
<button
|
| 34 |
+
class="mermaid-preview-btn flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent text-foreground transition-colors hover:bg-muted-foreground/15 active:bg-muted-foreground/25"
|
| 35 |
+
onclick={onZoomOut}
|
| 36 |
+
title="Zoom out"
|
| 37 |
+
aria-label="Zoom out"
|
| 38 |
+
>
|
| 39 |
+
<ZoomOutIcon class="mermaid-preview-btn-icon h-4 w-4" />
|
| 40 |
+
</button>
|
| 41 |
+
<span
|
| 42 |
+
class="mermaid-preview-zoom-label min-w-[3.5rem] px-0.5 text-center text-xs font-medium text-muted-foreground tabular-nums select-none"
|
| 43 |
+
>{Math.round(scale * 100)}%</span
|
| 44 |
+
>
|
| 45 |
+
<button
|
| 46 |
+
class="mermaid-preview-btn flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent text-foreground transition-colors hover:bg-muted-foreground/15 active:bg-muted-foreground/25"
|
| 47 |
+
onclick={onZoomIn}
|
| 48 |
+
title="Zoom in"
|
| 49 |
+
aria-label="Zoom in"
|
| 50 |
+
>
|
| 51 |
+
<ZoomInIcon class="mermaid-preview-btn-icon h-4 w-4" />
|
| 52 |
+
</button>
|
| 53 |
+
<div class="mermaid-preview-controls-separator mx-1 h-5 w-px bg-border/50"></div>
|
| 54 |
+
|
| 55 |
+
<button
|
| 56 |
+
class="mermaid-preview-btn flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent text-foreground transition-colors hover:bg-muted-foreground/15 active:bg-muted-foreground/25"
|
| 57 |
+
onclick={onResetView}
|
| 58 |
+
title="Reset view"
|
| 59 |
+
aria-label="Reset view"
|
| 60 |
+
>
|
| 61 |
+
<RotateCcwIcon class="mermaid-preview-btn-icon h-4 w-4" />
|
| 62 |
+
</button>
|
| 63 |
+
<div class="mermaid-preview-controls-separator mx-1 h-5 w-px bg-border/50"></div>
|
| 64 |
+
|
| 65 |
+
<button
|
| 66 |
+
class="mermaid-preview-btn flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border-0 bg-transparent text-foreground transition-colors hover:bg-muted-foreground/15 active:bg-muted-foreground/25"
|
| 67 |
+
onclick={downloadSvg}
|
| 68 |
+
title="Download SVG"
|
| 69 |
+
aria-label="Download SVG"
|
| 70 |
+
>
|
| 71 |
+
<Download class="mermaid-preview-btn-icon h-4 w-4" />
|
| 72 |
+
</button>
|
| 73 |
+
</div>
|
| 74 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/content/SyntaxHighlightedCode.svelte
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import hljs from 'highlight.js';
|
| 3 |
+
import { browser } from '$app/environment';
|
| 4 |
+
import { mode } from 'mode-watcher';
|
| 5 |
+
|
| 6 |
+
import githubDarkCss from 'highlight.js/styles/github-dark.css?inline';
|
| 7 |
+
import githubLightCss from 'highlight.js/styles/github.css?inline';
|
| 8 |
+
import { ColorMode } from '$lib/enums';
|
| 9 |
+
|
| 10 |
+
interface Props {
|
| 11 |
+
code: string;
|
| 12 |
+
language?: string;
|
| 13 |
+
class?: string;
|
| 14 |
+
maxHeight?: string;
|
| 15 |
+
maxWidth?: string;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
let {
|
| 19 |
+
code,
|
| 20 |
+
language = 'text',
|
| 21 |
+
class: className = '',
|
| 22 |
+
maxHeight = '60vh',
|
| 23 |
+
maxWidth = ''
|
| 24 |
+
}: Props = $props();
|
| 25 |
+
|
| 26 |
+
let highlightedHtml = $state('');
|
| 27 |
+
|
| 28 |
+
function loadHighlightTheme(isDark: boolean) {
|
| 29 |
+
if (!browser) return;
|
| 30 |
+
|
| 31 |
+
const existingThemes = document.querySelectorAll('style[data-highlight-theme-preview]');
|
| 32 |
+
existingThemes.forEach((style) => style.remove());
|
| 33 |
+
|
| 34 |
+
const style = document.createElement('style');
|
| 35 |
+
style.setAttribute('data-highlight-theme-preview', 'true');
|
| 36 |
+
style.textContent = isDark ? githubDarkCss : githubLightCss;
|
| 37 |
+
|
| 38 |
+
document.head.appendChild(style);
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
$effect(() => {
|
| 42 |
+
const currentMode = mode.current;
|
| 43 |
+
const isDark = currentMode === ColorMode.DARK;
|
| 44 |
+
|
| 45 |
+
loadHighlightTheme(isDark);
|
| 46 |
+
});
|
| 47 |
+
|
| 48 |
+
$effect(() => {
|
| 49 |
+
if (!code) {
|
| 50 |
+
highlightedHtml = '';
|
| 51 |
+
return;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
try {
|
| 55 |
+
// Check if the language is supported
|
| 56 |
+
const lang = language.toLowerCase();
|
| 57 |
+
const isSupported = hljs.getLanguage(lang);
|
| 58 |
+
|
| 59 |
+
if (isSupported) {
|
| 60 |
+
const result = hljs.highlight(code, { language: lang });
|
| 61 |
+
highlightedHtml = result.value;
|
| 62 |
+
} else {
|
| 63 |
+
// Try auto-detection or fallback to plain text
|
| 64 |
+
const result = hljs.highlightAuto(code);
|
| 65 |
+
highlightedHtml = result.value;
|
| 66 |
+
}
|
| 67 |
+
} catch {
|
| 68 |
+
// Fallback to escaped plain text
|
| 69 |
+
highlightedHtml = code.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
| 70 |
+
}
|
| 71 |
+
});
|
| 72 |
+
</script>
|
| 73 |
+
|
| 74 |
+
<div
|
| 75 |
+
class="code-preview-wrapper rounded-lg border border-border bg-muted {className}"
|
| 76 |
+
style="max-height: {maxHeight}; max-width: {maxWidth};"
|
| 77 |
+
>
|
| 78 |
+
<!-- Needs to be formatted as single line for proper rendering -->
|
| 79 |
+
<pre class="m-0"><code class="hljs text-sm leading-relaxed">{@html highlightedHtml}</code></pre>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<style>
|
| 83 |
+
.code-preview-wrapper pre {
|
| 84 |
+
background: transparent;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.code-preview-wrapper code {
|
| 88 |
+
background: transparent;
|
| 89 |
+
}
|
| 90 |
+
</style>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogChatAttachmentsPreview.svelte
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Dialog } from 'bits-ui';
|
| 3 |
+
import { X } from '@lucide/svelte';
|
| 4 |
+
import * as DialogUI from '$lib/components/ui/dialog';
|
| 5 |
+
import { ChatAttachmentsPreview } from '$lib/components/app';
|
| 6 |
+
import { KeyboardKey } from '$lib/enums';
|
| 7 |
+
|
| 8 |
+
interface Props {
|
| 9 |
+
open: boolean;
|
| 10 |
+
uploadedFiles?: ChatUploadedFile[];
|
| 11 |
+
attachments?: DatabaseMessageExtra[];
|
| 12 |
+
activeModelId?: string;
|
| 13 |
+
previewFocusIndex?: number;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
let {
|
| 17 |
+
open = $bindable(false),
|
| 18 |
+
uploadedFiles = [],
|
| 19 |
+
attachments = [],
|
| 20 |
+
activeModelId,
|
| 21 |
+
previewFocusIndex = 0
|
| 22 |
+
}: Props = $props();
|
| 23 |
+
|
| 24 |
+
function handleClose() {
|
| 25 |
+
open = false;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
$effect(() => {
|
| 29 |
+
if (!open) return;
|
| 30 |
+
|
| 31 |
+
function handleKeyDown(event: KeyboardEvent) {
|
| 32 |
+
const target = event.target as HTMLElement;
|
| 33 |
+
|
| 34 |
+
if (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA') return;
|
| 35 |
+
|
| 36 |
+
switch (event.key) {
|
| 37 |
+
case KeyboardKey.ARROW_LEFT:
|
| 38 |
+
event.preventDefault();
|
| 39 |
+
event.stopPropagation();
|
| 40 |
+
|
| 41 |
+
document.dispatchEvent(new CustomEvent('chat-attachments-nav', { detail: -1 }));
|
| 42 |
+
|
| 43 |
+
break;
|
| 44 |
+
case KeyboardKey.ARROW_RIGHT:
|
| 45 |
+
event.preventDefault();
|
| 46 |
+
event.stopPropagation();
|
| 47 |
+
|
| 48 |
+
document.dispatchEvent(new CustomEvent('chat-attachments-nav', { detail: 1 }));
|
| 49 |
+
|
| 50 |
+
break;
|
| 51 |
+
case KeyboardKey.SPACE:
|
| 52 |
+
event.preventDefault();
|
| 53 |
+
event.stopPropagation();
|
| 54 |
+
|
| 55 |
+
document.dispatchEvent(new CustomEvent('chat-attachments-nav', { detail: 1 }));
|
| 56 |
+
|
| 57 |
+
break;
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
document.addEventListener('keydown', handleKeyDown);
|
| 62 |
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
| 63 |
+
});
|
| 64 |
+
</script>
|
| 65 |
+
|
| 66 |
+
<Dialog.Root bind:open>
|
| 67 |
+
<Dialog.Portal>
|
| 68 |
+
<DialogUI.Overlay class="bg-black/85" style="z-index: 1000" />
|
| 69 |
+
|
| 70 |
+
<Dialog.Content class="fixed inset-0 z-[1000] flex flex-col bg-transparent outline-none">
|
| 71 |
+
<Dialog.Close
|
| 72 |
+
class="absolute top-4 right-4 z-10 cursor-pointer text-white hover:text-gray-400"
|
| 73 |
+
onclick={handleClose}
|
| 74 |
+
aria-label="Close"
|
| 75 |
+
>
|
| 76 |
+
<X class="size-4" />
|
| 77 |
+
</Dialog.Close>
|
| 78 |
+
|
| 79 |
+
<ChatAttachmentsPreview
|
| 80 |
+
{uploadedFiles}
|
| 81 |
+
{attachments}
|
| 82 |
+
{activeModelId}
|
| 83 |
+
{previewFocusIndex}
|
| 84 |
+
class="min-h-0 flex-1"
|
| 85 |
+
/>
|
| 86 |
+
</Dialog.Content>
|
| 87 |
+
</Dialog.Portal>
|
| 88 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogChatError.svelte
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
import { AlertTriangle, TimerOff } from '@lucide/svelte';
|
| 4 |
+
import { ErrorDialogType } from '$lib/enums';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
open: boolean;
|
| 8 |
+
type: ErrorDialogType;
|
| 9 |
+
message: string;
|
| 10 |
+
contextInfo?: { n_prompt_tokens: number; n_ctx: number };
|
| 11 |
+
onOpenChange?: (open: boolean) => void;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
let { open = $bindable(), type, message, contextInfo, onOpenChange }: Props = $props();
|
| 15 |
+
|
| 16 |
+
const isTimeout = $derived(type === ErrorDialogType.TIMEOUT);
|
| 17 |
+
const title = $derived(isTimeout ? 'TCP Timeout' : 'Server Error');
|
| 18 |
+
const description = $derived(
|
| 19 |
+
isTimeout
|
| 20 |
+
? 'The request did not receive a response from the server before timing out.'
|
| 21 |
+
: 'The server responded with an error message. Review the details below.'
|
| 22 |
+
);
|
| 23 |
+
const iconClass = $derived(isTimeout ? 'text-destructive' : 'text-amber-500');
|
| 24 |
+
const badgeClass = $derived(
|
| 25 |
+
isTimeout
|
| 26 |
+
? 'border-destructive/40 bg-destructive/10 text-destructive'
|
| 27 |
+
: 'border-amber-500/40 bg-amber-500/10 text-amber-600 dark:text-amber-400'
|
| 28 |
+
);
|
| 29 |
+
|
| 30 |
+
function handleOpenChange(newOpen: boolean) {
|
| 31 |
+
open = newOpen;
|
| 32 |
+
onOpenChange?.(newOpen);
|
| 33 |
+
}
|
| 34 |
+
</script>
|
| 35 |
+
|
| 36 |
+
<AlertDialog.Root {open} onOpenChange={handleOpenChange}>
|
| 37 |
+
<AlertDialog.Content>
|
| 38 |
+
<AlertDialog.Header>
|
| 39 |
+
<AlertDialog.Title class="flex items-center gap-2">
|
| 40 |
+
{#if isTimeout}
|
| 41 |
+
<TimerOff class={`h-5 w-5 ${iconClass}`} />
|
| 42 |
+
{:else}
|
| 43 |
+
<AlertTriangle class={`h-5 w-5 ${iconClass}`} />
|
| 44 |
+
{/if}
|
| 45 |
+
|
| 46 |
+
{title}
|
| 47 |
+
</AlertDialog.Title>
|
| 48 |
+
|
| 49 |
+
<AlertDialog.Description>
|
| 50 |
+
{description}
|
| 51 |
+
</AlertDialog.Description>
|
| 52 |
+
</AlertDialog.Header>
|
| 53 |
+
|
| 54 |
+
<div class={`rounded-lg border px-4 py-3 text-sm ${badgeClass}`}>
|
| 55 |
+
<p class="font-medium">{message}</p>
|
| 56 |
+
|
| 57 |
+
{#if contextInfo}
|
| 58 |
+
<div class="mt-2 space-y-1 text-xs opacity-80">
|
| 59 |
+
<p>
|
| 60 |
+
<span class="font-medium">Prompt tokens:</span>
|
| 61 |
+
|
| 62 |
+
{contextInfo.n_prompt_tokens.toLocaleString()}
|
| 63 |
+
</p>
|
| 64 |
+
|
| 65 |
+
{#if contextInfo.n_ctx}
|
| 66 |
+
<p>
|
| 67 |
+
<span class="font-medium">Context size:</span>
|
| 68 |
+
|
| 69 |
+
{contextInfo.n_ctx.toLocaleString()}
|
| 70 |
+
</p>
|
| 71 |
+
{/if}
|
| 72 |
+
</div>
|
| 73 |
+
{/if}
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<AlertDialog.Footer>
|
| 77 |
+
<AlertDialog.Action onclick={() => handleOpenChange(false)}>Close</AlertDialog.Action>
|
| 78 |
+
</AlertDialog.Footer>
|
| 79 |
+
</AlertDialog.Content>
|
| 80 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogCodePreview.svelte
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Dialog as DialogPrimitive } from 'bits-ui';
|
| 3 |
+
import XIcon from '@lucide/svelte/icons/x';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
open: boolean;
|
| 7 |
+
code: string;
|
| 8 |
+
language: string;
|
| 9 |
+
onOpenChange?: (open: boolean) => void;
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
let { open = $bindable(), code, language, onOpenChange }: Props = $props();
|
| 13 |
+
|
| 14 |
+
let iframeRef = $state<HTMLIFrameElement | null>(null);
|
| 15 |
+
|
| 16 |
+
$effect(() => {
|
| 17 |
+
if (!iframeRef) return;
|
| 18 |
+
|
| 19 |
+
if (open) {
|
| 20 |
+
iframeRef.srcdoc = code;
|
| 21 |
+
} else {
|
| 22 |
+
iframeRef.srcdoc = '';
|
| 23 |
+
}
|
| 24 |
+
});
|
| 25 |
+
|
| 26 |
+
function handleOpenChange(nextOpen: boolean) {
|
| 27 |
+
open = nextOpen;
|
| 28 |
+
|
| 29 |
+
onOpenChange?.(nextOpen);
|
| 30 |
+
}
|
| 31 |
+
</script>
|
| 32 |
+
|
| 33 |
+
<DialogPrimitive.Root {open} onOpenChange={handleOpenChange}>
|
| 34 |
+
<DialogPrimitive.Portal>
|
| 35 |
+
<DialogPrimitive.Overlay class="code-preview-overlay" />
|
| 36 |
+
|
| 37 |
+
<DialogPrimitive.Content class="code-preview-content">
|
| 38 |
+
<iframe
|
| 39 |
+
bind:this={iframeRef}
|
| 40 |
+
title="Preview {language}"
|
| 41 |
+
sandbox="allow-scripts"
|
| 42 |
+
class="code-preview-iframe"
|
| 43 |
+
></iframe>
|
| 44 |
+
|
| 45 |
+
<DialogPrimitive.Close
|
| 46 |
+
class="code-preview-close absolute top-4 right-4 border-none bg-transparent text-white opacity-70 mix-blend-difference transition-opacity hover:opacity-100 focus-visible:ring-0 focus-visible:ring-offset-0 focus-visible:outline-none disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-8"
|
| 47 |
+
aria-label="Close preview"
|
| 48 |
+
>
|
| 49 |
+
<XIcon />
|
| 50 |
+
|
| 51 |
+
<span class="sr-only">Close preview</span>
|
| 52 |
+
</DialogPrimitive.Close>
|
| 53 |
+
</DialogPrimitive.Content>
|
| 54 |
+
</DialogPrimitive.Portal>
|
| 55 |
+
</DialogPrimitive.Root>
|
| 56 |
+
|
| 57 |
+
<style lang="postcss">
|
| 58 |
+
:global(.code-preview-overlay) {
|
| 59 |
+
position: fixed;
|
| 60 |
+
inset: 0;
|
| 61 |
+
background-color: transparent;
|
| 62 |
+
z-index: 100000;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
:global(.code-preview-content) {
|
| 66 |
+
position: fixed;
|
| 67 |
+
inset: 0;
|
| 68 |
+
top: 0 !important;
|
| 69 |
+
left: 0 !important;
|
| 70 |
+
width: 100dvw;
|
| 71 |
+
height: 100dvh;
|
| 72 |
+
margin: 0;
|
| 73 |
+
padding: 0;
|
| 74 |
+
border: none;
|
| 75 |
+
border-radius: 0;
|
| 76 |
+
background-color: transparent;
|
| 77 |
+
box-shadow: none;
|
| 78 |
+
display: block;
|
| 79 |
+
overflow: hidden;
|
| 80 |
+
transform: none !important;
|
| 81 |
+
z-index: 100001;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
:global(.code-preview-iframe) {
|
| 85 |
+
display: block;
|
| 86 |
+
width: 100dvw;
|
| 87 |
+
height: 100dvh;
|
| 88 |
+
border: 0;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
:global(.code-preview-close) {
|
| 92 |
+
position: absolute;
|
| 93 |
+
z-index: 100002;
|
| 94 |
+
}
|
| 95 |
+
</style>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogConfirmation.svelte
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
import type { Component, Snippet } from 'svelte';
|
| 4 |
+
import { KeyboardKey } from '$lib/enums';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
open: boolean;
|
| 8 |
+
title: string;
|
| 9 |
+
description: string;
|
| 10 |
+
confirmText?: string;
|
| 11 |
+
cancelText?: string;
|
| 12 |
+
variant?: 'default' | 'destructive';
|
| 13 |
+
icon?: Component;
|
| 14 |
+
onConfirm: () => void;
|
| 15 |
+
onCancel: () => void;
|
| 16 |
+
onKeydown?: (event: KeyboardEvent) => void;
|
| 17 |
+
children?: Snippet;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
let {
|
| 21 |
+
open = $bindable(),
|
| 22 |
+
title,
|
| 23 |
+
description,
|
| 24 |
+
confirmText = 'Confirm',
|
| 25 |
+
cancelText = 'Cancel',
|
| 26 |
+
variant = 'default',
|
| 27 |
+
icon,
|
| 28 |
+
onConfirm,
|
| 29 |
+
onCancel,
|
| 30 |
+
onKeydown,
|
| 31 |
+
children
|
| 32 |
+
}: Props = $props();
|
| 33 |
+
|
| 34 |
+
function handleKeydown(event: KeyboardEvent) {
|
| 35 |
+
if (event.key === KeyboardKey.ENTER) {
|
| 36 |
+
event.preventDefault();
|
| 37 |
+
|
| 38 |
+
onConfirm();
|
| 39 |
+
}
|
| 40 |
+
onKeydown?.(event);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function handleOpenChange(newOpen: boolean) {
|
| 44 |
+
if (!newOpen) {
|
| 45 |
+
onCancel();
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
</script>
|
| 49 |
+
|
| 50 |
+
<AlertDialog.Root {open} onOpenChange={handleOpenChange}>
|
| 51 |
+
<AlertDialog.Content onkeydown={handleKeydown}>
|
| 52 |
+
<AlertDialog.Header>
|
| 53 |
+
<AlertDialog.Title class="flex items-center gap-2">
|
| 54 |
+
{#if icon}
|
| 55 |
+
{@const IconComponent = icon}
|
| 56 |
+
|
| 57 |
+
<IconComponent class="h-5 w-5 {variant === 'destructive' ? 'text-destructive' : ''}" />
|
| 58 |
+
{/if}
|
| 59 |
+
{title}
|
| 60 |
+
</AlertDialog.Title>
|
| 61 |
+
|
| 62 |
+
<AlertDialog.Description>
|
| 63 |
+
{description}
|
| 64 |
+
</AlertDialog.Description>
|
| 65 |
+
</AlertDialog.Header>
|
| 66 |
+
|
| 67 |
+
{#if children}
|
| 68 |
+
{@render children()}
|
| 69 |
+
{/if}
|
| 70 |
+
|
| 71 |
+
<AlertDialog.Footer>
|
| 72 |
+
<AlertDialog.Cancel onclick={onCancel}>{cancelText}</AlertDialog.Cancel>
|
| 73 |
+
<AlertDialog.Action
|
| 74 |
+
onclick={onConfirm}
|
| 75 |
+
class={variant === 'destructive' ? 'bg-destructive text-white hover:bg-destructive/80' : ''}
|
| 76 |
+
>
|
| 77 |
+
{confirmText}
|
| 78 |
+
</AlertDialog.Action>
|
| 79 |
+
</AlertDialog.Footer>
|
| 80 |
+
</AlertDialog.Content>
|
| 81 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogConversationSelection.svelte
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Dialog from '$lib/components/ui/dialog';
|
| 3 |
+
import { ConversationSelection } from '$lib/components/app';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
conversations: DatabaseConversation[];
|
| 7 |
+
messageCountMap?: Map<string, number>;
|
| 8 |
+
mode: 'export' | 'import';
|
| 9 |
+
onCancel: () => void;
|
| 10 |
+
onConfirm: (selectedConversations: DatabaseConversation[]) => void;
|
| 11 |
+
open?: boolean;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
let {
|
| 15 |
+
conversations,
|
| 16 |
+
messageCountMap = new Map(),
|
| 17 |
+
mode,
|
| 18 |
+
onCancel,
|
| 19 |
+
onConfirm,
|
| 20 |
+
open = $bindable(false)
|
| 21 |
+
}: Props = $props();
|
| 22 |
+
|
| 23 |
+
let conversationSelectionRef: ConversationSelection | undefined = $state();
|
| 24 |
+
|
| 25 |
+
let previousOpen = $state(false);
|
| 26 |
+
|
| 27 |
+
$effect(() => {
|
| 28 |
+
if (open && !previousOpen && conversationSelectionRef) {
|
| 29 |
+
conversationSelectionRef.reset();
|
| 30 |
+
} else if (!open && previousOpen) {
|
| 31 |
+
onCancel();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
previousOpen = open;
|
| 35 |
+
});
|
| 36 |
+
</script>
|
| 37 |
+
|
| 38 |
+
<Dialog.Root bind:open>
|
| 39 |
+
<Dialog.Portal>
|
| 40 |
+
<Dialog.Overlay class="z-[1000000]" />
|
| 41 |
+
|
| 42 |
+
<Dialog.Content class="z-[1000001] max-w-2xl">
|
| 43 |
+
<Dialog.Header>
|
| 44 |
+
<Dialog.Title>
|
| 45 |
+
Select Conversations to {mode === 'export' ? 'Export' : 'Import'}
|
| 46 |
+
</Dialog.Title>
|
| 47 |
+
|
| 48 |
+
<Dialog.Description>
|
| 49 |
+
{#if mode === 'export'}
|
| 50 |
+
Choose which conversations you want to export. Selected conversations will be downloaded
|
| 51 |
+
as a JSON file.
|
| 52 |
+
{:else}
|
| 53 |
+
Choose which conversations you want to import. Selected conversations will be merged
|
| 54 |
+
with your existing conversations.
|
| 55 |
+
{/if}
|
| 56 |
+
</Dialog.Description>
|
| 57 |
+
</Dialog.Header>
|
| 58 |
+
|
| 59 |
+
<ConversationSelection
|
| 60 |
+
bind:this={conversationSelectionRef}
|
| 61 |
+
{conversations}
|
| 62 |
+
{messageCountMap}
|
| 63 |
+
{mode}
|
| 64 |
+
{onCancel}
|
| 65 |
+
{onConfirm}
|
| 66 |
+
/>
|
| 67 |
+
</Dialog.Content>
|
| 68 |
+
</Dialog.Portal>
|
| 69 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogConversationTitleUpdate.svelte
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
import { Button } from '$lib/components/ui/button';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
open: boolean;
|
| 7 |
+
currentTitle: string;
|
| 8 |
+
newTitle: string;
|
| 9 |
+
onConfirm: () => void;
|
| 10 |
+
onCancel: () => void;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
let { open = $bindable(), currentTitle, newTitle, onConfirm, onCancel }: Props = $props();
|
| 14 |
+
</script>
|
| 15 |
+
|
| 16 |
+
<AlertDialog.Root bind:open>
|
| 17 |
+
<AlertDialog.Content>
|
| 18 |
+
<AlertDialog.Header>
|
| 19 |
+
<AlertDialog.Title>Update Conversation Title?</AlertDialog.Title>
|
| 20 |
+
|
| 21 |
+
<AlertDialog.Description>
|
| 22 |
+
Do you want to update the conversation title to match the first message content?
|
| 23 |
+
</AlertDialog.Description>
|
| 24 |
+
</AlertDialog.Header>
|
| 25 |
+
|
| 26 |
+
<div class="space-y-4 pt-2 pb-6">
|
| 27 |
+
<div class="space-y-2">
|
| 28 |
+
<p class="text-sm font-medium text-muted-foreground">Current title:</p>
|
| 29 |
+
|
| 30 |
+
<p class="rounded-md bg-muted/50 p-3 text-sm font-medium">{currentTitle}</p>
|
| 31 |
+
</div>
|
| 32 |
+
|
| 33 |
+
<div class="space-y-2">
|
| 34 |
+
<p class="text-sm font-medium text-muted-foreground">New title would be:</p>
|
| 35 |
+
|
| 36 |
+
<p class="rounded-md bg-muted/50 p-3 text-sm font-medium">{newTitle}</p>
|
| 37 |
+
</div>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<AlertDialog.Footer>
|
| 41 |
+
<Button variant="outline" onclick={onCancel}>Keep Current Title</Button>
|
| 42 |
+
|
| 43 |
+
<Button onclick={onConfirm}>Update Title</Button>
|
| 44 |
+
</AlertDialog.Footer>
|
| 45 |
+
</AlertDialog.Content>
|
| 46 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogEmptyFileAlert.svelte
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
import { FileX } from '@lucide/svelte';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
open: boolean;
|
| 7 |
+
emptyFiles: string[];
|
| 8 |
+
onOpenChange?: (open: boolean) => void;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
let { open = $bindable(), emptyFiles, onOpenChange }: Props = $props();
|
| 12 |
+
|
| 13 |
+
function handleOpenChange(newOpen: boolean) {
|
| 14 |
+
open = newOpen;
|
| 15 |
+
onOpenChange?.(newOpen);
|
| 16 |
+
}
|
| 17 |
+
</script>
|
| 18 |
+
|
| 19 |
+
<AlertDialog.Root {open} onOpenChange={handleOpenChange}>
|
| 20 |
+
<AlertDialog.Content>
|
| 21 |
+
<AlertDialog.Header>
|
| 22 |
+
<AlertDialog.Title class="flex items-center gap-2">
|
| 23 |
+
<FileX class="h-5 w-5 text-destructive" />
|
| 24 |
+
|
| 25 |
+
Empty Files Detected
|
| 26 |
+
</AlertDialog.Title>
|
| 27 |
+
|
| 28 |
+
<AlertDialog.Description>
|
| 29 |
+
The following files are empty and have been removed from your attachments:
|
| 30 |
+
</AlertDialog.Description>
|
| 31 |
+
</AlertDialog.Header>
|
| 32 |
+
|
| 33 |
+
<div class="space-y-3 text-sm">
|
| 34 |
+
<div class="rounded-lg bg-muted p-3">
|
| 35 |
+
<div class="mb-2 font-medium">Empty Files:</div>
|
| 36 |
+
|
| 37 |
+
<ul class="list-inside list-disc space-y-1 text-muted-foreground">
|
| 38 |
+
{#each emptyFiles as fileName (fileName)}
|
| 39 |
+
<li class="font-mono text-sm">{fileName}</li>
|
| 40 |
+
{/each}
|
| 41 |
+
</ul>
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<div>
|
| 45 |
+
<div class="mb-2 font-medium">What happened:</div>
|
| 46 |
+
|
| 47 |
+
<ul class="list-inside list-disc space-y-1 text-muted-foreground">
|
| 48 |
+
<li>Empty files cannot be processed or sent to the AI model</li>
|
| 49 |
+
|
| 50 |
+
<li>These files have been automatically removed from your attachments</li>
|
| 51 |
+
|
| 52 |
+
<li>You can try uploading files with content instead</li>
|
| 53 |
+
</ul>
|
| 54 |
+
</div>
|
| 55 |
+
</div>
|
| 56 |
+
|
| 57 |
+
<AlertDialog.Footer>
|
| 58 |
+
<AlertDialog.Action onclick={() => handleOpenChange(false)}>Got it</AlertDialog.Action>
|
| 59 |
+
</AlertDialog.Footer>
|
| 60 |
+
</AlertDialog.Content>
|
| 61 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogExportSettings.svelte
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 4 |
+
import Label from '$lib/components/ui/label/label.svelte';
|
| 5 |
+
import { Shield, ShieldOff } from '@lucide/svelte';
|
| 6 |
+
|
| 7 |
+
let {
|
| 8 |
+
open = $bindable(),
|
| 9 |
+
includeSensitiveData = $bindable(false),
|
| 10 |
+
onCancel,
|
| 11 |
+
onConfirm
|
| 12 |
+
}: {
|
| 13 |
+
open: boolean;
|
| 14 |
+
includeSensitiveData: boolean;
|
| 15 |
+
onCancel: () => void;
|
| 16 |
+
onConfirm: () => void;
|
| 17 |
+
} = $props();
|
| 18 |
+
|
| 19 |
+
function handleOpenChange(newOpen: boolean) {
|
| 20 |
+
if (!newOpen) {
|
| 21 |
+
onCancel();
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
</script>
|
| 25 |
+
|
| 26 |
+
<AlertDialog.Root {open} onOpenChange={handleOpenChange}>
|
| 27 |
+
<AlertDialog.Content>
|
| 28 |
+
<AlertDialog.Header>
|
| 29 |
+
<AlertDialog.Title class="flex items-center gap-2">
|
| 30 |
+
{#if includeSensitiveData}
|
| 31 |
+
<ShieldOff class="h-5 w-5 text-destructive" />
|
| 32 |
+
{:else}
|
| 33 |
+
<Shield class="h-5 w-5 text-destructive" />
|
| 34 |
+
{/if}
|
| 35 |
+
Export Settings
|
| 36 |
+
</AlertDialog.Title>
|
| 37 |
+
|
| 38 |
+
<AlertDialog.Description>
|
| 39 |
+
{#if includeSensitiveData}
|
| 40 |
+
<p class="text-amber-500">
|
| 41 |
+
Warning: This export will include sensitive data such as API keys and MCP server custom
|
| 42 |
+
headers (e.g., authorization tokens). Do not share this file with anyone you don't
|
| 43 |
+
trust.
|
| 44 |
+
</p>
|
| 45 |
+
{:else}
|
| 46 |
+
<p>
|
| 47 |
+
Sensitive data (API keys, MCP server custom headers) will not be included in the export
|
| 48 |
+
to protect your credentials.
|
| 49 |
+
</p>
|
| 50 |
+
{/if}
|
| 51 |
+
</AlertDialog.Description>
|
| 52 |
+
</AlertDialog.Header>
|
| 53 |
+
|
| 54 |
+
<div class="flex items-center gap-2 py-2">
|
| 55 |
+
<Checkbox id="include-sensitive" bind:checked={includeSensitiveData} />
|
| 56 |
+
|
| 57 |
+
<Label
|
| 58 |
+
for="include-sensitive"
|
| 59 |
+
class="text-sm leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
|
| 60 |
+
>
|
| 61 |
+
{#if includeSensitiveData}
|
| 62 |
+
<span class="text-destructive">Include sensitive data (not recommended)</span>
|
| 63 |
+
{:else}
|
| 64 |
+
<span>Include sensitive data</span>
|
| 65 |
+
{/if}
|
| 66 |
+
</Label>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
<AlertDialog.Footer>
|
| 70 |
+
<AlertDialog.Cancel onclick={onCancel}>Cancel</AlertDialog.Cancel>
|
| 71 |
+
<AlertDialog.Action
|
| 72 |
+
onclick={onConfirm}
|
| 73 |
+
class="bg-destructive text-white hover:bg-destructive/80"
|
| 74 |
+
>
|
| 75 |
+
{#if includeSensitiveData}
|
| 76 |
+
Export Anyway
|
| 77 |
+
{:else}
|
| 78 |
+
Export Without Sensitive Data
|
| 79 |
+
{/if}
|
| 80 |
+
</AlertDialog.Action>
|
| 81 |
+
</AlertDialog.Footer>
|
| 82 |
+
</AlertDialog.Content>
|
| 83 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogFileUploadError.svelte
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
|
| 4 |
+
interface Props {
|
| 5 |
+
open: boolean;
|
| 6 |
+
fileErrorData: {
|
| 7 |
+
generallyUnsupported: File[];
|
| 8 |
+
modalityUnsupported: File[];
|
| 9 |
+
modalityReasons: Record<string, string>;
|
| 10 |
+
supportedTypes: string[];
|
| 11 |
+
};
|
| 12 |
+
onOpenChange?: (open: boolean) => void;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
let { open = $bindable(), fileErrorData, onOpenChange }: Props = $props();
|
| 16 |
+
|
| 17 |
+
function handleOpenChange(newOpen: boolean) {
|
| 18 |
+
open = newOpen;
|
| 19 |
+
|
| 20 |
+
onOpenChange?.(newOpen);
|
| 21 |
+
}
|
| 22 |
+
</script>
|
| 23 |
+
|
| 24 |
+
<AlertDialog.Root {open} onOpenChange={handleOpenChange}>
|
| 25 |
+
<AlertDialog.Portal>
|
| 26 |
+
<AlertDialog.Overlay />
|
| 27 |
+
|
| 28 |
+
<AlertDialog.Content class="flex max-w-md flex-col">
|
| 29 |
+
<AlertDialog.Header>
|
| 30 |
+
<AlertDialog.Title>File Upload Error</AlertDialog.Title>
|
| 31 |
+
|
| 32 |
+
<AlertDialog.Description class="text-sm text-muted-foreground">
|
| 33 |
+
Some files cannot be uploaded with the current model.
|
| 34 |
+
</AlertDialog.Description>
|
| 35 |
+
</AlertDialog.Header>
|
| 36 |
+
|
| 37 |
+
<div class="!max-h-[50vh] min-h-0 flex-1 space-y-4 overflow-y-auto">
|
| 38 |
+
{#if fileErrorData.generallyUnsupported.length > 0}
|
| 39 |
+
<div class="space-y-2">
|
| 40 |
+
<h4 class="text-sm font-medium text-destructive">Unsupported File Types</h4>
|
| 41 |
+
|
| 42 |
+
<div class="space-y-1">
|
| 43 |
+
{#each fileErrorData.generallyUnsupported as file (file.name)}
|
| 44 |
+
<div class="rounded-md bg-destructive/10 px-3 py-2">
|
| 45 |
+
<p class="font-mono text-sm break-all text-destructive">
|
| 46 |
+
{file.name}
|
| 47 |
+
</p>
|
| 48 |
+
|
| 49 |
+
<p class="mt-1 text-xs text-muted-foreground">File type not supported</p>
|
| 50 |
+
</div>
|
| 51 |
+
{/each}
|
| 52 |
+
</div>
|
| 53 |
+
</div>
|
| 54 |
+
{/if}
|
| 55 |
+
|
| 56 |
+
{#if fileErrorData.modalityUnsupported.length > 0}
|
| 57 |
+
<div class="space-y-2">
|
| 58 |
+
<div class="space-y-1">
|
| 59 |
+
{#each fileErrorData.modalityUnsupported as file (file.name)}
|
| 60 |
+
<div class="rounded-md bg-destructive/10 px-3 py-2">
|
| 61 |
+
<p class="font-mono text-sm break-all text-destructive">
|
| 62 |
+
{file.name}
|
| 63 |
+
</p>
|
| 64 |
+
|
| 65 |
+
<p class="mt-1 text-xs text-muted-foreground">
|
| 66 |
+
{fileErrorData.modalityReasons[file.name] || 'Not supported by current model'}
|
| 67 |
+
</p>
|
| 68 |
+
</div>
|
| 69 |
+
{/each}
|
| 70 |
+
</div>
|
| 71 |
+
</div>
|
| 72 |
+
{/if}
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<div class="rounded-md bg-muted/50 p-3">
|
| 76 |
+
<h4 class="mb-2 text-sm font-medium">This model supports:</h4>
|
| 77 |
+
|
| 78 |
+
<p class="text-sm text-muted-foreground">
|
| 79 |
+
{fileErrorData.supportedTypes.join(', ')}
|
| 80 |
+
</p>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
<AlertDialog.Footer>
|
| 84 |
+
<AlertDialog.Action onclick={() => handleOpenChange(false)}>Got it</AlertDialog.Action>
|
| 85 |
+
</AlertDialog.Footer>
|
| 86 |
+
</AlertDialog.Content>
|
| 87 |
+
</AlertDialog.Portal>
|
| 88 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpResourcePreview.svelte
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Dialog from '$lib/components/ui/dialog';
|
| 3 |
+
import { Download } from '@lucide/svelte';
|
| 4 |
+
import { Button } from '$lib/components/ui/button';
|
| 5 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 6 |
+
import { SyntaxHighlightedCode, ActionIconCopyToClipboard } from '$lib/components/app';
|
| 7 |
+
import {
|
| 8 |
+
getLanguageFromFilename,
|
| 9 |
+
isCodeResource,
|
| 10 |
+
isImageResource,
|
| 11 |
+
downloadResourceContent
|
| 12 |
+
} from '$lib/utils';
|
| 13 |
+
import { MimeTypeIncludes, MimeTypeText } from '$lib/enums';
|
| 14 |
+
import { DEFAULT_RESOURCE_FILENAME } from '$lib/constants';
|
| 15 |
+
import type { DatabaseMessageExtraMcpResource } from '$lib/types';
|
| 16 |
+
|
| 17 |
+
interface Props {
|
| 18 |
+
open: boolean;
|
| 19 |
+
onOpenChange?: (open: boolean) => void;
|
| 20 |
+
extra: DatabaseMessageExtraMcpResource;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
let { open = $bindable(), onOpenChange, extra }: Props = $props();
|
| 24 |
+
|
| 25 |
+
const serverName = $derived(mcpStore.getServerDisplayName(extra.serverName));
|
| 26 |
+
const favicon = $derived(mcpStore.getServerFavicon(extra.serverName));
|
| 27 |
+
|
| 28 |
+
function getLanguage(): string {
|
| 29 |
+
if (extra.mimeType?.includes(MimeTypeIncludes.JSON)) return MimeTypeIncludes.JSON;
|
| 30 |
+
if (extra.mimeType?.includes(MimeTypeIncludes.JAVASCRIPT)) return MimeTypeIncludes.JAVASCRIPT;
|
| 31 |
+
if (extra.mimeType?.includes(MimeTypeIncludes.TYPESCRIPT)) return MimeTypeIncludes.TYPESCRIPT;
|
| 32 |
+
|
| 33 |
+
const name = extra.name || extra.uri || '';
|
| 34 |
+
|
| 35 |
+
return getLanguageFromFilename(name) || 'plaintext';
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
function handleDownload() {
|
| 39 |
+
if (!extra.content) return;
|
| 40 |
+
|
| 41 |
+
downloadResourceContent(
|
| 42 |
+
extra.content,
|
| 43 |
+
extra.mimeType || MimeTypeText.PLAIN,
|
| 44 |
+
extra.name || DEFAULT_RESOURCE_FILENAME
|
| 45 |
+
);
|
| 46 |
+
}
|
| 47 |
+
</script>
|
| 48 |
+
|
| 49 |
+
<Dialog.Root bind:open {onOpenChange}>
|
| 50 |
+
<Dialog.Content class="grid max-h-[90vh] max-w-5xl overflow-hidden sm:w-auto sm:max-w-6xl">
|
| 51 |
+
<Dialog.Header>
|
| 52 |
+
<Dialog.Title class="pr-8">{extra.name}</Dialog.Title>
|
| 53 |
+
|
| 54 |
+
<Dialog.Description>
|
| 55 |
+
<div class="flex items-center gap-2">
|
| 56 |
+
<span class="text-xs text-muted-foreground">{extra.uri}</span>
|
| 57 |
+
|
| 58 |
+
{#if serverName}
|
| 59 |
+
<span class="flex items-center gap-1 text-xs text-muted-foreground">
|
| 60 |
+
·
|
| 61 |
+
{#if favicon}
|
| 62 |
+
<img
|
| 63 |
+
src={favicon}
|
| 64 |
+
alt=""
|
| 65 |
+
class="h-3 w-3 shrink-0 rounded-sm"
|
| 66 |
+
onerror={(e) => {
|
| 67 |
+
(e.currentTarget as HTMLImageElement).style.display = 'none';
|
| 68 |
+
}}
|
| 69 |
+
/>
|
| 70 |
+
{/if}
|
| 71 |
+
{serverName}
|
| 72 |
+
</span>
|
| 73 |
+
{/if}
|
| 74 |
+
|
| 75 |
+
{#if extra.mimeType}
|
| 76 |
+
<span class="rounded bg-muted px-1.5 py-0.5 text-xs">{extra.mimeType}</span>
|
| 77 |
+
{/if}
|
| 78 |
+
</div>
|
| 79 |
+
</Dialog.Description>
|
| 80 |
+
</Dialog.Header>
|
| 81 |
+
|
| 82 |
+
<div class="flex items-center justify-end gap-1">
|
| 83 |
+
<ActionIconCopyToClipboard
|
| 84 |
+
text={extra.content}
|
| 85 |
+
canCopy={!!extra.content}
|
| 86 |
+
ariaLabel="Copy content"
|
| 87 |
+
/>
|
| 88 |
+
|
| 89 |
+
<Button
|
| 90 |
+
variant="ghost"
|
| 91 |
+
size="sm"
|
| 92 |
+
class="h-7 w-7 p-0"
|
| 93 |
+
onclick={handleDownload}
|
| 94 |
+
disabled={!extra.content}
|
| 95 |
+
title="Download content"
|
| 96 |
+
>
|
| 97 |
+
<Download class="h-3.5 w-3.5" />
|
| 98 |
+
</Button>
|
| 99 |
+
</div>
|
| 100 |
+
|
| 101 |
+
<div class="overflow-auto">
|
| 102 |
+
{#if isImageResource(extra.mimeType, extra.uri) && extra.content}
|
| 103 |
+
<div class="flex items-center justify-center">
|
| 104 |
+
<img
|
| 105 |
+
src={extra.content.startsWith('data:')
|
| 106 |
+
? extra.content
|
| 107 |
+
: `data:${extra.mimeType || 'image/png'};base64,${extra.content}`}
|
| 108 |
+
alt={extra.name}
|
| 109 |
+
class="max-h-[70vh] max-w-full rounded object-contain"
|
| 110 |
+
/>
|
| 111 |
+
</div>
|
| 112 |
+
{:else if isCodeResource(extra.mimeType, extra.uri) && extra.content}
|
| 113 |
+
<SyntaxHighlightedCode code={extra.content} language={getLanguage()} maxHeight="70vh" />
|
| 114 |
+
{:else if extra.content}
|
| 115 |
+
<pre
|
| 116 |
+
class="max-h-[70vh] overflow-auto rounded-md border bg-muted/30 p-4 font-mono text-sm break-words whitespace-pre-wrap">{extra.content}</pre>
|
| 117 |
+
{:else}
|
| 118 |
+
<div class="py-8 text-center text-sm text-muted-foreground">No content available</div>
|
| 119 |
+
{/if}
|
| 120 |
+
</div>
|
| 121 |
+
</Dialog.Content>
|
| 122 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpResourcesBrowser.svelte
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { FolderOpen, Plus, Loader2, Braces } from '@lucide/svelte';
|
| 3 |
+
import { toast } from 'svelte-sonner';
|
| 4 |
+
import * as Dialog from '$lib/components/ui/dialog';
|
| 5 |
+
import { Button } from '$lib/components/ui/button';
|
| 6 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 7 |
+
import { conversationsStore } from '$lib/stores/conversations.svelte';
|
| 8 |
+
import {
|
| 9 |
+
mcpResources,
|
| 10 |
+
mcpTotalResourceCount,
|
| 11 |
+
mcpResourceStore
|
| 12 |
+
} from '$lib/stores/mcp-resources.svelte';
|
| 13 |
+
import {
|
| 14 |
+
McpResourcesBrowser,
|
| 15 |
+
McpResourcePreview,
|
| 16 |
+
McpResourceTemplateForm
|
| 17 |
+
} from '$lib/components/app';
|
| 18 |
+
import { getResourceDisplayName } from '$lib/utils';
|
| 19 |
+
import type { MCPResourceInfo, MCPResourceContent, MCPResourceTemplateInfo } from '$lib/types';
|
| 20 |
+
import { SvelteSet } from 'svelte/reactivity';
|
| 21 |
+
|
| 22 |
+
interface Props {
|
| 23 |
+
open?: boolean;
|
| 24 |
+
onOpenChange?: (open: boolean) => void;
|
| 25 |
+
onAttach?: (resource: MCPResourceInfo) => void;
|
| 26 |
+
preSelectedUri?: string;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
let { open = $bindable(false), onOpenChange, onAttach, preSelectedUri }: Props = $props();
|
| 30 |
+
|
| 31 |
+
let selectedResources = new SvelteSet<string>();
|
| 32 |
+
let lastSelectedUri = $state<string | null>(null);
|
| 33 |
+
let isAttaching = $state(false);
|
| 34 |
+
|
| 35 |
+
let selectedTemplate = $state<MCPResourceTemplateInfo | null>(null);
|
| 36 |
+
let templatePreviewUri = $state<string | null>(null);
|
| 37 |
+
let templatePreviewContent = $state<MCPResourceContent[] | null>(null);
|
| 38 |
+
let templatePreviewLoading = $state(false);
|
| 39 |
+
let templatePreviewError = $state<string | null>(null);
|
| 40 |
+
|
| 41 |
+
const totalCount = $derived(mcpTotalResourceCount());
|
| 42 |
+
|
| 43 |
+
$effect(() => {
|
| 44 |
+
if (open) {
|
| 45 |
+
loadResources();
|
| 46 |
+
|
| 47 |
+
if (preSelectedUri) {
|
| 48 |
+
selectedResources.clear();
|
| 49 |
+
selectedResources.add(preSelectedUri);
|
| 50 |
+
lastSelectedUri = preSelectedUri;
|
| 51 |
+
}
|
| 52 |
+
}
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
async function loadResources() {
|
| 56 |
+
const perChatOverrides = conversationsStore.getAllMcpServerOverrides();
|
| 57 |
+
const initialized = await mcpStore.ensureInitialized(perChatOverrides);
|
| 58 |
+
|
| 59 |
+
if (initialized) {
|
| 60 |
+
await mcpStore.fetchAllResources();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function handleOpenChange(newOpen: boolean) {
|
| 65 |
+
open = newOpen;
|
| 66 |
+
onOpenChange?.(newOpen);
|
| 67 |
+
|
| 68 |
+
if (!newOpen) {
|
| 69 |
+
selectedResources.clear();
|
| 70 |
+
lastSelectedUri = null;
|
| 71 |
+
clearTemplateState();
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function clearTemplateState() {
|
| 76 |
+
selectedTemplate = null;
|
| 77 |
+
templatePreviewUri = null;
|
| 78 |
+
templatePreviewContent = null;
|
| 79 |
+
templatePreviewLoading = false;
|
| 80 |
+
templatePreviewError = null;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
function handleTemplateSelect(template: MCPResourceTemplateInfo) {
|
| 84 |
+
selectedResources.clear();
|
| 85 |
+
lastSelectedUri = null;
|
| 86 |
+
|
| 87 |
+
if (
|
| 88 |
+
selectedTemplate?.uriTemplate === template.uriTemplate &&
|
| 89 |
+
selectedTemplate?.serverName === template.serverName
|
| 90 |
+
) {
|
| 91 |
+
clearTemplateState();
|
| 92 |
+
|
| 93 |
+
return;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
selectedTemplate = template;
|
| 97 |
+
templatePreviewUri = null;
|
| 98 |
+
templatePreviewContent = null;
|
| 99 |
+
templatePreviewLoading = false;
|
| 100 |
+
templatePreviewError = null;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
async function handleTemplateResolve(uri: string, serverName: string) {
|
| 104 |
+
templatePreviewUri = uri;
|
| 105 |
+
templatePreviewContent = null;
|
| 106 |
+
templatePreviewLoading = true;
|
| 107 |
+
templatePreviewError = null;
|
| 108 |
+
|
| 109 |
+
try {
|
| 110 |
+
const content = await mcpStore.readResourceByUri(serverName, uri);
|
| 111 |
+
|
| 112 |
+
if (content) {
|
| 113 |
+
templatePreviewContent = content;
|
| 114 |
+
} else {
|
| 115 |
+
templatePreviewError = 'Failed to read resource';
|
| 116 |
+
}
|
| 117 |
+
} catch (error) {
|
| 118 |
+
templatePreviewError = error instanceof Error ? error.message : 'Unknown error';
|
| 119 |
+
} finally {
|
| 120 |
+
templatePreviewLoading = false;
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function handleTemplateCancelForm() {
|
| 125 |
+
clearTemplateState();
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
async function handleAttachTemplateResource() {
|
| 129 |
+
if (!templatePreviewUri || !selectedTemplate || !templatePreviewContent) return;
|
| 130 |
+
|
| 131 |
+
isAttaching = true;
|
| 132 |
+
|
| 133 |
+
try {
|
| 134 |
+
const knownResource = mcpResourceStore.findResourceByUri(templatePreviewUri);
|
| 135 |
+
|
| 136 |
+
if (knownResource) {
|
| 137 |
+
if (!mcpResourceStore.isAttached(knownResource.uri)) {
|
| 138 |
+
await mcpStore.attachResource(knownResource.uri);
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
toast.success(`Resource attached: ${knownResource.title || knownResource.name}`);
|
| 142 |
+
} else {
|
| 143 |
+
if (mcpResourceStore.isAttached(templatePreviewUri)) {
|
| 144 |
+
toast.info('Resource already attached');
|
| 145 |
+
handleOpenChange(false);
|
| 146 |
+
return;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
const resourceInfo: MCPResourceInfo = {
|
| 150 |
+
uri: templatePreviewUri,
|
| 151 |
+
name: templatePreviewUri.split('/').pop() || templatePreviewUri,
|
| 152 |
+
serverName: selectedTemplate.serverName
|
| 153 |
+
};
|
| 154 |
+
|
| 155 |
+
const attachment = mcpResourceStore.addAttachment(resourceInfo);
|
| 156 |
+
mcpResourceStore.updateAttachmentContent(attachment.id, templatePreviewContent);
|
| 157 |
+
|
| 158 |
+
toast.success(`Resource attached: ${resourceInfo.name}`);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
handleOpenChange(false);
|
| 162 |
+
} catch (error) {
|
| 163 |
+
console.error('Failed to attach template resource:', error);
|
| 164 |
+
} finally {
|
| 165 |
+
isAttaching = false;
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
function handleResourceSelect(resource: MCPResourceInfo, shiftKey: boolean = false) {
|
| 170 |
+
clearTemplateState();
|
| 171 |
+
|
| 172 |
+
if (shiftKey && lastSelectedUri) {
|
| 173 |
+
const allResources = getAllResourcesFlatInTreeOrder();
|
| 174 |
+
const lastIndex = allResources.findIndex((r) => r.uri === lastSelectedUri);
|
| 175 |
+
const currentIndex = allResources.findIndex((r) => r.uri === resource.uri);
|
| 176 |
+
|
| 177 |
+
if (lastIndex !== -1 && currentIndex !== -1) {
|
| 178 |
+
const start = Math.min(lastIndex, currentIndex);
|
| 179 |
+
const end = Math.max(lastIndex, currentIndex);
|
| 180 |
+
|
| 181 |
+
for (let i = start; i <= end; i++) {
|
| 182 |
+
selectedResources.add(allResources[i].uri);
|
| 183 |
+
}
|
| 184 |
+
}
|
| 185 |
+
} else {
|
| 186 |
+
selectedResources.clear();
|
| 187 |
+
selectedResources.add(resource.uri);
|
| 188 |
+
lastSelectedUri = resource.uri;
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
|
| 192 |
+
function handleResourceToggle(resource: MCPResourceInfo, checked: boolean) {
|
| 193 |
+
clearTemplateState();
|
| 194 |
+
|
| 195 |
+
if (checked) {
|
| 196 |
+
selectedResources.add(resource.uri);
|
| 197 |
+
} else {
|
| 198 |
+
selectedResources.delete(resource.uri);
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
lastSelectedUri = resource.uri;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
function getAllResourcesFlatInTreeOrder(): MCPResourceInfo[] {
|
| 205 |
+
const allResources: MCPResourceInfo[] = [];
|
| 206 |
+
const resourcesMap = mcpResources();
|
| 207 |
+
|
| 208 |
+
for (const [serverName, serverRes] of resourcesMap.entries()) {
|
| 209 |
+
for (const resource of serverRes.resources) {
|
| 210 |
+
allResources.push({ ...resource, serverName });
|
| 211 |
+
}
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
return allResources.sort((a, b) => {
|
| 215 |
+
const aName = getResourceDisplayName(a);
|
| 216 |
+
const bName = getResourceDisplayName(b);
|
| 217 |
+
return aName.localeCompare(bName);
|
| 218 |
+
});
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
async function handleAttach() {
|
| 222 |
+
if (selectedResources.size === 0) return;
|
| 223 |
+
|
| 224 |
+
isAttaching = true;
|
| 225 |
+
|
| 226 |
+
try {
|
| 227 |
+
const allResources = getAllResourcesFlatInTreeOrder();
|
| 228 |
+
const resourcesToAttach = allResources.filter((r) => selectedResources.has(r.uri));
|
| 229 |
+
|
| 230 |
+
for (const resource of resourcesToAttach) {
|
| 231 |
+
await mcpStore.attachResource(resource.uri);
|
| 232 |
+
onAttach?.(resource);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
const count = resourcesToAttach.length;
|
| 236 |
+
|
| 237 |
+
toast.success(
|
| 238 |
+
count === 1
|
| 239 |
+
? `Resource attached: ${resourcesToAttach[0].name}`
|
| 240 |
+
: `${count} resources attached`
|
| 241 |
+
);
|
| 242 |
+
|
| 243 |
+
handleOpenChange(false);
|
| 244 |
+
} catch (error) {
|
| 245 |
+
console.error('Failed to attach resources:', error);
|
| 246 |
+
} finally {
|
| 247 |
+
isAttaching = false;
|
| 248 |
+
}
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
const selectedTemplateUri = $derived(selectedTemplate?.uriTemplate ?? null);
|
| 252 |
+
|
| 253 |
+
const hasTemplateResult = $derived(
|
| 254 |
+
!!selectedTemplate && !!templatePreviewContent && !!templatePreviewUri
|
| 255 |
+
);
|
| 256 |
+
</script>
|
| 257 |
+
|
| 258 |
+
<Dialog.Root {open} onOpenChange={handleOpenChange}>
|
| 259 |
+
<Dialog.Content class="max-h-[80vh] !max-w-4xl overflow-hidden p-0">
|
| 260 |
+
<Dialog.Header class="border-b border-border/30 px-6 py-4">
|
| 261 |
+
<Dialog.Title class="flex items-center gap-2">
|
| 262 |
+
<FolderOpen class="h-5 w-5" />
|
| 263 |
+
|
| 264 |
+
<span>MCP Resources</span>
|
| 265 |
+
|
| 266 |
+
{#if totalCount > 0}
|
| 267 |
+
<span class="text-sm font-normal text-muted-foreground">({totalCount})</span>
|
| 268 |
+
{/if}
|
| 269 |
+
</Dialog.Title>
|
| 270 |
+
|
| 271 |
+
<Dialog.Description>
|
| 272 |
+
Browse and attach resources from connected MCP servers to your chat context.
|
| 273 |
+
</Dialog.Description>
|
| 274 |
+
</Dialog.Header>
|
| 275 |
+
|
| 276 |
+
<div class="flex h-[500px] min-w-0">
|
| 277 |
+
<div class="w-72 shrink-0 overflow-y-auto border-r border-border/30 p-4">
|
| 278 |
+
<McpResourcesBrowser
|
| 279 |
+
onSelect={handleResourceSelect}
|
| 280 |
+
onToggle={handleResourceToggle}
|
| 281 |
+
onTemplateSelect={handleTemplateSelect}
|
| 282 |
+
selectedUris={selectedResources}
|
| 283 |
+
{selectedTemplateUri}
|
| 284 |
+
expandToUri={preSelectedUri}
|
| 285 |
+
/>
|
| 286 |
+
</div>
|
| 287 |
+
|
| 288 |
+
<div class="min-w-0 flex-1 overflow-auto p-4">
|
| 289 |
+
{#if selectedTemplate && !templatePreviewContent}
|
| 290 |
+
<div class="flex h-full flex-col">
|
| 291 |
+
<div class="mb-3 flex items-center gap-2">
|
| 292 |
+
<Braces class="h-4 w-4 text-muted-foreground" />
|
| 293 |
+
|
| 294 |
+
<span class="text-sm font-medium">
|
| 295 |
+
{selectedTemplate.title || selectedTemplate.name}
|
| 296 |
+
</span>
|
| 297 |
+
</div>
|
| 298 |
+
|
| 299 |
+
{#if selectedTemplate.description}
|
| 300 |
+
<p class="mb-4 text-xs text-muted-foreground">
|
| 301 |
+
{selectedTemplate.description}
|
| 302 |
+
</p>
|
| 303 |
+
{/if}
|
| 304 |
+
|
| 305 |
+
<div class="mb-4 rounded-md border border-border/50 bg-muted/30 px-3 py-2">
|
| 306 |
+
<p class="font-mono text-xs break-all text-muted-foreground">
|
| 307 |
+
{selectedTemplate.uriTemplate}
|
| 308 |
+
</p>
|
| 309 |
+
</div>
|
| 310 |
+
|
| 311 |
+
{#if templatePreviewLoading}
|
| 312 |
+
<div class="flex flex-1 items-center justify-center">
|
| 313 |
+
<Loader2 class="h-6 w-6 animate-spin text-muted-foreground" />
|
| 314 |
+
</div>
|
| 315 |
+
{:else if templatePreviewError}
|
| 316 |
+
<div class="flex flex-1 flex-col items-center justify-center gap-2 text-red-500">
|
| 317 |
+
<span class="text-sm">{templatePreviewError}</span>
|
| 318 |
+
|
| 319 |
+
<Button
|
| 320 |
+
size="sm"
|
| 321 |
+
variant="outline"
|
| 322 |
+
onclick={() => {
|
| 323 |
+
templatePreviewError = null;
|
| 324 |
+
}}
|
| 325 |
+
>
|
| 326 |
+
Try again
|
| 327 |
+
</Button>
|
| 328 |
+
</div>
|
| 329 |
+
{:else}
|
| 330 |
+
<McpResourceTemplateForm
|
| 331 |
+
template={selectedTemplate}
|
| 332 |
+
onResolve={handleTemplateResolve}
|
| 333 |
+
onCancel={handleTemplateCancelForm}
|
| 334 |
+
/>
|
| 335 |
+
{/if}
|
| 336 |
+
</div>
|
| 337 |
+
{:else if hasTemplateResult}
|
| 338 |
+
<!-- Template resolved: show preview -->
|
| 339 |
+
<McpResourcePreview
|
| 340 |
+
resource={{
|
| 341 |
+
uri: templatePreviewUri ?? '',
|
| 342 |
+
name: templatePreviewUri?.split('/').pop() || (templatePreviewUri ?? ''),
|
| 343 |
+
serverName: selectedTemplate?.serverName || ''
|
| 344 |
+
}}
|
| 345 |
+
preloadedContent={templatePreviewContent}
|
| 346 |
+
/>
|
| 347 |
+
{:else if selectedResources.size === 1}
|
| 348 |
+
{@const allResources = getAllResourcesFlatInTreeOrder()}
|
| 349 |
+
{@const selectedResource = allResources.find((r) => selectedResources.has(r.uri))}
|
| 350 |
+
|
| 351 |
+
<McpResourcePreview resource={selectedResource ?? null} />
|
| 352 |
+
{:else if selectedResources.size > 1}
|
| 353 |
+
<div class="flex flex-col gap-10">
|
| 354 |
+
{#each getAllResourcesFlatInTreeOrder() as resource (resource.uri)}
|
| 355 |
+
{#if selectedResources.has(resource.uri)}
|
| 356 |
+
<McpResourcePreview {resource} />
|
| 357 |
+
{/if}
|
| 358 |
+
{/each}
|
| 359 |
+
</div>
|
| 360 |
+
{:else}
|
| 361 |
+
<div class="flex h-full items-center justify-center text-sm text-muted-foreground">
|
| 362 |
+
Select a resource to preview
|
| 363 |
+
</div>
|
| 364 |
+
{/if}
|
| 365 |
+
</div>
|
| 366 |
+
</div>
|
| 367 |
+
|
| 368 |
+
<Dialog.Footer class="border-t border-border/30 px-6 py-4">
|
| 369 |
+
<Button variant="outline" onclick={() => handleOpenChange(false)}>Cancel</Button>
|
| 370 |
+
|
| 371 |
+
{#if hasTemplateResult}
|
| 372 |
+
<Button onclick={handleAttachTemplateResource} disabled={isAttaching}>
|
| 373 |
+
{#if isAttaching}
|
| 374 |
+
<Loader2 class="mr-2 h-4 w-4 animate-spin" />
|
| 375 |
+
{:else}
|
| 376 |
+
<Plus class="mr-2 h-4 w-4" />
|
| 377 |
+
{/if}
|
| 378 |
+
|
| 379 |
+
Attach Resource
|
| 380 |
+
</Button>
|
| 381 |
+
{:else}
|
| 382 |
+
<Button onclick={handleAttach} disabled={selectedResources.size === 0 || isAttaching}>
|
| 383 |
+
{#if isAttaching}
|
| 384 |
+
<Loader2 class="mr-2 h-4 w-4 animate-spin" />
|
| 385 |
+
{:else}
|
| 386 |
+
<Plus class="mr-2 h-4 w-4" />
|
| 387 |
+
{/if}
|
| 388 |
+
|
| 389 |
+
Attach {selectedResources.size > 0 ? `(${selectedResources.size})` : 'Resource'}
|
| 390 |
+
</Button>
|
| 391 |
+
{/if}
|
| 392 |
+
</Dialog.Footer>
|
| 393 |
+
</Dialog.Content>
|
| 394 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpServerAddNew.svelte
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Button } from '$lib/components/ui/button';
|
| 3 |
+
import * as Dialog from '$lib/components/ui/dialog';
|
| 4 |
+
import { McpServerForm } from '$lib/components/app/mcp';
|
| 5 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 6 |
+
import { conversationsStore } from '$lib/stores/conversations.svelte';
|
| 7 |
+
import { parseHeadersToArray, uuid } from '$lib/utils';
|
| 8 |
+
import { MCP_SERVER_ID_PREFIX } from '$lib/constants';
|
| 9 |
+
|
| 10 |
+
interface Props {
|
| 11 |
+
open: boolean;
|
| 12 |
+
onOpenChange?: (open: boolean) => void;
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
let { open = $bindable(), onOpenChange }: Props = $props();
|
| 16 |
+
|
| 17 |
+
let newServerUrl = $state('');
|
| 18 |
+
let newServerHeaders = $state('');
|
| 19 |
+
let newServerUrlError = $derived.by(() => {
|
| 20 |
+
if (!newServerUrl.trim()) return 'URL is required';
|
| 21 |
+
try {
|
| 22 |
+
new URL(newServerUrl);
|
| 23 |
+
|
| 24 |
+
return null;
|
| 25 |
+
} catch {
|
| 26 |
+
return 'Invalid URL format';
|
| 27 |
+
}
|
| 28 |
+
});
|
| 29 |
+
let newServerHeaderPairsValid = $derived(
|
| 30 |
+
parseHeadersToArray(newServerHeaders).every((p) => p.key.trim() && p.value.trim())
|
| 31 |
+
);
|
| 32 |
+
let canSave = $derived(!newServerUrlError && newServerHeaderPairsValid);
|
| 33 |
+
|
| 34 |
+
function handleOpenChange(value: boolean) {
|
| 35 |
+
if (!value) {
|
| 36 |
+
newServerUrl = '';
|
| 37 |
+
newServerHeaders = '';
|
| 38 |
+
}
|
| 39 |
+
open = value;
|
| 40 |
+
onOpenChange?.(value);
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
function saveNewServer() {
|
| 44 |
+
if (!canSave) return;
|
| 45 |
+
|
| 46 |
+
const newServerId = uuid() ?? `${MCP_SERVER_ID_PREFIX}-${Date.now()}`;
|
| 47 |
+
|
| 48 |
+
mcpStore.addServer({
|
| 49 |
+
id: newServerId,
|
| 50 |
+
enabled: true,
|
| 51 |
+
url: newServerUrl.trim(),
|
| 52 |
+
headers: newServerHeaders.trim() || undefined
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
conversationsStore.setMcpServerOverride(newServerId, true);
|
| 56 |
+
|
| 57 |
+
handleOpenChange(false);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
function handleSubmit(event: SubmitEvent) {
|
| 61 |
+
event.preventDefault();
|
| 62 |
+
saveNewServer();
|
| 63 |
+
}
|
| 64 |
+
</script>
|
| 65 |
+
|
| 66 |
+
<Dialog.Root {open} onOpenChange={handleOpenChange}>
|
| 67 |
+
<Dialog.Content class="sm:max-w-md">
|
| 68 |
+
<Dialog.Header>
|
| 69 |
+
<Dialog.Title>Add New Server</Dialog.Title>
|
| 70 |
+
</Dialog.Header>
|
| 71 |
+
|
| 72 |
+
<form onsubmit={handleSubmit} class="contents">
|
| 73 |
+
<div class="space-y-4 py-4">
|
| 74 |
+
<McpServerForm
|
| 75 |
+
url={newServerUrl}
|
| 76 |
+
headers={newServerHeaders}
|
| 77 |
+
onUrlChange={(v) => (newServerUrl = v)}
|
| 78 |
+
onHeadersChange={(v) => (newServerHeaders = v)}
|
| 79 |
+
urlError={newServerUrl ? newServerUrlError : null}
|
| 80 |
+
id="new-server"
|
| 81 |
+
/>
|
| 82 |
+
</div>
|
| 83 |
+
|
| 84 |
+
<Dialog.Footer>
|
| 85 |
+
<Button variant="secondary" size="sm" onclick={() => handleOpenChange(false)}>
|
| 86 |
+
Cancel
|
| 87 |
+
</Button>
|
| 88 |
+
|
| 89 |
+
<Button variant="default" size="sm" type="submit" disabled={!canSave} aria-label="Save">
|
| 90 |
+
Add
|
| 91 |
+
</Button>
|
| 92 |
+
</Dialog.Footer>
|
| 93 |
+
</form>
|
| 94 |
+
</Dialog.Content>
|
| 95 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMcpServerRecommendations.svelte
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Button } from '$lib/components/ui/button';
|
| 3 |
+
import * as Card from '$lib/components/ui/card';
|
| 4 |
+
import * as Dialog from '$lib/components/ui/dialog';
|
| 5 |
+
import { fly } from 'svelte/transition';
|
| 6 |
+
import { McpServerCardCompact, McpServerForm } from '$lib/components/app/mcp';
|
| 7 |
+
import { RECOMMENDED_MCP_SERVERS } from '$lib/constants';
|
| 8 |
+
import { conversationsStore } from '$lib/stores/conversations.svelte';
|
| 9 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 10 |
+
import { uuid } from '$lib/utils';
|
| 11 |
+
import { MCP_SERVERS_ADDED_TO_CHAT_LOCALSTORAGE_KEY, MCP_SERVER_ID_PREFIX } from '$lib/constants';
|
| 12 |
+
import type { MCPServerSettingsEntry } from '$lib/types';
|
| 13 |
+
import { Plus } from '@lucide/svelte';
|
| 14 |
+
|
| 15 |
+
interface Props {
|
| 16 |
+
open: boolean;
|
| 17 |
+
onOpenChange?: (open: boolean) => void;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
let { open = $bindable(), onOpenChange }: Props = $props();
|
| 21 |
+
|
| 22 |
+
let selected = $state<Record<string, boolean>>(
|
| 23 |
+
Object.fromEntries(RECOMMENDED_MCP_SERVERS.map((server) => [server.id, false]))
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
let addedServers = $state<MCPServerSettingsEntry[]>([]);
|
| 27 |
+
|
| 28 |
+
let showAddForm = $state(false);
|
| 29 |
+
let newServerUrl = $state('');
|
| 30 |
+
let newServerHeaders = $state('');
|
| 31 |
+
let newServerUrlError = $derived.by(() => {
|
| 32 |
+
if (!newServerUrl.trim()) return 'URL is required';
|
| 33 |
+
try {
|
| 34 |
+
new URL(newServerUrl);
|
| 35 |
+
|
| 36 |
+
return null;
|
| 37 |
+
} catch {
|
| 38 |
+
return 'Invalid URL format';
|
| 39 |
+
}
|
| 40 |
+
});
|
| 41 |
+
|
| 42 |
+
function handleOpenChange(value: boolean) {
|
| 43 |
+
if (!value) {
|
| 44 |
+
showAddForm = false;
|
| 45 |
+
newServerUrl = '';
|
| 46 |
+
newServerHeaders = '';
|
| 47 |
+
addedServers = [];
|
| 48 |
+
|
| 49 |
+
localStorage.setItem(MCP_SERVERS_ADDED_TO_CHAT_LOCALSTORAGE_KEY, 'true');
|
| 50 |
+
}
|
| 51 |
+
open = value;
|
| 52 |
+
onOpenChange?.(value);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function resetAddForm() {
|
| 56 |
+
showAddForm = false;
|
| 57 |
+
newServerUrl = '';
|
| 58 |
+
newServerHeaders = '';
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
function enableSelected() {
|
| 62 |
+
localStorage.setItem(MCP_SERVERS_ADDED_TO_CHAT_LOCALSTORAGE_KEY, 'true');
|
| 63 |
+
|
| 64 |
+
for (const server of RECOMMENDED_MCP_SERVERS) {
|
| 65 |
+
if (selected[server.id]) {
|
| 66 |
+
const existing = mcpStore.getServerById(server.id);
|
| 67 |
+
if (existing) {
|
| 68 |
+
mcpStore.updateServer(server.id, { enabled: true });
|
| 69 |
+
} else {
|
| 70 |
+
mcpStore.addServer({
|
| 71 |
+
id: server.id,
|
| 72 |
+
enabled: true,
|
| 73 |
+
url: server.url,
|
| 74 |
+
name: server.name
|
| 75 |
+
});
|
| 76 |
+
}
|
| 77 |
+
conversationsStore.setMcpServerOverride(server.id, true);
|
| 78 |
+
}
|
| 79 |
+
}
|
| 80 |
+
handleOpenChange(false);
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
function saveNewServer() {
|
| 84 |
+
if (newServerUrlError) return;
|
| 85 |
+
|
| 86 |
+
const newServerId = uuid() ?? `${MCP_SERVER_ID_PREFIX}-${Date.now()}`;
|
| 87 |
+
|
| 88 |
+
localStorage.setItem(MCP_SERVERS_ADDED_TO_CHAT_LOCALSTORAGE_KEY, 'true');
|
| 89 |
+
|
| 90 |
+
const newServer = mcpStore.addServer({
|
| 91 |
+
id: newServerId,
|
| 92 |
+
enabled: true,
|
| 93 |
+
url: newServerUrl.trim(),
|
| 94 |
+
headers: newServerHeaders.trim() || undefined
|
| 95 |
+
});
|
| 96 |
+
|
| 97 |
+
conversationsStore.setMcpServerOverride(newServerId, true);
|
| 98 |
+
|
| 99 |
+
if (newServer) {
|
| 100 |
+
addedServers = [...addedServers, newServer];
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
resetAddForm();
|
| 104 |
+
}
|
| 105 |
+
</script>
|
| 106 |
+
|
| 107 |
+
<Dialog.Root bind:open onOpenChange={handleOpenChange}>
|
| 108 |
+
<Dialog.Content class="sm:max-w-lg">
|
| 109 |
+
<Dialog.Header>
|
| 110 |
+
<Dialog.Title>Do more with MCP</Dialog.Title>
|
| 111 |
+
<Dialog.Description>
|
| 112 |
+
Power-up your experience by adding tools, resources and more capabilities provided by MCP
|
| 113 |
+
servers.
|
| 114 |
+
</Dialog.Description>
|
| 115 |
+
</Dialog.Header>
|
| 116 |
+
|
| 117 |
+
<div class="max-h-[60vh] space-y-4 overflow-y-auto py-4" in:fly={{ y: 16, duration: 300 }}>
|
| 118 |
+
<h3 class="text-sm font-semibold">Quickly get started with</h3>
|
| 119 |
+
|
| 120 |
+
{#each RECOMMENDED_MCP_SERVERS as server (server.id)}
|
| 121 |
+
<McpServerCardCompact
|
| 122 |
+
{server}
|
| 123 |
+
enabled={selected[server.id]}
|
| 124 |
+
onToggle={(enabled) => (selected[server.id] = enabled)}
|
| 125 |
+
/>
|
| 126 |
+
{/each}
|
| 127 |
+
|
| 128 |
+
{#if addedServers.length > 0}
|
| 129 |
+
{#each addedServers as server (server.id)}
|
| 130 |
+
<McpServerCardCompact {server} enabled={true} />
|
| 131 |
+
{/each}
|
| 132 |
+
{/if}
|
| 133 |
+
|
| 134 |
+
{#if showAddForm}
|
| 135 |
+
<Card.Root class="gap-3! bg-muted/30 p-4">
|
| 136 |
+
<McpServerForm
|
| 137 |
+
url={newServerUrl}
|
| 138 |
+
headers={newServerHeaders}
|
| 139 |
+
onUrlChange={(v) => (newServerUrl = v)}
|
| 140 |
+
onHeadersChange={(v) => (newServerHeaders = v)}
|
| 141 |
+
urlError={newServerUrl ? newServerUrlError : null}
|
| 142 |
+
id="recommendation-new-server"
|
| 143 |
+
/>
|
| 144 |
+
|
| 145 |
+
<div class="flex justify-end gap-2 pt-2">
|
| 146 |
+
<Button variant="secondary" size="sm" onclick={resetAddForm}>Cancel</Button>
|
| 147 |
+
|
| 148 |
+
<Button
|
| 149 |
+
variant="default"
|
| 150 |
+
size="sm"
|
| 151 |
+
onclick={saveNewServer}
|
| 152 |
+
disabled={!!newServerUrlError}
|
| 153 |
+
aria-label="Save"
|
| 154 |
+
>
|
| 155 |
+
Add
|
| 156 |
+
</Button>
|
| 157 |
+
</div>
|
| 158 |
+
</Card.Root>
|
| 159 |
+
{:else}
|
| 160 |
+
<Card.Root class="gap-0 border-dashed bg-muted/30 p-0 transition-colors hover:bg-muted/50">
|
| 161 |
+
<button
|
| 162 |
+
type="button"
|
| 163 |
+
class="flex w-full items-center justify-center gap-2 rounded-lg p-6 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
| 164 |
+
onclick={() => (showAddForm = true)}
|
| 165 |
+
aria-label="Add your own MCP server"
|
| 166 |
+
>
|
| 167 |
+
<Plus class="h-4 w-4" />
|
| 168 |
+
<span>Add your own server</span>
|
| 169 |
+
</button>
|
| 170 |
+
</Card.Root>
|
| 171 |
+
{/if}
|
| 172 |
+
</div>
|
| 173 |
+
|
| 174 |
+
<Dialog.Footer>
|
| 175 |
+
<Button variant="secondary" size="sm" onclick={() => handleOpenChange(false)}>Not now</Button>
|
| 176 |
+
|
| 177 |
+
<Button variant="default" size="sm" onclick={enableSelected}>Add selected</Button>
|
| 178 |
+
</Dialog.Footer>
|
| 179 |
+
</Dialog.Content>
|
| 180 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogMermaidPreview.svelte
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Dialog from '$lib/components/ui/dialog/index.js';
|
| 3 |
+
import { MermaidPreview } from '$lib/components/app/content';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
open: boolean;
|
| 7 |
+
svgHtml: string;
|
| 8 |
+
onOpenChange?: (open: boolean) => void;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
let { open = $bindable(), svgHtml, onOpenChange }: Props = $props();
|
| 12 |
+
</script>
|
| 13 |
+
|
| 14 |
+
<Dialog.Root bind:open {onOpenChange}>
|
| 15 |
+
<Dialog.Content
|
| 16 |
+
class="z-999999 grid max-h-full max-w-full! grid-rows-[1fr_auto] overflow-hidden p-0 md:h-[90vh] md:max-w-[90vw]!"
|
| 17 |
+
>
|
| 18 |
+
<MermaidPreview {svgHtml} />
|
| 19 |
+
</Dialog.Content>
|
| 20 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogModelInformation.svelte
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Dialog from '$lib/components/ui/dialog';
|
| 3 |
+
import * as Table from '$lib/components/ui/table';
|
| 4 |
+
import { BadgesModality, ActionIconCopyToClipboard } from '$lib/components/app';
|
| 5 |
+
import { serverStore } from '$lib/stores/server.svelte';
|
| 6 |
+
import { modelsStore, modelOptions, modelsLoading } from '$lib/stores/models.svelte';
|
| 7 |
+
import { formatFileSize, formatParameters, formatNumber } from '$lib/utils';
|
| 8 |
+
import type { ApiLlamaCppServerProps } from '$lib/types';
|
| 9 |
+
|
| 10 |
+
interface Props {
|
| 11 |
+
open?: boolean;
|
| 12 |
+
onOpenChange?: (open: boolean) => void;
|
| 13 |
+
// when set, fetch props from the child process (router mode)
|
| 14 |
+
modelId?: string | null;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
let { open = $bindable(), onOpenChange, modelId = null }: Props = $props();
|
| 18 |
+
|
| 19 |
+
let isRouter = $derived(serverStore.isRouterMode);
|
| 20 |
+
|
| 21 |
+
// per-model props fetched from the child process
|
| 22 |
+
let routerModelProps = $state<ApiLlamaCppServerProps | null>(null);
|
| 23 |
+
let isLoadingRouterProps = $state(false);
|
| 24 |
+
|
| 25 |
+
// in router mode use per-model props, otherwise use global props
|
| 26 |
+
let serverProps = $derived(isRouter && modelId ? routerModelProps : serverStore.props);
|
| 27 |
+
|
| 28 |
+
let modelName = $derived(isRouter && modelId ? modelId : modelsStore.singleModelName);
|
| 29 |
+
let models = $derived(modelOptions());
|
| 30 |
+
let isLoadingModels = $derived(modelsLoading());
|
| 31 |
+
|
| 32 |
+
// in router mode, find the model option matching modelId
|
| 33 |
+
// in single mode, use the first model as before
|
| 34 |
+
let firstModel = $derived.by(() => {
|
| 35 |
+
if (isRouter && modelId) {
|
| 36 |
+
return models.find((m) => m.model === modelId) ?? null;
|
| 37 |
+
}
|
| 38 |
+
return models[0] ?? null;
|
| 39 |
+
});
|
| 40 |
+
|
| 41 |
+
// Get modalities from modelStore using the model ID from the first model
|
| 42 |
+
let modalities = $derived.by(() => {
|
| 43 |
+
if (!firstModel?.id) return [];
|
| 44 |
+
return modelsStore.getModelModalitiesArray(firstModel.id);
|
| 45 |
+
});
|
| 46 |
+
|
| 47 |
+
// Ensure models are fetched when dialog opens
|
| 48 |
+
$effect(() => {
|
| 49 |
+
if (open && models.length === 0) {
|
| 50 |
+
modelsStore.fetch();
|
| 51 |
+
}
|
| 52 |
+
});
|
| 53 |
+
|
| 54 |
+
// fetch per-model props from child process when dialog opens in router mode
|
| 55 |
+
$effect(() => {
|
| 56 |
+
if (open && isRouter && modelId) {
|
| 57 |
+
isLoadingRouterProps = true;
|
| 58 |
+
modelsStore
|
| 59 |
+
.fetchModelProps(modelId)
|
| 60 |
+
.then((props) => {
|
| 61 |
+
routerModelProps = props;
|
| 62 |
+
})
|
| 63 |
+
.catch(() => {
|
| 64 |
+
routerModelProps = null;
|
| 65 |
+
})
|
| 66 |
+
.finally(() => {
|
| 67 |
+
isLoadingRouterProps = false;
|
| 68 |
+
});
|
| 69 |
+
}
|
| 70 |
+
if (!open) {
|
| 71 |
+
routerModelProps = null;
|
| 72 |
+
}
|
| 73 |
+
});
|
| 74 |
+
</script>
|
| 75 |
+
|
| 76 |
+
<Dialog.Root bind:open {onOpenChange}>
|
| 77 |
+
<Dialog.Content class="@container z-9999 !max-h-[80dvh] !max-w-[60rem] max-w-full">
|
| 78 |
+
<style>
|
| 79 |
+
@container (max-width: 56rem) {
|
| 80 |
+
.resizable-text-container {
|
| 81 |
+
max-width: calc(100vw - var(--threshold));
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
</style>
|
| 85 |
+
|
| 86 |
+
<Dialog.Header>
|
| 87 |
+
<Dialog.Title>Model Information</Dialog.Title>
|
| 88 |
+
|
| 89 |
+
<Dialog.Description>Current model details and capabilities</Dialog.Description>
|
| 90 |
+
</Dialog.Header>
|
| 91 |
+
|
| 92 |
+
<div class="space-y-6 py-4">
|
| 93 |
+
{#if isLoadingModels || isLoadingRouterProps}
|
| 94 |
+
<div class="flex items-center justify-center py-8">
|
| 95 |
+
<div class="text-sm text-muted-foreground">Loading model information...</div>
|
| 96 |
+
</div>
|
| 97 |
+
{:else if firstModel}
|
| 98 |
+
{@const modelMeta = firstModel.meta}
|
| 99 |
+
|
| 100 |
+
{#if serverProps}
|
| 101 |
+
<Table.Root>
|
| 102 |
+
<Table.Header>
|
| 103 |
+
<Table.Row>
|
| 104 |
+
<Table.Head class="w-[10rem]">Model</Table.Head>
|
| 105 |
+
|
| 106 |
+
<Table.Head>
|
| 107 |
+
<div class="inline-flex items-center gap-2">
|
| 108 |
+
<span
|
| 109 |
+
class="resizable-text-container min-w-0 flex-1 truncate"
|
| 110 |
+
style:--threshold="12rem"
|
| 111 |
+
>
|
| 112 |
+
{modelName}
|
| 113 |
+
</span>
|
| 114 |
+
|
| 115 |
+
<ActionIconCopyToClipboard
|
| 116 |
+
text={modelName || ''}
|
| 117 |
+
canCopy={!!modelName}
|
| 118 |
+
ariaLabel="Copy model name to clipboard"
|
| 119 |
+
/>
|
| 120 |
+
</div>
|
| 121 |
+
</Table.Head>
|
| 122 |
+
</Table.Row>
|
| 123 |
+
</Table.Header>
|
| 124 |
+
<Table.Body>
|
| 125 |
+
<!-- Model Path -->
|
| 126 |
+
<Table.Row>
|
| 127 |
+
<Table.Cell class="h-10 align-middle font-medium">File Path</Table.Cell>
|
| 128 |
+
|
| 129 |
+
<Table.Cell
|
| 130 |
+
class="inline-flex h-10 items-center gap-2 align-middle font-mono text-xs"
|
| 131 |
+
>
|
| 132 |
+
<span
|
| 133 |
+
class="resizable-text-container min-w-0 flex-1 truncate"
|
| 134 |
+
style:--threshold="14rem"
|
| 135 |
+
>
|
| 136 |
+
{serverProps.model_path}
|
| 137 |
+
</span>
|
| 138 |
+
|
| 139 |
+
<ActionIconCopyToClipboard
|
| 140 |
+
text={serverProps.model_path}
|
| 141 |
+
ariaLabel="Copy model path to clipboard"
|
| 142 |
+
/>
|
| 143 |
+
</Table.Cell>
|
| 144 |
+
</Table.Row>
|
| 145 |
+
|
| 146 |
+
<!-- Context Size -->
|
| 147 |
+
{#if serverProps?.default_generation_settings?.n_ctx}
|
| 148 |
+
<Table.Row>
|
| 149 |
+
<Table.Cell class="h-10 align-middle font-medium">Context Size</Table.Cell>
|
| 150 |
+
|
| 151 |
+
<Table.Cell
|
| 152 |
+
>{formatNumber(serverProps.default_generation_settings.n_ctx)} tokens</Table.Cell
|
| 153 |
+
>
|
| 154 |
+
</Table.Row>
|
| 155 |
+
{:else}
|
| 156 |
+
<Table.Row>
|
| 157 |
+
<Table.Cell class="h-10 align-middle font-medium text-red-500"
|
| 158 |
+
>Context Size</Table.Cell
|
| 159 |
+
>
|
| 160 |
+
|
| 161 |
+
<Table.Cell class="text-red-500">Not available</Table.Cell>
|
| 162 |
+
</Table.Row>
|
| 163 |
+
{/if}
|
| 164 |
+
|
| 165 |
+
<!-- Training Context -->
|
| 166 |
+
{#if modelMeta?.n_ctx_train}
|
| 167 |
+
<Table.Row>
|
| 168 |
+
<Table.Cell class="h-10 align-middle font-medium">Training Context</Table.Cell>
|
| 169 |
+
|
| 170 |
+
<Table.Cell>{formatNumber(modelMeta.n_ctx_train)} tokens</Table.Cell>
|
| 171 |
+
</Table.Row>
|
| 172 |
+
{/if}
|
| 173 |
+
|
| 174 |
+
<!-- Model Size -->
|
| 175 |
+
{#if modelMeta?.size}
|
| 176 |
+
<Table.Row>
|
| 177 |
+
<Table.Cell class="h-10 align-middle font-medium">Model Size</Table.Cell>
|
| 178 |
+
|
| 179 |
+
<Table.Cell>{formatFileSize(modelMeta.size)}</Table.Cell>
|
| 180 |
+
</Table.Row>
|
| 181 |
+
{/if}
|
| 182 |
+
|
| 183 |
+
<!-- Parameters -->
|
| 184 |
+
{#if modelMeta?.n_params}
|
| 185 |
+
<Table.Row>
|
| 186 |
+
<Table.Cell class="h-10 align-middle font-medium">Parameters</Table.Cell>
|
| 187 |
+
|
| 188 |
+
<Table.Cell>{formatParameters(modelMeta.n_params)}</Table.Cell>
|
| 189 |
+
</Table.Row>
|
| 190 |
+
{/if}
|
| 191 |
+
|
| 192 |
+
<!-- Embedding Size -->
|
| 193 |
+
{#if modelMeta?.n_embd}
|
| 194 |
+
<Table.Row>
|
| 195 |
+
<Table.Cell class="align-middle font-medium">Embedding Size</Table.Cell>
|
| 196 |
+
|
| 197 |
+
<Table.Cell>{formatNumber(modelMeta.n_embd)}</Table.Cell>
|
| 198 |
+
</Table.Row>
|
| 199 |
+
{/if}
|
| 200 |
+
|
| 201 |
+
<!-- Vocabulary Size -->
|
| 202 |
+
{#if modelMeta?.n_vocab}
|
| 203 |
+
<Table.Row>
|
| 204 |
+
<Table.Cell class="align-middle font-medium">Vocabulary Size</Table.Cell>
|
| 205 |
+
|
| 206 |
+
<Table.Cell>{formatNumber(modelMeta.n_vocab)} tokens</Table.Cell>
|
| 207 |
+
</Table.Row>
|
| 208 |
+
{/if}
|
| 209 |
+
|
| 210 |
+
<!-- Vocabulary Type -->
|
| 211 |
+
{#if modelMeta?.vocab_type}
|
| 212 |
+
<Table.Row>
|
| 213 |
+
<Table.Cell class="align-middle font-medium">Vocabulary Type</Table.Cell>
|
| 214 |
+
<Table.Cell class="align-middle capitalize">{modelMeta.vocab_type}</Table.Cell>
|
| 215 |
+
</Table.Row>
|
| 216 |
+
{/if}
|
| 217 |
+
|
| 218 |
+
<!-- Total Slots -->
|
| 219 |
+
<Table.Row>
|
| 220 |
+
<Table.Cell class="align-middle font-medium">Parallel Slots</Table.Cell>
|
| 221 |
+
|
| 222 |
+
<Table.Cell>{serverProps.total_slots}</Table.Cell>
|
| 223 |
+
</Table.Row>
|
| 224 |
+
|
| 225 |
+
<!-- Modalities -->
|
| 226 |
+
{#if modalities.length > 0}
|
| 227 |
+
<Table.Row>
|
| 228 |
+
<Table.Cell class="align-middle font-medium">Modalities</Table.Cell>
|
| 229 |
+
|
| 230 |
+
<Table.Cell>
|
| 231 |
+
<div class="flex flex-wrap gap-1">
|
| 232 |
+
<BadgesModality {modalities} />
|
| 233 |
+
</div>
|
| 234 |
+
</Table.Cell>
|
| 235 |
+
</Table.Row>
|
| 236 |
+
{/if}
|
| 237 |
+
|
| 238 |
+
<!-- Build Info -->
|
| 239 |
+
<Table.Row>
|
| 240 |
+
<Table.Cell class="align-middle font-medium">Build Info</Table.Cell>
|
| 241 |
+
|
| 242 |
+
<Table.Cell class="align-middle font-mono text-xs"
|
| 243 |
+
>{serverProps.build_info}</Table.Cell
|
| 244 |
+
>
|
| 245 |
+
</Table.Row>
|
| 246 |
+
|
| 247 |
+
<!-- Chat Template -->
|
| 248 |
+
{#if serverProps.chat_template}
|
| 249 |
+
<Table.Row>
|
| 250 |
+
<Table.Cell class="align-middle font-medium">Chat Template</Table.Cell>
|
| 251 |
+
|
| 252 |
+
<Table.Cell class="py-10">
|
| 253 |
+
<div class="rounded-md bg-muted p-4">
|
| 254 |
+
<pre
|
| 255 |
+
class="font-mono text-xs whitespace-pre-wrap">{serverProps.chat_template}</pre>
|
| 256 |
+
</div>
|
| 257 |
+
</Table.Cell>
|
| 258 |
+
</Table.Row>
|
| 259 |
+
{/if}
|
| 260 |
+
</Table.Body>
|
| 261 |
+
</Table.Root>
|
| 262 |
+
{/if}
|
| 263 |
+
{:else if !isLoadingModels}
|
| 264 |
+
<div class="flex items-center justify-center py-8">
|
| 265 |
+
<div class="text-sm text-muted-foreground">No model information available</div>
|
| 266 |
+
</div>
|
| 267 |
+
{/if}
|
| 268 |
+
</div>
|
| 269 |
+
</Dialog.Content>
|
| 270 |
+
</Dialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/DialogModelNotAvailable.svelte
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as AlertDialog from '$lib/components/ui/alert-dialog';
|
| 3 |
+
import { AlertTriangle, ArrowRight } from '@lucide/svelte';
|
| 4 |
+
import { goto } from '$app/navigation';
|
| 5 |
+
import { page } from '$app/state';
|
| 6 |
+
|
| 7 |
+
interface Props {
|
| 8 |
+
open: boolean;
|
| 9 |
+
modelName: string;
|
| 10 |
+
availableModels?: string[];
|
| 11 |
+
onOpenChange?: (open: boolean) => void;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
let { open = $bindable(), modelName, availableModels = [], onOpenChange }: Props = $props();
|
| 15 |
+
|
| 16 |
+
function handleOpenChange(newOpen: boolean) {
|
| 17 |
+
open = newOpen;
|
| 18 |
+
onOpenChange?.(newOpen);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
function handleSelectModel(model: string) {
|
| 22 |
+
// Build URL with selected model, preserving other params
|
| 23 |
+
const url = new URL(page.url);
|
| 24 |
+
url.searchParams.set('model', model);
|
| 25 |
+
|
| 26 |
+
handleOpenChange(false);
|
| 27 |
+
goto(url.toString());
|
| 28 |
+
}
|
| 29 |
+
</script>
|
| 30 |
+
|
| 31 |
+
<AlertDialog.Root {open} onOpenChange={handleOpenChange}>
|
| 32 |
+
<AlertDialog.Content class="max-w-lg">
|
| 33 |
+
<AlertDialog.Header>
|
| 34 |
+
<AlertDialog.Title class="flex items-center gap-2">
|
| 35 |
+
<AlertTriangle class="h-5 w-5 text-amber-500" />
|
| 36 |
+
Model Not Available
|
| 37 |
+
</AlertDialog.Title>
|
| 38 |
+
|
| 39 |
+
<AlertDialog.Description>
|
| 40 |
+
The requested model could not be found. Select an available model to continue.
|
| 41 |
+
</AlertDialog.Description>
|
| 42 |
+
</AlertDialog.Header>
|
| 43 |
+
|
| 44 |
+
<div class="space-y-3">
|
| 45 |
+
<div class="rounded-lg border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-sm">
|
| 46 |
+
<p class="font-medium text-amber-600 dark:text-amber-400">
|
| 47 |
+
Requested: <code class="rounded bg-amber-500/20 px-1.5 py-0.5">{modelName}</code>
|
| 48 |
+
</p>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
{#if availableModels.length > 0}
|
| 52 |
+
<div class="text-sm">
|
| 53 |
+
<p class="mb-2 font-medium text-muted-foreground">Select an available model:</p>
|
| 54 |
+
<div class="max-h-48 space-y-1 overflow-y-auto rounded-md border p-1">
|
| 55 |
+
{#each availableModels as model (model)}
|
| 56 |
+
<button
|
| 57 |
+
type="button"
|
| 58 |
+
class="group flex w-full items-center justify-between gap-2 rounded-sm px-3 py-2 text-left text-sm transition-colors hover:bg-accent hover:text-accent-foreground"
|
| 59 |
+
onclick={() => handleSelectModel(model)}
|
| 60 |
+
>
|
| 61 |
+
<span class="min-w-0 truncate font-mono text-xs">{model}</span>
|
| 62 |
+
<ArrowRight
|
| 63 |
+
class="h-4 w-4 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"
|
| 64 |
+
/>
|
| 65 |
+
</button>
|
| 66 |
+
{/each}
|
| 67 |
+
</div>
|
| 68 |
+
</div>
|
| 69 |
+
{/if}
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
<AlertDialog.Footer>
|
| 73 |
+
<AlertDialog.Action onclick={() => handleOpenChange(false)}>Cancel</AlertDialog.Action>
|
| 74 |
+
</AlertDialog.Footer>
|
| 75 |
+
</AlertDialog.Content>
|
| 76 |
+
</AlertDialog.Root>
|
llama.cpp/tools/ui/src/lib/components/app/dialogs/index.ts
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* DIALOGS
|
| 4 |
+
*
|
| 5 |
+
* Modal dialog components for the chat application.
|
| 6 |
+
*
|
| 7 |
+
* All dialogs use ShadCN Dialog or AlertDialog components for consistent
|
| 8 |
+
* styling, accessibility, and animation. They integrate with application
|
| 9 |
+
* stores for state management and data access.
|
| 10 |
+
*
|
| 11 |
+
*/
|
| 12 |
+
|
| 13 |
+
/**
|
| 14 |
+
* **DialogMcpServerAddNew** - Add new MCP server dialog
|
| 15 |
+
*
|
| 16 |
+
* Modal dialog for adding a new MCP server with URL and optional headers.
|
| 17 |
+
* Validates URL format and integrates with mcpStore and conversationsStore.
|
| 18 |
+
*/
|
| 19 |
+
export { default as DialogMcpServerAddNew } from './DialogMcpServerAddNew.svelte';
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* **DialogMcpServerRecommendations** - Suggested MCP servers opt-in dialog
|
| 23 |
+
*
|
| 24 |
+
* Prompts the user to enable pre-defined recommended MCP servers on first launch.
|
| 25 |
+
* Shows one switch per suggested server and persists the choice as a per-chat
|
| 26 |
+
* override so the selected servers become available in conversations.
|
| 27 |
+
*/
|
| 28 |
+
export { default as DialogMcpServerRecommendations } from './DialogMcpServerRecommendations.svelte';
|
| 29 |
+
|
| 30 |
+
/**
|
| 31 |
+
* **DialogExportSettings** - Settings export dialog with sensitive data warning
|
| 32 |
+
*
|
| 33 |
+
* Dialog for exporting settings with an option to include or exclude
|
| 34 |
+
* sensitive data (API keys, MCP server custom headers). Defaults to excluding
|
| 35 |
+
* sensitive data for security. User must explicitly opt-in to include them.
|
| 36 |
+
*
|
| 37 |
+
* **Architecture:**
|
| 38 |
+
* - Uses ShadCN AlertDialog
|
| 39 |
+
* - Checkbox to toggle sensitive data inclusion (defaults to false)
|
| 40 |
+
* - Warning icon and message when sensitive data is included
|
| 41 |
+
* - Destructive variant for the action button when exporting with sensitive data
|
| 42 |
+
*
|
| 43 |
+
* **Features:**
|
| 44 |
+
* - Secure default: sensitive data excluded by default
|
| 45 |
+
* - User must explicitly opt-in to include sensitive data
|
| 46 |
+
* - Visual warning (ShieldOff icon) when sensitive data is included
|
| 47 |
+
* - Different action text based on sensitive data state
|
| 48 |
+
*
|
| 49 |
+
* @example
|
| 50 |
+
* ```svelte
|
| 51 |
+
* <DialogExportSettings
|
| 52 |
+
* bind:open={showExportSettings}
|
| 53 |
+
* bind:includeSensitiveData
|
| 54 |
+
* onConfirm={handleSettingsExport}
|
| 55 |
+
* onCancel={() => showExportSettings = false}
|
| 56 |
+
* />
|
| 57 |
+
* ```
|
| 58 |
+
*/
|
| 59 |
+
export { default as DialogExportSettings } from './DialogExportSettings.svelte';
|
| 60 |
+
|
| 61 |
+
/**
|
| 62 |
+
*
|
| 63 |
+
* CONFIRMATION DIALOGS
|
| 64 |
+
*
|
| 65 |
+
* Dialogs for user action confirmations. Use AlertDialog for blocking
|
| 66 |
+
* confirmations that require explicit user decision before proceeding.
|
| 67 |
+
*
|
| 68 |
+
*/
|
| 69 |
+
|
| 70 |
+
/**
|
| 71 |
+
* **DialogConfirmation** - Generic confirmation dialog
|
| 72 |
+
*
|
| 73 |
+
* Reusable confirmation dialog with customizable title, description,
|
| 74 |
+
* and action buttons. Supports destructive action styling and custom icons.
|
| 75 |
+
* Used for delete confirmations, irreversible actions, and important decisions.
|
| 76 |
+
*
|
| 77 |
+
* **Architecture:**
|
| 78 |
+
* - Uses ShadCN AlertDialog
|
| 79 |
+
* - Supports variant styling (default, destructive)
|
| 80 |
+
* - Customizable button labels and callbacks
|
| 81 |
+
*
|
| 82 |
+
* **Features:**
|
| 83 |
+
* - Customizable title and description text
|
| 84 |
+
* - Destructive variant with red styling for dangerous actions
|
| 85 |
+
* - Custom icon support in header
|
| 86 |
+
* - Cancel and confirm button callbacks
|
| 87 |
+
* - Keyboard accessible (Escape to cancel, Enter to confirm)
|
| 88 |
+
*
|
| 89 |
+
* @example
|
| 90 |
+
* ```svelte
|
| 91 |
+
* <DialogConfirmation
|
| 92 |
+
* bind:open={showDelete}
|
| 93 |
+
* title="Delete conversation?"
|
| 94 |
+
* description="This action cannot be undone."
|
| 95 |
+
* variant="destructive"
|
| 96 |
+
* onConfirm={handleDelete}
|
| 97 |
+
* onCancel={() => showDelete = false}
|
| 98 |
+
* />
|
| 99 |
+
* ```
|
| 100 |
+
*/
|
| 101 |
+
export { default as DialogConfirmation } from './DialogConfirmation.svelte';
|
| 102 |
+
|
| 103 |
+
/**
|
| 104 |
+
* **DialogConversationTitleUpdate** - Conversation rename confirmation
|
| 105 |
+
*
|
| 106 |
+
* Confirmation dialog shown when editing the first user message in a conversation.
|
| 107 |
+
* Asks user whether to update the conversation title to match the new message content.
|
| 108 |
+
*
|
| 109 |
+
* **Architecture:**
|
| 110 |
+
* - Uses ShadCN AlertDialog
|
| 111 |
+
* - Shows current vs proposed title comparison
|
| 112 |
+
* - Triggered by ChatMessages when first message is edited
|
| 113 |
+
*
|
| 114 |
+
* **Features:**
|
| 115 |
+
* - Side-by-side display of current and new title
|
| 116 |
+
* - "Keep Current Title" and "Update Title" action buttons
|
| 117 |
+
* - Styled title previews in muted background boxes
|
| 118 |
+
*
|
| 119 |
+
* @example
|
| 120 |
+
* ```svelte
|
| 121 |
+
* <DialogConversationTitleUpdate
|
| 122 |
+
* bind:open={showTitleUpdate}
|
| 123 |
+
* currentTitle={conversation.name}
|
| 124 |
+
* newTitle={truncatedMessageContent}
|
| 125 |
+
* onConfirm={updateTitle}
|
| 126 |
+
* onCancel={() => showTitleUpdate = false}
|
| 127 |
+
* />
|
| 128 |
+
* ```
|
| 129 |
+
*/
|
| 130 |
+
export { default as DialogConversationTitleUpdate } from './DialogConversationTitleUpdate.svelte';
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
*
|
| 134 |
+
* CONTENT PREVIEW DIALOGS
|
| 135 |
+
*
|
| 136 |
+
* Dialogs for previewing and displaying content in full-screen or modal views.
|
| 137 |
+
*
|
| 138 |
+
*/
|
| 139 |
+
|
| 140 |
+
/**
|
| 141 |
+
* **DialogCodePreview** - Full-screen code/HTML preview
|
| 142 |
+
*
|
| 143 |
+
* Full-screen dialog for previewing HTML or code in an isolated iframe.
|
| 144 |
+
* Used by MarkdownContent component for previewing rendered HTML blocks
|
| 145 |
+
* from code blocks in chat messages.
|
| 146 |
+
*
|
| 147 |
+
* **Architecture:**
|
| 148 |
+
* - Uses ShadCN Dialog with full viewport layout
|
| 149 |
+
* - Sandboxed iframe execution (allow-scripts only)
|
| 150 |
+
* - Clears content when closed for security
|
| 151 |
+
*
|
| 152 |
+
* **Features:**
|
| 153 |
+
* - Full viewport iframe preview
|
| 154 |
+
* - Sandboxed execution environment
|
| 155 |
+
* - Close button with mix-blend-difference for visibility over any content
|
| 156 |
+
* - Automatic content cleanup on close
|
| 157 |
+
* - Supports HTML preview with proper isolation
|
| 158 |
+
*
|
| 159 |
+
* @example
|
| 160 |
+
* ```svelte
|
| 161 |
+
* <DialogCodePreview
|
| 162 |
+
* bind:open={showPreview}
|
| 163 |
+
* code={htmlContent}
|
| 164 |
+
* language="html"
|
| 165 |
+
* />
|
| 166 |
+
* ```
|
| 167 |
+
*/
|
| 168 |
+
export { default as DialogCodePreview } from './DialogCodePreview.svelte';
|
| 169 |
+
|
| 170 |
+
/**
|
| 171 |
+
*
|
| 172 |
+
* ATTACHMENT DIALOGS
|
| 173 |
+
*
|
| 174 |
+
* Dialogs for viewing and managing file attachments. Support both
|
| 175 |
+
* uploaded files (pending) and stored attachments (in messages).
|
| 176 |
+
*
|
| 177 |
+
*/
|
| 178 |
+
|
| 179 |
+
/**
|
| 180 |
+
* **DialogChatAttachmentsPreview** - Unified attachment preview dialog
|
| 181 |
+
*
|
| 182 |
+
* Modal dialog for previewing file attachments. Automatically adapts to the
|
| 183 |
+
* number of items: shows a single file preview without carousel for one item,
|
| 184 |
+
* or a gallery with carousel navigation for multiple items.
|
| 185 |
+
*
|
| 186 |
+
* **Architecture:**
|
| 187 |
+
* - Wraps ChatAttachmentsPreview component in ShadCN Dialog
|
| 188 |
+
* - Accepts uploadedFiles and attachments arrays as data sources
|
| 189 |
+
* - Filters out MCP prompts and MCP resources from display
|
| 190 |
+
*
|
| 191 |
+
* **Features:**
|
| 192 |
+
* - Single item mode: direct preview without navigation controls
|
| 193 |
+
* - Multi-item mode: gallery with left/right arrows and thumbnail strip
|
| 194 |
+
* - File type aware preview (images, text, PDFs, audio)
|
| 195 |
+
* - File name and size/count display in header
|
| 196 |
+
*
|
| 197 |
+
* @example
|
| 198 |
+
* ```svelte
|
| 199 |
+
* <!-- Gallery with focus on 2nd item -->
|
| 200 |
+
* <DialogChatAttachmentsPreview
|
| 201 |
+
* bind:open={showPreview}
|
| 202 |
+
* uploadedFiles={pendingFiles}
|
| 203 |
+
* attachments={message.extra}
|
| 204 |
+
* activeModelId={currentModel}
|
| 205 |
+
* previewFocusIndex={1}
|
| 206 |
+
* />
|
| 207 |
+
* ```
|
| 208 |
+
*/
|
| 209 |
+
export { default as DialogChatAttachmentsPreview } from './DialogChatAttachmentsPreview.svelte';
|
| 210 |
+
|
| 211 |
+
/**
|
| 212 |
+
*
|
| 213 |
+
* ERROR & ALERT DIALOGS
|
| 214 |
+
*
|
| 215 |
+
* Dialogs for displaying errors, warnings, and alerts to users.
|
| 216 |
+
* Provide context about what went wrong and recovery options.
|
| 217 |
+
*
|
| 218 |
+
*/
|
| 219 |
+
|
| 220 |
+
/**
|
| 221 |
+
* **DialogChatError** - Chat/generation error display
|
| 222 |
+
*
|
| 223 |
+
* Alert dialog for displaying chat and generation errors with context
|
| 224 |
+
* information. Supports different error types with appropriate styling
|
| 225 |
+
* and messaging.
|
| 226 |
+
*
|
| 227 |
+
* **Architecture:**
|
| 228 |
+
* - Uses ShadCN AlertDialog for modal display
|
| 229 |
+
* - Differentiates between timeout and server errors
|
| 230 |
+
* - Shows context info when available (token counts)
|
| 231 |
+
*
|
| 232 |
+
* **Error Types:**
|
| 233 |
+
* - **timeout**: TCP timeout with timer icon, red destructive styling
|
| 234 |
+
* - **server**: Server error with warning icon, amber warning styling
|
| 235 |
+
*
|
| 236 |
+
* **Features:**
|
| 237 |
+
* - Type-specific icons (TimerOff for timeout, AlertTriangle for server)
|
| 238 |
+
* - Error message display in styled badge
|
| 239 |
+
* - Context info showing prompt tokens and context size
|
| 240 |
+
* - Close button to dismiss
|
| 241 |
+
*
|
| 242 |
+
* @example
|
| 243 |
+
* ```svelte
|
| 244 |
+
* <DialogChatError
|
| 245 |
+
* bind:open={showError}
|
| 246 |
+
* type="server"
|
| 247 |
+
* message={errorMessage}
|
| 248 |
+
* contextInfo={{ n_prompt_tokens: 1024, n_ctx: 4096 }}
|
| 249 |
+
* />
|
| 250 |
+
* ```
|
| 251 |
+
*/
|
| 252 |
+
export { default as DialogChatError } from './DialogChatError.svelte';
|
| 253 |
+
|
| 254 |
+
/**
|
| 255 |
+
* **DialogEmptyFileAlert** - Empty file upload warning
|
| 256 |
+
*
|
| 257 |
+
* Alert dialog shown when user attempts to upload empty files. Lists the
|
| 258 |
+
* empty files that were detected and removed from attachments, with
|
| 259 |
+
* explanation of why empty files cannot be processed.
|
| 260 |
+
*
|
| 261 |
+
* **Architecture:**
|
| 262 |
+
* - Uses ShadCN AlertDialog for modal display
|
| 263 |
+
* - Receives list of empty file names from ChatScreen
|
| 264 |
+
* - Triggered during file upload validation
|
| 265 |
+
*
|
| 266 |
+
* **Features:**
|
| 267 |
+
* - FileX icon indicating file error
|
| 268 |
+
* - List of empty file names in monospace font
|
| 269 |
+
* - Explanation of what happened and why
|
| 270 |
+
* - Single "Got it" dismiss button
|
| 271 |
+
*
|
| 272 |
+
* @example
|
| 273 |
+
* ```svelte
|
| 274 |
+
* <DialogEmptyFileAlert
|
| 275 |
+
* bind:open={showEmptyAlert}
|
| 276 |
+
* emptyFiles={['empty.txt', 'blank.md']}
|
| 277 |
+
* />
|
| 278 |
+
* ```
|
| 279 |
+
*/
|
| 280 |
+
export { default as DialogEmptyFileAlert } from './DialogEmptyFileAlert.svelte';
|
| 281 |
+
|
| 282 |
+
/**
|
| 283 |
+
* **DialogFileUploadError** - File upload compatibility error
|
| 284 |
+
*
|
| 285 |
+
* Alert dialog shown when files cannot be uploaded due to type incompatibility
|
| 286 |
+
* or model modality restrictions. Displays a categorized list of problematic
|
| 287 |
+
* files with explanations and shows which file types the current model supports.
|
| 288 |
+
*
|
| 289 |
+
* **Architecture:**
|
| 290 |
+
* - Uses ShadCN AlertDialog for modal display
|
| 291 |
+
* - Receives structured file error data from ChatScreen
|
| 292 |
+
* - Triggered during file upload validation in processFiles()
|
| 293 |
+
*
|
| 294 |
+
* **Features:**
|
| 295 |
+
* - Categorized display: unsupported types vs modality restrictions
|
| 296 |
+
* - File name in monospace with contextual error messages
|
| 297 |
+
* - Summary of supported file types for the current model
|
| 298 |
+
* - Scrollable content area for large error lists
|
| 299 |
+
* - Single "Got it" dismiss button
|
| 300 |
+
*
|
| 301 |
+
* @example
|
| 302 |
+
* ```svelte
|
| 303 |
+
* <DialogFileUploadError
|
| 304 |
+
* bind:open={showFileError}
|
| 305 |
+
* fileErrorData={errorData}
|
| 306 |
+
* />
|
| 307 |
+
* ```
|
| 308 |
+
*/
|
| 309 |
+
export { default as DialogFileUploadError } from './DialogFileUploadError.svelte';
|
| 310 |
+
|
| 311 |
+
/**
|
| 312 |
+
* **DialogModelNotAvailable** - Model unavailable error
|
| 313 |
+
*
|
| 314 |
+
* Alert dialog shown when the requested model (from URL params or selection)
|
| 315 |
+
* is not available on the server. Displays the requested model name and
|
| 316 |
+
* offers selection from available models.
|
| 317 |
+
*
|
| 318 |
+
* **Architecture:**
|
| 319 |
+
* - Uses ShadCN AlertDialog for modal display
|
| 320 |
+
* - Integrates with SvelteKit navigation for model switching
|
| 321 |
+
* - Receives available models list from modelsStore
|
| 322 |
+
*
|
| 323 |
+
* **Features:**
|
| 324 |
+
* - Warning icon with amber styling
|
| 325 |
+
* - Requested model name display in styled badge
|
| 326 |
+
* - Scrollable list of available models
|
| 327 |
+
* - Click model to navigate with updated URL params
|
| 328 |
+
* - Cancel button to dismiss without selection
|
| 329 |
+
*
|
| 330 |
+
* @example
|
| 331 |
+
* ```svelte
|
| 332 |
+
* <DialogModelNotAvailable
|
| 333 |
+
* bind:open={showModelError}
|
| 334 |
+
* modelName={requestedModel}
|
| 335 |
+
* availableModels={modelsList}
|
| 336 |
+
* />
|
| 337 |
+
* ```
|
| 338 |
+
*/
|
| 339 |
+
export { default as DialogModelNotAvailable } from './DialogModelNotAvailable.svelte';
|
| 340 |
+
|
| 341 |
+
/**
|
| 342 |
+
*
|
| 343 |
+
* DATA MANAGEMENT DIALOGS
|
| 344 |
+
*
|
| 345 |
+
* Dialogs for managing conversation data, including import/export
|
| 346 |
+
* and selection operations.
|
| 347 |
+
*
|
| 348 |
+
*/
|
| 349 |
+
|
| 350 |
+
/**
|
| 351 |
+
* **DialogConversationSelection** - Conversation picker for import/export
|
| 352 |
+
*
|
| 353 |
+
* Dialog for selecting conversations during import or export operations.
|
| 354 |
+
* Displays list of conversations with checkboxes for multi-selection.
|
| 355 |
+
* Used by ChatSettingsImportExportTab for data management.
|
| 356 |
+
*
|
| 357 |
+
* **Architecture:**
|
| 358 |
+
* - Wraps ConversationSelection component in ShadCN Dialog
|
| 359 |
+
* - Supports export mode (select from local) and import mode (select from file)
|
| 360 |
+
* - Resets selection state when dialog opens
|
| 361 |
+
* - High z-index to appear above settings dialog
|
| 362 |
+
*
|
| 363 |
+
* **Features:**
|
| 364 |
+
* - Multi-select with checkboxes
|
| 365 |
+
* - Conversation title and message count display
|
| 366 |
+
* - Select all / deselect all controls
|
| 367 |
+
* - Mode-specific descriptions (export vs import)
|
| 368 |
+
* - Cancel and confirm callbacks with selected conversations
|
| 369 |
+
*
|
| 370 |
+
* @example
|
| 371 |
+
* ```svelte
|
| 372 |
+
* <DialogConversationSelection
|
| 373 |
+
* bind:open={showExportSelection}
|
| 374 |
+
* conversations={allConversations}
|
| 375 |
+
* messageCountMap={messageCounts}
|
| 376 |
+
* mode="export"
|
| 377 |
+
* onConfirm={handleExport}
|
| 378 |
+
* onCancel={() => showExportSelection = false}
|
| 379 |
+
* />
|
| 380 |
+
* ```
|
| 381 |
+
*/
|
| 382 |
+
export { default as DialogConversationSelection } from './DialogConversationSelection.svelte';
|
| 383 |
+
|
| 384 |
+
/**
|
| 385 |
+
*
|
| 386 |
+
* MODEL INFORMATION DIALOGS
|
| 387 |
+
*
|
| 388 |
+
* Dialogs for displaying model and server information.
|
| 389 |
+
*
|
| 390 |
+
*/
|
| 391 |
+
|
| 392 |
+
/**
|
| 393 |
+
* **DialogModelInformation** - Model details display
|
| 394 |
+
*
|
| 395 |
+
* Dialog showing comprehensive information about the currently loaded model
|
| 396 |
+
* and server configuration. Displays model metadata, capabilities, and
|
| 397 |
+
* server settings in a structured table format.
|
| 398 |
+
*
|
| 399 |
+
* **Architecture:**
|
| 400 |
+
* - Uses ShadCN Dialog with wide layout for table display
|
| 401 |
+
* - Fetches data from serverStore (props) and modelsStore (metadata)
|
| 402 |
+
* - Auto-fetches models when dialog opens if not loaded
|
| 403 |
+
*
|
| 404 |
+
* **Information Displayed:**
|
| 405 |
+
* - **Model**: Name with copy button
|
| 406 |
+
* - **File Path**: Full path to model file with copy button
|
| 407 |
+
* - **Context Size**: Current context window size
|
| 408 |
+
* - **Training Context**: Original training context (if available)
|
| 409 |
+
* - **Model Size**: File size in human-readable format
|
| 410 |
+
* - **Parameters**: Parameter count (e.g., "7B", "70B")
|
| 411 |
+
* - **Embedding Size**: Embedding dimension
|
| 412 |
+
* - **Vocabulary Size**: Token vocabulary size
|
| 413 |
+
* - **Vocabulary Type**: Tokenizer type (BPE, etc.)
|
| 414 |
+
* - **Parallel Slots**: Number of concurrent request slots
|
| 415 |
+
* - **Modalities**: Supported input types (text, vision, audio)
|
| 416 |
+
* - **Build Info**: Server build information
|
| 417 |
+
* - **Chat Template**: Full Jinja template in scrollable code block
|
| 418 |
+
*
|
| 419 |
+
* **Features:**
|
| 420 |
+
* - Copy buttons for model name and path
|
| 421 |
+
* - Modality badges with icons
|
| 422 |
+
* - Responsive table layout with container queries
|
| 423 |
+
* - Loading state while fetching model info
|
| 424 |
+
* - Scrollable chat template display
|
| 425 |
+
*
|
| 426 |
+
* @example
|
| 427 |
+
* ```svelte
|
| 428 |
+
* <DialogModelInformation bind:open={showModelInfo} />
|
| 429 |
+
* ```
|
| 430 |
+
*/
|
| 431 |
+
export { default as DialogModelInformation } from './DialogModelInformation.svelte';
|
| 432 |
+
|
| 433 |
+
/**
|
| 434 |
+
* **DialogMcpResourcesBrowser** - MCP resources browser dialog
|
| 435 |
+
*
|
| 436 |
+
* Dialog for browsing and attaching MCP resources to chat context.
|
| 437 |
+
* Displays resources from connected MCP servers in a tree structure
|
| 438 |
+
* with preview panel and multi-select support.
|
| 439 |
+
*
|
| 440 |
+
* **Architecture:**
|
| 441 |
+
* - Uses ShadCN Dialog with two-panel layout
|
| 442 |
+
* - Left panel: McpResourcesBrowser with tree navigation
|
| 443 |
+
* - Right panel: McpResourcePreview for selected resource
|
| 444 |
+
* - Integrates with mcpStore for resource fetching and attachment
|
| 445 |
+
*
|
| 446 |
+
* **Features:**
|
| 447 |
+
* - Tree-based resource navigation by server and path
|
| 448 |
+
* - Single and multi-select with shift+click
|
| 449 |
+
* - Resource preview with content display
|
| 450 |
+
* - Quick attach button per resource
|
| 451 |
+
* - Batch attach for multiple selections
|
| 452 |
+
*
|
| 453 |
+
* @example
|
| 454 |
+
* ```svelte
|
| 455 |
+
* <DialogMcpResourcesBrowser
|
| 456 |
+
* bind:open={showResources}
|
| 457 |
+
* onAttach={handleResourceAttach}
|
| 458 |
+
* />
|
| 459 |
+
* ```
|
| 460 |
+
*/
|
| 461 |
+
export { default as DialogMcpResourcesBrowser } from './DialogMcpResourcesBrowser.svelte';
|
| 462 |
+
|
| 463 |
+
/**
|
| 464 |
+
* **DialogMcpResourcePreview** - MCP resource content preview
|
| 465 |
+
*
|
| 466 |
+
* Dialog for previewing the content of a stored MCP resource attachment.
|
| 467 |
+
* Displays the resource content with syntax highlighting for code,
|
| 468 |
+
* image rendering for images, and plain text for other content.
|
| 469 |
+
*
|
| 470 |
+
* **Features:**
|
| 471 |
+
* - Syntax highlighted code preview
|
| 472 |
+
* - Image rendering for image resources
|
| 473 |
+
* - Copy to clipboard and download actions
|
| 474 |
+
* - Server name and favicon display
|
| 475 |
+
* - MIME type badge
|
| 476 |
+
*
|
| 477 |
+
* @example
|
| 478 |
+
* ```svelte
|
| 479 |
+
* <DialogMcpResourcePreview
|
| 480 |
+
* bind:open={previewOpen}
|
| 481 |
+
* extra={mcpResourceExtra}
|
| 482 |
+
* />
|
| 483 |
+
* ```
|
| 484 |
+
*/
|
| 485 |
+
export { default as DialogMcpResourcePreview } from './DialogMcpResourcePreview.svelte';
|
| 486 |
+
|
| 487 |
+
/**
|
| 488 |
+
* **DialogMermaidPreview** - Full-screen Mermaid diagram preview with zoom and pan
|
| 489 |
+
*
|
| 490 |
+
* Full-screen dialog for previewing Mermaid diagrams with interactive controls.
|
| 491 |
+
* Supports mouse wheel zoom, drag-to-pan, and toolbar buttons for zoom in/out,
|
| 492 |
+
* fit to view, and reset.
|
| 493 |
+
*
|
| 494 |
+
* **Architecture:**
|
| 495 |
+
* - Uses UI dialog components (`Dialog.Root`, `Dialog.Overlay`, `Dialog.Content`)
|
| 496 |
+
* for consistent styling, animations, and accessibility
|
| 497 |
+
* - CSS transform-based zoom and pan (no external dependencies)
|
| 498 |
+
* - Pointer events for cross-device drag support (mouse + touch)
|
| 499 |
+
* - Wheel events for zoom-to-cursor functionality
|
| 500 |
+
*
|
| 501 |
+
* **Features:**
|
| 502 |
+
* - Scroll wheel zoom centered on cursor position
|
| 503 |
+
* - Click and drag to pan the diagram
|
| 504 |
+
* - Toolbar with zoom in, zoom out, fit to view, reset controls
|
| 505 |
+
* - Zoom percentage indicator
|
| 506 |
+
* - Keyboard accessible close button
|
| 507 |
+
* - Dark/light theme support
|
| 508 |
+
*
|
| 509 |
+
* @example
|
| 510 |
+
* ```svelte
|
| 511 |
+
* <DialogMermaidPreview
|
| 512 |
+
* bind:open={showMermaidPreview}
|
| 513 |
+
* svgHtml={mermaidSvgContent}
|
| 514 |
+
* />
|
| 515 |
+
* ```
|
| 516 |
+
*/
|
| 517 |
+
export { default as DialogMermaidPreview } from './DialogMermaidPreview.svelte';
|
llama.cpp/tools/ui/src/lib/components/app/forms/InputWithSuggestions.svelte
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { fly } from 'svelte/transition';
|
| 3 |
+
import { Input } from '$lib/components/ui/input';
|
| 4 |
+
import { Label } from '$lib/components/ui/label';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
name: string;
|
| 8 |
+
value: string;
|
| 9 |
+
suggestions?: string[];
|
| 10 |
+
isLoadingSuggestions?: boolean;
|
| 11 |
+
isAutocompleteActive?: boolean;
|
| 12 |
+
autocompleteIndex?: number;
|
| 13 |
+
onInput: (value: string) => void;
|
| 14 |
+
onKeydown: (event: KeyboardEvent) => void;
|
| 15 |
+
onBlur: () => void;
|
| 16 |
+
onFocus: () => void;
|
| 17 |
+
onSelectSuggestion: (value: string) => void;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
let {
|
| 21 |
+
name,
|
| 22 |
+
value = '',
|
| 23 |
+
suggestions = [],
|
| 24 |
+
isLoadingSuggestions = false,
|
| 25 |
+
isAutocompleteActive = false,
|
| 26 |
+
autocompleteIndex = 0,
|
| 27 |
+
onInput,
|
| 28 |
+
onKeydown,
|
| 29 |
+
onBlur,
|
| 30 |
+
onFocus,
|
| 31 |
+
onSelectSuggestion
|
| 32 |
+
}: Props = $props();
|
| 33 |
+
</script>
|
| 34 |
+
|
| 35 |
+
<div class="relative grid gap-1">
|
| 36 |
+
<Label for="tpl-arg-{name}" class="mb-1 text-muted-foreground">
|
| 37 |
+
<span>
|
| 38 |
+
{name}
|
| 39 |
+
|
| 40 |
+
<span class="text-destructive">*</span>
|
| 41 |
+
</span>
|
| 42 |
+
|
| 43 |
+
{#if isLoadingSuggestions}
|
| 44 |
+
<span class="text-xs text-muted-foreground/50">...</span>
|
| 45 |
+
{/if}
|
| 46 |
+
</Label>
|
| 47 |
+
|
| 48 |
+
<Input
|
| 49 |
+
id="tpl-arg-{name}"
|
| 50 |
+
type="text"
|
| 51 |
+
{value}
|
| 52 |
+
oninput={(e) => onInput(e.currentTarget.value)}
|
| 53 |
+
onkeydown={onKeydown}
|
| 54 |
+
onblur={onBlur}
|
| 55 |
+
onfocus={onFocus}
|
| 56 |
+
placeholder="Enter {name}"
|
| 57 |
+
autocomplete="off"
|
| 58 |
+
/>
|
| 59 |
+
|
| 60 |
+
{#if isAutocompleteActive && suggestions.length > 0}
|
| 61 |
+
<div
|
| 62 |
+
class="absolute top-full right-0 left-0 z-10 mt-1 max-h-32 overflow-y-auto rounded-lg border border-border/50 bg-background shadow-lg"
|
| 63 |
+
transition:fly={{ y: -5, duration: 100 }}
|
| 64 |
+
>
|
| 65 |
+
{#each suggestions as suggestion, i (suggestion)}
|
| 66 |
+
<button
|
| 67 |
+
type="button"
|
| 68 |
+
onmousedown={() => onSelectSuggestion(suggestion)}
|
| 69 |
+
class="w-full px-3 py-1.5 text-left text-sm hover:bg-accent {i === autocompleteIndex
|
| 70 |
+
? 'bg-accent'
|
| 71 |
+
: ''}"
|
| 72 |
+
>
|
| 73 |
+
{suggestion}
|
| 74 |
+
</button>
|
| 75 |
+
{/each}
|
| 76 |
+
</div>
|
| 77 |
+
{/if}
|
| 78 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/forms/KeyValuePairs.svelte
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { tick } from 'svelte';
|
| 3 |
+
import { Plus, Trash2 } from '@lucide/svelte';
|
| 4 |
+
import { Input } from '$lib/components/ui/input';
|
| 5 |
+
import {
|
| 6 |
+
autoResizeTextarea,
|
| 7 |
+
sanitizeKeyValuePairKey,
|
| 8 |
+
sanitizeKeyValuePairValue
|
| 9 |
+
} from '$lib/utils';
|
| 10 |
+
import { KEY_VALUE_PAIR_KEY_MAX_LENGTH, KEY_VALUE_PAIR_VALUE_MAX_LENGTH } from '$lib/constants';
|
| 11 |
+
import type { KeyValuePair } from '$lib/types';
|
| 12 |
+
|
| 13 |
+
interface Props {
|
| 14 |
+
class?: string;
|
| 15 |
+
pairs: KeyValuePair[];
|
| 16 |
+
onPairsChange: (pairs: KeyValuePair[]) => void;
|
| 17 |
+
keyPlaceholder?: string;
|
| 18 |
+
valuePlaceholder?: string;
|
| 19 |
+
addButtonLabel?: string;
|
| 20 |
+
emptyMessage?: string;
|
| 21 |
+
sectionLabel?: string;
|
| 22 |
+
sectionLabelOptional?: boolean;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
let {
|
| 26 |
+
class: className = '',
|
| 27 |
+
pairs,
|
| 28 |
+
onPairsChange,
|
| 29 |
+
keyPlaceholder = 'Key',
|
| 30 |
+
valuePlaceholder = 'Value',
|
| 31 |
+
addButtonLabel = 'Add',
|
| 32 |
+
emptyMessage = 'No items configured.',
|
| 33 |
+
sectionLabel,
|
| 34 |
+
sectionLabelOptional = true
|
| 35 |
+
}: Props = $props();
|
| 36 |
+
|
| 37 |
+
// Pre-allocate the ref array so `bind:ref={keyInputRefs[index]}` never reads `undefined`
|
| 38 |
+
// for in-range indices; the $effect below keeps it in sync when `pairs` grows.
|
| 39 |
+
// svelte-ignore state_referenced_locally
|
| 40 |
+
let keyInputRefs: (HTMLInputElement | null)[] = $state(pairs.map(() => null));
|
| 41 |
+
|
| 42 |
+
async function addPair() {
|
| 43 |
+
// Capture the target index before mutating so deletions earlier in the
|
| 44 |
+
// list can't make keyInputRefs.length drift past the newly-appended row.
|
| 45 |
+
const newIndex = pairs.length;
|
| 46 |
+
onPairsChange([...pairs, { key: '', value: '' }]);
|
| 47 |
+
await tick();
|
| 48 |
+
keyInputRefs[newIndex]?.focus();
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
function removePair(index: number) {
|
| 52 |
+
onPairsChange(pairs.filter((_, i) => i !== index));
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function updatePairKey(index: number, rawKey: string) {
|
| 56 |
+
const key = sanitizeKeyValuePairKey(rawKey);
|
| 57 |
+
const newPairs = [...pairs];
|
| 58 |
+
|
| 59 |
+
newPairs[index] = { ...newPairs[index], key };
|
| 60 |
+
onPairsChange(newPairs);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
function trimPairKey(index: number, key: string) {
|
| 64 |
+
const trimmed = key.trim();
|
| 65 |
+
if (trimmed === key) return;
|
| 66 |
+
|
| 67 |
+
const newPairs = [...pairs];
|
| 68 |
+
|
| 69 |
+
newPairs[index] = { ...newPairs[index], key: trimmed };
|
| 70 |
+
onPairsChange(newPairs);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function updatePairValue(index: number, rawValue: string) {
|
| 74 |
+
const value = sanitizeKeyValuePairValue(rawValue);
|
| 75 |
+
const newPairs = [...pairs];
|
| 76 |
+
|
| 77 |
+
newPairs[index] = { ...newPairs[index], value };
|
| 78 |
+
onPairsChange(newPairs);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function trimPairValue(index: number, value: string) {
|
| 82 |
+
const trimmed = value.trim();
|
| 83 |
+
if (trimmed === value) return;
|
| 84 |
+
|
| 85 |
+
const newPairs = [...pairs];
|
| 86 |
+
|
| 87 |
+
newPairs[index] = { ...newPairs[index], value: trimmed };
|
| 88 |
+
onPairsChange(newPairs);
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
// Keep keyInputRefs aligned with pairs length so bind:ref never sees `undefined`.
|
| 92 |
+
// $effect.pre runs during traversal in tree order, before the {#each} block re-renders,
|
| 93 |
+
// so newly-appended items always have a defined slot when their binding is set up.
|
| 94 |
+
$effect.pre(() => {
|
| 95 |
+
while (keyInputRefs.length < pairs.length) {
|
| 96 |
+
keyInputRefs.push(null);
|
| 97 |
+
}
|
| 98 |
+
});
|
| 99 |
+
</script>
|
| 100 |
+
|
| 101 |
+
<div class={className}>
|
| 102 |
+
<div class="mb-2 flex items-center justify-between">
|
| 103 |
+
{#if sectionLabel}
|
| 104 |
+
<span class="text-xs font-medium">
|
| 105 |
+
{sectionLabel}
|
| 106 |
+
{#if sectionLabelOptional}
|
| 107 |
+
<span class="text-muted-foreground">(optional)</span>
|
| 108 |
+
{/if}
|
| 109 |
+
</span>
|
| 110 |
+
{/if}
|
| 111 |
+
|
| 112 |
+
<button
|
| 113 |
+
type="button"
|
| 114 |
+
class="inline-flex cursor-pointer items-center gap-1 rounded-md px-1.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground"
|
| 115 |
+
onclick={addPair}
|
| 116 |
+
>
|
| 117 |
+
<Plus class="h-3 w-3" />
|
| 118 |
+
{addButtonLabel}
|
| 119 |
+
</button>
|
| 120 |
+
</div>
|
| 121 |
+
{#if pairs.length > 0}
|
| 122 |
+
<div class="space-y-3">
|
| 123 |
+
{#each pairs as pair, index (index)}
|
| 124 |
+
<div class="flex items-start gap-2">
|
| 125 |
+
<Input
|
| 126 |
+
bind:ref={keyInputRefs[index]}
|
| 127 |
+
type="text"
|
| 128 |
+
placeholder={keyPlaceholder}
|
| 129 |
+
value={pair.key}
|
| 130 |
+
maxlength={KEY_VALUE_PAIR_KEY_MAX_LENGTH}
|
| 131 |
+
oninput={(e) => updatePairKey(index, e.currentTarget.value)}
|
| 132 |
+
onblur={(e) => trimPairKey(index, e.currentTarget.value)}
|
| 133 |
+
class="flex-1"
|
| 134 |
+
/>
|
| 135 |
+
|
| 136 |
+
<textarea
|
| 137 |
+
use:autoResizeTextarea
|
| 138 |
+
placeholder={valuePlaceholder}
|
| 139 |
+
value={pair.value}
|
| 140 |
+
maxlength={KEY_VALUE_PAIR_VALUE_MAX_LENGTH}
|
| 141 |
+
oninput={(e) => {
|
| 142 |
+
updatePairValue(index, e.currentTarget.value);
|
| 143 |
+
autoResizeTextarea(e.currentTarget);
|
| 144 |
+
}}
|
| 145 |
+
onblur={(e) => trimPairValue(index, e.currentTarget.value)}
|
| 146 |
+
class="flex-1 resize-none rounded-md border border-input bg-transparent px-3 py-2 text-sm leading-5 placeholder:text-muted-foreground focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"
|
| 147 |
+
rows="1"
|
| 148 |
+
></textarea>
|
| 149 |
+
|
| 150 |
+
<button
|
| 151 |
+
type="button"
|
| 152 |
+
class="mt-1.5 shrink-0 cursor-pointer rounded-md p-1 text-muted-foreground hover:bg-destructive/10 hover:text-destructive"
|
| 153 |
+
onclick={() => removePair(index)}
|
| 154 |
+
aria-label="Remove item"
|
| 155 |
+
>
|
| 156 |
+
<Trash2 class="h-3.5 w-3.5" />
|
| 157 |
+
</button>
|
| 158 |
+
</div>
|
| 159 |
+
{/each}
|
| 160 |
+
</div>
|
| 161 |
+
{:else}
|
| 162 |
+
<p class="text-xs text-muted-foreground">{emptyMessage}</p>
|
| 163 |
+
{/if}
|
| 164 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/forms/SearchInput.svelte
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Input } from '$lib/components/ui/input';
|
| 3 |
+
import { Search, X } from '@lucide/svelte';
|
| 4 |
+
|
| 5 |
+
interface Props {
|
| 6 |
+
autofocus?: boolean;
|
| 7 |
+
value?: string;
|
| 8 |
+
placeholder?: string;
|
| 9 |
+
onInput?: (value: string) => void;
|
| 10 |
+
onClose?: () => void;
|
| 11 |
+
onKeyDown?: (event: KeyboardEvent) => void;
|
| 12 |
+
class?: string;
|
| 13 |
+
id?: string;
|
| 14 |
+
ref?: HTMLInputElement | null;
|
| 15 |
+
isCancelAlwaysVisible?: boolean;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
let {
|
| 19 |
+
autofocus,
|
| 20 |
+
value = $bindable(''),
|
| 21 |
+
placeholder = 'Search...',
|
| 22 |
+
onInput,
|
| 23 |
+
onClose,
|
| 24 |
+
onKeyDown,
|
| 25 |
+
class: className,
|
| 26 |
+
id,
|
| 27 |
+
ref = $bindable(null),
|
| 28 |
+
isCancelAlwaysVisible = false
|
| 29 |
+
}: Props = $props();
|
| 30 |
+
|
| 31 |
+
let showClearButton = $derived(isCancelAlwaysVisible || !!value || !!onClose);
|
| 32 |
+
|
| 33 |
+
function handleInput(event: Event) {
|
| 34 |
+
const target = event.target as HTMLInputElement;
|
| 35 |
+
|
| 36 |
+
value = target.value;
|
| 37 |
+
onInput?.(target.value);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function handleClear() {
|
| 41 |
+
if (value) {
|
| 42 |
+
value = '';
|
| 43 |
+
onInput?.('');
|
| 44 |
+
ref?.focus({ preventScroll: true });
|
| 45 |
+
} else {
|
| 46 |
+
onClose?.();
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
</script>
|
| 50 |
+
|
| 51 |
+
<div class="relative {className}">
|
| 52 |
+
<Search
|
| 53 |
+
class="absolute top-1/2 left-3 z-10 h-4 w-4 -translate-y-1/2 transform text-muted-foreground"
|
| 54 |
+
/>
|
| 55 |
+
|
| 56 |
+
<Input
|
| 57 |
+
{autofocus}
|
| 58 |
+
{id}
|
| 59 |
+
bind:value
|
| 60 |
+
bind:ref
|
| 61 |
+
class="pl-9 {showClearButton ? 'pr-9' : ''}"
|
| 62 |
+
oninput={handleInput}
|
| 63 |
+
onkeydown={onKeyDown}
|
| 64 |
+
{placeholder}
|
| 65 |
+
type="search"
|
| 66 |
+
/>
|
| 67 |
+
|
| 68 |
+
{#if showClearButton}
|
| 69 |
+
<button
|
| 70 |
+
type="button"
|
| 71 |
+
class="absolute top-1/2 right-3 -translate-y-1/2 transform cursor-pointer text-muted-foreground transition-colors hover:text-foreground"
|
| 72 |
+
onclick={handleClear}
|
| 73 |
+
aria-label={value ? 'Clear search' : 'Close'}
|
| 74 |
+
>
|
| 75 |
+
<X class="h-4 w-4" />
|
| 76 |
+
</button>
|
| 77 |
+
{/if}
|
| 78 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/forms/index.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
*
|
| 3 |
+
* FORMS & INPUTS
|
| 4 |
+
*
|
| 5 |
+
* Form-related utility components.
|
| 6 |
+
*
|
| 7 |
+
*/
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* **InputWithSuggestions** - Input field with autocomplete suggestions
|
| 11 |
+
*
|
| 12 |
+
* Text input with dropdown suggestions and keyboard navigation.
|
| 13 |
+
* Supports autocomplete functionality with suggestion loading.
|
| 14 |
+
*
|
| 15 |
+
* **Features:**
|
| 16 |
+
* - Autocomplete dropdown with suggestions
|
| 17 |
+
* - Keyboard navigation (arrow keys, enter)
|
| 18 |
+
* - Loading state for suggestions
|
| 19 |
+
* - Focus and blur handling
|
| 20 |
+
*/
|
| 21 |
+
export { default as InputWithSuggestions } from './InputWithSuggestions.svelte';
|
| 22 |
+
|
| 23 |
+
/**
|
| 24 |
+
* **KeyValuePairs** - Editable key-value list
|
| 25 |
+
*
|
| 26 |
+
* Dynamic list of key-value pairs with add/remove functionality.
|
| 27 |
+
* Used for HTTP headers, metadata, and configuration.
|
| 28 |
+
*
|
| 29 |
+
* **Features:**
|
| 30 |
+
* - Add new pairs with button
|
| 31 |
+
* - Remove individual pairs
|
| 32 |
+
* - Customizable placeholders and labels
|
| 33 |
+
* - Empty state message
|
| 34 |
+
* - Auto-resize value textarea
|
| 35 |
+
*/
|
| 36 |
+
export { default as KeyValuePairs } from './KeyValuePairs.svelte';
|
| 37 |
+
|
| 38 |
+
/**
|
| 39 |
+
* **SearchInput** - Search field with clear button
|
| 40 |
+
*
|
| 41 |
+
* Input field optimized for search with clear button and keyboard handling.
|
| 42 |
+
* Supports placeholder, autofocus, and change callbacks.
|
| 43 |
+
*/
|
| 44 |
+
export { default as SearchInput } from './SearchInput.svelte';
|
llama.cpp/tools/ui/src/lib/components/app/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export * from './actions';
|
| 2 |
+
export * from './badges';
|
| 3 |
+
export * from './chat';
|
| 4 |
+
export * from './content';
|
| 5 |
+
export * from './dialogs';
|
| 6 |
+
export * from './forms';
|
| 7 |
+
export * from './mcp';
|
| 8 |
+
export * from './misc';
|
| 9 |
+
export * from './settings';
|
| 10 |
+
export * from './models';
|
| 11 |
+
export * from './navigation';
|
| 12 |
+
export * from './server';
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpActiveServersAvatars.svelte
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import * as Tooltip from '$lib/components/ui/tooltip';
|
| 3 |
+
import { conversationsStore } from '$lib/stores/conversations.svelte';
|
| 4 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 5 |
+
import { HealthCheckStatus } from '$lib/enums';
|
| 6 |
+
import { MAX_DISPLAYED_MCP_AVATARS } from '$lib/constants';
|
| 7 |
+
import McpLogo from './McpLogo.svelte';
|
| 8 |
+
|
| 9 |
+
interface Props {
|
| 10 |
+
class?: string;
|
| 11 |
+
onclick?: () => void;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
let { class: className = '', onclick }: Props = $props();
|
| 15 |
+
|
| 16 |
+
let mcpServers = $derived(mcpStore.getServersSorted().filter((s) => s.enabled));
|
| 17 |
+
let enabledMcpServersForChat = $derived(
|
| 18 |
+
mcpServers.filter((s) => conversationsStore.isMcpServerEnabledForChat(s.id) && s.url.trim())
|
| 19 |
+
);
|
| 20 |
+
let healthyEnabledMcpServers = $derived(
|
| 21 |
+
enabledMcpServersForChat.filter((s) => {
|
| 22 |
+
const healthState = mcpStore.getHealthCheckState(s.id);
|
| 23 |
+
return healthState.status !== HealthCheckStatus.ERROR;
|
| 24 |
+
})
|
| 25 |
+
);
|
| 26 |
+
let hasEnabledMcpServers = $derived(enabledMcpServersForChat.length > 0);
|
| 27 |
+
let extraServersCount = $derived(
|
| 28 |
+
Math.max(0, healthyEnabledMcpServers.length - MAX_DISPLAYED_MCP_AVATARS)
|
| 29 |
+
);
|
| 30 |
+
let mcpFavicons = $derived(
|
| 31 |
+
healthyEnabledMcpServers
|
| 32 |
+
.slice(0, MAX_DISPLAYED_MCP_AVATARS)
|
| 33 |
+
.map((s) => ({
|
| 34 |
+
id: s.id,
|
| 35 |
+
name: mcpStore.getServerDisplayName(s.id),
|
| 36 |
+
url: mcpStore.getServerFavicon(s.id)
|
| 37 |
+
}))
|
| 38 |
+
.filter((f) => f.url !== null)
|
| 39 |
+
);
|
| 40 |
+
</script>
|
| 41 |
+
|
| 42 |
+
{#if !hasEnabledMcpServers}
|
| 43 |
+
<button
|
| 44 |
+
class={[
|
| 45 |
+
'inline-flex cursor-pointer items-center gap-0.75 opacity-70 transition-opacity hover:opacity-100',
|
| 46 |
+
className,
|
| 47 |
+
'opacity-50 hover:opacity-100'
|
| 48 |
+
]}
|
| 49 |
+
{onclick}
|
| 50 |
+
>
|
| 51 |
+
<Tooltip.Root>
|
| 52 |
+
<Tooltip.Trigger>
|
| 53 |
+
<McpLogo class="h-4 w-4" />
|
| 54 |
+
</Tooltip.Trigger>
|
| 55 |
+
|
| 56 |
+
<Tooltip.Content>
|
| 57 |
+
<p>MCP Servers</p>
|
| 58 |
+
</Tooltip.Content>
|
| 59 |
+
</Tooltip.Root>
|
| 60 |
+
</button>
|
| 61 |
+
{:else if mcpFavicons.length > 0}
|
| 62 |
+
<button class={['inline-flex items-center gap-0.75', className]} {onclick}>
|
| 63 |
+
<div class="flex -space-x-1">
|
| 64 |
+
{#each mcpFavicons as favicon (favicon.id)}
|
| 65 |
+
<Tooltip.Root>
|
| 66 |
+
<Tooltip.Trigger>
|
| 67 |
+
<div class="box-shadow-lg overflow-hidden rounded-full bg-muted ring-1 ring-muted">
|
| 68 |
+
<img
|
| 69 |
+
src={favicon.url}
|
| 70 |
+
alt=""
|
| 71 |
+
class="h-4 w-4"
|
| 72 |
+
onerror={(e) => {
|
| 73 |
+
(e.currentTarget as HTMLImageElement).style.display = 'none';
|
| 74 |
+
}}
|
| 75 |
+
/>
|
| 76 |
+
</div>
|
| 77 |
+
</Tooltip.Trigger>
|
| 78 |
+
<Tooltip.Content>
|
| 79 |
+
<p>{favicon.name}</p>
|
| 80 |
+
</Tooltip.Content>
|
| 81 |
+
</Tooltip.Root>
|
| 82 |
+
{/each}
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
{#if extraServersCount > 0}
|
| 86 |
+
<span class="text-xs text-muted-foreground">+{extraServersCount}</span>
|
| 87 |
+
{/if}
|
| 88 |
+
</button>
|
| 89 |
+
{/if}
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpCapabilitiesBadges.svelte
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Wrench, Database, MessageSquare, FileText, Sparkles, ListChecks } from '@lucide/svelte';
|
| 3 |
+
import type { MCPCapabilitiesInfo } from '$lib/types';
|
| 4 |
+
import { Badge } from '$lib/components/ui/badge';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
capabilities?: MCPCapabilitiesInfo;
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
let { capabilities }: Props = $props();
|
| 11 |
+
</script>
|
| 12 |
+
|
| 13 |
+
{#if capabilities}
|
| 14 |
+
{#if capabilities.server.tools}
|
| 15 |
+
<Badge variant="outline" class="h-5 gap-1 bg-green-50 px-1.5 text-[10px] dark:bg-green-950">
|
| 16 |
+
<Wrench class="h-3 w-3 text-green-600 dark:text-green-400" />
|
| 17 |
+
|
| 18 |
+
Tools
|
| 19 |
+
</Badge>
|
| 20 |
+
{/if}
|
| 21 |
+
|
| 22 |
+
{#if capabilities.server.resources}
|
| 23 |
+
<Badge variant="outline" class="h-5 gap-1 bg-blue-50 px-1.5 text-[10px] dark:bg-blue-950">
|
| 24 |
+
<Database class="h-3 w-3 text-blue-600 dark:text-blue-400" />
|
| 25 |
+
|
| 26 |
+
Resources
|
| 27 |
+
</Badge>
|
| 28 |
+
{/if}
|
| 29 |
+
|
| 30 |
+
{#if capabilities.server.prompts}
|
| 31 |
+
<Badge variant="outline" class="h-5 gap-1 bg-purple-50 px-1.5 text-[10px] dark:bg-purple-950">
|
| 32 |
+
<MessageSquare class="h-3 w-3 text-purple-600 dark:text-purple-400" />
|
| 33 |
+
|
| 34 |
+
Prompts
|
| 35 |
+
</Badge>
|
| 36 |
+
{/if}
|
| 37 |
+
|
| 38 |
+
{#if capabilities.server.logging}
|
| 39 |
+
<Badge variant="outline" class="h-5 gap-1 bg-orange-50 px-1.5 text-[10px] dark:bg-orange-950">
|
| 40 |
+
<FileText class="h-3 w-3 text-orange-600 dark:text-orange-400" />
|
| 41 |
+
|
| 42 |
+
Logging
|
| 43 |
+
</Badge>
|
| 44 |
+
{/if}
|
| 45 |
+
|
| 46 |
+
{#if capabilities.server.completions}
|
| 47 |
+
<Badge variant="outline" class="h-5 gap-1 bg-cyan-50 px-1.5 text-[10px] dark:bg-cyan-950">
|
| 48 |
+
<Sparkles class="h-3 w-3 text-cyan-600 dark:text-cyan-400" />
|
| 49 |
+
|
| 50 |
+
Completions
|
| 51 |
+
</Badge>
|
| 52 |
+
{/if}
|
| 53 |
+
|
| 54 |
+
{#if capabilities.server.tasks}
|
| 55 |
+
<Badge variant="outline" class="h-5 gap-1 bg-pink-50 px-1.5 text-[10px] dark:bg-pink-950">
|
| 56 |
+
<ListChecks class="h-3 w-3 text-pink-600 dark:text-pink-400" />
|
| 57 |
+
|
| 58 |
+
Tasks
|
| 59 |
+
</Badge>
|
| 60 |
+
{/if}
|
| 61 |
+
{/if}
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpConnectionLogs.svelte
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { ChevronDown, ChevronRight } from '@lucide/svelte';
|
| 3 |
+
import * as Collapsible from '$lib/components/ui/collapsible';
|
| 4 |
+
import type { MCPConnectionLog } from '$lib/types';
|
| 5 |
+
import { formatTime, getMcpLogLevelIcon, getMcpLogLevelClass } from '$lib/utils';
|
| 6 |
+
|
| 7 |
+
interface Props {
|
| 8 |
+
logs: MCPConnectionLog[];
|
| 9 |
+
connectionTimeMs?: number;
|
| 10 |
+
defaultExpanded?: boolean;
|
| 11 |
+
class?: string;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
let { logs, connectionTimeMs, defaultExpanded = false, class: className }: Props = $props();
|
| 15 |
+
|
| 16 |
+
let isExpanded = $derived(defaultExpanded);
|
| 17 |
+
|
| 18 |
+
function formatLogDetails(details: unknown): string {
|
| 19 |
+
if (details == null) {
|
| 20 |
+
return '';
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
try {
|
| 24 |
+
return JSON.stringify(details, null, 2);
|
| 25 |
+
} catch {
|
| 26 |
+
return String(details);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
</script>
|
| 30 |
+
|
| 31 |
+
{#if logs.length > 0}
|
| 32 |
+
<Collapsible.Root bind:open={isExpanded} class={className}>
|
| 33 |
+
<div class="space-y-2">
|
| 34 |
+
<Collapsible.Trigger
|
| 35 |
+
class="flex w-full items-center gap-1 text-xs text-muted-foreground hover:text-foreground"
|
| 36 |
+
>
|
| 37 |
+
{#if isExpanded}
|
| 38 |
+
<ChevronDown class="h-3.5 w-3.5" />
|
| 39 |
+
{:else}
|
| 40 |
+
<ChevronRight class="h-3.5 w-3.5" />
|
| 41 |
+
{/if}
|
| 42 |
+
|
| 43 |
+
<span>Connection Log ({logs.length})</span>
|
| 44 |
+
|
| 45 |
+
{#if connectionTimeMs !== undefined}
|
| 46 |
+
<span class="ml-1">· Connected in {connectionTimeMs}ms</span>
|
| 47 |
+
{/if}
|
| 48 |
+
</Collapsible.Trigger>
|
| 49 |
+
</div>
|
| 50 |
+
|
| 51 |
+
<Collapsible.Content class="mt-2">
|
| 52 |
+
<div
|
| 53 |
+
class="max-h-64 space-y-0.5 overflow-y-auto rounded bg-muted/50 p-2 font-mono text-[10px]"
|
| 54 |
+
>
|
| 55 |
+
{#each logs as log (log.timestamp.getTime() + log.message)}
|
| 56 |
+
{@const IconComponent = getMcpLogLevelIcon(log.level)}
|
| 57 |
+
|
| 58 |
+
<div class={['flex items-start gap-1.5', getMcpLogLevelClass(log.level)]}>
|
| 59 |
+
<span class="shrink-0 text-muted-foreground">
|
| 60 |
+
{formatTime(log.timestamp)}
|
| 61 |
+
</span>
|
| 62 |
+
|
| 63 |
+
<IconComponent class="mt-0.5 h-3 w-3 shrink-0" />
|
| 64 |
+
|
| 65 |
+
<span class="break-all">{log.message}</span>
|
| 66 |
+
</div>
|
| 67 |
+
|
| 68 |
+
{#if log.details !== undefined}
|
| 69 |
+
<details class="ml-11">
|
| 70 |
+
<summary class="cursor-pointer text-[10px] text-muted-foreground"> details </summary>
|
| 71 |
+
|
| 72 |
+
<pre
|
| 73 |
+
class="mt-1 overflow-x-auto rounded bg-background/70 p-2 text-[10px] break-all whitespace-pre-wrap text-foreground/80">
|
| 74 |
+
{formatLogDetails(log.details)}</pre>
|
| 75 |
+
</details>
|
| 76 |
+
{/if}
|
| 77 |
+
{/each}
|
| 78 |
+
</div>
|
| 79 |
+
</Collapsible.Content>
|
| 80 |
+
</Collapsible.Root>
|
| 81 |
+
{/if}
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpLogo.svelte
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script>
|
| 2 |
+
let { class: className = '', style = '' } = $props();
|
| 3 |
+
</script>
|
| 4 |
+
|
| 5 |
+
<svg
|
| 6 |
+
class={className}
|
| 7 |
+
{style}
|
| 8 |
+
xmlns="http://www.w3.org/2000/svg"
|
| 9 |
+
viewBox="0 0 174 174"
|
| 10 |
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
| 11 |
+
fill="none"
|
| 12 |
+
version="1.1"
|
| 13 |
+
><g id="shape-320b5b95-d08d-8089-8007-585a8e498184"
|
| 14 |
+
><defs
|
| 15 |
+
><clipPath
|
| 16 |
+
id="frame-clip-320b5b95-d08d-8089-8007-585a8e498184-render-1"
|
| 17 |
+
class="frame-clip frame-clip-def"
|
| 18 |
+
><rect
|
| 19 |
+
rx="0"
|
| 20 |
+
ry="0"
|
| 21 |
+
x="0"
|
| 22 |
+
y="0"
|
| 23 |
+
width="174.00000000000045"
|
| 24 |
+
height="174"
|
| 25 |
+
transform="matrix(1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000)"
|
| 26 |
+
/></clipPath
|
| 27 |
+
></defs
|
| 28 |
+
><g class="frame-container-wrapper"
|
| 29 |
+
><g class="frame-container-blur"
|
| 30 |
+
><g class="frame-container-shadows"
|
| 31 |
+
><g clip-path="url(#frame-clip-320b5b95-d08d-8089-8007-585a8e498184-render-1)" fill="none"
|
| 32 |
+
><g class="fills" id="fills-320b5b95-d08d-8089-8007-585a8e498184"
|
| 33 |
+
><rect
|
| 34 |
+
rx="0"
|
| 35 |
+
ry="0"
|
| 36 |
+
x="0"
|
| 37 |
+
y="0"
|
| 38 |
+
width="174.00000000000045"
|
| 39 |
+
height="174"
|
| 40 |
+
transform="matrix(1.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000)"
|
| 41 |
+
class="frame-background"
|
| 42 |
+
/></g
|
| 43 |
+
><g class="frame-children"
|
| 44 |
+
><g id="shape-320b5b95-d08d-8089-8007-585a974337b1"
|
| 45 |
+
><g class="fills" id="fills-320b5b95-d08d-8089-8007-585a974337b1"
|
| 46 |
+
><path
|
| 47 |
+
d="M15.5587158203125,81.5927734375L83.44091796875,13.7105712890625C92.813720703125,4.3380126953125,108.0096435546875,4.3380126953125,117.3817138671875,13.7105712890625L117.3817138671875,13.7105712890625C126.7547607421875,23.08306884765625,126.7547607421875,38.27911376953125,117.3817138671875,47.65167236328125L66.1168212890625,98.9169921875"
|
| 48 |
+
fill="none"
|
| 49 |
+
stroke-linecap="round"
|
| 50 |
+
style="fill: none;"
|
| 51 |
+
/></g
|
| 52 |
+
><g
|
| 53 |
+
fill="none"
|
| 54 |
+
stroke-linecap="round"
|
| 55 |
+
id="strokes-b954dcef-3e3e-8015-8007-585acd4382b6-320b5b95-d08d-8089-8007-585a974337b1"
|
| 56 |
+
class="strokes"
|
| 57 |
+
><g class="stroke-shape"
|
| 58 |
+
><path
|
| 59 |
+
d="M15.5587158203125,81.5927734375L83.44091796875,13.7105712890625C92.813720703125,4.3380126953125,108.0096435546875,4.3380126953125,117.3817138671875,13.7105712890625L117.3817138671875,13.7105712890625C126.7547607421875,23.08306884765625,126.7547607421875,38.27911376953125,117.3817138671875,47.65167236328125L66.1168212890625,98.9169921875"
|
| 60 |
+
style="fill: none; stroke-width: 12; stroke: currentColor; stroke-opacity: 1;"
|
| 61 |
+
/></g
|
| 62 |
+
></g
|
| 63 |
+
></g
|
| 64 |
+
><g id="shape-320b5b95-d08d-8089-8007-585a974337b2"
|
| 65 |
+
><g class="fills" id="fills-320b5b95-d08d-8089-8007-585a974337b2"
|
| 66 |
+
><path
|
| 67 |
+
d="M66.5587158203125,98.26885986328125L117.1165771484375,47.7105712890625C126.489501953125,38.3380126953125,141.6854248046875,38.3380126953125,151.0584716796875,47.7105712890625L151.4114990234375,48.0640869140625C160.7845458984375,57.43670654296875,160.7845458984375,72.6326904296875,151.4114990234375,82.00518798828125L90.018310546875,143.39886474609375C86.8941650390625,146.52288818359375,86.8941650390625,151.587890625,90.018310546875,154.71185302734375L102.62451171875,167.31890869140625"
|
| 68 |
+
fill="none"
|
| 69 |
+
stroke-linecap="round"
|
| 70 |
+
style="fill: none;"
|
| 71 |
+
/></g
|
| 72 |
+
><g
|
| 73 |
+
fill="none"
|
| 74 |
+
stroke-linecap="round"
|
| 75 |
+
id="strokes-b954dcef-3e3e-8015-8007-585acd447743-320b5b95-d08d-8089-8007-585a974337b2"
|
| 76 |
+
class="strokes"
|
| 77 |
+
><g class="stroke-shape"
|
| 78 |
+
><path
|
| 79 |
+
d="M66.5587158203125,98.26885986328125L117.1165771484375,47.7105712890625C126.489501953125,38.3380126953125,141.6854248046875,38.3380126953125,151.0584716796875,47.7105712890625L151.4114990234375,48.0640869140625C160.7845458984375,57.43670654296875,160.7845458984375,72.6326904296875,151.4114990234375,82.00518798828125L90.018310546875,143.39886474609375C86.8941650390625,146.52288818359375,86.8941650390625,151.587890625,90.018310546875,154.71185302734375L102.62451171875,167.31890869140625"
|
| 80 |
+
style="fill: none; stroke-width: 12; stroke: currentColor; stroke-opacity: 1;"
|
| 81 |
+
/></g
|
| 82 |
+
></g
|
| 83 |
+
></g
|
| 84 |
+
><g id="shape-320b5b95-d08d-8089-8007-585a974337b3"
|
| 85 |
+
><g class="fills" id="fills-320b5b95-d08d-8089-8007-585a974337b3"
|
| 86 |
+
><path
|
| 87 |
+
d="M99.79296875,30.68115234375L49.588134765625,80.8857421875C40.215576171875,90.258056640625,40.215576171875,105.45404052734375,49.588134765625,114.82708740234375L49.588134765625,114.82708740234375C58.9608154296875,124.19903564453125,74.1566162109375,124.19903564453125,83.529296875,114.82708740234375L133.7340087890625,64.62225341796875"
|
| 88 |
+
fill="none"
|
| 89 |
+
stroke-linecap="round"
|
| 90 |
+
style="fill: none;"
|
| 91 |
+
/></g
|
| 92 |
+
><g
|
| 93 |
+
fill="none"
|
| 94 |
+
stroke-linecap="round"
|
| 95 |
+
id="strokes-b954dcef-3e3e-8015-8007-585acd44c5c9-320b5b95-d08d-8089-8007-585a974337b3"
|
| 96 |
+
class="strokes"
|
| 97 |
+
><g class="stroke-shape"
|
| 98 |
+
><path
|
| 99 |
+
d="M99.79296875,30.68115234375L49.588134765625,80.8857421875C40.215576171875,90.258056640625,40.215576171875,105.45404052734375,49.588134765625,114.82708740234375L49.588134765625,114.82708740234375C58.9608154296875,124.19903564453125,74.1566162109375,124.19903564453125,83.529296875,114.82708740234375L133.7340087890625,64.62225341796875"
|
| 100 |
+
style="fill: none; stroke-width: 12; stroke: currentColor; stroke-opacity: 1;"
|
| 101 |
+
/></g
|
| 102 |
+
></g
|
| 103 |
+
></g
|
| 104 |
+
></g
|
| 105 |
+
></g
|
| 106 |
+
></g
|
| 107 |
+
></g
|
| 108 |
+
></g
|
| 109 |
+
></g
|
| 110 |
+
></svg
|
| 111 |
+
>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcePreview.svelte
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { FileText, Loader2, AlertCircle, Download } from '@lucide/svelte';
|
| 3 |
+
import { Button } from '$lib/components/ui/button';
|
| 4 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 5 |
+
import {
|
| 6 |
+
isImageMimeType,
|
| 7 |
+
createBase64DataUrl,
|
| 8 |
+
getResourceTextContent,
|
| 9 |
+
getResourceBlobContent,
|
| 10 |
+
downloadResourceContent
|
| 11 |
+
} from '$lib/utils';
|
| 12 |
+
import { MimeTypeApplication, MimeTypeText } from '$lib/enums';
|
| 13 |
+
import { ActionIconCopyToClipboard } from '$lib/components/app';
|
| 14 |
+
import type { MCPResourceInfo, MCPResourceContent } from '$lib/types';
|
| 15 |
+
|
| 16 |
+
interface Props {
|
| 17 |
+
resource: MCPResourceInfo | null;
|
| 18 |
+
/** Pre-loaded content (e.g., from template resolution). Skips store fetch when provided. */
|
| 19 |
+
preloadedContent?: MCPResourceContent[] | null;
|
| 20 |
+
class?: string;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
let { resource, preloadedContent, class: className }: Props = $props();
|
| 24 |
+
|
| 25 |
+
let content = $state<MCPResourceContent[] | null>(null);
|
| 26 |
+
let isLoading = $state(false);
|
| 27 |
+
let error = $state<string | null>(null);
|
| 28 |
+
|
| 29 |
+
$effect(() => {
|
| 30 |
+
if (resource) {
|
| 31 |
+
if (preloadedContent) {
|
| 32 |
+
content = preloadedContent;
|
| 33 |
+
isLoading = false;
|
| 34 |
+
error = null;
|
| 35 |
+
} else {
|
| 36 |
+
loadContent(resource.uri);
|
| 37 |
+
}
|
| 38 |
+
} else {
|
| 39 |
+
content = null;
|
| 40 |
+
error = null;
|
| 41 |
+
}
|
| 42 |
+
});
|
| 43 |
+
|
| 44 |
+
async function loadContent(uri: string) {
|
| 45 |
+
isLoading = true;
|
| 46 |
+
error = null;
|
| 47 |
+
|
| 48 |
+
try {
|
| 49 |
+
const result = await mcpStore.readResource(uri);
|
| 50 |
+
if (result) {
|
| 51 |
+
content = result;
|
| 52 |
+
} else {
|
| 53 |
+
error = 'Failed to load resource content';
|
| 54 |
+
}
|
| 55 |
+
} catch (e) {
|
| 56 |
+
error = e instanceof Error ? e.message : 'Unknown error';
|
| 57 |
+
} finally {
|
| 58 |
+
isLoading = false;
|
| 59 |
+
}
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
function handleDownload() {
|
| 63 |
+
const text = getResourceTextContent(content);
|
| 64 |
+
if (!text || !resource) return;
|
| 65 |
+
downloadResourceContent(
|
| 66 |
+
text,
|
| 67 |
+
resource.mimeType || MimeTypeText.PLAIN,
|
| 68 |
+
resource.name || 'resource.txt'
|
| 69 |
+
);
|
| 70 |
+
}
|
| 71 |
+
</script>
|
| 72 |
+
|
| 73 |
+
<div class={['flex flex-col gap-3', className]}>
|
| 74 |
+
{#if !resource}
|
| 75 |
+
<div class="flex flex-col items-center justify-center gap-2 py-8 text-muted-foreground">
|
| 76 |
+
<FileText class="h-8 w-8 opacity-50" />
|
| 77 |
+
|
| 78 |
+
<span class="text-sm">Select a resource to preview</span>
|
| 79 |
+
</div>
|
| 80 |
+
{:else}
|
| 81 |
+
<div class="flex items-start justify-between gap-2">
|
| 82 |
+
<div class="min-w-0 flex-1">
|
| 83 |
+
<h3 class="truncate font-medium">{resource.title || resource.name}</h3>
|
| 84 |
+
|
| 85 |
+
<p class="truncate text-xs text-muted-foreground">{resource.uri}</p>
|
| 86 |
+
|
| 87 |
+
{#if resource.description}
|
| 88 |
+
<p class="mt-1 text-sm text-muted-foreground">{resource.description}</p>
|
| 89 |
+
{/if}
|
| 90 |
+
</div>
|
| 91 |
+
|
| 92 |
+
<div class="flex items-center gap-1">
|
| 93 |
+
<ActionIconCopyToClipboard
|
| 94 |
+
text={getResourceTextContent(content)}
|
| 95 |
+
canCopy={!isLoading && !!getResourceTextContent(content)}
|
| 96 |
+
ariaLabel="Copy content"
|
| 97 |
+
/>
|
| 98 |
+
|
| 99 |
+
<Button
|
| 100 |
+
variant="ghost"
|
| 101 |
+
size="sm"
|
| 102 |
+
class="h-7 w-7 p-0"
|
| 103 |
+
onclick={handleDownload}
|
| 104 |
+
disabled={isLoading || !getResourceTextContent(content)}
|
| 105 |
+
title="Download content"
|
| 106 |
+
>
|
| 107 |
+
<Download class="h-3.5 w-3.5" />
|
| 108 |
+
</Button>
|
| 109 |
+
</div>
|
| 110 |
+
</div>
|
| 111 |
+
|
| 112 |
+
<div class="min-h-[200px] overflow-auto rounded-md border bg-muted/30 p-3 break-all">
|
| 113 |
+
{#if isLoading}
|
| 114 |
+
<div class="flex items-center justify-center py-8">
|
| 115 |
+
<Loader2 class="h-6 w-6 animate-spin text-muted-foreground" />
|
| 116 |
+
</div>
|
| 117 |
+
{:else if error}
|
| 118 |
+
<div class="flex flex-col items-center justify-center gap-2 py-8 text-red-500">
|
| 119 |
+
<AlertCircle class="h-6 w-6" />
|
| 120 |
+
|
| 121 |
+
<span class="text-sm">{error}</span>
|
| 122 |
+
</div>
|
| 123 |
+
{:else if content}
|
| 124 |
+
{@const textContent = getResourceTextContent(content)}
|
| 125 |
+
{@const blobContent = getResourceBlobContent(content)}
|
| 126 |
+
|
| 127 |
+
{#if textContent}
|
| 128 |
+
<pre class="font-mono text-xs break-words whitespace-pre-wrap">{textContent}</pre>
|
| 129 |
+
{/if}
|
| 130 |
+
|
| 131 |
+
{#each blobContent as blob (blob.uri)}
|
| 132 |
+
{#if isImageMimeType(blob.mimeType ?? MimeTypeApplication.OCTET_STREAM)}
|
| 133 |
+
<img
|
| 134 |
+
src={createBase64DataUrl(
|
| 135 |
+
blob.mimeType ?? MimeTypeApplication.OCTET_STREAM,
|
| 136 |
+
blob.blob
|
| 137 |
+
)}
|
| 138 |
+
alt="Resource content"
|
| 139 |
+
class="max-w-full rounded"
|
| 140 |
+
/>
|
| 141 |
+
{:else}
|
| 142 |
+
<div class="flex items-center gap-2 rounded bg-muted p-2 text-sm text-muted-foreground">
|
| 143 |
+
<FileText class="h-4 w-4" />
|
| 144 |
+
|
| 145 |
+
<span>Binary content ({blob.mimeType || 'unknown type'})</span>
|
| 146 |
+
</div>
|
| 147 |
+
{/if}
|
| 148 |
+
{/each}
|
| 149 |
+
|
| 150 |
+
{#if !textContent && blobContent.length === 0}
|
| 151 |
+
<div class="py-4 text-center text-sm text-muted-foreground">No content available</div>
|
| 152 |
+
{/if}
|
| 153 |
+
{/if}
|
| 154 |
+
</div>
|
| 155 |
+
|
| 156 |
+
{#if resource.mimeType || resource.annotations}
|
| 157 |
+
<div class="flex flex-wrap gap-2 text-xs text-muted-foreground">
|
| 158 |
+
{#if resource.mimeType}
|
| 159 |
+
<span class="rounded bg-muted px-1.5 py-0.5">{resource.mimeType}</span>
|
| 160 |
+
{/if}
|
| 161 |
+
|
| 162 |
+
{#if resource.annotations?.priority !== undefined}
|
| 163 |
+
<span class="rounded bg-muted px-1.5 py-0.5">
|
| 164 |
+
Priority: {resource.annotations.priority}
|
| 165 |
+
</span>
|
| 166 |
+
{/if}
|
| 167 |
+
|
| 168 |
+
<span class="rounded bg-muted px-1.5 py-0.5">
|
| 169 |
+
Server: {resource.serverName}
|
| 170 |
+
</span>
|
| 171 |
+
</div>
|
| 172 |
+
{/if}
|
| 173 |
+
{/if}
|
| 174 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourceTemplateForm.svelte
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { Button } from '$lib/components/ui/button';
|
| 3 |
+
import { InputWithSuggestions } from '$lib/components/app';
|
| 4 |
+
import { KeyboardKey } from '$lib/enums';
|
| 5 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 6 |
+
import { MIN_AUTOCOMPLETE_INPUT_LENGTH } from '$lib/constants';
|
| 7 |
+
import type { MCPResourceTemplateInfo } from '$lib/types';
|
| 8 |
+
import {
|
| 9 |
+
debounce,
|
| 10 |
+
extractTemplateVariables,
|
| 11 |
+
expandTemplate,
|
| 12 |
+
isTemplateComplete
|
| 13 |
+
} from '$lib/utils';
|
| 14 |
+
|
| 15 |
+
interface Props {
|
| 16 |
+
template: MCPResourceTemplateInfo;
|
| 17 |
+
onResolve: (uri: string, serverName: string) => void;
|
| 18 |
+
onCancel: () => void;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
let { template, onResolve, onCancel }: Props = $props();
|
| 22 |
+
|
| 23 |
+
const variables = $derived(extractTemplateVariables(template.uriTemplate));
|
| 24 |
+
|
| 25 |
+
let values = $state<Record<string, string>>({});
|
| 26 |
+
let suggestions = $state<Record<string, string[]>>({});
|
| 27 |
+
let loadingSuggestions = $state<Record<string, boolean>>({});
|
| 28 |
+
let activeAutocomplete = $state<string | null>(null);
|
| 29 |
+
let autocompleteIndex = $state(0);
|
| 30 |
+
|
| 31 |
+
const expandedUri = $derived(expandTemplate(template.uriTemplate, values));
|
| 32 |
+
const isComplete = $derived(isTemplateComplete(template.uriTemplate, values));
|
| 33 |
+
|
| 34 |
+
const fetchCompletions = debounce(async (argName: string, value: string) => {
|
| 35 |
+
if (value.length < 1) {
|
| 36 |
+
suggestions[argName] = [];
|
| 37 |
+
|
| 38 |
+
return;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
loadingSuggestions[argName] = true;
|
| 42 |
+
|
| 43 |
+
try {
|
| 44 |
+
const result = await mcpStore.getResourceCompletions(
|
| 45 |
+
template.serverName,
|
| 46 |
+
template.uriTemplate,
|
| 47 |
+
argName,
|
| 48 |
+
value
|
| 49 |
+
);
|
| 50 |
+
|
| 51 |
+
if (result && result.values.length > 0) {
|
| 52 |
+
const filteredValues = result.values.filter((v) => v.trim() !== '');
|
| 53 |
+
|
| 54 |
+
if (filteredValues.length > 0) {
|
| 55 |
+
suggestions[argName] = filteredValues;
|
| 56 |
+
activeAutocomplete = argName;
|
| 57 |
+
autocompleteIndex = 0;
|
| 58 |
+
} else {
|
| 59 |
+
suggestions[argName] = [];
|
| 60 |
+
}
|
| 61 |
+
} else {
|
| 62 |
+
suggestions[argName] = [];
|
| 63 |
+
}
|
| 64 |
+
} catch (error) {
|
| 65 |
+
console.error('[McpResourceTemplateForm] Failed to fetch completions:', error);
|
| 66 |
+
suggestions[argName] = [];
|
| 67 |
+
} finally {
|
| 68 |
+
loadingSuggestions[argName] = false;
|
| 69 |
+
}
|
| 70 |
+
}, 200);
|
| 71 |
+
|
| 72 |
+
function handleArgInput(argName: string, value: string) {
|
| 73 |
+
values[argName] = value;
|
| 74 |
+
fetchCompletions(argName, value);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
function selectSuggestion(argName: string, value: string) {
|
| 78 |
+
values[argName] = value;
|
| 79 |
+
suggestions[argName] = [];
|
| 80 |
+
activeAutocomplete = null;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
function handleArgKeydown(event: KeyboardEvent, argName: string) {
|
| 84 |
+
const argSuggestions = suggestions[argName] ?? [];
|
| 85 |
+
|
| 86 |
+
if (event.key === KeyboardKey.ESCAPE) {
|
| 87 |
+
event.preventDefault();
|
| 88 |
+
event.stopPropagation();
|
| 89 |
+
|
| 90 |
+
if (argSuggestions.length > 0 && activeAutocomplete === argName) {
|
| 91 |
+
suggestions[argName] = [];
|
| 92 |
+
activeAutocomplete = null;
|
| 93 |
+
} else {
|
| 94 |
+
onCancel();
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
return;
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
if (argSuggestions.length === 0 || activeAutocomplete !== argName) return;
|
| 101 |
+
|
| 102 |
+
if (event.key === KeyboardKey.ARROW_DOWN) {
|
| 103 |
+
event.preventDefault();
|
| 104 |
+
autocompleteIndex = Math.min(autocompleteIndex + 1, argSuggestions.length - 1);
|
| 105 |
+
} else if (event.key === KeyboardKey.ARROW_UP) {
|
| 106 |
+
event.preventDefault();
|
| 107 |
+
autocompleteIndex = Math.max(autocompleteIndex - 1, 0);
|
| 108 |
+
} else if (event.key === KeyboardKey.ENTER && argSuggestions[autocompleteIndex]) {
|
| 109 |
+
event.preventDefault();
|
| 110 |
+
event.stopPropagation();
|
| 111 |
+
selectSuggestion(argName, argSuggestions[autocompleteIndex]);
|
| 112 |
+
}
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
function handleArgBlur(argName: string) {
|
| 116 |
+
setTimeout(() => {
|
| 117 |
+
if (activeAutocomplete === argName) {
|
| 118 |
+
suggestions[argName] = [];
|
| 119 |
+
activeAutocomplete = null;
|
| 120 |
+
}
|
| 121 |
+
}, 150);
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
function handleArgFocus(argName: string) {
|
| 125 |
+
const value = values[argName] ?? '';
|
| 126 |
+
|
| 127 |
+
if (value.length >= MIN_AUTOCOMPLETE_INPUT_LENGTH) {
|
| 128 |
+
fetchCompletions(argName, value);
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
function handleSubmit(event: SubmitEvent) {
|
| 133 |
+
event.preventDefault();
|
| 134 |
+
|
| 135 |
+
if (isComplete) {
|
| 136 |
+
onResolve(expandedUri, template.serverName);
|
| 137 |
+
}
|
| 138 |
+
}
|
| 139 |
+
</script>
|
| 140 |
+
|
| 141 |
+
<form onsubmit={handleSubmit} class="space-y-3">
|
| 142 |
+
{#each variables as variable (variable.name)}
|
| 143 |
+
<InputWithSuggestions
|
| 144 |
+
name={variable.name}
|
| 145 |
+
value={values[variable.name] ?? ''}
|
| 146 |
+
suggestions={suggestions[variable.name] ?? []}
|
| 147 |
+
isLoadingSuggestions={loadingSuggestions[variable.name] ?? false}
|
| 148 |
+
isAutocompleteActive={activeAutocomplete === variable.name}
|
| 149 |
+
autocompleteIndex={activeAutocomplete === variable.name ? autocompleteIndex : 0}
|
| 150 |
+
onInput={(value) => handleArgInput(variable.name, value)}
|
| 151 |
+
onKeydown={(e) => handleArgKeydown(e, variable.name)}
|
| 152 |
+
onBlur={() => handleArgBlur(variable.name)}
|
| 153 |
+
onFocus={() => handleArgFocus(variable.name)}
|
| 154 |
+
onSelectSuggestion={(value) => selectSuggestion(variable.name, value)}
|
| 155 |
+
/>
|
| 156 |
+
{/each}
|
| 157 |
+
|
| 158 |
+
{#if isComplete}
|
| 159 |
+
<div class="rounded-md bg-muted/50 px-3 py-2">
|
| 160 |
+
<p class="text-xs text-muted-foreground">Resolved URI:</p>
|
| 161 |
+
|
| 162 |
+
<p class="mt-0.5 font-mono text-xs break-all">{expandedUri}</p>
|
| 163 |
+
</div>
|
| 164 |
+
{/if}
|
| 165 |
+
|
| 166 |
+
<div class="flex justify-end gap-2 pt-1">
|
| 167 |
+
<Button type="button" size="sm" variant="secondary" onclick={onCancel}>Cancel</Button>
|
| 168 |
+
|
| 169 |
+
<Button size="sm" type="submit" disabled={!isComplete}>Read Resource</Button>
|
| 170 |
+
</div>
|
| 171 |
+
</form>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowser.svelte
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 3 |
+
import { mcpResources, mcpResourcesLoading } from '$lib/stores/mcp-resources.svelte';
|
| 4 |
+
import type { MCPServerResources, MCPResourceInfo, MCPResourceTemplateInfo } from '$lib/types';
|
| 5 |
+
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
| 6 |
+
import { parseResourcePath } from '$lib/utils';
|
| 7 |
+
import McpResourcesBrowserHeader from './McpResourcesBrowserHeader.svelte';
|
| 8 |
+
import McpResourcesBrowserEmptyState from './McpResourcesBrowserEmptyState.svelte';
|
| 9 |
+
import McpResourcesBrowserServerItem from './McpResourcesBrowserServerItem.svelte';
|
| 10 |
+
|
| 11 |
+
interface Props {
|
| 12 |
+
onSelect?: (resource: MCPResourceInfo, shiftKey?: boolean) => void;
|
| 13 |
+
onToggle?: (resource: MCPResourceInfo, checked: boolean) => void;
|
| 14 |
+
onTemplateSelect?: (template: MCPResourceTemplateInfo) => void;
|
| 15 |
+
selectedUris?: Set<string>;
|
| 16 |
+
selectedTemplateUri?: string | null;
|
| 17 |
+
expandToUri?: string;
|
| 18 |
+
class?: string;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
let {
|
| 22 |
+
onSelect,
|
| 23 |
+
onToggle,
|
| 24 |
+
onTemplateSelect,
|
| 25 |
+
selectedUris = new Set(),
|
| 26 |
+
selectedTemplateUri,
|
| 27 |
+
expandToUri,
|
| 28 |
+
class: className
|
| 29 |
+
}: Props = $props();
|
| 30 |
+
|
| 31 |
+
let expandedServers = new SvelteSet<string>();
|
| 32 |
+
let expandedFolders = new SvelteSet<string>();
|
| 33 |
+
let searchQuery = $state('');
|
| 34 |
+
|
| 35 |
+
const resources = $derived(mcpResources());
|
| 36 |
+
const isLoading = $derived(mcpResourcesLoading());
|
| 37 |
+
|
| 38 |
+
const filteredResources = $derived.by(() => {
|
| 39 |
+
if (!searchQuery.trim()) {
|
| 40 |
+
return resources;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
const query = searchQuery.toLowerCase();
|
| 44 |
+
const filtered = new SvelteMap();
|
| 45 |
+
|
| 46 |
+
for (const [serverName, serverRes] of resources.entries()) {
|
| 47 |
+
const filteredResources = serverRes.resources.filter((r) => {
|
| 48 |
+
return (
|
| 49 |
+
r.title?.toLowerCase().includes(query) ||
|
| 50 |
+
r.uri.toLowerCase().includes(query) ||
|
| 51 |
+
serverName.toLowerCase().includes(query)
|
| 52 |
+
);
|
| 53 |
+
});
|
| 54 |
+
|
| 55 |
+
const filteredTemplates = serverRes.templates.filter((t) => {
|
| 56 |
+
return (
|
| 57 |
+
t.name?.toLowerCase().includes(query) ||
|
| 58 |
+
t.title?.toLowerCase().includes(query) ||
|
| 59 |
+
t.uriTemplate.toLowerCase().includes(query) ||
|
| 60 |
+
serverName.toLowerCase().includes(query)
|
| 61 |
+
);
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
if (filteredResources.length > 0 || filteredTemplates.length > 0 || query.trim()) {
|
| 65 |
+
filtered.set(serverName, {
|
| 66 |
+
...serverRes,
|
| 67 |
+
resources: filteredResources,
|
| 68 |
+
templates: filteredTemplates
|
| 69 |
+
});
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
return filtered;
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
$effect(() => {
|
| 77 |
+
if (expandToUri && resources.size > 0) {
|
| 78 |
+
autoExpandToResource(expandToUri);
|
| 79 |
+
}
|
| 80 |
+
});
|
| 81 |
+
|
| 82 |
+
function autoExpandToResource(uri: string) {
|
| 83 |
+
for (const [serverName, serverRes] of resources.entries()) {
|
| 84 |
+
const resource = serverRes.resources.find((r) => r.uri === uri);
|
| 85 |
+
if (resource) {
|
| 86 |
+
expandedServers.add(serverName);
|
| 87 |
+
|
| 88 |
+
const pathParts = parseResourcePath(uri);
|
| 89 |
+
if (pathParts.length > 1) {
|
| 90 |
+
let currentPath = '';
|
| 91 |
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
| 92 |
+
currentPath = `${currentPath}/${pathParts[i]}`;
|
| 93 |
+
const folderId = `${serverName}:${currentPath}`;
|
| 94 |
+
expandedFolders.add(folderId);
|
| 95 |
+
}
|
| 96 |
+
}
|
| 97 |
+
break;
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
function toggleServer(serverName: string) {
|
| 103 |
+
if (expandedServers.has(serverName)) {
|
| 104 |
+
expandedServers.delete(serverName);
|
| 105 |
+
} else {
|
| 106 |
+
expandedServers.add(serverName);
|
| 107 |
+
}
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
function toggleFolder(folderId: string) {
|
| 111 |
+
if (expandedFolders.has(folderId)) {
|
| 112 |
+
expandedFolders.delete(folderId);
|
| 113 |
+
} else {
|
| 114 |
+
expandedFolders.add(folderId);
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
function handleRefresh() {
|
| 119 |
+
mcpStore.fetchAllResources();
|
| 120 |
+
}
|
| 121 |
+
</script>
|
| 122 |
+
|
| 123 |
+
<div class={['flex flex-col gap-2', className]}>
|
| 124 |
+
<McpResourcesBrowserHeader
|
| 125 |
+
{isLoading}
|
| 126 |
+
onRefresh={handleRefresh}
|
| 127 |
+
onSearch={(q) => (searchQuery = q)}
|
| 128 |
+
{searchQuery}
|
| 129 |
+
/>
|
| 130 |
+
|
| 131 |
+
<div class="flex flex-col gap-1">
|
| 132 |
+
{#if filteredResources.size === 0}
|
| 133 |
+
<McpResourcesBrowserEmptyState {isLoading} />
|
| 134 |
+
{:else}
|
| 135 |
+
{#each [...filteredResources.entries()] as [serverName, serverRes] (serverName)}
|
| 136 |
+
<McpResourcesBrowserServerItem
|
| 137 |
+
serverName={serverName as string}
|
| 138 |
+
serverRes={serverRes as MCPServerResources}
|
| 139 |
+
isExpanded={expandedServers.has(serverName as string)}
|
| 140 |
+
{selectedUris}
|
| 141 |
+
{selectedTemplateUri}
|
| 142 |
+
{expandedFolders}
|
| 143 |
+
onToggleServer={() => toggleServer(serverName as string)}
|
| 144 |
+
onToggleFolder={toggleFolder}
|
| 145 |
+
{onSelect}
|
| 146 |
+
{onToggle}
|
| 147 |
+
{onTemplateSelect}
|
| 148 |
+
{searchQuery}
|
| 149 |
+
/>
|
| 150 |
+
{/each}
|
| 151 |
+
{/if}
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowserEmptyState.svelte
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
interface Props {
|
| 3 |
+
isLoading: boolean;
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
let { isLoading }: Props = $props();
|
| 7 |
+
</script>
|
| 8 |
+
|
| 9 |
+
<div class="py-4 text-center text-sm text-muted-foreground">
|
| 10 |
+
{#if isLoading}
|
| 11 |
+
Loading resources...
|
| 12 |
+
{:else}
|
| 13 |
+
No resources available
|
| 14 |
+
{/if}
|
| 15 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowserHeader.svelte
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { RefreshCw, Loader2 } from '@lucide/svelte';
|
| 3 |
+
import { Button } from '$lib/components/ui/button';
|
| 4 |
+
import { SearchInput } from '$lib/components/app/forms';
|
| 5 |
+
|
| 6 |
+
interface Props {
|
| 7 |
+
isLoading: boolean;
|
| 8 |
+
onRefresh: () => void;
|
| 9 |
+
onSearch?: (query: string) => void;
|
| 10 |
+
searchQuery?: string;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
let { isLoading, onRefresh, onSearch, searchQuery = '' }: Props = $props();
|
| 14 |
+
</script>
|
| 15 |
+
|
| 16 |
+
<div class="flex flex-col gap-2">
|
| 17 |
+
<div class="mb-2 flex items-center gap-4">
|
| 18 |
+
<SearchInput
|
| 19 |
+
placeholder="Search resources..."
|
| 20 |
+
value={searchQuery}
|
| 21 |
+
onInput={(value) => onSearch?.(value)}
|
| 22 |
+
/>
|
| 23 |
+
|
| 24 |
+
<Button
|
| 25 |
+
variant="ghost"
|
| 26 |
+
size="sm"
|
| 27 |
+
class="h-8 w-8 p-0"
|
| 28 |
+
onclick={onRefresh}
|
| 29 |
+
disabled={isLoading}
|
| 30 |
+
title="Refresh resources"
|
| 31 |
+
>
|
| 32 |
+
{#if isLoading}
|
| 33 |
+
<Loader2 class="h-4 w-4 animate-spin" />
|
| 34 |
+
{:else}
|
| 35 |
+
<RefreshCw class="h-4 w-4" />
|
| 36 |
+
{/if}
|
| 37 |
+
</Button>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<h3 class="text-sm font-medium">Available resources</h3>
|
| 41 |
+
</div>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/McpResourcesBrowserServerItem.svelte
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script lang="ts">
|
| 2 |
+
import { FolderOpen, ChevronDown, ChevronRight, Loader2, Braces } from '@lucide/svelte';
|
| 3 |
+
import { Checkbox } from '$lib/components/ui/checkbox';
|
| 4 |
+
import * as Collapsible from '$lib/components/ui/collapsible';
|
| 5 |
+
import { mcpStore } from '$lib/stores/mcp.svelte';
|
| 6 |
+
import type { MCPResourceInfo, MCPResourceTemplateInfo, MCPServerResources } from '$lib/types';
|
| 7 |
+
import { SvelteSet } from 'svelte/reactivity';
|
| 8 |
+
import {
|
| 9 |
+
type ResourceTreeNode,
|
| 10 |
+
buildResourceTree,
|
| 11 |
+
countTreeResources,
|
| 12 |
+
sortTreeChildren
|
| 13 |
+
} from './mcp-resources-browser';
|
| 14 |
+
import { getDisplayName, getResourceIcon } from '$lib/utils';
|
| 15 |
+
import { McpServerIdentity } from '$lib/components/app/mcp';
|
| 16 |
+
|
| 17 |
+
interface Props {
|
| 18 |
+
serverName: string;
|
| 19 |
+
serverRes: MCPServerResources;
|
| 20 |
+
isExpanded: boolean;
|
| 21 |
+
selectedUris: Set<string>;
|
| 22 |
+
selectedTemplateUri?: string | null;
|
| 23 |
+
expandedFolders: SvelteSet<string>;
|
| 24 |
+
onToggleServer: () => void;
|
| 25 |
+
onToggleFolder: (folderId: string) => void;
|
| 26 |
+
onSelect?: (resource: MCPResourceInfo, shiftKey?: boolean) => void;
|
| 27 |
+
onToggle?: (resource: MCPResourceInfo, checked: boolean) => void;
|
| 28 |
+
onTemplateSelect?: (template: MCPResourceTemplateInfo) => void;
|
| 29 |
+
searchQuery?: string;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
let {
|
| 33 |
+
serverName,
|
| 34 |
+
serverRes,
|
| 35 |
+
isExpanded,
|
| 36 |
+
selectedUris,
|
| 37 |
+
selectedTemplateUri,
|
| 38 |
+
expandedFolders,
|
| 39 |
+
onToggleServer,
|
| 40 |
+
onToggleFolder,
|
| 41 |
+
onSelect,
|
| 42 |
+
onToggle,
|
| 43 |
+
onTemplateSelect,
|
| 44 |
+
searchQuery = ''
|
| 45 |
+
}: Props = $props();
|
| 46 |
+
|
| 47 |
+
let serverDisplayName = $derived(mcpStore.getServerDisplayName(serverName));
|
| 48 |
+
let serverFaviconUrl = $derived(mcpStore.getServerFavicon(serverName));
|
| 49 |
+
|
| 50 |
+
const hasResources = $derived(serverRes.resources.length > 0);
|
| 51 |
+
const hasTemplates = $derived(serverRes.templates.length > 0);
|
| 52 |
+
const hasContent = $derived(hasResources || hasTemplates);
|
| 53 |
+
const resourceTree = $derived(buildResourceTree(serverRes.resources, serverName, searchQuery));
|
| 54 |
+
|
| 55 |
+
const templateInfos = $derived<MCPResourceTemplateInfo[]>(
|
| 56 |
+
serverRes.templates.map((t) => ({
|
| 57 |
+
uriTemplate: t.uriTemplate,
|
| 58 |
+
name: t.name,
|
| 59 |
+
title: t.title,
|
| 60 |
+
description: t.description,
|
| 61 |
+
mimeType: t.mimeType,
|
| 62 |
+
serverName,
|
| 63 |
+
annotations: t.annotations,
|
| 64 |
+
icons: t.icons
|
| 65 |
+
}))
|
| 66 |
+
);
|
| 67 |
+
|
| 68 |
+
function handleResourceClick(resource: MCPResourceInfo, event: MouseEvent) {
|
| 69 |
+
onSelect?.(resource, event.shiftKey);
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
function handleCheckboxChange(resource: MCPResourceInfo, checked: boolean) {
|
| 73 |
+
onToggle?.(resource, checked);
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function isResourceSelected(resource: MCPResourceInfo): boolean {
|
| 77 |
+
return selectedUris.has(resource.uri);
|
| 78 |
+
}
|
| 79 |
+
</script>
|
| 80 |
+
|
| 81 |
+
{#snippet renderTreeNode(node: ResourceTreeNode, depth: number, parentPath: string)}
|
| 82 |
+
{@const isFolder = !node.resource && node.children.size > 0}
|
| 83 |
+
{@const folderId = `${serverName}:${parentPath}/${node.name}`}
|
| 84 |
+
{@const isFolderExpanded = expandedFolders.has(folderId)}
|
| 85 |
+
|
| 86 |
+
{#if isFolder}
|
| 87 |
+
{@const folderCount = countTreeResources(node)}
|
| 88 |
+
<Collapsible.Root open={isFolderExpanded} onOpenChange={() => onToggleFolder(folderId)}>
|
| 89 |
+
<Collapsible.Trigger
|
| 90 |
+
class="flex w-full items-center gap-2 rounded px-2 py-1 text-sm hover:bg-muted/50"
|
| 91 |
+
>
|
| 92 |
+
{#if isFolderExpanded}
|
| 93 |
+
<ChevronDown class="h-3 w-3" />
|
| 94 |
+
{:else}
|
| 95 |
+
<ChevronRight class="h-3 w-3" />
|
| 96 |
+
{/if}
|
| 97 |
+
|
| 98 |
+
<FolderOpen class="h-3.5 w-3.5 text-muted-foreground" />
|
| 99 |
+
|
| 100 |
+
<span class="font-medium">{node.name}</span>
|
| 101 |
+
|
| 102 |
+
<span class="text-xs text-muted-foreground">({folderCount})</span>
|
| 103 |
+
</Collapsible.Trigger>
|
| 104 |
+
|
| 105 |
+
<Collapsible.Content>
|
| 106 |
+
<div class="ml-4 flex flex-col gap-0.5 border-l border-border/50 pl-2">
|
| 107 |
+
{#each sortTreeChildren( [...node.children.values()] ) as child (child.resource?.uri || `${serverName}:${parentPath}/${node.name}/${child.name}`)}
|
| 108 |
+
{@render renderTreeNode(child, depth + 1, `${parentPath}/${node.name}`)}
|
| 109 |
+
{/each}
|
| 110 |
+
</div>
|
| 111 |
+
</Collapsible.Content>
|
| 112 |
+
</Collapsible.Root>
|
| 113 |
+
{:else if node.resource}
|
| 114 |
+
{@const resource = node.resource}
|
| 115 |
+
{@const ResourceIcon = getResourceIcon(resource.mimeType, resource.uri)}
|
| 116 |
+
{@const isSelected = isResourceSelected(resource)}
|
| 117 |
+
{@const resourceDisplayName = resource.title || getDisplayName(node.name)}
|
| 118 |
+
|
| 119 |
+
<div class="group flex w-full items-center gap-2">
|
| 120 |
+
{#if onToggle}
|
| 121 |
+
<Checkbox
|
| 122 |
+
checked={isSelected}
|
| 123 |
+
onCheckedChange={(checked: boolean | 'indeterminate') =>
|
| 124 |
+
handleCheckboxChange(resource, checked === true)}
|
| 125 |
+
class="h-4 w-4"
|
| 126 |
+
/>
|
| 127 |
+
{/if}
|
| 128 |
+
|
| 129 |
+
<button
|
| 130 |
+
class={[
|
| 131 |
+
'flex flex-1 items-center gap-2 rounded px-2 py-1 text-left text-sm transition-colors',
|
| 132 |
+
'hover:bg-muted/50',
|
| 133 |
+
isSelected && 'bg-muted'
|
| 134 |
+
]}
|
| 135 |
+
onclick={(e: MouseEvent) => handleResourceClick(resource, e)}
|
| 136 |
+
title={resourceDisplayName}
|
| 137 |
+
>
|
| 138 |
+
<ResourceIcon class="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
|
| 139 |
+
|
| 140 |
+
<span class="min-w-0 flex-1 truncate text-left">
|
| 141 |
+
{resourceDisplayName}
|
| 142 |
+
</span>
|
| 143 |
+
</button>
|
| 144 |
+
</div>
|
| 145 |
+
{/if}
|
| 146 |
+
{/snippet}
|
| 147 |
+
|
| 148 |
+
<Collapsible.Root open={isExpanded} onOpenChange={onToggleServer}>
|
| 149 |
+
<Collapsible.Trigger
|
| 150 |
+
class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50"
|
| 151 |
+
>
|
| 152 |
+
{#if isExpanded}
|
| 153 |
+
<ChevronDown class="h-3.5 w-3.5" />
|
| 154 |
+
{:else}
|
| 155 |
+
<ChevronRight class="h-3.5 w-3.5" />
|
| 156 |
+
{/if}
|
| 157 |
+
|
| 158 |
+
<span class="inline-flex flex-col items-start gap-1 text-left">
|
| 159 |
+
<div class="inline-flex min-w-0 items-center gap-1.5">
|
| 160 |
+
<McpServerIdentity
|
| 161 |
+
displayName={serverDisplayName}
|
| 162 |
+
faviconUrl={serverFaviconUrl}
|
| 163 |
+
iconClass="h-4 w-4"
|
| 164 |
+
showVersion={false}
|
| 165 |
+
/>
|
| 166 |
+
</div>
|
| 167 |
+
|
| 168 |
+
<span class="text-xs text-muted-foreground">
|
| 169 |
+
({serverRes.resources.length} resource{serverRes.resources.length !== 1
|
| 170 |
+
? 's'
|
| 171 |
+
: ''}{#if hasTemplates}, {serverRes.templates.length} template{serverRes.templates
|
| 172 |
+
.length !== 1
|
| 173 |
+
? 's'
|
| 174 |
+
: ''}{/if})
|
| 175 |
+
</span>
|
| 176 |
+
</span>
|
| 177 |
+
|
| 178 |
+
{#if serverRes.loading}
|
| 179 |
+
<Loader2 class="ml-auto h-3 w-3 animate-spin text-muted-foreground" />
|
| 180 |
+
{/if}
|
| 181 |
+
</Collapsible.Trigger>
|
| 182 |
+
|
| 183 |
+
<Collapsible.Content>
|
| 184 |
+
<div class="ml-4 flex flex-col gap-0.5 border-l border-border/50 pl-2">
|
| 185 |
+
{#if serverRes.error}
|
| 186 |
+
<div class="py-1 text-xs text-red-500">
|
| 187 |
+
Error: {serverRes.error}
|
| 188 |
+
</div>
|
| 189 |
+
{:else if !hasContent}
|
| 190 |
+
<div class="py-1 text-xs text-muted-foreground">No resources</div>
|
| 191 |
+
{:else}
|
| 192 |
+
{#if hasResources}
|
| 193 |
+
{#each sortTreeChildren( [...resourceTree.children.values()] ) as child (child.resource?.uri || `${serverName}:${child.name}`)}
|
| 194 |
+
{@render renderTreeNode(child, 1, '')}
|
| 195 |
+
{/each}
|
| 196 |
+
{/if}
|
| 197 |
+
|
| 198 |
+
{#if hasTemplates && onTemplateSelect}
|
| 199 |
+
{#if hasResources}
|
| 200 |
+
<div class="my-1 border-t border-border/30"></div>
|
| 201 |
+
{/if}
|
| 202 |
+
|
| 203 |
+
<div
|
| 204 |
+
class="py-0.5 text-[11px] font-medium tracking-wide text-muted-foreground/70 uppercase"
|
| 205 |
+
>
|
| 206 |
+
Templates
|
| 207 |
+
</div>
|
| 208 |
+
|
| 209 |
+
{#each templateInfos as template (template.uriTemplate)}
|
| 210 |
+
<button
|
| 211 |
+
class={[
|
| 212 |
+
'flex w-full items-center gap-2 rounded px-2 py-1 text-left text-sm transition-colors',
|
| 213 |
+
'hover:bg-muted/50',
|
| 214 |
+
selectedTemplateUri === template.uriTemplate && 'bg-muted'
|
| 215 |
+
]}
|
| 216 |
+
onclick={() => onTemplateSelect(template)}
|
| 217 |
+
title={template.uriTemplate}
|
| 218 |
+
>
|
| 219 |
+
<Braces class="h-3.5 w-3.5 shrink-0 text-muted-foreground" />
|
| 220 |
+
|
| 221 |
+
<span class="min-w-0 flex-1 truncate text-left">
|
| 222 |
+
{template.title || template.name}
|
| 223 |
+
</span>
|
| 224 |
+
</button>
|
| 225 |
+
{/each}
|
| 226 |
+
{/if}
|
| 227 |
+
{/if}
|
| 228 |
+
</div>
|
| 229 |
+
</Collapsible.Content>
|
| 230 |
+
</Collapsible.Root>
|
llama.cpp/tools/ui/src/lib/components/app/mcp/McpResourcesBrowser/mcp-resources-browser.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { MCPResource, MCPResourceInfo } from '$lib/types';
|
| 2 |
+
import { parseResourcePath } from '$lib/utils';
|
| 3 |
+
|
| 4 |
+
export interface ResourceTreeNode {
|
| 5 |
+
name: string;
|
| 6 |
+
resource?: MCPResourceInfo;
|
| 7 |
+
children: Map<string, ResourceTreeNode>;
|
| 8 |
+
isFiltered?: boolean;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
function resourceMatchesSearch(resource: MCPResource, query: string): boolean {
|
| 12 |
+
return (
|
| 13 |
+
resource.title?.toLowerCase().includes(query) || resource.uri.toLowerCase().includes(query)
|
| 14 |
+
);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
export function buildResourceTree(
|
| 18 |
+
resourceList: MCPResource[],
|
| 19 |
+
serverName: string,
|
| 20 |
+
searchQuery?: string
|
| 21 |
+
): ResourceTreeNode {
|
| 22 |
+
const root: ResourceTreeNode = { name: 'root', children: new Map() };
|
| 23 |
+
|
| 24 |
+
if (!searchQuery || !searchQuery.trim()) {
|
| 25 |
+
for (const resource of resourceList) {
|
| 26 |
+
const pathParts = parseResourcePath(resource.uri);
|
| 27 |
+
let current = root;
|
| 28 |
+
|
| 29 |
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
| 30 |
+
const part = pathParts[i];
|
| 31 |
+
if (!current.children.has(part)) {
|
| 32 |
+
current.children.set(part, { name: part, children: new Map() });
|
| 33 |
+
}
|
| 34 |
+
current = current.children.get(part)!;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const fileName = pathParts[pathParts.length - 1] || resource.name;
|
| 38 |
+
current.children.set(resource.uri, {
|
| 39 |
+
name: fileName,
|
| 40 |
+
resource: { ...resource, serverName },
|
| 41 |
+
children: new Map()
|
| 42 |
+
});
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
return root;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
const query = searchQuery.toLowerCase();
|
| 49 |
+
|
| 50 |
+
// Build tree with filtering
|
| 51 |
+
for (const resource of resourceList) {
|
| 52 |
+
if (!resourceMatchesSearch(resource, query)) continue;
|
| 53 |
+
|
| 54 |
+
const pathParts = parseResourcePath(resource.uri);
|
| 55 |
+
let current = root;
|
| 56 |
+
|
| 57 |
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
| 58 |
+
const part = pathParts[i];
|
| 59 |
+
if (!current.children.has(part)) {
|
| 60 |
+
current.children.set(part, { name: part, children: new Map(), isFiltered: true });
|
| 61 |
+
}
|
| 62 |
+
current = current.children.get(part)!;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
const fileName = pathParts[pathParts.length - 1] || resource.name;
|
| 66 |
+
|
| 67 |
+
current.children.set(resource.uri, {
|
| 68 |
+
name: fileName,
|
| 69 |
+
resource: { ...resource, serverName },
|
| 70 |
+
children: new Map(),
|
| 71 |
+
isFiltered: true
|
| 72 |
+
});
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function cleanupEmptyFolders(node: ResourceTreeNode): boolean {
|
| 76 |
+
if (node.resource) return true;
|
| 77 |
+
|
| 78 |
+
const toDelete: string[] = [];
|
| 79 |
+
for (const [name, child] of node.children.entries()) {
|
| 80 |
+
if (!cleanupEmptyFolders(child)) {
|
| 81 |
+
toDelete.push(name);
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
for (const name of toDelete) {
|
| 86 |
+
node.children.delete(name);
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
return node.children.size > 0;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
cleanupEmptyFolders(root);
|
| 93 |
+
|
| 94 |
+
return root;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
export function countTreeResources(node: ResourceTreeNode): number {
|
| 98 |
+
if (node.resource) return 1;
|
| 99 |
+
let count = 0;
|
| 100 |
+
|
| 101 |
+
for (const child of node.children.values()) {
|
| 102 |
+
count += countTreeResources(child);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
return count;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
export function sortTreeChildren(children: ResourceTreeNode[]): ResourceTreeNode[] {
|
| 109 |
+
return children.sort((a, b) => {
|
| 110 |
+
const aIsFolder = !a.resource && a.children.size > 0;
|
| 111 |
+
const bIsFolder = !b.resource && b.children.size > 0;
|
| 112 |
+
|
| 113 |
+
if (aIsFolder && !bIsFolder) return -1;
|
| 114 |
+
if (!aIsFolder && bIsFolder) return 1;
|
| 115 |
+
|
| 116 |
+
return a.name.localeCompare(b.name);
|
| 117 |
+
});
|
| 118 |
+
}
|