Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# magpie-community plugins

[OpenCode](https://opencode.ai) provider plugins for coding-plan
subscriptions, and [gateway middleware](#gateway-middleware),
subscriptions and decision APIs, and [gateway middleware](#gateway-middleware),
[gateway hooks](#gateway-hooks), [routing strategies](#routing-strategies), [tools for every
agent](#tools-for-every-agent), [pages](#pages) and [agents](#agents) for
magpie, maintained by the community. To make one, see
[Write your own](#write-your-own). Each package signs in to one
subscription and makes its requests. The packages work in OpenCode and in
[Write your own](#write-your-own). Each provider package signs in to its
vendor service and makes its requests. The packages work in OpenCode and in
[magpie](https://usemagpie.ai), which runs OpenCode's provider plugins.

| Package | Signs in to | Provider id |
Expand All @@ -33,6 +33,7 @@ subscription and makes its requests. The packages work in OpenCode and in
| [minimax](packages/minimax) | MiniMax Code (international): account credits and M Plan, with MiniMax Code's device sign-in | `minimax-code-global` |
| [mimo](packages/mimo) | Xiaomi MiMo, with a Xiaomi account | `mimo-app` |
| [nous](packages/nous) | Nous Portal models, with Nous Portal's device sign-in | `nous-portal` |
| [openai-decisions](packages/openai-decisions) | OpenAI's native Decisions API as System One for magpie's classifiers and decision groups, with an API key or explicit reuse of magpie's saved official OpenAI key | `openai-decisions` |
| [opendesign](packages/opendesign) | Open Design Cloud (open-design.ai), with the Open Design CLI's device sign-in | `opendesign` |
| [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` |
Expand All @@ -47,6 +48,9 @@ subscription and makes its requests. The packages work in OpenCode and in
| [zed](packages/zed) | Zed (Pro, Pro Trial, Student, Business): Anthropic, OpenAI, Google and xAI models hosted by Zed | `zed` |
| [zen-free](packages/zen-free) | OpenCode Zen free models with the public credential | `opencode-zen-free` |

Decision providers are used through magpie's classifiers and `/v1/systemone`;
see their package READMEs for client compatibility.

## Gateway middleware

These packages aren't OpenCode plugins. magpie runs them in its gateway, on the requests every agent sends and the replies it gets back, whichever provider serves them. Each one is a port of something [New API](https://github.com/QuantumNous/new-api) does for its channels, or something agents commonly need.
Expand Down
9 changes: 9 additions & 0 deletions packages/openai-decisions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 0.1.0

- Add a native Magpie decision provider for OpenAI Decisions.
- Convert System One choice, score and noul questions while retaining answer probabilities and provider confidence.
- Support API key sign-in and optional reuse of Magpie's saved official OpenAI provider.
- Preserve upstream errors and cancellation; reject unsupported request shapes explicitly.
- Document released/source installation, sign-in storage, classifier setup, quota handling and verification limits; add the provider to the repository README.
22 changes: 22 additions & 0 deletions packages/openai-decisions/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2026 lintonggeng
Copyright (c) 2026 magpie-community contributors

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.
10 changes: 10 additions & 0 deletions packages/openai-decisions/NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The OpenCode 2.x compatibility bridge, `opencode2.mjs`, is an unmodified
copy of `scripts/opencode2.mjs` from magpie-community/plugins, distributed
under that repository's MIT license. Keep it byte-identical to that copy.

Upstream: https://github.com/magpie-community/plugins

The implementation follows the public provider/auth/decision contracts.
Reference implementations: the community River provider, AgentCompass's
decision-provider registration, and lesnolie/magpie-free-gateways' System
One integration. Their application logic is not bundled here.
241 changes: 241 additions & 0 deletions packages/openai-decisions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
# OpenAI Decisions for Magpie

A native Magpie provider exposing OpenAI's **Decisions API** through
Magpie's existing **System One** endpoint. The model is
`openai-decisions/gpt-6-luna`; use it as a routing group's classifier or a
member of a decision-model group alongside other System One providers.

**Provider id:** `openai-decisions`. **Decision model:** `gpt-6-luna`.
Verified with Magpie 0.1.3039; the minimum compatible release has not been established.

## Why this plugin

Magpie already speaks System One for compatible decision providers. Add
those directly with their decision endpoint and model IDs. OpenAI
Decisions uses a different path and request/answer schema; this plugin
converts that protocol while Magpie manages accounts, routing, rate
limits, failover and request records.

The built-in OpenAI provider handles normal Chat/Responses calls. This
provider calls `POST https://api.openai.com/v1/decisions` and retains native
decision probabilities. It does not simulate decisions with chat text.
The [upstream feature request](https://github.com/yetone/magpie/issues/4316)
describes the gap this fills.

## Install and sign in

Install the released community package through Magpie:

```sh
magpie plugin add @magpie-community/openai-decisions
magpie plugin login openai-decisions
```

For a source checkout, including a package that is not published yet, run
from the root of `magpie-community/plugins` instead:

```sh
magpie plugin add ./packages/openai-decisions
magpie plugin login openai-decisions
```

In Magpie's Plugins page, install **OpenAI Decisions**, then sign in.
The community's distribution branch can supply a released package before
its first npm publication; a separate `npm install` is unnecessary.

### Authentication and storage

Two sign-in methods:

1. **OpenAI API key**: enter a key that can access the native Decisions API.
Magpie stores the sign-in in `plugin-auth.json` in its configuration
directory, with Unix permissions 0600.
2. **Use the OpenAI key already saved in Magpie**: explicitly reuse the
primary key of the enabled official provider whose ID and preset are
`openai`. Its configured Chat/Responses endpoints must be
`https://api.openai.com/v1`. The plugin sign-in stores the reference
`magpie-provider:openai`; each request reads the current primary key
from Magpie's `providers.json`. It leaves that file unchanged.

The saved-key reader uses `XDG_CONFIG_HOME/magpie` when configured;
otherwise it uses `~/.config/magpie`, or `APPDATA/magpie` on Windows
with `~/AppData/Roaming/magpie` as its fallback. It selects the primary
key, not the provider's additional key pool. This optional keyless method
is a Magpie extension.

Direct key sign-in works without a separate OpenAI provider. Requests are
billed to the OpenAI account owning the selected key; reusing a key shares
that account's API allowance. OpenCode's regular API-key sign-in uses
its own `auth.json`. The package provides the community's OpenCode 1.x
and 2.x entry points, whose loader shapes are tested; live OpenCode decision
workflows and Windows/Linux execution have not been verified.

## One endpoint

Send a System One request to `http://127.0.0.1:3425/v1/systemone`:

```json
{
"model": "openai-decisions/gpt-6-luna",
"state": {"message": "What does HTTP 404 mean?"},
"questions": {
"intent": {
"type": "choice",
"instructions": "Which kind of request is this?",
"criteria": {"question": "Asks for an explanation", "code_change": "Asks to modify code"}
},
"is_question": {"type": "noul", "instructions": "Does this ask a question?"},
"effort": {
"type": "score",
"instructions": "How much work does this request require?",
"criteria": ["Little work", "Some work", "Much work", "Most work"]
}
}
}
```

### Decision groups and automatic effort

With an existing TypeSafe provider, create a decision group. Choose a new
group name: `magpie group add` replaces a group of the same name.

```sh
magpie group add Decisions models=typesafe/jev-latest,openai-decisions/gpt-6-luna routing=order
```

Then use `"model":"group/decisions"`. Magpie's group order and failover
decide which provider answers.

For an existing chat routing group whose ID is `coding`, enable automatic
effort with this decision provider:

```sh
magpie group set coding classifier=openai-decisions/gpt-6-luna effort=auto
```

Use your own chat group's ID in place of `coding`. Set
`classifier=group/decisions` to use the decision group instead. Chat
models remain in the chat group's `models`; decision models belong in
`classifier` or in a group containing only decision models. Magpie keeps
these models out of ordinary chat catalogs. Automatic effort rates the
turn's difficulty for chat models that support reasoning.

## Protocol and limits

| System One | OpenAI Decisions | System One answer |
| --- | --- | --- |
| Text `state` | Text `input` | Shared evidence |
| Object/array `state` | User message containing `input_json` | Shared evidence |
| Numeric/boolean `state` | JSON text `input` | Shared evidence |
| `choice` with `criteria` map | `choice` with `choices` array | Selected value, probability map, confidence |
| `score` with ordered `criteria` | `score` with `levels` array | Expected zero-based score, legend, probability map, confidence |
| `noul` with optional true/false definitions | `predicate` | Probability in `noul` |

Structured instructions and descriptions become compact JSON. Predicate
definitions and score-level ordering are retained, including numeric and
structured descriptions. This version accepts text and ordinary JSON,
and declares no image capability. Limits: 1–400 questions, 2–255 choice
options, 2–10 ordered score levels. Unsupported fields and `box` are
rejected explicitly; compressed requests are not implemented.

Probabilities and OpenAI's confidence values are retained. Magpie derives
its own routing confidence from option probabilities; vendor confidence
fields may use different calibration, so equal raw values across
providers do not imply equal reliability.

Upstream error statuses, error bodies, retry/rate-limit headers and request
IDs are preserved. Invalid or incomplete successful answers become 502.
Cancellation propagates upstream. Calls use the fixed OpenAI Decisions
endpoint, a fresh header set and no redirects.

## Troubleshooting

| Result | Check |
| --- | --- |
| 400 from the adapter | Use `gpt-6-luna`, text/JSON state and the documented choice, score or noul fields and limits. |
| Upstream 401/403 | Check the selected OpenAI key and its Decisions access. |
| Upstream 429 | Read the quota unit and actual token usage, honor `Retry-After` when present, and space checks by that budget. A quota refusal does not establish that a model is unsupported. |
| 503: credentials unavailable | Sign in again; for saved-key mode, check that the official `openai` provider is enabled and has a usable primary key. |
| 502 from the adapter | The upstream could not be reached or returned an incomplete/invalid decision answer; inspect Magpie's request record and any retained request ID. |

The adapter does not retry requests. Magpie owns routing and failover;
try one short question first when checking a constrained allowance.

## Develop and contribute

Tests cover conversion, structured questions, answer matching, invalid
distributions, errors, cancellation and credential selection. Live Magpie
tests are separate; fixtures are not evidence of account access.
See [VERIFICATION.md](VERIFICATION.md) for the real gateway checks and limits.

From the root of the community repository, run:

```sh
bun scripts/check.mjs openai-decisions
bun test packages/openai-decisions
```

For the Node test runner, run `npm test` from `packages/openai-decisions`.
To check installation without using your real Magpie sign-ins, use the
community harness from the repository root:

```sh
MAGPIE=/absolute/path/to/magpie scripts/try.sh openai-decisions
```

The harness keeps its own configuration under `.sandbox/openai-decisions`.
The command above lists the provider without signing in or calling OpenAI.
Keep automated tests offline and use synthetic credentials.

The plugin is registered in [index.mjs](index.mjs);
[adapter.mjs](adapter.mjs) owns request/answer conversion and the fixed
upstream fetch; [credentials.mjs](credentials.mjs) owns saved-key lookup.
Keep `opencode2.mjs` byte-identical to the community's canonical
`scripts/opencode2.mjs`. See [NOTICE.md](NOTICE.md) for attribution. MIT license.

Review checks for protocol changes:

- Keep the root README's provider table, this README, the registry's English/Chinese
summaries and the changelog aligned with the user-visible behavior.
- State each command's working directory and separate real-use evidence from fixtures.
- Keep object/array evidence as `input_json`; serialize primitive evidence as text.
- Preserve predicate definitions, ordered score criteria and vendor probabilities.
- Distinguish transport success from complete, valid decision answers.
- Verify a real classifier call as well as the downstream chat response.
- Treat HTTP 429 as a quota/rate-limit outcome, not proof of an unsupported model.
Record actual token usage and quota units, then pace live checks by that budget.
- Keep credentials, internal endpoints and local verification artifacts outside the distributable.

References: [OpenAI Decisions](https://developers.openai.com/api/docs/guides/decisions),
[Magpie plugins](https://github.com/yetone/magpie/blob/v0.1.3039/docs/subsystems/provider-plugins.md),
[River](https://github.com/magpie-community/plugins/tree/main/packages/river),
[System One example](https://github.com/lesnolie/magpie-free-gateways).

## 中文

安装社区发行包后登录:

```sh
magpie plugin add @magpie-community/openai-decisions
magpie plugin login openai-decisions
```

未发布时,在社区仓库根目录运行
`magpie plugin add ./packages/openai-decisions`,再执行同一登录命令。
提供方 ID 是 `openai-decisions`,决策模型为
`openai-decisions/gpt-6-luna`;已验证 Magpie 0.1.3039。

统一入口复用 Magpie `/v1/systemone`:兼容 System One 的供应商直接接入,
本插件负责转换 OpenAI Decisions。支持选择、评分、是非概率,保留结构化问题、
概率、置信度、用量、错误及取消行为,可用于决策模型组和意图路由。

登录可使用独立 API key,也可明确选择复用 Magpie 已保存的官方 OpenAI
提供方的主 key。前者保存在 Magpie 的 `plugin-auth.json`;后者只保存引用,
每次请求从 `providers.json` 读取当前主 key,共用该 key 所属 OpenAI 账号的 API
额度。已有聊天组可设置 `classifier=openai-decisions/gpt-6-luna effort=auto`,
也可把分类器设为决策模型组 `group/decisions`。

遇到 429 时按错误中的额度单位、实际 token 用量和 `Retry-After` 拉开调用间隔,
不要据此判断模型不受支持。真实 OpenCode 决策流程及 Windows/Linux 尚未验证;
完整验证范围见 [VERIFICATION.md](VERIFICATION.md)。社区代码使用公开协议与通用
示例;组织内部端点和凭据由本地维护。
58 changes: 58 additions & 0 deletions packages/openai-decisions/VERIFICATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Verification — 2026-11-05

Validated locally with Magpie 0.1.3039, Node 26.3.0 and Magpie's Bun 1.4.4.
The community package harness was read from magpie-community/plugins
commit `808f7a184d3a88db69691f4838deee46f64560b1`, then rechecked for
submission against `41e90a18d3affc7487460d032b0cdc5e09b20ebb`.

## Automated checks

- `npm test`: 18 pass, 0 fail.
- Community `bun scripts/check.mjs openai-decisions`: registry and provider checks pass.
- Community `bun test packages/openai-decisions`: 18 pass, 0 fail.
- OpenCode compatibility bridge matches the community's canonical file byte for byte.

## Documentation and source installation

- Root README provider table, package README, bilingual registry summary
and changelog describe the same provider and authentication methods.
- Package Markdown links and the JSON request example were checked against
the checked-in files and adapter.
- Community `scripts/try.sh openai-decisions` installed and listed the
provider under `.sandbox/openai-decisions`, with one decision model
and no sign-in. No OpenAI request or real account was used.
- This follow-up changes documentation and registry descriptions only;
the runtime, package version and dependencies are unchanged.

The full community repository test suite was not run locally. It remains
a separate upstream CI requirement; focused package tests and sandbox
installation do not establish a full-suite pass. Live OpenCode decision
workflows and Windows/Linux execution were not tested.

## Real local gateway

The same synthetic text/JSON case exercised choice, noul and score:

| Request model | Result | Actual model |
| --- | --- | --- |
| `typesafe/jev-latest` | HTTP 200; all three answers and distributions present | `jev-1.14.0` |
| `openai-decisions/gpt-6-luna` | HTTP 200; all three answers and distributions present | `gpt-6-luna` |
| `group/decisions` | HTTP 200; all three answers and distributions present | `jev-1.14.0`, first in the group's order |

A temporary chat group with `classifier=openai-decisions/gpt-6-luna` and
`effort=auto` returned HTTP 200 with `OK`. Magpie's usage record separately
confirmed a real `kind=routing`, provider `openai-decisions`, HTTP 200
classification call. Its downstream chat model was the catalog's
`openai/gpt-5.6-luna`; the temporary group was then removed.

The optional saved-key sign-in was exercised against the real gateway.
Ordinary API-key sign-in is covered by the auth hook tests; it does not
require an existing built-in OpenAI provider.

Live rate-limit/quota failures were not forced. Their status/body/header
handling is covered by fixtures, while cross-provider failover remains
Magpie's native responsibility. Image and box decisions are outside this
adapter's declared capabilities. Different vendors' confidence fields
retain their original calibration.

These local checks do not represent community review or acceptance.
Loading