diff --git a/README.md b/README.md index 790fab4..c8fa527 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ subscription and makes its requests. The packages work in OpenCode and in | [qoder](packages/qoder) | Qoder subscription (qoder.com), with Qoder's device sign-in | `qoder` | | [qoder](packages/qoder) | Qoder CN subscription (qoder.cn), with Qoder CN's device sign-in | `qoder-cn` | | [raccoon](packages/raccoon) | SenseTime Raccoon (商汤小浣熊, xiaohuanxiong.com): account credits and daily check-in, with browser sign-in or Raccoon desktop's sign-in | `raccoon` | +| [river](packages/river) | River (river.ai) pay-as-you-go inference, with your API key: per-account models, documented reasoning efforts and live prices | `river` | | [trae](packages/trae) | Trae CN (trae.cn) and Trae international (trae.ai), free tier included, with Trae's browser sign-in (experimental) | `trae-cn`, `trae-global` | | [workbuddy](packages/workbuddy) | WorkBuddy (China build, CodeBuddy plan) | `workbuddy` | | [workbuddy](packages/workbuddy) | WorkBuddy (international build) | `workbuddy-ai` | diff --git a/packages/river/LICENSE b/packages/river/LICENSE new file mode 100644 index 0000000..ae53f14 --- /dev/null +++ b/packages/river/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 real-jacket + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/river/README.md b/packages/river/README.md new file mode 100644 index 0000000..c3ef2e9 --- /dev/null +++ b/packages/river/README.md @@ -0,0 +1,62 @@ +# river + +River ([river.ai](https://river.ai)) with your API key, in +[OpenCode](https://opencode.ai) and [magpie](https://usemagpie.ai). River serves an +OpenAI-compatible inference API at `https://api.river.ai/v1`; this plugin signs every +request with your key, so agents reach its models like any other provider — +multi-account, fallback, quotas and all. + +**Provider id:** `river` + +## Sign-in + +A River API key, created on the [API Keys](https://console.river.ai/keys) page of the +River Console (`rv_…`). The key is stored as `{ "type": "api", "key": "rv_…" }` in +OpenCode's `auth.json` and magpie's `plugin-auth.json` (permissions 600); a key River +refuses marks the account for sign-in again. + +## Models + +The models your key can use, listed per account from `GET /v1/models`. Context and +output limits come from [River's docs](https://docs.river.ai/guides/inference-models/), +prices from [River's public pricing endpoint](https://console.river.ai/api/public/pricing) +(the same rates billing uses), and the documented reasoning efforts +(`reasoning_effort`) from [API controls](https://docs.river.ai/guides/inference-controls/): + +| Model | Efforts | +| --- | --- | +| DeepSeek-V4.1-Flash(-1017) | `none` / `low` / `high` / `max` | +| Kimi-K3 | `none` / `max` | +| Nemotron-3.5-Super-VL | `none` / `high` | +| GLM-5.3-Flash | `low` / `high` / `max` (reasoning required) | +| Qwen3.8-27B-FP8 | `none` / `low` / `medium` / `xhigh` | + +Every inference model streams, reasons and calls tools. Image input is limited to +the models the docs list for it (Kimi-K3, DeepSeek ×2, Nemotron, GLM-5.3-Flash, +Qwen3.8-27B-FP8); GLM-5.3 is text-only, and a model the docs don't list yet +defaults to text-only rather than being assumed to see images. + +## Usage + +River meters a prepaid balance per request and publishes no endpoint that reads it, +so the usage card shows the sign-in state and "Pay as you go" rather than invented +numbers; spend and balance live in the [River Console](https://console.river.ai/). + +## Install + +```sh +magpie plugin add @magpie-community/opencode-river-auth +magpie plugin login river +magpie provider test river +``` + +In OpenCode, add the same package under `plugin` and sign in with `opencode auth login`. + +## Development + +```sh +bun test +bun scripts/check.mjs river +``` + +MIT. Not affiliated with River. diff --git a/packages/river/index.mjs b/packages/river/index.mjs new file mode 100644 index 0000000..1e5fdf9 --- /dev/null +++ b/packages/river/index.mjs @@ -0,0 +1,238 @@ +// River (river.ai) for OpenCode and magpie. +// +// River serves an OpenAI-compatible inference API at https://api.river.ai/v1: +// an API key signs every request (Authorization: Bearer), chat completions and +// the Responses API serve the same models, and GET /v1/models lists the models +// a key can use (docs.river.ai/guides/inference). River meters a prepaid +// balance per request and publishes no balance endpoint, so the usage hook +// here reports only the sign-in state; spend lives in the River Console. + +const ID = "river" +const BASE = "https://api.river.ai/v1" +const PRICING = "https://console.river.ai/api/public/pricing" +const PRICING_TTL = 6 * 60 * 60 * 1000 + +// Documented per-model limits, from docs.river.ai/guides/inference-models. +// Models River serves beyond this table keep unknown limits (0) until the +// docs list them; costs still come from River's public pricing endpoint. +// GLM-5.3 (text only) has no id here yet: docs list it, no key we saw does. +const LIMITS = { + "moonshotai/Kimi-K3": { context: 1048576, output: 32768 }, + "deepseek-ai/DeepSeek-V4.1-Flash": { context: 1048576, output: 384000 }, + "deepseek-ai/DeepSeek-V4.1-Flash-1017": { context: 1048576, output: 384000 }, + "nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4": { context: 1048576, output: 131072 }, + "zai-org/GLM-5.3-Flash": { context: 1048576, output: 131072 }, + "Qwen/Qwen3.8-27B-FP8": { context: 262144, output: 262143 }, +} + +// Models River documents as taking image input (docs.river.ai/guides/ +// inference-models). Everything else is text-only — GLM-5.3 (text only) is +// documented as such — and an id the docs don't list yet defaults to +// text-only too, so a new model is never sent what it can't read. +const IMAGES = new Set([ + "moonshotai/Kimi-K3", + "deepseek-ai/DeepSeek-V4.1-Flash", + "deepseek-ai/DeepSeek-V4.1-Flash-1017", + "nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4", + "zai-org/GLM-5.3-Flash", + "Qwen/Qwen3.8-27B-FP8", +]) + +// Reasoning effort levels per model, from docs.river.ai/guides/inference-controls. +// The keys are the levels agents pick; each variant's object is the options +// OpenCode merges into the request ({ reasoningEffort: e }), which magpie's +// gateway sends as `reasoning_effort`. Only levels the standard field takes +// are listed: Kimi-K3's low/high/max tiers and Nemotron's medium_effort go +// through chat_template_kwargs instead. GLM requires reasoning (no "none"); +// Qwen3.8's top level is "xhigh". The 1017 release is the same model +// re-served, so it takes the same efforts. +const efforts = (...names) => Object.fromEntries(names.map((e) => [e, { reasoningEffort: e }])) +const VARIANTS = { + "moonshotai/Kimi-K3": efforts("none", "max"), + "deepseek-ai/DeepSeek-V4.1-Flash": efforts("none", "low", "high", "max"), + "deepseek-ai/DeepSeek-V4.1-Flash-1017": efforts("none", "low", "high", "max"), + "nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4": efforts("none", "high"), + "zai-org/GLM-5.3-Flash": efforts("low", "high", "max"), + "Qwen/Qwen3.8-27B-FP8": efforts("none", "low", "medium", "xhigh"), +} + +// Costs at the time of writing, per million tokens in USD, from River's +// public pricing endpoint (the same rates billing uses). The models hook +// replaces them with whatever the endpoint lists then. +const BOOT_PRICES = { + "Qwen/Qwen3.8-27B-FP8": { input: 0.1, cached_input: 0.02, output: 2.0 }, + "deepseek-ai/DeepSeek-V4.1-Flash": { input: 0.12, cached_input: 0.0024, output: 0.48 }, + "deepseek-ai/DeepSeek-V4.1-Flash-1017": { input: 0.12, cached_input: 0.0024, output: 0.48 }, + "moonshotai/Kimi-K3": { input: 3.0, cached_input: 0.3, output: 15.0 }, + "nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4": { input: 0.07, cached_input: 0.024, output: 0.37 }, + "zai-org/GLM-5.3-Flash": { input: 0.12, cached_input: 0.024, output: 0.4 }, +} + +// Every model in River's inference list streams, reasons and calls tools; +// image input is the IMAGES set's, everything else is text-only (docs.river.ai/ +// guides/inference-models). The row carries the fields both readers use: the +// config hook reads the top-level ones, the models hook reads the +// `capabilities` object. +function row(id, name, cost, limit, variants) { + const image = IMAGES.has(id) + return { + id, + name, + limit: limit ?? { context: 0, output: 0 }, + reasoning: true, + tool_call: true, + modalities: { input: image ? ["text", "image"] : ["text"], output: ["text"] }, + capabilities: { + reasoning: true, + toolcall: true, + attachment: image, + input: { text: true, image }, + output: { text: true }, + }, + ...(variants ? { variants } : {}), + ...(cost ? { cost } : {}), + } +} + +// pretty turns an API id into a display name: the part after the org slash, +// with separators spaced ("deepseek-ai/DeepSeek-V4.1-Flash" → "DeepSeek V4.1 Flash"). +function pretty(id) { + return id.split("/").pop().replace(/[-_]+/g, " ").trim() +} + +// costOf reads one entry of River's pricing list. Entries carry the rates +// per million tokens as numbers; anything else leaves the cost off. +function costOf(price) { + if (!price || typeof price !== "object") return undefined + const [input, output, cache_read] = [price.input, price.output, price.cached_input].map((v) => (typeof v === "number" ? v : undefined)) + if (input === undefined && output === undefined) return undefined + return { ...(input !== undefined && { input }), ...(output !== undefined && { output }), ...(cache_read !== undefined && { cache_read }) } +} + +// accountModels lists the model ids a key can use. River answers +// {"object":"list","data":[{"id":…}]} like every OpenAI-compatible server. +async function accountModels(fetchImpl, key) { + return await fetchImpl(`${BASE}/models`, { + headers: { authorization: `Bearer ${key}`, accept: "application/json" }, + signal: AbortSignal.timeout(15000), + redirect: "error", + }) +} + +// livePricing reads River's public pricing list, which needs no key. The +// answer is cached for PRICING_TTL; a failure just keeps the previous one. +let pricingCache = { at: 0, byId: null } +async function livePricing(fetchImpl) { + if (pricingCache.byId && Date.now() - pricingCache.at < PRICING_TTL) return pricingCache.byId + try { + const res = await fetchImpl(PRICING, { + headers: { accept: "application/json" }, + signal: AbortSignal.timeout(15000), + redirect: "error", + }) + if (!res.ok) throw new Error(`HTTP ${res.status}`) + const body = await res.json() + const byId = {} + for (const entry of body?.inference ?? []) { + if (typeof entry?.model === "string" && entry.model) byId[entry.model] = entry + } + if (Object.keys(byId).length) pricingCache = { at: Date.now(), byId } + } catch { + // keep whatever the cache holds, else the caller falls back to BOOT_PRICES + } + return pricingCache.byId +} + +// merged rows for the model ids an account may use: limits from the docs +// table, costs from River's live pricing (BOOT_PRICES as the fallback) +function rowsFor(ids, prices) { + return Object.fromEntries( + ids.map((id) => { + const price = prices?.[id] + const cost = costOf(price) ?? costOf(BOOT_PRICES[id]) + return [id, row(id, pretty(id), cost, LIMITS[id], VARIANTS[id])] + }), + ) +} + +function createPlugin({ fetchImpl = globalThis.fetch } = {}) { + return { + config: async (cfg) => { + cfg.provider ??= {} + // `??=` keeps a provider the user configured in plugins.json. + cfg.provider[ID] ??= { + name: "River", + npm: "@ai-sdk/openai-compatible", // chat completions + api: BASE, + models: rowsFor(Object.keys(BOOT_PRICES), BOOT_PRICES), + } + }, + + auth: { + provider: ID, + methods: [{ type: "api", label: "River API key", placeholder: "rv_…" }], + // magpie sends `Authorization: Bearer ` for + // @ai-sdk/openai-compatible; no custom fetch is needed, and the host + // applies the account's proxy to every request. + async loader(getAuth) { + const auth = await getAuth() + if (auth?.type !== "api" || !auth.key) return {} + return { baseURL: BASE, apiKey: auth.key } + }, + // River meters a prepaid balance per request and publishes no endpoint + // that reads it, so this only checks the sign-in and says where spend + // is visible. A key River refuses marks the account (signIn: "expired"). + async usage(getAuth) { + const auth = await getAuth() + if (auth?.type !== "api" || !auth.key) return {} + let res + try { + res = await accountModels(fetchImpl, auth.key) + } catch (error) { + return { error: `River unreachable: ${error?.cause?.code || error?.message || "network error"}`, windows: [] } + } + if (res.status === 401 || res.status === 403) { + return { error: `River refused this key (HTTP ${res.status}); sign in again`, signIn: "expired", windows: [] } + } + if (!res.ok) return { error: `River answered HTTP ${res.status}`, windows: [] } + return { plan: "Pay as you go", windows: [] } + }, + }, + + provider: { + id: ID, + async models(provider, { auth } = {}) { + if (auth?.type !== "api" || !auth.key) return provider.models + let res, prices + try { + ;[res, prices] = await Promise.all([accountModels(fetchImpl, auth.key), livePricing(fetchImpl)]) + } catch { + // A network failure keeps the previous list, like a non-2xx answer. + return provider.models + } + if (res.status === 401 || res.status === 403) { + throw Object.assign(new Error(`River refused this key (HTTP ${res.status}); sign in again`), { signIn: "expired" }) + } + if (!res.ok) return provider.models + let body + try { + body = await res.json() + } catch { + throw new Error("River sent no model list") + } + // A malformed answer keeps the previous list (the host marks it a + // fallback); an empty one is the account's list, as its key has no + // models, and replaces the bootstrap rows the way a live catalog does. + if (!Array.isArray(body?.data) || body.data.some((m) => typeof m?.id !== "string" || !m.id)) { + throw new Error("River sent no model list") + } + return rowsFor(body.data.map((m) => m.id), prices) + }, + }, + } +} + +// The plugin is the only exported function; magpie calls every exported +// function as a plugin, so tests reach the internals through this object. +export const RiverPlugin = async () => createPlugin() +export const _internal = { createPlugin, row, pretty, costOf, rowsFor, LIMITS, VARIANTS, BOOT_PRICES, BASE } diff --git a/packages/river/index.test.mjs b/packages/river/index.test.mjs new file mode 100644 index 0000000..da4b265 --- /dev/null +++ b/packages/river/index.test.mjs @@ -0,0 +1,241 @@ +import { describe, expect, test } from "bun:test" +import { RiverPlugin, _internal } from "./index.mjs" + +const { createPlugin, row, pretty, costOf, rowsFor, LIMITS, VARIANTS, BOOT_PRICES, BASE } = _internal + +function jsonRes(status, body) { + return new Response(body === undefined ? null : JSON.stringify(body), { + status, + headers: { "content-type": "application/json" }, + }) +} + +function fakeFetch(calls) { + return async (input, init) => { + calls.push({ input: String(input), init }) + return calls.handler(calls.length - 1, input, init) + } +} + +const auth = { type: "api", key: "rv_test" } + +describe("config", () => { + test("declares the river provider with bootstrap models and keeps a configured one", async () => { + const plugin = await createPlugin() + const cfg = { provider: { river: { name: "Mine" } } } + await plugin.config(cfg) + expect(cfg.provider.river.name).toBe("Mine") + const fresh = {} + await plugin.config(fresh) + const p = fresh.provider.river + expect(p.name).toBe("River") + expect(p.npm).toBe("@ai-sdk/openai-compatible") + expect(p.api).toBe(BASE) + expect(Object.keys(p.models)).toEqual(Object.keys(BOOT_PRICES)) + expect(p.models["deepseek-ai/DeepSeek-V4.1-Flash"].limit).toEqual(LIMITS["deepseek-ai/DeepSeek-V4.1-Flash"]) + expect(p.models["zai-org/GLM-5.3-Flash"].cost.input).toBe(0.12) + }) +}) + +describe("loader", () => { + test("maps an api account to the base URL and key", async () => { + const plugin = await createPlugin() + const loaded = await plugin.auth.loader(async () => auth) + expect(loaded).toEqual({ baseURL: BASE, apiKey: "rv_test" }) + }) + test("loads nothing without an account", async () => { + const plugin = await createPlugin() + expect(await plugin.auth.loader(async () => undefined)).toEqual({}) + expect(await plugin.auth.loader(async () => ({ type: "oauth" }))).toEqual({}) + }) + test("offers an api key sign-in", async () => { + const plugin = await createPlugin() + expect(plugin.auth.provider).toBe("river") + expect(plugin.auth.methods).toEqual([{ type: "api", label: "River API key", placeholder: "rv_…" }]) + }) +}) + +describe("provider.models", () => { + test("merges the account's models with docs limits and live prices, caching the pricing list", async () => { + const calls = [] + calls.handler = (_i, input) => + String(input).includes("/models") + ? jsonRes(200, { object: "list", data: [{ id: "zai-org/GLM-5.3-Flash" }, { id: "moonshotai/Kimi-K3" }] }) + : jsonRes(200, { inference: [{ model: "moonshotai/Kimi-K3", input: 3.0, cached_input: 0.3, output: 15.0 }] }) + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + const models = await plugin.provider.models({ models: {} }, { auth }) + expect(Object.keys(models)).toEqual(["zai-org/GLM-5.3-Flash", "moonshotai/Kimi-K3"]) + expect(models["zai-org/GLM-5.3-Flash"].limit).toEqual(LIMITS["zai-org/GLM-5.3-Flash"]) + expect(models["zai-org/GLM-5.3-Flash"].cost).toEqual({ input: 0.12, output: 0.4, cache_read: 0.024 }) + expect(models["moonshotai/Kimi-K3"].reasoning).toBe(true) + expect(models["moonshotai/Kimi-K3"].modalities.input).toEqual(["text", "image"]) + expect(calls[0].init.headers.authorization).toBe("Bearer rv_test") + // the pricing answer is cached: the second call still asks /v1/models + // but no longer asks the pricing endpoint + const before = calls.length + await plugin.provider.models({ models: {} }, { auth }) + expect(calls.length - before).toBe(1) + expect(calls[before].input).toContain("/models") + }) + test("a healthy empty list is the account's list and replaces the bootstrap", async () => { + const calls = [] + calls.handler = () => jsonRes(200, { object: "list", data: [] }) + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + expect(await plugin.provider.models({ models: { "zai-org/GLM-5.3-Flash": { name: "kept" } } }, { auth })).toEqual({}) + }) + test("keeps the previous list when River errs or the network fails, without marking the sign-in", async () => { + for (const answer of [jsonRes(500, "boom"), jsonRes(502, "")]) { + const calls = [] + calls.handler = () => answer + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + const kept = { models: { "zai-org/GLM-5.3-Flash": { name: "kept" } } } + expect(await plugin.provider.models(kept, { auth })).toBe(kept.models) + } + const plugin = createPlugin({ + fetchImpl: async () => { + throw new Error("offline") + }, + }) + const kept = { models: { "zai-org/GLM-5.3-Flash": { name: "kept" } } } + expect(await plugin.provider.models(kept, { auth })).toBe(kept.models) + }) + test("throws on a malformed answer, so the host keeps the previous list as a fallback", async () => { + for (const answer of [jsonRes(200, ""), jsonRes(200, { data: "x" }), jsonRes(200, { data: [{ id: 42 }] })]) { + const calls = [] + calls.handler = () => answer + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + await expect(plugin.provider.models({ models: {} }, { auth })).rejects.toThrow("River sent no model list") + } + }) + test("marks the account expired when River refuses the key", async () => { + for (const status of [401, 403]) { + const calls = [] + calls.handler = () => jsonRes(status, { error: { message: "bad key" } }) + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + expect(plugin.provider.models({ models: {} }, { auth })).rejects.toMatchObject({ signIn: "expired" }) + } + }) + test("lists nothing per-account without an account", async () => { + const plugin = await createPlugin() + const kept = { models: { x: { name: "x" } } } + expect(await plugin.provider.models(kept, {})).toBe(kept.models) + }) +}) + +describe("auth.usage", () => { + test("reports the pay-as-you-go plan on a healthy key", async () => { + const calls = [] + calls.handler = () => jsonRes(200, { data: [{ id: "zai-org/GLM-5.3-Flash" }] }) + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + expect(await plugin.auth.usage(async () => auth)).toMatchObject({ plan: "Pay as you go" }) + }) + test("marks a refused key as expired", async () => { + const calls = [] + calls.handler = () => jsonRes(401, {}) + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + expect(await plugin.auth.usage(async () => auth)).toMatchObject({ signIn: "expired" }) + }) + test("reports other statuses and network failures as errors", async () => { + const calls = [] + calls.handler = () => jsonRes(503, {}) + const plugin = createPlugin({ fetchImpl: fakeFetch(calls) }) + expect(await plugin.auth.usage(async () => auth).error).toBeUndefined() + const down = createPlugin({ + fetchImpl: async () => { + throw new Error("offline") + }, + }) + const card = await down.auth.usage(async () => auth) + expect(card.error).toContain("offline") + expect(card.signIn).toBeUndefined() + }) + test("says nothing without an account", async () => { + const plugin = await createPlugin() + expect(await plugin.auth.usage(async () => undefined)).toEqual({}) + }) +}) + +describe("helpers", () => { + test("pretty names an id", () => { + expect(pretty("deepseek-ai/DeepSeek-V4.1-Flash-1017")).toBe("DeepSeek V4.1 Flash 1017") + expect(pretty("Qwen/Qwen3.8-27B-FP8")).toBe("Qwen3.8 27B FP8") + expect(pretty("plain")).toBe("plain") + }) + test("costOf keeps numbers only", () => { + expect(costOf({ input: 1, output: 2, cached_input: 0.5 })).toEqual({ input: 1, output: 2, cache_read: 0.5 }) + expect(costOf({})).toBeUndefined() + expect(costOf(null)).toBeUndefined() + }) + test("rows carry image input, tools and reasoning in both shapes for a documented image model", () => { + const r = row("moonshotai/Kimi-K3", "Kimi K3", undefined, undefined) + expect(r.limit).toEqual({ context: 0, output: 0 }) + expect(r.modalities.input).toEqual(["text", "image"]) + expect(r.reasoning && r.tool_call).toBe(true) + expect(r.capabilities).toEqual({ + reasoning: true, + toolcall: true, + attachment: true, + input: { text: true, image: true }, + output: { text: true }, + }) + }) + test("a text-only model takes no images and no attachments", () => { + const r = row("zai-org/GLM-5.3", "GLM 5.3", undefined, undefined) + expect(r.modalities.input).toEqual(["text"]) + expect(r.capabilities.attachment).toBe(false) + expect(r.capabilities.input).toEqual({ text: true, image: false }) + }) + test("rowsFor keeps an id the docs don't list text-only rather than assuming it sees images", () => { + const rows = rowsFor(["moonshotai/Kimi-K3", "river/new-model"], null) + expect(rows["moonshotai/Kimi-K3"].capabilities.input.image).toBe(true) + expect(rows["river/new-model"].capabilities.input.image).toBe(false) + expect(rows["river/new-model"].modalities.input).toEqual(["text"]) + }) + test("image capability matches the docs per model — only the listed ids take images", () => { + const documented = { + "moonshotai/Kimi-K3": true, + "deepseek-ai/DeepSeek-V4.1-Flash": true, + "deepseek-ai/DeepSeek-V4.1-Flash-1017": true, + "nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A12B-NVFP4": true, + "zai-org/GLM-5.3-Flash": true, + "Qwen/Qwen3.8-27B-FP8": true, + "zai-org/GLM-5.3": false, // docs: GLM-5.3 (text only) + } + for (const [id, image] of Object.entries(documented)) { + const r = rowsFor([id], null)[id] + expect(r.capabilities.input.image).toBe(image) + expect(r.modalities.input.includes("image")).toBe(image) + } + }) + test("rowsFor falls back to boot prices without a live list", () => { + const rows = rowsFor(["zai-org/GLM-5.3-Flash"], null) + expect(rows["zai-org/GLM-5.3-Flash"].cost).toEqual(costOf(BOOT_PRICES["zai-org/GLM-5.3-Flash"])) + }) + test("rows carry the documented reasoning efforts", () => { + const rows = rowsFor(["deepseek-ai/DeepSeek-V4.1-Flash", "moonshotai/Kimi-K3", "Qwen/Qwen3.8-27B-FP8"], null) + expect(Object.keys(rows["deepseek-ai/DeepSeek-V4.1-Flash"].variants)).toEqual(["none", "low", "high", "max"]) + expect(Object.keys(rows["moonshotai/Kimi-K3"].variants)).toEqual(["none", "max"]) + expect(Object.keys(rows["Qwen/Qwen3.8-27B-FP8"].variants)).toEqual(["none", "low", "medium", "xhigh"]) + expect(Object.keys(VARIANTS)).toHaveLength(6) + }) + test("each variant's options carry its reasoningEffort — what OpenCode merges into the request", () => { + for (const variants of Object.values(VARIANTS)) { + for (const [effort, options] of Object.entries(variants)) { + expect(options).toEqual({ reasoningEffort: effort }) + } + } + }) + test("documented limits ride the rows", () => { + const rows = rowsFor(["moonshotai/Kimi-K3", "zai-org/GLM-5.3-Flash"], null) + expect(rows["moonshotai/Kimi-K3"].limit).toEqual({ context: 1048576, output: 32768 }) + expect(rows["zai-org/GLM-5.3-Flash"].limit).toEqual({ context: 1048576, output: 131072 }) + }) +}) + +test("the package exports one plugin function", async () => { + expect(typeof RiverPlugin).toBe("function") + const hooks = await RiverPlugin() + expect(typeof hooks.config).toBe("function") + expect(hooks.auth.provider).toBe("river") + expect(hooks.provider.id).toBe("river") +}) diff --git a/packages/river/package.json b/packages/river/package.json new file mode 100644 index 0000000..2c3ad5a --- /dev/null +++ b/packages/river/package.json @@ -0,0 +1,30 @@ +{ + "name": "@magpie-community/opencode-river-auth", + "version": "0.1.0", + "description": "River (api.river.ai) with your API key in OpenCode and magpie: chat completions, streaming, tools and images", + "type": "module", + "main": "./index.mjs", + "files": [ + "index.mjs", + "README.md", + "LICENSE" + ], + "keywords": [ + "opencode", + "opencode-plugin", + "magpie", + "river" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/magpie-community/plugins", + "directory": "packages/river" + }, + "scripts": { + "test": "bun test" + }, + "magpie": { + "icon": "https://river.ai/favicon.ico" + } +} diff --git a/registry.json b/registry.json index 0c269f6..9bc568c 100644 --- a/registry.json +++ b/registry.json @@ -89,6 +89,8 @@ { "package": "@magpie-community/opencode-cloudflare-workers-ai-auth", "name": "Cloudflare Workers AI", "providers": ["cloudflare-workers-ai"], "community": true, "summary": { "en": "Cloudflare Workers AI with your API token (Workers AI:Edit): 28+ models discovered live from models.dev, the 8 paid-only models flagged, and a Neurons/day allowance row in magpie quota.", "zh": "用你的 Cloudflare API Token(Workers AI:Edit 权限)登录 Workers AI:28+ 模型经 models.dev 实时发现,付费专属模型自动标注,magpie quota 显示每日 Neurons 免费额度。" } }, { "package": "officeace-auth", "name": "OfficeAce", "providers": ["officeace"], "community": true, - "summary": { "en": "Unofficial OfficeAce (Huawei Cloud AgentArts): browser sign-in to a Huawei Cloud account, live models with their credit multipliers, credit usage by bucket, and the daily check-in.", "zh": "非官方 OfficeAce(华为云 AgentArts):浏览器登录华为云账号,实时模型及其积分倍率、分桶积分用量,以及每日签到。" } } + "summary": { "en": "Unofficial OfficeAce (Huawei Cloud AgentArts): browser sign-in to a Huawei Cloud account, live models with their credit multipliers, credit usage by bucket, and the daily check-in.", "zh": "非官方 OfficeAce(华为云 AgentArts):浏览器登录华为云账号,实时模型及其积分倍率、分桶积分用量,以及每日签到。" } }, + { "package": "@magpie-community/opencode-river-auth", "name": "River", "providers": ["river"], "community": true, + "summary": { "en": "River (river.ai) pay-as-you-go inference with your API key: per-account models from /v1/models, documented reasoning efforts and live prices from River's public pricing endpoint.", "zh": "用你的 API key 接入 River (river.ai) 按量计费推理:按账号从 /v1/models 列出模型,带官方推理档位与实时价格。" } } ] }