@plurnk/plurnk-providers 0.5.0 → 0.5.1

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.
Files changed (2) hide show
  1. package/README.md +40 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -5,15 +5,52 @@ Framework + contract for `@plurnk/plurnk-providers-*` sibling packages (LLM tran
5
5
  ## Documentation
6
6
 
7
7
  - [`SPEC.md`](./SPEC.md) — author-facing contract for sibling implementers.
8
- - Constellation: [plurnk-grammar](https://github.com/plurnk/plurnk-grammar) (HEREDOC + AST), [plurnk-mimetypes](https://github.com/plurnk/plurnk-mimetypes), [plurnk-schemes](https://github.com/plurnk/plurnk-schemes), [plurnk-execs](https://github.com/plurnk/plurnk-execs).
8
+ - Constellation: [plurnk-grammar](https://github.com/plurnk/plurnk-grammar) (HEREDOC + AST), [plurnk-mimetypes](https://github.com/plurnk/plurnk-mimetypes), [plurnk-schemes](https://github.com/plurnk/plurnk-schemes), [plurnk-execs](https://github.com/plurnk/plurnk-execs) (the reference family this one mirrors).
9
+
10
+ ## Write a provider
11
+
12
+ Ship a provider by publishing a package — **under any scope** (`@acme/whatever`; discovery keys on `plurnk.kind`, not the `@plurnk` scope) — that declares its name and default-exports a `fromEnv` factory. (A plain OpenAI-compatible endpoint with no probe or wire quirk needs *no* package at all for first-party use — it's a frozen `STANDARD_PROVIDERS` entry; the package path is for bespoke providers and any third party.)
13
+
14
+ ### 1. Declare the name in `package.json`
15
+
16
+ ```json
17
+ {
18
+ "plurnk": { "kind": "provider", "name": "acme" }
19
+ }
20
+ ```
21
+
22
+ One package is **one** provider identity — the `<name>` segment of `PLURNK_MODEL_<alias>=<name>/<model>`. (Unlike execs' `runtimes[]` array; a provider is singular.)
23
+
24
+ ### 2. Default-export a `fromEnv` factory
25
+
26
+ The framework calls `YourClass.fromEnv(env, model)` (sync or async) and expects a `Provider`. Two ways in:
27
+
28
+ - **OpenAI-compatible backends** (the common case): `fromEnv` reads its env (base URL, key), probes whatever it needs (catalog, context window, pricing), and returns **`new OpenAICompatProvider(config)`**. You write a `fromEnv` and a config object — the transport spine (SSE, usage normalization, `finishReason`, grammar transport, slot affinity) is inherited. See `OpenAICompatConfig` / SPEC §11.
29
+ - **Non-OpenAI backends**: `implements Provider` directly — `generate`, `contextSize`, `model`, `countTokens(text)`, `costFor(usage)`.
30
+
31
+ `fromEnv` **MUST fail fast with a named error** when required env is missing — name the var the operator must set. (Why a factory, not a base-class constructor like execs/mimes: a provider often async-probes at construction — SPEC §3.)
32
+
33
+ ### 3. What `generate` receives — and returns
34
+
35
+ `generate({ messages, runId, signal?, grammar?, maxTokens? }) → Promise<ProviderResponse>`. Return **raw** wire output: `content` unparsed (the consumer parses the plurnk DSL — never parse it yourself), `reasoning` is the wire-reported CoT only. Honor `signal`. The provider never mutates `messages` or injects turns. `grammar` (GBNF) is attached only by backends that support it; all others ignore it (SPEC §13).
36
+
37
+ ## Discovery & trust
38
+
39
+ `discover(options?)` scans **every installed package** under `<cwd>/node_modules` — scope-agnostic — for `plurnk.kind === "provider"`, returning `{ registry, skipped }` (name → package specifier).
40
+
41
+ - **Name collisions are fail-hard.** Two packages claiming the same provider name throw at discovery, naming both.
42
+ - **The standard table wins.** A scanned package whose name duplicates a built-in standard provider (`openai`, `groq`, …) is shadowed — tier 1 resolves first.
43
+ - **Trust gate.** `discover()` honors **`PLURNK_PLUGINS_TRUSTED_ONLY`** (host posture, plurnk-service#229): unset/`""`/`0` → every package registers (default, no regression); any value → `@plurnk/*` always trusted plus a comma-separated allowlist (`1` = first-party only). An untrusted package is discovered but **not** registered (returned in `Discovery.skipped`), so requesting its name yields a precise *untrusted* error — never a crash.
44
+
45
+ First-party daughters install flat via [`@plurnk/plurnk-providers-all`](https://github.com/plurnk/plurnk-providers-all) so the scan finds them; a third party publishes under their own scope and installs alongside.
9
46
 
10
47
  ## Exports
11
48
 
12
- - `Provider`, `ChatMessage`, `ProviderResponse`, `ProviderAssistant`, `ProviderUsage`, `FinishReason`, `ProviderFactory` — types.
49
+ - `Provider`, `ChatMessage`, `ProviderResponse`, `ProviderAssistant`, `ProviderUsage`, `FinishReason`, `ProviderFactory` (+ `Discovery`, `DiscoverOptions`) — types.
13
50
  - `parseAliasesFromEnv`, `resolveActiveAlias`, `instantiateProvider`, `loadActiveProvider`, `discover` — alias-cascade resolution + two-tier provider instantiation. Tier 1 is the standard table; tier 2 is a scope-agnostic `node_modules` scan for `plurnk.kind:"provider"` packages — first-party daughters (flat via `@plurnk/plurnk-providers-all`) and third-party providers under any scope, gated by the host `PLURNK_PLUGINS_TRUSTED_ONLY` allowlist. The framework is contract-only (SPEC §5).
14
51
  - `OpenAICompatProvider` (+ `OpenAICompatConfig`, `ReasoningStyle`, `effortFromBudget`) — shared OpenAI-compatible transport spine; siblings extend it (SPEC §11). Transports GBNF grammar-constrained sampling for capable backends (SPEC §13).
15
52
  - `chatCompletionStream`, `OpenAiHttpError`, `StreamResponse` — the shared SSE client.
16
- - `parseRequiredInt`, `parseOptionalInt`, `requireEnv`, `reasoningBudgetFromEnv`, `planFromEnv` — env helpers (SPEC §4; all required-with-named-errors, no in-code defaults).
53
+ - `parseRequiredInt`, `parseOptionalInt`, `requireEnv`, `reasoningBudgetFromEnv` — env helpers (SPEC §4; all required-with-named-errors, no in-code defaults).
17
54
  - `normalizeUsage`, `computeCost` (+ `RawUsage`, `TokenRates`) — usage normalization to the §2 invariant and the single cost formula (SPEC §11).
18
55
  - `ProviderError`, `classifyProviderError`, `toProviderError`, `providerSource` (+ `TelemetryEvent`, `ProviderTelemetryKind`) — the TelemetryEvent envelope for transport failures (SPEC §12).
19
56
  - `tokenizerFor`, `tokenizerByPublisher`, `parseTokenizerFamily` (+ `TokenizerFamily`, `CountTokens`) — synchronous tokenizer strategies.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plurnk/plurnk-providers",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Framework + contract for the @plurnk/plurnk-providers-* LLM transport family.",
5
5
  "keywords": [
6
6
  "plurnk",