|
|
3 bulan lalu | |
|---|---|---|
| .. | ||
| src | 3 bulan lalu | |
| tests | 3 bulan lalu | |
| README.md | 3 bulan lalu | |
| package.json | 3 bulan lalu | |
| tsconfig.json | 3 bulan lalu | |
Provider-neutral LLM vocabulary and abstract service. This package defines the canonical language spoken by the agent loop, session logs, and every plugin.
LlmService (ctx key: llm)An adapter registry plus streaming / non-streaming call surfaces. Both call surfaces are interceptable via waterfall events.
ctx.llm.registerAdapter(models: string[], adapter: LlmAdapter): () => void
Register an adapter for the given model names. Disposed with the calling fiber.ctx.llm.models(): string[] — model names with a registered adapter.ctx.llm.stream(options: GenerateOptions): AsyncIterable<StreamChunk>
Stream one model call as raw chunks (token-level deltas).ctx.llm.streamBlocks(options: GenerateOptions): AsyncIterable<ContentBlock>
Stream as completed content blocks (convenience view).ctx.llm.generate(options: GenerateOptions): Promise<GenerateResult>
One model call, fully assembled.| Event | Mode | Purpose |
|---|---|---|
llm/stream |
waterfall | Intercept/wrap every streaming model call (retry, caching, routing) |
llm/generate |
waterfall | Intercept/wrap every non-streaming model call |
llm/adapter-change |
emit | An adapter was registered or unregistered |
LlmAdapter and call ctx.llm.registerAdapter(models, adapter)
to add a new model provider.llm/stream or llm/generate via ctx.on() waterfall listeners for
caching, retry, logging, rate-limiting, etc.types.ts)Messages are arrays of typed content blocks: text, reasoning, tool-call,
tool-result, image. The union is derived from the merge-extensible
ContentBlockMap, so plugins can add block types via declaration merging.
Streaming is a raw chunk protocol (block-start, text-delta,
reasoning-delta, tool-call-delta, block-end, usage, finish).
BlockAssembler is the single shared implementation that assembles chunks into
blocks/messages.
LlmAdapter — abstract base class for provider adapters. The only required
method is stream().BlockAssembler — incrementally assembles raw chunks into complete content
blocks and an assistant message. Used by the agent loop (raw chunks for replay
streamBlocks()/generate().LlmError — typed error with a code string (NO_ADAPTER,
DUPLICATE_ADAPTER).TODO(review) markers
and needs careful review before the first real adapter (DeepSeek V4 wire
format, partial JSON arguments, interleaved reasoning signatures, ...).