ShtukbaseStandard
package file→ .shtukbase/packages/llm-provider/README.md

README.md

27 lines, 1.4 KB.

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