Compare commits

..
24 Commits
Author SHA1 Message Date
Meet Amin 184862801a gemma4: Optimized prompt processing for multi-seq queries (#32342) 2026-11-20 23:41:02 +08:00
Aleksander GrygierandNicolas Mowen 79e81b0bd4 ui: voice messages and dictation with live waveforms and transcripts (#32531)
* ui: add a voice engine for capture, peaks and transcription

Voice input needs a live waveform, a clip that can be sent and drawn,
and a transcript, whether the model streams text while the user speaks
or not. This adds the engine for it in src/lib/voice, with no imports
of app stores or components, so it can move into a package later.

- VoiceCapture: one microphone start gives live levels (RMS on a dB
  curve, fixed history, newest last), PCM16 mono chunks at 16 kHz from
  an inline AudioWorklet (ScriptProcessor fallback), and on stop a
  16-bit mono WAV clip with its duration and peaks. Tracks, nodes and
  the context are released on stop, cancel, a failed start and page hide.
- computePeaks / computePeaksFromAudio: normalised peaks of samples, a
  buffer, or a stored base64 or Blob file.
- transcribeClip: POST /v1/audio/transcriptions, with the server's own
  error message on failure.
- RealtimeTranscriber: the /v1/realtime?intent=transcription socket,
  queueing audio until session.created, a final commit, and a typed
  RealtimeUnsupportedError when the model cannot stream or the socket
  is refused (a browser websocket cannot send the API key header).
- startVoiceSession and VoiceRecorder: try realtime, fall back to one
  HTTP transcription of the clip, and expose levels and live text.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add voice waveform and transcript components to Llama UI

Voice input needs three visuals that the app can feed with its own
recording and transcription logic: the live waveform while recording,
a playable waveform of a recorded clip, and a clip with its transcript
that opens on hover, keyboard focus or a tap.

VoiceWaveformLive draws input levels as many bars as fit the width,
newest on the right, and holds still with reduced motion.
VoiceWaveform plays a clip through its own audio element, fills the
played part in the primary colour, seeks by press, drag and arrow keys
(a slider) and pauses any other clip that was playing.
VoiceTranscriptReveal keeps the transcript in the DOM for screen
readers while it is closed, and shows transcribing and error states.

The waveform math (resampling peaks, bar capacity, seek and time
formatting) is in src/lib/voice with unit tests. The components are
exported from the package root and from @ggml-org/llama-ui/voice, which
Llama Chat resolves to the sources like the other entry points.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add stories and tests for the voice components

Storybook gets UI/Blocks/Voice: the live waveform fed by a fake
microphone meter in a chat form row, the clip waveform in its sizes and
states, and the transcript reveal in each state and on touch. The demo
audio is a WAV synthesised in the story, so no binary file is added.

The play functions check seeking by keys and by press, the reveal on
hover, keyboard focus and a tap, and a clip without audio. Pressing play
needs a real click before a browser plays audio, so a client test covers
play and pause and one clip pausing another.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: store voice messages with their transcript and send it to models that cannot hear

A voice message recorded in the chat form is an audio attachment like an
uploaded file, plus what the app needs to draw and read it. The audio
attachment gets four optional fields: voice (recorded in the app),
transcript, peaks and durationMs. Stored rows, export and import carry
them as they are, so no migration is needed and older messages keep
working.

The transcript is for reading. A model with audio input still gets the
audio alone; a model without it (the user switched models later) gets the
transcript as a labelled text part in place of the audio. When the
model's modalities are not known yet, or there is no transcript, the
audio goes as before.

A transcript often comes back after the message was sent. The new
voiceTranscriptsStore follows each pending transcript by the clip's name,
hands it to a send that happens after it arrived, and otherwise writes it
into the stored attachment of the message it went out with, in the open
chat or, if the user left it, in the database.

Copying a message now includes its voice transcript.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add Voice settings and resolve what the microphone does per model

The user should not have to think about which kind of voice input is in
use, so the app decides it from the conversation's model and two
settings. resolveVoiceMode is a small pure function: with Voice input on
Automatic and a chat model that has audio input, a recording is a voice
message, transcribed by that same model so a router swaps nothing.
Otherwise it is dictation, with the chat model when it can hear, else,
in router mode, with the chosen transcription model. When no model can
transcribe, the microphone is unavailable and says why.

Settings get a Voice section of their own rather than more rows in
General, which is already long: these four belong together and one of
them lists the server's models.

- Voice input: Automatic (default) or Always dictate.
- Transcription model: Same as chat model (default) or, in router mode,
  any model with audio input; on a single-model server it only says
  whether that model can transcribe. It notes that dictating with
  another model loads it beside the chat model.
- Transcribe voice messages: on by default.
- Transcription language: empty for automatic.

The keys live in the settings registry like the others, so defaults,
storage, reset and export need nothing new. The model picker is drawn by
SettingsChatVoiceTab, the way Extensions and Tools draw their sections.

Assisted-by: Claude (Opus 5.5 Medium)
Co-authored-by: Nicolas Mowen <14866235+NickM-27@users.noreply.github.com>

* ui: record voice messages and dictation from the chat form

The microphone now does what the conversation's model allows, without
the user choosing a mode: its label says "Send a voice message" or
"Dictate", and when no model can take audio it is disabled and says why
(shown in router mode only when some model there has audio input, so the
reason can be acted on; a single-model server without audio keeps the
send button as before). The microphone errors keep their warning state
and toast, now also for the voice engine's own capture errors.

Recording goes through the voice engine's VoiceRecorder instead of the
MediaRecorder flow. While it records, the actions row becomes a
recording row: cancel, the live waveform, the elapsed time and stop.
Escape or cancel drops the recording. The form keeps its two rows while
recording, so the message stays visible on desktop and the row fits the
phone layouts and the expanded sheet.

- Dictation writes the live transcript into the message at the caret
  as it streams. DictationSpan replaces only the dictated stretch, moves
  it when the user types before it, keeps what is typed after it, and
  hands text the user edits over to them. When nothing streams, the row
  shows Transcribing... after stop and the text goes in once it is back.
  Cancel takes the dictated text out again. No audio is attached.
- A voice message streams its live text, if any, under the waveform,
  not into the message. On stop the clip is attached as a voice file
  with its peaks and length, and its transcript is followed by the voice
  transcripts store (unless Transcribe voice messages is off).

Realtime transcription is skipped for servers reached through a tunnel
or with an API key, which a browser websocket cannot carry. The first
dictation with a separate router model shows a one-time note that it
loads beside the chat model.

The form takes an optional voiceRecorder, so tests and stories can run
it without a microphone.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: draw audio attachments as playable waveforms with their transcript

A voice message should read as a clip, not as a file chip. Audio
attachments now render with Llama UI's VoiceWaveform inside
VoiceTranscriptReveal, through a direct branch in the core attachment
item (voice is core, so it does not go through the extension renderers):
the removable sm chip in the chat form, and the md clip in a sent
message, on the user bubble's surface.

- The audio plays from an object URL made from the stored base64 (or the
  uploaded file's data URL), revoked when the clip leaves the screen.
- A clip stored without peaks, an older voice message or an uploaded
  audio file, gets them computed from its audio once per session, in
  memory only; uploaded files keep their name under the waveform.
- The transcript opens under the clip on hover, keyboard focus or a tap,
  and shows Transcribing... while the voice transcripts store waits for
  it, Transcription unavailable when it failed, and nothing when none
  was asked for.
- The full-screen preview keeps its player and shows the transcript.

Tests run the chat form with a fake recorder: the microphone per mode,
the recording row, dictation around typed text, the Transcribing...
state, cancel, and a voice message chip whose transcript arrives later
and goes with the send. Stories show the form recording each kind, a
recorded chip, and sent voice messages with the transcript, pending,
and computed peaks.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: drop the old audio recorder and proxy realtime transcription in dev

The voice engine replaced AudioRecorder, so it goes. The dev server now
proxies WebSockets on /v1, so realtime transcription works under vite dev.
The VoiceCapture test waits for the tone to be recorded instead of a fixed
700 ms, which a loaded test run could miss.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: dictate with a model that is already loaded when the chat model cannot hear

The Transcription model setting's Automatic choice now falls back to a
router model with audio input that is already loaded, so dictating with a
text-only chat model works without picking a model and loads nothing.
A picked model still wins, and the empty value is a named constant.
Idea from upstream PR 27567, by NickM-27.

Assisted-by: Claude (Opus 5.5 Medium)
Co-authored-by: Nicolas Mowen <14866235+NickM-27@users.noreply.github.com>

* ui: fill the recording waveform, and open voice message transcripts

- The live waveform fills the row from the start: a recording shorter
  than the row is stretched over all its bars, a longer one scrolls with
  the newest level on the right. No dotted placeholder.
- A voice message's transcript is open under its clip, in the chat form
  while it comes in and in the sent message, with the toggle beside it
  to fold it.
- Settings > Voice > Collapse transcripts (off by default) keeps them
  folded instead, opening on hover, keyboard focus or a tap.

Assisted-by: Claude (Opus 5.5 Medium)
(cherry picked from commit 2a93f2f948ed976e40f693ce5d3acf1168284b05)

* ui: record voice without ducking other audio, from the first word

- Voice input asks for the raw microphone signal: no echo cancellation,
  noise suppression or auto gain. Echo cancellation made the system treat
  a recording as a call, which lowers or interrupts other playback, and
  auto gain faded the first words in.
- One AudioContext serves every recording, with the capture worklet
  loaded once, suspended in between and, where the browser allows it,
  without an output device, so recording never touches the speakers.
- The chat form prepares it when it gets focus (no microphone, so no
  recording indicator), and a mouse starts recording on press.
- A recording starts counting once audio flows: until then the bar says
  Starting... instead of running the timer. Development builds log how
  long each step of a start took.
- Settings > Voice > Microphone: Automatic (the system default, or the
  built-in microphone when the default is a Bluetooth headset, which
  would switch to its low-quality call mode), System default, or a
  listed microphone.

Assisted-by: Claude (Opus 5.5 Medium)
(cherry picked from commit 76643e7210d21617d734fdfde677e84af7273153)

* ui: show voice text live in the message box, and follow transcripts as spoken

- A model that hears but has no live ASR (e.g. LFM3-Omni) now gives text
  while you record: the realtime client commits the audio piece by piece,
  at the pauses the levels show, one piece at a time, and the final
  commit takes only what is left.
- A voice message's live text shows as the empty message box's
  placeholder. Clicking into the box makes it text to edit there, and
  what is said next follows it. On stop the text leaves the box and goes
  with the clip; when it was edited, the edit is the clip's transcript.
- Llama UI gains VoiceSpokenText and spokenLength(): spoken words in the
  full foreground colour, which they keep, the rest muted. A clip's
  transcript follows its playback (estimated over the parts with speech,
  as there are no word timings), and live text brightens as it arrives.
- The recording bar has a send button that stops and sends in one go.

Assisted-by: Claude (Opus 5.5 Medium)
(cherry picked from commit ce773017f902f8a5690ab9ecca368cecb6427422)

* ui: let the capture test start with silence

A capture starts with its first audio block, which can come before a
stream's first sound, so the steady tone is checked from where it begins.

Assisted-by: Claude (Opus 5.5 Medium)
(cherry picked from commit a41ee5337b83fef685a5cbaff176925f1647ce9d)

* ui: show live voice text sooner, and keep silence from becoming "yeah"

- A model that transcribes per commit (LFM3-Omni) gets shorter pieces:
  cut at a 0.35 s pause after speech, or at the next quiet moment once a
  piece reaches 3 s, so the text follows the speaker within a few
  seconds in dictation, the message box and voice mode.
- When the recording stops, the audio after the last piece is committed
  only if speech was heard in it. LFM3-Omni transcribes a commit of pure
  silence as "Yeah." (or "はい。"), which ended up at the end of the text.
  A recording whose only piece is that rest still commits it.

Assisted-by: Claude (Opus 5.5 Medium)
(cherry picked from commit 43e52cbab0fba9d8e84b9491890a406e3c6c90f3)

* ui: transcribe a recording cut at pauses once more as a whole

Live text comes piece by piece, cut at the speaker's short pauses, and a
model reads each piece as a sentence of its own: "I went. To the store."
When the recording ends, one pass over the whole clip gives the final
text, punctuated by meaning, in dictation and in voice mode alike. The
pieces' text stays the live text until then, and is kept when that pass
fails or the recording is longer than two minutes.

Assisted-by: Claude (Opus 5.5 Medium)
(cherry picked from commit 359dd9632e6c88000a1d23c2575bd1e6fcdd9ec1)

* ui: give live text over HTTP for models without a realtime session

A model that hears but cannot hold a realtime session, such as
Qwen3-ASR, was transcribed only after the recording, so dictation
showed no text while speaking. The recording is now cut at the
speaker's pauses as with a realtime session, and each piece sent to
/v1/audio/transcriptions on its own, one at a time, its text joined
live. The audio is kept from the start, so what is said while the
socket answers goes with the first piece. The whole clip is still
transcribed once more at the end, and the pieces' text is kept if
that fails. A server a websocket cannot reach (an API key, a remote
server) gets live text the same way.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: say when the browser processes the microphone despite the raw request

The browser keeps one processing setting per microphone: while a call,
another tab or voice mode has it open with echo cancellation, a
dictation that asked for the raw signal is processed too, sounds
distant, and the system may lower other sound. The capture now warns
when it gets processing it did not ask for, and its development log
names the microphone, its rate and what processing is on.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the microphone beside the stop and send buttons

While a reply streams, or once the message has text, the microphone no longer
gives way to the main button: it stays beside it as a quieter, secondary
button, so more can be dictated without clearing the message or waiting for
the reply.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: show the voice components' stories with Llama UI

VoiceWaveform and VoiceTranscriptReveal are Llama UI components, so their
stories move to the library's Storybook, under Llama UI/Voice, with the demo
audio they play. Llama Chat's Storybook shows them there too, and its own
voice stories take the demo audio from the library. VoiceWaveformLive stays
with Llama Chat, as its demo records through the chat form's microphone.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a noise suppression setting for voice input

Recordings stay raw by default. Settings > Voice can now switch the
browser's noise suppression on; echo cancellation and automatic gain stay
off either way, as they interrupt other sound and fade the first words in.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep live voice text coming when the room is never quiet

Pieces were cut only at a quiet moment, so with music or talk in the room
none was ever cut and no text showed until the recording ended. A piece half
as long again as its longest length is now cut where it is.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add echo cancellation and automatic gain settings for voice input

Settings > Voice now has a switch for each kind of microphone processing the
browser offers. All three stay off by default, so recordings are raw; each
one says what switching it on costs.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: put the microphone after the stop button, filled like it

While a reply streams, the microphone is the last button of the row and
looks like the stop and skip buttons beside it, instead of a bare icon
before them.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: say when dictated text is being refined, and send it refined

After a recording with live text, the whole clip is transcribed once more
so pauses do not end sentences. The form now says so while that pass is
out, and a send asked for meanwhile waits for it, so the message goes out
with the refined text rather than the pieces.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the send button in place and put the microphone beside it

The send button no longer gives way to the microphone on an empty
message. The microphone stands before it as a quieter, tertiary button,
with the same tooltip, warning and recording states as before.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: let a recording be sent while a reply streams, once it has words

While a reply streams, the recording row now shows its send button as
soon as the first transcribed words are in the message, so the
recording no longer has to be stopped first. The microphone also stays
beside the send button once a voice message is attached.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: raise quiet speech for transcription, and say when it is too quiet

A quiet microphone gave the model near silence to transcribe. A new
Voice setting, Boost quiet speech (on by default), raises speech to a
level speech models hear well, up to eight times louder: the audio
streamed for live text as it goes, and the whole recording in one pass
when it stops, so its first words get the same gain as the rest. Only
speech is measured, never the silence around it, loud speech is left
as it is, and a soft limiter keeps raised peaks from clipping. When
speech stays quiet even at the highest gain, the recording row says so.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the voice engine free of app code

The engine in lib/voice imported the microphone messages from the app's
utils and the WAV type from its enums, the only two things keeping it
from moving into a package of its own. The microphone checks and
messages move into the engine (voice/support.ts), next to the capture
that needs them; the uploaded-file helpers stay in the app's utils.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: start voice sessions from one voice service

How a recording reaches the server (routes, API key, whether the
realtime socket can be used) and how the Voice settings become capture
and transcribe options were built inside the chat form's voice hook,
and copied into every other feature that records. VoiceService builds
them in one place: a feature asks it for its session options and adds
only its own callbacks.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: tell speech from the room in one place

The pause detector, the speech gain and (in voice mode) the listener for
speech over a reply each followed a noise floor with their own numbers.
A SpeechDetector now does it for all of them, in dB, with one set of
settings in VOICE_SPEECH.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: let any text field take dictation

Writing dictated text into a field (at the caret, around the user's
typing, replaced by the whole recording's text when it comes) moves out
of the chat form's hook into a plain createDictation(). The hook keeps
what is the chat form's own: voice messages, toasts and the hint.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: move the recording row into Llama UI

VoiceRecordingBar draws the row shown while recording (cancel, waveform
and time, send, and a caption or warning under it) from data alone, so
voice mode or a notes page can show the same row. The chat form passes
its labels and its microphone button as the stop button.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the voice engine's Svelte recorder behind its own entry

VoiceRecorder, the one part of lib/voice written with runes, moves to
lib/voice/svelte, so the rest of the engine is plain TypeScript any app
can use without Svelte.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: move voice input into its own package, Llama Voice

The voice engine (capture, the speech signal, transcription over the
realtime socket or HTTP) and dictation into a text field move from the
app to ui/lib/voice as @ggml-org/llama-voice, so another app, such as a
notes app, can use them. The Svelte recorder is its ./svelte entry.
Llama Chat compiles the sources, as it does Llama UI's, and keeps its
server and settings wiring. The package has its own type check, tests
and build, and a CI job for them.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: show which model does what in voice input

The model picker and the Models manager mark each model that hears:
Dictation on the one that transcribes dictation, Speech to text on
transcription models such as Qwen3-ASR, and Voice on chat models that
take voice messages. A loaded model kept only for dictation sits apart
from the chat models, a model can be made the dictation model from its
row, and Settings > Voice groups the transcription models apart from
the chat models with audio input. A voice store now resolves what the
microphone does, for the chat form and the model lists alike.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: warn of a quiet microphone inside the recording row

The too-quiet line under the waveform made the form grow and jump. The
warning now stays inside the row: the waveform turns the warning colour,
an icon sits by the time, and the advice opens above the row in a
tooltip for a few seconds, then on hover or focus. Screen readers still
hear it when it appears.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: open the microphone while the pointer is on its button

The first seconds of a recording could come out quiet while the
microphone settled, and the too-quiet warning showed for them. With the
pointer or the focus on the microphone button, the microphone now opens
ahead of the press (only when the page may already use it, so nothing
asks), and the recording takes it at once; it is let go shortly after
the pointer leaves without a press. The warning also waits until the
speech has stayed too quiet for two seconds.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: tidy voice input after review

Fix a microphone left open when a recording is cancelled while it starts
or the pointer leaves while it opens, a capture that is still letting go
silencing the next one, and live text stopping after a realtime error.
Share the dictation model choice, the transcript lookup, base64 decoding,
PCM joining and stopping a stream instead of repeating them, and export
only Llama Voice's public API.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: pin Llama Voice's dev dependencies to Llama UI's versions

Assisted-by: Claude (Opus 5.5 Medium)

* ui: let demos speak into a synthetic microphone

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the microphone for voice input, off the audio files entry

The attach menu's Audio Files entry used a microphone, which now sits
beside the form's own microphone button. The microphone stands for
recording and dictation only; a model's audio modality is headphones, and
the audio files entry is a file with headphones.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: set voice input on the slimmed design tokens

Voice input's components use the type roles, the one corner scale and
shadcn's utility names for the neutral colours, as the rest of Llama UI
and Llama Chat do since the design tokens were slimmed down.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: name voice states, platform strings, patterns and tunings

Addresses the review on the voice PR:

- Llama Voice: VoiceCaptureState, VoiceRecorderStatus, RealtimeState and
  RealtimeUnsupportedReason are enums (src/enums.ts, exported); DOMException
  names, AudioContext states, transcription form fields, socket protocols,
  device kinds, worklet messages, error messages, regexes and tuning values
  are named constants.
- Llama UI: VoiceTranscriptStatus, VoiceWaveformSize and
  VoiceRecordingBarStatus are enums; KeyboardKey, MouseButton and PointerType
  join its UI enums; the voice components' sizes, labels, timings, selectors
  and patterns move to constants/voice.constants.ts. The voice unit tests
  move from src to tests/unit.
- App: ChatFormVoiceState is an enum, the recording bar's status comes from a
  map, and the voice code uses the enums above, BooleanString, HEADERS and
  new voice constants in place of inline strings, regexes and numbers.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep all of Llama UI's tests under tests

The Model UI formatting spec moves to tests/unit and the button spec to
tests/client, next to the voice specs; the test projects now read only
tests/unit and tests/client.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: show a transcript's words without the model's own format

Qwen3-ASR names the language before its text (language French<asr_text>...) and
VibeVoice-ASR answers with timed segments as JSON, which the server passes on as they
are. The voice engine now takes both off, over HTTP and over the realtime socket, also
while segments still stream, so the message box and the clip show the words alone.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: dictate when a speech-to-text model is picked for the conversation

A speech-to-text model has audio input, so on Automatic the microphone recorded a voice
message for it, which such a model has nothing to answer with. It now dictates, as the
model's badge already says it is for.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: say why a live-only model cannot transcribe behind an API key

A browser websocket cannot send the API key, so the realtime socket is left out on a
server that needs one, and a model that only transcribes over it (Voxtral Realtime)
answers the HTTP route with a 501. The clip and the dictation toast now say so instead of
only that transcription is unavailable.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: pick the dictation model with a microphone on its row

The model that transcribes dictation was marked with a filled Dictation badge. It is now
marked by a red microphone among the row's actions in the model picker, beside the heart,
and every other model that hears shows the same microphone on hover: a click makes it the
transcription model, and a click on the chosen one hands the choice back to Automatic. The
badge keeps saying what kind of hearing model a row is, and the Models manager marks the
dictation model with a small microphone beside its name.

Assisted-by: Claude (Opus 5.5 Medium)

---------

Co-authored-by: Nicolas Mowen <14866235+NickM-27@users.noreply.github.com>
2026-11-20 16:34:52 +01:00
Aleksander Grygier 059cac2848 ui: search message content and Discover models from the search dialog (#32670)
* ui: search message content and Discover models from the search dialog

The search dialog matched chat titles only. It now also scans what was
said in each chat (content, reasoning, tool calls and results, attachment
names and text), newest chat first, stopping at the first match per chat
and after 20 chats, and shows a snippet around the match. Ids, timestamps
and base64 payloads are not searched.

With Discover on, it also lists matching catalog models and, once typing
settles, Hugging Face repos; picking one opens Discover on that repo.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the search dialog one width whatever it lists

The shared dialog sizes itself to its content from md up, so the search
was narrow while empty and widened as results came in. It now takes the
full max-w-2xl there, less a margin on narrower windows.

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 16:20:00 +01:00
Aleksander Grygier cf4153a9ba ui: publish llama-ui as an alias of @ggml-org/llama-ui (#32667)
The unscoped llama-ui on npm is a 0.0.1 placeholder. After the scoped
publish, the workflow renames the same build and publishes it again at
the same version, with a readme note pointing at the scoped package.

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 15:46:18 +01:00
yoch 8e7862411d tts : forward -t to the mtmd context (#32664)
llama-tts built the mtmd context from mtmd_context_params_default(), which hardcodes 4 threads, and never copied n_threads over, so -t never reach the mtmd side.
Copy params.cpuparams.n_threads into mtmd_params.n_threads, as mtmd-cli and the server do; with no -t this now follows the resolved default.

Verified: -t 1 now runs single-threaded, -t 4 is unchanged, and the produced WAV is identical.

Assisted-by: Claude
2026-11-20 15:34:58 +01:00
Xuejun ZhaiandSigbjørn Skjæret e626db7caa server-bench : fix TypeError in histogram generation (#32518)
* fix(server-bench): prevent float bin-count TypeError in histogram generation

Symptom: benchmark crashes while generating gen_rate histogram.

Root cause: np.ceil(...) returns numpy.float64, and that value was used where an integer count/shape argument is required.

Fix: cast ceil result to int before +1, ensuring bin count is an integer.

Result: histogram path completes and gen_rate.png is generated reliably.

* Update scripts/server-bench.py

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

---------

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
2026-11-20 15:16:52 +01:00
Aleksander Grygier c6a25fc622 ui: load highlight.js languages on demand (#32661)
* ui: load highlight.js on first use

highlight.js and every lowlight language (~900 KB raw) moved out of
Llama Chat's first load into a chunk that loads with the first code block.

- @ggml-org/llama-ui/code: highlightCode stays synchronous. Until
  highlight.js has loaded it returns the code escaped as plain text and
  starts the load; a $derived or $effect that called it runs again once
  it has loaded. New loadHighlighter() and isHighlighterLoaded().
- Markdown: rehype-highlight runs through a lazy rehype step, like
  KaTeX's: the first message with a code block waits for it, every
  other one renders in the same pass.

First-load JS of the chat page: 3.47 -> 2.56 MB raw, 1.05 -> 0.75 MB
gzip, 0.84 -> 0.60 MB brotli.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: load each highlight.js language on first use

highlight.js now loads one language at a time instead of all ~190 at
once with the first code block: every language is its own chunk, and
the core loads with the first one.

- @ggml-org/llama-ui/code: highlightCode looks a language or alias up
  in a generated table (scripts/generate-highlight-languages.mjs), loads
  it with the languages it embeds (CSS and JavaScript inside HTML, say)
  and returns plain text until then; a $derived or $effect that called
  it runs again once it has loaded. Auto-detection picks among lowlight's
  37 common languages, loaded the first time something auto-detects.
  New loadHighlightLanguages(), isHighlightLanguageLoaded(),
  resolveHighlightLanguage() and getLoadedHighlightLanguages() replace
  loadHighlighter() and isHighlighterLoaded().
- Markdown: rehypeLazyHighlight highlights with lowlight's core and the
  languages a message uses, waiting only for one it is the first to use.
  rehype-highlight is no longer in the pipeline, since it bundles
  lowlight's common languages.

First-load JS of the chat page stays at 2.58 MB raw, 0.76 MB gzip,
0.61 MB brotli: no highlight.js code, only the 14 KB language table.
The first code block now loads its language (1-12 KB for most) and the
20 KB core instead of 900 KB.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: name the code-block class names and shell language as constants

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 15:06:10 +01:00
Xuan-Son Nguyen 5f837145d8 server: add more audio tests (#32579) 2026-11-20 14:21:58 +01:00
Xuan-Son Nguyen 36cd3aff40 server: add --ui-mcp-proxy-allow-private-urls (#32633) 2026-11-20 14:10:06 +01:00
Aleksander Grygier 28de970cc1 ui : focus the chat form when typing with nothing focused (#32570)
A printable key pressed on the chat screen while no field, editor,
dialog or menu has focus now moves focus to the chat form, and the
character lands there.

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 14:01:50 +01:00
Georgi Gerganov 4b69c79cca cuda : update GDN supports_op check (#32660) 2026-11-20 14:35:20 +02:00
Daniel HanandSigbjørn Skjæret a1f4222608 model : load ffn_gate_up_exps scales (#32657)
* model: load `ffn_gate_up_exps` scales

The generic scale pass loads per-expert scales for ffn_gate_exps,
ffn_up_exps and ffn_down_exps but not for the merged ffn_gate_up_exps.
Load ~ffn_gate_up_exps_s there~ and expose it as ffn_up_exps_s ~when the layer
has no separate up tensor,~ since build_moe_ffn applies up_exps_s to the
merged gate_up output. Inkling 2 now passes the expert scales to
build_moe_ffn like the other MoE models.

* Update src/llama-model.cpp

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

* Update src/llama-model.h

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>

---------

Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@huggingface.co>
2026-11-20 13:11:28 +01:00
Aman Gupta 4783b1145c llama : move the indexer key rotation choice into the model classes (#32653)
* llama : move the indexer key rotation choice into the model classes

The KV cache forced a Hadamard rotation for the lightning indexer keys
based on a list of architectures. The virtual llama_model::indexer_k_rot()
now returns true for the same models. DeepSeek4.1 inherits from DeepSeek4
but was not in the list, so it overrides it back to false.

* llama : rename indexer_k_rot() to lid_k_hdmd()
2026-11-20 18:49:16 +08:00
Sigbjørn Skjæret 6abcbe5d35 remove ui-lib publish verification step (#32658) 2026-11-20 11:45:46 +01:00
Aleksander Grygier b81aa847c2 ui: slim the design tokens and set all text through type roles (#32615)
* ui: drop component tokens that only alias a semantic token

A component token now exists only for what a component decides itself:
a value no semantic token has, or one that only this component changes
between themes. Components that take a semantic token as it is read it
directly, so 88 of the 118 component tokens go, with no change to what
is drawn.

Also drops semantic tokens that repeat another one (status-* is fill-*,
elevation-tooltip is elevation-surface), the unused info lamp tokens and
14 primitives nothing reads, and adds fg-soft for the label of an option
that is not the picked one (tabs, toggle group).

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a short summary on top of DESIGN.md

The rules most changes need, in one screen: components, colour, type,
shape, sizes, surfaces, tokens and no arbitrary values. The sections
below keep the detail.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: derive design tokens by rule and drop the alias layers

Semantic tokens are either a pick (a primitive per theme) or a derivation,
mixed from another semantic token by a fixed rule and declared once: hover
fills, status surfaces and lines, dark shadows (--elevation-strength), the
middle of a matte edge, a lamp's rim and glyph.

Primitives keep colours only. shadcn's colour names stay as Tailwind
utilities and no longer exist as variables; neutral semantic utilities that
duplicated them are gone.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: set all text through type roles and move off-scale values onto the scale

Tailwind's text sizes and bracketed sizes become the type roles, with a new
text-caption-sm (10px) for tags and counts. Body and caption roles no longer
set a weight, and line heights are written as Tailwind writes its own, so the
swap from text-sm and text-xs changes no pixel. A unit test keeps old sizes
from coming back.

Arbitrary values with a scale equivalent use it (z-20, max-w-4/5, min-w-32),
and the two easing curves repeated across the app are ease-out-quint and
ease-sheet. DESIGN.md is updated and regenerated.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: bump @ggml-org/llama-ui to 0.5.0

Removed and renamed tokens are breaking for an app that reads them.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a display type role for the biggest headline

The greeting on a new chat keeps its 30px from md up, now as text-display
instead of a Tailwind size.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: one corner scale, one set of shadows and three more derived tokens

Six corner roles named values Tailwind's rounded-md to rounded-4xl
already have, and components used the Tailwind names nine times out of
ten. The roles are gone; the whole scale is computed from --radius.

Tailwind's shadow sizes were restated next to the elevation tokens and
did not follow the theme, so they were five times fainter in dark. The
five uses take elevation tokens and a unit test keeps both from coming
back.

A button group's seam is the button's own text colour at 25%, the dark
status text is the dark status fill, and the pressed shadow scales with
--elevation-strength like the inset one.

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 11:26:26 +01:00
Aleksander Grygier 9d6f04fa99 ui: show vision as glasses and audio as headphones (#32617)
The model modality icons match the ones the Llama apps use: glasses for
vision, headphones for audio. The attach menu's list of what the model
takes reads the same icons instead of its own microphone and picture.

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 10:33:34 +01:00
Aman Gupta 652d559edf llama : move the graph node budget into the model classes (#32648)
graph_max_nodes() picked the nodes-per-tensor factor from lists of
architectures. Each model class now gives it through a new virtual,
llama_model::graph_nodes_per_tensor(), which defaults to 8. The
architectures that need 32 or 64 override it in models.h, and DFlash
keeps its hparams-based rule in dflash.cpp.

LoRA adapter nodes are now added for every architecture, not only for
the ones on the default factor.
2026-11-20 17:19:14 +08:00
Aleksander Grygier 6aee50801d ui: set the reasoning effort from the model picker (#32632)
* ui: move the reasoning effort into the model picker

The chat form's row no longer holds the reasoning button: the model
picker ends with a Reasoning row, in place of Manage models, that shows
the level in use and opens the levels under it. A phone's model drawer
has the same row. A desktop server with a single model, whose selector
opens the manager instead of a picker, keeps the button beside it.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: show a reasoning effort that is not the default on the model selector

Next to the model on the closed selector, a set level shows as its word,
and reasoning that is off as a small crossed-out lightbulb. At the
default, which leaves it to the model, nothing more shows.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: keep the model picker's footer in place while it opens in Safari

WebKit pins a bottom-sticky element against the scaled box of a parent
that zooms in, so the Reasoning row rode up over the model list until
the opening animation ended. The desktop picker now scrolls its search
and list in a box of their own, with the footer under it.

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 09:58:11 +01:00
Aleksander Grygier 55b8d8d898 ui: full-screen diagram preview that zooms around what is on screen, inert diagrams (#32591)
* ui: keep Pele diagrams inert

Pele turns a node with `click ... href` into a live link, where Mermaid's
strict security level left diagrams without links. Unwrap every link in
Pele's output, keeping its children, so the inline block, the live-preview
editor, the preview dialog and the downloaded svg stay inert. The Diagrams
story's flowchart now carries click directives and its play test checks
that no link or href is left.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: open diagrams full screen, zoom around what is on screen

The diagram preview dialog fills the window on every device. The preview
places the diagram from its top left corner, so a zoom keeps a screen point
fixed: the wheel and a trackpad pinch zoom around the pointer, the buttons
and +/- keys around the middle of the screen, wherever the diagram has been
panned to. Two-finger pinch, double-click and arrow keys work too. The
diagram opens fitted and keeps fitting until panned or zoomed; Reset view
fits it again.

Adds MermaidPreview and DialogMermaidPreview stories with play tests and a
unit test for the zoom math.

Assisted-by: Claude (Opus 5.5 Medium)

* ui: add a diagrams trace to the demo fixtures

Assisted-by: Claude (Opus 5.5 Medium)
2026-11-20 09:57:44 +01:00
Aman Gupta 4c4a0f0a42 llama : reserve graph nodes for the MoE cache (#32636)
The MoE cache adds a slot lookup to every MoE layer, and with
--moe-cache-cpu-share a second expert path, but graph_max_nodes() did
not account for it. Models on the default 8*n_tensors budget with few
tensors per layer (cohere2moe: 443 tensors, 49 layers) overflow the
graph context when the cache is combined with a quantized KV cache
(K/V rotation), aborting in ggml_new_tensor with GGML_ASSERT(obj_new).

Fixes #32584

Assisted-by: Claude Opus 5.5
2026-11-20 16:13:00 +08:00
nicholas-mainardi-domyn 55d323507d model: add Domyn Edge 4B Model (#32559)
* feat: add domyn-edge model

* Generate tokenizer hash for conversion + fix tests

* Address changes according to code-review skill

* catch ValueError in convert_hf_to_gguf_update.py

* renegerate fusion test baseline + fix model naming style
2026-11-20 09:51:41 +02:00
Aaron Teo bed8ec2f8d llamafile(s390x): add QK data type support (#32600)
* llamafile: add QK support for s390x

Signed-off-by: Aaron Teo <aaron.teo1@ibm.com>

* llamafile: clean up for s390x

Signed-off-by: Aaron Teo <aaron.teo1@ibm.com>

---------

Signed-off-by: Aaron Teo <aaron.teo1@ibm.com>
2026-11-20 09:47:41 +02:00
sys2008 52e8db6550 kleidiai : allow OHOS (HarmonyOS) AArch64 target (#32265)
* kleidiai : allow OHOS (HarmonyOS) AArch64 target

* kleidiai : allow OHOS AArch64 target

Assisted-by: GLM
2026-11-20 09:46:59 +02:00
Nikhil Jain d7d1b632da webgpu : fix 2D indexing for copy kernel (#32576)
* Only run webgpu CI on my fork

* Add webgpu only workflow

* resolve merge conflicts

* Add 2d indexing to copy kernel

* move test
2026-11-20 09:45:44 +02:00
509 changed files with 19812 additions and 2299 deletions
+47 -18
View File
@@ -18,6 +18,10 @@ name: UI Lib Publish
# ui-lib-publish.yml, and Environment left blank - this job names no environment, since creating
# one needs repository admin. Merging this workflow before that exists leaves the publish step
# red on master: the release is late rather than wrong, and re-running the job publishes it.
#
# The unscoped llama-ui is an alias: once the scoped package is out, the same build is renamed
# and published again at the same version, so the two never drift. It is a package of its own
# on npm, and needs the same trusted publisher set on it.
on:
workflow_dispatch:
@@ -128,26 +132,29 @@ jobs:
npm publish --access public --provenance --ignore-scripts --tag "$TAG"
working-directory: ${{ env.LIB_DIR }}
- name: Verify it landed
if: github.ref == 'refs/heads/master' && steps.version.outputs.should_publish == 'true' && inputs.dry_run != true
- name: Rename the build to the unscoped alias
# after the scoped publish, so nothing above sees the changed name. Not on a PR: the
# advisory check there is about the version, which the alias shares.
if: github.event_name != 'pull_request'
run: node scripts/alias-package.mjs
working-directory: ${{ env.LIB_DIR }}
- name: Compare the alias with npm
id: alias
if: github.event_name != 'pull_request'
run: node scripts/npm-version-check.mjs
working-directory: ${{ env.LIB_DIR }}
- name: Publish the alias
# its own verdict rather than the scoped one's, so an alias that fell behind catches up
# on the next run instead of waiting for a bump
if: github.ref == 'refs/heads/master' && steps.alias.outputs.should_publish == 'true' && inputs.dry_run != true
env:
NAME: ${{ steps.version.outputs.name }}
VERSION: ${{ steps.version.outputs.version }}
TAG: ${{ steps.alias.outputs.tag }}
run: |
# the registry can serve a new version some time after publish returns, so retry rather
# than call a release that worked a failure
for try in 1 2 3 4 5 6; do
seen=$(npm view "$NAME@$VERSION" version 2>/dev/null || true)
if [ "$seen" = "$VERSION" ]; then
echo "$NAME@$VERSION is on npm"
npm view "$NAME@$VERSION" dist-tags version dist.integrity
exit 0
fi
echo "not visible yet (attempt $try of 6)"
sleep 10
done
echo "::error::$NAME@$VERSION published without error but is not visible on the registry after 6 attempts. The publish did not fail: check the package on npm before publishing again."
exit 1
test -d dist || { echo "dist/ is missing: nothing was built, so nothing is published"; exit 1; }
npm publish --access public --provenance --ignore-scripts --tag "$TAG"
working-directory: ${{ env.LIB_DIR }}
- name: Report
if: always()
@@ -161,6 +168,11 @@ jobs:
NOTE: ${{ steps.version.outputs.note }}
SHOULD: ${{ steps.version.outputs.should_publish }}
DRY: ${{ inputs.dry_run }}
ALIAS_LATEST: ${{ steps.alias.outputs.latest }}
ALIAS_VERDICT: ${{ steps.alias.outputs.verdict || 'not reached' }}
ALIAS_NOTE: ${{ steps.alias.outputs.note }}
ALIAS_SHOULD: ${{ steps.alias.outputs.should_publish }}
EVENT: ${{ github.event_name }}
run: |
if [ "$DRY" = "true" ]; then published="no (dry run)"
elif [ "$SHOULD" = "true" ]; then published=yes
@@ -177,6 +189,23 @@ jobs:
echo
echo "> $NOTE"
} >> "$GITHUB_STEP_SUMMARY"
[ "$EVENT" = "pull_request" ] && exit 0
if [ "$DRY" = "true" ]; then published="no (dry run)"
elif [ "$ALIAS_SHOULD" = "true" ]; then published=yes
else published=no
fi
{
echo
echo "### llama-ui (alias) $VERSION"
echo
echo "| | |"
echo "| --- | --- |"
echo "| npm latest was | ${ALIAS_LATEST:-nothing published yet} |"
echo "| verdict | \`$ALIAS_VERDICT\` |"
echo "| published | $published |"
echo
echo "> $ALIAS_NOTE"
} >> "$GITHUB_STEP_SUMMARY"
- name: Mind the verdict
if: always() && github.event_name != 'pull_request' && steps.version.outcome == 'success'
+2
View File
@@ -19,6 +19,7 @@ on:
'.github/workflows/ui-build-self-hosted.yml',
'ui/apps/chat/**.*',
'ui/lib/ui/**.*',
'ui/lib/voice/**.*',
'tools/server/tests/**.*'
]
pull_request:
@@ -28,6 +29,7 @@ on:
'.github/workflows/ui-build-self-hosted.yml',
'ui/apps/chat/**.*',
'ui/lib/ui/**.*',
'ui/lib/voice/**.*',
'tools/server/tests/**.*'
]
+31
View File
@@ -150,6 +150,37 @@ jobs:
run: npm run prepack
working-directory: ui/lib/ui
voice-checks:
name: Voice checks
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.sha || github.event.pull_request.head.sha || github.sha || github.head_ref || github.ref_name }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
package-manager-cache: false
- name: Install dependencies
run: npm ci
working-directory: ui/lib/voice
- name: Run type checking
run: npm run check
working-directory: ui/lib/voice
- name: Run tests
run: npm test
working-directory: ui/lib/voice
- name: Build the package
run: npm run prepack
working-directory: ui/lib/voice
e2e-tests:
name: E2E Tests
needs: ui-build
+9 -1
View File
@@ -3420,12 +3420,20 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
add_opt(common_arg(
{"--ui-mcp-proxy", "--webui-mcp-proxy"},
{"--no-ui-mcp-proxy", "--no-webui-mcp-proxy"},
"experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused - do not enable in untrusted environments (default: disabled)\n"
"experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused unless --ui-mcp-proxy-allow-private-urls is set - do not enable in untrusted environments (default: disabled)\n"
"note: for security reasons, this will limit --cors-origins to localhost by default",
[](common_params & params, bool value) {
params.ui_mcp_proxy = value;
}
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_UI_MCP_PROXY"));
add_opt(common_arg(
{"--ui-mcp-proxy-allow-private-urls"},
"allow the MCP CORS proxy to reach local or private addresses (e.g. MCP servers on localhost or LAN) - anyone who can reach the proxy can then reach your local network (default: disabled, only public addresses)\n"
"note: only has effect with --ui-mcp-proxy",
[](common_params & params) {
params.ui_mcp_proxy_allow_private_urls = true;
}
).set_examples({LLAMA_EXAMPLE_SERVER}).set_env("LLAMA_ARG_UI_MCP_PROXY_ALLOW_PRIVATE_URLS"));
add_opt(common_arg(
{"--tools"}, "TOOL1,TOOL2,...",
"experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)\n"
+1
View File
@@ -702,6 +702,7 @@ struct common_params {
// UI configs
bool ui = true;
bool ui_mcp_proxy = false;
bool ui_mcp_proxy_allow_private_urls = false; // allow the MCP CORS proxy to reach local or private addresses
std::string ui_config_json;
// "advanced" endpoints are disabled by default for better security
+1
View File
@@ -78,6 +78,7 @@ TEXT_MODEL_MAP: dict[str, str] = {
"DistilBertForMaskedLM": "bert",
"DistilBertForSequenceClassification": "bert",
"DistilBertModel": "bert",
"DomynEdgeForCausalLM": "domynedge",
"Dots1ForCausalLM": "dots1",
"Dots3NoteForCausalLM": "dots3",
"Dots3NoteForConditionalGeneration": "dots3",
+3
View File
@@ -2470,6 +2470,9 @@ class TextModel(ModelBase):
if chkhsh == "5635e1c8d621dff7b4825f41f2f97b6ceb39bcf2d5c541db28577080d6efd5e5":
# ref: https://huggingface.co/thinkingmachines/Inkling-2-Small
res = "inkling2"
if chkhsh == "32d85c31273f8019248f2559fed492d929ea28b17e51d81d3bb36fff23ca72b3":
# ref: https://huggingface.co/domyn/Domyn-Edge-Teacher-IF
res = "domyn-edge"
if res is None:
logger.warning("\n")
+53
View File
@@ -0,0 +1,53 @@
from .base import TextModel, ModelBase
import gguf
@ModelBase.register("DomynEdgeForCausalLM")
@ModelBase.example("domyn/Domyn-Edge-Teacher-IF")
class DomynEdgeModel(TextModel):
model_arch = gguf.MODEL_ARCH.DOMYN_EDGE
def set_gguf_parameters(self):
super().set_gguf_parameters()
hparams = self.hparams
self.gguf_writer.add_vocab_size(hparams["vocab_size"])
position_layers = hparams["position_layers"] # list of "rope"/"nope" strings per layer
head_sizes = hparams["head_sizes"] # list of int head dims per layer
# Per-layer rope/SWA pattern: True="rope", False="nope"
rope_pattern = [v == "rope" for v in position_layers]
self.gguf_writer.add_rope_pattern(rope_pattern)
self.gguf_writer.add_sliding_window_pattern(rope_pattern) # SWA <-> RoPE in domyn-edge
# window_sizes entries are flash-attn style [left, right] (current token excluded; -1 = full attention),
# while llama.cpp's n_swa counts the current token, hence the +1 (matches HF's sliding_window=1025)
swa_window = hparams.get("sliding_window")
if swa_window is None:
window_sizes = hparams.get("window_sizes") # list of [size, offset] pairs per layer
if window_sizes is None:
raise KeyError("Neither `sliding_window` nor `window_sizes` found among domyn edge hyperparameters")
left = next((ws[0] for v, ws in zip(position_layers, window_sizes) if v == "rope"), None)
swa_window = left + 1 if left is not None and left > 0 else None
if swa_window is None:
raise ValueError("No sliding window size found among domyn edge hyperparameters")
self.gguf_writer.add_sliding_window(swa_window)
# Head dims differ between full-attention ("nope") and SWA ("rope") layers
full_head_dims = {h for v, h in zip(position_layers, head_sizes) if v == "nope"}
swa_head_dims = {h for v, h in zip(position_layers, head_sizes) if v == "rope"}
if len(full_head_dims) != 1:
raise ValueError(f"Expected one head dimension for full attention layers, found {len(full_head_dims)}")
full_head_dim = full_head_dims.pop()
self.gguf_writer.add_key_length(full_head_dim)
self.gguf_writer.add_value_length(full_head_dim)
if len(swa_head_dims) != 1:
raise ValueError(f"Expected one head dimension for SWA attention layers, found {len(swa_head_dims)}")
swa_head_dim = swa_head_dims.pop()
self.gguf_writer.add_key_length_swa(swa_head_dim)
self.gguf_writer.add_value_length_swa(swa_head_dim)
self.gguf_writer.add_rope_dimension_count_swa(swa_head_dim)
+3 -3
View File
@@ -168,6 +168,7 @@ models = [
{"name": "mmbert", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/jhu-clsp/mmBERT-base", },
{"name": "k2-horizon", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/IFM/K2-Horizon-36B", },
{"name": "inkling2", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/thinkingmachines/Inkling-2-Small", },
{"name": "domyn-edge", "tokt": TOKENIZER_TYPE.BPE, "repo": "https://huggingface.co/domyn/Domyn-Edge-Teacher-IF", },
]
# some models are known to be broken upstream, so we will skip them as exceptions
@@ -227,8 +228,6 @@ def download_model(model):
repo = model["repo"]
tokt = model["tokt"]
os.makedirs(f"models/tokenizers/{name}", exist_ok=True)
files = ["config.json", "tokenizer.json", "tokenizer_config.json"]
if name == "gpt-4o":
@@ -243,6 +242,7 @@ def download_model(model):
if os.path.isdir(repo):
# If repo is a path on the file system, copy the directory
os.makedirs(f"models/tokenizers/{name}", exist_ok=True)
for file in files:
src_path = os.path.join(repo, file)
dst_path = f"models/tokenizers/{name}/{file}"
@@ -484,7 +484,7 @@ for model in models:
tokenizer = AutoTokenizer.from_pretrained(f"models/tokenizers/{name}", use_fast=False)
else:
tokenizer = AutoTokenizer.from_pretrained(f"models/tokenizers/{name}")
except (OSError, TypeError) as e:
except (OSError, TypeError, ValueError) as e:
logger.error(f"Failed to load tokenizer for model {name}. Error: {e}")
continue # Skip this model and continue with the next one in the loop
+1 -1
View File
@@ -635,7 +635,7 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
set(GGML_CPU_KLEIDIAI_AARCH64 OFF)
if (GGML_SYSTEM_ARCH STREQUAL "ARM" AND
(APPLE OR WIN32 OR CMAKE_SYSTEM_NAME MATCHES "^(Linux|Android)$") AND
(APPLE OR WIN32 OR CMAKE_SYSTEM_NAME MATCHES "^(Linux|Android|OHOS)$") AND
(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64|ARM64|arm64-v8a)$" OR
CMAKE_OSX_ARCHITECTURES MATCHES "arm64" OR
CMAKE_GENERATOR_PLATFORM_LWR STREQUAL "arm64" OR
+361
View File
@@ -1474,6 +1474,282 @@ class tinyBLAS_Q0_VXE {
const int32_t ith;
const int32_t nth;
};
template <typename TA>
class tinyBLAS_QK_VXE {
public:
tinyBLAS_QK_VXE(int64_t k,
const TA * A, int64_t lda,
const block_q8_K * B, int64_t ldb,
float * C, int64_t ldc,
int32_t ith, int32_t nth)
: A(A), B(B), C(C), k(k), lda(lda), ldb(ldb), ldc(ldc), ith(ith), nth(nth) {
}
void matmul(int64_t m, int64_t n) {
const int64_t n4 = n / 4 * 4;
const int64_t n2 = n / 2 * 2;
gemm<4>(m, 0, n4);
gemm<2>(m, n4, n2);
gemm<1>(m, n2, n);
}
private:
// one block of A is loaded once and used for RN columns of B
template <int32_t RN>
void gemm(int64_t m, int64_t n0, int64_t n) {
const int64_t tiles = m * ((n - n0) / RN);
const int64_t duty = (tiles + nth - 1) / nth;
const int64_t start = duty * ith;
const int64_t end = MIN(start + duty, tiles);
for (int64_t job = start; job < end; ++job) {
const int64_t ii = job % m;
const int64_t jj = n0 + RN * (job / m);
float32x4_t v_sum[RN] = {};
for (int64_t l = 0; l < k; ++l) {
const TA & x = A[lda * ii + l];
int8x16_t v_x[n_group];
load(x, v_x);
// scale and minimum of the 16 groups, 8 groups per vector
int16x8_t v_scalel, v_scaleh;
int16x8_t v_minl, v_minh;
load_scale(x, v_scalel, v_scaleh, v_minl, v_minh);
int16x8_t v_scale[n_group];
for (int32_t g = 0; g < n_group; ++g) {
v_scale[g] = vec_splats((g < n_group / 2 ? v_scalel : v_scaleh)[g % (n_group / 2)]);
}
const int8_t * y_qs[RN];
for (int32_t j = 0; j < RN; ++j) {
y_qs[j] = B[ldb * (jj + j) + l].qs;
}
// the columns are in the inner loop, so that their sums do not wait for each other
int32x4_t v_dot[RN] = {};
for (int32_t g = 0; g < n_group; ++g) {
for (int32_t j = 0; j < RN; ++j) {
const int8x16_t v_y = vec_xl(0, y_qs[j] + 16 * g);
const int16x8_t v_xy = vec_meadd(v_x[g], v_y, vec_mulo(v_x[g], v_y));
v_dot[j] = vec_meadd(v_xy, v_scale[g], vec_moadd(v_xy, v_scale[g], v_dot[j]));
}
}
const float x_d = unhalf(x.d);
for (int32_t j = 0; j < RN; ++j) {
const block_q8_K & y = B[ldb * (jj + j) + l];
v_sum[j] = vec_madd(vec_float(v_dot[j]), vec_splats(x_d * y.d), v_sum[j]);
}
if (has_min) {
const float x_dmin = dmin(x);
for (int32_t j = 0; j < RN; ++j) {
const block_q8_K & y = B[ldb * (jj + j) + l];
const int16_t * y_bsums = y.bsums;
const int16x8_t v_bsumsl = vec_xl(0, y_bsums);
const int16x8_t v_bsumsh = vec_xl(0, y_bsums + n_group / 2);
const int32x4_t v_minsl = vec_meadd(v_bsumsl, v_minl, vec_mulo(v_bsumsl, v_minl));
const int32x4_t v_minsh = vec_meadd(v_bsumsh, v_minh, vec_mulo(v_bsumsh, v_minh));
v_sum[j] = vec_madd(vec_float(v_minsl + v_minsh), vec_splats(-x_dmin * y.d), v_sum[j]);
}
}
}
for (int32_t j = 0; j < RN; ++j) {
C[ldc * (jj + j) + ii] = hsum(v_sum[j]);
}
}
}
// a block has 16 groups of 16 weights, Q4_K and Q5_K share one scale and minimum per 2 groups
static constexpr int32_t n_group = QK_K / 16;
// Q3_K and Q6_K have no minimum, their weights are loaded as signed values.
static constexpr bool has_min = !std::is_same<TA, block_q3_K>::value && !std::is_same<TA, block_q6_K>::value;
static float dmin(const block_q2_K & x) { return unhalf(x.dmin); }
static float dmin(const block_q4_K & x) { return unhalf(x.dmin); }
static float dmin(const block_q5_K & x) { return unhalf(x.dmin); }
template <typename T> static float dmin(const T &) { return 0.0f; }
static void load(const block_q2_K & x, int8x16_t * v_x) {
const uint8x16_t v_mask = vec_splats((uint8_t)0x03);
const uint8_t * x_qs = x.qs;
for (int32_t g = 0; g < n_group; ++g) {
const int32_t qs_offset = 16 * (2 * (g / 8) + g % 2);
const int32_t qs_shift = 2 * (g % 8 / 2);
const uint8x16_t v_qs = vec_xl(0, x_qs + qs_offset);
v_x[g] = (int8x16_t)vec_and(vec_sr(v_qs, qs_shift), v_mask);
}
}
static void load(const block_q3_K & x, int8x16_t * v_x) {
const uint8x16_t v_mask = vec_splats((uint8_t)0x03);
const uint8x16_t v_one = vec_splats((uint8_t)0x01);
const uint8_t * x_qs = x.qs;
const uint8_t * x_hmask = x.hmask;
for (int32_t g = 0; g < n_group; ++g) {
const int32_t qs_offset = 16 * (2 * (g / 8) + g % 2);
const int32_t qs_shift = 2 * (g % 8 / 2);
const int32_t hmask_offset = 16 * (g % 2);
const int32_t hmask_shift = g / 2;
const uint8x16_t v_qs = vec_xl(0, x_qs + qs_offset);
const uint8x16_t v_hmask = vec_xl(0, x_hmask + hmask_offset);
const uint8x16_t v_lo = vec_and(vec_sr(v_qs, qs_shift), v_mask);
const uint8x16_t v_hi = vec_sl(vec_and(vec_sr(v_hmask, hmask_shift), v_one), 2);
v_x[g] = (int8x16_t)vec_or(v_lo, v_hi) - vec_splats((int8_t)4);
}
}
static void load(const block_q4_K & x, int8x16_t * v_x) {
const uint8x16_t v_mask = vec_splats((uint8_t)0x0F);
const uint8_t * x_qs = x.qs;
for (int32_t g = 0; g < n_group; ++g) {
const int32_t qs_offset = 16 * (2 * (g / 4) + g % 2);
const bool qs_low = g % 4 < 2;
const uint8x16_t v_qs = vec_xl(0, x_qs + qs_offset);
v_x[g] = (int8x16_t)(qs_low ? vec_and(v_qs, v_mask) : vec_sr(v_qs, 4));
}
}
static void load(const block_q5_K & x, int8x16_t * v_x) {
const uint8x16_t v_mask = vec_splats((uint8_t)0x0F);
const uint8x16_t v_one = vec_splats((uint8_t)0x01);
const uint8_t * x_qs = x.qs;
const uint8_t * x_qh = x.qh;
for (int32_t g = 0; g < n_group; ++g) {
const int32_t qs_offset = 16 * (2 * (g / 4) + g % 2);
const bool qs_low = g % 4 < 2;
const int32_t qh_offset = 16 * (g % 2);
const int32_t qh_shift = g / 2;
const uint8x16_t v_qs = vec_xl(0, x_qs + qs_offset);
const uint8x16_t v_qh = vec_xl(0, x_qh + qh_offset);
const uint8x16_t v_lo = qs_low ? vec_and(v_qs, v_mask) : vec_sr(v_qs, 4);
const uint8x16_t v_hi = vec_sl(vec_and(vec_sr(v_qh, qh_shift), v_one), 4);
v_x[g] = (int8x16_t)vec_or(v_lo, v_hi);
}
}
static void load(const block_q6_K & x, int8x16_t * v_x) {
const uint8x16_t v_mask4 = vec_splats((uint8_t)0x0F);
const uint8x16_t v_mask2 = vec_splats((uint8_t)0x03);
const uint8_t * x_ql = x.ql;
const uint8_t * x_qh = x.qh;
for (int32_t g = 0; g < n_group; ++g) {
const int32_t ql_offset = 16 * (4 * (g / 8) + 2 * (g % 4 / 2) + g % 2);
const bool ql_low = g % 8 < 4;
const int32_t qh_offset = 16 * (2 * (g / 8) + g % 2);
const int32_t qh_shift = 2 * (g % 8 / 2);
const uint8x16_t v_ql = vec_xl(0, x_ql + ql_offset);
const uint8x16_t v_qh = vec_xl(0, x_qh + qh_offset);
const uint8x16_t v_lo = ql_low ? vec_and(v_ql, v_mask4) : vec_sr(v_ql, 4);
const uint8x16_t v_hi = vec_sl(vec_and(vec_sr(v_qh, qh_shift), v_mask2), 4);
v_x[g] = (int8x16_t)vec_or(v_lo, v_hi) - vec_splats((int8_t)32);
}
}
static void load_scale(const block_q2_K & x, int16x8_t & v_scalel, int16x8_t & v_scaleh, int16x8_t & v_minl, int16x8_t & v_minh) {
const uint8_t * x_scales = x.scales;
const uint8x16_t v_s = vec_xl(0, x_scales);
const uint8x16_t v_scale = vec_and(v_s, vec_splats((uint8_t)0x0F));
const uint8x16_t v_min = vec_sr(v_s, 4);
v_scalel = (int16x8_t)vec_unpackh(v_scale);
v_scaleh = (int16x8_t)vec_unpackl(v_scale);
v_minl = (int16x8_t)vec_unpackh(v_min);
v_minh = (int16x8_t)vec_unpackl(v_min);
}
static void load_scale(const block_q3_K & x, int16x8_t & v_scalel, int16x8_t & v_scaleh, int16x8_t & v_minl, int16x8_t & v_minh) {
// 6-bit scales: low 4 bits in scales[0..7], high 2 bits in scales[8..11]
const uint8x16_t v_lo_byte = { 4, 5, 6, 7, 8, 9, 10, 11, 4, 5, 6, 7, 8, 9, 10, 11 };
const uint8x16_t v_lo_shift = { 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4 };
const uint8x16_t v_hi_byte = { 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15, 12, 13, 14, 15 };
const uint8x16_t v_hi_shift = { 0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6 };
// the load starts 4 bytes before scales, so that it stays inside the block
const uint8_t * x_qs = x.qs;
const uint8x16_t v_s = vec_xl(0, x_qs + sizeof(x.qs) - 4);
const uint8x16_t v_lo = vec_and(vec_sr(vec_perm(v_s, v_s, v_lo_byte), v_lo_shift), vec_splats((uint8_t)0x0F));
const uint8x16_t v_hi = vec_sl(vec_and(vec_sr(vec_perm(v_s, v_s, v_hi_byte), v_hi_shift), vec_splats((uint8_t)0x03)), 4);
const int8x16_t v_scale = (int8x16_t)vec_or(v_lo, v_hi) - vec_splats((int8_t)32);
v_scalel = vec_unpackh(v_scale);
v_scaleh = vec_unpackl(v_scale);
v_minl = vec_splats((int16_t)0);
v_minh = vec_splats((int16_t)0);
}
static void load_scale(const block_q4_K & x, int16x8_t & v_scalel, int16x8_t & v_scaleh, int16x8_t & v_minl, int16x8_t & v_minh) {
load_scale_min_k4(x.scales, v_scalel, v_scaleh, v_minl, v_minh);
}
static void load_scale(const block_q5_K & x, int16x8_t & v_scalel, int16x8_t & v_scaleh, int16x8_t & v_minl, int16x8_t & v_minh) {
load_scale_min_k4(x.scales, v_scalel, v_scaleh, v_minl, v_minh);
}
static void load_scale(const block_q6_K & x, int16x8_t & v_scalel, int16x8_t & v_scaleh, int16x8_t & v_minl, int16x8_t & v_minh) {
const int8_t * x_scales = x.scales;
const int8x16_t v_scale = vec_xl(0, x_scales);
v_scalel = vec_unpackh(v_scale);
v_scaleh = vec_unpackl(v_scale);
v_minl = vec_splats((int16_t)0);
v_minh = vec_splats((int16_t)0);
}
// 8 scales and 8 minimums of 6 bits, same packing as get_scale_min_k4 in ggml-quants.c
static void load_scale_min_k4(const uint8_t * q, int16x8_t & v_scalel, int16x8_t & v_scaleh, int16x8_t & v_minl, int16x8_t & v_minh) {
// bytes 0..3 and 4..7 have the high 2 bits of scale 4..7 and minimum 4..7, move them to bytes 8..11
const uint8x16_t v_hi_scale = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0 };
const uint8x16_t v_hi_min = { 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 0, 0, 0, 0 };
// each scale and minimum is for 2 groups
const uint8x16_t v_group_scale = { 0, 0, 1, 1, 2, 2, 3, 3, 24, 24, 25, 25, 26, 26, 27, 27 };
const uint8x16_t v_group_min = { 4, 4, 5, 5, 6, 6, 7, 7, 24, 24, 25, 25, 26, 26, 27, 27 };
// the 4 bytes after the 12 scale bytes are in the same block
const uint8x16_t v_s = vec_xl(0, q);
const uint8x16_t v_lo = vec_and(v_s, vec_splats((uint8_t)0x3F));
const uint8x16_t v_hi = vec_sl(vec_sr(v_s, 6), 4);
const uint8x16_t v_scale_47 = vec_or(vec_and(v_s, vec_splats((uint8_t)0x0F)), vec_perm(v_hi, v_hi, v_hi_scale));
const uint8x16_t v_min_47 = vec_or(vec_sr(v_s, 4), vec_perm(v_hi, v_hi, v_hi_min));
const uint8x16_t v_scale = vec_perm(v_lo, v_scale_47, v_group_scale);
const uint8x16_t v_min = vec_perm(v_lo, v_min_47, v_group_min);
v_scalel = (int16x8_t)vec_unpackh(v_scale);
v_scaleh = (int16x8_t)vec_unpackl(v_scale);
v_minl = (int16x8_t)vec_unpackh(v_min);
v_minh = (int16x8_t)vec_unpackl(v_min);
}
const TA * const A;
const block_q8_K * const B;
float * const C;
const int64_t k;
const int64_t lda;
const int64_t ldb;
const int64_t ldc;
const int32_t ith;
const int32_t nth;
};
#endif
#if defined(__ARM_FEATURE_DOTPROD)
@@ -4488,6 +4764,91 @@ bool llamafile_sgemm(const struct ggml_compute_params * params, int64_t m, int64
#endif
}
case GGML_TYPE_Q2_K: {
if (Btype != GGML_TYPE_Q8_K) {
return false;
}
#if defined(__VXE__) || defined(__VXE2__)
tinyBLAS_QK_VXE<block_q2_K> tb{
k, (const block_q2_K *)A, lda,
(const block_q8_K *)B, ldb,
(float *)C, ldc,
params->ith, params->nth};
tb.matmul(m, n);
return true;
#else
return false;
#endif
}
case GGML_TYPE_Q3_K: {
if (Btype != GGML_TYPE_Q8_K) {
return false;
}
#if defined(__VXE__) || defined(__VXE2__)
tinyBLAS_QK_VXE<block_q3_K> tb{
k, (const block_q3_K *)A, lda,
(const block_q8_K *)B, ldb,
(float *)C, ldc,
params->ith, params->nth};
tb.matmul(m, n);
return true;
#else
return false;
#endif
}
case GGML_TYPE_Q4_K: {
if (Btype != GGML_TYPE_Q8_K) {
return false;
}
#if defined(__VXE__) || defined(__VXE2__)
tinyBLAS_QK_VXE<block_q4_K> tb{
k, (const block_q4_K *)A, lda,
(const block_q8_K *)B, ldb,
(float *)C, ldc,
params->ith, params->nth};
tb.matmul(m, n);
return true;
#else
return false;
#endif
}
case GGML_TYPE_Q5_K: {
if (Btype != GGML_TYPE_Q8_K) {
return false;
}
#if defined(__VXE__) || defined(__VXE2__)
tinyBLAS_QK_VXE<block_q5_K> tb{
k, (const block_q5_K *)A, lda,
(const block_q8_K *)B, ldb,
(float *)C, ldc,
params->ith, params->nth};
tb.matmul(m, n);
return true;
#else
return false;
#endif
}
case GGML_TYPE_Q6_K: {
if (Btype != GGML_TYPE_Q8_K) {
return false;
}
#if defined(__VXE__) || defined(__VXE2__)
tinyBLAS_QK_VXE<block_q6_K> tb{
k, (const block_q6_K *)A, lda,
(const block_q8_K *)B, ldb,
(float *)C, ldc,
params->ith, params->nth};
tb.matmul(m, n);
return true;
#else
return false;
#endif
}
case GGML_TYPE_IQ4_NL: {
if (Btype != GGML_TYPE_Q8_0)
return false;
+1 -1
View File
@@ -6798,7 +6798,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g
case GGML_OP_RWKV_WKV7:
return true;
case GGML_OP_GATED_DELTA_NET:
return true;
return ggml_are_same_stride(op->src[0], op->src[1]);
case GGML_OP_DSV4_HC_COMB:
return op->src[0]->type == GGML_TYPE_F32 && op->src[1]->type == GGML_TYPE_F32 &&
op->src[2]->type == GGML_TYPE_F32 && op->type == GGML_TYPE_F32;
+5 -3
View File
@@ -53,12 +53,14 @@ var<uniform> params: Params;
@compute @workgroup_size(WG_SIZE)
fn main(
@builtin(global_invocation_id) gid: vec3<u32>,
@builtin(num_workgroups) num_wg: vec3<u32>,
) {
if (gid.x >= params.ne) {
let idx = gid.x + num_wg.x * WG_SIZE * gid.y;
if (idx >= params.ne) {
return;
}
var i = gid.x;
var i = idx;
let i3 = i / (params.src_ne2 * params.src_ne1 * params.src_ne0);
i = i % (params.src_ne2 * params.src_ne1 * params.src_ne0);
let i2 = i / (params.src_ne1 * params.src_ne0);
@@ -66,7 +68,7 @@ fn main(
let i1 = i / params.src_ne0;
let i0 = i % params.src_ne0;
var j = gid.x;
var j = idx;
let j3 = j / (params.dst_ne2 * params.dst_ne1 * params.dst_ne0);
j = j % (params.dst_ne2 * params.dst_ne1 * params.dst_ne0);
let j2 = j / (params.dst_ne1 * params.dst_ne0);
+18
View File
@@ -778,6 +778,7 @@ class MODEL_ARCH(IntEnum):
KOLIBRI1 = auto()
LIMITE = auto()
INKLING2 = auto()
DOMYN_EDGE = auto()
class VISION_PROJECTOR_TYPE(IntEnum):
@@ -1778,6 +1779,7 @@ MODEL_ARCH_NAMES: dict[MODEL_ARCH, str] = {
MODEL_ARCH.KOLIBRI1: "kolibri1",
MODEL_ARCH.LIMITE: "limite",
MODEL_ARCH.INKLING2: "inkling2",
MODEL_ARCH.DOMYN_EDGE: "domynedge",
}
VISION_PROJECTOR_TYPE_NAMES: dict[VISION_PROJECTOR_TYPE, str] = {
@@ -7085,6 +7087,22 @@ MODEL_TENSORS: dict[MODEL_ARCH, list[MODEL_TENSOR]] = {
MODEL_TENSOR.FFN_POST_CONV,
MODEL_TENSOR.FFN_RES_QUERY,
],
MODEL_ARCH.DOMYN_EDGE: [
MODEL_TENSOR.TOKEN_EMBD,
MODEL_TENSOR.ATTN_Q,
MODEL_TENSOR.ATTN_K,
MODEL_TENSOR.ATTN_V,
MODEL_TENSOR.ATTN_OUT,
MODEL_TENSOR.ATTN_K_NORM,
MODEL_TENSOR.ATTN_NORM,
MODEL_TENSOR.ATTN_POST_NORM,
MODEL_TENSOR.FFN_PRE_NORM,
MODEL_TENSOR.FFN_POST_NORM,
MODEL_TENSOR.FFN_DOWN,
MODEL_TENSOR.FFN_UP,
MODEL_TENSOR.FFN_GATE,
MODEL_TENSOR.OUTPUT_NORM,
],
}
# tensors that will not be serialized
+8
View File
@@ -272,6 +272,7 @@ class TensorNameMap:
"model.layers.{bid}.pre_attention_layernorm", # kormo
"head.layers.{bid}.norm1", # laya
"model.layers.{bid}.attn_norm", # inkling2
"model.layers.{bid}.pre_attention_norm", # domynedge
),
# Attention norm 2
@@ -440,6 +441,7 @@ class TensorNameMap:
"model.layers.{bid}.post_attn_norm", # kolibri1
"model.layers.layers.{bid}.post_mixer_norm.weight", # plamo2
"model.layers.{bid}.post_operator_norm", # lfm3
"model.layers.{bid}.post_attention_norm", # domynedge
),
# Rotary embeddings
@@ -579,6 +581,7 @@ class TensorNameMap:
"layers.{bid}.pre_feedforward_layernorm", # embeddinggemma
"model.layers.{bid}.pre_ff_layernorm.weight",
"model.layers.{bid}.pre_mlp_layernorm", # afmoe
"model.layers.{bid}.pre_feedforward_norm", # domynedge
),
MODEL_TENSOR.FFN_PRE_NORM_2: (
@@ -603,6 +606,7 @@ class TensorNameMap:
"model.layers.{bid}.feed_forward.up_proj",
"model.layers.{bid}.post_moe_norm", # grok-2
"model.layers.{bid}.post_ffn_norm", # lfm3
"model.layers.{bid}.post_feedforward_norm", # domynedge
),
MODEL_TENSOR.FFN_POST_NORM_1: (
@@ -692,6 +696,7 @@ class TensorNameMap:
"encoder.layers.{bid}.mlp.dense_h_to_4h", # chatglm
"transformer.h.{bid}.mlp.c_fc_1", # exaone
"model.layers.{bid}.feed_forward.up_proj", # llama4 jamba granite-hybrid
"model.layers.{bid}.feedforward.up_proj", # domynedge
"transformer_encoder.{bid}.ffn.w12", # neobert
"model.layers.{bid}.block_sparse_moe.up", # smallthinker
"model.transformer.blocks.{bid}.up_proj", # llada
@@ -755,6 +760,7 @@ class TensorNameMap:
"layers.{bid}.mlp.gate_proj", # qwen3-embedding
"model.layers.{bid}.mlp.language_mlp.gate_proj", # cogvlm
"model.blocks.{bid}.mlp.mlp_gate", # talkie
"model.layers.{bid}.feedforward.gate_proj", # domynedge
),
MODEL_TENSOR.FFN_GATE_EXP: (
@@ -923,6 +929,7 @@ class TensorNameMap:
"encoder.layers.{bid}.mlp.dense_4h_to_h", # chatglm
"model.layers.h.{bid}.mlp.c_proj", # exaone
"model.layers.{bid}.feed_forward.down_proj", # llama4 jamba granite-hybrid
"model.layers.{bid}.feedforward.down_proj", # domynedge
"transformer_encoder.{bid}.ffn.w3", # neobert
"model.layers.{bid}.block_sparse_moe.down", # smallthinker
"model.transformer.blocks.{bid}.ff_out", # llada
@@ -997,6 +1004,7 @@ class TensorNameMap:
"layers.{bid}.self_attn.k_norm", # qwen3-embedding
"model.layers.{bid}.self_attn.k_rope_only_layernorm", # dots3note
"model.layers.{bid}.attention.key_layernorm", # apertus
"model.layers.{bid}.attention.k_norm", # domynedge
),
MODEL_TENSOR.ROPE_FREQS: (
+1 -1
View File
@@ -264,7 +264,7 @@ def benchmark(
bin_max = np.ceil(token_t_last) + 1
plt.figure()
plt.hist(token_t, np.linspace(0, bin_max, bin_max, endpoint=False).tolist())
plt.hist(token_t, np.linspace(0, bin_max, int(bin_max), endpoint=False).tolist())
plt.xlim(0, bin_max + 1)
plt.title(name or "")
plt.xlabel("Time [s]")
+1
View File
@@ -184,6 +184,7 @@ static const std::map<llm_arch, const char *> LLM_ARCH_NAMES = {
{ LLM_ARCH_KOLIBRI1, "kolibri1" },
{ LLM_ARCH_RICURSIVE, "ricursive" },
{ LLM_ARCH_INKLING2, "inkling2" },
{ LLM_ARCH_DOMYN_EDGE, "domynedge" },
{ LLM_ARCH_UNKNOWN, "(unknown)" },
};
+1
View File
@@ -188,6 +188,7 @@ enum llm_arch {
LLM_ARCH_LIMITE,
LLM_ARCH_RICURSIVE,
LLM_ARCH_INKLING2,
LLM_ARCH_DOMYN_EDGE,
LLM_ARCH_UNKNOWN,
};
+9 -36
View File
@@ -2911,42 +2911,15 @@ void llama_context::output_reorder() {
//
uint32_t llama_context::graph_max_nodes() const {
uint32_t res;
if (model.arch == LLM_ARCH_KIMI_K3 || model.arch == LLM_ARCH_KIMI_K31 || model.arch == LLM_ARCH_GLM5_NEXT ||
model.arch == LLM_ARCH_HRM_TEXT) {
res = std::max<uint32_t>(1024u, 64u * model.n_tensors());
} else if (model.arch == LLM_ARCH_QWEN3NEXT ||
model.arch == LLM_ARCH_KIMI_LINEAR ||
model.arch == LLM_ARCH_METIS16 ||
model.arch == LLM_ARCH_BAILINGMOE3 ||
model.arch == LLM_ARCH_QWEN35 ||
model.arch == LLM_ARCH_QWEN35MOE ||
model.arch == LLM_ARCH_ZONOS3 ||
model.arch == LLM_ARCH_CLEF ||
model.arch == LLM_ARCH_CLOVER_MOE ||
model.arch == LLM_ARCH_QWEN4EXP ||
model.arch == LLM_ARCH_DEEPSEEK4 ||
model.arch == LLM_ARCH_DEEPSEEK41 ||
model.arch == LLM_ARCH_XING4_0 ||
(model.arch == LLM_ARCH_DFLASH && model.hparams.dsv4_hc_mult > 0) ||
model.arch == LLM_ARCH_NANBEIGE ||
model.arch == LLM_ARCH_MINIMAX_01 ||
model.arch == LLM_ARCH_MINIMAX_M3 ||
model.arch == LLM_ARCH_HY_V4 ||
model.arch == LLM_ARCH_INKLING2) {
res = std::max<uint32_t>(1024u, 32u * model.n_tensors());
} else if (model.arch == LLM_ARCH_DFLASH && model.hparams.dflash_selector_rank > 0) {
// DFlash2's convolutions and selector are shape work rather than matmuls,
// so they cost ~8.6 nodes per tensor against ~5.9 for a plain DFlash draft.
// The selector lattice scales with the draft block size; 12u was calibrated
// on block-8 drafters, so scale the budget for larger blocks (e.g. Ripple's 16).
const uint32_t block_scale = std::max<uint32_t>(1u, model.hparams.dflash_block_size/8u);
res = std::max<uint32_t>(1024u, 12u*block_scale*model.n_tensors());
} else {
res = std::max<uint32_t>(1024u, 8u*model.n_tensors());
for (const auto & lora : model.loras) {
res += lora->get_n_nodes();
}
uint32_t res = std::max<uint32_t>(1024u, model.graph_nodes_per_tensor()*model.n_tensors());
for (const auto & lora : model.loras) {
res += lora->get_n_nodes();
}
// the MoE cache adds a lookup to each MoE layer, and a second expert path with a CPU share (up to ~16 tensors per layer),
// which the per-tensor estimates above do not cover for models with few tensors per layer
if (cparams.moe_cache_size > 0) {
res += 32u*model.hparams.n_layer_all;
}
// every sampler builds n_outputs_max_per_seq chains, see llm_graph_context::build_sampling
+2 -5
View File
@@ -314,11 +314,8 @@ llama_kv_cache::llama_kv_cache(
ggml_is_quantized(type_k) &&
hparams.n_embd_head_k() % 64 == 0;
// always create Hadamard rotation tensors for DeepSeek lightning indexers
if ((model.arch == LLM_ARCH_DEEPSEEK32 || model.arch == LLM_ARCH_DEEPSEEK4 ||
model.arch == LLM_ARCH_GLM_DSA || model.arch == LLM_ARCH_DOTS3NOTE ||
model.arch == LLM_ARCH_MISTRAL_LARGE4) &&
hparams.n_embd_head_k_full == hparams.indexer_head_size) {
// always create Hadamard rotation tensors for lightning indexer keys
if (model.lid_k_hdmd() && hparams.n_embd_head_k_full == hparams.indexer_head_size) {
attn_rot_k = true;
}
+9
View File
@@ -394,6 +394,8 @@ static llama_model * llama_model_mapping(llm_arch arch, const llama_model_params
return new llama_model_k2_horizon(params);
case LLM_ARCH_KOLIBRI1:
return new llama_model_kolibri1(params);
case LLM_ARCH_DOMYN_EDGE:
return new llama_model_domyn_edge(params);
default:
throw std::runtime_error(std::string("unsupported model architecture: '") + llm_arch_name(arch) + "'");
}
@@ -1909,6 +1911,12 @@ bool llama_model_base::load_tensors(llama_model_loader & ml) {
}
if (!layer.ffn_up_exps_s && layer.ffn_up_exps) {
layer.ffn_up_exps_s = create_tensor(tn(LLM_TENSOR_FFN_UP_EXPS, "scale", i), {n_expert}, TENSOR_NOT_REQUIRED);
if (layer.ffn_up_exps_s && layer.ffn_gate_up_exps) {
throw std::runtime_error(format("ffn_up_exps.scale and ffn_gate_up_exps.weight both exist for layer %d", i));
}
}
if (!layer.ffn_up_exps_s && layer.ffn_gate_up_exps) {
layer.ffn_up_exps_s = create_tensor(tn(LLM_TENSOR_FFN_GATE_UP_EXPS, "scale", i), {n_expert}, TENSOR_NOT_REQUIRED);
}
// recurrent / linear-attention weight scales (per-tensor, shape {1})
@@ -3873,6 +3881,7 @@ llama_rope_type llama_model_rope_type(const llama_model * model) {
case LLM_ARCH_HRM_TEXT:
case LLM_ARCH_BEAM:
case LLM_ARCH_KOLIBRI1:
case LLM_ARCH_DOMYN_EDGE:
return LLAMA_ROPE_TYPE_NEOX;
case LLM_ARCH_DFLASH:
+6
View File
@@ -1052,6 +1052,12 @@ struct llama_model {
llama_memory_i * create_memory(const llama_memory_params & params, const llama_cparams & cparams) const;
// graph size budget: max graph nodes per model tensor
virtual uint32_t graph_nodes_per_tensor() const { return 8; }
// apply Hadamard transform to the lightning indexer keys
virtual bool lid_k_hdmd() const { return false; }
ggml_cgraph * build_graph(const llm_graph_params & params) const;
virtual void load_stats (llama_model_loader & ml) = 0;
+2 -1
View File
@@ -2566,7 +2566,8 @@ void llama_vocab::impl::load(llama_model_loader & ml, const LLM_KV & kv) {
tokenizer_pre == "qwen2" ||
tokenizer_pre == "deepseek-r1-qwen" ||
tokenizer_pre == "kormo" ||
tokenizer_pre == "f2llmv2") {
tokenizer_pre == "f2llmv2" ||
tokenizer_pre == "domyn-edge") {
pre_type = LLAMA_VOCAB_PRE_TYPE_QWEN2;
clean_spaces = false;
} else if (
+14
View File
@@ -125,6 +125,20 @@ void llama_model_dflash::load_arch_tensors(llama_model_loader &) {
}
}
uint32_t llama_model_dflash::graph_nodes_per_tensor() const {
if (hparams.dsv4_hc_mult > 0) {
return 32;
}
if (hparams.dflash_selector_rank > 0) {
// DFlash2's convolutions and selector are shape work rather than matmuls,
// so they cost ~8.6 nodes per tensor against ~5.9 for a plain DFlash draft.
// The selector lattice scales with the draft block size; 12u was calibrated
// on block-8 drafters, so scale the budget for larger blocks (e.g. Ripple's 16).
return 12u*std::max<uint32_t>(1u, hparams.dflash_block_size/8u);
}
return llama_model_base::graph_nodes_per_tensor();
}
void llama_model_dflash::load_tensors_layers_base() {
LLAMA_LOAD_LOCALS;
+164
View File
@@ -0,0 +1,164 @@
#include "models.h"
void llama_model_domyn_edge::load_arch_hparams(llama_model_loader & ml) {
ml.get_key(LLM_KV_ATTENTION_LAYERNORM_RMS_EPS, hparams.f_norm_rms_eps);
ml.get_key(LLM_KV_ATTENTION_SLIDING_WINDOW, hparams.n_swa);
// required: the base loader defaults it to n_rot_full if the key is not found
ml.get_key(LLM_KV_ROPE_DIMENSION_COUNT_SWA, hparams.n_rot_swa);
// RoPE cannot rotate more dims than the SWA head has: CPU aborts, GPU backends read past the row
if (hparams.n_rot_swa > hparams.n_embd_head_k_swa) {
throw std::runtime_error(format("invalid n_rot_swa: %u, max %u", hparams.n_rot_swa, hparams.n_embd_head_k_swa));
}
hparams.swa_type = LLAMA_SWA_TYPE_STANDARD;
ml.get_arr(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, hparams.is_swa_impl);
ml.get_arr(LLM_KV_ATTENTION_ROPE_PATTERN, hparams.rope_pattern);
// only for print_info / saver; get_rope_params uses cparams
hparams.rope_freq_base_train_swa = hparams.rope_freq_base_train;
hparams.rope_freq_scale_train_swa = hparams.rope_freq_scale_train;
switch (hparams.n_layer()) {
case 36: type = LLM_TYPE_4B; break;
default: type = LLM_TYPE_UNKNOWN;
}
}
void llama_model_domyn_edge::load_arch_tensors(llama_model_loader &) {
LLAMA_LOAD_LOCALS;
tok_embd = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, 0);
output_norm = create_tensor(tn(LLM_TENSOR_OUTPUT_NORM, "weight"), {n_embd}, 0);
output = create_tensor(tn(LLM_TENSOR_OUTPUT, "weight"), {n_embd, n_vocab}, TENSOR_NOT_REQUIRED);
// if output is NULL, init from the input tok embed
if (output == NULL) {
output = create_tensor(tn(LLM_TENSOR_TOKEN_EMBD, "weight"), {n_embd, n_vocab}, TENSOR_DUPLICATED);
}
for (int i = 0; i < n_layer; ++i) {
auto & layer = layers[i];
const int64_t n_embd_head_i = hparams.n_embd_head_k(i);
const int64_t n_embd_k_i = hparams.n_embd_k_gqa(i);
const int64_t n_embd_v_i = hparams.n_embd_v_gqa(i);
layer.attn_norm = create_tensor(tn(LLM_TENSOR_ATTN_NORM, "weight", i), {n_embd}, 0);
layer.attn_post_norm = create_tensor(tn(LLM_TENSOR_ATTN_POST_NORM, "weight", i), {n_embd}, 0);
const int64_t n_embd_q_i = n_embd_head_i * n_head;
create_tensor_qkv(layer, i, n_embd, n_embd_q_i, n_embd_k_i, n_embd_v_i, 0);
layer.wo = create_tensor(tn(LLM_TENSOR_ATTN_OUT, "weight", i), {n_embd_head_i * n_head, n_embd}, 0);
// K-norm has a learnable weight; Q-norm does not
layer.attn_k_norm = create_tensor(tn(LLM_TENSOR_ATTN_K_NORM, "weight", i), {n_embd_head_i}, 0);
layer.ffn_norm = create_tensor(tn(LLM_TENSOR_FFN_NORM, "weight", i), {n_embd}, 0);
layer.ffn_post_norm = create_tensor(tn(LLM_TENSOR_FFN_POST_NORM, "weight", i), {n_embd}, 0);
layer.ffn_gate = create_tensor(tn(LLM_TENSOR_FFN_GATE, "weight", i), {n_embd, n_ff}, 0);
layer.ffn_up = create_tensor(tn(LLM_TENSOR_FFN_UP, "weight", i), {n_embd, n_ff}, 0);
layer.ffn_down = create_tensor(tn(LLM_TENSOR_FFN_DOWN, "weight", i), {n_ff, n_embd}, 0);
}
}
llama_rope_params llama_model_domyn_edge::get_rope_params(const llama_cparams & cparams, int il) const {
auto res = llama_model::get_rope_params(cparams, il);
// the SWA layers use the global base and scale
res.freq_base = cparams.rope_freq_base;
res.freq_scale = cparams.rope_freq_scale;
return res;
}
llama_model_domyn_edge::graph::graph(const llm_graph_params & params)
: llm_graph_context(params) {
ggml_tensor * cur;
ggml_tensor * inpL = build_inp_embd(model.tok_embd);
ggml_tensor * inp_pos = build_inp_pos();
auto * inp_attn = build_attn_inp_kv_iswa();
ggml_tensor * inp_out_ids = build_inp_out_ids();
for (int il = 0; il < n_layer; ++il) {
const auto & layer = model.layers[il];
const int64_t n_embd_head = hparams.n_embd_head_k(il);
const int64_t n_head_il = hparams.n_head(il);
const int64_t n_head_kv_il = hparams.n_head_kv(il);
const float kq_scale = 1.0f / sqrtf((float)n_embd_head);
ggml_tensor * residual = inpL;
// pre-attention norm
cur = build_norm(inpL, layer.attn_norm, NULL, LLM_NORM_RMS, il);
cb(cur, "attn_norm", il);
auto [Qcur, Kcur, Vcur] = build_qkv(layer, cur, n_embd_head, n_head_il, n_head_kv_il, il);
// Q-norm: RMSNorm without learnable weight (elementwise_affine=False)
Qcur = build_norm(Qcur, NULL, NULL, LLM_NORM_RMS, il);
cb(Qcur, "Qcur_normed", il);
// K-norm: RMSNorm with learnable weight
Kcur = build_norm(Kcur, layer.attn_k_norm, NULL, LLM_NORM_RMS, il);
cb(Kcur, "Kcur_normed", il);
// build_rope already applies RoPE only if the current layer is a RoPE layer
Qcur = build_rope(Qcur, inp_pos, il);
cb(Qcur, "Qcur_rope", il);
Kcur = build_rope(Kcur, inp_pos, il);
cb(Kcur, "Kcur_rope", il);
cur = build_attn(inp_attn,
layer.wo, NULL, layer.wo_s,
Qcur, Kcur, Vcur, nullptr, nullptr, nullptr, kq_scale, il);
cb(cur, "attn_out", il);
// post-attention norm applied to attn output before residual add
cur = build_norm(cur, layer.attn_post_norm, NULL, LLM_NORM_RMS, il);
cb(cur, "attn_post_norm", il);
if (il == n_layer - 1 && inp_out_ids) {
cur = ggml_get_rows(ctx0, cur, inp_out_ids);
residual = ggml_get_rows(ctx0, residual, inp_out_ids);
}
ggml_tensor * ffn_inp = ggml_add(ctx0, cur, residual);
cb(ffn_inp, "ffn_inp", il);
// pre-FFN norm
cur = build_norm(ffn_inp, layer.ffn_norm, NULL, LLM_NORM_RMS, il);
cb(cur, "ffn_norm", il);
// SwiGLU FFN
cur = build_ffn(cur,
layer.ffn_up, NULL, NULL,
layer.ffn_gate, NULL, NULL,
layer.ffn_down, NULL, NULL, NULL,
LLM_FFN_SILU, LLM_FFN_PAR, il);
cb(cur, "ffn_out", il);
// post-FFN norm applied to ffn output before residual add
cur = build_norm(cur, layer.ffn_post_norm, NULL, LLM_NORM_RMS, il);
cb(cur, "ffn_post_norm", il);
cur = ggml_add(ctx0, cur, ffn_inp);
inpL = build_cvec(cur, il);
cb(inpL, "l_out", il);
}
cur = build_norm(inpL, model.output_norm, NULL, LLM_NORM_RMS, -1);
cb(cur, "result_norm", -1);
res->t_embd = cur;
cur = build_lora_mm(model.output, cur, model.output_s);
cb(cur, "result_output", -1);
res->t_logits = cur;
}
std::unique_ptr<llm_graph_context> llama_model_domyn_edge::build_arch_graph(const llm_graph_params & params) const {
return std::make_unique<graph>(params);
}
+151 -17
View File
@@ -157,6 +157,29 @@ static ggml_tensor * gemma4_view_2d_slice(ggml_context * ctx0, ggml_tensor * x,
return ggml_view_2d(ctx0, x, x->ne[0], x->ne[1], x->nb[1], idx * x->nb[2]);
}
class llm_graph_input_gemma4_prune : public llm_graph_input_i {
int64_t n_slices;
int64_t n_slice_tokens;
int64_t n_slice_outputs;
public:
ggml_tensor * full_mask = nullptr;
ggml_tensor * full_mask_swa = nullptr;
ggml_tensor * out_mask = nullptr;
ggml_tensor * out_mask_swa = nullptr;
ggml_tensor * inp_prune_ids = nullptr;
ggml_tensor * inp_prune_keep = nullptr;
llm_graph_input_gemma4_prune(int64_t n_slices, int64_t n_slice_tokens, int64_t n_slice_outputs)
: n_slices(n_slices), n_slice_tokens(n_slice_tokens), n_slice_outputs(n_slice_outputs) {}
void set_input(const llama_ubatch * ubatch) override;
bool can_reuse(const llm_graph_params & params) override;
static int64_t max_outputs_per_slice(
const llama_ubatch & ubatch, int64_t n_slices, int64_t n_slice_tokens
);
};
llama_model_gemma4::graph::graph(const llm_graph_params & params) :
llm_graph_context(params),
n_embd_per_layer(model.hparams.n_embd_per_layer) {
@@ -181,11 +204,8 @@ llama_model_gemma4::graph::graph(const llm_graph_params & params) :
// TODO: is causal == true correct? might need some changes
auto * inp_attn = build_attn_inp_kv_iswa();
auto inp_attn_full = *inp_attn;
auto inp_attn_prune = *inp_attn;
ggml_tensor * inp_out_ids = build_inp_out_ids();
if (model.per_layer_tok_embd) {
// fold per_layer_input_scale (1/sqrt(2)) from project_per_layer_inputs() into tok_embd_scale
const float tok_embd_scale = sqrtf((float) n_embd_per_layer) / sqrtf(2.0f);
@@ -197,34 +217,57 @@ llama_model_gemma4::graph::graph(const llm_graph_params & params) :
inp_per_layer = project_per_layer_inputs(inpL, inp_per_layer);
}
const bool needs_unmasked_nextn =
cparams.embeddings_nextn && !cparams.embeddings_nextn_masked;
// KV-shared layers do not write to the KV cache, so prune non-output token rows before the first KV-shared layer
bool prune_shared = crop_before_nextn(inp_out_ids) &&
bool prune_shared = !needs_unmasked_nextn &&
hparams.n_layer_kv_from_start > 0 && hparams.n_layer_kv_from_start < n_layer &&
!cparams.embeddings && cparams.n_seq_max == 1;
!cparams.embeddings;
for (int il = (int) hparams.n_layer_kv_from_start; prune_shared && il <= n_layer; ++il) {
prune_shared = !cparams.embeddings_layer_inp[il];
}
int64_t n_rows = n_tokens;
ggml_tensor * inp_prune_ids = nullptr;
ggml_tensor * inp_prune_keep = nullptr;
ggml_tensor * inp_out_ids = prune_shared ? nullptr : build_inp_out_ids();
for (int il = 0; il < n_layer; ++il) {
if (prune_shared && il == (int) hparams.n_layer_kv_from_start) {
inpL = ggml_get_rows(ctx0, inpL, inp_out_ids);
inp_pos = ggml_reshape_1d(ctx0, ggml_get_rows(ctx0, ggml_reshape_2d(ctx0, inp_pos, 1, n_tokens), inp_out_ids), n_outputs);
ggml_tensor * full = inp_attn->self_attn_mask.raw;
ggml_tensor * full_swa = inp_attn->self_attn_mask_swa.raw;
// TODO: instead of doing get_rows here, extend llm_attn_mask to have a `out` mask that
// is construted during set_input to contain just the pruned output cells
// this can be used to enable pruning with more than 1 sequence, both with unified and split KV cache
// ref: https://github.com/ggml-org/llama.cpp/pull/31356#discussion_r4455286628
inp_attn_prune.self_attn_mask.raw = ggml_get_rows(ctx0, inp_attn_full.self_attn_mask.raw, inp_out_ids);
inp_attn_prune.self_attn_mask_swa.raw = ggml_get_rows(ctx0, inp_attn_full.self_attn_mask_swa.raw, inp_out_ids);
const int64_t n_slices = full->ne[3], n_slice_tokens = full->ne[1];
const int64_t n_slice_outputs = llm_graph_input_gemma4_prune::max_outputs_per_slice(ubatch, n_slices, n_slice_tokens);
inp_attn_prune.self_attn_mask.raw = ggml_cast(ctx0, inp_attn_prune.self_attn_mask.raw, GGML_TYPE_F16);
inp_attn_prune.self_attn_mask_swa.raw = ggml_cast(ctx0, inp_attn_prune.self_attn_mask_swa.raw, GGML_TYPE_F16);
n_rows = n_slices * n_slice_outputs;
n_rows = n_outputs;
auto prune_input = std::make_unique<llm_graph_input_gemma4_prune>(n_slices, n_slice_tokens, n_slice_outputs);
prune_input->full_mask = full;
prune_input->full_mask_swa = full_swa;
prune_input->out_mask = ggml_new_tensor_4d(ctx0, full->type, full->ne[0], n_slice_outputs, 1, n_slices);
prune_input->out_mask_swa = ggml_new_tensor_4d(ctx0, full_swa->type, full_swa->ne[0], n_slice_outputs, 1, n_slices);
prune_input->inp_prune_ids = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_rows);
prune_input->inp_prune_keep = ggml_new_tensor_1d(ctx0, GGML_TYPE_I32, n_outputs);
ggml_set_input(prune_input->out_mask);
ggml_set_input(prune_input->out_mask_swa);
ggml_set_input(prune_input->inp_prune_ids);
ggml_set_input(prune_input->inp_prune_keep);
inp_prune_ids = prune_input->inp_prune_ids;
inp_prune_keep = prune_input->inp_prune_keep;
inpL = ggml_get_rows(ctx0, inpL, inp_prune_ids);
inp_pos = ggml_reshape_1d(ctx0, ggml_get_rows(ctx0, ggml_reshape_2d(ctx0, inp_pos, 1, n_tokens), inp_prune_ids), n_rows);
inp_attn_prune.self_attn_mask.raw = prune_input->out_mask;
inp_attn_prune.self_attn_mask_swa.raw = prune_input->out_mask_swa;
inp_attn = &inp_attn_prune;
res->add_input(std::move(prune_input));
}
const int64_t n_embd_head = hparams.n_embd_head_k(il);
@@ -406,7 +449,9 @@ llama_model_gemma4::graph::graph(const llm_graph_params & params) :
ggml_tensor * inp_this_layer = gemma4_view_2d_slice(ctx0, inp_per_layer, il); // [n_embd_per_layer, n_tokens]
if ((prune_shared && !hparams.has_kv(il)) || (il == n_layer - 1 && crop_before_nextn(inp_out_ids))) {
if (prune_shared && !hparams.has_kv(il)) {
inp_this_layer = ggml_get_rows(ctx0, inp_this_layer, inp_prune_ids);
} else if (il == n_layer - 1 && crop_before_nextn(inp_out_ids)) {
inp_this_layer = ggml_get_rows(ctx0, inp_this_layer, inp_out_ids);
}
@@ -432,6 +477,9 @@ llama_model_gemma4::graph::graph(const llm_graph_params & params) :
inpL = cur;
}
cur = inpL;
if (prune_shared) {
cur = ggml_get_rows(ctx0, cur, inp_prune_keep);
}
cur = build_norm(cur,
model.output_norm, nullptr,
@@ -558,3 +606,89 @@ ggml_tensor * llama_model_gemma4::graph::project_per_layer_inputs(ggml_tensor *
// permute to shape: [n_embd_per_layer, n_tokens, n_layer]
return ggml_permute(ctx0, inp_per_layer, 0, 2, 1, 3);
}
void llm_graph_input_gemma4_prune::set_input(const llama_ubatch * ubatch) {
std::vector<std::vector<int32_t>> selected(n_slices);
for (int32_t s = 0; s < n_slices; ++s) {
for (int32_t t = 0; t < n_slice_tokens; ++t) {
const int32_t i = s * n_slice_tokens + t;
if (ubatch->output[i]) {
selected[s].push_back(i);
}
}
}
std::vector<int32_t> take, keep;
for (int32_t s = 0; s < n_slices; ++s) {
const auto & ids = selected[s];
for (int32_t j = 0; j < int32_t(ids.size()); ++j) {
keep.push_back(s * n_slice_outputs + j);
}
take.insert(take.end(), ids.begin(), ids.end());
const int32_t dummy = ids.empty() ? s * n_slice_tokens : ids.back();
take.insert(take.end(), n_slice_outputs - ids.size(), dummy);
}
GGML_ASSERT(take.size() == size_t(inp_prune_ids->ne[0]));
if (!take.empty()) {
ggml_backend_tensor_set(inp_prune_ids, take.data(), 0,
take.size() * sizeof(int32_t));
}
auto copy_mask = [&](const ggml_tensor * full, ggml_tensor * out) {
if (take.empty() || !out->buffer) {
return;
}
GGML_ASSERT(full->buffer && ggml_backend_buffer_is_host(full->buffer));
const size_t row_bytes = full->ne[0] * ggml_element_size(full);
const auto * src = static_cast<const uint8_t *>(full->data);
std::vector<uint8_t> packed(take.size() * row_bytes);
for (size_t j = 0; j < take.size(); ++j) {
memcpy(packed.data() + j * row_bytes,
src + take[j] * row_bytes,
row_bytes);
}
ggml_backend_tensor_set(out, packed.data(), 0, packed.size());
};
copy_mask(full_mask, out_mask);
copy_mask(full_mask_swa, out_mask_swa);
if (!keep.empty()) {
ggml_backend_tensor_set(
inp_prune_keep, keep.data(), 0,
keep.size() * sizeof(int32_t));
}
}
bool llm_graph_input_gemma4_prune::can_reuse(const llm_graph_params & params) {
const auto & ubatch = params.ubatch;
if (ubatch.n_tokens != n_slices * n_slice_tokens || !ubatch.output) {
return false;
}
return max_outputs_per_slice(ubatch, n_slices, n_slice_tokens) == n_slice_outputs;
}
int64_t llm_graph_input_gemma4_prune::max_outputs_per_slice(const llama_ubatch & ubatch, int64_t n_slices, int64_t n_slice_tokens) {
int64_t res = 0;
for (int32_t s = 0; s < n_slices; ++s) {
int64_t m = 0;
for (int32_t t = 0; t < n_slice_tokens; ++t) {
const int32_t i = s * n_slice_tokens + t;
if (ubatch.output[i]) {
m++;
}
}
res = std::max(res, m);
}
return res;
}
+4 -1
View File
@@ -372,7 +372,10 @@ llama_model_inkling2::graph::graph(const llm_graph_params & params) : llm_graph_
LLAMA_EXPERT_GATING_FUNC_TYPE_SIGMOID,
il,
nullptr,
layer.ffn_gate_up_exps);
layer.ffn_gate_up_exps,
layer.ffn_up_exps_s,
layer.ffn_gate_exps_s,
layer.ffn_down_exps_s);
cur = convolve(cur, layer.ffn_post_conv, nullptr, state, history, recr, 2*n_embd_k_gqa + n_embd);
cb(cur, "ffn_out", il);
+40
View File
@@ -442,6 +442,7 @@ struct llama_model_nanbeige : public llama_model_base {
llama_model_nanbeige(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
int n_loops = 1;
int n_layer_phys = 0;
@@ -801,6 +802,7 @@ struct llama_model_zonos3 : public llama_model_base {
llama_model_zonos3(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -1244,6 +1246,7 @@ struct llama_model_deepseek32 : public llama_model_base {
llama_model_deepseek32(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
bool lid_k_hdmd() const override { return true; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -1260,6 +1263,7 @@ struct llama_model_dots3note : public llama_model_base {
llama_model_dots3note(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
bool lid_k_hdmd() const override { return true; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -1282,6 +1286,8 @@ struct llama_model_deepseek4 : public llama_model_base {
llama_model_deepseek4(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
bool lid_k_hdmd() const override { return true; }
struct graph : public llm_graph_context {
struct no_build {};
@@ -1439,6 +1445,7 @@ struct llama_model_xing4_0 : public llama_model_base {
llama_model_xing4_0(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_graph_context {
graph(const llama_model & model, const llm_graph_params & params);
@@ -1481,6 +1488,7 @@ struct llama_model_deepseek41 : public llama_model_deepseek4 {
llama_model_deepseek41(const struct llama_model_params & params) : llama_model_deepseek4(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
bool lid_k_hdmd() const override { return false; }
// Engram: the hash constants are hparams.ple_* (one module per Engram layer), hashed on the host (ggml has no int64 mul/xor/mod)
int engram_index(int il) const;
@@ -1539,6 +1547,7 @@ struct llama_model_glm_dsa : public llama_model_base {
llama_model_glm_dsa(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
bool lid_k_hdmd() const override { return true; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -1571,6 +1580,7 @@ struct llama_model_dflash : public llama_model_base {
llama_model_dflash(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override;
enum variant_type {
VARIANT_DFLASH,
@@ -1672,6 +1682,7 @@ struct llama_model_mistral_large4 : public llama_model_base {
llama_model_mistral_large4(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
bool lid_k_hdmd() const override { return true; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -1833,6 +1844,7 @@ struct llama_model_metis16 : public llama_model_base {
llama_model_metis16(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
uint32_t n_pass = 1;
uint32_t n_stream = 1;
@@ -2134,6 +2146,7 @@ struct llama_model_hrm_text : public llama_model_base {
llama_model_hrm_text(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 64; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -2176,6 +2189,7 @@ struct llama_model_bailingmoe3 : public llama_model_base {
llama_model_bailingmoe3(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -2346,6 +2360,7 @@ struct llama_model_hy_v4 : public llama_model_base {
llama_model_hy_v4(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -2475,6 +2490,7 @@ struct llama_model_inkling2 : public llama_model_base {
llama_model_inkling2(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -2599,6 +2615,7 @@ struct llama_model_minimax_01 : public llama_model_base {
llama_model_minimax_01(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -2629,6 +2646,7 @@ struct llama_model_minimax_m3 : public llama_model_base {
llama_model_minimax_m3(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
msa_params msa_p;
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
@@ -2673,6 +2691,7 @@ struct llama_model_qwen3next : public llama_model_base {
llama_model_qwen3next(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -2715,6 +2734,7 @@ struct llama_model_qwen35 : public llama_model_base {
llama_model_qwen35(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -2851,6 +2871,7 @@ struct llama_model_qwen4exp : public llama_model_base {
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -2965,6 +2986,7 @@ struct llama_model_qwen35moe : public llama_model_base {
llama_model_qwen35moe(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -3007,6 +3029,7 @@ struct llama_model_clover_moe : public llama_model_base {
llama_model_clover_moe(const llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -3055,6 +3078,7 @@ struct llama_model_kimi_k3 : public llama_model_base {
llama_model_kimi_k3(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 64; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -3095,6 +3119,7 @@ struct llama_model_kimi_k31 : public llama_model_base {
llama_model_kimi_k31(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 64; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -3141,6 +3166,7 @@ struct llama_model_glm5_next : public llama_model_base {
llama_model_glm5_next(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 64; }
// k-pool indexer inputs on top of the generic hybrid input
class llm_graph_input_kpool;
@@ -3225,6 +3251,7 @@ struct llama_model_kimi_linear : public llama_model_base {
llama_model_kimi_linear(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
uint32_t graph_nodes_per_tensor() const override { return 32; }
struct graph : public llm_build_delta_net_base {
graph(const llm_graph_params & params);
@@ -3308,3 +3335,16 @@ struct llama_model_kolibri1 : public llama_model_base {
std::unique_ptr<llm_graph_context> build_arch_graph(const llm_graph_params & params) const override;
};
struct llama_model_domyn_edge : public llama_model_base {
llama_model_domyn_edge(const struct llama_model_params & params) : llama_model_base(params) {}
void load_arch_hparams(llama_model_loader & ml) override;
void load_arch_tensors(llama_model_loader & ml) override;
llama_rope_params get_rope_params(const llama_cparams & cparams, int il) const override;
struct graph : public llm_graph_context {
graph(const llm_graph_params & params);
};
std::unique_ptr<llm_graph_context> build_arch_graph(const llm_graph_params & params) const override;
};
+2
View File
@@ -65,6 +65,8 @@ deepseek4 ,0 ,any ,UNARY+SQRT+ADD+ARGSORT+GET_ROWS+SUM_ROWS+CLAM
deepseek41 ,0 ,any ,MUL+ADD , 12
deepseek41 ,0 ,any ,RMS_NORM+MUL , 29
deepseek41 ,0 ,any ,UNARY+SQRT+ADD+ARGSORT+GET_ROWS+SUM_ROWS+SCALE+DIV, 6
domynedge ,0 ,any ,RMS_NORM+MUL , 8
domynedge ,0 ,any ,RMS_NORM+MUL+ADD , 3
dots1 ,0 ,any ,ADD+ADD , 1
dots1 ,0 ,any ,MUL+ADD , 2
dots1 ,0 ,any ,RMS_NORM+MUL , 9
1 # test-fusion baseline for device MTL
65 deepseek41 ,0 ,any ,MUL+ADD , 12
66 deepseek41 ,0 ,any ,RMS_NORM+MUL , 29
67 deepseek41 ,0 ,any ,UNARY+SQRT+ADD+ARGSORT+GET_ROWS+SUM_ROWS+SCALE+DIV, 6
68 domynedge ,0 ,any ,RMS_NORM+MUL , 8
69 domynedge ,0 ,any ,RMS_NORM+MUL+ADD , 3
70 dots1 ,0 ,any ,ADD+ADD , 1
71 dots1 ,0 ,any ,MUL+ADD , 2
72 dots1 ,0 ,any ,RMS_NORM+MUL , 9
+1 -1
View File
@@ -11507,7 +11507,7 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
test_cases.emplace_back(new test_cpy(GGML_TYPE_F16, GGML_TYPE_F16, {128, 2, 3, 1}, {128, 2, 3, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, false, {128, 4, 3, 1})); // strided dst
test_cases.emplace_back(new test_cpy(GGML_TYPE_F32, GGML_TYPE_F32, {64, 16, 1, 1}, {1, 64, 16, 1}, {1, 2, 0, 3}, {0, 0, 0, 0}, false, {32, 64, 16, 1})); // permuted src, strided dst
test_cases.emplace_back(new test_cpy(GGML_TYPE_F16, GGML_TYPE_F16, {64, 16, 1, 1}, {1, 64, 16, 1}, {1, 2, 0, 3}, {0, 0, 0, 0}, false, {32, 64, 16, 1})); // permuted src, strided dst
test_cases.emplace_back(new test_cpy(GGML_TYPE_F32, GGML_TYPE_F32, {2, 2, 524281, 1}, {-1,-1,-1,-1}, {1, 0, 2, 3}));
// CPY - different src/dst shapes (reshaping via CPY)
// Use permutations of {3, 5, 7, 32}. Total elements: 3*5*7*32 = 3360.
// Each src permutation is tested against canonical sorted and reverse dst (skip self).
+8 -2
View File
@@ -496,16 +496,22 @@ static gguf_context_ptr get_gguf_ctx(const llm_arch arch, const bool moe, const
ms.add_kv(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, pattern);
} else if (arch == LLM_ARCH_COHERE2MOE || arch == LLM_ARCH_MIMO2 || arch == LLM_ARCH_STEP35 || arch == LLM_ARCH_SPARK2_5 ||
arch == LLM_ARCH_MUSE_GLIMMER || arch == LLM_ARCH_MUSE_SPARK || arch == LLM_ARCH_GRANITE_SWA || arch == LLM_ARCH_DOTS3NOTE ||
arch == LLM_ARCH_KOLIBRI1 || arch == LLM_ARCH_MAPLE || arch == LLM_ARCH_FLINT || arch == LLM_ARCH_BEAM || arch == LLM_ARCH_RICURSIVE) {
arch == LLM_ARCH_KOLIBRI1 || arch == LLM_ARCH_MAPLE || arch == LLM_ARCH_FLINT || arch == LLM_ARCH_BEAM || arch == LLM_ARCH_RICURSIVE || arch == LLM_ARCH_DOMYN_EDGE) {
std::vector<uint32_t> pattern;
pattern.reserve(n_layer);
for (uint32_t il = 0; il < n_layer; il++) {
pattern.push_back(il % 2);
}
ms.add_kv(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, pattern);
if (arch == LLM_ARCH_FLINT) {
if (arch == LLM_ARCH_FLINT || arch == LLM_ARCH_DOMYN_EDGE) {
ms.add_kv(LLM_KV_ATTENTION_ROPE_PATTERN, pattern);
}
if (arch == LLM_ARCH_DOMYN_EDGE) {
// SWA (rope) layers use a smaller head dim than the full-attention (nope) layers
ms.add_kv(LLM_KV_ATTENTION_KEY_LENGTH_SWA, n_embd_head/2);
ms.add_kv(LLM_KV_ATTENTION_VALUE_LENGTH_SWA, n_embd_head/2);
ms.add_kv(LLM_KV_ROPE_DIMENSION_COUNT_SWA, n_embd_head/2);
}
} else if (arch == LLM_ARCH_LFM3) {
ms.add_kv(LLM_KV_ATTENTION_SLIDING_WINDOW_PATTERN, std::vector<uint32_t>({0, 0, 1}));
ms.add_kv(LLM_KV_ROPE_FREQ_BASE_SWA, 10000.0f);
+5 -4
View File
@@ -80,6 +80,7 @@ class LibLlamaModel:
raise RuntimeError("error: failed to load model '%s'" % path_model)
if isinstance(cparams, dict):
cparams = libllama.context_default_params(**cparams)
self.vocab = self.lib.llama_model_get_vocab(self.model)
self.ctx = self.lib.llama_init_from_model(self.model, cparams)
if not self.ctx:
raise RuntimeError("error: failed to create context for model '%s'" % path_model)
@@ -98,10 +99,10 @@ class LibLlamaModel:
def tokenize(self, text: str, add_special: bool = False, parse_special: bool = False) -> list[int]:
encoded_text: bytes = text.encode("utf-8")
num = self.lib.llama_tokenize(self.model, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special)
num = self.lib.llama_tokenize(self.vocab, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special)
while num < 0 and len(self.token_ids) < (16 << 20):
self.token_ids = self.ffi.new("llama_token[]", -2 * num)
num = self.lib.llama_tokenize(self.model, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special)
num = self.lib.llama_tokenize(self.vocab, encoded_text, len(encoded_text), self.token_ids, len(self.token_ids), add_special, parse_special)
return list(self.token_ids[0:num])
def detokenize(self, ids: list[int], remove_special: bool = False, unparse_special: bool = False) -> str:
@@ -109,10 +110,10 @@ class LibLlamaModel:
self.token_ids = self.ffi.new("llama_token[]", 2 * len(ids))
for i, id in enumerate(ids):
self.token_ids[i] = id
num = self.lib.llama_detokenize(self.model, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special)
num = self.lib.llama_detokenize(self.vocab, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special)
while num < 0 and len(self.text_buff) < (16 << 20):
self.text_buff = self.ffi.new("uint8_t[]", -2 * num)
num = self.lib.llama_detokenize(self.model, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special)
num = self.lib.llama_detokenize(self.vocab, self.token_ids, len(ids), self.text_buff, len(self.text_buff), remove_special, unparse_special)
return str(self.ffi.buffer(self.text_buff, num), encoding="utf-8", errors="replace") # replace errors with '\uFFFD' # pyright: ignore[reportArgumentType]
+3 -2
View File
@@ -202,7 +202,8 @@ For the full list of features, please refer to [server's changelog](https://gith
| `--api-prefix PREFIX` | prefix path the server serves from, without the trailing slash (default: )<br/>(env: LLAMA_ARG_API_PREFIX) |
| `--ui-config, --webui-config JSON` | JSON that provides default UI settings (overrides UI defaults)<br/>(env: LLAMA_ARG_UI_CONFIG) |
| `--ui-config-file, --webui-config-file PATH` | JSON file that provides default UI settings (overrides UI defaults)<br/>(env: LLAMA_ARG_UI_CONFIG_FILE) |
| `--ui-mcp-proxy, --webui-mcp-proxy, --no-ui-mcp-proxy, --no-webui-mcp-proxy` | experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused - do not enable in untrusted environments (default: disabled)<br/>note: for security reasons, this will limit --cors-origins to localhost by default<br/>(env: LLAMA_ARG_UI_MCP_PROXY) |
| `--ui-mcp-proxy, --webui-mcp-proxy, --no-ui-mcp-proxy, --no-webui-mcp-proxy` | experimental: whether to enable MCP CORS proxy, for Llama Chat to reach public MCP servers without CORS headers; local and private addresses are refused unless --ui-mcp-proxy-allow-private-urls is set - do not enable in untrusted environments (default: disabled)<br/>note: for security reasons, this will limit --cors-origins to localhost by default<br/>(env: LLAMA_ARG_UI_MCP_PROXY) |
| `--ui-mcp-proxy-allow-private-urls` | allow the MCP CORS proxy to reach local or private addresses (e.g. MCP servers on localhost or LAN) - anyone who can reach the proxy can then reach your local network (default: disabled, only public addresses)<br/>note: only has effect with --ui-mcp-proxy<br/>(env: LLAMA_ARG_UI_MCP_PROXY_ALLOW_PRIVATE_URLS) |
| `--tools TOOL1,TOOL2,...` | experimental: whether to enable built-in tools for AI agents - do not enable in untrusted environments (default: no tools)<br/>specify "all" to enable all tools<br/>available tools: read_file, file_glob_search, grep_search, exec_shell_command, write_file, edit_file, get_info<br/>note: for security reasons, this will limit --cors-origins to localhost by default<br/>(env: LLAMA_ARG_TOOLS) |
| `--tools-runtime OPTION` | experimental: run tools in a separate runtime environment (default: none, use host environment)<br/>available options:<br/> 'docker:<image>', 'podman:<image>': spin up a new container and reuse it for all invocations, clean up on server exit<br/> 'docker-container:<id>', 'podman-container:<id>': use an existing container by ID, won't stop on server exit<br/> 'ssh:<target>': run tools on a remote POSIX host over SSH, key-based auth and a trusted host key are required<br/><br/>(env: LLAMA_ARG_TOOLS_RUNTIME) |
| `--allow-unauthenticated-tools` | allow server tools, MCP servers or MCP proxy on a non-loopback address without an API key - only for trusted networks (default: disabled)<br/>(env: LLAMA_ARG_ALLOW_UNAUTHENTICATED_TOOLS) |
@@ -393,7 +394,7 @@ Every server is spawned once at startup to list its tools, then stopped, and res
The child process runs with the same privileges as the server, so only declare commands you trust. As with `--tools`, `--cors-origins` then defaults to `localhost`.
Note: `--ui-mcp-proxy` is unrelated, it only lets Llama Chat reach public MCP servers that do not send CORS headers. It refuses local and private addresses (loopback, LAN, link-local); connect to those from Llama Chat directly.
Note: `--ui-mcp-proxy` is unrelated, it only lets Llama Chat reach public MCP servers that do not send CORS headers. By default it refuses local and private addresses (loopback, LAN, link-local); either connect to those from Llama Chat directly (the MCP server must send CORS headers), or add `--ui-mcp-proxy-allow-private-urls`.
Any server written against the [MCP specification](https://modelcontextprotocol.io) works as is, whether it uses an official SDK or not: the transport is one JSON-RPC message per line on stdio, so a script wrapping an existing program is a valid server too.
+7 -10
View File
@@ -20,7 +20,7 @@ static std::string proxy_header_to_lower(std::string header) {
return header;
}
static server_http_res_ptr proxy_request(const server_http_req & req, std::string method) {
static server_http_res_ptr proxy_request(const server_http_req & req, std::string method, bool allow_private_urls) {
std::string target_url = req.get_param("url");
common_http_url parsed_url = common_http_parse_url(target_url);
@@ -70,8 +70,7 @@ static server_http_res_ptr proxy_request(const server_http_req & req, std::strin
req.should_stop,
600, // timeout_read (default to 10 minutes)
600, // timeout_write (default to 10 minutes)
// test-only escape hatch
server_resolve_public_addr(parsed_url.host, !common_get_env("LLAMA_SERVER_DEBUG_PROXY_ALLOW_PRIVATE").empty())
server_resolve_public_addr(parsed_url.host, allow_private_urls)
);
// route redirects back through the proxy, so each hop is checked
@@ -86,10 +85,8 @@ static server_http_res_ptr proxy_request(const server_http_req & req, std::strin
return proxy;
}
static server_http_context::handler_t proxy_handler_post = [](const server_http_req & req) -> server_http_res_ptr {
return proxy_request(req, "POST");
};
static server_http_context::handler_t proxy_handler_get = [](const server_http_req & req) -> server_http_res_ptr {
return proxy_request(req, "GET");
};
static server_http_context::handler_t proxy_make_handler(const std::string & method, bool allow_private_urls) {
return [method, allow_private_urls](const server_http_req & req) -> server_http_res_ptr {
return proxy_request(req, method, allow_private_urls);
};
}
+5 -3
View File
@@ -281,9 +281,11 @@ static bool server_setup_features(
// CORS proxy (EXPERIMENTAL, only used by Llama Chat for MCP)
if (params.ui_mcp_proxy) {
ctx_http.get ("/cors-proxy", ex_wrapper(proxy_handler_get));
ctx_http.post("/cors-proxy", ex_wrapper(proxy_handler_post));
warn_names.push_back("MCP proxy (experimental)");
ctx_http.get ("/cors-proxy", ex_wrapper(proxy_make_handler("GET", params.ui_mcp_proxy_allow_private_urls)));
ctx_http.post("/cors-proxy", ex_wrapper(proxy_make_handler("POST", params.ui_mcp_proxy_allow_private_urls)));
warn_names.push_back(params.ui_mcp_proxy_allow_private_urls
? "MCP proxy (experimental, local and private addresses allowed)"
: "MCP proxy (experimental)");
} else {
ctx_http.get ("/cors-proxy", ex_wrapper(res_403));
ctx_http.post("/cors-proxy", ex_wrapper(res_403));
+1
View File
@@ -6,4 +6,5 @@ numpy~=2.5.4; python_version >= "3.14"
openai~=2.14.0
prometheus-client~=0.20.0
requests~=2.32.3
websockets~=15.0
wget~=3.2
@@ -1,3 +1,4 @@
import base64
import pytest
import requests
import struct
@@ -135,3 +136,78 @@ def test_speech_router():
server = ServerPreset.router()
server.start()
assert_wav(post_audio("/v1/audio/speech", model=model))
#
# tts only model, with voice cloning
#
def pocket_tts(path: str = "/v1/audio/speech", **extra) -> requests.Response:
body = {"input": "Hello there.", "seed": 42, "n_predict": 8, **extra}
return requests.post(server.make_url(path), json=body, timeout=DEFAULT_REQUEST_TIMEOUT)
def test_tts_only():
global server
server = ServerPreset.tinypockettts()
server.start()
res = server.make_request("GET", "/props")
assert not res.body.get("voices") # this slice has no predefined voices
res = server.make_request("GET", "/v1/models")
assert res.body["data"][0]["architecture"]["output_modalities"] == ["audio"]
res = pocket_tts()
assert_wav(res)
assert res.content == pocket_tts().content
def test_tts_only_speaker_ref():
global server
server = ServerPreset.tinypockettts()
server.start()
ref_a = make_wav(seconds=2.0, rate=24000, freq=220)
ref_b = make_wav(seconds=2.0, rate=24000, freq=440)
res = pocket_tts("/tts", speaker_ref_b64=base64.b64encode(ref_a).decode())
assert_wav(res)
assert res.content != pocket_tts("/tts").content
assert res.content != pocket_tts("/tts", speaker_ref_b64=base64.b64encode(ref_b).decode()).content
# the same reference as an uploaded file
fields = {"input": (None, "Hello there."), "seed": (None, "42"), "n_predict": (None, "8"), "speaker_ref": ("ref.wav", ref_a)}
res_file = requests.post(server.make_url("/tts"), files=fields, timeout=DEFAULT_REQUEST_TIMEOUT)
assert res_file.content == res.content
# /v1/audio/speech passes it through
assert pocket_tts(speaker_ref_b64=base64.b64encode(ref_a).decode()).content == res.content
@pytest.mark.parametrize("speaker_ref_b64,message", [
("!!!", "not valid base64"),
(base64.b64encode(b"not an audio file").decode(), "failed to decode"),
])
def test_tts_only_invalid_speaker_ref(speaker_ref_b64: str, message: str):
global server
server = ServerPreset.tinypockettts()
server.start()
res = pocket_tts("/tts", speaker_ref_b64=speaker_ref_b64)
assert res.status_code == 400
assert message in res.json()["error"]["message"]
def test_tts_only_end_of_speech():
global server
server = ServerPreset.tinypockettts()
server.start()
# the end-of-speech head stops the generation before n_predict
res = pocket_tts(n_predict=16)
assert_wav(res)
assert res.content == pocket_tts(n_predict=1000).content
@pytest.mark.parametrize("path", ["/v1/chat/completions", "/v1/audio/transcriptions"])
def test_tts_only_no_text_output(path: str):
global server
server = ServerPreset.tinypockettts()
server.start()
if path == "/v1/audio/transcriptions":
res = requests.post(server.make_url(path), files={"file": ("audio.wav", make_wav())}, timeout=DEFAULT_REQUEST_TIMEOUT)
else:
res = requests.post(server.make_url(path), json={"messages": [{"role": "user", "content": "hello"}]}, timeout=DEFAULT_REQUEST_TIMEOUT)
assert res.status_code == 501
@@ -0,0 +1,144 @@
import base64
import json
import pytest
import requests
from utils import *
server: ServerProcess
MP3_PATH = os.path.join(os.path.dirname(__file__), "../../../mtmd/test-2.mp3")
# full random sampling, so that the output depends on the audio
SAMPLING_RANDOM = {"temperature": 1.0, "top_k": 0, "top_p": 1.0, "min_p": 0.0, "seed": 42}
@pytest.fixture(autouse=True)
def create_server():
global server
server = ServerPreset.tinylfm3omni()
server.jinja = True
server.reasoning = "off"
def post_transcription(path: str = "/v1/audio/transcriptions", audio: bytes | None = None, filename: str = "audio.wav", **fields) -> requests.Response:
data = {"max_tokens": "8", **fields}
files = {"file": (filename, make_wav() if audio is None else audio)}
return requests.post(server.make_url(path), data=data, files=files, timeout=DEFAULT_REQUEST_TIMEOUT)
def chat_with_audio(audio: bytes, fmt: str = "wav", extra: dict | None = None) -> str:
res = server.make_request("POST", "/v1/chat/completions", data={
"max_tokens": 8,
"messages": [{"role": "user", "content": [
{"type": "input_audio", "input_audio": {"data": base64.b64encode(audio).decode(), "format": fmt}},
]}],
**(extra or {}),
})
assert res.status_code == 200, res.body
return res.body["choices"][0]["message"]["content"]
@pytest.mark.parametrize("path", ["/v1/audio/transcriptions", "/audio/transcriptions"])
def test_transcription(path: str):
server.start()
res = post_transcription(path)
assert res.status_code == 200
body = res.json()
assert body["type"] == "transcript.text.done"
assert len(body["text"]) > 0
assert 0 < body["usage"]["output_tokens"] <= 8
assert body["usage"]["input_tokens"] > 0
def test_transcription_mp3():
server.start()
with open(MP3_PATH, "rb") as f:
res = post_transcription(audio=f.read(), filename="audio.mp3")
assert res.status_code == 200
assert len(res.json()["text"]) > 0
def test_transcription_stream():
server.start()
res = post_transcription(stream="true")
assert res.status_code == 200
lines = [line[len("data: "):] for line in res.text.splitlines() if line.startswith("data: ")]
assert lines[-1] == "[DONE]"
events = [json.loads(line) for line in lines[:-1]]
assert len(events) > 1
assert all(ev["type"] == "transcript.text.delta" for ev in events[:-1])
assert events[-1]["type"] == "transcript.text.done"
text = "".join(ev["delta"] for ev in events[:-1])
assert text == events[-1]["text"]
assert text == post_transcription().json()["text"]
def test_transcription_language():
server.start()
# the LFM3 template puts the language in the system prompt
n_default = post_transcription().json()["usage"]["input_tokens"]
n_fr = post_transcription(language="fr").json()["usage"]["input_tokens"]
assert n_fr > n_default
@pytest.mark.parametrize("fields,files,message", [
({"response_format": "text"}, None, "response_format"),
({}, {"file": ("audio.wav", b"not an audio file")}, None),
({}, {"other": ("audio.wav", b"")}, None),
])
def test_transcription_invalid_request(fields: dict, files: dict | None, message: str | None):
server.start()
res = requests.post(server.make_url("/v1/audio/transcriptions"), data={"max_tokens": "8", **fields},
files=files or {"file": ("audio.wav", make_wav())}, timeout=DEFAULT_REQUEST_TIMEOUT)
assert res.status_code == 400
if message:
assert message in res.json()["error"]["message"]
@pytest.mark.parametrize("preset", [
"tinyllama2", # no audio input
"tinyvoxtralrt", # live transcription only
])
def test_transcription_not_supported(preset: str):
global server
server = getattr(ServerPreset, preset)()
server.start()
assert post_transcription().status_code == 501 # ERROR_TYPE_NOT_SUPPORTED
def test_transcription_router():
global server
model = server.model_hf_repo
server = ServerPreset.router()
server.start()
res = post_transcription(model=model)
assert res.status_code == 200
assert res.json()["type"] == "transcript.text.done"
def test_chat_input_audio():
server.start()
a = make_wav(freq=220)
b = make_wav(freq=880)
assert chat_with_audio(a, extra=SAMPLING_RANDOM) == chat_with_audio(a, extra=SAMPLING_RANDOM)
assert chat_with_audio(a, extra=SAMPLING_RANDOM) != chat_with_audio(b, extra=SAMPLING_RANDOM)
def test_chat_input_audio_mp3():
server.start()
with open(MP3_PATH, "rb") as f:
assert len(chat_with_audio(f.read(), fmt="mp3")) > 0
def test_chat_input_audio_no_audio_model():
global server
server = ServerPreset.tinyllama2()
server.start()
res = server.make_request("POST", "/v1/chat/completions", data={
"max_tokens": 8,
"messages": [{"role": "user", "content": [
{"type": "input_audio", "input_audio": {"data": base64.b64encode(make_wav()).decode(), "format": "wav"}},
]}],
})
assert res.status_code != 200
assert "audio input is not supported" in res.body["error"]["message"]
+3 -3
View File
@@ -35,7 +35,7 @@ def test_mcp_proxy():
def test_mcp_proxy_custom_port():
global server
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
# try getting the server's models API via the proxy
@@ -61,7 +61,7 @@ def test_mcp_proxy_no_content():
try:
global server
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
res = server.make_request("POST", f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/", data={})
@@ -116,7 +116,7 @@ def test_mcp_proxy_redirect_goes_through_proxy():
try:
global server
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
url = server.make_url(f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/start")
+410
View File
@@ -0,0 +1,410 @@
import base64
import json
import time
import pytest
from websockets.exceptions import ConnectionClosed
from websockets.sync.client import connect, ClientConnection
from websockets.sync.connection import Connection
from utils import *
server: ServerProcess
@pytest.fixture(autouse=True)
def create_server():
global server
server = ServerPreset.tinylfm3omni()
server.jinja = True
server.reasoning = "off"
def ws_connect(path: str = "/v1/realtime") -> ClientConnection:
return connect(server.make_url(path).replace("http://", "ws://", 1), max_size=None, open_timeout=DEFAULT_REQUEST_TIMEOUT)
def send(ws: Connection, type: str, **fields):
ws.send(json.dumps({"type": type, **fields}))
def send_audio(ws: Connection, pcm: bytes):
send(ws, "input_audio_buffer.append", audio=base64.b64encode(pcm).decode())
def send_text(ws: Connection, text: str):
send(ws, "conversation.item.create", item={"type": "message", "role": "user", "content": [{"type": "input_text", "text": text}]})
def recv(ws: Connection) -> dict:
return json.loads(ws.recv(timeout=DEFAULT_REQUEST_TIMEOUT))
def recv_until(ws: Connection, type: str) -> list[dict]:
events = []
while True:
ev = recv(ws)
events.append(ev)
if ev["type"] == type:
return events
assert ev["type"] != "error", ev
def recv_all(ws: Connection) -> list[dict]:
""" read events until the server closes the socket """
events = []
try:
while True:
events.append(recv(ws))
except ConnectionClosed:
return events
def get_transcripts(events: list[dict]) -> list[tuple[str, str]]:
""" (item_id, transcript) of each completed item, checked against its deltas """
deltas: dict[str, str] = {}
out = []
for ev in events:
assert ev["type"] != "error", ev
if ev["type"] == "conversation.item.input_audio_transcription.delta":
deltas[ev["item_id"]] = deltas.get(ev["item_id"], "") + ev["delta"]
elif ev["type"] == "conversation.item.input_audio_transcription.completed":
assert ev["transcript"] == deltas.get(ev["item_id"], "")
out.append((ev["item_id"], ev["transcript"]))
return out
def session_update(ws: Connection, **session) -> dict:
send(ws, "session.update", session=session)
return recv_until(ws, "session.updated")[-1]["session"]
#
# live transcription
#
LIVE_ASR = [
# a chat model with an "asr" chat template, live only in sessions opened with ?intent=transcription
("tinylfm3omni", "/v1/realtime?intent=transcription"),
# no chat, the text follows the audio by a few tokens
("tinyvoxtralrt", "/v1/realtime"),
]
def start_live_asr(preset: str):
global server
if preset != "tinylfm3omni":
server = getattr(ServerPreset, preset)()
server.start()
@pytest.mark.parametrize("preset,path", LIVE_ASR)
def test_live_asr(preset: str, path: str):
start_live_asr(preset)
with ws_connect(path) as ws:
session = recv(ws)
assert session["type"] == "session.created"
assert session["session"]["object"] == "realtime.transcription_session"
assert session["session"]["audio"]["input"]["format"] == {"type": "audio/pcm", "rate": 16000}
send_audio(ws, make_pcm16())
send(ws, "input_audio_buffer.commit")
send_audio(ws, make_pcm16(freq=880))
send(ws, "input_audio_buffer.commit", final=True)
events = recv_all(ws)
committed = [ev for ev in events if ev["type"] == "input_audio_buffer.committed"]
assert len(committed) == 1
assert committed[0]["previous_item_id"] is None
transcripts = get_transcripts(events)
assert len(transcripts) == 2
assert transcripts[0][0] == committed[0]["item_id"]
assert transcripts[1][0] != transcripts[0][0]
assert all(len(text) > 0 for _, text in transcripts)
@pytest.mark.parametrize("preset,path", LIVE_ASR)
def test_live_asr_chunked_audio(preset: str, path: str):
start_live_asr(preset)
pcm = make_pcm16()
results = []
for n_chunks in [1, 7]:
size = len(pcm) // n_chunks // 2 * 2
with ws_connect(path) as ws:
recv(ws)
for i in range(0, len(pcm), size):
send_audio(ws, pcm[i:i + size])
send(ws, "input_audio_buffer.commit", final=True)
results.append([text for _, text in get_transcripts(recv_all(ws))])
assert results[0] == results[1]
@pytest.mark.parametrize("preset,path", LIVE_ASR)
def test_live_asr_input_rate(preset: str, path: str):
start_live_asr(preset)
with ws_connect(path) as ws:
recv(ws)
send(ws, "session.update", session={"audio": {"input": {"format": {"type": "audio/pcm", "rate": 4000}}}})
assert "between 8000 and 192000" in recv_until(ws, "error")[-1]["error"]["message"]
send(ws, "session.update", session={"audio": {"input": {"format": {"type": "audio/pcm", "rate": 24000}}}})
assert recv_until(ws, "session.updated")[-1]["session"]["audio"]["input"]["format"]["rate"] == 24000
send_audio(ws, make_pcm16(rate=24000))
send(ws, "input_audio_buffer.commit", final=True)
transcripts = get_transcripts(recv_all(ws))
assert len(transcripts) == 1
assert len(transcripts[0][1]) > 0
@pytest.mark.parametrize("preset,path", LIVE_ASR)
def test_live_asr_invalid_events(preset: str, path: str):
start_live_asr(preset)
with ws_connect(path) as ws:
recv(ws)
ws.send("not json")
assert recv_until(ws, "error")[-1]["error"]["message"] == "invalid JSON"
send(ws, "response.create")
assert "unknown event type" in recv_until(ws, "error")[-1]["error"]["message"]
send(ws, "input_audio_buffer.clear")
recv_until(ws, "input_audio_buffer.cleared")
# the session still works
send_audio(ws, make_pcm16())
send(ws, "input_audio_buffer.commit", final=True)
assert len(get_transcripts(recv_all(ws))) == 1
def test_live_asr_depends_on_audio():
# the random weights of this model give a different text for each input
start_live_asr("tinyvoxtralrt")
results = []
for freq in [220, 880, 220]:
with ws_connect() as ws:
recv(ws)
send_audio(ws, make_pcm16(freq=freq))
send(ws, "input_audio_buffer.commit", final=True)
results.append(get_transcripts(recv_all(ws))[0][1])
assert results[0] != results[1]
assert results[0] == results[2]
@pytest.mark.parametrize("preset", ["tinypockettts", "tinyllama2"])
def test_realtime_not_supported(preset: str):
global server
server = getattr(ServerPreset, preset)()
server.start()
with ws_connect() as ws:
events = recv_all(ws)
assert len(events) == 1
assert events[0]["type"] == "error"
assert "does not support realtime" in events[0]["error"]["message"]
#
# realtime conversation
#
def test_conversation_text():
server.start()
with ws_connect() as ws:
session = recv(ws)
assert session["type"] == "session.created"
assert session["session"]["object"] == "realtime.session"
assert session["session"]["audio"]["output"]["format"]["rate"] > 0
session_update(ws, output_modalities=["text"], max_output_tokens=8)
send_text(ws, "hello")
user_item = recv_until(ws, "conversation.item.done")[-1]["item"]
assert user_item["role"] == "user"
assert user_item["content"] == [{"type": "input_text", "text": "hello"}]
send(ws, "response.create")
events = recv_until(ws, "response.done")
types = [ev["type"] for ev in events]
n_deltas = types.count("response.output_text.delta")
assert n_deltas == 8
assert types == [
"response.created",
"response.output_item.added",
"response.content_part.added",
*["response.output_text.delta"] * n_deltas,
"response.output_text.done",
"response.content_part.done",
"response.output_item.done",
"response.done",
]
response = events[-1]["response"]
assert response["status"] == "completed"
assert response["id"] == events[0]["response"]["id"]
assert response["usage"]["output_tokens"] == 8
text = "".join(ev["delta"] for ev in events if ev["type"] == "response.output_text.delta")
assert response["output"][0]["role"] == "assistant"
assert response["output"][0]["content"] == [{"type": "output_text", "text": text}]
def test_conversation_audio():
server.start()
with ws_connect() as ws:
recv(ws)
session_update(ws, output_modalities=["audio"], max_output_tokens=8)
send_audio(ws, make_pcm16())
# response.create commits the pending audio
send(ws, "response.create")
events = recv_until(ws, "response.done")
types = [ev["type"] for ev in events]
assert types[:3] == ["input_audio_buffer.committed", "conversation.item.added", "conversation.item.done"]
assert events[2]["item"]["content"] == [{"type": "input_audio"}]
assert "response.output_text.delta" not in types
audio = b"".join(base64.b64decode(ev["delta"]) for ev in events if ev["type"] == "response.output_audio.delta")
assert len(audio) > 0 and len(audio) % 2 == 0
response = events[-1]["response"]
assert response["status"] == "completed"
assert response["output"][0]["content"][0]["type"] == "output_audio"
def test_conversation_multi_turn():
server.start()
with ws_connect() as ws:
recv(ws)
session_update(ws, output_modalities=["text"], max_output_tokens=4)
send_text(ws, "hello")
recv_until(ws, "conversation.item.done")
send(ws, "response.create")
first = recv_until(ws, "response.done")[-1]["response"]
send_audio(ws, make_pcm16())
send(ws, "input_audio_buffer.commit")
committed = recv_until(ws, "input_audio_buffer.committed")[-1]
assert committed["previous_item_id"] == first["output"][0]["id"]
send(ws, "response.create")
second = recv_until(ws, "response.done")[-1]["response"]
assert second["status"] == "completed"
assert second["id"] != first["id"]
def test_conversation_cancel():
server.start()
with ws_connect() as ws:
recv(ws)
session_update(ws, output_modalities=["text"])
send_text(ws, "hello")
send(ws, "response.create")
recv_until(ws, "response.output_text.delta")
send(ws, "response.cancel")
assert recv_until(ws, "response.done")[-1]["response"]["status"] == "cancelled"
# the session still works
send_text(ws, "hello again")
send(ws, "response.create", response={"max_output_tokens": 4})
response = recv_until(ws, "response.done")[-1]["response"]
assert response["status"] == "completed"
assert response["usage"]["output_tokens"] == 4
def test_conversation_session_update():
server.start()
tools = [{"type": "function", "name": "get_weather", "description": "Get the weather",
"parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}]
with ws_connect() as ws:
recv(ws)
session = session_update(ws, instructions="Be brief.", tools=tools, tool_choice="none", max_output_tokens=16,
audio={"output": {"voice": {"id": "male"}}})
assert session["instructions"] == "Be brief."
assert session["tools"] == tools
assert session["tool_choice"] == "none"
assert session["max_output_tokens"] == 16
assert session["audio"]["output"]["voice"] == "male"
session = session_update(ws, max_output_tokens="inf", output_modalities=["text", "audio"])
assert session["max_output_tokens"] == "inf"
assert session["output_modalities"] == ["text", "audio"]
@pytest.mark.parametrize("events,message", [
([{"type": "response.create"}], "commit audio or create a message first"),
([{"type": "input_audio_buffer.commit"}], "the buffer is empty"),
([{"type": "conversation.item.create", "item": {"type": "message", "role": "assistant", "content": []}}], "only user messages"),
([{"type": "conversation.item.create", "item": {"type": "message", "role": "user", "content": [{"type": "input_image"}]}}], "unsupported content type"),
([{"type": "conversation.item.create", "item": {"type": "function_call_output", "call_id": "x", "output": "{}"}}], "must follow the response"),
([{"type": "session.update", "session": {"type": "foo"}}], "unknown session type"),
([{"type": "session.update", "session": {"output_modalities": []}}], "non-empty array"),
([{"type": "session.update", "session": {"output_modalities": ["video"]}}], "unknown modality"),
([{"type": "session.update", "session": {"max_output_tokens": 0}}], "max_output_tokens"),
([{"type": "session.update", "session": {"tool_choice": "maybe"}}], "tool_choice"),
([{"type": "session.update", "session": {"audio": {"output": {"voice": "alloy"}}}}], "unknown voice"),
([{"type": "conversation.item.create", "item": {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "hi"}]}},
{"type": "session.update", "session": {"instructions": "Be brief."}}], "cannot change after"),
([{"type": "conversation.item.create", "item": {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "hi"}]}},
{"type": "session.update", "session": {"type": "transcription"}}], "cannot change after"),
])
def test_conversation_invalid_events(events: list[dict], message: str):
server.start()
with ws_connect() as ws:
recv(ws)
for ev in events:
ws.send(json.dumps(ev))
err = recv_until(ws, "error")[-1]
assert message in err["error"]["message"]
def test_transcription_session():
server.start()
with ws_connect() as ws:
recv(ws)
session = session_update(ws, type="transcription", max_output_tokens=8,
audio={"input": {"transcription": {"language": "fr"}}})
assert session["object"] == "realtime.transcription_session"
assert session["audio"]["input"]["transcription"]["language"] == "fr"
send_text(ws, "hello")
assert "not supported in a transcription session" in recv_until(ws, "error")[-1]["error"]["message"]
transcripts = []
for freq in [440, 880]:
send_audio(ws, make_pcm16(freq=freq))
send(ws, "input_audio_buffer.commit")
committed = recv_until(ws, "input_audio_buffer.committed")[-1]
events = recv_until(ws, "conversation.item.input_audio_transcription.completed")
transcripts += get_transcripts(events)
assert transcripts[-1][0] == committed["item_id"]
assert len(transcripts) == 2
assert all(len(text) > 0 for _, text in transcripts)
#
# slot and server state
#
@pytest.mark.parametrize("path", ["/v1/realtime", "/v1/realtime?intent=transcription"])
def test_realtime_disconnect_frees_slot(path: str):
server.n_slots = 1
server.start()
with ws_connect(path) as ws:
recv(ws)
send_audio(ws, make_pcm16())
if path == "/v1/realtime":
send(ws, "response.create")
recv_until(ws, "response.output_item.added")
# the socket is closed in the middle of the session
res = server.make_request("POST", "/v1/chat/completions", data={
"max_tokens": 4,
"messages": [{"role": "user", "content": "hello"}],
})
assert res.status_code == 200
def test_realtime_router():
global server
model = server.model_hf_repo
server = ServerPreset.router()
server.start()
with ws_connect(f"/v1/realtime?model={model}") as ws:
assert recv(ws)["type"] == "session.created"
session_update(ws, output_modalities=["text"], max_output_tokens=4)
send_text(ws, "hello")
send(ws, "response.create")
assert recv_until(ws, "response.done")[-1]["response"]["status"] == "completed"
def test_realtime_sleep():
server.sleep_idle_seconds = 1
server.start()
start = time.time()
while not server.make_request("GET", "/props").body["is_sleeping"]:
assert time.time() - start < 10, "server did not go to sleep"
time.sleep(0.1)
# the session wakes the server up
with ws_connect() as ws:
assert recv(ws)["type"] == "session.created"
session_update(ws, output_modalities=["text"], max_output_tokens=4)
send_text(ws, "hello")
send(ws, "response.create")
assert recv_until(ws, "response.done")[-1]["response"]["status"] == "completed"
+1 -1
View File
@@ -314,7 +314,7 @@ def test_cors_proxy_only_forwards_explicit_proxy_headers():
server = ServerPreset.tinyllama2()
server.api_key = TEST_API_KEY
server.ui_mcp_proxy = True
server.debug_proxy_allow_private = True
server.ui_mcp_proxy_allow_private_urls = True
server.start()
res = server.make_request("GET", f"/cors-proxy?url=http://127.0.0.1:{target.server_port}/capture", headers={
+53 -3
View File
@@ -5,6 +5,10 @@
import subprocess
import os
import io
import math
import struct
import wave
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tmp")
import re
@@ -126,7 +130,7 @@ class ServerProcess:
no_cache_idle_slots: bool = False
log_path: str | None = None
ui_mcp_proxy: bool = False
debug_proxy_allow_private: bool = False # test-only: lets the CORS proxy reach local servers
ui_mcp_proxy_allow_private_urls: bool = False
media_allow_private_urls: bool = False
allow_unauthenticated_tools: bool = False
backend_sampling: bool = False
@@ -155,8 +159,6 @@ class ServerProcess:
**os.environ,
"LLAMA_SERVER_DEBUG_FAKE_TIMING": "1",
}
if self.debug_proxy_allow_private:
env["LLAMA_SERVER_DEBUG_PROXY_ALLOW_PRIVATE"] = "1"
if self.llama_cache is not None:
env["LLAMA_CACHE"] = self.llama_cache
elif "LLAMA_CACHE" not in os.environ:
@@ -313,6 +315,8 @@ class ServerProcess:
server_args.append("--no-cache-idle-slots")
if self.ui_mcp_proxy:
server_args.append("--ui-mcp-proxy")
if self.ui_mcp_proxy_allow_private_urls:
server_args.append("--ui-mcp-proxy-allow-private-urls")
if self.media_allow_private_urls:
server_args.append("--media-allow-private-urls")
if self.allow_unauthenticated_tools:
@@ -726,6 +730,36 @@ class ServerPreset:
server.seed = 42
return server
@staticmethod
def tinypockettts() -> ServerProcess:
# tts only, with voice cloning
server = ServerProcess()
server.offline = True # will be downloaded by load_all()
# mmproj is already provided by HF registry API
server.model_hf_file = None
server.model_hf_repo = "ggml-org-dev/tinyPocketTTS-for-testing-gguf:Q8_0"
server.model_alias = "tinypockettts"
server.n_ctx = 1024
server.n_batch = 512
server.n_slots = 1
server.seed = 42
return server
@staticmethod
def tinyvoxtralrt() -> ServerProcess:
# live transcription only, no chat
server = ServerProcess()
server.offline = True # will be downloaded by load_all()
# mmproj is already provided by HF registry API
server.model_hf_file = None
server.model_hf_repo = "ggml-org-dev/tinyVoxtral-Realtime-for-testing-gguf:Q8_0"
server.model_alias = "tinyvoxtralrt"
server.n_ctx = 1024
server.n_batch = 512
server.n_slots = 1
server.seed = 42
return server
@staticmethod
def router() -> ServerProcess:
server = ServerProcess()
@@ -832,3 +866,19 @@ def get_lan_ip(server: ServerProcess) -> str | None:
def is_slow_test_allowed():
return os.environ.get("SLOW_TESTS") == "1" or os.environ.get("SLOW_TESTS") == "ON"
def make_pcm16(seconds: float = 1.0, rate: int = 16000, freq: float = 440.0) -> bytes:
""" sine tone as raw PCM16 mono samples """
n = int(seconds * rate)
return struct.pack(f"<{n}h", *(int(0.3 * 32767 * math.sin(2 * math.pi * freq * i / rate)) for i in range(n)))
def make_wav(seconds: float = 1.0, rate: int = 16000, freq: float = 440.0) -> bytes:
buf = io.BytesIO()
with wave.open(buf, "wb") as w:
w.setnchannels(1)
w.setsampwidth(2)
w.setframerate(rate)
w.writeframes(make_pcm16(seconds, rate, freq))
return buf.getvalue()
+3 -2
View File
@@ -86,8 +86,9 @@ int main(int argc, char ** argv) {
}
mtmd_context_params mtmd_params = mtmd_context_params_default();
mtmd_params.use_gpu = params.mmproj_use_gpu;
mtmd_params.device = params.mmproj_device;
mtmd_params.use_gpu = params.mmproj_use_gpu;
mtmd_params.device = params.mmproj_device;
mtmd_params.n_threads = params.cpuparams.n_threads;
mtmd::context_ptr mctx(mtmd_init_from_file(params.mmproj.path.c_str(), model, mtmd_params));
if (!mctx) {
LOG_ERR("failed to load mmproj %s\n", params.mmproj.path.c_str());
+6 -2
View File
@@ -5,7 +5,8 @@ The UI of llama.cpp: the packages in `lib` and the apps built on them.
```text
ui/
├── lib/
│ └── ui/ @ggml-org/llama-ui: design tokens, fonts, surfaces and components
│ ├── ui/ @ggml-org/llama-ui: design tokens, fonts, surfaces and components
│ └── voice/ @ggml-org/llama-voice: microphone capture, transcription and dictation
└── apps/
└── chat/ Llama Chat, the chat app that llama-server serves
```
@@ -13,12 +14,15 @@ ui/
- [`lib/ui`](lib/ui/README.md) draws the parts and handles interaction, with no business logic. It is built with
`@sveltejs/package` and published to npm as `@ggml-org/llama-ui`. Apps in this repo skip the package: they compile
its sources as part of their own build, so they hold no copy of a component, a token or a font.
- [`lib/voice`](lib/voice/README.md) records the microphone and turns speech into text through llama-server, with no
UI: Llama UI draws the voice parts. It is plain TypeScript built with `tsc`, plus a Svelte entry
(`@ggml-org/llama-voice/svelte`). Apps in this repo compile its sources too. It is not published to npm yet.
- [`apps/chat`](apps/chat/README.md) talks to llama-server, stores conversations and runs the agentic loop. CMake
builds it into llama-server (see `scripts/ui-assets.cmake`), and it is published to npm as `@ggml-org/llama-chat`
(with `llama-chat` as its short name), so `npx llama-chat` runs it against any llama-server.
Each folder is its own npm package with its own `package-lock.json`: run `npm ci` in the one you work on. Building,
checking and testing `apps/chat` needs no install in `lib/ui`.
checking and testing `apps/chat` needs no install in `lib/ui` or `lib/voice`.
## Releases
+1 -1
View File
@@ -16,7 +16,7 @@ const config: StorybookConfig = {
'../tests/stories/**/*.stories.@(js|ts|svelte)',
{
directory: '../../../lib/ui/tests/stories',
files: '{foundations,components,app,models,mockups}/**/*.stories.svelte'
files: '{foundations,components,app,models,mockups,voice}/**/*.stories.svelte'
}
],
addons: [
+200 -191
View File
@@ -38,35 +38,21 @@ colors:
art-night-sky: 'oklch(0.33 0.07 256)'
art-cinder: 'oklch(0.68 0.18 46)'
art-cinder-light: 'oklch(0.85 0.065 46)'
cool-gray-50: 'oklch(0.958 0.002 250)'
cool-gray-100: 'oklch(0.938 0.004 250)'
cool-gray-200: 'oklch(0.91 0.005 250)'
cool-gray-300: 'oklch(0.86 0.007 250)'
cool-gray-400: 'oklch(0.81 0.01 250)'
red-400: 'oklch(0.69 0.2 27)'
red-450: 'oklch(0.635 0.229 28)'
red-500: 'oklch(0.6 0.235 27)'
red-550: 'oklch(0.588 0.236 28)'
red-600: 'oklch(0.55 0.22 27)'
red-800: 'oklch(0.43 0.17 27)'
yellow-300: 'oklch(0.9 0.14 84)'
yellow-400: 'oklch(0.85 0.17 84)'
yellow-800: 'oklch(0.5 0.1 84)'
green-400: 'oklch(0.81 0.16 148)'
green-450: 'oklch(0.756 0.197 147)'
green-500: 'oklch(0.73 0.2 148)'
green-550: 'oklch(0.669 0.197 147)'
green-650: 'oklch(0.52 0.17 147)'
green-800: 'oklch(0.45 0.14 148)'
amber-250: 'oklch(0.842 0.165 84)'
amber-400: 'oklch(0.752 0.157 78)'
amber-650: 'oklch(0.547 0.116 74)'
blue-400: 'oklch(0.7 0.163 255)'
blue-450: 'oklch(0.67 0.173 256)'
blue-500: 'oklch(0.62 0.15 255)'
blue-550: 'oklch(0.587 0.177 256)'
blue-650: 'oklch(0.535 0.177 256)'
blue-800: 'oklch(0.42 0.11 255)'
white-a2: 'oklch(1 0 0 / 0.02)'
white-a4: 'oklch(1 0 0 / 0.04)'
white-a6: 'oklch(1 0 0 / 0.06)'
@@ -75,7 +61,6 @@ colors:
white-a18: 'oklch(1 0 0 / 0.18)'
white-a20: 'oklch(1 0 0 / 0.2)'
white-a30: 'oklch(1 0 0 / 0.3)'
white-a40: 'oklch(1 0 0 / 0.4)'
white-a50: 'oklch(1 0 0 / 0.5)'
white-a85: 'oklch(1 0 0 / 0.85)'
black-a3: 'oklch(0 0 0 / 0.03)'
@@ -83,15 +68,8 @@ colors:
black-a5: 'oklch(0 0 0 / 0.05)'
black-a6: 'oklch(0 0 0 / 0.06)'
black-a8: 'oklch(0 0 0 / 0.08)'
black-a10: 'oklch(0 0 0 / 0.1)'
black-a12: 'oklch(0 0 0 / 0.12)'
black-a18: 'oklch(0 0 0 / 0.18)'
black-a25: 'oklch(0 0 0 / 0.25)'
black-a30: 'oklch(0 0 0 / 0.3)'
black-a35: 'oklch(0 0 0 / 0.35)'
black-a40: 'oklch(0 0 0 / 0.4)'
black-a55: 'oklch(0 0 0 / 0.55)'
black-a60: 'oklch(0 0 0 / 0.6)'
surface-page: '{colors.neutral-25}'
surface-muted: '{colors.neutral-100}'
surface-emphasis: '{colors.neutral-150}'
@@ -103,6 +81,7 @@ colors:
surface-code: '{colors.neutral-100}'
surface-overlay: '{colors.black-a40}'
fg-default: '{colors.neutral-950}'
fg-soft: 'color-mix(in oklch, {colors.fg-default} 70%, transparent)'
fg-muted: '{colors.neutral-500}'
fg-on-action: '{colors.neutral-50}'
fg-on-danger: '{colors.neutral-0}'
@@ -128,39 +107,21 @@ colors:
line-warning-soft: 'color-mix(in oklab, {colors.fill-warning} 34%, {colors.line-default})'
line-danger-soft: 'color-mix(in oklab, {colors.fill-danger} 34%, {colors.line-default})'
line-info-soft: 'color-mix(in oklab, {colors.fill-info} 34%, {colors.line-default})'
edge-rest-side: '{colors.cool-gray-200}'
edge-rest-mid: '{colors.cool-gray-100}'
edge-focus-side: '{colors.cool-gray-400}'
edge-focus-mid: '{colors.cool-gray-300}'
edge-ambient-side: '{colors.cool-gray-100}'
edge-ambient-mid: '{colors.cool-gray-50}'
edge-faint: '{colors.cool-gray-100}'
edge-rest: '{colors.cool-gray-200}'
edge-focus: '{colors.cool-gray-400}'
edge-ambient: '{colors.cool-gray-100}'
edge-raised: '{colors.cool-gray-200}'
action-primary: '{colors.neutral-900}'
action-primary-hover: 'oklch(0.205 0 0 / 0.9)'
action-primary-hover: 'color-mix(in oklch, {colors.action-primary} 90%, transparent)'
action-danger: '{colors.fill-danger}'
action-danger-hover: 'color-mix(in oklch, {colors.fill-danger} 90%, transparent)'
action-danger-hover: 'color-mix(in oklch, {colors.action-danger} 90%, transparent)'
action-quiet: 'oklch(0.97 0 0 / 0.3)'
action-quiet-hover: '{colors.neutral-100}'
action-ghost-hover: 'oklch(0.556 0 0 / 0.1)'
field-background: '{colors.neutral-0}'
field-shade: '{colors.black-a6}'
status-danger: '{colors.fill-danger}'
status-danger-rim: '{colors.red-400}'
status-danger-glyph: '{colors.red-800}'
status-warning: '{colors.fill-warning}'
status-warning-rim: '{colors.yellow-300}'
status-warning-glyph: '{colors.yellow-800}'
status-success: '{colors.fill-success}'
status-success-rim: '{colors.green-400}'
status-success-glyph: '{colors.green-800}'
status-info: '{colors.fill-info}'
status-info-rim: '{colors.blue-400}'
status-info-glyph: '{colors.blue-800}'
highlight-inner: '{colors.white-a50}'
highlight-inverse: '{colors.white-a12}'
sheen-start: '{colors.white-a20}'
sheen-end: 'transparent'
elevation-ring: '{colors.black-a5}'
surface-page-matte: '{colors.neutral-0}'
surface-glass-matte: 'oklch(0.97 0 0 / 0.6)'
@@ -180,13 +141,14 @@ colors:
surface-glass-dark: 'oklch(0.269 0 0 / 0.75)'
surface-code-dark: '{colors.neutral-900}'
fg-default-dark: '{colors.neutral-50}'
fg-soft-dark: 'color-mix(in oklch, {colors.fg-default-dark} 70%, transparent)'
fg-muted-dark: '{colors.neutral-400}'
fg-on-action-dark: '{colors.neutral-900}'
fg-code-dark: '{colors.neutral-300}'
fg-danger-dark: '{colors.red-450}'
fg-success-dark: '{colors.green-450}'
fg-warning-dark: '{colors.amber-250}'
fg-info-dark: '{colors.blue-400}'
fg-danger-dark: '{colors.fill-danger-dark}'
fg-success-dark: '{colors.fill-success-dark}'
fg-warning-dark: '{colors.fill-warning-dark}'
fg-info-dark: '{colors.fill-info-dark}'
line-default-dark: '{colors.white-a30}'
line-field-dark: '{colors.white-a30}'
line-control-dark: '{colors.white-a12}'
@@ -204,27 +166,18 @@ colors:
line-warning-soft-dark: 'color-mix(in oklab, {colors.fill-warning-dark} 38%, {colors.line-default-dark})'
line-danger-soft-dark: 'color-mix(in oklab, {colors.fill-danger-dark} 38%, {colors.line-default-dark})'
line-info-soft-dark: 'color-mix(in oklab, {colors.fill-info-dark} 38%, {colors.line-default-dark})'
edge-rest-side-dark: '{colors.white-a6}'
edge-rest-mid-dark: '{colors.white-a4}'
edge-focus-side-dark: '{colors.white-a18}'
edge-focus-mid-dark: '{colors.white-a12}'
edge-ambient-side-dark: '{colors.white-a4}'
edge-ambient-mid-dark: '{colors.white-a2}'
edge-faint-dark: '{colors.white-a4}'
edge-rest-dark: '{colors.white-a6}'
edge-focus-dark: '{colors.white-a18}'
edge-ambient-dark: '{colors.white-a4}'
edge-raised-dark: '{colors.white-a9}'
action-primary-dark: '{colors.neutral-200}'
action-primary-hover-dark: 'oklch(0.922 0 0 / 0.9)'
action-primary-hover-dark: 'color-mix(in oklch, {colors.action-primary-dark} 90%, transparent)'
action-danger-dark: 'color-mix(in oklch, {colors.fill-danger-dark} 58%, transparent)'
action-danger-hover-dark: 'color-mix(in oklch, {colors.fill-danger-dark} 68%, transparent)'
action-quiet-dark: 'oklch(0.708 0 0 / 0.15)'
action-quiet-hover-dark: 'oklch(0.708 0 0 / 0.25)'
action-ghost-hover-dark: 'oklch(0.708 0 0 / 0.1)'
field-background-dark: '{colors.white-a9}'
field-shade-dark: '{colors.black-a30}'
status-danger-dark: '{colors.fill-danger-dark}'
status-warning-dark: '{colors.fill-warning-dark}'
status-success-dark: '{colors.fill-success-dark}'
status-info-dark: '{colors.fill-info-dark}'
highlight-inner-dark: '{colors.white-a4}'
sheen-start-dark: '{colors.white-a2}'
elevation-ring-dark: '{colors.white-a18}'
@@ -254,6 +207,11 @@ typography:
fontSize: 0.75rem
fontWeight: 400
lineHeight: 1rem
caption-sm:
fontFamily: 'Llama Sans'
fontSize: 0.625rem
fontWeight: 400
lineHeight: 0.875rem
title:
fontFamily: 'Llama Sans'
fontSize: 1.125rem
@@ -264,18 +222,24 @@ typography:
fontSize: 1.5rem
fontWeight: 600
lineHeight: 2rem
display:
fontFamily: 'Llama Sans'
fontSize: 1.875rem
fontWeight: 600
lineHeight: 2.25rem
code:
fontFamily: 'Llama Mono'
fontSize: 0.875rem
fontWeight: 400
lineHeight: 1.25rem
rounded:
control: 0.5rem
panel: 0.625rem
card: 0.875rem
container: 1rem
surface: 1.5rem
surface-lg: 2rem
sm: 6px
md: 8px
lg: 10px
xl: 14px
2xl: 16px
3xl: 24px
4xl: 32px
full: 9999px
spacing:
xs: 4px
@@ -288,7 +252,7 @@ components:
chat-form:
backgroundColor: '#f9f9f9'
textColor: '{colors.fg-default}'
rounded: '{rounded.surface}'
rounded: '{rounded.3xl}'
typography: '{typography.body}'
chat-form-dark:
backgroundColor: '#202020'
@@ -298,47 +262,47 @@ components:
chat-form-placeholder-dark:
textColor: '{colors.fg-muted-dark}'
chat-form-edge:
backgroundColor: '{colors.edge-rest-side}'
backgroundColor: '{colors.edge-rest}'
chat-form-edge-dark:
backgroundColor: '{colors.edge-rest-side-dark}'
backgroundColor: '{colors.edge-rest-dark}'
chat-form-edge-focus:
backgroundColor: '{colors.edge-focus-side}'
backgroundColor: '{colors.edge-focus}'
chat-form-edge-focus-dark:
backgroundColor: '{colors.edge-focus-side-dark}'
backgroundColor: '{colors.edge-focus-dark}'
card:
backgroundColor: '#f9f9f9'
textColor: '{colors.fg-default}'
rounded: '{rounded.card}'
rounded: '{rounded.xl}'
padding: '24px'
card-dark:
backgroundColor: '#202020'
textColor: '{colors.fg-default-dark}'
card-edge:
backgroundColor: '{colors.edge-rest-side}'
backgroundColor: '{colors.edge-rest}'
card-edge-dark:
backgroundColor: '{colors.edge-rest-side-dark}'
backgroundColor: '{colors.edge-rest-dark}'
sidebar:
backgroundColor: '#f9f9f9'
textColor: '{colors.fg-default}'
rounded: '{rounded.container}'
rounded: '{rounded.2xl}'
sidebar-dark:
backgroundColor: '#1c1c1c'
textColor: '{colors.fg-default-dark}'
sidebar-edge:
backgroundColor: '{colors.edge-ambient-side}'
backgroundColor: '{colors.edge-ambient}'
sidebar-edge-dark:
backgroundColor: '{colors.edge-ambient-side-dark}'
backgroundColor: '{colors.edge-ambient-dark}'
inset-group:
backgroundColor: 'oklch(1 0 0 / 0.85)'
textColor: '{colors.fg-default}'
rounded: '{rounded.card}'
rounded: '{rounded.xl}'
inset-group-dark:
backgroundColor: 'oklch(0.985 0 0 / 0.03)'
textColor: '{colors.fg-default-dark}'
inset-group-edge:
backgroundColor: '{colors.edge-ambient-side}'
backgroundColor: '{colors.edge-ambient}'
inset-group-edge-dark:
backgroundColor: '{colors.edge-ambient-side-dark}'
backgroundColor: '{colors.edge-ambient-dark}'
selected-row:
backgroundColor: 'oklch(0.145 0 0 / 0.05)'
textColor: '{colors.fg-default}'
@@ -348,19 +312,19 @@ components:
user-bubble:
backgroundColor: '#f3f3f3'
textColor: '{colors.fg-default}'
rounded: '{rounded.surface}'
rounded: '{rounded.2xl}'
typography: '{typography.body}'
user-bubble-dark:
backgroundColor: '#181818'
textColor: '{colors.fg-default-dark}'
user-bubble-edge:
backgroundColor: '{colors.edge-faint}'
backgroundColor: '{colors.edge-ambient}'
user-bubble-edge-dark:
backgroundColor: '{colors.edge-faint-dark}'
backgroundColor: '{colors.edge-ambient-dark}'
floating-panel:
backgroundColor: '#ffffff'
textColor: '{colors.fg-default}'
rounded: '{rounded.panel}'
rounded: '{rounded.lg}'
typography: '{typography.body-sm}'
floating-panel-dark:
backgroundColor: '#161616'
@@ -376,14 +340,14 @@ components:
dialog:
backgroundColor: '#ffffff'
textColor: '{colors.fg-default}'
rounded: '{rounded.panel}'
rounded: '{rounded.lg}'
dialog-dark:
backgroundColor: '#0d0d0d'
textColor: '{colors.fg-default-dark}'
tooltip:
backgroundColor: '{colors.action-primary}'
textColor: '{colors.fg-on-action}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.caption}'
tooltip-dark:
backgroundColor: '{colors.action-primary-dark}'
@@ -391,7 +355,7 @@ components:
button-primary:
backgroundColor: '{colors.action-primary}'
textColor: '{colors.fg-on-action}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '36px'
button-primary-dark:
@@ -406,7 +370,7 @@ components:
button-secondary:
backgroundColor: '#f9f9f9'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '36px'
button-secondary-dark:
@@ -425,7 +389,7 @@ components:
button-tertiary:
backgroundColor: '#fcfcfc'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '36px'
button-tertiary-dark:
@@ -444,7 +408,7 @@ components:
button-outline:
backgroundColor: '{colors.field-background}'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '36px'
button-outline-dark:
@@ -462,7 +426,7 @@ components:
textColor: '{colors.fg-default-dark}'
button-ghost:
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
button-ghost-dark:
textColor: '{colors.fg-default-dark}'
@@ -475,7 +439,7 @@ components:
button-destructive:
backgroundColor: '{colors.action-danger}'
textColor: '{colors.fg-on-danger}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '36px'
button-destructive-dark:
@@ -490,7 +454,7 @@ components:
toggle-on:
backgroundColor: '{colors.surface-selected}'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '36px'
toggle-on-dark:
@@ -505,7 +469,7 @@ components:
toggle-group:
backgroundColor: '#f9f9f9'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
height: '32px'
toggle-group-dark:
@@ -533,7 +497,7 @@ components:
textColor: '{colors.fg-default-dark}'
tabs-list:
backgroundColor: '{colors.surface-muted}'
rounded: '{rounded.panel}'
rounded: '{rounded.lg}'
height: '36px'
padding: '2px'
tabs-list-dark:
@@ -541,7 +505,7 @@ components:
tabs-trigger:
backgroundColor: '{colors.surface-muted}'
textColor: 'oklch(0.145 0 0 / 0.7)'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label}'
tabs-trigger-dark:
backgroundColor: '{colors.surface-muted-dark}'
@@ -582,7 +546,7 @@ components:
input:
backgroundColor: '{colors.field-background}'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.body-sm}'
height: '36px'
input-dark:
@@ -607,7 +571,7 @@ components:
badge-default:
backgroundColor: '{colors.action-primary}'
textColor: '{colors.fg-on-action}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
padding: '2px 8px'
badge-default-dark:
@@ -616,14 +580,14 @@ components:
badge-secondary:
backgroundColor: '#dadada'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-secondary-dark:
backgroundColor: '#252525'
textColor: '{colors.fg-default-dark}'
badge-outline:
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-outline-dark:
textColor: '{colors.fg-default-dark}'
@@ -634,7 +598,7 @@ components:
badge-destructive:
backgroundColor: '{colors.action-danger}'
textColor: '{colors.fg-on-danger}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-destructive-dark:
backgroundColor: '#952420'
@@ -642,7 +606,7 @@ components:
badge-success:
backgroundColor: '{colors.surface-success}'
textColor: '{colors.fg-success}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-success-dark:
backgroundColor: '{colors.surface-success-dark}'
@@ -650,7 +614,7 @@ components:
badge-warning:
backgroundColor: '{colors.surface-warning}'
textColor: '{colors.fg-warning}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-warning-dark:
backgroundColor: '{colors.surface-warning-dark}'
@@ -658,7 +622,7 @@ components:
badge-danger:
backgroundColor: '{colors.surface-danger}'
textColor: '{colors.fg-danger}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-danger-dark:
backgroundColor: '{colors.surface-danger-dark}'
@@ -666,7 +630,7 @@ components:
badge-info:
backgroundColor: '{colors.surface-info}'
textColor: '{colors.fg-info}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
typography: '{typography.label-sm}'
badge-info-dark:
backgroundColor: '{colors.surface-info-dark}'
@@ -674,7 +638,7 @@ components:
code-block:
backgroundColor: '{colors.surface-code}'
textColor: '{colors.fg-code}'
rounded: '{rounded.panel}'
rounded: '{rounded.lg}'
typography: '{typography.code}'
code-block-dark:
backgroundColor: '{colors.surface-code-dark}'
@@ -684,21 +648,21 @@ components:
list-row-selected:
backgroundColor: '{colors.surface-selected}'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
list-row-selected-dark:
backgroundColor: '{colors.surface-selected-dark}'
textColor: '{colors.fg-default-dark}'
panel-muted:
backgroundColor: '{colors.surface-muted}'
textColor: '{colors.fg-default}'
rounded: '{rounded.panel}'
rounded: '{rounded.lg}'
panel-muted-dark:
backgroundColor: '{colors.surface-muted-dark}'
textColor: '{colors.fg-default-dark}'
chip-emphasis:
backgroundColor: '{colors.surface-emphasis}'
textColor: '{colors.fg-default}'
rounded: '{rounded.control}'
rounded: '{rounded.md}'
chip-emphasis-dark:
backgroundColor: '{colors.surface-emphasis-dark}'
textColor: '{colors.fg-default-dark}'
@@ -708,22 +672,6 @@ components:
page-dark:
backgroundColor: '{colors.surface-page-dark}'
textColor: '{colors.fg-default-dark}'
chat-form-edge-mid:
backgroundColor: '{colors.edge-rest-mid}'
chat-form-edge-mid-dark:
backgroundColor: '{colors.edge-rest-mid-dark}'
chat-form-edge-mid-focus:
backgroundColor: '{colors.edge-focus-mid}'
chat-form-edge-mid-focus-dark:
backgroundColor: '{colors.edge-focus-mid-dark}'
sidebar-edge-mid:
backgroundColor: '{colors.edge-ambient-mid}'
sidebar-edge-mid-dark:
backgroundColor: '{colors.edge-ambient-mid-dark}'
inset-group-edge-mid:
backgroundColor: '{colors.edge-ambient-mid}'
inset-group-edge-mid-dark:
backgroundColor: '{colors.edge-ambient-mid-dark}'
glass-highlight:
backgroundColor: '{colors.highlight-inner}'
glass-highlight-dark:
@@ -734,33 +682,61 @@ components:
backgroundColor: '{colors.sheen-start}'
user-bubble-sheen-dark:
backgroundColor: '{colors.sheen-start-dark}'
field-shade:
backgroundColor: '{colors.field-shade}'
field-shade-dark:
backgroundColor: '{colors.field-shade-dark}'
status-lamp-danger-rim:
backgroundColor: '{colors.status-danger-rim}'
status-lamp-warning-rim:
backgroundColor: '{colors.status-warning-rim}'
status-lamp-success-rim:
backgroundColor: '{colors.status-success-rim}'
status-lamp-danger:
backgroundColor: '{colors.status-danger}'
textColor: '{colors.status-danger-glyph}'
backgroundColor: '{colors.fill-danger}'
rounded: '{rounded.full}'
size: '8px'
status-lamp-warning:
backgroundColor: '{colors.status-warning}'
textColor: '{colors.status-warning-glyph}'
backgroundColor: '{colors.fill-warning}'
rounded: '{rounded.full}'
size: '8px'
status-lamp-success:
backgroundColor: '{colors.status-success}'
textColor: '{colors.status-success-glyph}'
backgroundColor: '{colors.fill-success}'
rounded: '{rounded.full}'
size: '8px'
---
## In short
The rules most changes need. The sections below hold the detail and the reasons, and they
win where this list is too short. Before adding a token, a size or a component, use what is
here; if something really is missing, add it here first.
- **Components:** take base components from Llama UI (`@ggml-org/llama-ui/ui/<name>`); do not
build a new one when an existing one fits. Style them through their variants
(`variant="outline"`, `size="sm"`), not by overriding classes.
- **Colour:** greys build the UI; colour is for meaning only (status, destructive actions,
focus). Neutral colours go by shadcn's utility names (`bg-background`, `bg-muted`, `bg-card`,
`text-foreground`, `text-muted-foreground`, `border-border`), status by `bg-surface-*`,
`bg-fill-*`, `text-fg-*` and `border-line-*-soft` of `success`, `warning`, `danger` and
`info`, and any other semantic token as `bg-(--surface-lifted)`. In CSS, read the semantic
token (`var(--surface-page)`). No Tailwind palette classes, no hex.
- **Type:** Llama Sans, and Llama Mono for code, through roles: `text-body` (16px) for chat
messages and the chat input, `text-body-sm` (14px) for most text, `text-label` (14px, medium)
for buttons and labels, `text-label-sm` and `text-caption` (12px) for badges and hints,
`text-caption-sm` (10px) for tags and counts, `text-title` (18px) and `text-heading` (24px)
for the rare heading, `text-display` (30px) for the biggest headline. Never Tailwind's own sizes (`text-sm`, `text-xs`) or a size in
brackets.
- **Shape:** one corner scale, `rounded-sm` to `rounded-4xl`: `rounded-md` (8px) for controls,
fields and badges, `rounded-lg` (10px) for menus and dialogs, `rounded-xl` (14px) for cards,
`rounded-2xl` (16px) and `rounded-3xl` (24px) for the larger surfaces, `rounded-full` for
pills, avatars and lamps.
- **Sizes:** Tailwind's 4px spacing scale. Icons are Lucide, `size-icon-md` (16px), or
`size-icon-sm` (14px) in compact controls. Controls are `h-control-sm`, `h-control-md` or
`h-control-lg` (32, 36, 40px).
- **Surfaces:** one surface utility per element (`card-surface`, `matte-float`, `matte-key`,
`matte-well`), never raw `shadow-*`, `border-*` and `backdrop-blur-*` combinations.
- **Tokens:** read a semantic token directly. A component token is only for a value the
component decides itself. A value that follows from another token is mixed from it, not
picked again.
- **No arbitrary values** (`text-[11px]`, `rounded-[1.125rem]`, `p-[7px]`, `z-[20]`): pick the
nearest from the scale (`z-20`, `max-w-4/5`, `min-w-32`). Brackets are for what no scale can
hold: a `calc()`, a grid template, a list of transition properties.
- **Motion:** `ease-out-quint` for what enters or answers a press, `ease-sheet` for a sheet
or a page that slides.
- **Phones:** every dialog is full screen; only alerts stay small and centred.
- **The conversation is the loudest thing on screen;** everything around it stays quiet.
## Overview
**Llama UI** is the design system and component library this file describes. **Llama Chat**,
@@ -793,7 +769,7 @@ This file is the how, written for agents first. Its principles, as rules to appl
- **Colour has one job.** Greys build everything; status colours show status and nothing else;
art colours and cinder are for artwork and the odd brand detail, never for the UI's controls.
- **Recognisable, easy to change.** Keep the character in the icon, the type and one
accent, so an app built on Llama UI can restyle it through component tokens alone.
accent, so an app built on Llama UI can restyle it through semantic and component tokens alone.
- **Design lives in code.** The CSS is the source of truth; prefer what is generated or
derived over hand-tuned values, and record the reason next to the value. Content pages are
Markdown with Svelte components in them, as `.svx` (see `AGENTS.md`).
@@ -802,18 +778,35 @@ This file is the how, written for agents first. Its principles, as rules to appl
Design tokens come in three tiers, each in its own file under `ui/lib/ui/src/lib/styles/tokens/`:
1. **Primitives** (`primitives.css`): raw values named by what they are, such as
`neutral-900`, `cool-gray-200`, `red-500`, `white-a30`, `font-size-14` or `length-24`.
Only semantic tokens point at them.
1. **Primitives** (`primitives.css`): raw colours named by what they are, such as
`neutral-900`, `cool-gray-200`, `red-550` or `white-a30`. Only semantic tokens point at
them. Sizes are not primitives: a role holds its own value, and spacing is Tailwind's 4px
grid.
2. **Semantic tokens** (`semantic.css`): named by purpose, such as `surface-glass`,
`fg-muted`, `line-field`, `edge-focus-side`, `action-primary` or `status-warning`. They
point at primitives and are the only tier that changes between light and dark. The type,
corner, icon size and control height roles live here too and are Tailwind utilities:
`text-label`, `rounded-control`, `size-icon-md`, `h-control-md`.
3. **Component tokens** (`components.css`): one group per component, named
`[component]-[variant]-[property]-[state]`, such as `chat-form-edge-side-focus` or
`button-secondary-background-hover`. They point at semantic tokens, and components read
them as `bg-(--button-primary-background)` and similar.
`fg-muted`, `line-field`, `edge-focus`, `action-primary` or `fill-warning`, and the only
tier that changes between light and dark. Each is either a pick, which names a primitive
per theme, or a derivation, which is mixed from another semantic token by a fixed rule and
so follows it through every theme with a single declaration:
- soft text is the text colour at 70% (`fg-soft`);
- a hover fill is the fill at 90% (`action-primary-hover`);
- a status surface is its fill mixed into the page, and a status line its fill mixed into
the default line, by a share the theme sets (11% and 34% in light, 16% and 38% in dark);
- a dark shadow is the light one, `elevation-strength` (1 in light, 5 in dark) times as
dense;
- the middle of a matte edge is its side at two thirds, and a lamp's rim and glyph are
its fill mixed 30% towards white and towards black (both in `surfaces.css`).
The type, icon size and control height roles live here too and are Tailwind utilities:
`text-label`, `size-icon-md`, `h-control-md`. Corners are Tailwind's own `rounded-sm` to
`rounded-4xl`, computed from `--radius` in `theme.css`. shadcn's
colour names (`background`, `muted-foreground`, `border` ...) exist as Tailwind utilities
only, each mapped to a semantic token in `theme.css`.
3. **Component tokens** (`components.css`): only what a component decides itself, named
`[component]-[variant]-[property]-[state]`, such as `button-secondary-background-hover` or
`float-panel-background-modal`: a value no semantic token has, or one that only this
component changes between themes. A component that takes a semantic token as it is reads
the semantic token, as `bg-(--action-primary)` and similar, and gets no alias here.
The front matter's `colors`, `typography` and `rounded` are generated from the primitives, the
semantic tokens and the font stacks by `npm run design:tokens` in `ui/apps/chat`, and CI fails
@@ -860,16 +853,18 @@ the Surface switch in Storybook's toolbar, and only its surface tokens differ: `
`surface-raised` for menus and dialogs, `surface-lifted` for a selection raised on a
recessed track, `surface-pressed` for a key pressed in, `surface-glass` for the translucent matte fill, `surface-code` for code and
`surface-overlay` behind dialogs.
- **Foreground:** `fg-default` and `fg-muted` for text and icons, `fg-on-action` and
- **Foreground:** `fg-default` and `fg-muted` for text and icons, `fg-soft` (the text colour
at 70%) for the label of an option that is not the picked one, `fg-on-action` and
`fg-on-danger` on filled buttons, `fg-code` for code, `fg-danger` for errors,
`fg-success` for confirmations such as a copied check, `fg-warning` for cautions and
`fg-info` for neutral notices.
- **Lines:** `line-default` for dividers, `line-control` for outlined controls (soft in dark
mode), `line-field` for inputs, `line-focus` for focus and `line-danger` for invalid fields.
- **Edges:** the hairlines of matte surfaces, darker at the sides than in the middle.
`edge-rest-*` at rest, `edge-focus-*` when focus is inside, `edge-ambient-*` for large
quiet containers whose edge never changes, `edge-faint` for the user bubble and
`edge-raised` for floating panels.
- **Edges:** the hairlines of matte surfaces, darker at the sides than in the middle (the
token is the side; the surface fades it to two thirds in the middle). `edge-rest` at rest,
`edge-focus` when focus is inside, `edge-ambient` for large quiet containers whose edge
never changes and, kept even all round, for the user bubble, and `edge-raised` for floating
panels.
- **Actions:** `action-primary` (near black in light mode, near white in dark mode) and its
hover, `action-danger` and its hover, and `action-ghost-hover`.
- **Status fills:** `fill-success`, `fill-warning`, `fill-danger` and `fill-info` are each
@@ -880,9 +875,9 @@ the Surface switch in Storybook's toolbar, and only its surface tokens differ: `
`surface-info` are soft tints of each status fill for alerts and soft badges, with
`line-*-soft` hairlines to match. They are mixed in oklab so the hue holds over the page.
Soft status badges are pills with a small dot in the status fill before the label.
- **Status:** `status-danger`, `status-warning`, `status-success` and `status-info` are the
lamp fills for error or stopped, loading or warning, ready or connected, and informational. They take the status
fills, and each has a lighter `-rim` and a darker `-glyph`. Known gap: the glyph on the red lamp
- **Status:** `fill-danger`, `fill-warning`, `fill-success` and `fill-info` are the
lamp fills for error or stopped, loading or warning, ready or connected, and informational. A lamp adds
a lighter rim and a darker glyph, both mixed from its fill. Known gap: the glyph on the red lamp
reaches only about 2:1 and on the green lamp about 3.2:1, below WCAG AA, so the lamp colour
must never be the only signal; pair it with a label or tooltip.
@@ -895,14 +890,21 @@ is one variable font with an optical size axis: the browser sets it from the fon
looser Small one, with a blend in between. Nothing needs choosing per element; pin a point only to
show it, with `font-variation-settings: 'opsz' 16` or `36`. Its line box is 1.25 at every size, centred on the
cap height; large headings set `line-height: 1.15` themselves. Llama Mono keeps every character,
its coding ligatures included, in one cell, so code and numbers line up in columns. Type is set through roles that fix size, line height and weight together:
its coding ligatures included, in one cell, so code and numbers line up in columns. Type is set through roles that fix size and line height together, and for labels and headings the weight too:
- `body` (16/24, 400): chat messages and the chat input.
- `body-sm` (14/20, 400): most text, fields and lists.
- `body` (16/24): chat messages and the chat input.
- `body-sm` (14/20): most text, fields and lists.
- `label` (14/20, 500): buttons and field labels.
- `label-sm` (12/16, 500): badges and compact labels.
- `caption` (12/16, 400): tooltips, hints and metadata.
- `title` (18/28, 600) and `heading` (24/32, 600): rare headings; there is no display size.
- `caption` (12/16): tooltips, hints and metadata.
- `caption-sm` (10/14): the smallest text, for tags, compact badges and counts.
- `title` (18/28, 600) and `heading` (24/32, 600): rare headings.
- `display` (30/36, 600): the biggest headline, such as the greeting on a new chat.
Body and caption text takes the weight around it, regular unless a parent says otherwise; add
a weight class for anything else (`text-body-sm font-semibold`). The roles are the whole
scale: no `text-sm` or `text-xs`, and no size in brackets. On a phone a row that needs larger
text takes the next role up (`text-body-sm max-md:text-body`).
When a component lets callers override the size, keep an explicit weight class next to the
role (`text-label font-medium`) so a size override does not drop the weight. Placeholders
@@ -978,8 +980,8 @@ matches the role of the surface instead of combining raw shadows.
- **`matte-float`** and **`matte-float-modal`:** menus, popovers, select lists, hover cards
and drawers, and dialogs over the page colour. An 86% opaque panel with blur, a faint edge,
a rim and a deeper shadow. The edge is a hairline ring baked into the shadow as its last
layer (`float-panel-edge`). The panel's 1px border is its rim, the inner highlight
(`float-panel-highlight`) right inside the ring; an inset shadow for the rim would sit inside
layer (`edge-raised`). The panel's 1px border is its rim, the inner highlight
(`highlight-inner`) right inside the ring; an inset shadow for the rim would sit inside
the border instead, and the 1px between the two would draw a double edge. In light mode
dialogs are solid white instead: over the dimmed page a translucent white turns grey.
- **`matte-key`:** buttons, selects, toggles and tabs. The matte finish: on top of the
@@ -991,12 +993,12 @@ matches the role of the surface instead of combining raw shadows.
(`--key-sheen-solid`), the same blur, and an even 1px hairline in a shade of the fill drawn
inside the button (`--key-edge`), so the width does not change. The danger key stays matte
glass rather than metal: its sheen is almost none (`--button-danger-sheen`), and in dark mode
it is a frosted, translucent red (`red-500` at 58%) whose edge is a soft tint of the red, never
it is a frosted, translucent red (`fill-danger` at 58%) whose edge is a soft tint of the red, never
a lighter rim.
- **`elevated-control`**, **`elevated-surface`** and **`elevated-raised`:** cards, floating
bars and thumbnails. An elevation token with a hairline ring baked in as its last layer, so
the edge melts into the shadow and the shadow deepens in dark mode. The ring is
`--elevation-ring` (black 5%, white 18% in dark) at `--elevation-ring-width` (1px). They
`--elevation-ring` (black 5%, white 18% in dark), 1px wide. They
replace a border plus a shadow; never add a border to them.
- **`matte-well`:** inputs, textareas and checkboxes. A shallow inset shade so
fields read as recessed.
@@ -1007,16 +1009,16 @@ matches the role of the surface instead of combining raw shadows.
an even hairline, with no glow.
The elevation tokens are `elevation-surface`, `elevation-control`, `elevation-raised`,
`elevation-inset` and `elevation-tooltip`. The drop shadows are smooth stacks: a few soft
`elevation-inset` and `elevation-pressed`; a tooltip takes `elevation-surface`. The drop shadows are smooth stacks: a few soft
layers instead of one hard one, the closest the darkest and smallest, each further layer about
twice the offset and blur and fainter, the far ones pulled in with a negative spread, so the
shadow fades out instead of ending in a visible edge. They stay as close as upstream's
Tailwind shadows: `elevation-surface` reaches about 20px, like `shadow-lg`, `elevation-raised`
about 38px, like `shadow-xl`, and `elevation-control` is three tight layers reaching no further
than 4px, so buttons and other controls sit close to the page. Two softer steps sit below them: `elevation-soft` for the chat form,
shadow fades out instead of ending in a visible edge. They are the only shadows: Tailwind's
own `shadow-sm` to `shadow-2xl` do not follow the theme and are not used. `elevation-surface`
reaches about 20px, `elevation-raised` about 38px, and `elevation-control` is three tight
layers reaching no further than 4px, so buttons and other controls sit close to the page. Two softer steps sit below them: `elevation-soft` for the chat form,
which floats only a little, and `elevation-faint` for the user message bubble, which barely
lifts. The keys inside the chat form, the add key and the model selector, take `elevation-key`
(`--chat-form-key-shadow`): a 0.5px hairline all round and a 1px drop, since the control elevation's soft
lifts. The keys inside the chat form, the add key and the model selector, take `elevation-key`:
a 0.5px hairline all round and a 1px drop, since the control elevation's soft
spread blends into the white form; in dark it is the control elevation. Dark mode deepens the same stacks. Tailwind's own `shadow-xs` to `shadow-2xl` are
built the same way (`tokens/semantic.css`), each reaching about as far as Tailwind's default for
it. Every
@@ -1025,11 +1027,12 @@ with a 2px blur.
## Shapes
Corners are soft and consistent, set through roles: `control` (8px) for buttons, fields and
badges, `panel` (10px) for menus and dialogs, `card` (14px) for cards, `container` (16px) for
the sidebar, and `surface` (24px) for the chat form and message bubbles, rising to
`surface-lg` (32px) for the chat form on small screens. Status lamps, avatars and the round
icon buttons in the chat form are fully round.
Corners are soft and consistent, on one scale that is computed from a single base radius
(`--radius`, 10px, in `theme.css`), so changing the base moves every corner with it: `sm`
(6px) for small marks and chips, `md` (8px) for buttons, fields and badges, `lg` (10px) for
menus and dialogs, `xl` (14px) for cards, `2xl` (16px) for the sidebar and message bubbles,
and `3xl` (24px) for the chat form, rising to `4xl` (32px) for the chat form on small
screens. Status lamps, avatars and the round icon buttons in the chat form are fully round.
## Brand
@@ -1071,15 +1074,15 @@ icon buttons in the chat form are fully round.
- **Toggles:** the same corners, type, heights, padding and icon size as buttons, with
square `icon-sm`, `icon` and `icon-lg` sizes for icon-only toggles. `default` has no fill
until hovered; `outline` borrows the outline button. Pressed toggles take
`toggle-background-on`.
`surface-selected`.
- **Button groups:** joined buttons share one shadow, drawn by the group, and one border at
each seam. A group separator replaces the seam border. Filled buttons draw a seam in their
own text colour (`button-primary-seam`, `button-danger-seam`) instead.
own text colour at 25% instead.
- **Selection on a track:** a choice that moves along a track is a recessed track with the
selection raised on it, never a row of outlined buttons. The track is `surface-muted` with
the inset shade (`elevation-inset`); the selection is a `surface-lifted` chip with
`elevation-control`, and unselected options are softened text with no fill. Tabs use the
same track for their list, with the active tab raised (`tabs-*`); a `line` variant
`elevation-control`, and unselected options are softened text (`fg-soft`) with no fill. Tabs use the
same track for their list, with the active tab raised; a `line` variant
underlines the active tab instead. The chip or underline slides between tabs in 300ms on a
plain ease-out, with a stretch of at most 5% along the move that is gone by the time it
lands; with reduced motion it jumps instead. The switch is the same track with a raised
@@ -1095,7 +1098,7 @@ icon buttons in the chat form are fully round.
- **Chat form:** one `chat-form-surface` holding the input, attachments and actions. Its fill
is the muted grey at 60% in light mode and 75% in dark mode.
- **User message bubble:** the primary colour at 5% with `matte-sheen` and the very faint
`edge-faint` hairline, so it separates from the page without a visible border.
`edge-ambient` hairline, so it separates from the page without a visible border.
- **Sidebar:** `sidebar-surface`, the muted fill at 60% with no inner highlight and the
ambient edge. On small screens it keeps a plain `shadow-md` instead.
- **Inset groups:** `inset-group-surface` gathers rows inside a glass panel, like the
@@ -1151,6 +1154,12 @@ icon buttons in the chat form are fully round.
(`--sidebar-reveal-x`), taking no taps while the page is aside. The page keeps room under its
last row (`max-md:pb-safe-24`) so the key never covers it. One per page, only for its main
action; from `md` up the action stays a button in the header.
- **Voice clips:** a recorded clip is a round primary play key, its waveform and the time in
`caption`: bars in the muted foreground at 40%, the played part in the primary colour, so
the clip stays neutral in both modes. The live waveform while recording is as tall as the
input's line (24px), the newest level on the right, and holds still with reduced motion. A
voice message's transcript opens under the clip on hover, keyboard focus or a tap, and
stays in the DOM for screen readers while closed.
- **Copy feedback:** a copy action turns its icon into a `fg-success` check for 1.5s
(`COPY_FEEDBACK_RESET_MS`), only when the copy succeeded, then back. The icon pops in with a
150ms fade and scale, skipped on first render and with reduced motion.
@@ -1168,8 +1177,8 @@ icon buttons in the chat form are fully round.
lifting the surface.
- Do use the status colours only for status. Buttons keep their neutral colours, and the
submit button stays black in light mode and white in dark mode.
- Do read component tokens in components, semantic tokens in shared styles, and primitives
only in semantic tokens.
- Do read a semantic token directly wherever a component takes it as it is. Add a component
token only for a value the component decides itself, never as an alias of a semantic token.
- Do add a new colour as a primitive first, then give it a semantic name before any
component uses it.
- Do give motion a job: show where something went or what changed, like a selection sliding
+1
View File
@@ -89,6 +89,7 @@ The app imports the library as `@ggml-org/llama-ui/ui/<name>` and compiles its s
| Routes | `src/routes` | `/`, `/chat/[id]`, `/models`, `/mcp-servers`, `/settings`, `/search` |
| App components | `src/lib/components/app` | Chat, navigation, models, MCP, settings and dialogs, grouped by area |
| UI components | `ui/lib/ui` | shadcn-svelte on bits-ui, from Llama UI |
| Voice | `ui/lib/voice` | Microphone capture, transcription and dictation, from Llama Voice (`@ggml-org/llama-voice`) |
| Hooks | `src/lib/hooks` | View logic between components and stores: scroll, drag and drop, pickers, keyboard |
| Stores | `src/lib/stores` | Application state as Svelte 5 runes: chat, conversations, the agentic loop, tools, models, settings |
| Services | `src/lib/services` | Stateless I/O: the llama-server API, IndexedDB, MCP, the Hugging Face Hub, the tool sandbox |
+1 -1
View File
@@ -115,7 +115,7 @@ Records every `scripts/docs/*.demo.ts` from the storage target and uploads `vide
## Writing a demo
Scripts get `test` and `expect` from `helpers.ts` without importing them. `demo.click`, `demo.hover` and `demo.type` glide a visible cursor to the target before acting, with timing varied like a person's (seeded per demo, so re-takes match); `demo.scroll` turns the mouse wheel over a target; `demo.zoom` pinches in on a control or a point to show a detail too small to read in the frame, holds, and pinches back out (with the fingertips drawn on a touch device); `demo.caption` shows a caption at the top of the frame. Use `test.use({ settings, startPath })` to seed other settings or start on another route.
Scripts get `test` and `expect` from `helpers.ts` without importing them. `demo.click`, `demo.hover` and `demo.type` glide a visible cursor to the target before acting, with timing varied like a person's (seeded per demo, so re-takes match); `demo.scroll` turns the mouse wheel over a target; `demo.zoom` pinches in on a control or a point to show a detail too small to read in the frame, holds, and pinches back out (with the fingertips drawn on a touch device); `demo.caption` shows a caption at the top of the frame. For voice input, `demo.microphone()` gives the page a microphone that hears nothing but `demo.speak(text)`, which reads the text in a synthetic voice (macOS `say`) and shows it as a caption, since the video has no sound. Use `test.use({ settings, startPath })` to seed other settings or start on another route.
## Conversations
+30
View File
@@ -301,9 +301,39 @@ function agenticDebugging(): Trace {
return trace;
}
/** A reply with a diagram, for diagram preview demos. */
function diagrams(): Trace {
const trace = new Trace('How a request flows through llama-server');
trace.user('Can you draw how a chat request flows through llama-server?');
trace.assistant(
[
'Here is the path a request takes:',
'',
'```mermaid',
'flowchart LR',
' U[Browser] -->|POST /v1/chat/completions| S(llama-server)',
' S --> Q{Slot free?}',
' Q -->|yes| P[Prompt processing]',
' Q -->|no| W[Queue]',
' W --> P',
' P --> G[Sample token]',
' G -->|more| G',
' G -->|SSE tokens| U',
' click S href "https://github.com/ggml-org/llama.cpp" "llama.cpp on GitHub" _blank',
'```',
'',
'Requests wait in the queue until a slot is free, then tokens stream back as they are sampled.'
].join('\n')
);
return trace;
}
/** Built-in traces, by name. */
export const DEMO_TRACES: Record<string, () => Trace> = {
'agentic-debugging': agenticDebugging,
diagrams,
'long-chat': longChat
};
+117 -13
View File
@@ -3,7 +3,15 @@ import { generateTrace } from './fixtures/traces.ts';
import { ScreencastRecorder } from './recorder.ts';
import { type CDPSession, type Locator, type Page, test as base } from '@playwright/test';
import { execFileSync } from 'node:child_process';
import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import {
appendFileSync,
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync
} from 'node:fs';
import { tmpdir } from 'node:os';
import { basename, join, resolve } from 'node:path';
const VIDEOS_DIR = resolve(import.meta.dirname, 'videos');
@@ -112,6 +120,68 @@ function seedSettings(config: Record<string, unknown>): void {
}
}
/**
* Swaps the page's microphone for one that hears only what `window.demoSpeak` plays into it,
* silence otherwise. Chromium's fake capture device crashes the page, so voice input is
* recorded with this instead. Runs in the page.
*/
function installFakeMicrophone(): void {
const context = new AudioContext();
const output = context.createMediaStreamDestination();
navigator.mediaDevices.getUserMedia = async (constraints) => {
if (!constraints?.audio || constraints.video) {
throw new DOMException('demo: only the microphone is faked', 'NotSupportedError');
}
await context.resume();
// each opening gets its own tracks, so a recording that stops them leaves the source on
return new MediaStream(output.stream.getAudioTracks().map((track) => track.clone()));
};
Object.assign(window, {
demoSpeak: async (wavBase64: string) => {
const bytes = Uint8Array.from(atob(wavBase64), (c) => c.charCodeAt(0));
const source = context.createBufferSource();
source.buffer = await context.decodeAudioData(bytes.buffer);
source.connect(output);
await context.resume();
await new Promise((done) => {
source.onended = done;
source.start();
});
}
});
}
/** `text` read by a synthetic voice, as a base64 WAV. Uses macOS `say`. */
function synthesizeSpeech(text: string, voice: string): string {
const dir = mkdtempSync(join(tmpdir(), 'demo-speech-'));
const file = join(dir, 'speech.wav');
try {
execFileSync('say', [
'-v',
voice,
'-o',
file,
'--file-format=WAVE',
'--data-format=LEI16@24000',
text
]);
return readFileSync(file).toString('base64');
} catch (error) {
throw new Error(`demo: speak() needs macOS \`say\` with the voice ${voice}`, {
cause: error
});
} finally {
rmSync(dir, { force: true, recursive: true });
}
}
/** Seeded randomness, so a demo moves the same way on every recording. */
function createRandom(seed: string): () => number {
let state = [...seed].reduce((h, c) => Math.imul(h ^ c.charCodeAt(0), 2654435761), 1);
@@ -143,19 +213,9 @@ export class Demo {
/** Shows a caption at the top of the frame for `ms`, clear of the chat form. */
async caption(text: string, ms = 2200): Promise<void> {
await this.page.evaluate((t) => {
const el = document.getElementById('demo-caption');
if (!el) return;
el.textContent = t;
el.classList.add('visible');
}, text);
await this.showCaption(text);
await this.page.waitForTimeout(ms);
await this.page.evaluate(() =>
document.getElementById('demo-caption')?.classList.remove('visible')
);
await this.page.waitForTimeout(250);
await this.hideCaption();
}
async click(target: Locator, ms = 400): Promise<void> {
@@ -182,6 +242,15 @@ export class Demo {
await this.pause(ms);
}
/**
* Gives the page a microphone that hears only what `speak` says, and allows the page to
* use it. Call it before the microphone is first used.
*/
async microphone(): Promise<void> {
await this.page.context().grantPermissions(['microphone']);
await this.page.evaluate(installFakeMicrophone);
}
/** Glides the cursor to a point near the center of `target`. */
async moveTo(target: Locator): Promise<void> {
await target.scrollIntoViewIfNeeded();
@@ -240,6 +309,23 @@ export class Demo {
await this.pause(ms);
}
/**
* Says `text` into the microphone from `microphone` in a synthetic voice (macOS `say`), and
* returns once it is said. The words show as a caption, since the video has no sound.
*/
async speak(text: string, voice = 'Samantha', ms = 400): Promise<void> {
const wav = synthesizeSpeech(text, voice);
await this.showCaption(`“${text}”`);
await this.page.evaluate(
(base64) =>
(window as unknown as { demoSpeak(wav: string): Promise<void> }).demoSpeak(base64),
wav
);
await this.hideCaption();
await this.pause(ms);
}
/** Types quickly with uneven key timing, a little slower after spaces and punctuation. */
async type(target: Locator, text: string, ms = 500): Promise<void> {
await this.click(target, 200);
@@ -305,6 +391,13 @@ export class Demo {
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
}
private async hideCaption(): Promise<void> {
await this.page.evaluate(() =>
document.getElementById('demo-caption')?.classList.remove('visible')
);
await this.page.waitForTimeout(250);
}
/** A pinch that reaches the screen's edge can end without its last touchend reaching the page. */
private async liftFingers(): Promise<void> {
await this.page.evaluate(() =>
@@ -340,6 +433,17 @@ export class Demo {
return this.cdp;
}
private async showCaption(text: string): Promise<void> {
await this.page.evaluate((t) => {
const el = document.getElementById('demo-caption');
if (!el) return;
el.textContent = t;
el.classList.add('visible');
}, text);
}
}
interface DemoOptions {
+40 -9
View File
@@ -34,9 +34,11 @@ const THEMES = [
];
// the type roles, by the @theme names Tailwind turns into text-body, text-label-sm, ...: a size with a line height
const TYPE_ROLE = /^--text-([a-z]+(?:-[a-z]+)*)$/;
// body and caption text takes the weight around it, which is regular unless a parent says otherwise
const DEFAULT_WEIGHT = '400';
// code takes the body-sm role in the mono stack (see `:where(code, pre, kbd, samp)` in theme.css)
const CODE_ROLE = 'body-sm';
// Tailwind's own `rounded-full`, for lamps, avatars and round buttons; the other corners are roles in semantic.css
// Tailwind's own `rounded-full`, for lamps, avatars and round buttons; the other corners are the scale in theme.css
const ROUNDED_FULL = '9999px';
// the sections this script owns, in the order they appear in the front matter; the next one is written by hand
const SECTIONS = ['colors', 'typography', 'rounded'];
@@ -104,6 +106,8 @@ const isColorLiteral = (value) =>
/^(oklch|oklab|rgb|hsl)\([^()]*\)$/.test(value);
/** @param {string} value */
const isColorMix = (value) => /^color-mix\(.*\)$/.test(value) && !/\)\s*,/.test(value);
/** a share a theme sets for a derivation, e.g. `--status-surface-share: 11%` @param {string} value */
const isShare = (value) => /^\d+(?:\.\d+)?%$/.test(value);
/** @param {string} value */
const varName = (value) => /^var\(--([\w-]+)\)$/.exec(value)?.[1];
@@ -136,7 +140,19 @@ function build() {
return next !== undefined && isColor(next, scope);
};
const semanticColors = [...semantic].filter(([, value]) => isColor(value, semantic));
/**
* A value with the shares it reads written out, as the theme whose declarations are `scope` sets them, so a
* derivation reads as the mix it is: `color-mix(in oklab, var(--fill-danger) 11%, var(--surface-page))`.
* @param {string} value
* @param {Map<string, string>} [scope]
*/
const withShares = (value, scope) =>
value.replace(/var\((--[\w-]+)\)/g, (reference, name) => {
const share = scope?.get(name) ?? semantic.get(name) ?? '';
return isShare(share) ? share : reference;
});
const semanticColors = [...semantic].filter(([, value]) => isColor(withShares(value), semantic));
const semanticNames = new Set(semanticColors.map(([name]) => name.slice(2)));
/**
* A token's value as the front matter writes it: a reference to another token, a literal, or a mix of them. A
@@ -166,7 +182,7 @@ function build() {
const base = new Map();
for (const [name, value] of semanticColors) {
const rendered = render(value, (n) => n);
const rendered = render(withShares(value), (n) => n);
base.set(name, rendered);
colors.push([name.slice(2), rendered]);
@@ -190,7 +206,9 @@ function build() {
if (semanticNames.has(ref)) resolve(`--${ref}`);
}
const result = render(value, (n) => (twins.has(n) ? `${n}${suffix}` : n));
const result = render(withShares(value, overrides), (n) =>
twins.has(n) ? `${n}${suffix}` : n
);
rendered.set(name, result);
@@ -217,6 +235,13 @@ function build() {
return (name && primitives.get(`--${name}`)) ?? value ?? '';
};
// a line height is written as the line over the size, `calc(1.25 / 0.875)`: the line, in rem
/** @param {string | undefined} value */
const lineHeight = (value) => {
const ratio = /^calc\(([\d.]+) \/ [\d.]+\)$/.exec(value ?? '');
return ratio ? `${ratio[1]}rem` : length(value);
};
/** @type {[string, Record<string, string>][]} */
const typography = [];
@@ -230,8 +255,8 @@ function build() {
{
fontFamily: sans,
fontSize: length(value),
fontWeight: length(inline.get(`${name}--font-weight`)),
lineHeight: length(inline.get(`${name}--line-height`))
fontWeight: inline.get(`${name}--font-weight`) ?? DEFAULT_WEIGHT,
lineHeight: lineHeight(inline.get(`${name}--line-height`))
}
]);
}
@@ -242,11 +267,17 @@ function build() {
/** @type {[string, string][]} */
const rounded = [];
// the corner scale is computed from --radius: `calc(var(--radius) + 4px)`, with 1rem as 16px
const baseRadius = parseFloat(theme.get(':root')?.get('--radius') ?? '') * 16;
for (const [name, value] of inline) {
const role = /^--radius-([a-z-]+)$/.exec(name)?.[1];
for (const [name, value] of theme.get('@theme inline') ?? []) {
const step = /^--radius-([a-z0-9]+)$/.exec(name)?.[1];
const offset = /^calc\(var\(--radius\) ([+-]) ([\d.]+)px\)$/.exec(value);
if (role) rounded.push([role, length(value)]);
if (!step) continue;
if (offset) rounded.push([step, `${baseRadius + Number(offset[1] + offset[2])}px`]);
else if (value === 'var(--radius)') rounded.push([step, `${baseRadius}px`]);
}
rounded.push(['full', ROUNDED_FULL]);
+1
View File
@@ -26,6 +26,7 @@ const LLAMA_UI_EXPORTS = [
['@ggml-org/llama-ui/enums', `${source}/enums/index.ts`],
['@ggml-org/llama-ui/code', `${source}/utils/index.ts`],
['@ggml-org/llama-ui/utils', `${source}/components/ui/utils.ts`],
['@ggml-org/llama-ui/voice', `${source}/components/voice/index.ts`],
['@ggml-org/llama-ui/styles/*', `${source}/styles/*`],
['@ggml-org/llama-ui/theme.css', `${source}/styles/theme.css`],
['@ggml-org/llama-ui/tokens.css', `${source}/styles/tokens.css`],
+28 -32
View File
@@ -30,7 +30,7 @@
/* phone sidebar width, which the page slides aside to reveal */
--sidebar-reveal: min(80dvw, 20rem);
/* the desktop sidebar's muted/60 over the page, made opaque so the slid page's corners can match it */
--sidebar-reveal-tint: color-mix(in oklab, var(--muted) 60%, var(--background));
--sidebar-reveal-tint: color-mix(in oklab, var(--surface-muted) 60%, var(--surface-page));
/* how far the phone sidebar is open, 0 to 1, stepped every frame by useSidebarReveal */
--sidebar-reveal-progress: 0;
/* the same on a log curve: the sidebar's contents hold on until the page nearly covers them */
@@ -39,7 +39,7 @@
--sidebar-reveal-bg: color-mix(
in oklab,
var(--sidebar-reveal-tint) calc(var(--sidebar-reveal-progress) * 100%),
var(--background)
var(--surface-page)
);
--layer-popover: 1000000;
@@ -63,7 +63,7 @@
/* the chat form's corners while its text and actions share one row */
--chat-form-single-row-radius: 1.25rem;
/* the card's translucent fill over the page, made opaque: the phone sheet, and the page and Safari's bars around it */
--chat-form-sheet-fill: color-mix(in oklab, var(--muted) 60%, var(--background));
--chat-form-sheet-fill: color-mix(in oklab, var(--surface-muted) 60%, var(--surface-page));
--max-message-height: max(24rem, min(80dvh, calc(100dvh - var(--chat-form-area-height) - 12rem)));
}
@@ -91,7 +91,7 @@
}
.dark {
--chat-form-sheet-fill: color-mix(in oklab, var(--muted) 75%, var(--background));
--chat-form-sheet-fill: color-mix(in oklab, var(--surface-muted) 75%, var(--surface-page));
}
@layer base {
@@ -202,9 +202,9 @@
.chat-top-fade {
background: linear-gradient(
to bottom,
color-mix(in srgb, var(--background) 100%, transparent) 25%,
color-mix(in srgb, var(--background) 80%, transparent) 50%,
color-mix(in srgb, var(--background) 40%, transparent) 75%,
color-mix(in srgb, var(--surface-page) 100%, transparent) 25%,
color-mix(in srgb, var(--surface-page) 80%, transparent) 50%,
color-mix(in srgb, var(--surface-page) 40%, transparent) 75%,
transparent 100%
);
}
@@ -219,8 +219,8 @@
height: var(--page-top);
background: linear-gradient(
to bottom,
var(--background) calc(var(--corner-control-top) + 1.25rem),
color-mix(in srgb, var(--background) 55%, transparent)
var(--surface-page) calc(var(--corner-control-top) + 1.25rem),
color-mix(in srgb, var(--surface-page) 55%, transparent)
calc(var(--corner-control-top) + 2.5rem),
transparent 100%
);
@@ -234,14 +234,14 @@
10px Safari ignores; what it covers sits under the fade's solid part anyway */
.status-bar-edge {
height: 0.75rem;
background-color: var(--background);
background-color: var(--surface-page);
}
/* The bottom edge's counterpart, which Safari takes for its bottom toolbar the same way:
without it, it finds the chat form there and takes the form's colour */
.screen-bottom-edge {
height: 0.75rem;
background-color: var(--background);
background-color: var(--surface-page);
}
/* The same fade at the bottom of a phone's screen: solid behind the home indicator and
@@ -251,8 +251,9 @@
height: calc(var(--safe-area-bottom) + 3rem);
background: linear-gradient(
to top,
var(--background) var(--safe-area-bottom),
color-mix(in srgb, var(--background) 60%, transparent) calc(var(--safe-area-bottom) + 1.5rem),
var(--surface-page) var(--safe-area-bottom),
color-mix(in srgb, var(--surface-page) 60%, transparent)
calc(var(--safe-area-bottom) + 1.5rem),
transparent 100%
);
}
@@ -261,7 +262,7 @@
panel's translucent muted tint, and a fade above it, like the one under
the tab bar, so the rows scrolling beneath end softly */
.sidebar-show-more {
--sidebar-surface: color-mix(in oklab, var(--muted) 60%, var(--background));
--sidebar-surface: color-mix(in oklab, var(--surface-muted) 60%, var(--surface-page));
background: var(--sidebar-surface);
&::before {
@@ -284,14 +285,14 @@
over the other sections while dragged */
.sidebar-drag-surface,
.sidebar-drag-overlay {
background: color-mix(in oklab, var(--muted) 60%, var(--background));
background: color-mix(in oklab, var(--surface-muted) 60%, var(--surface-page));
}
/* the copy of a chat row that follows the pointer, raised above the page */
.sidebar-drag-overlay {
box-shadow:
0 10px 30px -10px rgb(0 0 0 / 0.35),
0 0 0 1px color-mix(in srgb, var(--foreground) 12%, transparent);
0 0 0 1px color-mix(in srgb, var(--fg-default) 12%, transparent);
}
/* While something is dragged, what it passes over takes no hover: only the
@@ -329,12 +330,7 @@
}
.shimmer-text {
background: linear-gradient(
90deg,
var(--muted-foreground),
var(--foreground),
var(--muted-foreground)
);
background: linear-gradient(90deg, var(--fg-muted), var(--fg-default), var(--fg-muted));
background-size: 200% 100%;
background-clip: text;
-webkit-background-clip: text;
@@ -361,16 +357,16 @@
* so the svg also inherits them inside the preview dialog's shadow root, and follow the theme.
*/
:root {
--pele-bg: var(--code-background);
--pele-fg: var(--code-foreground);
--pele-muted: var(--muted-foreground);
--pele-line: var(--muted-foreground);
--pele-surface: var(--background);
--pele-surface-alt: var(--muted);
--pele-border: var(--border);
--pele-accent: var(--primary);
--pele-critical: var(--destructive);
--pele-error: var(--destructive);
--pele-bg: var(--surface-code);
--pele-fg: var(--fg-code);
--pele-muted: var(--fg-muted);
--pele-line: var(--fg-muted);
--pele-surface: var(--surface-page);
--pele-surface-alt: var(--surface-muted);
--pele-border: var(--line-default);
--pele-accent: var(--action-primary);
--pele-critical: var(--fg-danger);
--pele-error: var(--fg-danger);
--pele-radius: calc(var(--radius) - 4px);
}
@@ -18,7 +18,7 @@
{@const ModalityIcon = MODALITY_ICONS[modality]}
<span
class={[
'inline-flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-xs font-medium',
'inline-flex items-center gap-1 rounded-md bg-muted px-2 py-1 text-caption font-medium',
className
]}
>
@@ -1,9 +1,11 @@
<script lang="ts">
import { VoiceWaveformSize } from '@ggml-org/llama-ui/voice';
import {
ChatAttachmentsListItemMcpPrompt,
ChatAttachmentsListItemMcpResource,
ChatAttachmentsListItemThumbnailFile,
ChatAttachmentsListItemThumbnailImage
ChatAttachmentsListItemThumbnailImage,
ChatAttachmentsListItemVoice
} from '#lib/components/app/index.ts';
import { AttachmentType } from '#lib/enums/index.ts';
import type {
@@ -12,7 +14,7 @@
DatabaseMessageExtraMcpResource,
MCPResourceAttachment
} from '#lib/types/index.ts';
import { isMcpPrompt, isMcpResource, isPdfFile } from '#lib/utils/index.ts';
import { isAudioFile, isMcpPrompt, isMcpResource, isPdfFile } from '#lib/utils/index.ts';
interface Props {
class?: string;
@@ -77,7 +79,7 @@
: null}
{#if mcpPrompt}
<ChatAttachmentsListItemMcpPrompt
class="max-w-[300px] min-w-[200px] flex-shrink-0 {className} {scrollClasses}"
class="max-w-75 min-w-50 flex-shrink-0 {className} {scrollClasses}"
isLoading={item.isLoading}
loadError={item.loadError}
onRemove={onFileRemove ? () => onFileRemove(item.id) : undefined}
@@ -93,6 +95,15 @@
class="flex-shrink-0 {className} {scrollClasses}"
onclick={() => onMcpResourcePreview?.(mcpResource)}
/>
{:else if isAudioFile(item.attachment, item.uploadedFile)}
<!-- a clip plays where it is: the waveform takes the presses a chip would -->
<ChatAttachmentsListItemVoice
class="{layoutClasses} {className} {scrollClasses}"
{item}
onRemove={onFileRemove}
{readonly}
size={readonly ? VoiceWaveformSize.MD : VoiceWaveformSize.SM}
/>
{:else if item.isImage && item.preview}
<ChatAttachmentsListItemThumbnailImage
class="{layoutClasses} cursor-pointer {className} {scrollClasses}"
@@ -35,7 +35,7 @@
<Tooltip.Trigger>
<button
class={[
'flex flex-shrink-0 items-center gap-1.5 rounded-md border px-2 py-0.75 text-sm transition-colors',
'flex flex-shrink-0 items-center gap-1.5 rounded-md border px-2 py-0.75 text-body-sm transition-colors',
getStatusClass(attachment),
onclick && 'cursor-pointer hover:bg-muted/50',
className
@@ -52,7 +52,7 @@
<ResourceIcon class="size-icon-xs text-muted-foreground" />
{/if}
<span class="max-w-[150px] truncate text-xs">
<span class="max-w-37.5 truncate text-caption">
{getResourceDisplayName(attachment.resource)}
</span>
@@ -70,7 +70,7 @@
</Tooltip.Trigger>
<Tooltip.Content>
<div class="flex items-center gap-1 text-xs">
<div class="flex items-center gap-1 text-caption">
{#if favicon}
<img
alt={attachment.resource.serverName}
@@ -80,7 +80,7 @@
{#snippet textPreview(content: string)}
<div class="relative">
<div
class="font-mono text-xs leading-relaxed break-words whitespace-pre-wrap text-muted-foreground {!readonly
class="font-mono text-caption leading-relaxed break-words whitespace-pre-wrap text-muted-foreground {!readonly
? 'max-h-3rem line-height-1.2'
: ''}"
>
@@ -107,7 +107,7 @@
{#snippet fileIcon()}
<div
class="flex size-8 items-center justify-center rounded bg-primary/10 text-xs font-medium text-primary"
class="flex size-8 items-center justify-center rounded bg-primary/10 text-label-sm text-primary"
>
{#if isAudio}
<Music class="{ICON_CLASS_DEFAULT} text-white/70" />
@@ -121,7 +121,7 @@
{#snippet info(text: string | undefined)}
{#if text}
<span class="text-xs text-muted-foreground">{text}</span>
<span class="text-caption text-muted-foreground">{text}</span>
{/if}
{/snippet}
@@ -142,7 +142,7 @@
{#if readonly}
<div class="flex items-start gap-3">
<div class="flex min-w-0 flex-1 flex-col items-start text-left">
<span class="w-full truncate text-sm font-medium text-foreground">{name}</span>
<span class="w-full truncate text-label text-foreground">{name}</span>
{@render info(pdfProcessingMode || (size ? formatFileSize(size) : undefined))}
@@ -152,7 +152,7 @@
</div>
</div>
{:else}
<span class="mb-3 block truncate text-sm font-medium text-foreground">{name}</span>
<span class="mb-3 block truncate text-label text-foreground">{name}</span>
{#if textContent}
{@render textPreview(textContent)}
@@ -170,7 +170,7 @@
<div class="flex flex-col items-start gap-0.5">
<span
class="max-w-24 truncate text-sm font-medium text-foreground {readonly
class="max-w-24 truncate text-label text-foreground {readonly
? ''
: 'group-hover:pr-6'} md:max-w-32"
>
@@ -51,7 +51,7 @@
{#if label}
<span
class="pointer-events-none absolute bottom-1 left-1 rounded-md bg-black/40 px-1.5 py-0.5 text-[10px] font-medium text-white matte-chip backdrop-blur-md [--badge-highlight:rgb(255_255_255/0.18)]"
class="pointer-events-none absolute bottom-1 left-1 rounded-md bg-black/40 px-1.5 py-0.5 text-caption-sm font-medium text-white matte-chip backdrop-blur-md [--badge-highlight:rgb(255_255_255/0.18)]"
>
{label}
</span>
@@ -0,0 +1,126 @@
<!--
An audio attachment drawn as a clip: a playable waveform, and for a voice message its transcript under it, open while
it comes in and after, unless the Collapse transcripts setting folds it (then it opens on hover, keyboard focus or a
tap). `sm` is the chip in the chat form, `md` the clip in a sent message. A clip
stored without peaks (an older message, an uploaded file) gets them computed from its audio.
-->
<script lang="ts">
import {
spokenLength,
VoiceTranscriptReveal,
VoiceWaveform,
VoiceWaveformSize
} from '@ggml-org/llama-ui/voice';
import { X } from '@lucide/svelte';
import { ActionIcon } from '#lib/components/app/index.ts';
import { SETTINGS_KEYS, VOICE_MESSAGE_LABEL } from '#lib/constants/index.ts';
import { settingsStore, voiceTranscriptsStore } from '#lib/stores/index.ts';
import type { ChatAttachmentDisplayItem } from '#lib/types/index.ts';
import { audioUrl, lazyPeaks, voiceAttachmentSource } from '#lib/utils/voice-attachment.ts';
interface Props {
class?: string;
item: ChatAttachmentDisplayItem;
onRemove?: (id: string) => void;
readonly?: boolean;
size?: VoiceWaveformSize;
}
let {
class: className = '',
item,
onRemove,
readonly = false,
size = VoiceWaveformSize.MD
}: Props = $props();
let source = $derived(voiceAttachmentSource(item));
let computedPeaks = $state<number[] | null>(null);
let src = $state<string | undefined>();
let peaks = $derived(source.peaks ?? computedPeaks ?? []);
let shown = $derived(voiceTranscriptsStore.shown(source.name, source.transcript));
let transcript = $derived(shown.transcript);
let status = $derived(shown.status);
let errorReason = $derived(shown.errorReason);
let label = $derived(source.voice ? VOICE_MESSAGE_LABEL : source.name);
// the transcript lights up word by word as the clip plays, and stays lit
let playbackMs = $state<number | null>(null);
let spoken = $derived(
transcript && playbackMs !== null && source.durationMs
? spokenLength(transcript, peaks, source.durationMs, playbackMs)
: null
);
let collapsed = $derived(settingsStore.config[SETTINGS_KEYS.VOICE_COLLAPSE_TRANSCRIPTS] === true);
// an object URL lives as long as the clip is on screen
$effect(() => {
const audio = source.audio;
if (!audio) {
src = undefined;
return;
}
const playable = audioUrl(audio, source.mimeType);
src = playable?.url;
return () => {
if (playable?.revoke) URL.revokeObjectURL(playable.url);
};
});
$effect(() => {
const { audio, name, peaks: stored } = source;
computedPeaks = null;
if (stored || !audio) return;
let cancelled = false;
lazyPeaks(name, audio).then((value) => {
if (!cancelled) computedPeaks = value;
});
return () => {
cancelled = true;
};
});
</script>
<div
class={[
'group relative min-w-0',
size === VoiceWaveformSize.SM
? 'w-60 max-w-[calc(100vw-4rem)] rounded-lg border border-border bg-muted py-2 pr-9 pl-2'
: 'w-80 max-w-full rounded-2xl matte-sheen bg-(--user-bubble-background) px-3 py-2.5 backdrop-blur-md dark:bg-primary/15',
className
]}
data-slot="chat-attachment-voice"
data-voice={source.voice || undefined}
>
{#key collapsed}
<VoiceTranscriptReveal defaultOpen={!collapsed} {errorReason} {spoken} {status} {transcript}>
<VoiceWaveform bind:playbackMs durationMs={source.durationMs} {label} {peaks} {size} {src} />
</VoiceTranscriptReveal>
{/key}
{#if !source.voice}
<p class="mt-1 truncate px-1 text-caption text-muted-foreground">{source.name}</p>
{/if}
{#if !readonly && onRemove}
<div class="absolute top-1/2 right-1 -translate-y-1/2">
<ActionIcon
ariaLabel={source.voice ? 'Remove voice message' : `Remove ${source.name}`}
icon={X}
onclick={() => onRemove?.(item.id)}
stopPropagationOnClick
tooltip="Remove"
/>
</div>
{/if}
</div>
@@ -1,12 +1,23 @@
<script lang="ts">
import { VoiceTranscriptStatus } from '@ggml-org/llama-ui/voice';
import { Music } from '@lucide/svelte';
import { VOICE_MESSAGE_LABEL } from '#lib/constants/index.ts';
import { voiceTranscriptsStore } from '#lib/stores/index.ts';
import type { ChatAttachmentDisplayItem } from '#lib/types/index.ts';
import { voiceAttachmentSource } from '#lib/utils/voice-attachment.ts';
interface Props {
currentItem: { name?: string } | null;
currentItem: ChatAttachmentDisplayItem | null;
audioSrc: string | null;
}
let { audioSrc, currentItem }: Props = $props();
let source = $derived(currentItem ? voiceAttachmentSource(currentItem) : null);
// a voice message's transcript, from the message or still on its way
let shown = $derived(source ? voiceTranscriptsStore.shown(source.name, source.transcript) : null);
let transcript = $derived(shown?.transcript);
let transcribing = $derived(shown?.status === VoiceTranscriptStatus.TRANSCRIBING);
</script>
<div class="flex flex-1 items-center justify-center p-8">
@@ -21,6 +32,19 @@
<p class="mb-4 text-white/70">Audio preview not available</p>
{/if}
<p class="text-sm text-white/50">{currentItem?.name || 'Audio'}</p>
<p class="text-body-sm text-white/50">
{source?.voice ? VOICE_MESSAGE_LABEL : currentItem?.name || 'Audio'}
</p>
{#if transcript}
<p
class="mt-6 max-h-[40vh] overflow-y-auto text-left text-body-sm whitespace-pre-wrap text-white/80"
data-slot="voice-preview-transcript"
>
<span class="sr-only">Transcript: </span>{transcript}
</p>
{:else if transcribing}
<p class="mt-6 text-caption text-white/50">Transcribing...</p>
{/if}
</div>
</div>
@@ -206,7 +206,7 @@
{@render status('Failed to load PDF images', pdfImagesError)}
{:else if pdfImages.length > 0}
{#each pdfImages as image, index (index)}
<p class="mb-2 text-sm text-white/50">Page {index + 1}</p>
<p class="mb-2 text-body-sm text-white/50">Page {index + 1}</p>
<img
alt="PDF Page {index + 1}"
@@ -240,7 +240,7 @@
<p class={['text-white/70', detail && 'mb-4']}>{message}</p>
{#if detail}
<p class="text-sm text-white/50">{detail}</p>
<p class="text-body-sm text-white/50">{detail}</p>
{/if}
</div>
</div>
@@ -22,6 +22,6 @@
<p class="mb-4 text-white/70">Video preview not available</p>
{/if}
<p class="text-sm text-white/50">{currentItem?.name || 'Video'}</p>
<p class="text-body-sm text-white/50">{currentItem?.name || 'Video'}</p>
</div>
</div>
@@ -7,10 +7,10 @@
let { displayName, fileSize }: Props = $props();
</script>
<div class="sticky top-0 z-[20] mb-4 rounded-lg bg-black/5 px-4 py-2 text-center backdrop-blur-md">
<div class="sticky top-0 z-20 mb-4 rounded-lg bg-black/5 px-4 py-2 text-center backdrop-blur-md">
<p class="font-medium text-white">{displayName}</p>
{#if fileSize}
<p class="text-xs text-white/60">{fileSize}</p>
<p class="text-caption text-white/60">{fileSize}</p>
{/if}
</div>
@@ -61,7 +61,9 @@
<FileText class="{ICON_CLASS_DEFAULT} text-white/70" />
{/if}
<span class="font-mono text-[9px] text-white/60">{getFileExtension(item.name)}</span>
<span class="font-mono text-caption-sm text-white/60"
>{getFileExtension(item.name)}</span
>
</div>
{/if}
</button>
@@ -1,10 +1,13 @@
<script lang="ts">
import ContextGaugePopup from './ChatFormContextGauge/ContextGaugePopup.svelte';
import { microphoneUnavailableReason, warmUpVoiceCapture } from '@ggml-org/llama-voice';
import { VoiceRecorder } from '@ggml-org/llama-voice/svelte';
import { Maximize, Minimize } from '@lucide/svelte';
import {
ActionIcon,
ChatAttachmentsList,
ChatFormActions,
ChatFormActionsRecording,
ChatFormCurrentWorkingDirectory,
ChatFormInput,
ChatFormInputFileInputInvisible,
@@ -18,7 +21,8 @@
ICON_CLASS_DEFAULT,
INITIAL_FILE_SIZE,
PROMPT_CONTENT_SEPARATOR,
SETTING_CONFIG_DEFAULT
SETTING_CONFIG_DEFAULT,
VOICE_EDITOR_SELECTOR
} from '#lib/constants/index.ts';
import {
ContentPartType,
@@ -30,6 +34,10 @@
} from '#lib/enums/index.ts';
import { useChatFormExpansion } from '#lib/hooks/use-chat-form-expansion.svelte.ts';
import { useChatFormPickers } from '#lib/hooks/use-chat-form-pickers.svelte.ts';
import {
useChatFormVoice,
type VoiceRecorderLike
} from '#lib/hooks/use-chat-form-voice.svelte.ts';
import {
chatStore,
conversationsStore,
@@ -39,7 +47,8 @@
serverStore,
settingsStore,
toolsStore,
uiStore
uiStore,
voiceTranscriptsStore
} from '#lib/stores/index.ts';
import type {
FileMentionEntry,
@@ -48,14 +57,6 @@
MCPResourceInfo,
PromptMessage
} from '#lib/types/index.ts';
import {
AudioRecorder,
convertToWav,
createAudioFile,
describeMicrophoneError,
isAudioRecordingSupported,
microphoneUnavailableReason
} from '#lib/utils/browser-only.ts';
import {
buildMentionInsertion,
findCommandToken,
@@ -65,7 +66,7 @@
parseClipboardContent,
uuid
} from '#lib/utils/index.ts';
import { onMount, untrack } from 'svelte';
import { onMount, tick, untrack } from 'svelte';
import type { ClassValue } from 'svelte/elements';
import { toast } from 'svelte-sonner';
@@ -96,6 +97,9 @@
onUploadedFileRemove?: (fileId: string) => void;
onUploadedFilesChange?: (files: ChatUploadedFile[]) => void;
onValueChange?: (value: string) => void;
/** Records voice input; tests and stories pass a fake, the app a VoiceRecorder. */
voiceRecorder?: VoiceRecorderLike;
}
let {
@@ -117,21 +121,20 @@
showModelSelector = true,
singleRow = false,
uploadedFiles = $bindable([]),
value = $bindable('')
value = $bindable(''),
voiceRecorder
}: Props = $props();
// Component References
let audioRecorder: AudioRecorder | undefined;
let chatFormActionsRef: ChatFormActions | undefined = $state(undefined);
let fileInputRef: ChatFormInputFileInputInvisible | undefined = $state(undefined);
let pickersRef: { handleKeydown: (event: KeyboardEvent) => boolean } | undefined =
$state(undefined);
let inputRef: ChatFormInput | undefined = $state(undefined);
// Audio Recording State
let isRecording = $state(false);
let recordingSupported = $state(false);
// Voice input
const recorder: VoiceRecorderLike = untrack(() => voiceRecorder) ?? new VoiceRecorder();
/** Why this page can't record at all (no HTTPS, no recorder), which no tap fixes. */
let micUnavailableReason = $state<string | null>(null);
/** Why the last start failed (denied, no microphone, busy); the next tap tries again. */
@@ -189,6 +192,25 @@
}
});
const voice = useChatFormVoice({
addVoiceFile: (file) => {
uploadedFiles = [...uploadedFiles, file];
onUploadedFilesChange?.(uploadedFiles);
},
getCaretOffset: () => inputRef?.getCaretOffset() ?? value.length,
getValue: () => value,
onMicError: (message) => (micError = message),
recorder,
// on a phone placing the caret would open the keyboard
setCaretOffset: (offset) => {
if (!deviceStore.isMobile) inputRef?.setCaretOffset(offset);
},
setValue: (next) => {
value = next;
onValueChange?.(next);
}
});
async function handleWorkingDirectoryChange(newDir: string | null) {
// Committing a directory consumes the `/cwd` token; the chip's
// clear-X path has no token to consume.
@@ -234,6 +256,14 @@
(attachments && attachments.length > 0) || (uploadedFiles && uploadedFiles.length > 0)
);
let canSubmit = $derived(value.trim().length > 0 || hasAttachments);
// while a voice message records, what is being said shows in the empty message box; once
// it stops, the text goes with the clip, as its transcript
let voicePlaceholder = $derived(
voice.isActive && voice.liveCaption && !value.trim() ? voice.liveCaption : null
);
// while a reply streams, sending what is recorded waits for its first words in the form
let hasVoiceText = $derived(!!value.trim() || !!voice.liveCaption);
const EXPANDED_SHEET_FILL = 'max-md:bg-(--chat-form-sheet-fill)';
@@ -263,6 +293,7 @@
singleRow &&
!deviceStore.isMobile &&
!isExpanded &&
!voice.isActive &&
!hasAttachments &&
!mcpStore.resources.hasAttachments &&
!value.includes('\n')
@@ -327,9 +358,7 @@
);
onMount(() => {
recordingSupported = isAudioRecordingSupported();
micUnavailableReason = microphoneUnavailableReason();
audioRecorder = new AudioRecorder();
});
/** Expands for the message as it stands, e.g. one put back after a send failed. */
@@ -375,6 +404,10 @@
onAttachmentRemove?.(index);
}
} else {
const removed = uploadedFiles.find((file) => file.id === fileId);
if (removed?.voice) voiceTranscriptsStore.forget(removed.name);
onUploadedFileRemove?.(fileId);
}
}
@@ -399,9 +432,7 @@
event.preventDefault();
if (!canSubmit || disabled || hasLoadingAttachments) return;
onSubmit?.();
void submit();
}
}
@@ -586,7 +617,7 @@
inputRef?.replaceText(built.newValue, built.caretOffset);
}
async function handleMicClick() {
function handleMicClick() {
// a phone shows no tooltip on a tap, so the reason comes as a toast
if (micUnavailableReason) {
toast.error(micUnavailableReason);
@@ -594,36 +625,61 @@
return;
}
if (!audioRecorder || !recordingSupported) {
console.warn('Audio recording not supported');
void voice.start();
}
return;
}
// the audio set-up takes a moment, so it is made while the message is being written;
// it asks for no microphone, so the browser shows no recording indicator
function handleFocusIn(event: FocusEvent) {
if (voice.showButton && !voice.isActive) warmUpVoiceCapture();
if (isRecording) {
isRecording = false;
try {
const audioBlob = await audioRecorder.stopRecording();
const wavBlob = await convertToWav(audioBlob);
const audioFile = createAudioFile(wavBlob);
onFilesAdd?.([audioFile]);
} catch (error) {
console.error('Failed to stop recording:', error);
}
} else {
try {
await audioRecorder.startRecording();
isRecording = true;
micError = null;
} catch (error) {
micError = describeMicrophoneError(error);
toast.error(micError);
}
// the voice message's live text shown as the placeholder turns into text to edit
if (voicePlaceholder && (event.target as Element | null)?.closest(VOICE_EDITOR_SELECTOR)) {
voice.adoptLiveText();
}
}
// a send asked for while the dictated text is still being refined waits for it
let isSendWaiting = $state(false);
/** Sends the message; dictated text that is still being refined is sent refined. */
async function submit() {
if (!canSubmit || disabled || hasLoadingAttachments || isSendWaiting) return;
if (voice.isRefining) {
isSendWaiting = true;
try {
await voice.settled();
await tick();
} finally {
isSendWaiting = false;
}
if (!canSubmit || disabled || hasLoadingAttachments) return;
}
onSubmit?.();
}
/** Stops the recording and sends the message once its text or clip is in the form. */
async function handleStopAndSend() {
await voice.stop();
await tick();
await submit();
}
// Escape drops a recording, wherever the focus is
function handleWindowKeydown(event: KeyboardEvent) {
if (event.key !== KeyboardKey.ESCAPE || !voice.isActive || event.defaultPrevented) return;
event.preventDefault();
voice.cancel();
}
</script>
<svelte:window onkeydown={handleWindowKeydown} />
<ChatFormInputFileInputInvisible bind:this={fileInputRef} onFileSelect={handleFileSelect} />
<form
@@ -636,12 +692,10 @@
'max-h-[calc(100dvh-var(--chat-tabs-offset,0px)-var(--chat-form-padding-top)-2rem)] max-md:max-h-dvh',
className
]}
onfocusin={handleFocusIn}
onsubmit={(event) => {
event.preventDefault();
if (!canSubmit || disabled || hasLoadingAttachments) return;
onSubmit?.();
void submit();
}}
>
<!-- the pickers' own triggers fill this box, so all of them share the anchor -->
@@ -678,9 +732,7 @@
bind:this={cardEl}
class={[
'chat-form-surface group/chat-form relative flex shrink flex-col overflow-hidden outline-none transition-[min-height,padding,border-radius,border-color,background-color] duration-400 ease-[var(--chat-form-resize-ease,cubic-bezier(0.3,1.12,0.5,1))] motion-reduce:transition-none',
isSingleRow
? 'rounded-(--chat-form-single-row-radius)'
: 'rounded-(--chat-form-radius-compact) md:rounded-(--chat-form-radius)',
isSingleRow ? 'rounded-(--chat-form-single-row-radius)' : 'rounded-4xl md:rounded-3xl',
// on a phone the sheet's animation moves it (see useChatFormExpansion): only its
// border, hidden on the sheet, fades back in after
'max-md:transition-[border-color] max-md:duration-200',
@@ -702,7 +754,7 @@
'max-md:pt-safe',
// no rim, ring or visible border along the screen's edges; the border stays
// transparent so nothing inside shifts by its width
'max-md:[--glass-edge-side:transparent] max-md:[--glass-edge-mid:transparent] max-md:[--glass-edge-side-focus:transparent] max-md:[--glass-edge-mid-focus:transparent] max-md:[--glass-highlight:transparent]',
'max-md:[--glass-edge:transparent] max-md:[--glass-edge-focus:transparent] max-md:[--glass-highlight:transparent]',
'max-md:border-transparent max-md:focus-within:border-transparent max-md:dark:border-transparent max-md:dark:focus-within:border-transparent',
EXPANDED_SHEET_FILL
],
@@ -734,7 +786,7 @@
<div
class={[
'relative flex flex-1 shadow-sm transition-shadow focus-within:shadow-md',
'relative flex flex-1 shadow-(--elevation-control) transition-shadow focus-within:shadow-(--elevation-surface)',
// the add button, the text and the rest of the actions, or the text above them
isSingleRow
? 'items-center gap-2 rounded-(--chat-form-single-row-radius) px-3 py-2.5'
@@ -755,13 +807,14 @@
{disabled}
expanded={isExpanded}
onInput={() => {
voice.handleUserInput();
expansion.handleInput();
pickers.handleInput();
onValueChange?.(value);
}}
onKeydown={handleKeydown}
onPaste={handlePaste}
{placeholder}
placeholder={voicePlaceholder ?? placeholder}
/>
{#if mcpStore.resources.hasAttachments}
@@ -776,29 +829,55 @@
<!-- its own box, so the phone sheet can hold it by the bottom edge while it moves -->
<div bind:this={actionsEl} class={isSingleRow ? 'contents' : 'relative mt-auto'}>
<ChatFormActions
bind:this={chatFormActionsRef}
canSend={canSubmit}
class={isSingleRow ? undefined : 'px-3'}
{disabled}
inline={isSingleRow}
{isLoading}
isReasoning={chatStore.isReasoning}
{isRecording}
micWarning={micUnavailableReason ?? micError}
onFileUpload={handleFileUpload}
onMicClick={handleMicClick}
{onStop}
onSystemPromptClick={() =>
onSystemPromptClick?.({ files: uploadedFiles, message: value })}
onWorkingDirectoryClick={isWorkingDirectoryInAddMenu
? pickers.handleWorkingDirectoryOpen
: undefined}
{showAddButton}
{showModelSelector}
{uploadedFiles}
workingDirectory={cwd}
/>
{#if voice.isActive}
<ChatFormActionsRecording
class="px-3"
elapsedMs={voice.elapsedMs}
levels={voice.levels}
liveCaption={voicePlaceholder ? '' : voice.liveCaption}
mode={voice.mode}
onCancel={voice.cancel}
onSend={isLoading && !hasVoiceText ? undefined : () => void handleStopAndSend()}
onStop={() => void voice.stop()}
quiet={voice.quiet}
state={voice.state}
/>
{/if}
<!-- kept while recording, so its selector and menus keep their state -->
<div class={voice.isActive ? 'hidden' : 'contents'}>
<ChatFormActions
bind:this={chatFormActionsRef}
canSend={canSubmit}
class={isSingleRow ? undefined : 'px-3'}
{disabled}
inline={isSingleRow}
{isLoading}
isReasoning={chatStore.isReasoning}
{isSendWaiting}
isVoiceRefining={voice.isRefining}
micWarning={micUnavailableReason ?? micError}
onFileUpload={handleFileUpload}
onMicClick={handleMicClick}
{onStop}
onSystemPromptClick={() =>
onSystemPromptClick?.({ files: uploadedFiles, message: value })}
onWorkingDirectoryClick={isWorkingDirectoryInAddMenu
? pickers.handleWorkingDirectoryOpen
: undefined}
{showAddButton}
{showModelSelector}
voice={{
action: voice.label,
hint: voice.hint,
prepare: () => void voice.prepare(),
show: voice.showButton,
unavailableReason: voice.unavailableReason,
unprepare: voice.unprepare
}}
workingDirectory={cwd}
/>
</div>
</div>
</div>
</div>
@@ -15,7 +15,7 @@
<Tooltip.Root>
<Tooltip.Trigger class="w-full">
<Button
class="file-upload-button bg-background size-9 rounded-full p-0 shadow-(--chat-form-key-shadow) md:size-8 dark:bg-muted-foreground/15"
class="file-upload-button bg-background size-9 rounded-full p-0 shadow-(--elevation-key) md:size-8 dark:bg-muted-foreground/15"
{disabled}
{onclick}
type="button"
@@ -8,24 +8,23 @@
ChevronRight,
File,
Folder,
Image,
MessageSquare,
Mic,
PencilRuler,
Video
PencilRuler
} from '@lucide/svelte';
import {
ATTACHMENT_FILE_ITEMS,
ATTACHMENT_MENU_TEXT,
ATTACHMENT_MODALITY_TEXT,
ICON_CLASS_DEFAULT
ICON_CLASS_DEFAULT,
MODALITY_ICONS
} from '#lib/constants/index.ts';
import { getChatFormActionsContext } from '#lib/contexts/index.ts';
import { AttachmentAction, AttachmentItemEnabledWhen } from '#lib/enums/attachment.enums.ts';
import { ModelModality } from '#lib/enums/index.ts';
import { useAttachmentMenu } from '#lib/hooks/use-attachment-menu.svelte.ts';
import { useToolsPanel } from '#lib/hooks/use-tools-panel.svelte.ts';
import type { ToolGroup } from '#lib/types/index.ts';
import type { Snippet } from 'svelte';
import type { Component, Snippet } from 'svelte';
interface Props {
class?: string;
@@ -54,17 +53,17 @@
}
);
const FILE_MODALITY_ICONS: Record<string, { icon: typeof Image; label: string }> = {
const FILE_MODALITY_ICONS: Record<string, { icon: Component; label: string }> = {
[AttachmentItemEnabledWhen.HAS_AUDIO_MODALITY]: {
icon: Mic,
icon: MODALITY_ICONS[ModelModality.AUDIO],
label: ATTACHMENT_MODALITY_TEXT[AttachmentItemEnabledWhen.HAS_AUDIO_MODALITY]
},
[AttachmentItemEnabledWhen.HAS_VIDEO_MODALITY]: {
icon: Video,
icon: MODALITY_ICONS[ModelModality.VIDEO],
label: ATTACHMENT_MODALITY_TEXT[AttachmentItemEnabledWhen.HAS_VIDEO_MODALITY]
},
[AttachmentItemEnabledWhen.HAS_VISION_MODALITY]: {
icon: Image,
icon: MODALITY_ICONS[ModelModality.VISION],
label: ATTACHMENT_MODALITY_TEXT[AttachmentItemEnabledWhen.HAS_VISION_MODALITY]
}
};
@@ -78,10 +77,10 @@
const toolsPanel = useToolsPanel();
const itemClass =
'flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-sm transition-colors hover:bg-accent active:bg-accent disabled:cursor-not-allowed disabled:opacity-50';
'flex w-full items-center gap-3 rounded-md px-3 py-2.5 text-left text-body-sm transition-colors hover:bg-accent active:bg-accent disabled:cursor-not-allowed disabled:opacity-50';
const itemRowClass =
'flex w-full items-center justify-between gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-accent';
'flex w-full items-center justify-between gap-2 rounded-md px-3 py-2 text-left text-body-sm transition-colors hover:bg-accent';
</script>
<div class="flex items-center gap-1 {className}">
@@ -205,9 +204,9 @@
/>
{/if}
<span class="min-w-0 flex-1 truncate text-sm font-medium">{group.label}</span>
<span class="min-w-0 flex-1 truncate text-label">{group.label}</span>
<span class="shrink-0 text-xs text-muted-foreground">
<span class="shrink-0 text-caption text-muted-foreground">
{enabledCount}/{group.tools.length}
</span>
@@ -3,18 +3,20 @@
import * as DropdownMenu from '@ggml-org/llama-ui/ui/dropdown-menu';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { cn } from '@ggml-org/llama-ui/utils';
import { File, Folder, Image, MessageSquare, Mic, Plus, Video } from '@lucide/svelte';
import { File, Folder, MessageSquare, Plus } from '@lucide/svelte';
import { ChatFormActionAddToolsSubmenu } from '#lib/components/app/index.ts';
import {
ATTACHMENT_FILE_ITEMS,
ATTACHMENT_MENU_TEXT,
ATTACHMENT_MODALITY_TEXT,
ATTACHMENT_TOOLTIP_TEXT,
ICON_CLASS_DEFAULT
ICON_CLASS_DEFAULT,
MODALITY_ICONS
} from '#lib/constants/index.ts';
import { getChatFormActionsContext } from '#lib/contexts/index.ts';
import { AttachmentAction, AttachmentItemEnabledWhen } from '#lib/enums/index.ts';
import { AttachmentAction, AttachmentItemEnabledWhen, ModelModality } from '#lib/enums/index.ts';
import { useAttachmentMenu } from '#lib/hooks/use-attachment-menu.svelte.ts';
import type { Component } from 'svelte';
interface Props {
class?: string;
@@ -44,17 +46,17 @@
}
);
const FILE_MODALITY_ICONS: Record<string, { icon: typeof Image; label: string }> = {
const FILE_MODALITY_ICONS: Record<string, { icon: Component; label: string }> = {
[AttachmentItemEnabledWhen.HAS_AUDIO_MODALITY]: {
icon: Mic,
icon: MODALITY_ICONS[ModelModality.AUDIO],
label: ATTACHMENT_MODALITY_TEXT[AttachmentItemEnabledWhen.HAS_AUDIO_MODALITY]
},
[AttachmentItemEnabledWhen.HAS_VIDEO_MODALITY]: {
icon: Video,
icon: MODALITY_ICONS[ModelModality.VIDEO],
label: ATTACHMENT_MODALITY_TEXT[AttachmentItemEnabledWhen.HAS_VIDEO_MODALITY]
},
[AttachmentItemEnabledWhen.HAS_VISION_MODALITY]: {
icon: Image,
icon: MODALITY_ICONS[ModelModality.VISION],
label: ATTACHMENT_MODALITY_TEXT[AttachmentItemEnabledWhen.HAS_VISION_MODALITY]
}
};
@@ -78,7 +80,7 @@
class={cn(
// ghost brings no fill of its own for the muted composer surface to fight over
buttonVariants({ variant: 'ghost' }),
'file-upload-button matte-key size-8 [--button-shadow:var(--chat-form-key-shadow)] cursor-pointer rounded-full bg-background p-0 dark:bg-muted-foreground/15'
'file-upload-button matte-key size-8 [--button-shadow:var(--elevation-key)] cursor-pointer rounded-full bg-background p-0 dark:bg-muted-foreground/15'
)}
disabled={chatFormActions.disabled}
>
@@ -23,13 +23,13 @@
<DropdownMenu.SubContent class="w-72 p-0">
{#if toolsPanel.totalToolCount === 0}
{#if toolsStore.loading}
<div class="px-3 py-4 text-center text-sm text-muted-foreground">
<div class="px-3 py-4 text-center text-body-sm text-muted-foreground">
<Loader2 class="mx-auto mb-1 {ICON_CLASS_DEFAULT} animate-spin" />
Loading tools...
</div>
{:else if toolsStore.isToolsEndpointUnreachable}
<div class="grid gap-2.5 px-3 py-4 text-sm text-muted-foreground">
<div class="grid gap-2.5 px-3 py-4 text-body-sm text-muted-foreground">
<span class="flex gap-2">
<Info class="mt-0.5 {ICON_CLASS_DEFAULT} shrink-0" />
@@ -54,15 +54,19 @@
{/if}
</div>
{:else if toolsStore.error}
<div class="px-3 py-4 text-center text-sm text-muted-foreground">Failed to load tools</div>
<div class="px-3 py-4 text-center text-body-sm text-muted-foreground">
Failed to load tools
</div>
{:else if toolsPanel.noToolsInfoMessage}
<div class="flex gap-2 px-3 py-4 text-sm text-muted-foreground">
<div class="flex gap-2 px-3 py-4 text-body-sm text-muted-foreground">
<Info class="mt-0.5 {ICON_CLASS_DEFAULT} shrink-0" />
<span>{toolsPanel.noToolsInfoMessage}</span>
</div>
{:else}
<div class="px-3 py-4 text-center text-sm text-muted-foreground">No tools available</div>
<div class="px-3 py-4 text-center text-body-sm text-muted-foreground">
No tools available
</div>
{/if}
{:else}
<div class="max-h-80 overflow-y-auto p-2 pr-1">
@@ -90,7 +94,7 @@
>
<div class="flex items-center gap-1 {groupDisabled ? 'pointer-events-none opacity-50' : ''}">
<Collapsible.Trigger
class="flex min-w-0 flex-1 items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-muted/50"
class="flex min-w-0 flex-1 items-center gap-2 rounded px-2 py-1.5 text-body-sm hover:bg-muted/50"
>
{#if isExpanded}
<ChevronDown class="size-icon-sm shrink-0" />
@@ -113,7 +117,7 @@
<span class="truncate">{group.label}</span>
</span>
<span class="ml-auto shrink-0 text-xs text-muted-foreground">
<span class="ml-auto shrink-0 text-caption text-muted-foreground">
{toolsPanel.getEnabledToolCount(group)}/{group.tools.length}
</span>
</Collapsible.Trigger>
@@ -146,7 +150,7 @@
{@const enabled = toolsPanel.isToolEnabled(entry)}
{@const parentDisabled = toolsPanel.isToolParentDisabled(entry)}
<button
class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm transition-colors hover:bg-muted/50 {parentDisabled
class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-body-sm transition-colors hover:bg-muted/50 {parentDisabled
? 'opacity-50'
: ''}"
onclick={() => toolsPanel.toggleTool(entry)}
@@ -162,7 +166,7 @@
{/if}
</span>
<span class="min-w-0 flex-1 truncate font-mono text-[12px]">
<span class="min-w-0 flex-1 truncate font-mono text-caption">
{entry.definition.function.name}
</span>
</button>
@@ -46,7 +46,7 @@
<button
aria-pressed={reasoning.isSelected(level)}
class="flex min-h-11 w-full cursor-pointer items-center gap-3 rounded-md px-3 text-left text-sm transition-colors hover:bg-accent"
class="flex min-h-11 w-full cursor-pointer items-center gap-3 rounded-md px-3 text-left text-body-sm transition-colors hover:bg-accent"
onclick={() => select(level)}
type="button"
>
@@ -59,7 +59,7 @@
<span class="min-w-0 flex-1 truncate">{level.label}</span>
{#if tokenLabel}
<span class="shrink-0 text-[11px] text-muted-foreground opacity-60">{tokenLabel}</span>
<span class="shrink-0 text-caption text-muted-foreground opacity-60">{tokenLabel}</span>
{/if}
{#if level.hasInfo}
@@ -75,7 +75,7 @@
aria-label="Reasoning effort"
class="h-auto gap-1 rounded-sm bg-transparent! backdrop-blur-none! {isDefault
? 'px-1'
: 'px-1.75!'} py-1 text-xs max-md:h-8"
: 'px-1.75!'} py-1 text-caption max-md:h-8"
onclick={() => (isOpen = true)}
variant="ghost"
>
@@ -104,7 +104,7 @@
aria-label="Reasoning effort"
class="-mr-px h-6 min-w-6 gap-1 rounded-sm bg-transparent backdrop-blur-none! {isDefault
? 'px-1'
: 'px-1.75!'} py-0 text-xs hover:bg-muted-foreground/15 data-[state=open]:bg-muted-foreground/15"
: 'px-1.75!'} py-0 text-caption hover:bg-muted-foreground/15 data-[state=open]:bg-muted-foreground/15"
variant="ghost"
>
{@render triggerLabel()}
@@ -126,7 +126,7 @@
<span class="min-w-0 flex-1 truncate">{level.label}</span>
{#if tokenLabel}
<span class="shrink-0 text-[11px] text-muted-foreground opacity-60">{tokenLabel}</span>
<span class="shrink-0 text-caption text-muted-foreground opacity-60">{tokenLabel}</span>
{/if}
{#if level.hasInfo}
@@ -2,34 +2,95 @@
import { Button } from '@ggml-org/llama-ui/ui/button';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { Mic, MicOff, Square } from '@lucide/svelte';
import { ICON_CLASS_DEFAULT } from '#lib/constants/index.ts';
import {
ICON_CLASS_DEFAULT,
VOICE_MODE_MESSAGE,
VOICE_PRESS_CLICK_MS
} from '#lib/constants/index.ts';
import { MouseButton, PointerType } from '#lib/enums/index.ts';
interface Props {
/** What a press does: send a voice message or dictate. */
action?: string;
class?: string;
disabled?: boolean;
hasAudioModality?: boolean;
/** Said after the action in the tooltip, e.g. that another model may be loaded. */
hint?: string | null;
isLoading?: boolean;
isRecording?: boolean;
/** Why the microphone can't record (no HTTPS, access denied...), shown on the button. */
micWarning?: string | null;
/** Why no model can take the recording; disables the button. */
unavailableReason?: string | null;
/** A quieter (tertiary) button, beside the main one: send or stop. */
secondary?: boolean;
/** With `secondary`: filled like the stop button it stands beside, not bare. */
filled?: boolean;
onMicClick?: () => void;
/** A mouse or the focus came to the button: a press may follow, the microphone can open. */
onPrepare?: () => void;
/** It left again without a press. */
onPrepareEnd?: () => void;
}
let {
action = VOICE_MODE_MESSAGE.voiceMessage,
class: className = '',
disabled = false,
hasAudioModality = false,
filled = false,
hint = null,
isLoading = false,
isRecording = false,
micWarning = null,
onMicClick
onMicClick,
onPrepare,
onPrepareEnd,
secondary = false,
unavailableReason = null
}: Props = $props();
// a model without audio input disables the button; a microphone that can't record keeps it
// no model to take the recording disables the button; a microphone that can't record keeps it
// tappable, so a tap can say why
const showWarning = $derived(hasAudioModality && !isRecording && !!micWarning);
const showWarning = $derived(!unavailableReason && !isRecording && !!micWarning);
// a mouse starts recording on press, not on release, so the first words are not lost;
// a touch or a key goes through the click, which is when the browser allows it
let pressedAt = -Infinity;
function handlePointerDown(event: PointerEvent) {
if (isRecording || disabled || isLoading || unavailableReason) return;
if (event.pointerType !== PointerType.MOUSE || event.button !== MouseButton.PRIMARY) return;
pressedAt = performance.now();
onMicClick?.();
}
// a touch presses at once, so only a mouse, a pen or the keyboard come ahead of the press
function handlePointerEnter(event: PointerEvent) {
if (event.pointerType !== PointerType.TOUCH && !isRecording) onPrepare?.();
}
function handlePointerLeave(event: PointerEvent) {
if (event.pointerType !== PointerType.TOUCH) onPrepareEnd?.();
}
function handleClick() {
// the click that ends the press that already started it; the recording bar may have
// taken the button's place meanwhile, so this one can also never come
if (performance.now() - pressedAt < VOICE_PRESS_CLICK_MS) {
pressedAt = -Infinity;
return;
}
onMicClick?.();
}
const tooltip = $derived(
!hasAudioModality ? 'Current model does not support audio' : showWarning ? micWarning : null
isRecording
? null
: (unavailableReason ??
(showWarning ? micWarning : [action, hint].filter(Boolean).join('. ')))
);
</script>
@@ -37,28 +98,41 @@
<Tooltip.Root>
<Tooltip.Trigger>
<Button
class="size-8 max-md:size-9 rounded-full p-0 {isRecording
? 'matte-orb orb-danger animate-pulse text-white! hover:bg-transparent'
class="group size-8 max-md:size-9 rounded-full p-0 {isRecording
? 'matte-orb orb-danger text-white! hover:bg-transparent'
: showWarning
? 'bg-surface-warning text-fg-warning hover:bg-surface-warning'
: ''}"
disabled={disabled || isLoading || !hasAudioModality}
onclick={onMicClick}
disabled={disabled || isLoading || !!unavailableReason}
onblur={() => onPrepareEnd?.()}
onclick={handleClick}
onfocus={() => !isRecording && onPrepare?.()}
onpointerdown={handlePointerDown}
onpointerenter={handlePointerEnter}
onpointerleave={handlePointerLeave}
type="button"
variant={isRecording || showWarning ? 'ghost' : 'default'}
variant={isRecording || showWarning
? 'ghost'
: secondary
? filled
? 'secondary'
: 'tertiary'
: 'default'}
>
<span class="sr-only"
>{isRecording
? 'Stop recording'
: showWarning
? `Recording unavailable: ${micWarning}`
: 'Start recording'}</span
: action}</span
>
{#if isRecording}
<Square class="{ICON_CLASS_DEFAULT} animate-pulse fill-white" />
<Square class="{ICON_CLASS_DEFAULT} fill-white" />
{:else if showWarning}
<MicOff class={ICON_CLASS_DEFAULT} />
{:else if secondary}
<Mic class="{ICON_CLASS_DEFAULT} stroke-muted-foreground group-hover:stroke-foreground" />
{:else}
<Mic class={ICON_CLASS_DEFAULT} />
{/if}
@@ -1,16 +1,24 @@
<script lang="ts">
import { Button } from '@ggml-org/llama-ui/ui/button';
import * as Tooltip from '@ggml-org/llama-ui/ui/tooltip';
import { ArrowUp } from '@lucide/svelte';
import { ArrowUp, LoaderCircle } from '@lucide/svelte';
interface Props {
canSend?: boolean;
disabled?: boolean;
/** The send is on its way: it waits for something, e.g. dictated text being refined. */
loading?: boolean;
showErrorState?: boolean;
tooltipLabel?: string;
}
let { canSend = false, disabled = false, showErrorState = false, tooltipLabel }: Props = $props();
let {
canSend = false,
disabled = false,
loading = false,
showErrorState = false,
tooltipLabel
}: Props = $props();
let isDisabled = $derived(!canSend || disabled);
</script>
@@ -28,7 +36,11 @@
>
<span class="sr-only">Send</span>
<ArrowUp class="size-icon-md" />
{#if loading}
<LoaderCircle class="size-icon-md animate-spin" />
{:else}
<ArrowUp class="size-icon-md" />
{/if}
</Button>
{/snippet}
@@ -1,22 +1,24 @@
<script lang="ts">
import { Button } from '@ggml-org/llama-ui/ui/button';
import { SkipForward, Square } from '@lucide/svelte';
import { LoaderCircle, SkipForward, Square } from '@lucide/svelte';
import {
ChatFormActionReasoning,
ChatFormActionRecord,
ChatFormActionsAdd,
ChatFormActionSubmit,
ChatFormContextGauge,
ModelsSelector
} from '#lib/components/app/index.ts';
import { ICON_CLASS_DEFAULT, SET_WORKING_DIRECTORY_LABEL } from '#lib/constants/index.ts';
import {
ICON_CLASS_DEFAULT,
SET_WORKING_DIRECTORY_LABEL,
VOICE_MODE_MESSAGE
} from '#lib/constants/index.ts';
import { setChatFormActionsContext } from '#lib/contexts/index.ts';
import { FileTypeCategory } from '#lib/enums/index.ts';
import { useChatFormModel } from '#lib/hooks/use-chat-form-model.svelte.ts';
import { useShowContextGauge } from '#lib/hooks/use-context-gauge.svelte.ts';
import { ChatService } from '#lib/services/index.ts';
import { conversationsStore, deviceStore, settingsStore, toolsStore } from '#lib/stores/index.ts';
import { abbreviateWorkingDir, getFileTypeCategory } from '#lib/utils/index.ts';
import { abbreviateWorkingDir } from '#lib/utils/index.ts';
interface Props {
canSend?: boolean;
@@ -26,12 +28,25 @@
inline?: boolean;
isLoading?: boolean;
isReasoning?: boolean;
isRecording?: boolean;
/** A send was asked for and waits for the dictated text to be refined. */
isSendWaiting?: boolean;
/** The dictated text in the message is still being refined. */
isVoiceRefining?: boolean;
/** Why the microphone can't record, shown on its button. */
micWarning?: string | null;
/** Voice input: whether the microphone shows, what it does, and why it can't. */
voice?: {
action: string;
hint: string | null;
show: boolean;
unavailableReason: string | null;
/** The pointer or the focus came to the microphone button, a press may follow */
prepare?: () => void;
/** It left without a press */
unprepare?: () => void;
};
showAddButton?: boolean;
showModelSelector?: boolean;
uploadedFiles?: ChatUploadedFile[];
/** The chat's working directory, which the + menu names. */
workingDirectory?: string | null;
onFileUpload?: () => void;
@@ -48,7 +63,8 @@
inline = false,
isLoading = false,
isReasoning = false,
isRecording = false,
isSendWaiting = false,
isVoiceRefining = false,
micWarning = null,
onFileUpload,
onMicClick,
@@ -57,7 +73,7 @@
onWorkingDirectoryClick,
showAddButton = true,
showModelSelector = true,
uploadedFiles = [],
voice,
workingDirectory = null
}: Props = $props();
@@ -78,12 +94,17 @@
return '';
});
let hasAudioAttachments = $derived(
uploadedFiles.some((file) => getFileTypeCategory(file.type) === FileTypeCategory.AUDIO)
);
let shouldShowRecordButton = $derived(
hasAudioModality && !canSend && !hasAudioAttachments && currentConfig.autoMicOnEmpty
);
// the microphone sits beside the send or stop button: on an empty message when the setting
// asks for it (disabled, saying why, when no model can take a recording), and while a reply
// streams or the message has text or a recording, so more can be said without clearing it
let showStop = $derived(isLoading && !canSend);
let showRecord = $derived.by(() => {
if (!voice?.show) return false;
if (showStop || canSend) return !voice.unavailableReason;
return currentConfig.autoMicOnEmpty;
});
let selectorModelRef: ModelsSelector | undefined = $state(undefined);
@@ -149,17 +170,29 @@
{/if}
{#if showModelSelector}
<ChatFormActionReasoning />
<!-- the reasoning effort sits in the model picker, under the models -->
<ModelsSelector
bind:this={selectorModelRef}
{disabled}
forceForegroundText
showReasoning
useGlobalSelection
/>
{/if}
</div>
{#if isVoiceRefining}
<span
class="flex items-center gap-1.5 text-caption whitespace-nowrap text-muted-foreground"
data-slot="voice-refining"
role="status"
>
<LoaderCircle class="size-icon-sm animate-spin" />
{isSendWaiting ? VOICE_MODE_MESSAGE.sendAfterRefining : VOICE_MODE_MESSAGE.refining}
</span>
{/if}
{#if isReasoning && !canSend}
<Button
class="group size-8 rounded-full p-0 max-md:size-9"
@@ -177,7 +210,26 @@
</Button>
{/if}
{#if isLoading && !canSend}
{#snippet record(filled: boolean)}
<ChatFormActionRecord
action={voice?.action}
{disabled}
{filled}
hint={voice?.hint}
{micWarning}
{onMicClick}
onPrepare={voice?.prepare}
onPrepareEnd={voice?.unprepare}
secondary
unavailableReason={voice?.unavailableReason}
/>
{/snippet}
{#if showRecord && !showStop}
{@render record(false)}
{/if}
{#if showStop}
<Button
class="group size-8 rounded-full p-0 max-md:size-9 hover:bg-destructive/10!"
onclick={onStop}
@@ -190,21 +242,18 @@
class="size-icon-md fill-muted-foreground stroke-muted-foreground group-hover:fill-destructive group-hover:stroke-destructive hover:fill-destructive hover:stroke-destructive"
/>
</Button>
{:else if shouldShowRecordButton}
<ChatFormActionRecord
{disabled}
{hasAudioModality}
{isLoading}
{isRecording}
{micWarning}
{onMicClick}
/>
{:else}
<ChatFormActionSubmit
canSend={canSend && (showModelSelector ? hasModelSelected && isSelectedModelInCache : true)}
{disabled}
loading={isSendWaiting}
showErrorState={showModelSelector && hasModelSelected && !isSelectedModelInCache}
tooltipLabel={submitTooltip}
/>
{/if}
<!-- while a reply streams, the microphone is the last button, filled like stop -->
{#if showRecord && showStop}
{@render record(true)}
{/if}
</div>
@@ -0,0 +1,63 @@
<!--
The chat form's actions row while it records: Llama UI's VoiceRecordingBar with the form's labels and its
microphone button as the stop button. A voice message's text, when the model streams it, runs under the waveform;
dictated text goes into the message instead. After a dictation that streamed nothing, it waits for the text in
place of the waveform. Speech that stays too quiet even boosted is said inside the row, with the advice in a tooltip above it, so the form does not jump.
-->
<script lang="ts">
import { VoiceRecordingBar } from '@ggml-org/llama-ui/voice';
import { ChatFormActionRecord } from '#lib/components/app/index.ts';
import { VOICE_MODE_MESSAGE, VOICE_RECORDING_BAR_STATUS } from '#lib/constants/index.ts';
import { type ChatFormVoiceState, VoiceMode } from '#lib/enums/index.ts';
interface Props {
class?: string;
elapsedMs: number;
levels: number[];
/** Text streaming while a voice message is recorded. */
liveCaption?: string;
mode: VoiceMode;
/** The speech is too quiet even at the highest gain: the row says so, without changing its height. */
quiet?: boolean;
state: ChatFormVoiceState;
onCancel: () => void;
onStop: () => void;
/** Stops and sends; left out, there is no send button. */
onSend?: () => void;
}
let {
class: className = '',
elapsedMs,
levels,
liveCaption = '',
mode,
onCancel,
onSend,
onStop,
quiet = false,
state
}: Props = $props();
const LABELS = {
starting: VOICE_MODE_MESSAGE.starting,
waiting: VOICE_MODE_MESSAGE.transcribing
};
</script>
<VoiceRecordingBar
caption={liveCaption}
class={className}
{elapsedMs}
label={mode === VoiceMode.DICTATION ? VOICE_MODE_MESSAGE.dictating : VOICE_MODE_MESSAGE.recording}
labels={LABELS}
{levels}
{onCancel}
{onSend}
status={VOICE_RECORDING_BAR_STATUS[state]}
warning={quiet ? VOICE_MODE_MESSAGE.tooQuiet : null}
>
{#snippet stop({ disabled })}
<ChatFormActionRecord class="shrink-0" {disabled} isRecording onMicClick={onStop} />
{/snippet}
</VoiceRecordingBar>
@@ -16,7 +16,7 @@
</div>
{#if subtitle}
<div class="text-[10px] leading-tight text-muted-foreground/70 max-md:text-[11px]">
<div class="text-caption-sm leading-tight text-muted-foreground/70 max-md:text-caption">
{subtitle}
</div>
{/if}
@@ -33,13 +33,13 @@
</script>
<div class="mt-3 border-t border-border/50 pt-4">
<p class="text-xs text-muted-foreground max-md:text-[13px]">Token usage details</p>
<p class="text-caption text-muted-foreground max-md:text-body-sm">Token usage details</p>
<div class="flex flex-col gap-4 pt-4 text-xs max-md:gap-5 max-md:text-[13px]">
<div class="flex flex-col gap-4 pt-4 text-caption max-md:gap-5 max-md:text-body-sm">
{#if hasCumulative}
<div>
<h3
class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground/70 mb-2 max-md:text-xs"
class="text-label-sm uppercase tracking-wide text-muted-foreground/70 mb-2 max-md:text-caption"
>
Across all turns
</h3>
@@ -68,7 +68,7 @@
{#if hasCurrent}
<div>
<h3
class="text-[11px] font-medium uppercase tracking-wide text-muted-foreground/70 mb-2 max-md:text-xs"
class="text-label-sm uppercase tracking-wide text-muted-foreground/70 mb-2 max-md:text-caption"
>
This turn · KV cache
</h3>
@@ -12,13 +12,17 @@
</script>
{#if modelId !== null && !isLoading}
<div class="flex flex-col gap-2 border-t border-border/50 pt-2 text-xs text-muted-foreground">
<div
class="flex flex-col gap-2 border-t border-border/50 pt-2 text-caption text-muted-foreground"
>
<span>Available context size is only visible once the model is loaded.</span>
<Button class="self-start" onclick={onLoad} size="sm" variant="outline">Load model</Button>
</div>
{:else if isLoading}
<div class="flex items-center gap-2 border-t border-border/50 pt-2 text-xs text-muted-foreground">
<div
class="flex items-center gap-2 border-t border-border/50 pt-2 text-caption text-muted-foreground"
>
<Loader2 class="size-icon-sm animate-spin" />
<span>Loading model...</span>
@@ -120,7 +120,7 @@
></div>
</div>
<div class="flex justify-between text-xs text-muted-foreground max-md:text-[13px]">
<div class="flex justify-between text-caption text-muted-foreground max-md:text-body-sm">
<span>
<span class={colorLevelTextClass(gauge.colorLevel)}>{gauge.contextPercent}%</span> used
</span>
@@ -130,7 +130,7 @@
</span>
</div>
{:else}
<div class="text-xs text-muted-foreground">No context info available</div>
<div class="text-caption text-muted-foreground">No context info available</div>
{/if}
{#if gauge.hasAnyUsage}
@@ -172,7 +172,7 @@
{:else if gaugePopup.open}
<div
bind:this={cardEl}
class="absolute z-50 w-64 -translate-x-1/2 rounded-xl border matte-float p-1.5 text-sm"
class="absolute z-50 w-64 -translate-x-1/2 rounded-xl border matte-float p-1.5 text-body-sm"
onpointerenter={gaugeCardEnter}
onpointerleave={gaugeCardLeave}
role="status"
@@ -339,7 +339,7 @@
/>
{#if !fileSearchEnabled}
<div class="px-2 py-1.5 text-sm text-muted-foreground">{searchUnavailableMessage}</div>
<div class="px-2 py-1.5 text-body-sm text-muted-foreground">{searchUnavailableMessage}</div>
{:else if query.trim() && (search.isSearching || queryResults.length > 0 || searchError)}
<ChatFormCurrentWorkingDirectoryResultsList
bind:container={listContainer}
@@ -358,8 +358,8 @@
class={[
'flex cursor-pointer items-center outline-hidden select-none hover:bg-accent hover:text-accent-foreground',
inDrawer
? 'mt-1 gap-2 rounded-lg px-2 py-2.5 text-[15px]'
: '-mt-1 gap-2 rounded-sm px-2 py-1.5 text-sm'
? 'mt-1 gap-2 rounded-lg px-2 py-2.5 text-body'
: '-mt-1 gap-2 rounded-sm px-2 py-1.5 text-body-sm'
]}
onclick={browseNative}
type="button"
@@ -375,8 +375,8 @@
class={[
'flex cursor-pointer items-center outline-hidden select-none hover:bg-accent hover:text-accent-foreground',
inDrawer
? 'gap-2 rounded-lg px-2 py-2.5 text-[15px]'
: 'gap-2 rounded-sm px-2 py-1.5 text-sm'
? 'gap-2 rounded-lg px-2 py-2.5 text-body'
: 'gap-2 rounded-sm px-2 py-1.5 text-body-sm'
]}
onclick={clearDirectory}
type="button"
@@ -393,7 +393,9 @@
class={['h-px', inDrawer ? 'my-1 bg-border/60' : '-mx-2 my-2 bg-border/20']}
></div>
<span class={['font-mono', inDrawer ? 'px-2 py-2 text-xs' : 'px-2 py-1.5 text-[10px]']}>
<span
class={['font-mono', inDrawer ? 'px-2 py-2 text-caption' : 'px-2 py-1.5 text-caption-sm']}
>
Searching in:
<span class="truncate text-muted-foreground/70" title={searchScope}
@@ -30,7 +30,7 @@
<span
class={[
'text-muted-foreground inline-flex items-center gap-1 text-xs group',
'text-muted-foreground inline-flex items-center gap-1 text-caption group',
directory && 'text-foreground'
]}
>
@@ -38,18 +38,18 @@
class="max-h-48 overflow-y-auto py-2"
>
{#if isSearching && results.length === 0}
<div class="px-2 py-1.5 text-sm text-muted-foreground">Searching...</div>
<div class="px-2 py-1.5 text-body-sm text-muted-foreground">Searching...</div>
{:else if error}
<div class="px-2 py-1.5 text-sm text-destructive">{error}</div>
<div class="px-2 py-1.5 text-body-sm text-destructive">{error}</div>
{:else if results.length === 0}
<div class="px-2 py-1.5 text-sm text-muted-foreground">No matching folders</div>
<div class="px-2 py-1.5 text-body-sm text-muted-foreground">No matching folders</div>
{:else}
{#each results as path, index (path)}
<button
type="button"
{...{ [UI_DATA_ATTRS.RESULT_INDEX]: index }}
class={cn(
'relative flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground'
'relative flex w-full cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-body-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground'
)}
data-highlighted={index === hoveredIndex ? '' : undefined}
onclick={() => onCommit?.(path)}
@@ -18,7 +18,7 @@
</script>
<div class="min-w-0 flex-1">
<div class="mb-0.5 flex items-center gap-1.5 text-xs text-muted-foreground">
<div class="mb-0.5 flex items-center gap-1.5 text-caption text-muted-foreground">
{#if faviconUrl}
<img
alt=""
@@ -44,7 +44,7 @@
</div>
{#if description}
<p class="mt-0.5 truncate text-sm text-muted-foreground">
<p class="mt-0.5 truncate text-body-sm text-muted-foreground">
{description}
</p>
{/if}
@@ -97,7 +97,7 @@
{/if}
{:else if items && items.length === 0}
{#if emptyMessage}
<div class="py-6 text-center text-sm text-muted-foreground">{emptyMessage}</div>
<div class="py-6 text-center text-body-sm text-muted-foreground">{emptyMessage}</div>
{/if}
{:else}
{#each items as itemData, index (itemKey(itemData, index))}
@@ -134,9 +134,9 @@
<Icon class="mt-0.5 size-icon-md shrink-0 text-muted-foreground" />
<div class="flex min-w-0 flex-1 flex-col">
<span class="font-mono text-sm font-medium">/{command.name}</span>
<span class="font-mono text-label">/{command.name}</span>
<span class="min-w-0 flex-1 truncate text-left text-xs text-muted-foreground">
<span class="min-w-0 flex-1 truncate text-left text-caption text-muted-foreground">
{command.description}
</span>
</div>
@@ -57,7 +57,7 @@
{#if promptError}
<div
class="flex items-start gap-2 rounded-lg border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive"
class="flex items-start gap-2 rounded-lg border border-destructive/50 bg-destructive/10 px-3 py-2 text-body-sm text-destructive"
role="alert"
>
<span class="shrink-0">⚠</span>
@@ -46,7 +46,7 @@
</span>
{#if isLoadingSuggestions}
<span class="text-xs text-muted-foreground/50">...</span>
<span class="text-caption text-muted-foreground/50">...</span>
{/if}
</Label>
@@ -70,7 +70,7 @@
>
{#each suggestions as suggestion, i (suggestion)}
<button
class="w-full px-3 py-1.5 text-left text-sm hover:bg-accent {i === autocompleteIndex
class="w-full px-3 py-1.5 text-left text-body-sm hover:bg-accent {i === autocompleteIndex
? 'bg-accent'
: ''}"
onmousedown={() => onSelectSuggestion(suggestion)}
@@ -258,7 +258,7 @@
<Tooltip.Root>
<Tooltip.Trigger>
{#snippet child({ props })}
<span {...props} class="truncate text-sm font-medium">{entry.name}</span>
<span {...props} class="truncate text-label">{entry.name}</span>
{/snippet}
</Tooltip.Trigger>
@@ -267,17 +267,17 @@
</Tooltip.Content>
</Tooltip.Root>
{:else}
<span class="truncate text-sm font-medium">{entry.name}</span>
<span class="truncate text-label">{entry.name}</span>
{/if}
<span
class="shrink-0 rounded-full bg-muted px-1.5 py-0.5 font-mono text-[9px] uppercase tracking-wide text-muted-foreground"
class="shrink-0 rounded-full bg-muted px-1.5 py-0.5 font-mono text-caption-sm uppercase tracking-wide text-muted-foreground"
>
{entry.type}
</span>
</div>
<span class="min-w-0 flex-1 truncate font-mono text-left text-xs">
<span class="min-w-0 flex-1 truncate font-mono text-left text-caption">
<HighlightedMatch query={trimmedQuery} text={abbreviateHome(entry.path, home)} />
</span>
</div>
@@ -199,7 +199,7 @@
{#if displayedModel}
<div class="info my-6 grid gap-4 tabular-nums">
<div class="inline-flex flex-wrap items-start gap-2 text-xs text-muted-foreground">
<div class="inline-flex flex-wrap items-start gap-2 text-caption text-muted-foreground">
<ChatMessageAssistantModel
{displayedModel}
isLoading={chatStore.isLoading}
@@ -15,7 +15,7 @@
<div in:fade class="{marginClass} w-full max-w-3xl">
<div class="flex flex-col items-start gap-2">
<span class="shimmer-text text-sm">
<span class="shimmer-text text-body-sm">
{modelLoadingText ??
processingState.getPromptProgressText() ??
processingState.getProcessingMessage() ??
@@ -24,8 +24,8 @@
margin-top: 1.5rem;
padding: 1rem 1.25rem;
border-radius: 1rem;
background: hsl(var(--muted) / 0.3);
color: var(--foreground);
background: hsl(var(--surface-muted) / 0.3);
color: var(--fg-default);
font-size: 0.875rem;
line-height: 1.6;
white-space: pre-wrap;
@@ -20,13 +20,13 @@
{#if info.path === null}
<FolderX class="text-muted-foreground/60 size-icon-sm shrink-0" />
<span class="text-foreground/80 text-sm font-medium">Working directory cleared</span>
<span class="text-foreground/80 text-label">Working directory cleared</span>
{:else}
<Folder class="text-muted-foreground/60 h-3.5 w-3.5 shrink-0" />
<span class="text-foreground/80 text-sm font-medium">Set working directory to&nbsp;</span>
<span class="text-foreground/80 text-label">Set working directory to&nbsp;</span>
<span class="font-mono text-foreground/90 text-sm break-all" title={info.path}>
<span class="font-mono text-foreground/90 text-body-sm break-all" title={info.path}>
{info.display}
</span>
{/if}
@@ -29,13 +29,13 @@
<ChatMessageEditForm />
{:else}
<ChatMessageMcpPromptContent
class="w-full max-w-[80%]"
class="w-full max-w-4/5"
prompt={mcpPrompt}
variant={McpPromptVariant.MESSAGE}
/>
{#if message.timestamp}
<div class="max-w-[80%]">
<div class="max-w-4/5">
<ChatMessageActionIcons actionsPosition="right" justify="end" />
</div>
{/if}
@@ -82,7 +82,7 @@
let showArgBadges = $derived(hasArguments && !isLoading && !loadError);
let isAttachment = $derived(variant === McpPromptVariant.ATTACHMENT);
let textSizeClass = $derived(isAttachment ? 'text-xs' : 'text-md');
let textSizeClass = $derived(isAttachment ? 'text-caption' : 'text-md');
let paddingClass = $derived(isAttachment ? 'px-3 py-2' : 'px-3.75 py-2.5');
let maxHeightStyle = $derived(
isAttachment ? 'max-height: 6rem;' : 'max-height: var(--max-message-height);'
@@ -94,7 +94,7 @@
<div class="flex flex-col gap-2 {className}">
<div class="flex items-center justify-between gap-2">
<div class="inline-flex flex-wrap items-center gap-1.25 text-xs text-muted-foreground">
<div class="inline-flex flex-wrap items-center gap-1.25 text-caption text-muted-foreground">
<Tooltip.Root>
<Tooltip.Trigger>
{#if serverFavicon}
@@ -124,7 +124,7 @@
<Tooltip.Trigger>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<span
class="rounded-sm bg-purple-200/60 px-1.5 py-0.5 text-[10px] leading-none text-purple-700 transition-opacity dark:bg-purple-800/40 dark:text-purple-300 {hoveredArgKey &&
class="rounded-sm bg-purple-200/60 px-1.5 py-0.5 text-caption-sm leading-none text-purple-700 transition-opacity dark:bg-purple-800/40 dark:text-purple-300 {hoveredArgKey &&
hoveredArgKey !== key
? 'opacity-30'
: ''}"
@@ -146,7 +146,7 @@
{#if loadError}
<Card
class="relative overflow-hidden rounded-[1.125rem] border border-destructive/50 bg-destructive/10 backdrop-blur-md"
class="relative overflow-hidden rounded-2xl border border-destructive/50 bg-destructive/10 backdrop-blur-md"
>
<div
class="overflow-y-auto {paddingClass}"
@@ -157,7 +157,7 @@
</Card>
{:else if isLoading}
<Card
class="relative overflow-hidden rounded-[1.125rem] border border-purple-200 bg-purple-500/10 px-1 py-2 backdrop-blur-md dark:border-purple-800 dark:bg-purple-500/20"
class="relative overflow-hidden rounded-2xl border border-purple-200 bg-purple-500/10 px-1 py-2 backdrop-blur-md dark:border-purple-800 dark:bg-purple-500/20"
>
<div
class="overflow-y-auto {paddingClass}"
@@ -174,7 +174,7 @@
</Card>
{:else if hasContent}
<Card
class="relative overflow-hidden rounded-[1.125rem] border border-purple-200 bg-purple-500/10 py-0 text-foreground backdrop-blur-md dark:border-purple-800 dark:bg-purple-500/20"
class="relative overflow-hidden rounded-2xl border border-purple-200 bg-purple-500/10 py-0 text-foreground backdrop-blur-md dark:border-purple-800 dark:bg-purple-500/20"
>
<div
class="overflow-y-auto {paddingClass}"
@@ -19,5 +19,5 @@
{#if isCwdChange}
<ChatMessageCwdChange class={className} {message} />
{:else}
<span class="text-muted-foreground block text-sm {className}">{message.content}</span>
<span class="text-muted-foreground block text-body-sm {className}">{message.content}</span>
{/if}
@@ -81,10 +81,10 @@
role="group"
>
{#if editCtx.isEditing}
<div class="w-full max-w-[80%]">
<div class="w-full max-w-4/5">
<textarea
bind:this={textareaElement}
class="min-h-[60px] w-full resize-none rounded-2xl px-3 py-2 text-base md:text-sm {INPUT_CLASSES}"
class="min-h-15 w-full resize-none rounded-2xl px-3 py-2 text-body md:text-body-sm {INPUT_CLASSES}"
oninput={(e) => {
autoResizeTextarea(e.currentTarget);
editCtx.setContent(e.currentTarget.value);
@@ -116,7 +116,7 @@
</div>
{:else}
{#if message.content.trim()}
<div class="relative max-w-[80%]">
<div class="relative max-w-4/5">
<button
class="group/expand block w-full text-left {!isExpanded && showExpandButton
? 'cursor-pointer'
@@ -125,9 +125,9 @@
type="button"
>
<Card
class="overflow-y-auto rounded-[1.125rem] !border-2 !border-dashed !border-border/50 bg-muted px-3.75 py-1.5 data-[multiline]:py-2.5"
class="overflow-y-auto rounded-2xl !border-2 !border-dashed !border-border/50 bg-muted px-3.75 py-1.5 data-[multiline]:py-2.5"
data-multiline={isMultiline ? '' : undefined}
style="border: 2px dashed hsl(var(--border)); max-height: var(--max-message-height); overflow-wrap: anywhere; word-break: break-word;"
style="border: 2px dashed hsl(var(--line-default)); max-height: var(--max-message-height); overflow-wrap: anywhere; word-break: break-word;"
>
<div
class="relative transition-all duration-300 {isExpanded
@@ -159,7 +159,7 @@
class="pointer-events-none absolute right-0 bottom-4 left-0 flex justify-center opacity-0 transition-opacity group-hover/expand:opacity-100"
>
<Button
class="rounded-full px-4 py-1.5 text-xs shadow-(--elevation-surface)"
class="rounded-full px-4 py-1.5 text-caption shadow-(--elevation-surface)"
size="sm"
variant="outline"
>
@@ -172,7 +172,7 @@
{#if isExpanded && showExpandButton}
<div class="mb-2 flex justify-center">
<Button
class="rounded-full px-4 py-1.5 text-xs"
class="rounded-full px-4 py-1.5 text-caption"
onclick={(e) => {
e.stopPropagation();
toggleExpand();
@@ -190,7 +190,7 @@
{/if}
{#if message.timestamp}
<div class="max-w-[80%]">
<div class="max-w-4/5">
<ChatMessageActionIcons actionsPosition="right" justify="end" />
</div>
{/if}
@@ -37,7 +37,7 @@
<ToolCallBlock {isStreaming} meta={null} {onToggle} {open} {section} {title}>
{#snippet children(_meta, ctx)}
{#if ctx.isStreamingCall}
<div class="mb-2 flex items-center gap-2 text-xs text-muted-foreground/70">
<div class="mb-2 flex items-center gap-2 text-caption text-muted-foreground/70">
<span>Input</span>
{#if ctx.isStreaming}
@@ -53,12 +53,12 @@
streaming={ctx.isCodeStreaming}
/>
{:else if ctx.isStreaming}
<div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">
<div class="rounded bg-muted/20 p-2 text-caption text-muted-foreground/70 italic">
Receiving arguments...
</div>
{:else}
<div
class="rounded bg-yellow-500/10 p-2 text-xs text-yellow-600 italic dark:text-yellow-400"
class="rounded bg-yellow-500/10 p-2 text-caption text-yellow-600 italic dark:text-yellow-400"
>
Response was truncated
</div>
@@ -66,7 +66,7 @@
{:else}
{@const showInput = Boolean(section.toolArgs)}
{#if showInput}
<div class="mb-1.5 flex items-center gap-2 text-xs text-muted-foreground/70">
<div class="mb-1.5 flex items-center gap-2 text-caption text-muted-foreground/70">
<span>Input</span>
</div>
@@ -80,8 +80,8 @@
<div
class={showInput
? 'mt-4 mb-1.5 flex items-center gap-2 text-xs text-muted-foreground/70'
: 'mb-1.5 flex items-center gap-2 text-xs text-muted-foreground/70'}
? 'mt-4 mb-1.5 flex items-center gap-2 text-caption text-muted-foreground/70'
: 'mb-1.5 flex items-center gap-2 text-caption text-muted-foreground/70'}
>
<span>Output</span>
@@ -91,7 +91,7 @@
</div>
{#if ctx.isPending}
<div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">
<div class="rounded bg-muted/20 p-2 text-caption text-muted-foreground/70 italic">
Waiting for result...
</div>
{:else if section.toolResult}
@@ -106,7 +106,7 @@
{:else}
<div class="overflow-auto">
{#each parsedLines as line, i (i)}
<div class="font-mono text-[11px] leading-relaxed whitespace-pre-wrap">
<div class="font-mono text-caption leading-relaxed whitespace-pre-wrap">
{line.text}
</div>
@@ -135,7 +135,9 @@
</div>
{/if}
{:else}
<div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">No output</div>
<div class="rounded bg-muted/20 p-2 text-caption text-muted-foreground/70 italic">
No output
</div>
{/if}
{/if}
{/snippet}
@@ -45,7 +45,7 @@
</span>
{#if editFileMeta?.errorMessage}
<span class="shrink-0 text-xs italic text-muted-foreground/70">(failed)</span>
<span class="shrink-0 text-caption italic text-muted-foreground/70">(failed)</span>
{/if}
</span>
</span>
@@ -54,7 +54,7 @@
{#snippet children(_meta, ctx)}
{#if editFileBody?.errorMessage}
<div
class="flex items-start gap-2 rounded bg-surface-danger p-2 text-xs text-fg-danger italic"
class="flex items-start gap-2 rounded bg-surface-danger p-2 text-caption text-fg-danger italic"
>
<XCircle class="mt-0.5 size-icon-xs shrink-0" />
@@ -63,7 +63,7 @@
{:else if editFileBody?.edits.length}
{#each editDiffs as diffLines, ei (ei)}
<div class={ei === 0 ? '' : 'mt-3'}>
<div class="mb-1.5 text-xs text-muted-foreground/70 italic">
<div class="mb-1.5 text-caption text-muted-foreground/70 italic">
Edit {ei + 1}&nbsp;of&nbsp;{editFileBody.edits.length}
</div>
@@ -85,7 +85,7 @@
</div>
{/each}
<div class="mt-1.5 text-xs text-muted-foreground/70 italic">
<div class="mt-1.5 text-caption text-muted-foreground/70 italic">
{#if editFileBody.resultMessage}
{editFileBody.resultMessage}{editFileBody.editsApplied != null
? RESULT_STAT_SEPARATOR
@@ -105,11 +105,13 @@
streaming={ctx.isCodeStreaming}
/>
{:else if ctx.isStreaming}
<div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">
<div class="rounded bg-muted/20 p-2 text-caption text-muted-foreground/70 italic">
Receiving arguments...
</div>
{:else}
<div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">No edits</div>
<div class="rounded bg-muted/20 p-2 text-caption text-muted-foreground/70 italic">
No edits
</div>
{/if}
{/snippet}
</ToolCallBlock>
@@ -119,13 +121,13 @@
overflow: auto;
border-radius: 0.75rem;
border-width: 1px;
border-color: color-mix(in oklch, var(--border) 30%, transparent);
background: var(--code-background);
border-color: color-mix(in oklch, var(--line-default) 30%, transparent);
background: var(--surface-code);
box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}
:global(.dark) .diff-block {
border-color: color-mix(in oklch, var(--border) 20%, transparent);
border-color: color-mix(in oklch, var(--line-default) 20%, transparent);
}
/* Each row is a 4-column grid: old-line#, marker, new-line#, text.
@@ -144,13 +146,13 @@
text-align: right;
padding-right: 0.5rem;
user-select: none;
color: color-mix(in oklch, var(--muted-foreground) 70%, transparent);
color: color-mix(in oklch, var(--fg-muted) 70%, transparent);
font-variant-numeric: tabular-nums;
}
.diff-marker {
text-align: center;
color: color-mix(in oklch, var(--muted-foreground) 70%, transparent);
color: color-mix(in oklch, var(--fg-muted) 70%, transparent);
user-select: none;
}
@@ -248,18 +248,18 @@
{#snippet children(_meta, ctx)}
{#if (ctx.isPending && !commandStreaming) || (isLive && !section.toolResult)}
<div class="flex items-start gap-2 text-xs text-muted-foreground/70">
<div class="flex items-start gap-2 text-caption text-muted-foreground/70">
<Loader2 class="size-icon-xs animate-spin" />
Executing command...
</div>
{:else if ctx.isInterrupted}
<div class="flex items-start gap-2 text-xs text-muted-foreground/70 italic">
<div class="flex items-start gap-2 text-caption text-muted-foreground/70 italic">
<CircleStop class="mt-0.5 h-3 w-3 shrink-0" />
<span>Command interrupted before it returned output</span>
</div>
{:else if execShellError}
<div class="flex items-start gap-2 text-xs text-fg-danger italic">
<div class="flex items-start gap-2 text-caption text-fg-danger italic">
<XCircle class="mt-0.5 size-icon-xs shrink-0" />
<span>{execShellError}</span>
@@ -271,7 +271,7 @@
onscroll={handleScrollEvent}
>
{#each outputLines as line, i (i)}
<div class="font-mono text-[11px] leading-relaxed whitespace-pre-wrap">{line.text}</div>
<div class="font-mono text-caption leading-relaxed whitespace-pre-wrap">{line.text}</div>
{#if line.media?.type === AttachmentType.IMAGE}
<img
@@ -316,13 +316,13 @@
.exec-wd {
font-family: var(--font-mono);
color: var(--muted-foreground);
color: var(--fg-muted);
margin-right: var(--exec-wd-margin);
}
.exec-prompt {
font-family: var(--font-mono);
color: var(--muted-foreground);
color: var(--fg-muted);
opacity: 0.55;
margin-right: var(--exec-wd-margin);
}
@@ -333,7 +333,7 @@
height: 1.05em;
margin-left: 0.15rem;
vertical-align: text-bottom;
background: var(--foreground);
background: var(--fg-default);
animation: exec-cursor-blink 1.1s steps(1) infinite;
}
@@ -40,12 +40,12 @@
{#snippet children(meta, ctx)}
{#if ctx.isPending}
<div class="rounded bg-muted/20 p-2 text-xs text-muted-foreground/70 italic">
<div class="rounded bg-muted/20 p-2 text-caption text-muted-foreground/70 italic">
Searching...
</div>
{:else if meta?.errorMessage}
<div
class="flex items-start gap-2 rounded bg-surface-danger p-2 text-xs text-fg-danger italic"
class="flex items-start gap-2 rounded bg-surface-danger p-2 text-caption text-fg-danger italic"
>
<XCircle class="mt-0.5 size-icon-xs shrink-0" />
@@ -54,17 +54,17 @@
{:else if meta && meta.matches.length > 0}
<div class="max-h-96 overflow-auto">
{#each meta.matches as match, i (i)}
<div class="font-mono text-[11px] leading-relaxed whitespace-pre-wrap">{match}</div>
<div class="font-mono text-caption leading-relaxed whitespace-pre-wrap">{match}</div>
{/each}
</div>
<div class="mt-1.5 text-xs text-muted-foreground/70 italic">
<div class="mt-1.5 text-caption text-muted-foreground/70 italic">
Total matches: <span class="font-mono">{meta.totalMatches ?? meta.matches.length}</span>
</div>
{:else}
<div class="text-xs text-muted-foreground/70 italic">No matches</div>
<div class="text-caption text-muted-foreground/70 italic">No matches</div>
<div class="mt-1.5 text-xs text-muted-foreground/70 italic">
<div class="mt-1.5 text-caption text-muted-foreground/70 italic">
Total matches: <span class="font-mono">{meta?.totalMatches ?? 0}</span>
</div>
{/if}
@@ -46,18 +46,18 @@
<Clock class="text-muted-foreground/60 size-icon-sm shrink-0" />
{#if showSpinner}
<span class="text-foreground/80 text-sm font-medium">Current time</span>
<span class="text-foreground/80 text-label">Current time</span>
<Loader2 class="text-muted-foreground/70 size-icon-xs animate-spin" />
{:else if dateMeta.errorMessage}
<span class="text-foreground/80 text-sm font-medium">Current time&nbsp;</span>
<span class="text-foreground/80 text-label">Current time&nbsp;</span>
<span class="text-fg-danger text-xs italic">-&nbsp;{dateMeta.errorMessage}</span>
<span class="text-fg-danger text-caption italic">-&nbsp;{dateMeta.errorMessage}</span>
{:else if dateMeta.dateString}
<span class="text-foreground/80 text-sm font-medium">Current time is&nbsp;</span>
<span class="text-foreground/80 text-label">Current time is&nbsp;</span>
<span class="font-mono text-foreground/90 text-sm">{dateMeta.dateString}</span>
<span class="font-mono text-foreground/90 text-body-sm">{dateMeta.dateString}</span>
{:else}
<span class="text-foreground/80 text-sm font-medium">Current time</span>
<span class="text-foreground/80 text-label">Current time</span>
{/if}
</div>

Some files were not shown because too many files have changed in this diff Show More