universal-llm-client 4.3.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -24
- package/README.md +60 -11
- package/dist/ai-model.d.ts +12 -1
- package/dist/ai-model.d.ts.map +1 -1
- package/dist/ai-model.js +36 -1
- package/dist/ai-model.js.map +1 -1
- package/dist/auditor.js.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/gemma-channel.d.ts +14 -0
- package/dist/gemma-channel.d.ts.map +1 -0
- package/dist/gemma-channel.js +38 -0
- package/dist/gemma-channel.js.map +1 -0
- package/dist/gemma-diffusion.d.ts +49 -0
- package/dist/gemma-diffusion.d.ts.map +1 -0
- package/dist/gemma-diffusion.js +147 -0
- package/dist/gemma-diffusion.js.map +1 -0
- package/dist/http.d.ts +4 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +14 -1
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +163 -7
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/mcp.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +28 -3
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google.d.ts +22 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +223 -13
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/ollama.d.ts +2 -0
- package/dist/providers/ollama.d.ts.map +1 -1
- package/dist/providers/ollama.js +59 -30
- package/dist/providers/ollama.js.map +1 -1
- package/dist/providers/openai.d.ts +14 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +200 -22
- package/dist/providers/openai.js.map +1 -1
- package/dist/router.d.ts +2 -0
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +4 -0
- package/dist/router.js.map +1 -1
- package/dist/stream-decoder.d.ts +12 -0
- package/dist/stream-decoder.d.ts.map +1 -1
- package/dist/stream-decoder.js +182 -5
- package/dist/stream-decoder.js.map +1 -1
- package/dist/structured-output.js.map +1 -1
- package/dist/thinking.d.ts +36 -0
- package/dist/thinking.d.ts.map +1 -0
- package/dist/thinking.js +52 -0
- package/dist/thinking.js.map +1 -0
- package/dist/tools.js.map +1 -1
- package/dist/zod-adapter.js.map +1 -1
- package/package.json +4 -1
- package/src/ai-model.ts +400 -0
- package/src/auditor.ts +213 -0
- package/src/client.ts +402 -0
- package/src/debug/debug-google-streaming.ts +97 -0
- package/src/debug/debug-tool-execution.ts +86 -0
- package/src/debug/test-lmstudio-tools.ts +155 -0
- package/src/demos/README.md +47 -0
- package/src/demos/basic/universal-llm-examples.ts +161 -0
- package/src/demos/diffusion-gemma/.env +29 -0
- package/src/demos/diffusion-gemma/.env.example +27 -0
- package/src/demos/diffusion-gemma/CLAUDE.md +95 -0
- package/src/demos/diffusion-gemma/README.md +59 -0
- package/src/demos/diffusion-gemma/canvas.ts +1606 -0
- package/src/demos/diffusion-gemma/docker-compose.yml +29 -0
- package/src/demos/diffusion-gemma/probe-stream.ts +51 -0
- package/src/demos/diffusion-gemma/probe-tools.ts +55 -0
- package/src/demos/diffusion-gemma/server.ts +1205 -0
- package/src/demos/diffusion-gemma/start-vllm.sh +98 -0
- package/src/demos/mcp/astrid-memory-demo.ts +295 -0
- package/src/demos/mcp/astrid-persona-memory.ts +357 -0
- package/src/demos/mcp/mcp-mongodb-demo.ts +275 -0
- package/src/demos/mcp/simple-astrid-memory.ts +148 -0
- package/src/demos/mcp/simple-mcp-demo.ts +68 -0
- package/src/demos/mcp/working-mcp-demo.ts +62 -0
- package/src/demos/model-alias-demo.ts +0 -0
- package/src/demos/tools/RAG_MEMORY_INTEGRATION.md +267 -0
- package/src/demos/tools/astrid-memory-demo.ts +270 -0
- package/src/demos/tools/astrid-production-memory-clean.ts +785 -0
- package/src/demos/tools/astrid-production-memory.ts +558 -0
- package/src/demos/tools/basic-translation-test.ts +66 -0
- package/src/demos/tools/chromadb-similarity-tuning.ts +390 -0
- package/src/demos/tools/clean-multilingual-conversation.ts +209 -0
- package/src/demos/tools/clean-translation-test.ts +119 -0
- package/src/demos/tools/clean-universal-multilingual-test.ts +131 -0
- package/src/demos/tools/complete-rag-demo.ts +369 -0
- package/src/demos/tools/complete-tool-demo.ts +132 -0
- package/src/demos/tools/demo-tool-calling.ts +124 -0
- package/src/demos/tools/dynamic-language-switching-test.ts +251 -0
- package/src/demos/tools/hybrid-thinking-test.ts +154 -0
- package/src/demos/tools/memory-integration-test.ts +420 -0
- package/src/demos/tools/multilingual-memory-system.ts +802 -0
- package/src/demos/tools/ondemand-translation-demo.ts +655 -0
- package/src/demos/tools/production-tool-demo.ts +245 -0
- package/src/demos/tools/revolutionary-multilingual-test.ts +151 -0
- package/src/demos/tools/rigorous-language-analysis.ts +218 -0
- package/src/demos/tools/test-universal-memory-system.ts +126 -0
- package/src/demos/tools/translation-integration-guide.ts +346 -0
- package/src/demos/tools/universal-memory-system.ts +560 -0
- package/src/gemma-channel.ts +47 -0
- package/src/gemma-diffusion.ts +167 -0
- package/src/http.ts +261 -0
- package/src/index.ts +180 -0
- package/src/interfaces.ts +843 -0
- package/src/mcp.ts +345 -0
- package/src/providers/anthropic.ts +796 -0
- package/src/providers/google.ts +840 -0
- package/src/providers/index.ts +8 -0
- package/src/providers/ollama.ts +503 -0
- package/src/providers/openai.ts +587 -0
- package/src/router.ts +785 -0
- package/src/stream-decoder.ts +535 -0
- package/src/structured-output.ts +759 -0
- package/src/test-scripts/test-advanced-tools.ts +310 -0
- package/src/test-scripts/test-google-deep-research.ts +33 -0
- package/src/test-scripts/test-google-streaming-enhanced.ts +147 -0
- package/src/test-scripts/test-google-streaming.ts +63 -0
- package/src/test-scripts/test-google-system-prompt-comprehensive.ts +189 -0
- package/src/test-scripts/test-google-thinking.ts +46 -0
- package/src/test-scripts/test-mcp-config.ts +28 -0
- package/src/test-scripts/test-mcp-connection.ts +29 -0
- package/src/test-scripts/test-system-message-positions.ts +163 -0
- package/src/test-scripts/test-system-prompt-improvement-demo.ts +83 -0
- package/src/test-scripts/test-tool-calling.ts +231 -0
- package/src/test-scripts/test-vllm-qwen36.ts +256 -0
- package/src/tests/ai-model.test.ts +1614 -0
- package/src/tests/auditor.test.ts +224 -0
- package/src/tests/gemma-diffusion.test.ts +115 -0
- package/src/tests/http.test.ts +200 -0
- package/src/tests/interfaces.test.ts +117 -0
- package/src/tests/providers/anthropic.test.ts +118 -0
- package/src/tests/providers/google.test.ts +841 -0
- package/src/tests/providers/ollama.test.ts +1034 -0
- package/src/tests/providers/openai.test.ts +1511 -0
- package/src/tests/router.test.ts +254 -0
- package/src/tests/stream-decoder.test.ts +263 -0
- package/src/tests/structured-output.test.ts +1450 -0
- package/src/tests/thinking.test.ts +65 -0
- package/src/tests/tools.test.ts +175 -0
- package/src/thinking.ts +73 -0
- package/src/tools.ts +246 -0
- package/src/zod-adapter.ts +72 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# DiffusionGemma demo — test harness + "Signal from Noise" canvas
|
|
2
|
+
|
|
3
|
+
Standalone Bun server exercising `universal-llm-client` against DiffusionGemma
|
|
4
|
+
(a discrete diffusion LM served by vLLM).
|
|
5
|
+
|
|
6
|
+
## Run
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
bun run demo:diffusion-gemma:engine # starts vLLM via demo-local docker compose
|
|
10
|
+
bun run demo:diffusion-gemma # starts the Bun demo server
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- Demo server: **http://localhost:3333** (`/` test harness, `/canvas` diffusion chat UI)
|
|
14
|
+
- vLLM upstream: `VLLM_URL` env, default `http://localhost:8000`
|
|
15
|
+
- Model: `MODEL_NAME` env, default `RedHatAI/diffusiongemma-26B-A4B-it-NVFP4`
|
|
16
|
+
- vLLM is started via `src/demos/diffusion-gemma/docker-compose.yml` and
|
|
17
|
+
`src/demos/diffusion-gemma/start-vllm.sh` — includes a WSL2 UVA patch and
|
|
18
|
+
the `entropy_bound` diffusion sampler. Runs as docker container
|
|
19
|
+
`diffusiongemma` (script is bind-mounted as `/start-vllm.sh`, so edits apply
|
|
20
|
+
on `docker restart diffusiongemma`). The script also sources
|
|
21
|
+
`src/demos/diffusion-gemma/.cache/huggingface/diffusion-env.sh`
|
|
22
|
+
(host-writable through the HF-cache bind mount) — that's how
|
|
23
|
+
`/api/engine-config` changes settings without recreating the container.
|
|
24
|
+
- **Tuned for single-user local serving** (env-overridable in the start script):
|
|
25
|
+
`GPU_MEM_UTIL` (default 0.28 ≈ 27 GiB — without caps vLLM grabbed ~88 GiB:
|
|
26
|
+
69 GiB KV cache for the native 262k context, measured <0.5% used),
|
|
27
|
+
`MAX_MODEL_LEN` (32768), `MAX_NUM_SEQS` (1), `DIFFUSION_ENTROPY` (0.1),
|
|
28
|
+
`ENFORCE_EAGER` (0). Weights are 17.4 GiB.
|
|
29
|
+
- **Never re-add `--enforce-eager` casually:** it disables CUDA graphs AND
|
|
30
|
+
torch.compile and cost 2.2× throughput (387 → 841 tok/s avg, peak 1002,
|
|
31
|
+
steady-state ~644 on long runs). Set `ENFORCE_EAGER=1` only to debug
|
|
32
|
+
WSL2/Blackwell graph-capture issues. Entropy 0.1→0.2 measured ≈ no speed
|
|
33
|
+
change (745–845 tok/s) — the dial trades quality, not meaningful speed,
|
|
34
|
+
at these settings.
|
|
35
|
+
|
|
36
|
+
## Routes
|
|
37
|
+
|
|
38
|
+
| Route | What |
|
|
39
|
+
| ----- | ---- |
|
|
40
|
+
| `/` | Test harness UI (chat + compatibility tests via universal-llm-client) |
|
|
41
|
+
| `/canvas` | "Signal from Noise" — cinematic chat UI replaying the diffusion process |
|
|
42
|
+
| `/api/chat` | Chat via universal-llm-client (`messages`, `stream`, `maxTokens`, `temperature`) |
|
|
43
|
+
| `/api/stream-raw` | Direct vLLM SSE proxy preserving chunk timing (`messages` or `prompt`, `maxTokens`, `thinking:false` to disable the thought channel). Always sets `skip_special_tokens:false` so channel markers survive. |
|
|
44
|
+
| `/api/engine-config` | GET current entropy; POST `{entropy}` writes the env file + `docker restart`s the engine (~2–4 min; UI polls `/api/health`) |
|
|
45
|
+
| `/api/health` | Pings vLLM `/v1/models` |
|
|
46
|
+
|
|
47
|
+
## Native protocol (no server-side parsers!)
|
|
48
|
+
|
|
49
|
+
This vLLM build has **no reasoning parser and no tool-call parser module** —
|
|
50
|
+
request-level `tools` with auto choice 400s. Everything is client-side, against
|
|
51
|
+
the chat template's native markers (visible only with `skip_special_tokens:false`):
|
|
52
|
+
|
|
53
|
+
- Reasoning: `<|channel>thought\n …<channel|>answer`. The canvas splits this
|
|
54
|
+
with a streaming state machine (partial markers carried across chunks) and
|
|
55
|
+
renders reasoning as a collapsible amber channel above the answer surface.
|
|
56
|
+
- **Canvas reading view:** the mono token surface is the animation; when a
|
|
57
|
+
reply settles it fades into a rendered-markdown view (zero-dep renderer in
|
|
58
|
+
the inner script — headings/lists/code/bold/links, all input HTML-escaped
|
|
59
|
+
first; backticks via `String.fromCharCode(96)` because literal backticks
|
|
60
|
+
would terminate the outer template literal). Replay/scrub swaps back to the
|
|
61
|
+
token surface. Root font scales with viewport (`clamp` on `html`) for
|
|
62
|
+
screen-recording legibility. Max-tokens select goes to 16k (default 4k);
|
|
63
|
+
`finish_reason:'length'` shows an amber "⚠ capped" warning in phase+footer.
|
|
64
|
+
- Tool calls: `<|tool_call>call:name{k:<|"|>v<|"|>,n:3}<tool_call|>` — pseudo-JSON
|
|
65
|
+
args (bare keys, `<|"|>` quote token). Send `tools` + `tool_choice:'none'`
|
|
66
|
+
(declarations still get rendered into the template); history tool turns go as
|
|
67
|
+
standard structured `tool_calls` + `role:'tool'` messages (template renders
|
|
68
|
+
them natively).
|
|
69
|
+
- All of this is implemented for the library in `src/gemma-diffusion.ts` and
|
|
70
|
+
wired into the OpenAI provider (auto-detected by model name; override with
|
|
71
|
+
`LLMClientOptions.gemmaNativeProtocol`). `chatWithTools` works end-to-end.
|
|
72
|
+
Tests: `src/tests/gemma-diffusion.test.ts`. Probes: `probe-stream.ts`
|
|
73
|
+
(chunk timing), `probe-tools.ts` (tool-loop wire format).
|
|
74
|
+
|
|
75
|
+
## Things that bite
|
|
76
|
+
|
|
77
|
+
- **`canvas.ts` is one giant TS template literal.** Backslash escapes inside the
|
|
78
|
+
inner `<script>` are eaten by the outer literal (`/\S+/` silently becomes
|
|
79
|
+
`/S+/`). The inner script is written with ZERO backslashes — newlines via
|
|
80
|
+
`String.fromCharCode(10)`, tokenizing via charCode scans. Keep it that way.
|
|
81
|
+
- **No hot reload.** `CANVAS_HTML` is bundled at startup — restart the server
|
|
82
|
+
after editing `canvas.ts` (kill the bun process on :3333, start again).
|
|
83
|
+
- **Don't name a top-level browser var `history`** — `window.history` is
|
|
84
|
+
unshadowable; the conversation array is called `convo`.
|
|
85
|
+
- **Stream shape (measured):** the vLLM OpenAI stream emits ~1KB bursts, one per
|
|
86
|
+
finished 256-token diffusion block, every ~0.8–1.2s. There is no per-denoise-step
|
|
87
|
+
state in the stream; `/canvas` animates each block's reveal during the real
|
|
88
|
+
compute window of the next block. `probe-stream.ts` logs chunk timing.
|
|
89
|
+
- **The model emits stray unbalanced `<channel|>` closers** occasionally —
|
|
90
|
+
the parser strips them (`RESIDUAL_SPECIAL` in gemma-diffusion.ts), and it
|
|
91
|
+
sometimes puts the whole final answer inside the thought channel on
|
|
92
|
+
post-tool turns.
|
|
93
|
+
- **Entropy is engine-level** (`hf_overrides` read once at model init in
|
|
94
|
+
vLLM's `diffusion_gemma.py`); per-request `vllm_xargs` is accepted but
|
|
95
|
+
ignored. Hence the reload-based `/api/engine-config`.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# DiffusionGemma demo
|
|
2
|
+
|
|
3
|
+
Standalone Bun demo for testing `universal-llm-client` against DiffusionGemma
|
|
4
|
+
served by vLLM's OpenAI-compatible API.
|
|
5
|
+
|
|
6
|
+
## Run the backend
|
|
7
|
+
|
|
8
|
+
From `packages/universal-llm-client`:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
docker compose -f src/demos/diffusion-gemma/docker-compose.yml up -d
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The compose file runs a `diffusiongemma` container on `localhost:8000`, mounts a
|
|
15
|
+
demo-local Hugging Face cache at `src/demos/diffusion-gemma/.cache/huggingface`,
|
|
16
|
+
and bind-mounts `start-vllm.sh` as the container entrypoint.
|
|
17
|
+
|
|
18
|
+
If you already have an older hand-created `diffusiongemma` container, remove it
|
|
19
|
+
before switching to the demo compose file:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
docker rm -f diffusiongemma
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Optional overrides:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cp src/demos/diffusion-gemma/.env.example src/demos/diffusion-gemma/.env
|
|
29
|
+
docker compose --env-file src/demos/diffusion-gemma/.env -f src/demos/diffusion-gemma/docker-compose.yml up -d
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Useful knobs are `VLLM_IMAGE`, `GPU_MEM_UTIL`, `MAX_MODEL_LEN`,
|
|
33
|
+
`DIFFUSION_ENTROPY`, `ENFORCE_EAGER`, and `VLLM_NO_USAGE_STATS`.
|
|
34
|
+
|
|
35
|
+
## Run the demo UI
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
bun run src/demos/diffusion-gemma/server.ts
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
- Harness: <http://localhost:3333/>
|
|
42
|
+
- Canvas: <http://localhost:3333/canvas>
|
|
43
|
+
- vLLM API: <http://localhost:8000/v1/models>
|
|
44
|
+
|
|
45
|
+
## Notes
|
|
46
|
+
|
|
47
|
+
- The prior BentoKit setup did not use a `docker-compose.yml`; it was a direct
|
|
48
|
+
Docker container using a repo-root `scripts/diffusiongemma-start.sh` bind
|
|
49
|
+
mount. This demo now carries its own compose file and startup script.
|
|
50
|
+
- The default image is `vllm/vllm-openai:gemma`, the vLLM image line that
|
|
51
|
+
includes DiffusionGemma support. Set `VLLM_IMAGE` if you need to test another
|
|
52
|
+
local or registry image.
|
|
53
|
+
- The first startup can take several minutes while vLLM loads and compiles the
|
|
54
|
+
model. Poll `docker logs -f diffusiongemma` or `/api/health` from the demo UI.
|
|
55
|
+
- The `/api/engine-config` endpoint writes `diffusion-env.sh` into the mounted
|
|
56
|
+
Hugging Face cache and restarts the `diffusiongemma` container.
|
|
57
|
+
- `VLLM_NO_USAGE_STATS=1` is enabled by default because this vLLM image can hit
|
|
58
|
+
a non-fatal `py-cpuinfo` `JSONDecodeError` in its background usage-reporting
|
|
59
|
+
thread under WSL during startup/reload.
|