package file→ .shtukbase/packages/llm-provider/README.md
README.md
27 lines, 1.4 KB.
- # llm-provider
- Settings for an OpenAI-compatible model provider (`baseUrl`, `model`, `apiKey`, see
- `package.md`) and `llm.js`, a dependency-free streaming client:
- ```js
- const msg = await shtukLLM.chat(shtukLLM.loadSettings(), messages, tools, (d) => {/* d.text | d.toolCall */}, abortSignal);
- // msg = { role: 'assistant', content, tool_calls? }
- ```
- `tools` are MCP-style (`{name, description, inputSchema}`, as `space.tools` returns them);
- the client turns them into OpenAI function tools and assembles streamed `tool_calls`.
- ## Prototype limits — the key lives in the browser
- For the prototype the key is kept in `localStorage` (key `shtuk-llm`) and the browser calls
- `<baseUrl>/chat/completions` directly. That is fine for one owner on his own machine, but:
- - any script on the same origin can read the key (lenses run in opaque-origin frames, so
- storage there is per-frame and may be blocked; the chat lens falls back to memory);
- - the key cannot be shared with other members of a space without handing it out;
- - there is no spend limit or audit on our side.
- **Next step:** a server-side proxy. The host (`shtuk serve` / the cloud Worker) keeps the key
- as a secret (Worker secret `LLM_API_KEY`), exposes `POST /_llm/chat/completions` behind the
- space session, forwards to the provider and streams back. `llm.js` then only needs
- `baseUrl: '/_llm'` and no key; settings in `package.md` become host settings.