mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-21 15:05:56 +00:00
Compare commits
3 Commits
fix/pre-co
...
fix/codeql
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6441b5b6f3 | ||
|
|
b03f265540 | ||
|
|
909af20270 |
20
.env.example
20
.env.example
@@ -891,19 +891,6 @@ ALLOW_API_KEY_REVEAL=false
|
||||
# Default: https://api.getnadir.com
|
||||
# OMNIROUTE_NADIR_BASE_URL=https://api.getnadir.com
|
||||
|
||||
# Opt-in for the `decision` auto-combo router strategy (feature flag; a dashboard DB
|
||||
# override wins). While off, decision combos read no credential, make no call and route
|
||||
# with the rules strategy.
|
||||
# Used by: open-sse/services/autoCombo/decisionStrategy.ts
|
||||
# Default: false
|
||||
# COMBO_DECISION_ROUTER_ENABLED=false
|
||||
|
||||
# Key for the `decision` router's network deciders (systemone, http), used when the
|
||||
# combo's config.decision.connectionId is unset (and, for systemone, no typesafe
|
||||
# connection is in scope). A combo never stores a key. Sensitive.
|
||||
# Used by: open-sse/services/decision/credentials.ts
|
||||
# OMNIROUTE_DECISION_API_KEY=
|
||||
|
||||
# Weekly window for per-API-key USD usage limits.
|
||||
# Used by: src/lib/usage/apiKeyUsageLimits.ts (request enforcement, key usage-limit
|
||||
# status, @@om-usage). Values: provider | calendar | Default: provider
|
||||
@@ -2626,13 +2613,6 @@ APP_LOG_TO_FILE=true
|
||||
# Used by: src/lib/healthzLag.ts (event-loop stall sampler). Disabled by default;
|
||||
# logs sizes and inflight count only, never bodies or heap snapshots.
|
||||
# OMNIROUTE_EVENT_LOOP_STALL_THRESHOLD_MS=0 stops that sampler, and this diagnostic with it.
|
||||
# Optional response header for troubleshooting Codex OAuth plan eligibility.
|
||||
# OFF by default: when enabled, API callers can see the recognized subscription tier
|
||||
# of the selected Codex connection in X-OmniRoute-Selected-Connection-Plan.
|
||||
# Do not enable on public/multi-tenant gateways if this account metadata is private.
|
||||
# Arbitrary/unrecognized plan values and non-Codex requests never get this header.
|
||||
# OMNIROUTE_CODEX_PLAN_RESPONSE_HEADER=0
|
||||
|
||||
# OMNIROUTE_HEAP_DIAGNOSTICS_ENABLED=0
|
||||
# Heap-use threshold in MiB for the opt-in diagnostic (default: 900).
|
||||
# A high-heap log is rate-limited to once per 60 seconds.
|
||||
|
||||
38
.github/workflows/omni-queue.yml
vendored
38
.github/workflows/omni-queue.yml
vendored
@@ -22,11 +22,7 @@ name: omni-queue
|
||||
# • Both jobs run in the `omni-queue` environment, which holds the App's credentials and the
|
||||
# owner's OMNI_QUEUE_LAND_TOKEN and admits the default branch only, by its exact name: a
|
||||
# workflow on a candidate branch cannot read them. The App writes omni-queue/land, the status release rulesets
|
||||
# require, so its private key is the root of trust. The land token reaches the tick only
|
||||
# (the landing with landing.actor "owner"; the comments, label removals and issues with
|
||||
# config voice "owner"). The owner's merge-commit signing key (OMNI_QUEUE_SIGNING_KEY,
|
||||
# config landing.signing "ssh") reaches one step of the tick, which writes it to a 0600 file
|
||||
# under RUNNER_TEMP; the job's last step removes it, whatever happened.
|
||||
# require, so its private key is the root of trust. The land token reaches the tick only.
|
||||
# • action=bless (the explicit emergency exit): the tick writes omni-queue/land on ONE commit
|
||||
# for a hotfix, sync-back or base repair, after checking that both the dispatcher
|
||||
# (github.actor) and whoever triggered the run (github.triggering_actor, the re-runner of a
|
||||
@@ -239,35 +235,10 @@ jobs:
|
||||
echo "name=${login}"
|
||||
echo "email=${id}+${login}@users.noreply.github.com"
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
# config.landing.signing "ssh": the owner's SSH signing key, for the queue's merge commits
|
||||
# (scripts/merge-queue/compose.mjs reads it at compose.signingKeyPath(RUNNER_TEMP) and hands
|
||||
# git the path as per-command configuration, never as an argument). The key exists only in
|
||||
# this step's environment and in a file only the runner user can read; it is never
|
||||
# printed. Without the secret nothing is written and a tick that is asked to sign composes
|
||||
# unsigned, with one `error` event per batch. This step never fails the job: a key it
|
||||
# cannot write is the same case (signing never blocks the queue).
|
||||
- name: Write the merge-commit signing key
|
||||
env:
|
||||
OMNI_QUEUE_SIGNING_KEY: ${{ secrets.OMNI_QUEUE_SIGNING_KEY }}
|
||||
run: |
|
||||
set -uo pipefail
|
||||
if [ -z "${OMNI_QUEUE_SIGNING_KEY:-}" ]; then
|
||||
echo "no merge-commit signing key in the environment: nothing written"
|
||||
exit 0
|
||||
fi
|
||||
umask 077
|
||||
if ! { mkdir -p "$RUNNER_TEMP/omni-queue-signing" \
|
||||
&& chmod 700 "$RUNNER_TEMP/omni-queue-signing" \
|
||||
&& printf '%s\n' "$OMNI_QUEUE_SIGNING_KEY" > "$RUNNER_TEMP/omni-queue-signing/signing-key" \
|
||||
&& chmod 600 "$RUNNER_TEMP/omni-queue-signing/signing-key"; }; then
|
||||
rm -rf "$RUNNER_TEMP/omni-queue-signing"
|
||||
echo "::warning::the merge-commit signing key could not be written: merge commits stay unsigned"
|
||||
fi
|
||||
# Inputs travel through env and are assembled into an argv array: no expression is ever
|
||||
# expanded inside the script body. Scheduled, workflow_run and pull_request_target ticks
|
||||
# pass no base (the tick discovers the bases with work). The owner's land token is used
|
||||
# by the landing itself when config.landing.actor is "owner", and by the queue's comments,
|
||||
# label removals and issues when config.voice is "owner" (never printed).
|
||||
# only by the landing itself when config.landing.actor is "owner" (never printed).
|
||||
# GITHUB_ACTOR and GITHUB_TRIGGERING_ACTOR are the runner's own default variables, named
|
||||
# here because a bless is checked against both: the original dispatcher, whose inputs a
|
||||
# re-run keeps, and whoever triggered this run (the re-runner of a re-run).
|
||||
@@ -294,8 +265,3 @@ jobs:
|
||||
if [ -n "${INPUT_SHA:-}" ]; then args+=(--sha "$INPUT_SHA"); fi
|
||||
fi
|
||||
node scripts/merge-queue/tick.mjs "${args[@]}"
|
||||
# Last step, whatever happened before it (failure, cancellation): the signing key leaves
|
||||
# the runner. Needs no secret; nothing to remove is not an error.
|
||||
- name: Remove the merge-commit signing key
|
||||
if: always()
|
||||
run: rm -rf "$RUNNER_TEMP/omni-queue-signing"
|
||||
|
||||
13
.github/workflows/release-acceptance.yml
vendored
13
.github/workflows/release-acceptance.yml
vendored
@@ -20,7 +20,6 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
|
||||
with:
|
||||
ref: ${{ github.sha }}
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
|
||||
with:
|
||||
@@ -29,13 +28,17 @@ jobs:
|
||||
- uses: ./.github/actions/npm-ci-retry
|
||||
with:
|
||||
cache: "false"
|
||||
- name: Validate and retain the live gate inventory
|
||||
run: node scripts/quality/release-acceptance/run-shadow.mjs "$RUNNER_TEMP/release-acceptance-shadow"
|
||||
- name: Emit shadow acceptance report
|
||||
run: |
|
||||
node scripts/quality/validate-release-acceptance.mjs \
|
||||
--plan tests/fixtures/release-acceptance/plan-lint.json \
|
||||
--manifests tests/fixtures/release-acceptance/shadow-manifests \
|
||||
--out release-acceptance-report.json
|
||||
continue-on-error: true
|
||||
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
|
||||
if: always()
|
||||
with:
|
||||
name: release-acceptance-report
|
||||
path: ${{ runner.temp }}/release-acceptance-shadow/
|
||||
if-no-files-found: error
|
||||
path: release-acceptance-report.json
|
||||
if-no-files-found: ignore
|
||||
retention-days: 30
|
||||
|
||||
@@ -9,12 +9,6 @@ fi
|
||||
# Cheap, deterministic local gates (re-enabled). Slower checks (i18n drift,
|
||||
# openapi coverage/security-tiers, env-doc sync) run in CI to keep commits fast.
|
||||
sh scripts/check/check-git-identity.sh
|
||||
# Migration names (#20578): only when the commit touches src/lib/db/migrations/. The
|
||||
# assignment aborts the hook if git fails. Names only; the comparison with the base stays in CI.
|
||||
staged_migrations=$(git diff --cached --name-only --diff-filter=ACMRD -- src/lib/db/migrations/)
|
||||
if [ -n "$staged_migrations" ]; then
|
||||
GITHUB_EVENT_NAME= MIGRATION_BASE_REF= node scripts/check/check-migration-numbering.mjs
|
||||
fi
|
||||
# The stash is shared by every worktree. Never let a local hook stash another
|
||||
# session's changes, and never download a missing tool during a commit.
|
||||
npx --no-install lint-staged --no-stash
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
- **feat(images):** `/v1/images/edits` supports Leonardo: the reference image is uploaded through Leonardo's init-image flow and the generation is guided by it (`init_image_id`, `init_strength` 0.3), instead of the edit being rejected as unsupported. Leonardo takes one reference image; more than one returns 400, and a combo moves on to its next provider rather than editing with the first image only ([#18674](https://github.com/cheaper-inference/OmniRoute/pull/18674), closes [#18671](https://github.com/cheaper-inference/OmniRoute/issues/18671))
|
||||
@@ -1 +0,0 @@
|
||||
- **feat(providers):** `expiry-first` treats a lapsed weekly/monthly reset (stale quota read) as refilled instead of "expires now", and gains an opt-in `expiryFirstOrder: "deadline"` (per provider) that spends the account whose quota is lost first while it has quota ([#19583](https://github.com/diegosouzapw/OmniRoute/pull/19583)) — thanks @feci
|
||||
@@ -1 +0,0 @@
|
||||
- **feat(plugins):** Opt-in `PLUGIN_PERMISSION_MODEL_ENABLED` feature flag (off by default) runs each plugin process under the Node.js permission model built from its manifest: reads confined to the plugin directory, writes only to its data directory with `file-write`, child processes only with `exec`; `network` stays declarative
|
||||
@@ -1 +0,0 @@
|
||||
- **feat(ci):** omni-queue can speak as the owner and sign its merge commits, both off by default. With `voice: "owner"` in `config/merge-queue/config.json`, the queue's comments and label removals on pull requests, the dashboard issue and its comments, base-red comments and the tree-divergence issue go out with `OMNI_QUEUE_LAND_TOKEN`; statuses, refs, the state branch, re-runs and reads stay the App's, and a missing or refused token falls back to the App with one `error` event. With `landing.signing: "ssh"` (owner actor only), every merge commit the queue composes is signed with the owner's key from the `OMNI_QUEUE_SIGNING_KEY` environment secret, and a missing key composes unsigned with one `error` event per batch ([#20792](https://github.com/cheaper-inference/OmniRoute/pull/20792))
|
||||
@@ -1 +0,0 @@
|
||||
- **feat(combo):** new `decision` router strategy for Auto combos: a decider picks the model for each request and `rules` picks the account. The decider can be TypeSafe System One, your own decision URL (System One or OpenAI chat format), or one of the combo's own models called in process. Only the last user message (up to 8000 characters) and the model menu are sent; the key comes from a stored connection inside the API key's allowed connections or from `OMNIROUTE_DECISION_API_KEY`, never from the combo. Calls go through the outbound guard with no redirects, a 64 KB answer cap and a 2 s default timeout (5 s max), and any failure routes with `rules`. Off by default behind `COMBO_DECISION_ROUTER_ENABLED`; combos without a decision block do not change. The combo builder gets the settings and a Test decision button, and the TypeSafe client now uses the same guarded transport — thanks @BelphegorPrime, @alvinveroy, @rafacpti23 and @miguelenes
|
||||
@@ -1 +0,0 @@
|
||||
- Add an opt-in `X-OmniRoute-Selected-Connection-Plan` response header for Codex account-routing troubleshooting (`OMNIROUTE_CODEX_PLAN_RESPONSE_HEADER=1`), off by default with an explicit plan allowlist.
|
||||
@@ -1 +0,0 @@
|
||||
- **feat(models):** add GPT-6.1 Terra to OpenAI API and Codex model catalogs, including Responses-only tool routing, supported reasoning tiers, verified token pricing, long-context rates, and Codex aliases.
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(security):** the prompt-injection guard now decodes base64, hex and percent-encoded text in a request and scans the result, so an instruction hidden in an encoded string is scored like the same instruction in plain text. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(resilience):** a circuit breaker with `halfOpenRequests` above 1 now needs that many probe successes in a row before it closes, so one lucky probe no longer restores a flapping provider. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(pii):** a custom PII regex that backtracks for exponential time on a long run of one character, such as an overlapping alternation, is now refused when you save or test it, instead of freezing the gateway. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(antigravity):** parallel conversations on one account no longer share a single Cloud Code session and evict each other's prompt cache — the upstream `sessionId` is now derived from account + conversation ([#19876](https://github.com/cheaper-inference/OmniRoute/pull/19876)) — thanks @adevwithpurpose
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(dashboard):** move the custom banned-keyword editor back to the Resilience settings tab (next to Auto Disable) instead of Security, and harden its save/load path: keywords appear only after the server accepts the PATCH, a failed settings load surfaces an error instead of a misleading empty list, the 200-character limit is enforced in the UI, and removals match by keyword value rather than index. The editor now also stays available when `/api/resilience` fails to load ([#20078](https://github.com/cheaper-inference/OmniRoute/pull/20078)) — thanks @sdfsdfw2
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(security):** an HTTP 400 counts subscription/plan quota wording ("usage limit reached", "plan limit", weekly/session usage limits) as quota exhaustion only when the structured error code is a credit/quota code or the provider documents a message-only 400 form (`command-code`, `bai`, `openai-compatible-*`), the same contract as #20567, so such a phrase echoed from the request no longer puts a shared LLM or search connection on hold
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(security):** Choosing the local corpus root (`POST /api/settings/local-corpus`) or the Obsidian WebDAV vault (`POST /api/settings/obsidian/webdav`) now needs a dashboard session or the local CLI: API keys and access tokens of any scope get 403. Both routes also refuse the filesystem root, the home directory itself and system directories (`/etc`, `/usr`, `/bin`, `/sbin`, `/var`, `/proc`, `/sys`, `/dev`, `/boot`, `/root`) with a fixed 400 (CodeQL #1371, #1372, #1373)
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(security):** The internal chat admission bypass and the internal upstream-start cap are granted only on a per-process token held in memory; the deployment env key (`OMNIROUTE_API_KEY` / `ROUTER_API_KEY`) still authenticates requests but no longer marks them as internal
|
||||
1
changelog.d/fixes/20823-codeql-redos-model-ids.md
Normal file
1
changelog.d/fixes/20823-codeql-redos-model-ids.md
Normal file
@@ -0,0 +1 @@
|
||||
- **fix(security):** GitHub Copilot Responses-only inference, model display names and the Context7 library id check use linear regexes, so a long crafted model or library id no longer blocks the event loop for seconds (CodeQL js/polynomial-redos #1325, #1324, #1296)
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(security):** Image generation on NanoBanana, Magnific, Black Forest Labs and RenderHour caps a caller's `poll_interval_ms` at 30 s and `timeout_ms` / `poll_timeout_ms` at 10 minutes (defaults unchanged), and RenderHour stops waiting between polls when the request is aborted; SYNTX provider rules only run for names defined in the rules table, so an `ai_name` such as `constructor` or `__proto__` no longer reaches an inherited `Object.prototype` member (CodeQL #1389, #1392) ([#20824](https://github.com/cheaper-inference/OmniRoute/pull/20824))
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(auth):** continue background token health-check and OAuth credential refresh for inactive connections (`isActive: false`), preserving their disabled routing state while preventing rotating refresh token expiration on quota-exhausted Claude accounts.
|
||||
@@ -1 +0,0 @@
|
||||
- Codex hosted Responses `image_generation` edits now admit up to 128 reference images instead of the historical, unverified eight-image guard. Live isolated Codex OAuth smokes with 9, 17, 24, 32, 64 and 128 small references each returned a real PNG (HTTP 200). The 128-image value is an operational request guard, **not** a claim of the backend's absolute maximum. The separate dedicated GPT Image edits endpoint remains capped at its documented 16 inputs. Existing per-image MIME/size checks and 20 MiB aggregate decoded-input limit remain unchanged.
|
||||
@@ -1 +0,0 @@
|
||||
- **test(batch):** the batch rate-limit E2E keeps the background-services kill switch on and starts only the batch worker, behind a development-only double opt-in, instead of booting every production scheduler ([#18626](https://github.com/cheaper-inference/OmniRoute/pull/18626)) — thanks @ahmedgo17390
|
||||
@@ -1 +0,0 @@
|
||||
- **refactor(db):** Isolate reasoning-routing rule persistence behind a Promise-based repository while preserving rule ordering, reference validation, cache invalidation and SQLite reset behavior (#19669 — thanks @xiaoyaner0201).
|
||||
@@ -1 +0,0 @@
|
||||
- **perf(providers):** resolving a provider alias or id is now one map lookup instead of a scan of the whole provider catalog on every routing step. ([#19724](https://github.com/cheaper-inference/OmniRoute/pull/19724))
|
||||
@@ -1 +0,0 @@
|
||||
- **perf(claude):** The last tool-result turn of a translated Claude tool loop now gets the 5m cache marker (when fewer than 4 markers are used), so the next call reads those tool results from cache instead of paying the full input price again. A single request that ends with a tool result and has no follow-up pays a one-time 0.25x write premium on those tokens. ([#19750](https://github.com/cheaper-inference/OmniRoute/pull/19750))
|
||||
@@ -1 +0,0 @@
|
||||
- **fix(db):** the pre-commit hook now runs `check:migration-numbering` when the commit stages a file under `src/lib/db/migrations/`, so a hand-numbered or badly named migration fails locally with the same message CI prints (names only; the comparison with the base stays in CI); commits without migrations skip it ([#20938](https://github.com/cheaper-inference/OmniRoute/pull/20938))
|
||||
@@ -14,8 +14,7 @@
|
||||
"name": "diegosouzapw",
|
||||
"email": "8016841+diegosouzapw@users.noreply.github.com"
|
||||
},
|
||||
"statusContext": "omni-queue/land",
|
||||
"signing": "none"
|
||||
"statusContext": "omni-queue/land"
|
||||
},
|
||||
"requiredChecks": [
|
||||
"Gate / CI",
|
||||
@@ -52,6 +51,5 @@
|
||||
"config/merge-queue/**",
|
||||
".mergify.yml"
|
||||
],
|
||||
"mode": "shadow",
|
||||
"voice": "app"
|
||||
"mode": "shadow"
|
||||
}
|
||||
|
||||
@@ -635,7 +635,7 @@
|
||||
},
|
||||
{
|
||||
"name": "test:property",
|
||||
"command": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./tests/_setup/isolateDataDir.ts --test --test-force-exit tests/unit/correctness/*.property.test.ts",
|
||||
"command": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --test --test-force-exit tests/unit/correctness/*.property.test.ts",
|
||||
"disposition": "separately-invoked"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -165,7 +165,7 @@ Runs on every PR to `main`. Blocks merge on failure.
|
||||
| `check:vitest-exclusions` | Every Vitest exclusion names a tracking issue and appears in `config/quality/vitest-exclusions.json` (#13204) | Yes |
|
||||
| `check:file-size` | Source files (`.ts`/`.tsx` in `src/`, `open-sse/`, `electron/`, `bin/`) stay within `cap` and test files (`*.test.ts(x)`) within `testCap`; files frozen in `file-size-baseline.json` (`frozen` / `testFrozen`) must not grow past their recorded size | Yes |
|
||||
| `check:error-helper` | Error responses in executors/handlers use `buildErrorBody()` / `sanitizeErrorMessage()` (Hard Rule #12) | Yes |
|
||||
| `check:migration-numbering` | Migration file names: the old `001`–`241` series is frozen and new files are `YYYYMMDDHHMMSS_<description>.sql`. Against the PR base it rejects a removed migration, a renamed one without a compatibility entry, and an out-of-order or edited one whose final schema does not commute. Also runs in the husky pre-commit hook when the commit stages a file under `src/lib/db/migrations/` (names, duplicates and the frozen series only; the comparison with the base stays in CI — #20578) |
|
||||
| `check:migration-numbering` | Migration file names: the old `001`–`241` series is frozen and new files are `YYYYMMDDHHMMSS_<description>.sql`. Against the PR base it rejects a removed migration, a renamed one without a compatibility entry, and an out-of-order or edited one whose final schema does not commute |
|
||||
| `check:public-creds` | No literal OAuth `client_id`/`client_secret` or Firebase Web keys outside `publicCreds.ts` (Hard Rule #11) | Yes |
|
||||
| `check:db-rules` | No raw SQL outside `src/lib/db/` modules; no barrel-imports from `localDb.ts` (Hard Rules #2/#5) | Yes |
|
||||
| `check:known-symbols` | Provider executors, routing strategies, and translators registered in their dispatch tables match the files on disk — no orphaned or undeclared symbols | Yes |
|
||||
|
||||
@@ -258,17 +258,13 @@ silently falls back to the built-in seed registry and logs a warning.
|
||||
|
||||
### Plugin execution isolation
|
||||
|
||||
> **Plugins are not sandboxed by default.** The child is an ordinary Node.js
|
||||
> process running as the OmniRoute user, with no VM context and no Node.js
|
||||
> permission flags, so plugin code can read and write any file that user can,
|
||||
> run programs and reach the network. `requires.permissions` only decides which
|
||||
> environment variables the child receives; the other permissions are not
|
||||
> enforced. The opt-in `PLUGIN_PERMISSION_MODEL_ENABLED` feature flag (off by
|
||||
> default) runs each plugin under the Node.js permission model built from those
|
||||
> permissions, except `network`, which Node.js cannot restrict (see
|
||||
> [`PLUGIN_SDK.md`](./PLUGIN_SDK.md#permission-system)). Install only plugins
|
||||
> you trust. The process boundary below contains crashes and hangs; it is not a
|
||||
> security boundary.
|
||||
> **Plugins are not sandboxed.** The child is an ordinary Node.js process running
|
||||
> as the OmniRoute user, with no VM context and no Node.js permission flags, so
|
||||
> plugin code can read and write any file that user can, run programs and reach
|
||||
> the network. `requires.permissions` only decides which environment variables
|
||||
> the child receives; the other permissions are not enforced. Install only
|
||||
> plugins you trust. The process boundary below contains crashes and hangs; it
|
||||
> is not a security boundary.
|
||||
|
||||
- **Process isolation** — `loadPlugin()` (`src/lib/plugins/loader.ts`) spawns
|
||||
each plugin in a separate Node.js child process and communicates over IPC.
|
||||
|
||||
@@ -146,42 +146,22 @@ Or as simple booleans (default priority 100):
|
||||
|
||||
## Permission System
|
||||
|
||||
By default plugins are **not sandboxed**. Each active plugin runs as a separate, ordinary Node.js
|
||||
child process (`loadPlugin()` in `src/lib/plugins/loader.ts`) under the same operating-system user
|
||||
as OmniRoute, with no VM context and no Node.js permission flags. Plugin code can use `node:fs`,
|
||||
Plugins are **not sandboxed**. Each active plugin runs as a separate, ordinary Node.js child
|
||||
process (`loadPlugin()` in `src/lib/plugins/loader.ts`) under the same operating-system user as
|
||||
OmniRoute, with no VM context and no Node.js permission flags. Plugin code can use `node:fs`,
|
||||
`node:child_process`, `fetch` and every other Node.js API: it can read and write any file the
|
||||
OmniRoute user can (including the data directory), run programs and reach the network.
|
||||
|
||||
The manifest's `requires.permissions` accepts `network`, `file-read`, `file-write`, `env` and
|
||||
`exec`. With the default settings only `env` has an effect at runtime.
|
||||
`exec`, but today only `env` has an effect at runtime:
|
||||
|
||||
### Opt-in permission model (`PLUGIN_PERMISSION_MODEL_ENABLED`)
|
||||
| Permission | Effect today |
|
||||
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `env` | The plugin process also receives `PORT`, `HOSTNAME`, `TZ` and `TMPDIR`. Without it, it receives only `PATH`, `HOME`, `USER`, `LANG`, `LC_ALL`, `NODE_ENV`, `PLUGIN_ENTRY` and `PLUGIN_NAME` (plus `SystemRoot` and `windir` on Windows). |
|
||||
| `network`, `file-read`, `file-write`, `exec` | None. They are declarations only: nothing is blocked when they are missing. |
|
||||
|
||||
The `PLUGIN_PERMISSION_MODEL_ENABLED` feature flag (category `security`, **off by default**) starts
|
||||
each plugin process with the
|
||||
[Node.js permission model](https://nodejs.org/api/permissions.html) (`--permission`, accepted by
|
||||
every supported Node.js line: 22.22+, 24 and 26). The flags are built from the manifest by
|
||||
`buildPermissionModelArgs()` in `src/lib/plugins/permissionModel.ts`. The flag is read when a plugin
|
||||
is activated, so it applies to plugins activated after the change; deactivate and activate a
|
||||
running plugin to apply it.
|
||||
|
||||
The plugin data directory is `plugin-data/<plugin-name>` next to the plugin root
|
||||
(`~/.omniroute/plugin-data/<plugin-name>` by default, `getPluginDataDir()`). With the flag on, its
|
||||
path is passed to the plugin as `PLUGIN_DATA_DIR`.
|
||||
|
||||
| Permission | Flag off (default) | Flag on |
|
||||
| ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| (none) | Full privileges of the OmniRoute user. | File reads only inside the plugin directory. No file writes, no child processes, no worker threads, no native addons, no WASI. |
|
||||
| `env` | The plugin process also receives `PORT`, `HOSTNAME`, `TZ` and `TMPDIR`. Without it, it receives only `PATH`, `HOME`, `USER`, `LANG`, `LC_ALL`, `NODE_ENV`, `PLUGIN_ENTRY` and `PLUGIN_NAME` (plus `SystemRoot` and `windir` on Windows). | Same as with the flag off. |
|
||||
| `file-read` | None (declaration only). | The plugin data directory also becomes readable (it is created if missing). |
|
||||
| `file-write` | None (declaration only). | The plugin data directory becomes readable and writable (`--allow-fs-write`). Nothing else is writable. |
|
||||
| `exec` | None (declaration only). | Child processes are allowed (`--allow-child-process`). Node.js passes the permission flags on to child Node.js processes through `NODE_OPTIONS`, but any other program runs without restrictions, so `exec` effectively lifts the file-system limits. |
|
||||
| `network` | None (declaration only). | None. The Node.js permission model does not restrict outbound network access, so `network` stays a declaration and is never enforced. |
|
||||
|
||||
Turning the flag on breaks plugins that read files outside their own directory (for example a
|
||||
module resolved from a parent `node_modules`), write anywhere but their data directory, or spawn
|
||||
processes without declaring `exec`. Even with the flag on the plugin keeps network access and runs
|
||||
as the OmniRoute user, so install only plugins whose source you trust.
|
||||
Installing a plugin is like installing any other program on the host. Install only plugins whose
|
||||
source you trust.
|
||||
|
||||
## Config Schema
|
||||
|
||||
|
||||
@@ -3519,86 +3519,6 @@ paths:
|
||||
"404":
|
||||
description: Combo not found
|
||||
|
||||
/api/combos/decision-preview:
|
||||
post:
|
||||
tags: [Combos]
|
||||
summary: Preview the decision router menu and optionally test one decision
|
||||
description: >-
|
||||
Builds the menu (unique model ids of the given steps, in order) and the generated
|
||||
cost-rank descriptions that the `decision` auto-router sends at request time. With
|
||||
`prompt`, also runs one decision with the unsaved `decision` block; that call only
|
||||
happens while the `COMBO_DECISION_ROUTER_ENABLED` feature flag is on (otherwise
|
||||
`test.status` is `skipped` with reason `disabled`) and may bill the decider. A
|
||||
`combo-model` decider is skipped (`live_request_only`). Requires management auth.
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [models]
|
||||
properties:
|
||||
models:
|
||||
type: array
|
||||
maxItems: 200
|
||||
items:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 300
|
||||
description: Combo step model strings (`provider/model`).
|
||||
prompt:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 8000
|
||||
decision:
|
||||
type: object
|
||||
additionalProperties: false
|
||||
required: [decider]
|
||||
properties:
|
||||
decider:
|
||||
type: string
|
||||
enum: [systemone, http, combo-model]
|
||||
model:
|
||||
type: string
|
||||
maxLength: 200
|
||||
baseUrl:
|
||||
type: string
|
||||
maxLength: 500
|
||||
description: http(s) URL without credentials, query or fragment.
|
||||
connectionId:
|
||||
type: string
|
||||
maxLength: 200
|
||||
wire:
|
||||
type: string
|
||||
enum: [systemone, openai-chat]
|
||||
timeoutMs:
|
||||
type: integer
|
||||
minimum: 100
|
||||
maximum: 5000
|
||||
minConfidence:
|
||||
type: number
|
||||
minimum: 0
|
||||
maximum: 1
|
||||
descriptions:
|
||||
type: object
|
||||
maxProperties: 50
|
||||
additionalProperties:
|
||||
type: string
|
||||
maxLength: 1000
|
||||
responses:
|
||||
"200":
|
||||
description: >-
|
||||
`menu` and `generated`; with a prompt also `test` (`status`: `selected`, `skipped`
|
||||
or `failed`, plus a log-safe `reason`, or `choice`, `confidence`, `probabilities`,
|
||||
`backendModel` and `latencyMs`).
|
||||
"400":
|
||||
description: Invalid JSON or body (an `apiKey` field is rejected)
|
||||
"401":
|
||||
description: Management authentication required
|
||||
"500":
|
||||
description: Sanitized error
|
||||
|
||||
/api/settings:
|
||||
get:
|
||||
tags: [Settings]
|
||||
|
||||
@@ -309,7 +309,7 @@ Use `IF NOT EXISTS`, `IF EXISTS`, and `OR IGNORE` / `OR REPLACE` clauses liberal
|
||||
1. **Create the file with the generator**: `npm run db:new-migration -- <description>` (for example `npm run db:new-migration -- add combo priority`). It writes `src/lib/db/migrations/<YYYYMMDDHHMMSS>_<description>.sql` with the current UTC time and a comment header, moves forward one second if that timestamp is taken, and never overwrites a file. Do not pick a number by hand.
|
||||
2. **Use safe DDL**: `CREATE TABLE IF NOT EXISTS`, `CREATE INDEX IF NOT EXISTS`, `ALTER TABLE ... ADD COLUMN`
|
||||
3. **Backfill data carefully**: use `UPDATE ... WHERE ...` to handle existing rows
|
||||
4. **Check order and naming**: `npm run test:migrations:fresh` (all migrations on an empty database) and `npm run check:migration-numbering`. The husky pre-commit hook runs `check:migration-numbering` on its own when the commit stages a file under `src/lib/db/migrations/`, so a hand-picked or badly formed name (for example `242_x.sql`) fails the commit locally with the same message CI prints. The hook checks names, duplicates and the frozen `001`–`241` series only; the comparison with the PR base (removed, renamed or out-of-order migrations) still runs in CI
|
||||
4. **Check order and naming**: `npm run test:migrations:fresh` (all migrations on an empty database) and `npm run check:migration-numbering`
|
||||
5. **Test on a copy**: never run untested migrations on production
|
||||
6. **A table created from code needs a migration too**: if a module also creates the table lazily (`CREATE TABLE IF NOT EXISTS`, kept as a self-heal path), a migration must create it with the same DDL. Otherwise a clean install and an upgraded install end up with different schemas, depending on whether that code path ran. `tests/unit/db/lazy-table-migration-guard.test.ts` scans `src/` and `open-sse/` and fails on a lazy `CREATE` without a migration (#20557). Example: `src/lib/db/migrations/20261118120853_compression_run_telemetry.sql`.
|
||||
|
||||
|
||||
@@ -153,7 +153,6 @@ commit status the release rulesets require (`scripts/merge-queue/config.mjs`):
|
||||
| `actor` | `app` (the default when absent) or `owner` | `app`: the App's token pushes or merges. `owner`: the owner's token (`OMNI_QUEUE_LAND_TOKEN`) does, and the queue's merge commits carry `landing.identity`. |
|
||||
| `identity` | `{name, email}`; the email ends in `@users.noreply.github.com` | Required when `actor` is `owner`, refused otherwise. |
|
||||
| `statusContext` | `[A-Za-z0-9._/-]{1,100}`, starting with `omni-queue/`; default `omni-queue/land` | The commit status the release ruleset requires. It must not equal a name in `requiredChecks` or `aggregateChecks`, nor an approval context (`omni-queue/approval`, `omni-queue/protected-approval`). |
|
||||
| `signing` | `none` (the default when absent) or `ssh` | `ssh`: every merge commit the queue composes is signed with the owner's SSH key (see [Signed merge commits](#signed-merge-commits-landingsigning)). Refused unless `actor` is `owner`. |
|
||||
|
||||
With `actor: "owner"` (the value in the shipped config):
|
||||
|
||||
@@ -333,119 +332,6 @@ In live mode:
|
||||
The land token is fine-grained and valid for 90 days: write the date it expires next to the secret
|
||||
and rotate it before then.
|
||||
|
||||
### Signed merge commits (`landing.signing`)
|
||||
|
||||
With `landing.signing: "ssh"` (shipped `none`) the queue signs every merge commit it composes:
|
||||
batch candidates, bisection halves and recompositions, in shadow and in live mode
|
||||
(`composeCandidate` in `scripts/merge-queue/compose.mjs`, `git commit-tree -S`). The commits carry
|
||||
`landing.identity`, so `signing: "ssh"` is refused unless `landing.actor` is `owner`: GitHub
|
||||
verifies a signature against the signing keys of the committer's account, and the App's bot user
|
||||
has none.
|
||||
|
||||
**Where the key lives.** The private key is the environment secret OMNI_QUEUE_SIGNING_KEY
|
||||
(environment `omni-queue`, next to the land token). Only the tick job reads it, in one step,
|
||||
"Write the merge-commit signing key", which writes it to `$RUNNER_TEMP/omni-queue-signing/signing-key`
|
||||
(directory `0700`, file `0600`); the job's last step, "Remove the merge-commit signing key"
|
||||
(`if: always()`), deletes the directory whatever happened before it. The tick process never holds
|
||||
the key: it reads the file's path (`signingKeyPath` in `scripts/merge-queue/compose.mjs`) and
|
||||
hands it to git as configuration of the `commit-tree` call alone (`gpg.format=ssh`,
|
||||
`user.signingkey=<path>`), through the environment (`GIT_CONFIG_COUNT`/`KEY`/`VALUE`), never as an
|
||||
argument. Neither the key nor its path is written to a log line, an event, the state, a comment or
|
||||
an error message. The step's script, which GitHub prints, names `$RUNNER_TEMP/omni-queue-signing/signing-key`
|
||||
unexpanded.
|
||||
|
||||
**A missing key or a failed signature never blocks the queue.** When signing is configured and the
|
||||
file is not there (no secret, a write that failed), or git cannot sign (a key that is not a valid
|
||||
unencrypted SSH private key, for example), the batch is composed unsigned, exactly as without
|
||||
signing, and one `error` event per batch says so: `<batchId>: <n> merge commit(s) composed
|
||||
unsigned: <cause>`, where the cause is
|
||||
`no signing key file in the job (is the OMNI_QUEUE_SIGNING_KEY secret set?)` or
|
||||
`git could not sign a merge commit (exit <code>)` (see [Merge commits composed
|
||||
unsigned](#merge-commits-composed-unsigned)). This "degrade and alert" choice keeps the queue
|
||||
landing when the key breaks; an unsigned queue merge commit then lands without the Verified badge.
|
||||
|
||||
**What verifies a candidate does not read signatures.** `verifyComposition` and every other reader
|
||||
of a candidate (`mergedPrsBetween`, `candidate-base.mjs`, `history-map.mjs`) read trees, parents
|
||||
and messages (`%B`, which never contains the `gpgsig` header): a signed candidate verifies exactly
|
||||
as the unsigned composition of the same inputs, and a signed commit with another tree, other
|
||||
parents or other trailers is refused as before
|
||||
(`tests/unit/merge-queue/integration/compose-signing.test.mjs` signs with a real ed25519 key and
|
||||
checks the result with `git verify-commit`).
|
||||
|
||||
**The owner's setup**, once, before `signing` is set to `ssh` (GitHub's rules:
|
||||
[About commit signature verification](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification),
|
||||
[Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account),
|
||||
[Telling Git about your signing key](https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key)):
|
||||
|
||||
1. Generate a dedicated key, used for nothing else, without a passphrase (the job cannot type one):
|
||||
`ssh-keygen -t ed25519 -N "" -C "omni-queue merge commits" -f omni-queue-signing`.
|
||||
2. On the account of `landing.identity` (Settings → SSH and GPG keys → New SSH key), add the public
|
||||
key `omni-queue-signing.pub` with the key type **Signing Key**. A key added as an authentication
|
||||
key does not verify commits; the same key used for both must be added twice, and this one
|
||||
should be a signing key only.
|
||||
3. Store the full contents of the private key file `omni-queue-signing` as the environment secret
|
||||
OMNI_QUEUE_SIGNING_KEY of the environment `omni-queue` (never at repository level).
|
||||
4. Delete both local files. The key exists only in the secret and, as a public key, on the account.
|
||||
5. In a separate change, set `landing.signing` to `ssh`.
|
||||
|
||||
GitHub shows a commit as **Verified** when its signature verifies against a signing key of the
|
||||
account; the committer of the queue's merge commits is `landing.identity`, the account's
|
||||
`@users.noreply.github.com` address. With vigilant mode on (Settings → SSH and GPG keys → "Flag
|
||||
unsigned commits as unverified"), every unsigned commit with that committer shows **Unverified**: a
|
||||
batch composed unsigned (above) would land so; GitHub advises vigilant mode only to people who sign
|
||||
every commit. The badge can only be proven on real GitHub: rehearse a landing in the rehearsal
|
||||
repository before production turns signing on.
|
||||
|
||||
**Rotation.** Generate a new key (step 1), add its public key as a signing key (step 2), replace the
|
||||
secret (step 3), delete the files, then remove the old public key from the account. GitHub keeps a
|
||||
verification record of every commit it verified: per the first page above, "once a commit signature
|
||||
is verified, it remains verified within its repository's network", "even if signing keys are
|
||||
rotated, revoked". If the key leaks, remove it from the account and rotate at once.
|
||||
|
||||
### Who speaks (`voice`)
|
||||
|
||||
The top-level `voice` key (shipped `app`) chooses whose token performs the queue's writes that
|
||||
people read on GitHub (`scripts/merge-queue/voice.mjs`). With `app`, every one is the App's
|
||||
(`omni-queue[bot]`). With `owner`, they go out with the owner's `OMNI_QUEUE_LAND_TOKEN`, the token the
|
||||
tick already holds for the landing (no second token secret), whatever `landing.actor` says. The
|
||||
full list is in [What appears as the owner and what appears as the App](#what-appears-as-the-owner-and-what-appears-as-the-app).
|
||||
|
||||
- **Reads stay the App's.** Every read (comments, issues, pull requests, statuses) uses the App's
|
||||
token; the owner's makes only the writes, plus one `GET /user` per run that reads the owner's
|
||||
login from the token itself.
|
||||
- **The queue still recognises its own comments.** A comment marker (the hidden key of
|
||||
`commentOnce`, which makes each comment once) counts only when the comment's author is
|
||||
`<appSlug>[bot]` or, with `voice: "owner"`, that login read from the token. A marker in anybody
|
||||
else's comment never counts. Switching `voice` back to `app` makes the owner's earlier comments
|
||||
unknown again: a comment the owner already posted may be posted once more by the App.
|
||||
- **Never a lost message.** Without `OMNI_QUEUE_LAND_TOKEN`, or when GitHub answers 401 or 403 to
|
||||
an owner write (or to the login read), the same write is made with the App's token at once.
|
||||
Each such write is a line in the tick's decisions
|
||||
(`owner voice: <write> written with the App's token (<cause>)`), and the first of the tick is an
|
||||
`error` event, `owner voice unavailable, written with the App's token instead: <cause>`, not
|
||||
repeated while the newest such event names the same cause (a token missing for days adds one
|
||||
event, not one per tick). A refused owner write never fails the tick. Any other error (a 5xx, a
|
||||
timeout) is handled as the App's own errors are: the next tick redoes the write. The failure path
|
||||
of a failed tick (the stalled alert, a missing dashboard) writes the same way and logs the
|
||||
fallback. See [Owner voice unavailable](#owner-voice-unavailable).
|
||||
- **Shadow mode** still writes nothing on a pull request. It writes the dashboard issue, its
|
||||
stalled alert and the base-red comments, so with `voice: "owner"` shadow mode uses the token
|
||||
too: without it those writes fall back to the App, with the event above.
|
||||
- **The approval job is the exception**: it never receives the owner's token (it runs on label
|
||||
events with minimal permissions), so its "not an approver" comment stays the App's. The tick's
|
||||
own `not-approver` comment for the same pull request then finds that one by its marker and posts
|
||||
nothing.
|
||||
- **Dashboard migration.** A tick finds the dashboard issue of a base by its exact title and the
|
||||
label `omni-queue-dashboard` among the open issues (the oldest wins), never by its author, and
|
||||
the queue never closes or recreates an issue by itself. An open dashboard opened by the App
|
||||
stays the App's issue: with `voice: "owner"` the owner edits its body and posts its comments. To
|
||||
have a dashboard opened by the owner: set `voice` to `owner`, close the old dashboard issue by
|
||||
hand, then dispatch a tick for that base (`workflow_dispatch`, action `tick`, its `base`). That
|
||||
tick opens a new dashboard with the configured voice. Dispatch it at once: a tick run without a
|
||||
base finds a base with no labeled pull request only through its open dashboard issue
|
||||
(`discoverBases` in `scripts/merge-queue/tick.mjs`), so until a tick of that base runs, a base
|
||||
whose only work is a pause or stored withdrawals is not visited.
|
||||
|
||||
## Eligibility
|
||||
|
||||
A PR can enter a batch only when **all** of these hold (`scripts/merge-queue/eligibility.mjs`;
|
||||
@@ -1164,41 +1050,40 @@ history holds a type the code does not know is refused, which matters for a roll
|
||||
[Cut-over and rollback](#cut-over-and-rollback)). `tests/unit/merge-queue/runbook.test.mjs` fails
|
||||
when this table and `EVENT_TYPES` differ.
|
||||
|
||||
| Event | When it happens | What the operator does |
|
||||
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `batch-started` | A candidate was composed and pushed: a new batch, a recomposition or a bisection segment. The detail names the PRs and the base, and for a root batch with `batch.adaptive` the window it was cut to (`window W`). A lane batch names its lane instead of a window (`lane hotfix` or `lane base-repair`). | Nothing. Its CI is linked from the dashboard. |
|
||||
| `pr-skipped-conflict` | A PR conflicts with an earlier PR of the same batch. It is left out of this candidate and stays queued for a later batch. | Nothing. If it repeats, the author rebases the PR over the one it conflicts with. |
|
||||
| `pr-dequeued` | A PR left the queue: `base-conflict` (it no longer merges into the base: label removed, comment), `already-in-base` (both labels removed, comment), or `withdrawn: <why>` before composition (label, head or approval changed). In shadow mode the first two are `would-dequeue` events instead. | For `base-conflict` the author updates the branch and an approver labels it again; the other cases need nothing. |
|
||||
| `checks-green` | Every required check of the candidate (or of a base check) concluded `success`. | Nothing. The landing (or `would-land`) follows. |
|
||||
| `checks-red` | A check of the candidate failed. The detail names the failing checks; on a base check it starts with `base-check red`. It ends with `; re-run refused (<status or reason>)` when the re-run of the failed jobs was refused. A batch red again after its re-run records a second one. | Nothing yet: classification follows (a re-run of the failed jobs, infra retry, base check, bisection or culprit). |
|
||||
| `flaky-rerun` | A red batch or bisection segment that would be bisected, tested against the base or dequeued: its failed jobs are re-run once after its runs end (`flakyReruns`). Detail: `re-running the failed jobs of <batch> once (<jobs>) before <bisecting\|a base check\|dequeuing #n>` (five jobs at most). A green re-run's `checks-green` reads `green after re-running <jobs> (flaky)`. | Nothing. A real failure is blamed later: after the rest of the CI run and the re-run. Jobs that often turn green on the re-run are flaky tests to fix. |
|
||||
| `checks-timeout` | No verdict after `checksTimeoutMinutes`, or no CI run at all after 45 minutes (`no CI run for candidate`). | For `no CI run`, check the Actions policies and the `omni-queue/**` triggers of `ci.yml` / `quality.yml` (see [Infra failure or timeout](#infra-failure-or-timeout)). |
|
||||
| `land-blessed` | Live mode: the App wrote the land status (`landing.statusContext`, `success`) on the commits about to land, right before the landing. | Nothing. A `landed` event should follow; if a pause follows, the status was withdrawn. |
|
||||
| `manual-bless` | An approver's `bless`: the App wrote the land status on one chosen commit. The detail names who and why. | Push or merge that commit yourself (see [Land status and manual bless](#land-status-and-manual-bless)). |
|
||||
| `landed` | Live mode: the batch reached the base (the `merge-ff` push or every `squash-api` merge). | Nothing. |
|
||||
| `would-land` | Shadow mode: a green batch that live mode would have landed. The detail can add `merged meanwhile by another path`, `live mode would pause: queue refs unprotected (…)` and, after the name of a check, `could not run (…): live mode would fail the tick`. | Compare with what Mergify merged. Both notes must be gone before `mode: "live"`: apply the queue-refs ruleset, or fix the check that could not run. |
|
||||
| `would-dequeue` | Shadow mode: live mode would have removed this PR from the queue (label kept, no comment). The detail gives the reason code(s). | Nothing during shadow. |
|
||||
| `land-rejected` | The batch was not landed: the base moved (`base moved…; recomposing`: the same PRs are recomposed on the tip), the batch changed before landing (`batch changed before landing: …`: the PRs left are recomposed), or a release-freeze holds it (`base-frozen: …; <batch> waits for the freeze to lift`, once per batch: it stays in flight, not recomposed, and lands after the freeze). | Nothing for an occasional one; frequent ones mean something else merges into the base (see [Recomposition when the base moves](#recomposition-when-the-base-moves)). |
|
||||
| `bisect-split` | A red batch (or a red segment of a bisection) is split; the detail names the segment tested next. | Nothing. |
|
||||
| `culprit-found` | Bisection or a batch of one isolated the PR that fails. Live: label removed, comment. Shadow, or a head that moved: label kept. | The author fixes the PR and an approver labels it again. |
|
||||
| `base-check-started` | A red batch on a base with no verdict: the bare base is pushed as a `basecheck-<sha12>` candidate. | Nothing. |
|
||||
| `base-red-paused` | The base check is red with the same failures as the batch: the base is paused with reason `base-red`. | Fix the base (see [Base-red](#base-red)). The pause lifts when the tip moves. |
|
||||
| `hang-suspected` | A job hit its time limit on every run of the candidate: treated as a hanging test (base check, then bisection) instead of an infra pause. | Nothing yet; look at the culprit comment when one is named. |
|
||||
| `infra-retry` | Every failure is infrastructure (or the checks timed out): the same SHA is retried under a new ref (`-r1`, `-r2`, …), while retries of `infraRetries` are left. The detail reads `retry <n>/<infraRetries>: …`. | Nothing. |
|
||||
| `infra-paused` | An infrastructure failure (or a timeout) with no retry of `infraRetries` left: the base is paused with reason `infra`. With the shipped `infraRetries: 1` that is the second failure; with `0`, the first. When every run only hit a job time limit, the outcome is `hang-suspected` instead (see its row). A base repair under a `base-red` pause is dropped instead, with an `error` event, and the `base-red` pause stays. | Check the Actions status and the candidate's run, then `npm run queue -- resume <base>`. |
|
||||
| `paused` | A manual pause (`npm run queue -- pause`, or `action=pause`). The detail is the reason, on one line, cut at 200 characters. | `npm run queue -- resume <base>` when ready. |
|
||||
| `resumed` | A manual resume (`manual resume (was <reason>)`, followed by `; the pause it cleared named commits kept nowhere (both lists full), check their <landing.statusContext> by hand: <sha> (<batchId>), …` when that pause named such commits), a `base-red` pause lifted because the base tip moved (`base moved <sha12> → <sha12> after a base-red pause`), or, in live mode, a `base-red` pause lifted because a PR of the base-repair lane landed (`base repaired by #<n>`). Neither automatic lift happens while `landWithdrawalsOverflow` holds entries: a tick replaces such a `base-red` pause with the full-list pause. | For a detail that names commits kept nowhere: check their land status by hand (see [Paused: landWithdrawals is full](#paused-landwithdrawals-is-full)). Otherwise nothing. |
|
||||
| `tree-divergence` | `squash-api` only: the base tree after the merges differs from the candidate tree, or an open divergence issue stops a landing. The base is paused with reason `tree-divergence`. | Compare the trees, fix the base, close the issue, resume (see [Tree divergence](#tree-divergence-squash-api-only)). |
|
||||
| `error` | A tick failed (the detail is its error message); a landing pause (reason `error`: land token, landing refused, composition mismatch, queue refs, base not found, attempts limit); a land-status withdrawal GitHub refused (`<batchId>: could not withdraw …`); a stored withdrawal refused for a day (`… has been refused for more than 24 h, since …; the queue keeps retrying it`); a refused withdrawal that found the `landWithdrawals` list (20) full, kept in `landWithdrawalsOverflow` (`landWithdrawals is full …`; it pauses a base that is not paused, or replaces a `base-red` pause, also one a tick loads together with overflow entries); a refused resume (`resume refused: …`, the pause stays); a candidate gone from origin (`… is gone from origin; recomposing …`), whose PRs are recomposed; check runs on the candidate that are no job of its push runs (`check runs on the candidate that are not jobs of its push runs, ignored for the verdict: …`, once per batch); a base repair dropped after an infrastructure failure under a `base-red` pause (`… failed for infrastructure after … dropped; the base-red pause stays`); a batch composed unsigned although `landing.signing` is `ssh` (`<batchId>: <n> merge commit(s) composed unsigned: …`, once per batch); the owner voice falling back to the App's token (`owner voice unavailable, written with the App's token instead: …`, at most once per tick). A tick that hit a rate limit while landing fails with `landing <batchId> hit a rate limit (…)`. The detail says which. | Read the detail: each pause detail, and each other `error` detail an operator must act on, has an entry in [Incidents](#incidents). A landing that fails on every tick ends in the pause after three attempts. |
|
||||
| `queue-stalled` | The queue stopped making progress: paused for more than 120 minutes (with reason `error` or `tree-divergence`, at once), a candidate in flight for more than `checksTimeoutMinutes` + 60, eligible PRs and nothing started for more than `batch.maxWaitMinutes` + 30, three ticks in a row that failed, a stored withdrawal refused for more than 60 minutes, or three landings in a row without a verdict. One per episode, with one comment on the dashboard issue that mentions the approvers (see [Health](#health)). The detail lists the reasons. | See [The queue stalled](#the-queue-stalled). |
|
||||
| Event | When it happens | What the operator does |
|
||||
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `batch-started` | A candidate was composed and pushed: a new batch, a recomposition or a bisection segment. The detail names the PRs and the base, and for a root batch with `batch.adaptive` the window it was cut to (`window W`). A lane batch names its lane instead of a window (`lane hotfix` or `lane base-repair`). | Nothing. Its CI is linked from the dashboard. |
|
||||
| `pr-skipped-conflict` | A PR conflicts with an earlier PR of the same batch. It is left out of this candidate and stays queued for a later batch. | Nothing. If it repeats, the author rebases the PR over the one it conflicts with. |
|
||||
| `pr-dequeued` | A PR left the queue: `base-conflict` (it no longer merges into the base: label removed, comment), `already-in-base` (both labels removed, comment), or `withdrawn: <why>` before composition (label, head or approval changed). In shadow mode the first two are `would-dequeue` events instead. | For `base-conflict` the author updates the branch and an approver labels it again; the other cases need nothing. |
|
||||
| `checks-green` | Every required check of the candidate (or of a base check) concluded `success`. | Nothing. The landing (or `would-land`) follows. |
|
||||
| `checks-red` | A check of the candidate failed. The detail names the failing checks; on a base check it starts with `base-check red`. It ends with `; re-run refused (<status or reason>)` when the re-run of the failed jobs was refused. A batch red again after its re-run records a second one. | Nothing yet: classification follows (a re-run of the failed jobs, infra retry, base check, bisection or culprit). |
|
||||
| `flaky-rerun` | A red batch or bisection segment that would be bisected, tested against the base or dequeued: its failed jobs are re-run once after its runs end (`flakyReruns`). Detail: `re-running the failed jobs of <batch> once (<jobs>) before <bisecting\|a base check\|dequeuing #n>` (five jobs at most). A green re-run's `checks-green` reads `green after re-running <jobs> (flaky)`. | Nothing. A real failure is blamed later: after the rest of the CI run and the re-run. Jobs that often turn green on the re-run are flaky tests to fix. |
|
||||
| `checks-timeout` | No verdict after `checksTimeoutMinutes`, or no CI run at all after 45 minutes (`no CI run for candidate`). | For `no CI run`, check the Actions policies and the `omni-queue/**` triggers of `ci.yml` / `quality.yml` (see [Infra failure or timeout](#infra-failure-or-timeout)). |
|
||||
| `land-blessed` | Live mode: the App wrote the land status (`landing.statusContext`, `success`) on the commits about to land, right before the landing. | Nothing. A `landed` event should follow; if a pause follows, the status was withdrawn. |
|
||||
| `manual-bless` | An approver's `bless`: the App wrote the land status on one chosen commit. The detail names who and why. | Push or merge that commit yourself (see [Land status and manual bless](#land-status-and-manual-bless)). |
|
||||
| `landed` | Live mode: the batch reached the base (the `merge-ff` push or every `squash-api` merge). | Nothing. |
|
||||
| `would-land` | Shadow mode: a green batch that live mode would have landed. The detail can add `merged meanwhile by another path`, `live mode would pause: queue refs unprotected (…)` and, after the name of a check, `could not run (…): live mode would fail the tick`. | Compare with what Mergify merged. Both notes must be gone before `mode: "live"`: apply the queue-refs ruleset, or fix the check that could not run. |
|
||||
| `would-dequeue` | Shadow mode: live mode would have removed this PR from the queue (label kept, no comment). The detail gives the reason code(s). | Nothing during shadow. |
|
||||
| `land-rejected` | The batch was not landed: the base moved (`base moved…; recomposing`: the same PRs are recomposed on the tip), the batch changed before landing (`batch changed before landing: …`: the PRs left are recomposed), or a release-freeze holds it (`base-frozen: …; <batch> waits for the freeze to lift`, once per batch: it stays in flight, not recomposed, and lands after the freeze). | Nothing for an occasional one; frequent ones mean something else merges into the base (see [Recomposition when the base moves](#recomposition-when-the-base-moves)). |
|
||||
| `bisect-split` | A red batch (or a red segment of a bisection) is split; the detail names the segment tested next. | Nothing. |
|
||||
| `culprit-found` | Bisection or a batch of one isolated the PR that fails. Live: label removed, comment. Shadow, or a head that moved: label kept. | The author fixes the PR and an approver labels it again. |
|
||||
| `base-check-started` | A red batch on a base with no verdict: the bare base is pushed as a `basecheck-<sha12>` candidate. | Nothing. |
|
||||
| `base-red-paused` | The base check is red with the same failures as the batch: the base is paused with reason `base-red`. | Fix the base (see [Base-red](#base-red)). The pause lifts when the tip moves. |
|
||||
| `hang-suspected` | A job hit its time limit on every run of the candidate: treated as a hanging test (base check, then bisection) instead of an infra pause. | Nothing yet; look at the culprit comment when one is named. |
|
||||
| `infra-retry` | Every failure is infrastructure (or the checks timed out): the same SHA is retried under a new ref (`-r1`, `-r2`, …), while retries of `infraRetries` are left. The detail reads `retry <n>/<infraRetries>: …`. | Nothing. |
|
||||
| `infra-paused` | An infrastructure failure (or a timeout) with no retry of `infraRetries` left: the base is paused with reason `infra`. With the shipped `infraRetries: 1` that is the second failure; with `0`, the first. When every run only hit a job time limit, the outcome is `hang-suspected` instead (see its row). A base repair under a `base-red` pause is dropped instead, with an `error` event, and the `base-red` pause stays. | Check the Actions status and the candidate's run, then `npm run queue -- resume <base>`. |
|
||||
| `paused` | A manual pause (`npm run queue -- pause`, or `action=pause`). The detail is the reason, on one line, cut at 200 characters. | `npm run queue -- resume <base>` when ready. |
|
||||
| `resumed` | A manual resume (`manual resume (was <reason>)`, followed by `; the pause it cleared named commits kept nowhere (both lists full), check their <landing.statusContext> by hand: <sha> (<batchId>), …` when that pause named such commits), a `base-red` pause lifted because the base tip moved (`base moved <sha12> → <sha12> after a base-red pause`), or, in live mode, a `base-red` pause lifted because a PR of the base-repair lane landed (`base repaired by #<n>`). Neither automatic lift happens while `landWithdrawalsOverflow` holds entries: a tick replaces such a `base-red` pause with the full-list pause. | For a detail that names commits kept nowhere: check their land status by hand (see [Paused: landWithdrawals is full](#paused-landwithdrawals-is-full)). Otherwise nothing. |
|
||||
| `tree-divergence` | `squash-api` only: the base tree after the merges differs from the candidate tree, or an open divergence issue stops a landing. The base is paused with reason `tree-divergence`. | Compare the trees, fix the base, close the issue, resume (see [Tree divergence](#tree-divergence-squash-api-only)). |
|
||||
| `error` | A tick failed (the detail is its error message); a landing pause (reason `error`: land token, landing refused, composition mismatch, queue refs, base not found, attempts limit); a land-status withdrawal GitHub refused (`<batchId>: could not withdraw …`); a stored withdrawal refused for a day (`… has been refused for more than 24 h, since …; the queue keeps retrying it`); a refused withdrawal that found the `landWithdrawals` list (20) full, kept in `landWithdrawalsOverflow` (`landWithdrawals is full …`; it pauses a base that is not paused, or replaces a `base-red` pause, also one a tick loads together with overflow entries); a refused resume (`resume refused: …`, the pause stays); a candidate gone from origin (`… is gone from origin; recomposing …`), whose PRs are recomposed; check runs on the candidate that are no job of its push runs (`check runs on the candidate that are not jobs of its push runs, ignored for the verdict: …`, once per batch); a base repair dropped after an infrastructure failure under a `base-red` pause (`… failed for infrastructure after … dropped; the base-red pause stays`). A tick that hit a rate limit while landing fails with `landing <batchId> hit a rate limit (…)`. The detail says which. | Read the detail: each pause detail, and each other `error` detail an operator must act on, has an entry in [Incidents](#incidents). A landing that fails on every tick ends in the pause after three attempts. |
|
||||
| `queue-stalled` | The queue stopped making progress: paused for more than 120 minutes (with reason `error` or `tree-divergence`, at once), a candidate in flight for more than `checksTimeoutMinutes` + 60, eligible PRs and nothing started for more than `batch.maxWaitMinutes` + 30, three ticks in a row that failed, a stored withdrawal refused for more than 60 minutes, or three landings in a row without a verdict. One per episode, with one comment on the dashboard issue that mentions the approvers (see [Health](#health)). The detail lists the reasons. | See [The queue stalled](#the-queue-stalled). |
|
||||
|
||||
## Configuration keys
|
||||
|
||||
`config/merge-queue/config.json`, validated by `validateConfig` in `scripts/merge-queue/config.mjs`.
|
||||
The workflow reads the copy on the default branch. Every key without a default is required, except
|
||||
`landing.identity`, which is required or refused depending on `landing.actor` (see its row), and
|
||||
`landing.signing: "ssh"`, which needs `landing.actor: "owner"`. An unknown key, top-level or in
|
||||
`batch`, `landing`, `landing.identity` or `lanes`, is refused.
|
||||
`landing.identity`, which is required or refused depending on `landing.actor` (see its row). An
|
||||
unknown key, top-level or in `batch`, `landing`, `landing.identity` or `lanes`, is refused.
|
||||
"Shipped" is the value in the config file of this repository.
|
||||
`tests/unit/merge-queue/runbook.test.mjs` fails when this table and the keys `validateConfig` reads
|
||||
differ.
|
||||
@@ -1221,7 +1106,6 @@ differ.
|
||||
| `landing.mode` | `merge-ff` or `squash-api` | none; shipped `merge-ff` | How a green batch lands (see [Landing modes](#landing-modes-landingmode)). |
|
||||
| `landing.actor` | `app` or `owner` | `app`; shipped `owner` | Whose token lands: the App's, or `OMNI_QUEUE_LAND_TOKEN` (see [Who lands](#who-lands-landingactor)). |
|
||||
| `landing.identity` | `{name, email}`, the email a `@users.noreply.github.com` one | none; required with `actor: "owner"`, refused otherwise | Identity of the queue's merge commits when the owner lands. |
|
||||
| `landing.signing` | `none` or `ssh` | `none`; shipped `none` | `ssh` signs every merge commit the queue composes with the key of the secret OMNI_QUEUE_SIGNING_KEY; refused unless `landing.actor` is `owner` (see [Signed merge commits](#signed-merge-commits-landingsigning)). |
|
||||
| `landing.statusContext` | `omni-queue/<name>`, `[A-Za-z0-9._/-]{1,100}` | `omni-queue/land`; shipped `omni-queue/land` | The land status the release ruleset requires. Must not be a required, aggregate or approval context. |
|
||||
| `requiredChecks` | list of check names, at least one | none; shipped three checks | Checks that must conclude `success` on a candidate (see [Accepting a candidate](#accepting-a-candidate)). |
|
||||
| `advisoryChecks` | list of check names, none in `requiredChecks` | none; shipped `Build (advisory)` | Checks whose failure does not make a candidate red. |
|
||||
@@ -1234,7 +1118,6 @@ differ.
|
||||
| `prChecksRequired` | list of distinct check names | `[]`; shipped `Gate / CI`, `Gate / Quality`, `API Route Typecheck` | Green on a PR head to enter a batch: worst of the suites reporting it; if they disagree, a run superseded by a newer run of the same workflow and event drops ([Eligibility](#eligibility)). |
|
||||
| `protectedPaths` | list of globs, at least one | none; shipped the agent-instruction surfaces and the queue's control plane | A PR that touches one also needs `protectedApprovalLabel` (see [Eligibility](#eligibility)). |
|
||||
| `lanes.hotfixLabel` | label name, distinct from every other label of the config | no `lanes` = no lanes; shipped `omni-queue-hotfix` | Applied by an approver to an eligible PR: at the next batch start it is composed alone, ahead of the FIFO. Never replaces what is in flight. Repeated in the tick's job filter. |
|
||||
| `voice` | `app` or `owner` | `app`; shipped `app` | Whose token posts the queue's comments, removes its labels and writes its issues: the App's, or `OMNI_QUEUE_LAND_TOKEN`, with a fallback to the App's (see [Who speaks](#who-speaks-voice)). |
|
||||
| `lanes.baseRepairLabel` | label name, distinct from every other label of the config | no `lanes` = no lanes; shipped `omni-queue-base-repair` | Applied by an approver: composed alone (PR gates not required), the only work of a `base-red` pause; its landing lifts the pause. Never in a FIFO batch. Repeated in the tick's job filter. A repair that fails like the base is not composed again at that head (`repairTried`): push a fix (a new head is tried again), or remove this label (anyone who can label the PR can): the PR rejoins the FIFO. |
|
||||
|
||||
## CLI
|
||||
@@ -1543,16 +1426,16 @@ action.
|
||||
3. **Homepage URL**: the repository URL. **Webhook**: untick "Active" (the queue needs no webhook).
|
||||
4. **Repository permissions**:
|
||||
|
||||
| Permission | Access | What the queue does with it |
|
||||
| --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Contents | Read and write | tick: push candidate branches, read and write `state/<base>.json` on `omni-queue-state`, delete candidate branches, read base tips and commits; with `landing.actor: "app"`, the landing push or merges too. approval: read |
|
||||
| Pull requests | Read and write | tick: read each queued PR (head, base, files, mergeability); write: only the per-PR merge of `squash-api` with `landing.actor: "app"` (`PUT /repos/{owner}/{repo}/pulls/{n}/merge`). Labels and comments on PRs go through the issues endpoints. With the shipped config (`owner`, `merge-ff`) no call of the App uses write here. approval: read the PR |
|
||||
| Issues | Read and write | tick: the dashboard issue and its stalled comment, comments on the `base-red` issue, the tree-divergence issue, reading `release-freeze` issues and PR timelines, removing labels from and commenting on PRs (live mode only); with `voice: "owner"` the App makes these writes only when the owner's token is missing or refused. approval: the "not an approver" comment |
|
||||
| Commit statuses | Read and write | approval: write `omni-queue/approval` and `omni-queue/protected-approval`. tick: read them, write and withdraw the land status, `bless` |
|
||||
| Workflows | Read and write | tick: push a candidate (and, with `landing.actor: "app"`, land it) when a PR of the batch changes a file under `.github/workflows/` |
|
||||
| Checks | Read-only | tick: the check runs and annotations of a candidate, and the PR gates of a PR head |
|
||||
| Actions | Read and write | tick: list the workflow runs of a candidate ref and of a PR head (read); re-run the failed jobs of a red candidate (write, `flakyReruns`) |
|
||||
| Metadata | Read-only | always granted |
|
||||
| Permission | Access | What the queue does with it |
|
||||
| --------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Contents | Read and write | tick: push candidate branches, read and write `state/<base>.json` on `omni-queue-state`, delete candidate branches, read base tips and commits; with `landing.actor: "app"`, the landing push or merges too. approval: read |
|
||||
| Pull requests | Read and write | tick: read each queued PR (head, base, files, mergeability); write: only the per-PR merge of `squash-api` with `landing.actor: "app"` (`PUT /repos/{owner}/{repo}/pulls/{n}/merge`). Labels and comments on PRs go through the issues endpoints. With the shipped config (`owner`, `merge-ff`) no call of the App uses write here. approval: read the PR |
|
||||
| Issues | Read and write | tick: the dashboard issue and its stalled comment, comments on the `base-red` issue, the tree-divergence issue, reading `release-freeze` issues and PR timelines, removing labels from and commenting on PRs (live mode only). approval: the "not an approver" comment |
|
||||
| Commit statuses | Read and write | approval: write `omni-queue/approval` and `omni-queue/protected-approval`. tick: read them, write and withdraw the land status, `bless` |
|
||||
| Workflows | Read and write | tick: push a candidate (and, with `landing.actor: "app"`, land it) when a PR of the batch changes a file under `.github/workflows/` |
|
||||
| Checks | Read-only | tick: the check runs and annotations of a candidate, and the PR gates of a PR head |
|
||||
| Actions | Read and write | tick: list the workflow runs of a candidate ref and of a PR head (read); re-run the failed jobs of a red candidate (write, `flakyReruns`) |
|
||||
| Metadata | Read-only | always granted |
|
||||
|
||||
Each job mints its token with only part of this (the `approval` job: contents and pull requests
|
||||
read, issues and statuses write; the `tick` job: everything above). The tick also reads the
|
||||
@@ -1605,9 +1488,6 @@ action.
|
||||
Secrets: OMNI_QUEUE_APP_CLIENT_ID the Client ID from step 5
|
||||
OMNI_QUEUE_APP_PRIVATE_KEY the full contents of the .pem from step 6
|
||||
OMNI_QUEUE_LAND_TOKEN the owner's fine-grained token (see below)
|
||||
OMNI_QUEUE_SIGNING_KEY optional: the owner's SSH signing key, only
|
||||
for landing.signing "ssh" (see Signed merge
|
||||
commits)
|
||||
Repository variable (Settings → Secrets and variables → Actions → Variables)
|
||||
OMNI_QUEUE_ENABLED "true" only when the queue should run
|
||||
```
|
||||
@@ -1620,24 +1500,7 @@ action.
|
||||
write the expiry date down and rotate it before then. GitHub requires the Workflows permission
|
||||
for a push of commits that change files under `.github/workflows/`, and the landing is made with
|
||||
this token: without it, the landing of every batch that touches a workflow is refused. The token
|
||||
is optional while the queue runs in shadow mode (see [Who lands](#who-lands-landingactor)),
|
||||
unless `voice` is `owner`.
|
||||
|
||||
With `voice: "owner"` ([Who speaks](#who-speaks-voice)) the same token also needs **Issues: Read
|
||||
and write**: opening and updating an issue (the dashboard, the tree-divergence issue) and
|
||||
commenting on an issue (the dashboard, the `base-red` issue) are Issues endpoints. Comments on
|
||||
pull requests and the removal of a label from a pull request are already covered by Pull
|
||||
requests: Read and write. GitHub's table of
|
||||
[permissions required for fine-grained personal access tokens](https://docs.github.com/en/rest/authentication/permissions-required-for-fine-grained-personal-access-tokens)
|
||||
lists `POST /repos/{owner}/{repo}/issues` under Issues (write) only;
|
||||
`PATCH /repos/{owner}/{repo}/issues/{issue_number}`,
|
||||
`POST /repos/{owner}/{repo}/issues/{issue_number}/comments`,
|
||||
`DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}` and
|
||||
`DELETE /repos/{owner}/{repo}/issues/{issue_number}/labels/{name}` under both Issues (write) and
|
||||
Pull requests (write), marked as needing additional permissions, which on an issue are Issues.
|
||||
The tick also reads the owner's login with `GET /user`, which that table does not list. A
|
||||
missing permission is a 403: the write is made by the App (see [Who speaks](#who-speaks-voice)),
|
||||
and the `error` event names it.
|
||||
is optional while the queue runs in shadow mode (see [Who lands](#who-lands-landingactor)).
|
||||
|
||||
Both jobs of `.github/workflows/omni-queue.yml` declare this environment with
|
||||
`deployment: false`: they get its secrets and its branch policy, and no deployment record is
|
||||
@@ -1694,9 +1557,7 @@ this order:
|
||||
exact name, step 8 above);
|
||||
2. put its secrets in it: OMNI_QUEUE_APP_CLIENT_ID and OMNI_QUEUE_APP_PRIVATE_KEY, and
|
||||
`OMNI_QUEUE_LAND_TOKEN`. A shadow run never lands, so it works without the land token, but a live
|
||||
landing needs it: have it in place at the latest before `mode: "live"`, and before `voice` is
|
||||
set to `owner` (shadow mode writes the dashboard issue with it). OMNI_QUEUE_SIGNING_KEY only
|
||||
before `landing.signing` is set to `ssh`;
|
||||
landing needs it: have it in place at the latest before `mode: "live"`;
|
||||
3. check that the App's installation has every permission of step 4 above, Actions: Read and
|
||||
write included, and that the labels of step 9 exist;
|
||||
4. in a public repository, create the Actions policy that allows the events of
|
||||
@@ -2010,38 +1871,6 @@ the pause. While no ruleset requiring the status is applied to the branch (the c
|
||||
before the cut-over), a bless changes nothing about what can be pushed: it only records the status
|
||||
and the event.
|
||||
|
||||
## What appears as the owner and what appears as the App
|
||||
|
||||
With the shipped config (`landing.actor: "owner"`, `voice: "app"`, `landing.signing: "none"`):
|
||||
|
||||
| On GitHub | Appears as |
|
||||
| --------------------------------------------------------------- | ---------------------------------------- |
|
||||
| "merged by" on a landed pull request (the `merge-ff` push) | the owner (`OMNI_QUEUE_LAND_TOKEN`) |
|
||||
| author and committer of the queue's merge commits | `landing.identity` (the owner), unsigned |
|
||||
| every comment on a pull request, every label removal | the App (`omni-queue[bot]`) |
|
||||
| the dashboard issue, its body, its comments (the stalled alert) | the App |
|
||||
| comments on the `base-red` issue, the tree-divergence issue | the App |
|
||||
| commit statuses (`omni-queue/land`, both approvals, a bless) | the App, always |
|
||||
|
||||
With `voice: "owner"` the third to fifth rows become the owner (each one the App's again when the
|
||||
owner's token is missing or refused), and with `landing.signing: "ssh"` the merge commits are
|
||||
signed with the owner's key.
|
||||
|
||||
**Always the App, whatever the config**, and why:
|
||||
|
||||
- every commit status: `omni-queue/land` (the release ruleset's door pins it to the App's
|
||||
integration id), `omni-queue/approval`, `omni-queue/protected-approval`, a `bless`;
|
||||
- candidate branches `omni-queue/**` and the `omni-queue-state` branch (the queue-refs ruleset
|
||||
admits the App only);
|
||||
- re-runs of a candidate's failed jobs;
|
||||
- every read, including the comment listings the markers are checked against;
|
||||
- the `approval` job's "not an approver" comment: that job never receives the owner's token;
|
||||
- a write the owner's token cannot make (missing token, 401 or 403): the App makes it instead, and
|
||||
an `error` event says so.
|
||||
|
||||
**The watchdog speaks as `github-actions[bot]`**: its issue and comments use the workflow's own
|
||||
token on purpose, so it works when the environment's secrets fail.
|
||||
|
||||
## Security posture
|
||||
|
||||
- **No PR code runs in the queue workflow.** Both jobs check out the default branch (sparse:
|
||||
@@ -2058,18 +1887,7 @@ token on purpose, so it works when the environment's secrets fail.
|
||||
trigger on candidate branches.
|
||||
- **Least privilege**: one App token per job with only the permissions that job needs; the
|
||||
workflow's own `GITHUB_TOKEN` is read-only. The owner's `OMNI_QUEUE_LAND_TOKEN` reaches only the
|
||||
tick step; the landing uses it with `landing.actor: "owner"`, and the queue's comments, label
|
||||
removals and issues with `voice: "owner"` (never a commit status, a ref, the state branch or a
|
||||
re-run). The `approval` job never receives it.
|
||||
- **The signing key** (OMNI_QUEUE_SIGNING_KEY, `landing.signing: "ssh"`) reaches one step of the
|
||||
tick job, which writes it to a `0600` file under `RUNNER_TEMP`; the job's last step removes it
|
||||
(`if: always()`). git gets the path as per-command configuration through the environment, never
|
||||
as an argument; no log line, event, state, comment or error message holds the key or its path.
|
||||
A signature changes nothing the queue verifies (see
|
||||
[Signed merge commits](#signed-merge-commits-landingsigning)).
|
||||
- **Comment markers are trusted by author**: only markers written by `<appSlug>[bot]`, or by the
|
||||
owner's login read from the owner's token itself, count; a marker anybody else writes is
|
||||
ignored.
|
||||
tick step, and only the landing uses it.
|
||||
- **The App key is the root of trust of the status door.** Whoever can use it can write the land
|
||||
status on any commit. Both jobs run in the `omni-queue` environment, which holds the App's
|
||||
credentials and the land token and admits the default branch only, so a workflow on a candidate
|
||||
@@ -2079,9 +1897,6 @@ token on purpose, so it works when the environment's secrets fail.
|
||||
message and escaped in the dashboard; git runs through `scripts/merge-queue/gitexec.mjs` (no
|
||||
shell, token in the environment as an HTTP header, OMNI_QUEUE_TOKEN and `OMNI_QUEUE_LAND_TOKEN`
|
||||
removed from the environment of every git process, redacted errors).
|
||||
- **One thing still speaks as `github-actions[bot]`**: the watchdog
|
||||
(`.github/workflows/omni-queue-watchdog.yml`, `scripts/merge-queue/watchdog.mjs`) uses its
|
||||
workflow's own token on purpose, so it keeps working when the environment's secrets fail.
|
||||
- **Approvals are bound to SHAs**, never to commit dates (see [Eligibility](#eligibility)).
|
||||
|
||||
## Incidents
|
||||
@@ -2345,31 +2160,6 @@ discovery (red runs with `setup failed` or `base discovery failed`, see
|
||||
that is pending forever (only one tick runs at a time, by design); a closed dashboard issue, on a
|
||||
base whose only work is not a labeled PR (see [State](#state)).
|
||||
|
||||
### Owner voice unavailable
|
||||
|
||||
`error` event `owner voice unavailable, written with the App's token instead: <cause>` (with
|
||||
`voice: "owner"`). Nothing was lost: every write of that tick was made by the App. By cause:
|
||||
|
||||
- `OMNI_QUEUE_LAND_TOKEN is not set`: put the token in the environment `omni-queue`;
|
||||
- `GitHub refused the owner's token (401)` or `… reading its login (401)`: the token expired or was
|
||||
revoked: rotate it;
|
||||
- `GitHub refused the owner's token (403)`: a permission is missing, most often Issues: Read and
|
||||
write (see [Installing the GitHub App](#installing-the-github-app), step 8);
|
||||
- `the owner's token does not name a user account`: the secret holds some other token.
|
||||
|
||||
The event is not repeated while the cause stays the same; the decisions of every tick that falls
|
||||
back say which write did.
|
||||
|
||||
### Merge commits composed unsigned
|
||||
|
||||
`error` event `<batchId>: <n> merge commit(s) composed unsigned: <cause>` (with
|
||||
`landing.signing: "ssh"`). The batch was composed, tested and (live) lands as usual, without the
|
||||
signature. `no signing key file in the job …`: the secret OMNI_QUEUE_SIGNING_KEY is missing from
|
||||
the environment or the step that writes it warned that it could not. `git could not sign a merge
|
||||
commit (exit <code>)`: the secret is not an unencrypted SSH private key (a passphrase, a public key,
|
||||
a truncated paste); store the private key file's full contents again. To stop signing, set
|
||||
`landing.signing` back to `none`.
|
||||
|
||||
### Dequeued PR
|
||||
|
||||
What you see, in live mode: a comment on the PR that starts "❌ omni-queue isolated this PR as the
|
||||
|
||||
@@ -340,8 +340,6 @@ OmniRoute provides a two-layer defense: request-side injection scanning and resp
|
||||
| `OMNIROUTE_DISABLE_CONVERSATION_TRACKING` | _(unset)_ | `open-sse/services/conversationTracker.ts` | Set `1` to stop collecting conversation history. `resolveConversationId()` returns an untracked result before it reads SQLite or parses message history, and client-supplied session IDs are covered too. Routing-session handling is unchanged and existing records are not deleted. For deployments that do not use the dashboard's conversation view and want the turn table to stop growing. |
|
||||
| `OMNIROUTE_NADIR_API_KEY` | _(unset)_ | `open-sse/services/autoCombo/nadirStrategy.ts` | API key for the opt-in `nadir` auto-combo router strategy, used when the combo's own `config.nadir.apiKey` is unset. Optional: keyless calls land on Nadir's anonymous tier, which is rate-limited per IP and so is not usable behind a shared gateway. Sensitive; prefer the per-combo field when combos use different accounts. |
|
||||
| `OMNIROUTE_NADIR_BASE_URL` | `https://api.getnadir.com` | `open-sse/services/autoCombo/nadirStrategy.ts` | Base origin of the Nadir decision API, used when the combo's own `config.nadir.baseUrl` is unset. Only needed for a self-hosted Nadir, which keeps prompt heads inside your own network. A trailing `/v1` is tolerated and stripped. |
|
||||
| `OMNIROUTE_DECISION_API_KEY` | _(unset)_ | `open-sse/services/decision/credentials.ts` | Key sent as a Bearer token by the `decision` auto-combo router's network deciders (`systemone`, `http`) when the combo's `config.decision.connectionId` is unset and, for `systemone`, no `typesafe` connection is in scope. A combo never stores a key. Only read while the default-off `COMBO_DECISION_ROUTER_ENABLED` feature flag is on. Sensitive. |
|
||||
| `COMBO_DECISION_ROUTER_ENABLED` | `false` | `src/shared/constants/featureFlagDefinitionsSystemOne.ts`| Opt-in feature flag (see [FEATURE_FLAGS.md](./FEATURE_FLAGS.md); a dashboard DB override wins). Lets combos using the `decision` router strategy call their decider. Off: no credential read, no call, the combo routes with `rules`. |
|
||||
| `OMNIROUTE_API_KEY_WEEKLY_WINDOW` | `provider` | `src/lib/usage/apiKeyUsageLimits.ts` | Weekly window for per-API-key USD usage limits (request enforcement, `GET /api/keys/{id}/usage-limits`, `@@om-usage`). `provider`: the week ends at the earliest weekly reset among the upstream connections the key can reach, or is a rolling 7 days when none is known. `calendar`: the local week from Monday 00:00 to the next Monday 00:00, identical for every key. `calendar` is recommended when one pool of upstream accounts is shared by many individually budgeted keys. Invalid values fall back to `provider`. |
|
||||
| `OMNIROUTE_API_KEY_WEEKLY_WINDOW_TIMEZONE` | _(process timezone)_ | `src/lib/usage/apiKeyUsageLimits.ts` | IANA timezone (for example `Asia/Shanghai`) that defines Monday 00:00 for the `calendar` weekly window. Unset or invalid: the timezone of the OmniRoute process (the `TZ` of the host or container, which is often unset, i.e. Coordinated Universal Time, in container images). Ignored in `provider` mode. |
|
||||
| `OMNIROUTE_MAX_TOOLS_LIMIT` | `128` | `open-sse/config/constants.ts` | Default maximum number of tools allowed in a request (OpenAI default). Positive integers only; unset or invalid values keep `128`. A provider with a known/proactive limit (`grok-cli` 200, `nvidia` 1536) still applies its own cap — this only moves the default ceiling. Claude-format targets have no default cap (the Messages API has none); a learned limit still applies. |
|
||||
@@ -931,7 +929,6 @@ REQUEST_TIMEOUT_MS (global override)
|
||||
| `OMNIROUTE_AGENT_GOAL_READINESS_MAX_TIMEOUT_MS` | `600000` | Maximum first-event readiness window for detected `/goal` agent runs or requests forced with `x-omniroute-agent-goal`. |
|
||||
| `OMNIROUTE_AGENT_GOAL_STREAM_RECOVERY` | `true` | Enable early stream recovery automatically for detected `/goal` agent runs. Set `false`/`0`/`off` to disable the goal-specific opt-in. This can only ADD recovery on top of the operator default — it never overrides an explicit `STREAM_RECOVERY_ENABLED`/DB settings opt-out. |
|
||||
| `OMNIROUTE_CODEX_DROP_NONSTANDARD_EVENTS` | `true` | Strip non-standard `codex.*` SSE events (e.g. `codex.rate_limits`) that break the OpenAI SDK's `responses.stream()` with a 502. Default ON (#11014). Set `0`/`false`/`no`/`off` to forward them. |
|
||||
| `OMNIROUTE_CODEX_PLAN_RESPONSE_HEADER` | `0` (off) | Opt-in Codex OAuth troubleshooting response header. Set to `1` to emit `X-OmniRoute-Selected-Connection-Plan` with the recognized plan tier of the selected Codex connection. Not sent for non-Codex requests or unrecognized plans. Avoid enabling on public or multi-tenant gateways where subscription metadata is private. |
|
||||
| `OMNIROUTE_CODEX_APPSERVER_WS` | _(unset)_ | Opt-in Codex app-server transport. WebSocket endpoint (`ws://`/`wss://`) of a local `codex app-server` sidecar. When set together with a token, Codex requests are routed over JSON-RPC to the sidecar instead of the HTTP Responses API. Also settable per-connection via `providerSpecificData.codexAppServerUrl`. Used by `open-sse/executors/codex/appServerConfig.ts`. |
|
||||
| `OMNIROUTE_CODEX_APPSERVER_WS_TOKEN` | _(unset)_ | Inline capability/bearer token presented to the app-server. Per-connection override: `providerSpecificData.codexAppServerToken`. |
|
||||
| `OMNIROUTE_CODEX_APPSERVER_WS_TOKEN_FILE` | _(unset)_ | Path to a file holding the app-server capability token (from `codex app-server --ws-token-file`). Used when `OMNIROUTE_CODEX_APPSERVER_WS_TOKEN` is unset. Per-connection override: `providerSpecificData.codexAppServerTokenFile`. |
|
||||
|
||||
@@ -46,26 +46,25 @@ A boolean flag is considered **enabled** when its effective value is `"true"`,
|
||||
|
||||
## Flag Catalog
|
||||
|
||||
128 flags across 6 categories. **Default** is the definition default — the value
|
||||
126 flags across 6 categories. **Default** is the definition default — the value
|
||||
used when neither a DB override nor an environment variable is present.
|
||||
|
||||
### Security (13)
|
||||
### Security (12)
|
||||
|
||||
| Key | Type | Default | Description |
|
||||
| --------------------------------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `REQUIRE_API_KEY` | boolean | `false` | Require an API key for all incoming requests. |
|
||||
| `INPUT_SANITIZER_ENABLED` | boolean | `true` | Enable input sanitization for all requests. |
|
||||
| `INJECTION_GUARD_MODE` | enum | `off` | Prompt injection guard mode. Values: `off`, `warn`, `block`, `redact`. |
|
||||
| `PII_REDACTION_ENABLED` | boolean | `false` | Redact PII from requests (independent of `INPUT_SANITIZER_MODE`). |
|
||||
| `PII_RESPONSE_SANITIZATION` | boolean | `false` | Sanitize PII from provider responses. |
|
||||
| `PII_RESPONSE_SANITIZATION_MODE` | enum | `redact` | Mode for PII response sanitization. Values: `redact`, `warn`, `block`, `off`. |
|
||||
| `PII_REVERSIBLE_VAULT_ENABLED` | boolean | `false` | Reversible PII vault: with `PII_REDACTION_ENABLED` on, request PII becomes per-request surrogate tokens instead of placeholders, and 2xx responses (SSE and JSON) get the originals back. |
|
||||
| `OUTBOUND_SSRF_GUARD_ENABLED` | boolean | `true` | Legacy alias: a value saved on this flag's dashboard toggle is read before the environment; `false`, `0`, `no`, or `off` in either turns the outbound URL guard's host checks off like `OMNIROUTE_ALLOW_PRIVATE_PROVIDER_URLS`. |
|
||||
| `ALLOW_API_KEY_REVEAL` | boolean | `false` | Allow authenticated dashboard users to reveal stored API keys instead of only seeing masked values. |
|
||||
| `AUTH_LOG_INCLUDE_ACCOUNT_ID` | boolean | `false` | Include account prefix in AUTH log lines (e.g. "Using <provider> account: abc12345..."). Disabled by default so account identifiers are redacted from shared/multi-tenant process logs. Independent from Debug Mode; flipping Debug Mode does not reveal this. |
|
||||
| `OMNIROUTE_OIDC_DISABLE_PASSWORD_LOGIN` | boolean | `false` | When OIDC is enabled, disable password login so users can only authenticate via OIDC Single Sign-On. When disabled (default), both password login and OIDC are available. |
|
||||
| `API_KEY_AUDIT_CLIENT_DETAILS_ENABLED` | boolean | `false` | Record the caller's IP address and user-agent on the `api_key.auth.touch` audit-log rows written for successful API-key metadata and discovery reads (#17982). Off by default: those rows still record which key was used, when, and on which path, without IP or user-agent. |
|
||||
| `PLUGIN_PERMISSION_MODEL_ENABLED` | boolean | `false` | Run each plugin process under the Node.js permission model, derived from the permissions its manifest declares: file reads limited to the plugin directory (plus its data directory with `file-read` or `file-write`), file writes only in the plugin data directory with `file-write`, child processes only with `exec`, and no worker threads, native addons or WASI. Network access is not restricted. Applies to plugins activated after the change. See [`PLUGIN_SDK.md`](../frameworks/PLUGIN_SDK.md#permission-system). |
|
||||
| Key | Type | Default | Description |
|
||||
| --------------------------------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `REQUIRE_API_KEY` | boolean | `false` | Require an API key for all incoming requests. |
|
||||
| `INPUT_SANITIZER_ENABLED` | boolean | `true` | Enable input sanitization for all requests. |
|
||||
| `INJECTION_GUARD_MODE` | enum | `off` | Prompt injection guard mode. Values: `off`, `warn`, `block`, `redact`. |
|
||||
| `PII_REDACTION_ENABLED` | boolean | `false` | Redact PII from requests (independent of `INPUT_SANITIZER_MODE`). |
|
||||
| `PII_RESPONSE_SANITIZATION` | boolean | `false` | Sanitize PII from provider responses. |
|
||||
| `PII_RESPONSE_SANITIZATION_MODE` | enum | `redact` | Mode for PII response sanitization. Values: `redact`, `warn`, `block`, `off`. |
|
||||
| `PII_REVERSIBLE_VAULT_ENABLED` | boolean | `false` | Reversible PII vault: with `PII_REDACTION_ENABLED` on, request PII becomes per-request surrogate tokens instead of placeholders, and 2xx responses (SSE and JSON) get the originals back. |
|
||||
| `OUTBOUND_SSRF_GUARD_ENABLED` | boolean | `true` | Legacy alias: a value saved on this flag's dashboard toggle is read before the environment; `false`, `0`, `no`, or `off` in either turns the outbound URL guard's host checks off like `OMNIROUTE_ALLOW_PRIVATE_PROVIDER_URLS`. |
|
||||
| `ALLOW_API_KEY_REVEAL` | boolean | `false` | Allow authenticated dashboard users to reveal stored API keys instead of only seeing masked values. |
|
||||
| `AUTH_LOG_INCLUDE_ACCOUNT_ID` | boolean | `false` | Include account prefix in AUTH log lines (e.g. "Using <provider> account: abc12345..."). Disabled by default so account identifiers are redacted from shared/multi-tenant process logs. Independent from Debug Mode; flipping Debug Mode does not reveal this. |
|
||||
| `OMNIROUTE_OIDC_DISABLE_PASSWORD_LOGIN` | boolean | `false` | When OIDC is enabled, disable password login so users can only authenticate via OIDC Single Sign-On. When disabled (default), both password login and OIDC are available. |
|
||||
| `API_KEY_AUDIT_CLIENT_DETAILS_ENABLED` | boolean | `false` | Record the caller's IP address and user-agent on the `api_key.auth.touch` audit-log rows written for successful API-key metadata and discovery reads (#17982). Off by default: those rows still record which key was used, when, and on which path, without IP or user-agent. |
|
||||
|
||||
### Network (32)
|
||||
|
||||
@@ -125,7 +124,7 @@ Invalid enum values and unreadable feature-flag storage fail closed. Neither opt
|
||||
priced spend or a failed pricing lookup. Enforcement and the administrator report resolve the
|
||||
same effective policy.
|
||||
|
||||
### Runtime (63)
|
||||
### Runtime (62)
|
||||
|
||||
| Key | Type | Default | Restart | Description |
|
||||
| ---------------------------------------------- | ------- | ------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
@@ -191,7 +190,6 @@ same effective policy.
|
||||
| `SYSTEMONE_CLOUDFLARE_BACKEND_ENABLED` | boolean | `false` | | Let `POST /v1/systemone` serve the `cloudflare-ai/<jev\|clef\|clef-flash>` decisions models (alias `cf/`) on Cloudflare Workers AI through the existing `cloudflare-ai` connection (#16676). Jev on Cloudflare draws AI Gateway credits; Clef draws Workers AI neurons. Off by default: those model ids are refused with a 400 and no upstream call. |
|
||||
| `SYSTEMONE_OLLAMA_LOCAL_BACKEND_ENABLED` | boolean | `false` | | Let `POST /v1/systemone` serve `ollama-local/<model>` decisions models on the local Ollama configured in the existing `ollama-local` connection (its base URL, never a request field) (#14667). Ollama's own limits apply before any upstream call: 2-26 candidates per choice/score question, at most 64 questions, no chat sampling fields, raw base64 images only. Off by default: those model ids are refused with a 400 and no upstream call. |
|
||||
| `COMBO_JEV_STRATEGY_ENABLED` | boolean | `false` | | Let combos that use the `jev` strategy ask TypeSafe System One (Jev) which of their models should answer each request (#15279). Every routed request then sends a bounded excerpt of the conversation to api.typesafe.ai and draws paid TypeSafe usage on the configured `typesafe` connection; a stored TypeSafe key alone never turns it on. Off by default: jev combos make no TypeSafe call and keep the operator's preference order. |
|
||||
| `COMBO_DECISION_ROUTER_ENABLED` | boolean | `false` | | Let auto combos that use the `decision` router strategy ask their configured decider which model should answer each request: TypeSafe System One, an operator decision URL (System One or OpenAI chat wire), or one of the combo's own models in process. Every routed request then sends the last user message (at most 8000 characters) and the model menu to that decider, which may be a paid third-party call; a stored key alone never turns it on. Off by default: decision combos read no credential, make no call and route with the `rules` strategy. |
|
||||
| `CODEX_SEARCH_AUTO_FALLBACK_ENABLED` | boolean | `false` | | Let an automatic web search (no explicit `provider`) use a connected Codex (ChatGPT) account through `codex-search`: as the last resort ahead of the keyless providers when no credentialed search provider is usable, and as the failover alternate (#17933). Each such search spends ChatGPT subscription quota and takes about 10–40 s. Off by default: `codex-search` runs only when a request names it explicitly. |
|
||||
| `CODE_ASSIST_INELIGIBLE_ONBOARD_LEGACY_TIER` | boolean | `false` | | For Antigravity / Code Assist onboarding, an account whose `loadCodeAssist` answer lists `ineligibleTiers` and marks no allowed tier as default onboards with `legacy-tier` instead of its `currentTier` (#18060), matching the Antigravity-Manager `fetch_project_id` order. Not yet confirmed on a real restricted account. Off by default: such an account keeps onboarding with its `currentTier`. |
|
||||
|
||||
@@ -291,10 +289,10 @@ Returns every flag with its effective value, source, and a summary.
|
||||
"requiresRestart": false,
|
||||
"warningLevel": "caution",
|
||||
},
|
||||
// ... all 128 flags
|
||||
// ... all 126 flags
|
||||
],
|
||||
"summary": {
|
||||
"total": 128,
|
||||
"total": 126,
|
||||
"active": 0,
|
||||
"inactive": 0,
|
||||
"overriddenByDb": 0,
|
||||
|
||||
@@ -597,9 +597,6 @@ Persisted `strategy: "auto"` combos can set `config.routerStrategy` (or legacy
|
||||
- `lkgp` — last known good provider first
|
||||
- `nadir` — ask [Nadir](https://getnadir.com)'s decision API which model in the pool the
|
||||
prompt needs; opt-in, fail-open to `rules`
|
||||
- `decision` — ask a configured decider (TypeSafe System One, your own decision URL, or one
|
||||
of the combo's own models) which model in the pool fits the request; behind the
|
||||
default-off `COMBO_DECISION_ROUTER_ENABLED` flag, fail-open to `rules`
|
||||
|
||||
### Router strategies in detail
|
||||
|
||||
@@ -825,90 +822,6 @@ and a frontier model), where always-frontier is the cost you want to cut.
|
||||
|
||||
---
|
||||
|
||||
#### 7. `decision` — pluggable decider picks the model
|
||||
|
||||
`decision` asks a **decider** which model in the pool fits the request, then narrows the
|
||||
pool to that model and lets `rules` pick the connection (quota, health and cost still
|
||||
choose the account). The decider is set in the combo's decision block — `config.decision`
|
||||
when the router knobs sit at the top of `config` (what the dashboard writes), or
|
||||
`config.auto.decision` next to `config.auto.routerStrategy`:
|
||||
|
||||
| `decider` | Who answers | Needs |
|
||||
| ------------- | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------- |
|
||||
| `systemone` | TypeSafe System One (`POST https://api.typesafe.ai/v1/systemone`), default model `jev-latest` | a `typesafe` connection or the env key |
|
||||
| `http` | your own decider at `baseUrl`: `wire: "systemone"` (`{baseUrl}/v1/systemone`) or `"openai-chat"` (chat completions) | `baseUrl` + `model`; key optional |
|
||||
| `combo-model` | one of your provider models, called in process like the fusion judge | `model` as `provider/model` (no combo) |
|
||||
|
||||
```json
|
||||
{
|
||||
"strategy": "auto",
|
||||
"config": {
|
||||
"routerStrategy": "decision",
|
||||
"decision": {
|
||||
"decider": "http",
|
||||
"baseUrl": "https://decider.example.com",
|
||||
"wire": "openai-chat",
|
||||
"model": "qwen-small",
|
||||
"connectionId": "<stored connection id>",
|
||||
"timeoutMs": 2000,
|
||||
"minConfidence": 0.6,
|
||||
"descriptions": { "gpt-4o-mini": "Quick drafts and short answers" }
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Fields (validated by a strict schema on save and again at request time):
|
||||
|
||||
- `decider` — `systemone`, `http` or `combo-model`.
|
||||
- `model` — TypeSafe model, the decision model at your URL, or the `provider/model` of a
|
||||
combo-model call (up to 200 characters).
|
||||
- `baseUrl` — `http` only: an `http(s)` URL up to 500 characters, without credentials,
|
||||
query or fragment. A URL pointing at this OmniRoute (loopback + `PORT`) is refused.
|
||||
- `wire` — `http` only: `systemone` (default) or `openai-chat`.
|
||||
- `connectionId` — the stored connection whose key is used (only inside the calling API
|
||||
key's allowed connections). Without it, `systemone` reads a `typesafe` connection and
|
||||
every network decider falls back to `OMNIROUTE_DECISION_API_KEY`. There is no `apiKey`
|
||||
field: a key is never stored in a combo.
|
||||
- `timeoutMs` — integer, 100–5000, default 2000.
|
||||
- `minConfidence` — 0–1; a lower-confidence answer falls back to `rules` (a decider that
|
||||
reports no confidence counts as 0).
|
||||
- `descriptions` — up to 50 entries (key up to 300, text up to 1000 characters), keyed by
|
||||
model id or `provider/model`; unset entries get a generated cost-rank description.
|
||||
|
||||
**Flag.** `COMBO_DECISION_ROUTER_ENABLED` (default `false`) gates every decider. While it is
|
||||
off, a `decision` combo reads no credential, makes no call and routes with `rules`; the log
|
||||
says `fallback (disabled)`. A stored key alone never turns it on. Combos without a decision
|
||||
block are not affected at all.
|
||||
|
||||
**What leaves the box.** Only the text of the last user message (up to 8000 characters;
|
||||
chat/Claude `messages` or Responses `input`) and the menu of model ids with their
|
||||
descriptions. Never the system prompt, Responses `instructions`, tools, history, headers or
|
||||
account data. Network calls go through the provider outbound guard with no retries, no
|
||||
redirects and a 64 KB response cap. The `combo-model` call is non-streaming, tool-free,
|
||||
`temperature: 0`, with a 256-token budget; a decision started inside a decision call is
|
||||
refused.
|
||||
|
||||
**Failure behavior** is fail-open: any failure resolves to the `rules` decision, and the
|
||||
reason reads `decision(<decider>): fallback (<reason>)`, with `<reason>` one of
|
||||
`disabled`, `not_configured`, `missing_credential`, `timeout`, `http_error`,
|
||||
`invalid_response`, `out_of_menu`, `refused`, `cooldown`, `network_error`, `recursion`,
|
||||
`low_confidence`, `single_option` or `no_user_text`. After a timeout, HTTP error or network
|
||||
error the endpoint is skipped for 30 s. A successful pick reads
|
||||
`decision(<decider>): selected <model> from <n>; confidence <c> (<rules reason>)`. No URL,
|
||||
key, prompt or upstream body reaches the log.
|
||||
|
||||
The combo builder shows these fields when the router strategy is `decision`, with the
|
||||
generated descriptions as placeholders and a **Test decision** button that calls
|
||||
`POST /api/combos/decision-preview` once with the unsaved settings (same flag).
|
||||
|
||||
**When to use**: mixed-difficulty traffic where you want the tier picked per request by a
|
||||
classifier you choose, not by Nadir specifically.
|
||||
|
||||
**Alias**: `decision` (no alias)
|
||||
|
||||
---
|
||||
|
||||
### Custom router strategies
|
||||
|
||||
You can register your own `RouterStrategy` implementation via the public API:
|
||||
@@ -962,7 +875,6 @@ Then use it:
|
||||
| Strict SLOs | `sla-aware` | Filters by p95/error/cost thresholds |
|
||||
| Multi-turn chat | `lkgp` | Session stickiness |
|
||||
| Mixed difficulty | `nadir` | Picks the model tier per prompt |
|
||||
| Own classifier | `decision` | Your decider picks the model |
|
||||
|
||||
SLA-aware fields:
|
||||
|
||||
|
||||
@@ -83,23 +83,6 @@ export const codexProvider: RegistryEntry = {
|
||||
},
|
||||
{ id: "gpt-6.1-sol-medium", name: "GPT 6.1 Sol (Medium)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6.1-sol-low", name: "GPT 6.1 Sol (Low)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6.1-terra", name: "GPT 6.1 Terra", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6.1-terra-ultra", name: "GPT 6.1 Terra (Ultra)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6.1-terra-max", name: "GPT 6.1 Terra (Max)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{
|
||||
id: "gpt-6.1-terra-xhigh",
|
||||
name: "GPT 6.1 Terra (xHigh)",
|
||||
...GPT_5_6_CODEX_CAPABILITIES,
|
||||
timeoutMs: 1200000,
|
||||
},
|
||||
{
|
||||
id: "gpt-6.1-terra-high",
|
||||
name: "GPT 6.1 Terra (High)",
|
||||
...GPT_5_6_CODEX_CAPABILITIES,
|
||||
timeoutMs: 1200000,
|
||||
},
|
||||
{ id: "gpt-6.1-terra-medium", name: "GPT 6.1 Terra (Medium)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6.1-terra-low", name: "GPT 6.1 Terra (Low)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6-luna", name: "GPT 6 Luna", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{ id: "gpt-6-luna-max", name: "GPT 6 Luna (Max)", ...GPT_5_6_CODEX_CAPABILITIES },
|
||||
{
|
||||
|
||||
@@ -22,16 +22,6 @@ export const openaiProvider: RegistryEntry = {
|
||||
...GPT_5_6_API_CAPABILITIES,
|
||||
unsupportedParams: ["temperature", "top_p", "top_logprobs", "logprobs"],
|
||||
},
|
||||
// https://developers.openai.com/api/docs/models/gpt-6.1-terra
|
||||
{
|
||||
id: "gpt-6.1-terra",
|
||||
name: "GPT-6.1 Terra",
|
||||
...GPT_5_6_API_CAPABILITIES,
|
||||
// Unlike Sol/Astra, Terra accepts sampling with reasoning.effort="none".
|
||||
// The effort-aware GPT sampling guard strips these fields only with
|
||||
// active reasoning; static unsupportedParams would strip them always.
|
||||
supportedThinkingEfforts: ["none", "low", "medium", "high", "xhigh", "max"],
|
||||
},
|
||||
// Astra shares the public GPT-5.6 limits; tool calling requires Responses.
|
||||
// https://developers.openai.com/api/docs/guides/latest-model
|
||||
{
|
||||
|
||||
@@ -10,7 +10,6 @@ export const CODEX_EFFORT_ORDER = [
|
||||
export type CodexEffortLevel = (typeof CODEX_EFFORT_ORDER)[number];
|
||||
export const CODEX_MAX_ALIAS_MODELS = new Set([
|
||||
"gpt-6.1-sol",
|
||||
"gpt-6.1-terra",
|
||||
"gpt-5.6-sol",
|
||||
"gpt-5.6-terra",
|
||||
"gpt-5.6-luna",
|
||||
@@ -21,7 +20,6 @@ export const CODEX_MAX_ALIAS_MODELS = new Set([
|
||||
]);
|
||||
export const CODEX_ULTRA_ALIAS_MODELS = new Set([
|
||||
"gpt-6.1-sol",
|
||||
"gpt-6.1-terra",
|
||||
"gpt-5.6-sol",
|
||||
"gpt-5.6-terra",
|
||||
"gpt-6-astra",
|
||||
|
||||
@@ -1015,10 +1015,6 @@ async function handleChatCoreInner({
|
||||
)) || null;
|
||||
const pipelineSessionId = explicitSessionIdHeader || skillRequestId;
|
||||
const reasoningReplaySessionKey = sessionAffinityKey || explicitSessionIdHeader;
|
||||
// One upstream Antigravity session per conversation (prompt-cache scope); the
|
||||
// non-streaming server-tool follow-up leg must reuse it, or it falls back to the
|
||||
// account-wide session and evicts parallel conversations' caches.
|
||||
const antigravitySessionKey = conversationId || sessionAffinityKey || null;
|
||||
const reasoningCacheScope = buildReasoningCacheScope(
|
||||
apiKeyInfo?.id,
|
||||
reasoningReplaySessionKey ? String(reasoningReplaySessionKey) : null
|
||||
@@ -2461,7 +2457,6 @@ async function handleChatCoreInner({
|
||||
signatureNamespace: connectionId,
|
||||
copilotClient: copilotCompatibleReasoning,
|
||||
reasoningCacheScope,
|
||||
antigravitySessionKey,
|
||||
videoTranscriptSensitive: videoBridgeObserved,
|
||||
onReasoningReplayHistory: (messages) => {
|
||||
reasoningReplayHistory = messages;
|
||||
@@ -3509,7 +3504,6 @@ async function handleChatCoreInner({
|
||||
persistFailureUsage,
|
||||
pipelineRecovered,
|
||||
pipelineSessionId,
|
||||
antigravitySessionKey,
|
||||
preserveCacheControl,
|
||||
provider,
|
||||
providerHeaders,
|
||||
|
||||
@@ -209,7 +209,6 @@ export async function runNonStreamingResponse(deps: NonStreamingDeps) {
|
||||
isResponsesEndpoint,
|
||||
preserveCacheControl,
|
||||
reasoningCacheScope,
|
||||
antigravitySessionKey,
|
||||
requestToolIdentityMap,
|
||||
stream,
|
||||
toolNameMap,
|
||||
@@ -575,7 +574,6 @@ export async function runNonStreamingResponse(deps: NonStreamingDeps) {
|
||||
signatureNamespace: connectionId,
|
||||
copilotClient: copilotCompatibleReasoning,
|
||||
reasoningCacheScope,
|
||||
antigravitySessionKey,
|
||||
onReasoningReplayHistory: (messages) => {
|
||||
reasoningReplayHistory = messages;
|
||||
},
|
||||
|
||||
@@ -24,7 +24,6 @@ import { mapImageSize } from "../translator/image/sizeMapper.ts";
|
||||
import { getCodexClientVersion, getCodexUserAgent } from "../config/codexClient.ts";
|
||||
import { isCodexFreePlan } from "../executors/codex/tools.ts";
|
||||
import { sleep } from "../utils/sleep.ts";
|
||||
import { clampPollIntervalMs, clampPollTimeoutMs } from "../utils/pollBounds.ts";
|
||||
import { codexReferenceImageUrl } from "./imageGeneration/providers/codexReferences.ts";
|
||||
export { shrinkCodexReferenceImage } from "./imageGeneration/providers/codexReferences.ts";
|
||||
import {
|
||||
@@ -2966,11 +2965,11 @@ async function handleNanoBananaImageGeneration({
|
||||
return { success: false, status: 500, error: errorText };
|
||||
}
|
||||
|
||||
const timeoutMs = clampPollTimeoutMs(
|
||||
const timeoutMs = normalizePositiveNumber(
|
||||
body.timeout_ms,
|
||||
normalizePositiveNumber(process.env.NANOBANANA_POLL_TIMEOUT_MS, 120000)
|
||||
);
|
||||
const pollIntervalMs = clampPollIntervalMs(
|
||||
const pollIntervalMs = normalizePositiveNumber(
|
||||
body.poll_interval_ms,
|
||||
normalizePositiveNumber(process.env.NANOBANANA_POLL_INTERVAL_MS, 2500)
|
||||
);
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
import { mapImageSize } from "../../../translator/image/sizeMapper.ts";
|
||||
import { sleep } from "../../../utils/sleep.ts";
|
||||
import { clampPollIntervalMs, clampPollTimeoutMs } from "../../../utils/pollBounds.ts";
|
||||
import { sanitizeErrorMessage } from "../../../utils/error.ts";
|
||||
import {
|
||||
extractImageInputs,
|
||||
isHttpUrl,
|
||||
normalizePositiveNumber,
|
||||
normalizeProviderImagePayload,
|
||||
normalizeRequestedImageFormat,
|
||||
parseSizeToDimensions,
|
||||
@@ -180,8 +180,8 @@ export async function handleBlackForestLabsImageGeneration({
|
||||
}
|
||||
|
||||
async function pollBlackForestLabsResult({ pollingUrl, token, body, log }) {
|
||||
const timeoutMs = clampPollTimeoutMs(body.timeout_ms, 300000);
|
||||
const pollIntervalMs = clampPollIntervalMs(body.poll_interval_ms, 1500);
|
||||
const timeoutMs = normalizePositiveNumber(body.timeout_ms, 300000);
|
||||
const pollIntervalMs = normalizePositiveNumber(body.poll_interval_ms, 1500);
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
|
||||
@@ -40,51 +40,6 @@ export function resolveLeonardoImageSize(body: {
|
||||
};
|
||||
}
|
||||
|
||||
// init_strength (0.1-0.9) is how closely the output follows the edit reference. In a live
|
||||
// check 0.3 kept the reference's composition and still applied the edit prompt (#18671).
|
||||
const LEONARDO_EDIT_INIT_STRENGTH = 0.3;
|
||||
|
||||
const LEONARDO_INIT_IMAGE_EXTENSIONS: Record<string, string> = {
|
||||
"image/png": "png",
|
||||
"image/jpeg": "jpg",
|
||||
"image/jpg": "jpg",
|
||||
"image/webp": "webp",
|
||||
};
|
||||
|
||||
/**
|
||||
* Uploads an edit reference through Leonardo's init-image flow (a presigned S3 form post,
|
||||
* which must not carry the Leonardo token) and returns the init image id.
|
||||
*/
|
||||
export async function uploadLeonardoInitImage(
|
||||
generationsUrl: string,
|
||||
token: string,
|
||||
image: { bytes: Buffer; mime: string }
|
||||
): Promise<string> {
|
||||
const res = await fetch(generationsUrl.replace(/\/generations$/, "/init-image"), {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ extension: LEONARDO_INIT_IMAGE_EXTENSIONS[image.mime] ?? "png" }),
|
||||
});
|
||||
if (!res.ok) throw new Error(`Leonardo init-image request failed: HTTP ${res.status}`);
|
||||
const { uploadInitImage } = await res.json();
|
||||
const form = new FormData();
|
||||
for (const [key, value] of Object.entries(JSON.parse(uploadInitImage.fields))) {
|
||||
form.append(key, String(value));
|
||||
}
|
||||
form.append("file", new Blob([new Uint8Array(image.bytes)], { type: image.mime }), "init");
|
||||
// Send the multipart body pre-encoded: a FormData body handed to OmniRoute's patched
|
||||
// fetch reached S3 as HTTP 412, while the same form as bytes plus its boundary header is
|
||||
// accepted (204).
|
||||
const encoded = new Response(form);
|
||||
const upload = await fetch(uploadInitImage.url, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": encoded.headers.get("content-type") || "" },
|
||||
body: Buffer.from(await encoded.arrayBuffer()),
|
||||
});
|
||||
if (!upload.ok) throw new Error(`Leonardo init-image upload failed: HTTP ${upload.status}`);
|
||||
return uploadInitImage.id;
|
||||
}
|
||||
|
||||
export async function handleLeonardoImageGeneration({
|
||||
model,
|
||||
provider,
|
||||
@@ -93,23 +48,14 @@ export async function handleLeonardoImageGeneration({
|
||||
credentials,
|
||||
log,
|
||||
pollIntervalMs = 5000,
|
||||
// An edit reference (/v1/images/edits): the generation becomes image-to-image.
|
||||
initImage = null,
|
||||
}) {
|
||||
const startTime = Date.now();
|
||||
const logPath = initImage ? "/v1/images/edits" : "/v1/images/generations";
|
||||
const token = credentials?.apiKey || "";
|
||||
const prompt = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? "");
|
||||
if (log) {
|
||||
log.info("IMAGE", `${provider}/${model} (leonardo) | prompt: "${prompt.slice(0, 60)}..."`);
|
||||
}
|
||||
try {
|
||||
const initFields = initImage
|
||||
? {
|
||||
init_image_id: await uploadLeonardoInitImage(providerConfig.baseUrl, token, initImage),
|
||||
init_strength: LEONARDO_EDIT_INIT_STRENGTH,
|
||||
}
|
||||
: {};
|
||||
const res = await fetch(providerConfig.baseUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
||||
@@ -118,14 +64,13 @@ export async function handleLeonardoImageGeneration({
|
||||
prompt,
|
||||
...resolveLeonardoImageSize(body),
|
||||
num_images: 1,
|
||||
...initFields,
|
||||
}),
|
||||
});
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text();
|
||||
saveCallLog({
|
||||
method: "POST",
|
||||
path: logPath,
|
||||
path: "/v1/images/generations",
|
||||
status: res.status,
|
||||
model: `${provider}/${model}`,
|
||||
provider,
|
||||
@@ -139,7 +84,7 @@ export async function handleLeonardoImageGeneration({
|
||||
if (!genId) {
|
||||
saveCallLog({
|
||||
method: "POST",
|
||||
path: logPath,
|
||||
path: "/v1/images/generations",
|
||||
status: 502,
|
||||
model: `${provider}/${model}`,
|
||||
provider,
|
||||
@@ -171,7 +116,7 @@ export async function handleLeonardoImageGeneration({
|
||||
}
|
||||
saveCallLog({
|
||||
method: "POST",
|
||||
path: logPath,
|
||||
path: "/v1/images/generations",
|
||||
status: 200,
|
||||
model: `${provider}/${model}`,
|
||||
provider,
|
||||
@@ -189,7 +134,7 @@ export async function handleLeonardoImageGeneration({
|
||||
if (gen.status === "FAILED") {
|
||||
saveCallLog({
|
||||
method: "POST",
|
||||
path: logPath,
|
||||
path: "/v1/images/generations",
|
||||
status: 502,
|
||||
model: `${provider}/${model}`,
|
||||
provider,
|
||||
@@ -201,7 +146,7 @@ export async function handleLeonardoImageGeneration({
|
||||
}
|
||||
saveCallLog({
|
||||
method: "POST",
|
||||
path: logPath,
|
||||
path: "/v1/images/generations",
|
||||
status: 504,
|
||||
model: `${provider}/${model}`,
|
||||
provider,
|
||||
@@ -213,7 +158,7 @@ export async function handleLeonardoImageGeneration({
|
||||
if (log) log.error("IMAGE", `${provider} leonardo error: ${err.message}`);
|
||||
saveCallLog({
|
||||
method: "POST",
|
||||
path: logPath,
|
||||
path: "/v1/images/generations",
|
||||
status: 502,
|
||||
model: `${provider}/${model}`,
|
||||
provider,
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
import { saveCallLog } from "../../imageResult.ts";
|
||||
import { sleep } from "../../../utils/sleep.ts";
|
||||
import { clampPollIntervalMs, clampPollTimeoutMs } from "../../../utils/pollBounds.ts";
|
||||
import { sanitizeErrorMessage } from "../../../utils/error.ts";
|
||||
import {
|
||||
UPSTREAM_MEDIA_LIMITS,
|
||||
@@ -20,6 +19,12 @@ import {
|
||||
const DEFAULT_POLL_INTERVAL_MS = 4000;
|
||||
const DEFAULT_POLL_TIMEOUT_MS = 180000;
|
||||
|
||||
function normalizePositiveNumber(value: unknown, fallback: number): number {
|
||||
const n = Number(value);
|
||||
if (!Number.isFinite(n) || n <= 0) return fallback;
|
||||
return Math.floor(n);
|
||||
}
|
||||
|
||||
interface MagnificProviderConfig {
|
||||
baseUrl: string;
|
||||
statusUrl?: string;
|
||||
@@ -262,8 +267,8 @@ export async function handleMagnificImageGeneration({
|
||||
const startTime = Date.now();
|
||||
const token = credentials?.apiKey || "";
|
||||
const prompt = typeof body.prompt === "string" ? body.prompt : String(body.prompt ?? "");
|
||||
const pollIntervalMs = clampPollIntervalMs(body.poll_interval_ms, DEFAULT_POLL_INTERVAL_MS);
|
||||
const pollTimeoutMs = clampPollTimeoutMs(body.poll_timeout_ms, DEFAULT_POLL_TIMEOUT_MS);
|
||||
const pollIntervalMs = normalizePositiveNumber(body.poll_interval_ms, DEFAULT_POLL_INTERVAL_MS);
|
||||
const pollTimeoutMs = normalizePositiveNumber(body.poll_timeout_ms, DEFAULT_POLL_TIMEOUT_MS);
|
||||
if (log) {
|
||||
log.info(
|
||||
"IMAGE",
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
renderhourBaseUrl,
|
||||
renderhourConfig,
|
||||
renderhourFailure,
|
||||
renderhourNumber,
|
||||
renderhourToken,
|
||||
runRenderhourJob,
|
||||
uploadRenderhourInputs,
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
saveImageErrorResult,
|
||||
saveImageSuccessResult,
|
||||
} from "../../imageGeneration.ts";
|
||||
import { clampPollIntervalMs, clampPollTimeoutMs } from "../../../utils/pollBounds.ts";
|
||||
|
||||
const MAX_IMAGES_PER_JOB = 4;
|
||||
|
||||
@@ -72,8 +72,8 @@ export async function handleRenderhourImageGeneration({
|
||||
baseUrl,
|
||||
token,
|
||||
request,
|
||||
timeoutMs: clampPollTimeoutMs(body.timeout_ms, 300_000),
|
||||
pollIntervalMs: clampPollIntervalMs(body.poll_interval_ms, 2000),
|
||||
timeoutMs: renderhourNumber(body.timeout_ms, 300_000),
|
||||
pollIntervalMs: renderhourNumber(body.poll_interval_ms, 2000),
|
||||
log,
|
||||
signal,
|
||||
});
|
||||
|
||||
@@ -302,7 +302,7 @@ async function pollRenderhourJob({
|
||||
error: `RenderHour job ${job.id} did not finish within ${Math.round(timeoutMs / 1000)} s`,
|
||||
};
|
||||
}
|
||||
await sleep(delay, signal);
|
||||
await sleep(delay);
|
||||
delay = pollIntervalMs;
|
||||
// Asking about a job also moves it forward on RenderHour's side.
|
||||
const response = await fetch(`${baseUrl}/v1/generations/${encodeURIComponent(job.id)}`, {
|
||||
|
||||
@@ -193,9 +193,6 @@ const TAVILY_FIELDS: FieldSchemas = {
|
||||
exact_match: z.boolean(),
|
||||
include_usage: z.boolean(),
|
||||
safe_search: z.boolean(),
|
||||
// 1..720 hours of cache, 0 to always fetch live, -1 to never fetch live.
|
||||
// Anything else (2.5, 721, "720") is dropped rather than sent upstream.
|
||||
max_age_hours: z.union([z.literal(-1), z.literal(0), int(1, 720)]),
|
||||
};
|
||||
|
||||
export function resolveTavilyPassthrough(
|
||||
|
||||
@@ -16,7 +16,7 @@ import { fetchWithCheckedRedirects, isRegistryEndpoint } from "./redirectGuard.t
|
||||
import type { SearchUrlGuard } from "./baseUrl.ts";
|
||||
import { HTTP_STATUS } from "../../config/constants.ts";
|
||||
import { lockBorrowedSearchKey } from "./borrowedKeyLock.ts";
|
||||
import { isSubscriptionQuotaForStatus } from "../../services/quotaTextCooldowns.ts";
|
||||
import { isSubscriptionQuotaText } from "../../services/quotaTextCooldowns.ts";
|
||||
import type { SearchProviderConfig } from "../../config/searchRegistry.ts";
|
||||
import type { SearchResult } from "../search.ts";
|
||||
import {
|
||||
@@ -53,9 +53,7 @@ export function shouldCoolDownSearchConnection(status: number, errorText: string
|
||||
if (SEARCH_COOLDOWN_STATUSES.has(status)) return true;
|
||||
const lower = errorText.toLowerCase();
|
||||
if (SEARCH_CREDIT_EXHAUSTION_PHRASES.some((phrase) => lower.includes(phrase))) return true;
|
||||
// A 400 can quote the caller's query back: plan/usage-limit wording counts on 400
|
||||
// only with a structured quota code (same status contract as LLM fallback).
|
||||
return isSubscriptionQuotaForStatus(status, null, errorText);
|
||||
return isSubscriptionQuotaText(lower);
|
||||
}
|
||||
|
||||
/** Post-dispatch state cleanup shared by JSON and SSE search providers. */
|
||||
|
||||
@@ -138,10 +138,7 @@ import { resolveApiKeyForbiddenFallback } from "./accountFallback/nonRetryableUp
|
||||
import * as exactModelLock from "./accountFallback/exactModelLock.ts";
|
||||
import { isCreditsExhaustedWithSharedWallet } from "./accountFallback/sharedWalletCredits.ts";
|
||||
import { CREDITS_EXHAUSTED_SIGNALS } from "./accountFallback/creditExhaustionSignals.ts";
|
||||
import {
|
||||
isCreditsExhaustedForStatus,
|
||||
quotaTextSignalCountsForStatus,
|
||||
} from "./accountFallback/creditsExhaustedForStatus.ts";
|
||||
import { isCreditsExhaustedForStatus } from "./accountFallback/creditsExhaustedForStatus.ts";
|
||||
export { CREDITS_EXHAUSTED_SIGNALS } from "./accountFallback/creditExhaustionSignals.ts";
|
||||
import { isMistralAmbiguous401 } from "./accountFallback/mistralAmbiguousAuth.ts";
|
||||
import { isRegisteredFeatureFlagEnabled } from "../utils/registeredFeatureFlag.ts";
|
||||
@@ -2309,20 +2306,8 @@ export function checkFallbackError(
|
||||
// UNCONDITIONALLY (not gated by shouldUseQuotaSignal) because it targets
|
||||
// apikey-category providers like ollama-cloud, which the oauth-only
|
||||
// shouldUseQuotaSignal gate deliberately excludes from the subscription
|
||||
// check above. On 400 none of these quota TEXT signals counts without a structured
|
||||
// code or an allow-listed provider: the message may quote the caller's own input.
|
||||
const quotaTextCounts = quotaTextSignalCountsForStatus(
|
||||
status,
|
||||
provider,
|
||||
errorStr,
|
||||
structuredError?.code
|
||||
);
|
||||
if (
|
||||
quotaTextCounts &&
|
||||
shouldUseQuotaSignal &&
|
||||
!isCreditsExhausted(errorStr) &&
|
||||
!isDailyQuotaExhausted(errorStr)
|
||||
) {
|
||||
// check above.
|
||||
if (shouldUseQuotaSignal && !isCreditsExhausted(errorStr) && !isDailyQuotaExhausted(errorStr)) {
|
||||
const subResult = buildSubscriptionQuotaFallback(
|
||||
errorStr,
|
||||
getUpstreamRetryHint,
|
||||
@@ -2332,17 +2317,14 @@ export function checkFallbackError(
|
||||
);
|
||||
if (subResult) return subResult;
|
||||
}
|
||||
const weeklyResult = quotaTextCounts
|
||||
? buildWeeklyQuotaFallback(errorStr, undefined, provider)
|
||||
: null;
|
||||
const weeklyResult = buildWeeklyQuotaFallback(errorStr, undefined, provider);
|
||||
if (weeklyResult) return weeklyResult;
|
||||
// Issue #7071 (session usage cap) is the same sibling gap as #3709 above —
|
||||
// runs UNCONDITIONALLY for the same reason: apikey-category providers
|
||||
// like ollama-cloud are excluded from the oauth-only shouldUseQuotaSignal
|
||||
// gate.
|
||||
const sessionResult = quotaTextCounts
|
||||
? (buildSessionQuotaFallback(errorStr) ?? buildRolling24hQuotaFallback(errorStr))
|
||||
: null;
|
||||
const sessionResult =
|
||||
buildSessionQuotaFallback(errorStr) ?? buildRolling24hQuotaFallback(errorStr);
|
||||
if (sessionResult) return sessionResult;
|
||||
|
||||
const detectedRetryHint = detectRetryHint();
|
||||
@@ -2354,7 +2336,6 @@ export function checkFallbackError(
|
||||
? "body"
|
||||
: undefined;
|
||||
if (
|
||||
quotaTextCounts &&
|
||||
shouldUseQuotaSignal &&
|
||||
quotaResetHintMs &&
|
||||
classifyErrorText(errorStr) === RateLimitReason.QUOTA_EXHAUSTED
|
||||
|
||||
@@ -60,25 +60,6 @@ function hasCreditErrorCode(text: string, structured: unknown): boolean {
|
||||
return codes.some((code) => CREDIT_ERROR_CODES.has(code.trim().toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a quota/credit TEXT signal found in an upstream error may count at this
|
||||
* status. Every status except 400 keeps the plain text match; on 400 the signal
|
||||
* counts only with a structured credit code or for an allow-listed provider (see
|
||||
* the header). Shared by the credit check below and the subscription/plan quota
|
||||
* text checks in quotaTextCooldowns.ts.
|
||||
*/
|
||||
export function quotaTextSignalCountsForStatus(
|
||||
status: number,
|
||||
provider: string | null | undefined,
|
||||
errorText: string,
|
||||
structured?: unknown
|
||||
): boolean {
|
||||
if (status !== 400) return true;
|
||||
return (
|
||||
allowsMessageOnlyCredit400(provider) || hasCreditErrorCode(String(errorText || ""), structured)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status-aware credit exhaustion check shared by the classifier, the fallback
|
||||
* engine and terminal-status resolution. `structured` is what the caller holds
|
||||
@@ -92,5 +73,6 @@ export function isCreditsExhaustedForStatus(
|
||||
): boolean {
|
||||
const text = String(errorText || "");
|
||||
if (!isCreditsExhaustedWithSharedWallet(text, CREDITS_EXHAUSTED_SIGNALS)) return false;
|
||||
return quotaTextSignalCountsForStatus(status, provider, text, structured);
|
||||
if (status !== 400) return true;
|
||||
return allowsMessageOnlyCredit400(provider) || hasCreditErrorCode(text, structured);
|
||||
}
|
||||
|
||||
@@ -102,33 +102,6 @@ export function deriveAntigravitySessionId(accountKey?: string | null): string |
|
||||
return hash.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Upstream Cloud Code session for one conversation on one account. Stable across turns
|
||||
* of that conversation (prompt-cache reuse) yet distinct between conversations running in
|
||||
* parallel on the same account, which otherwise share and evict one session cache.
|
||||
*
|
||||
* @param credentials - Connection credentials; their account key scopes the session.
|
||||
* @param conversationKey - Resolved conversation id (or session-affinity key); when empty,
|
||||
* the account-derived session from {@link getAntigravitySessionId} is returned unchanged.
|
||||
* @returns The `request.sessionId` to send in the Cloud Code envelope.
|
||||
*/
|
||||
export function getAntigravityConversationSessionId(
|
||||
credentials?: AntigravityCredentialsLike | null,
|
||||
conversationKey?: string | null
|
||||
): string {
|
||||
const conversation = toNonEmptyString(conversationKey);
|
||||
const account = getAntigravityAccountKey(credentials);
|
||||
if (!conversation) return getAntigravitySessionId(credentials);
|
||||
return (
|
||||
deriveAntigravitySessionId(`${account ?? ""}\x1f${conversation}`) ||
|
||||
getAntigravitySessionId(credentials)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Account-scoped Cloud Code session id: an explicit fallback wins, else a stable hash of the
|
||||
* account key, else a random id when no account is known.
|
||||
*/
|
||||
export function getAntigravitySessionId(
|
||||
credentials?: AntigravityCredentialsLike | null,
|
||||
fallback?: unknown
|
||||
|
||||
@@ -1,159 +0,0 @@
|
||||
/**
|
||||
* `decision` auto-router strategy: a decider picks the model, `rules` picks the connection.
|
||||
*
|
||||
* The combo's decision block (`config.auto.decision`, decision/schema.ts) names the decider:
|
||||
* - `systemone` — TypeSafe System One (base client, #15278);
|
||||
* - `http` — an operator URL on the System One or OpenAI-chat wire (#18555, #15641);
|
||||
* - `combo-model` — one of the operator's own models, in process (fusion-judge style).
|
||||
*
|
||||
* The answer narrows the pool to the chosen model and the fallback (`rules`) picks the
|
||||
* connection. Every failure — flag off, missing or invalid config, missing credential,
|
||||
* timeout, HTTP error, bad answer, out-of-menu choice, low confidence, recursion — returns
|
||||
* the `rules` decision with `decision(<kind>): fallback (<reason>)` in the reason. The log
|
||||
* line never carries a URL, key, prompt or upstream body.
|
||||
*
|
||||
* COMBO_DECISION_ROUTER_ENABLED (default off) gates every decider: while it is off no
|
||||
* decider is built, so no credential is read and nothing is fetched.
|
||||
*/
|
||||
import { isRegisteredFeatureFlagEnabled } from "../../utils/registeredFeatureFlag.ts";
|
||||
import { createDeciderForConfig, type DecisionRoutingContext } from "../decision/factory.ts";
|
||||
import {
|
||||
buildDecisionMenu,
|
||||
describeDecisionMenu,
|
||||
extractDecisionUserText,
|
||||
} from "../decision/menu.ts";
|
||||
import type { DecisionRoutingConfig } from "../decision/schema.ts";
|
||||
import { decisionDepth } from "../decision/scope.ts";
|
||||
import type {
|
||||
Decider,
|
||||
DecisionChoiceFailure,
|
||||
DecisionChoiceResult,
|
||||
DecisionChoiceSuccess,
|
||||
} from "../decision/types.ts";
|
||||
import type { ProviderCandidate } from "./scoring.ts";
|
||||
import type { RouterStrategy, RoutingContext, RoutingDecision } from "./routerStrategy.ts";
|
||||
|
||||
export const DECISION_ROUTER_FLAG = "COMBO_DECISION_ROUTER_ENABLED";
|
||||
|
||||
export interface DecisionStrategyOptions {
|
||||
fallback: RouterStrategy;
|
||||
/** Flag seam (tests). */
|
||||
isEnabled?: () => boolean;
|
||||
/** Decider seam (tests). */
|
||||
createDecider?: (config: DecisionRoutingConfig, context: DecisionRoutingContext) => Decider;
|
||||
}
|
||||
|
||||
type Prepared =
|
||||
| { skip: string; kind?: string }
|
||||
| {
|
||||
config: DecisionRoutingConfig;
|
||||
decision: DecisionRoutingContext;
|
||||
options: Record<string, string>;
|
||||
state: string;
|
||||
menuSize: number;
|
||||
};
|
||||
|
||||
/** Why a decider answer cannot route, or `null` when it can. */
|
||||
function rejectionReason(
|
||||
result: DecisionChoiceResult,
|
||||
options: Record<string, string>,
|
||||
minConfidence: number | undefined
|
||||
): string | null {
|
||||
// `strict: false` does not narrow the `ok` union, so name each variant.
|
||||
if (!result.ok) return (result as DecisionChoiceFailure).reason;
|
||||
const chosen = result as DecisionChoiceSuccess;
|
||||
if (!Object.prototype.hasOwnProperty.call(options, chosen.choice)) return "out_of_menu";
|
||||
if (minConfidence !== undefined && chosen.confidence < minConfidence) return "low_confidence";
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Score rounded to four decimals for the log. */
|
||||
function formatScore(value: number): string {
|
||||
return String(Number(value.toFixed(4)));
|
||||
}
|
||||
|
||||
export class DecisionStrategyImpl implements RouterStrategy {
|
||||
readonly name = "decision";
|
||||
readonly description =
|
||||
"Asks the configured decider (TypeSafe, an operator URL or one of the combo's own models) which model in the pool fits the request; connection choice and every failure fall back to the rules strategy";
|
||||
|
||||
private readonly fallback: RouterStrategy;
|
||||
private readonly isEnabled: () => boolean;
|
||||
private readonly createDecider: NonNullable<DecisionStrategyOptions["createDecider"]>;
|
||||
|
||||
constructor(options: DecisionStrategyOptions) {
|
||||
this.fallback = options.fallback;
|
||||
this.isEnabled =
|
||||
options.isEnabled ?? (() => isRegisteredFeatureFlagEnabled(DECISION_ROUTER_FLAG));
|
||||
this.createDecider = options.createDecider ?? createDeciderForConfig;
|
||||
}
|
||||
|
||||
select(pool: ProviderCandidate[], context: RoutingContext): RoutingDecision {
|
||||
return this.fallbackDecision(pool, context, "sync_caller");
|
||||
}
|
||||
|
||||
async selectAsync(pool: ProviderCandidate[], context: RoutingContext): Promise<RoutingDecision> {
|
||||
const healthy = pool.filter((item) => item.circuitBreakerState !== "OPEN");
|
||||
const candidates = healthy.length ? healthy : pool;
|
||||
if (!candidates.length) throw new Error(`[${this.name}] No candidates available`);
|
||||
const prepared = this.prepare(candidates, context);
|
||||
if ("skip" in prepared) {
|
||||
return this.fallbackDecision(candidates, context, prepared.skip, prepared.kind);
|
||||
}
|
||||
const { config, decision, options, state, menuSize } = prepared;
|
||||
const kind = config.decider;
|
||||
const result = await this.createDecider(
|
||||
config,
|
||||
decision
|
||||
)({
|
||||
state,
|
||||
options,
|
||||
signal: decision.signal,
|
||||
});
|
||||
const rejected = rejectionReason(result, options, config.minConfidence);
|
||||
if (rejected) return this.fallbackDecision(candidates, context, rejected, kind);
|
||||
const chosen = result as DecisionChoiceSuccess;
|
||||
|
||||
const matching = candidates.filter((item) => item.model === chosen.choice);
|
||||
const picked = this.fallback.select(matching, context);
|
||||
const model = chosen.backendModel
|
||||
? `; decision model ${JSON.stringify(chosen.backendModel)}`
|
||||
: "";
|
||||
return {
|
||||
...picked,
|
||||
strategy: this.name,
|
||||
candidatesConsidered: candidates.length,
|
||||
reason: `decision(${kind}): selected ${chosen.choice} from ${menuSize}; confidence ${formatScore(
|
||||
chosen.confidence
|
||||
)}${model} (${picked.reason})`,
|
||||
};
|
||||
}
|
||||
|
||||
/** Every check that happens before a decider is built; the flag comes first. */
|
||||
private prepare(candidates: ProviderCandidate[], context: RoutingContext): Prepared {
|
||||
// Off means no credential read and no fetch: nothing below runs.
|
||||
if (!this.isEnabled()) return { skip: "disabled" };
|
||||
if (decisionDepth() > 0) return { skip: "recursion" };
|
||||
const decision = context.decision;
|
||||
const resolved = decision?.config;
|
||||
if (!decision || !resolved?.valid) return { skip: "not_configured" };
|
||||
const { config } = resolved;
|
||||
const menu = buildDecisionMenu(candidates);
|
||||
if (menu.length < 2) return { skip: "single_option", kind: config.decider };
|
||||
const state = extractDecisionUserText(decision.body ?? { messages: context.messages });
|
||||
if (!state) return { skip: "no_user_text", kind: config.decider };
|
||||
const options = describeDecisionMenu(menu, candidates, config.descriptions);
|
||||
return { config, decision, options, state, menuSize: menu.length };
|
||||
}
|
||||
|
||||
private fallbackDecision(
|
||||
pool: ProviderCandidate[],
|
||||
context: RoutingContext,
|
||||
reason: string,
|
||||
kind?: string
|
||||
): RoutingDecision {
|
||||
const decision = this.fallback.select(pool, context);
|
||||
const label = kind ? `decision(${kind})` : "decision";
|
||||
return { ...decision, reason: `${label}: fallback (${reason}); ${decision.reason}` };
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
* - SLAStrategy: prefers candidates that satisfy latency/error/cost SLOs
|
||||
* - LKGPStrategy: tries last known good provider first
|
||||
* - NadirStrategy: asks Nadir's decision API which model the prompt needs (nadirStrategy.ts)
|
||||
* - DecisionStrategy: asks the combo's configured decider which model fits (decisionStrategy.ts)
|
||||
*/
|
||||
|
||||
import type { ProviderCandidate, ScoredProvider, ScoringWeights } from "./scoring.ts";
|
||||
@@ -20,8 +19,6 @@ import { clamp01 } from "../../utils/number.ts";
|
||||
import { rankBySpeed } from "./speedRanking.ts";
|
||||
import type { SpeedCandidate } from "./speedRanking.ts";
|
||||
import { NadirStrategyImpl, type NadirRoutingConfig } from "./nadirStrategy.ts";
|
||||
import { DecisionStrategyImpl } from "./decisionStrategy.ts";
|
||||
import type { DecisionRoutingContext } from "../decision/factory.ts";
|
||||
import type { RoutingHint } from "../manifestAdapter.ts";
|
||||
|
||||
export interface SlaRoutingPolicy {
|
||||
@@ -46,8 +43,6 @@ export interface RoutingContext {
|
||||
messages?: unknown;
|
||||
/** The combo's `config.nadir` block; see nadirStrategy.ts. */
|
||||
nadir?: NadirRoutingConfig;
|
||||
/** The combo's decision block plus request seams; see decisionStrategy.ts. */
|
||||
decision?: DecisionRoutingContext;
|
||||
}
|
||||
|
||||
export interface RoutingDecision {
|
||||
@@ -409,7 +404,6 @@ strategyRegistry.set("sla-aware", slaStrategy);
|
||||
strategyRegistry.set("sla", slaStrategy); // alias
|
||||
strategyRegistry.set("lkgp", lkgpStrategy);
|
||||
strategyRegistry.set("nadir", new NadirStrategyImpl({ fallback: rulesStrategy }));
|
||||
strategyRegistry.set("decision", new DecisionStrategyImpl({ fallback: rulesStrategy }));
|
||||
|
||||
export function getStrategy(name: string): RouterStrategy {
|
||||
const strategy = strategyRegistry.get(name);
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
} from "../autoCombo/scoring.ts";
|
||||
import { getModePack } from "../autoCombo/modePacks.ts";
|
||||
import { resolveNadirRoutingConfig } from "../autoCombo/nadirStrategy.ts";
|
||||
import { resolveDecisionRoutingConfig } from "../decision/schema.ts";
|
||||
import { isRecord } from "./comboData.ts";
|
||||
import { readAccountPreferences } from "./accountPreferences.ts";
|
||||
import { resolveAutoResetWindowConfig, resolveSlaRoutingPolicy } from "./quotaScoring.ts";
|
||||
@@ -16,7 +15,7 @@ import type { ComboLike, ResolvedComboTarget } from "./types.ts";
|
||||
*
|
||||
* Pure function of `(combo, eligibleTargets)`: derives the router strategy name,
|
||||
* candidate provider pool, scoring weights, exploration rate, budget cap, mode
|
||||
* pack, reset-window config, SLA policy, Nadir and decision config from the combo's
|
||||
* pack, reset-window config, SLA policy and Nadir config from the combo's
|
||||
* `autoConfig`/`config`.
|
||||
* No side effects, no early returns — extracted verbatim from `handleComboChat`
|
||||
* so its behavior is byte-identical to the previous inline block.
|
||||
@@ -67,7 +66,6 @@ export function parseAutoConfig(combo: ComboLike, eligibleTargets: ResolvedCombo
|
||||
const resetWindowConfig = resolveAutoResetWindowConfig(autoConfigSource);
|
||||
const slaPolicy = resolveSlaRoutingPolicy(autoConfigSource);
|
||||
const nadirConfig = resolveNadirRoutingConfig(autoConfigSource.nadir);
|
||||
const decisionConfig = resolveDecisionRoutingConfig(autoConfigSource.decision);
|
||||
|
||||
return {
|
||||
routingStrategy,
|
||||
@@ -80,7 +78,6 @@ export function parseAutoConfig(combo: ComboLike, eligibleTargets: ResolvedCombo
|
||||
resetWindowConfig,
|
||||
slaPolicy,
|
||||
nadirConfig,
|
||||
decisionConfig,
|
||||
accountPreferences: readAccountPreferences(autoConfigSource.accountPreferences),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -411,24 +411,10 @@ const EXPIRY_FIRST_DEFAULTS = {
|
||||
tieBandPercent: 5,
|
||||
minHours: 0.25,
|
||||
exhaustedFloorPercent: 1,
|
||||
deadlineTieMinutes: 60,
|
||||
};
|
||||
|
||||
/**
|
||||
* How `expiry-first` orders accounts that still hold quota:
|
||||
* - `rate` (default): by how much each account must spend per hour before its
|
||||
* deadline (`scoreExpiryFirstQuota`).
|
||||
* - `deadline`: strictly by the nearest deadline — the account whose quota is
|
||||
* lost first is spent first, as long as it has quota left. Exhausted accounts
|
||||
* (including a spent 5h session) are skipped until they refill.
|
||||
*/
|
||||
export const EXPIRY_FIRST_ORDERS = ["rate", "deadline"] as const;
|
||||
export type ExpiryFirstOrder = (typeof EXPIRY_FIRST_ORDERS)[number];
|
||||
|
||||
/** Reads the expiry-first settings (global or a provider override) with their defaults and bounds. */
|
||||
export function resolveExpiryFirstConfig(config: Record<string, unknown> | null | undefined) {
|
||||
const minHours = finiteNumberOrNull(config?.expiryFirstMinHours);
|
||||
const deadlineTieMinutes = finiteNumberOrNull(config?.expiryFirstDeadlineTieMinutes);
|
||||
return {
|
||||
tieBand:
|
||||
getPercentConfig(config?.expiryFirstTieBandPercent, EXPIRY_FIRST_DEFAULTS.tieBandPercent) /
|
||||
@@ -439,19 +425,6 @@ export function resolveExpiryFirstConfig(config: Record<string, unknown> | null
|
||||
config?.expiryFirstExhaustedFloorPercent,
|
||||
EXPIRY_FIRST_DEFAULTS.exhaustedFloorPercent
|
||||
) / 100,
|
||||
order: (config?.expiryFirstOrder === "deadline" ? "deadline" : "rate") as ExpiryFirstOrder,
|
||||
deadlineTieMs:
|
||||
Math.min(
|
||||
24 * 60,
|
||||
Math.max(
|
||||
0,
|
||||
deadlineTieMinutes !== null
|
||||
? deadlineTieMinutes
|
||||
: EXPIRY_FIRST_DEFAULTS.deadlineTieMinutes
|
||||
)
|
||||
) *
|
||||
60 *
|
||||
1000,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -494,44 +467,6 @@ function msUntilWindowReset(window: QuotaWindowSnapshot, nowMs: number): number
|
||||
return Number.isFinite(resetMs) ? resetMs - nowMs : Number.POSITIVE_INFINITY;
|
||||
}
|
||||
|
||||
/** Nominal length of a longer (non-session) window, read from its name; null when unknown. */
|
||||
function nominalLongerWindowMs(key: string): number | null {
|
||||
const name = key.toLowerCase();
|
||||
if (name.startsWith("weekly") || name.includes("(7d)")) return RESET_AWARE_WEEKLY_WINDOW_MS;
|
||||
if (name.startsWith("monthly") || name.includes("(30d)")) return RESET_AWARE_MONTHLY_WINDOW_MS;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time left until a window's reset, and whether that reset already lapsed.
|
||||
*
|
||||
* A window whose reset is in the past comes from a stale quota read: the window
|
||||
* has refilled since, so its old fraction no longer applies and its real next
|
||||
* reset is one nominal period later (5h session, 7d weekly, 30d monthly).
|
||||
* Treating the lapsed reset as "expires now" made a stale account look like the
|
||||
* most urgent one and drained it first (two Claude accounts, 2026-11-06/07). A
|
||||
* lapsed window of unknown length keeps no deadline.
|
||||
*/
|
||||
function resolveWindowReset(
|
||||
entry: ExpiryWindow,
|
||||
nowMs: number
|
||||
): { msLeft: number; lapsed: boolean } {
|
||||
const msLeft = msUntilWindowReset(entry.window, nowMs);
|
||||
if (!Number.isFinite(msLeft) || msLeft > 0) return { msLeft, lapsed: false };
|
||||
const periodMs = entry.session ? RESET_AWARE_SESSION_WINDOW_MS : nominalLongerWindowMs(entry.key);
|
||||
if (periodMs === null) return { msLeft: Number.POSITIVE_INFINITY, lapsed: true };
|
||||
return { msLeft: msLeft + periodMs * (Math.floor(-msLeft / periodMs) + 1), lapsed: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* How much of a window can still be spent. An unreported fraction caps nothing, and
|
||||
* neither does a lapsed window: it has refilled, so its stale fraction no longer applies.
|
||||
*/
|
||||
function windowUsableCap(window: QuotaWindowSnapshot, lapsed: boolean): number {
|
||||
if (window.fractionReported === false || lapsed) return 1;
|
||||
return clamp01(1 - (window.percentUsed ?? 0.5));
|
||||
}
|
||||
|
||||
function resolveUsableAndReset(
|
||||
windows: ExpiryWindow[],
|
||||
nowMs: number,
|
||||
@@ -541,14 +476,14 @@ function resolveUsableAndReset(
|
||||
let usable = 1;
|
||||
let msUntilReset = Number.POSITIVE_INFINITY;
|
||||
let msUntilSessionReset = Number.POSITIVE_INFINITY;
|
||||
for (const entry of windows) {
|
||||
const { window, session } = entry;
|
||||
for (const { window, session } of windows) {
|
||||
if (window.fractionReported === false && skipUnreported) continue;
|
||||
const { msLeft, lapsed } = resolveWindowReset(entry, nowMs);
|
||||
const msLeft = msUntilWindowReset(window, nowMs);
|
||||
const capOnly = session && hasLongerWindow;
|
||||
// A lapsed session has refilled: inside a longer window it caps nothing.
|
||||
if (capOnly && lapsed) continue;
|
||||
usable = Math.min(usable, windowUsableCap(window, lapsed));
|
||||
if (capOnly && msLeft <= 0) continue;
|
||||
if (window.fractionReported !== false) {
|
||||
usable = Math.min(usable, clamp01(1 - (window.percentUsed ?? 0.5)));
|
||||
}
|
||||
if (capOnly) msUntilSessionReset = Math.min(msUntilSessionReset, msLeft);
|
||||
else msUntilReset = Math.min(msUntilReset, msLeft);
|
||||
}
|
||||
@@ -582,22 +517,19 @@ function projectExpiryScore(
|
||||
): { score: number; hasReset: boolean } {
|
||||
let score = 0;
|
||||
let hasReset = false;
|
||||
for (const entry of windows) {
|
||||
const { key, window, session } = entry;
|
||||
for (const { key, window, session } of windows) {
|
||||
if (window.fractionReported === false && ctx.skipUnreported) continue;
|
||||
// A session refills many times before a longer window resets, so its reset is not
|
||||
// where quota is lost (#18541); it already caps `usable`. This also covers an
|
||||
// unreported longer reset, a conservative deadline fallback that is not evidence
|
||||
// that the session's entire balance must be spent in a few hours (#18552).
|
||||
if (session && ctx.skipSession) continue;
|
||||
const { msLeft, lapsed } = resolveWindowReset(entry, ctx.nowMs);
|
||||
if (!Number.isFinite(msLeft)) continue;
|
||||
const resetMs = parseResetTimeMs(window.resetAt);
|
||||
if (!Number.isFinite(resetMs)) continue;
|
||||
hasReset = true;
|
||||
const hours = Math.max(ctx.config.minHours, msLeft / (60 * 60 * 1000));
|
||||
const hours = Math.max(ctx.config.minHours, (resetMs - ctx.nowMs) / (60 * 60 * 1000));
|
||||
const remaining =
|
||||
window.fractionReported === false || lapsed
|
||||
? ctx.usable
|
||||
: clamp01(1 - (window.percentUsed ?? 0.5));
|
||||
window.fractionReported === false ? ctx.usable : clamp01(1 - (window.percentUsed ?? 0.5));
|
||||
const burnRate = Math.max(0, ctx.burnRates[key] ?? 0);
|
||||
const projectedRemaining = Math.max(0, remaining - burnRate * hours);
|
||||
const predictedWaste = Math.min(ctx.usable, projectedRemaining);
|
||||
@@ -686,32 +618,6 @@ export function scoreExpiryFirstQuota(
|
||||
return { score };
|
||||
}
|
||||
|
||||
/**
|
||||
* The deadline view `expiry-first` uses in `deadline` order: how much an account
|
||||
* can spend right now (`usable`, the tightest window, a spent session included)
|
||||
* and how long until its quota is lost (the nearest longer-window reset, rolled
|
||||
* forward when it already lapsed; the session reset only when no longer window
|
||||
* reports one). Null when there is no telemetry or nothing left to spend.
|
||||
*/
|
||||
export function resolveExpiryFirstDeadline(
|
||||
quota: unknown,
|
||||
config: ExpiryConfig,
|
||||
nowMs: number = Date.now()
|
||||
): { usable: number; msUntilDeadline: number } | null {
|
||||
if (!quota || !isRecord(quota)) return null;
|
||||
if (quota.limitReached === true) return null;
|
||||
const windows = collectExpiryWindows(quota);
|
||||
if (windows.length === 0) return null;
|
||||
if (windows.every(({ window }) => window.fractionReported === false)) return null;
|
||||
const { usable, msUntilReset } = resolveUsableAndReset(
|
||||
windows,
|
||||
nowMs,
|
||||
hasLongerReset(windows, true)
|
||||
);
|
||||
if (usable <= config.exhaustedFloor) return null;
|
||||
return { usable, msUntilDeadline: msUntilReset };
|
||||
}
|
||||
|
||||
export function getResetAwareRemainingPercent(quota: unknown): number {
|
||||
if (!quota || !isRecord(quota)) return 100;
|
||||
if (quota.limitReached === true) return 0;
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
parseRequestBudgetFallback,
|
||||
} from "../autoCombo/requestControls.ts";
|
||||
import { selectWithStrategyAsync } from "../autoCombo/routerStrategy.ts";
|
||||
import { buildDecisionRoutingContext, type DecisionRuntime } from "../decision/factory.ts";
|
||||
import { buildComplexityRoutingHint } from "../autoCombo/complexityRouter";
|
||||
import { getModePack } from "../autoCombo/modePacks.ts";
|
||||
import { recordComboIntent } from "../comboMetrics.ts";
|
||||
@@ -92,8 +91,6 @@ export interface ResolveAutoStrategyDeps {
|
||||
log: ComboLogger;
|
||||
buildAutoCandidates: BuildAutoCandidates;
|
||||
apiKeyAllowedConnections?: string[] | null;
|
||||
/** Request seams for the `decision` router (signal, handleSingleModel, combos). */
|
||||
decisionRuntime?: DecisionRuntime | null;
|
||||
}
|
||||
|
||||
export type ResolveAutoStrategyResult =
|
||||
@@ -334,7 +331,6 @@ export async function resolveAutoStrategyOrder(
|
||||
resetWindowConfig,
|
||||
slaPolicy,
|
||||
nadirConfig,
|
||||
decisionConfig,
|
||||
accountPreferences,
|
||||
} = parseAutoConfig(combo, eligibleTargets);
|
||||
|
||||
@@ -528,12 +524,6 @@ export async function resolveAutoStrategyOrder(
|
||||
manifestHint: autoManifestHint,
|
||||
messages: body.messages,
|
||||
nadir: nadirConfig,
|
||||
decision: buildDecisionRoutingContext(
|
||||
decisionConfig,
|
||||
deps.decisionRuntime,
|
||||
body,
|
||||
deps.apiKeyAllowedConnections
|
||||
),
|
||||
},
|
||||
routingStrategy
|
||||
);
|
||||
|
||||
@@ -501,11 +501,6 @@ async function orderByStrategy(
|
||||
log,
|
||||
buildAutoCandidates: deps.buildAutoCandidates,
|
||||
apiKeyAllowedConnections: deps.apiKeyAllowedConnections,
|
||||
decisionRuntime: {
|
||||
signal: deps.signal,
|
||||
dispatch: deps.handleSingleModelWithTimeout,
|
||||
allCombos: deps.allCombos,
|
||||
},
|
||||
});
|
||||
if ("earlyResponse" in autoResult) return { earlyResponse: autoResult.earlyResponse };
|
||||
return {
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
/**
|
||||
* `combo-model` decider: one of the operator's own provider models answers the routing
|
||||
* question in process, through the combo's `handleSingleModel` — the way the fusion judge
|
||||
* runs (fusion.ts). Prompt and parser are the OpenAI-chat decision wire (#15641).
|
||||
*
|
||||
* Guards: a combo reference (`auto`, `auto/*`, a configured combo name, or any id without a
|
||||
* provider prefix) is refused; the call is non-streaming, tool-free, temperature 0 with a small
|
||||
* output budget and none of the client's system prompt, tools or history; it runs inside the
|
||||
* decision scope, so a decision started from within it is refused (depth guard); one timeout
|
||||
* aborts it through the target's `modelAbortSignal`.
|
||||
*/
|
||||
import { extractPanelText } from "../fusion.ts";
|
||||
import type { ComboCollectionLike, HandleSingleModel } from "../combo/types.ts";
|
||||
import {
|
||||
clampDecisionTimeout,
|
||||
DEFAULT_DECISION_TIMEOUT_MS,
|
||||
MAX_DECISION_TIMEOUT_MS,
|
||||
} from "./config.ts";
|
||||
import { decisionDepth, runInDecisionScope } from "./scope.ts";
|
||||
import { readBoundedJson } from "./transport.ts";
|
||||
import {
|
||||
decisionFailure,
|
||||
type Decider,
|
||||
type DecisionChoiceRequest,
|
||||
type DecisionFailureReason,
|
||||
} from "./types.ts";
|
||||
import {
|
||||
DECISION_MAX_OUTPUT_TOKENS,
|
||||
OPENAI_DECISION_SYSTEM_PROMPT,
|
||||
buildOpenAiDecisionMessages,
|
||||
parseDecisionAnswerText,
|
||||
toDecisionChoiceResult,
|
||||
} from "./wires.ts";
|
||||
|
||||
export interface ComboModelDeciderOptions {
|
||||
/** `provider/model` of one of the operator's models. */
|
||||
model?: string;
|
||||
timeoutMs?: number;
|
||||
/** The combo's `handleSingleModel`; absent outside a live request (e.g. the preview). */
|
||||
dispatch?: HandleSingleModel;
|
||||
allCombos?: ComboCollectionLike;
|
||||
/** The client's request body: only its shape (messages / input / contents) is reused. */
|
||||
clientBody?: Record<string, unknown> | null;
|
||||
now?: () => number;
|
||||
}
|
||||
|
||||
function comboNames(allCombos: ComboCollectionLike): Set<string> {
|
||||
const list = Array.isArray(allCombos)
|
||||
? allCombos
|
||||
: Array.isArray(allCombos?.combos)
|
||||
? allCombos.combos
|
||||
: [];
|
||||
return new Set(
|
||||
list
|
||||
.map((combo) => (combo as { name?: unknown } | null)?.name)
|
||||
.filter((name): name is string => typeof name === "string" && name.length > 0)
|
||||
);
|
||||
}
|
||||
|
||||
/** True when `model` would route through a combo instead of one provider model. */
|
||||
export function isDecisionComboRef(model: string, allCombos: ComboCollectionLike): boolean {
|
||||
const id = model.trim();
|
||||
if (id === "auto" || id.startsWith("auto/") || !id.includes("/")) return true;
|
||||
return comboNames(allCombos).has(id);
|
||||
}
|
||||
|
||||
/** Decision body in the client's own wire shape, so the dispatcher translates it as usual. */
|
||||
function buildBody(model: string, request: DecisionChoiceRequest, clientBody: unknown) {
|
||||
const [, user] = buildOpenAiDecisionMessages(request);
|
||||
// One user turn carries the instructions: valid for OpenAI, Claude and Gemini alike.
|
||||
const text = `${OPENAI_DECISION_SYSTEM_PROMPT}\n\n${user.content}`;
|
||||
const shape = (clientBody ?? {}) as { input?: unknown; contents?: unknown; messages?: unknown };
|
||||
const common = { model, stream: false, temperature: 0 };
|
||||
if (!Array.isArray(shape.messages) && shape.input !== undefined) {
|
||||
return {
|
||||
...common,
|
||||
max_output_tokens: DECISION_MAX_OUTPUT_TOKENS,
|
||||
input: [{ role: "user", content: text }],
|
||||
};
|
||||
}
|
||||
if (!Array.isArray(shape.messages) && Array.isArray(shape.contents)) {
|
||||
return {
|
||||
...common,
|
||||
generationConfig: { temperature: 0, maxOutputTokens: DECISION_MAX_OUTPUT_TOKENS },
|
||||
contents: [{ role: "user", parts: [{ text }] }],
|
||||
};
|
||||
}
|
||||
return {
|
||||
...common,
|
||||
max_tokens: DECISION_MAX_OUTPUT_TOKENS,
|
||||
messages: [{ role: "user", content: text }],
|
||||
};
|
||||
}
|
||||
|
||||
/** Why the in-process call must not run, or `null` when it may. */
|
||||
function preconditionFailure(
|
||||
options: ComboModelDeciderOptions,
|
||||
model: string | undefined,
|
||||
request: DecisionChoiceRequest
|
||||
): DecisionFailureReason | null {
|
||||
if (!model || !options.dispatch) return "not_configured";
|
||||
if (isDecisionComboRef(model, options.allCombos)) return "recursion";
|
||||
if (decisionDepth() > 0) return "recursion";
|
||||
if (request.signal?.aborted) return "timeout";
|
||||
return null;
|
||||
}
|
||||
|
||||
type DispatchOutcome = { status: number } | { json: unknown };
|
||||
|
||||
/** Dispatch inside the decision scope; non-2xx keeps the status only, the body is never read. */
|
||||
function dispatchInScope(
|
||||
dispatch: HandleSingleModel,
|
||||
model: string,
|
||||
body: Record<string, unknown>,
|
||||
signal: AbortSignal
|
||||
): Promise<DispatchOutcome> {
|
||||
return runInDecisionScope(async () => {
|
||||
const response = await dispatch(body, model, { modelAbortSignal: signal });
|
||||
if (!response.ok) {
|
||||
await response.body?.cancel().catch(() => {});
|
||||
return { status: response.status };
|
||||
}
|
||||
return { json: await readBoundedJson(response) };
|
||||
});
|
||||
}
|
||||
|
||||
export function createComboModelDecider(options: ComboModelDeciderOptions): Decider {
|
||||
const now = options.now ?? Date.now;
|
||||
const clamped = clampDecisionTimeout(options.timeoutMs);
|
||||
// Explicit upper bound at the timer site (the clamp above already enforces it).
|
||||
const timeoutMs =
|
||||
clamped > 0 && clamped <= MAX_DECISION_TIMEOUT_MS ? clamped : DEFAULT_DECISION_TIMEOUT_MS;
|
||||
|
||||
return async (request) => {
|
||||
const model = options.model?.trim();
|
||||
const blocked = preconditionFailure(options, model, request);
|
||||
if (blocked) return decisionFailure(blocked);
|
||||
|
||||
const controller = new AbortController();
|
||||
const onCallerAbort = () => controller.abort();
|
||||
request.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
||||
const startedAt = now();
|
||||
const elapsed = () => Math.max(0, now() - startedAt);
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
const timedOut = new Promise<"timeout">((resolve) => {
|
||||
timer = setTimeout(() => {
|
||||
controller.abort();
|
||||
resolve("timeout");
|
||||
}, timeoutMs);
|
||||
});
|
||||
const body = buildBody(model as string, request, options.clientBody);
|
||||
const call = dispatchInScope(
|
||||
options.dispatch as HandleSingleModel,
|
||||
model as string,
|
||||
body,
|
||||
controller.signal
|
||||
);
|
||||
call.catch(() => {});
|
||||
|
||||
try {
|
||||
const outcome = await Promise.race([call, timedOut]);
|
||||
if (outcome === "timeout" || controller.signal.aborted) {
|
||||
return decisionFailure("timeout", { latencyMs: elapsed() });
|
||||
}
|
||||
if ("status" in outcome) {
|
||||
return decisionFailure("http_error", { status: outcome.status, latencyMs: elapsed() });
|
||||
}
|
||||
const json = outcome.json as { model?: unknown } | null;
|
||||
const answer = parseDecisionAnswerText(extractPanelText(json), json?.model ?? model);
|
||||
return toDecisionChoiceResult(answer, request, elapsed());
|
||||
} catch {
|
||||
return decisionFailure(controller.signal.aborted ? "timeout" : "invalid_response", {
|
||||
latencyMs: elapsed(),
|
||||
});
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
request.signal?.removeEventListener("abort", onCallerAbort);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* Limits and endpoint rules shared by the deciders: timeout default and ceiling, base-URL
|
||||
* validation (#18555), self-gateway detection (#15641) and the per-endpoint failure cooldown.
|
||||
*/
|
||||
|
||||
/** Default decision timeout (ms). */
|
||||
export const DEFAULT_DECISION_TIMEOUT_MS = 2_000;
|
||||
/** Hard ceiling (ms): a decision must never stall dispatch longer than this. */
|
||||
export const MAX_DECISION_TIMEOUT_MS = 5_000;
|
||||
export const MIN_DECISION_TIMEOUT_MS = 100;
|
||||
/** After a failed call, the endpoint is not called again for this long. */
|
||||
export const DECISION_FAILURE_COOLDOWN_MS = 30_000;
|
||||
|
||||
/** Timeout in ms: the default for anything unusable, clamped to [100, 5000]. */
|
||||
export function clampDecisionTimeout(value: unknown): number {
|
||||
const n = typeof value === "number" ? value : Number.NaN;
|
||||
if (!Number.isFinite(n) || n <= 0) return DEFAULT_DECISION_TIMEOUT_MS;
|
||||
return Math.min(MAX_DECISION_TIMEOUT_MS, Math.max(MIN_DECISION_TIMEOUT_MS, Math.round(n)));
|
||||
}
|
||||
|
||||
/** Absolute http(s) URL without credentials, query or fragment; `undefined` otherwise. */
|
||||
export function normalizeDecisionBaseUrl(value: unknown): string | undefined {
|
||||
if (typeof value !== "string" || !value.trim()) return undefined;
|
||||
try {
|
||||
const url = new URL(value.trim());
|
||||
if (
|
||||
!["http:", "https:"].includes(url.protocol) ||
|
||||
url.username ||
|
||||
url.password ||
|
||||
url.search ||
|
||||
url.hash
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
return `${url.origin}${url.pathname.replace(/\/+$/, "")}`;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True when a URL points at this OmniRoute (loopback + the server port): a decision call
|
||||
* there would re-enter the gateway and route again (#15641 `isSelfGatewayBaseUrl`).
|
||||
*/
|
||||
export function isSelfGatewayUrl(baseUrl: string): boolean {
|
||||
try {
|
||||
const url = new URL(baseUrl);
|
||||
const host = url.hostname.toLowerCase();
|
||||
const loopback =
|
||||
host === "127.0.0.1" || host === "localhost" || host === "::1" || host === "[::1]";
|
||||
if (!loopback) return false;
|
||||
const port = url.port || (url.protocol === "https:" ? "443" : "80");
|
||||
return port === (process.env.PORT?.trim() || "20128");
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export interface DecisionCooldown {
|
||||
/** Remaining cooldown in ms for `key` (0 = callable). */
|
||||
remainingMs(key: string): number;
|
||||
trip(key: string): void;
|
||||
}
|
||||
|
||||
/** Per-endpoint cooldown table (#18555); `now` is a clock seam for tests. */
|
||||
export function createDecisionCooldown(now: () => number = Date.now): DecisionCooldown {
|
||||
const until = new Map<string, number>();
|
||||
return {
|
||||
remainingMs(key) {
|
||||
const end = until.get(key) ?? 0;
|
||||
const left = end - now();
|
||||
if (left <= 0) until.delete(key);
|
||||
return Math.max(0, left);
|
||||
},
|
||||
trip(key) {
|
||||
until.set(key, now() + DECISION_FAILURE_COOLDOWN_MS);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Process-wide table used by the live deciders. */
|
||||
export const sharedDecisionCooldown = createDecisionCooldown();
|
||||
@@ -1,81 +0,0 @@
|
||||
/**
|
||||
* Where a network decider's key comes from. Only two sources, never a key typed into the
|
||||
* combo config:
|
||||
* 1. a stored connection, by reference (`connectionId`), read through the normal credential
|
||||
* selection and inside the caller's API-key allowlist (the jevAsk pattern, #15279);
|
||||
* 2. the `OMNIROUTE_DECISION_API_KEY` environment variable.
|
||||
* A referenced connection that the allowlist does not cover yields no key at all: it never
|
||||
* falls through to the environment.
|
||||
*/
|
||||
import { getRegisteredConnectionStore } from "../../utils/registeredConnectionStore.ts";
|
||||
|
||||
export const DECISION_API_KEY_ENV = "OMNIROUTE_DECISION_API_KEY";
|
||||
|
||||
type EnvLike = Record<string, string | undefined>;
|
||||
|
||||
export interface DecisionCredentialArgs {
|
||||
/** Provider of the credential (`typesafe` for the System One decider); `null` = look it up. */
|
||||
provider?: string | null;
|
||||
connectionId?: string;
|
||||
apiKeyAllowedConnections?: string[] | null;
|
||||
}
|
||||
|
||||
export interface DecisionCredentialDeps {
|
||||
getCredentials?: (provider: string, allowlist: string[] | null) => Promise<unknown>;
|
||||
getConnectionProvider?: (connectionId: string) => Promise<string | null>;
|
||||
env?: EnvLike;
|
||||
}
|
||||
|
||||
async function defaultGetCredentials(
|
||||
provider: string,
|
||||
allowlist: string[] | null
|
||||
): Promise<unknown> {
|
||||
// Lazy: the credential selector pulls the DB layer; it loads only for a live decision.
|
||||
const { getProviderCredentials } = await import("../combo/autoStrategy.ts");
|
||||
return getProviderCredentials(provider, null, allowlist);
|
||||
}
|
||||
|
||||
async function defaultGetConnectionProvider(connectionId: string): Promise<string | null> {
|
||||
const connection = (await getRegisteredConnectionStore()?.getProviderConnectionById(
|
||||
connectionId
|
||||
)) as { provider?: unknown } | null | undefined;
|
||||
return typeof connection?.provider === "string" ? connection.provider : null;
|
||||
}
|
||||
|
||||
function readApiKey(credentials: unknown): string | null {
|
||||
const apiKey = (credentials as { apiKey?: unknown } | null)?.apiKey;
|
||||
return typeof apiKey === "string" && apiKey.trim() ? apiKey.trim() : null;
|
||||
}
|
||||
|
||||
/** Key of one referenced connection, only inside the allowlist; never an env fallback. */
|
||||
async function keyFromReferencedConnection(
|
||||
connectionId: string,
|
||||
args: DecisionCredentialArgs,
|
||||
allowlist: string[] | null,
|
||||
deps: DecisionCredentialDeps
|
||||
): Promise<string | null> {
|
||||
if (allowlist && !allowlist.includes(connectionId)) return null;
|
||||
const provider =
|
||||
args.provider ??
|
||||
(await (deps.getConnectionProvider ?? defaultGetConnectionProvider)(connectionId));
|
||||
if (!provider) return null;
|
||||
const getCredentials = deps.getCredentials ?? defaultGetCredentials;
|
||||
return readApiKey(await getCredentials(provider, [connectionId]));
|
||||
}
|
||||
|
||||
export async function resolveDecisionApiKey(
|
||||
args: DecisionCredentialArgs,
|
||||
deps: DecisionCredentialDeps = {}
|
||||
): Promise<string | null> {
|
||||
const allowlist = args.apiKeyAllowedConnections?.length ? args.apiKeyAllowedConnections : null;
|
||||
const connectionId = args.connectionId?.trim();
|
||||
if (connectionId) return keyFromReferencedConnection(connectionId, args, allowlist, deps);
|
||||
|
||||
if (args.provider) {
|
||||
const getCredentials = deps.getCredentials ?? defaultGetCredentials;
|
||||
const stored = readApiKey(await getCredentials(args.provider, allowlist));
|
||||
if (stored) return stored;
|
||||
}
|
||||
const env = deps.env ?? process.env;
|
||||
return env[DECISION_API_KEY_ENV]?.trim() || null;
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
/**
|
||||
* Builds the decider a combo's decision block names, plus the per-request context the
|
||||
* `decision` strategy reads (autoCombo/decisionStrategy.ts).
|
||||
*/
|
||||
import type { ComboCollectionLike, HandleSingleModel } from "../combo/types.ts";
|
||||
import { createComboModelDecider } from "./comboModelDecider.ts";
|
||||
import { clampDecisionTimeout } from "./config.ts";
|
||||
import { createHttpDecider } from "./httpDecider.ts";
|
||||
import type { DecisionConfigResolution, DecisionRoutingConfig } from "./schema.ts";
|
||||
import { createSystemOneDecider } from "./systemOneDecider.ts";
|
||||
import type { Decider } from "./types.ts";
|
||||
|
||||
/** Request-scoped seams the combo pipeline hands to the decision strategy. */
|
||||
export interface DecisionRuntime {
|
||||
signal?: AbortSignal | null;
|
||||
/** The combo's `handleSingleModel` (for the `combo-model` decider). */
|
||||
dispatch?: HandleSingleModel;
|
||||
allCombos?: ComboCollectionLike;
|
||||
}
|
||||
|
||||
export interface DecisionRoutingContext extends DecisionRuntime {
|
||||
config?: DecisionConfigResolution;
|
||||
/** The client request body; only the last user text and its wire shape are read. */
|
||||
body?: Record<string, unknown>;
|
||||
apiKeyAllowedConnections?: string[] | null;
|
||||
}
|
||||
|
||||
/** `undefined` for combos without a decision block, so their routing context is unchanged. */
|
||||
export function buildDecisionRoutingContext(
|
||||
config: DecisionConfigResolution | undefined,
|
||||
runtime: DecisionRuntime | null | undefined,
|
||||
body: Record<string, unknown>,
|
||||
apiKeyAllowedConnections: string[] | null | undefined
|
||||
): DecisionRoutingContext | undefined {
|
||||
if (!config) return undefined;
|
||||
return { ...runtime, config, body, apiKeyAllowedConnections: apiKeyAllowedConnections ?? null };
|
||||
}
|
||||
|
||||
export function createDeciderForConfig(
|
||||
config: DecisionRoutingConfig,
|
||||
context: DecisionRoutingContext
|
||||
): Decider {
|
||||
const timeoutMs = clampDecisionTimeout(config.timeoutMs);
|
||||
const apiKeyAllowedConnections = context.apiKeyAllowedConnections ?? null;
|
||||
if (config.decider === "systemone") {
|
||||
return createSystemOneDecider({
|
||||
model: config.model,
|
||||
connectionId: config.connectionId,
|
||||
timeoutMs,
|
||||
apiKeyAllowedConnections,
|
||||
});
|
||||
}
|
||||
if (config.decider === "http") {
|
||||
return createHttpDecider({
|
||||
baseUrl: config.baseUrl,
|
||||
wire: config.wire,
|
||||
model: config.model,
|
||||
connectionId: config.connectionId,
|
||||
timeoutMs,
|
||||
apiKeyAllowedConnections,
|
||||
});
|
||||
}
|
||||
return createComboModelDecider({
|
||||
model: config.model,
|
||||
timeoutMs,
|
||||
dispatch: context.dispatch,
|
||||
allCombos: context.allCombos,
|
||||
clientBody: context.body ?? null,
|
||||
});
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/**
|
||||
* `http` decider: an operator-run classifier at its own URL, speaking the System One wire
|
||||
* (#18555 `decision-systemone`) or the OpenAI chat-completions wire (#15641 adapters).
|
||||
*
|
||||
* Never called when the URL or model is missing or invalid, when the URL is this gateway,
|
||||
* when a referenced connection yields no key, or while the endpoint cools down after a
|
||||
* failure (30 s, per URL). Only the bounded user text and the menu leave the process.
|
||||
*/
|
||||
import {
|
||||
clampDecisionTimeout,
|
||||
isSelfGatewayUrl,
|
||||
normalizeDecisionBaseUrl,
|
||||
sharedDecisionCooldown,
|
||||
type DecisionCooldown,
|
||||
} from "./config.ts";
|
||||
import { resolveDecisionApiKey } from "./credentials.ts";
|
||||
import { postDecisionJson, type DecisionPostFailure, type DecisionTransport } from "./transport.ts";
|
||||
import { decisionFailure, type Decider, type DecisionWire } from "./types.ts";
|
||||
import {
|
||||
buildOpenAiChatWireBody,
|
||||
buildSystemOneWireBody,
|
||||
parseOpenAiChatWireAnswer,
|
||||
parseSystemOneWireAnswer,
|
||||
resolveChatCompletionsUrl,
|
||||
toDecisionChoiceResult,
|
||||
} from "./wires.ts";
|
||||
|
||||
export interface HttpDeciderOptions {
|
||||
baseUrl?: string;
|
||||
wire?: DecisionWire;
|
||||
model?: string;
|
||||
connectionId?: string;
|
||||
timeoutMs?: number;
|
||||
apiKeyAllowedConnections?: string[] | null;
|
||||
resolveApiKey?: () => Promise<string | null>;
|
||||
transport?: DecisionTransport;
|
||||
cooldown?: DecisionCooldown;
|
||||
now?: () => number;
|
||||
}
|
||||
|
||||
/** Failures that say the endpoint itself is unhealthy (a bad answer does not). */
|
||||
const COOLDOWN_REASONS = new Set(["timeout", "http_error", "network_error"]);
|
||||
|
||||
export function createHttpDecider(options: HttpDeciderOptions): Decider {
|
||||
const wire: DecisionWire = options.wire ?? "systemone";
|
||||
const cooldown = options.cooldown ?? sharedDecisionCooldown;
|
||||
const now = options.now ?? Date.now;
|
||||
const timeoutMs = clampDecisionTimeout(options.timeoutMs);
|
||||
const resolveApiKey =
|
||||
options.resolveApiKey ??
|
||||
(() =>
|
||||
resolveDecisionApiKey({
|
||||
provider: null,
|
||||
connectionId: options.connectionId,
|
||||
apiKeyAllowedConnections: options.apiKeyAllowedConnections,
|
||||
}));
|
||||
|
||||
return async (request) => {
|
||||
const base = normalizeDecisionBaseUrl(options.baseUrl);
|
||||
const model = options.model?.trim();
|
||||
if (!base || !model) return decisionFailure("not_configured");
|
||||
if (isSelfGatewayUrl(base)) return decisionFailure("recursion");
|
||||
const url = wire === "openai-chat" ? resolveChatCompletionsUrl(base) : `${base}/v1/systemone`;
|
||||
if (cooldown.remainingMs(url) > 0) return decisionFailure("cooldown");
|
||||
|
||||
const apiKey = await resolveApiKey();
|
||||
if (!apiKey && options.connectionId?.trim()) return decisionFailure("missing_credential");
|
||||
|
||||
const posted = await postDecisionJson({
|
||||
url,
|
||||
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
|
||||
body:
|
||||
wire === "openai-chat"
|
||||
? buildOpenAiChatWireBody(model, request)
|
||||
: buildSystemOneWireBody(model, request),
|
||||
timeoutMs,
|
||||
signal: request.signal,
|
||||
transport: options.transport,
|
||||
now,
|
||||
});
|
||||
if (!posted.ok) {
|
||||
// `strict: false` does not narrow the `ok` union, so name the failure variant.
|
||||
const failure = posted as DecisionPostFailure;
|
||||
if (COOLDOWN_REASONS.has(failure.reason)) cooldown.trip(url);
|
||||
return failure;
|
||||
}
|
||||
const answer =
|
||||
wire === "openai-chat"
|
||||
? parseOpenAiChatWireAnswer(posted.data)
|
||||
: parseSystemOneWireAnswer(posted.data);
|
||||
return toDecisionChoiceResult(answer, request, posted.latencyMs);
|
||||
};
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/**
|
||||
* What a decider is shown: the menu of model ids, one description per entry, and the
|
||||
* bounded text of the last user message. Nothing else of the request leaves the process:
|
||||
* no system prompt, tools, assistant turns, tool output, headers or account data.
|
||||
*
|
||||
* Menu and descriptions ported from #18555 (decisionModelStrategy.ts).
|
||||
*/
|
||||
import type { ProviderCandidate } from "../autoCombo/scoring.ts";
|
||||
|
||||
/** Menu cap shared by every decider (and by the `descriptions` schema). */
|
||||
export const MAX_DECISION_MENU_ITEMS = 50;
|
||||
/** Cap on the user text sent to a decider. */
|
||||
export const MAX_DECISION_STATE_CHARS = 8_000;
|
||||
|
||||
type Part = { type?: unknown; text?: unknown } | null;
|
||||
|
||||
/** Joined text parts (`text` / `input_text`) of one message content; `null` when empty. */
|
||||
function readContentText(content: unknown): string | null {
|
||||
if (typeof content === "string") return content.trim() || null;
|
||||
if (!Array.isArray(content)) return null;
|
||||
const text = content
|
||||
.map((part: unknown) => {
|
||||
const item = part as Part;
|
||||
const isText = item?.type === "text" || item?.type === "input_text";
|
||||
return isText && typeof item?.text === "string" ? item.text : "";
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join("\n")
|
||||
.trim();
|
||||
return text || null;
|
||||
}
|
||||
|
||||
/** Text of the last `role: "user"` item of a messages / Responses input array. */
|
||||
function lastUserText(items: unknown): string | null {
|
||||
if (!Array.isArray(items)) return null;
|
||||
for (let index = items.length - 1; index >= 0; index -= 1) {
|
||||
const item = items[index] as { role?: unknown; type?: unknown; content?: unknown } | null;
|
||||
if (!item || item.role !== "user") continue;
|
||||
if (item.type !== undefined && item.type !== "message") continue;
|
||||
return readContentText(item.content);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bounded text of the last user message: chat/Claude `messages`, else Responses `input`
|
||||
* (a string or message items). Claude's top-level `system` and Responses `instructions`
|
||||
* are never read. `null` when the request carries no user text.
|
||||
*/
|
||||
export function extractDecisionUserText(body: unknown): string | null {
|
||||
if (!body || typeof body !== "object") return null;
|
||||
const record = body as { messages?: unknown; input?: unknown };
|
||||
const text =
|
||||
lastUserText(record.messages) ??
|
||||
(typeof record.input === "string" ? record.input.trim() || null : lastUserText(record.input));
|
||||
return text ? text.slice(0, MAX_DECISION_STATE_CHARS) : null;
|
||||
}
|
||||
|
||||
/** Unique pool models in pool order, capped at `MAX_DECISION_MENU_ITEMS`. */
|
||||
export function buildDecisionMenu(candidates: Pick<ProviderCandidate, "model">[]): string[] {
|
||||
return [...new Set(candidates.map((item) => item.model))].slice(0, MAX_DECISION_MENU_ITEMS);
|
||||
}
|
||||
|
||||
/**
|
||||
* One description per menu entry. An operator description (by model id, else by
|
||||
* `provider/model`) wins; otherwise the text carries the pool's cost ranking, but only
|
||||
* when costs differ — unpriced models are left out of the ranking.
|
||||
*/
|
||||
export function describeDecisionMenu(
|
||||
menu: string[],
|
||||
candidates: Pick<ProviderCandidate, "provider" | "model" | "costPer1MTokens">[],
|
||||
descriptions: Record<string, string> | undefined
|
||||
): Record<string, string> {
|
||||
const costs = new Map<string, number>();
|
||||
for (const item of candidates) {
|
||||
const cost = item.costPer1MTokens;
|
||||
if (!Number.isFinite(cost) || cost < 0) continue;
|
||||
costs.set(item.model, Math.min(costs.get(item.model) ?? Infinity, cost));
|
||||
}
|
||||
const ranked = [...new Set(menu.map((id) => costs.get(id)).filter((c) => c !== undefined))].sort(
|
||||
(a, b) => a - b
|
||||
);
|
||||
return Object.fromEntries(
|
||||
menu.map((id) => {
|
||||
const operator =
|
||||
descriptions?.[id] ??
|
||||
candidates
|
||||
.filter((item) => item.model === id)
|
||||
.map((item) => descriptions?.[`${item.provider}/${id}`])
|
||||
.find(Boolean);
|
||||
if (operator) return [id, operator];
|
||||
const cost = costs.get(id);
|
||||
if (cost === undefined || ranked.length < 2) return [id, `Model ${id}`];
|
||||
return [
|
||||
id,
|
||||
`Model ${id}; estimated cost $${Number(cost.toPrecision(3))} per 1M tokens (cost rank ${
|
||||
ranked.indexOf(cost) + 1
|
||||
} of ${ranked.length}, 1 = cheapest)`,
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/**
|
||||
* Strict schema of a combo's decision block (`config.auto.decision`, or `config.decision`
|
||||
* when the combo keeps its router knobs at the top level). The combo save schema and the
|
||||
* runtime parser share it, so a stored block that fails it is never used.
|
||||
*
|
||||
* No secret belongs here: the credential is a `connectionId` reference (or an environment
|
||||
* variable), and `.strict()` rejects an `apiKey` field outright (#14239 pattern).
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { MAX_DECISION_MENU_ITEMS } from "./menu.ts";
|
||||
import {
|
||||
MAX_DECISION_TIMEOUT_MS,
|
||||
MIN_DECISION_TIMEOUT_MS,
|
||||
normalizeDecisionBaseUrl,
|
||||
} from "./config.ts";
|
||||
import { DECIDER_KINDS, DECISION_WIRES } from "./types.ts";
|
||||
|
||||
export const MAX_DECISION_DESCRIPTION_KEY_CHARS = 300;
|
||||
export const MAX_DECISION_DESCRIPTION_CHARS = 1_000;
|
||||
|
||||
export const decisionRoutingConfigSchema = z
|
||||
.object({
|
||||
decider: z.enum(DECIDER_KINDS),
|
||||
/** TypeSafe model, http decision model, or the `provider/model` of a combo-model call. */
|
||||
model: z.string().trim().min(1).max(200).optional(),
|
||||
baseUrl: z
|
||||
.string()
|
||||
.trim()
|
||||
.max(500)
|
||||
.refine((value) => normalizeDecisionBaseUrl(value) !== undefined, {
|
||||
message: "baseUrl must be an http(s) URL without credentials, query or fragment",
|
||||
})
|
||||
.optional(),
|
||||
connectionId: z.string().trim().min(1).max(200).optional(),
|
||||
wire: z.enum(DECISION_WIRES).optional(),
|
||||
timeoutMs: z.coerce
|
||||
.number()
|
||||
.int()
|
||||
.min(MIN_DECISION_TIMEOUT_MS)
|
||||
.max(MAX_DECISION_TIMEOUT_MS)
|
||||
.optional(),
|
||||
minConfidence: z.coerce.number().min(0).max(1).optional(),
|
||||
// Keyed by model id or provider/model; capped like the decision menu.
|
||||
descriptions: z
|
||||
.record(
|
||||
z.string().trim().min(1).max(MAX_DECISION_DESCRIPTION_KEY_CHARS),
|
||||
z.string().trim().min(1).max(MAX_DECISION_DESCRIPTION_CHARS)
|
||||
)
|
||||
.refine((value) => Object.keys(value).length <= MAX_DECISION_MENU_ITEMS, {
|
||||
message: `At most ${MAX_DECISION_MENU_ITEMS} model descriptions`,
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
export type DecisionRoutingConfig = z.infer<typeof decisionRoutingConfigSchema>;
|
||||
|
||||
export type DecisionConfigResolution =
|
||||
{ valid: true; config: DecisionRoutingConfig } | { valid: false };
|
||||
|
||||
/** `undefined` when the combo has no decision block; `{valid:false}` when it fails the schema. */
|
||||
export function resolveDecisionRoutingConfig(raw: unknown): DecisionConfigResolution | undefined {
|
||||
if (raw === undefined || raw === null) return undefined;
|
||||
const parsed = decisionRoutingConfigSchema.safeParse(raw);
|
||||
return parsed.success ? { valid: true, config: parsed.data } : { valid: false };
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Depth guard for decision calls. A `combo-model` decision runs a model in process; anything
|
||||
* that would start another decision inside that call sees `decisionDepth() > 0` and falls
|
||||
* back instead (the in-process twin of the `x-omniroute-decision-model` header).
|
||||
*/
|
||||
import { AsyncLocalStorage } from "node:async_hooks";
|
||||
|
||||
const depthStore = new AsyncLocalStorage<number>();
|
||||
|
||||
/** Decision calls currently running in this async context (0 outside any). */
|
||||
export function decisionDepth(): number {
|
||||
return depthStore.getStore() ?? 0;
|
||||
}
|
||||
|
||||
export function runInDecisionScope<T>(fn: () => Promise<T>): Promise<T> {
|
||||
return depthStore.run(decisionDepth() + 1, fn);
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* `systemone` decider: TypeSafe System One through the base client (#15278,
|
||||
* typesafe/systemOne.ts), whose transport is the guarded decision transport.
|
||||
*/
|
||||
import {
|
||||
evaluateSystemOneChoice,
|
||||
TYPESAFE_PROVIDER_ID,
|
||||
type SystemOneChoiceResult,
|
||||
type EvaluateSystemOneChoiceOptions,
|
||||
type SystemOneChoiceUnavailable,
|
||||
} from "../typesafe/systemOne.ts";
|
||||
import { resolveDecisionApiKey } from "./credentials.ts";
|
||||
import {
|
||||
decisionFailure,
|
||||
toLoggableModelName,
|
||||
type Decider,
|
||||
type DecisionChoiceResult,
|
||||
} from "./types.ts";
|
||||
|
||||
export interface SystemOneDeciderOptions {
|
||||
/** TypeSafe decision model; the client default (`jev-latest`) when unset. */
|
||||
model?: string;
|
||||
connectionId?: string;
|
||||
timeoutMs: number;
|
||||
apiKeyAllowedConnections?: string[] | null;
|
||||
resolveApiKey?: () => Promise<string | null>;
|
||||
evaluate?: (options: EvaluateSystemOneChoiceOptions) => Promise<SystemOneChoiceResult>;
|
||||
now?: () => number;
|
||||
}
|
||||
|
||||
export function createSystemOneDecider(options: SystemOneDeciderOptions): Decider {
|
||||
const evaluate = options.evaluate ?? evaluateSystemOneChoice;
|
||||
const now = options.now ?? Date.now;
|
||||
const resolveApiKey =
|
||||
options.resolveApiKey ??
|
||||
(() =>
|
||||
resolveDecisionApiKey({
|
||||
provider: TYPESAFE_PROVIDER_ID,
|
||||
connectionId: options.connectionId,
|
||||
apiKeyAllowedConnections: options.apiKeyAllowedConnections,
|
||||
}));
|
||||
|
||||
return async (request): Promise<DecisionChoiceResult> => {
|
||||
const apiKey = await resolveApiKey();
|
||||
if (!apiKey) return decisionFailure("missing_credential");
|
||||
const startedAt = now();
|
||||
const result = await evaluate({
|
||||
apiKey,
|
||||
state: request.state,
|
||||
criteria: request.options,
|
||||
instructions: request.instructions,
|
||||
model: options.model,
|
||||
timeoutMs: options.timeoutMs,
|
||||
signal: request.signal,
|
||||
});
|
||||
if (result.ok) {
|
||||
return {
|
||||
ok: true,
|
||||
choice: result.choice,
|
||||
confidence: result.confidence,
|
||||
probabilities: result.probabilities,
|
||||
...(toLoggableModelName(result.model) && {
|
||||
backendModel: toLoggableModelName(result.model),
|
||||
}),
|
||||
latencyMs: Math.max(0, now() - startedAt),
|
||||
};
|
||||
}
|
||||
// `strict: false` does not narrow the `ok` union, so name the unavailable variant.
|
||||
const failure = result as SystemOneChoiceUnavailable;
|
||||
if (failure.reason === "missing_api_key") return decisionFailure("missing_credential");
|
||||
if (failure.reason === "empty_criteria") return decisionFailure("not_configured");
|
||||
if (failure.reason === "http_error") {
|
||||
return decisionFailure("http_error", { status: failure.status });
|
||||
}
|
||||
return decisionFailure(failure.reason);
|
||||
};
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/**
|
||||
* The single outbound path of the network deciders (TypeSafe, operator URLs).
|
||||
*
|
||||
* - `safeOutboundFetch` with the provider outbound guard (SSRF policy + global proxy), no
|
||||
* retries, redirects refused (`allowRedirect: false` blocks every 3xx; the transport seam
|
||||
* also receives `redirect: "error"`, #14239);
|
||||
* - the response body is read up to 64 KB (`readBoundedJson`, #14239), so a hostile or broken
|
||||
* decider cannot make the router buffer an unbounded answer;
|
||||
* - one timeout bounds the whole round trip, body included, and a caller abort cancels it;
|
||||
* - failures are status-only: an upstream body can echo the prompt or the key.
|
||||
*/
|
||||
import { DEFAULT_DECISION_TIMEOUT_MS, MAX_DECISION_TIMEOUT_MS } from "./config.ts";
|
||||
import { DECISION_MODEL_REQUEST_HEADER, type DecisionFailureReason } from "./types.ts";
|
||||
|
||||
export const MAX_DECISION_RESPONSE_BYTES = 64 * 1024;
|
||||
|
||||
export interface DecisionTransportInit {
|
||||
method: "POST";
|
||||
headers: Record<string, string>;
|
||||
body: string;
|
||||
timeoutMs: number;
|
||||
signal: AbortSignal;
|
||||
redirect: "error";
|
||||
}
|
||||
|
||||
/** The HTTP seam: production uses safeOutboundFetch, tests inject a fake. */
|
||||
export type DecisionTransport = (url: string, init: DecisionTransportInit) => Promise<Response>;
|
||||
|
||||
export const defaultDecisionTransport: DecisionTransport = async (url, init) => {
|
||||
// Lazy so this module stays free of the proxy/TLS fetch stack until the first call.
|
||||
const [{ safeOutboundFetch }, { getProviderOutboundGuard }] = await Promise.all([
|
||||
import("@/shared/network/safeOutboundFetch"),
|
||||
import("@/shared/network/outboundUrlGuardPolicy"),
|
||||
]);
|
||||
return safeOutboundFetch(url, {
|
||||
method: init.method,
|
||||
headers: init.headers,
|
||||
body: init.body,
|
||||
signal: init.signal,
|
||||
timeoutMs: init.timeoutMs,
|
||||
redirect: init.redirect,
|
||||
allowRedirect: false,
|
||||
retry: false,
|
||||
guard: getProviderOutboundGuard(),
|
||||
});
|
||||
};
|
||||
|
||||
class DecisionTransportError extends Error {
|
||||
constructor(readonly reason: DecisionFailureReason) {
|
||||
super(reason);
|
||||
this.name = "DecisionTransportError";
|
||||
}
|
||||
}
|
||||
|
||||
/** Parse a JSON body of at most `maxBytes`; throws `oversized` / `invalid_json`. */
|
||||
export async function readBoundedJson(
|
||||
response: Response,
|
||||
maxBytes = MAX_DECISION_RESPONSE_BYTES
|
||||
): Promise<unknown> {
|
||||
if (!response.body) throw new Error("invalid_json");
|
||||
const reader = response.body.getReader();
|
||||
const chunks: Uint8Array[] = [];
|
||||
let size = 0;
|
||||
try {
|
||||
for (;;) {
|
||||
const result = await reader.read();
|
||||
if (result.done) break;
|
||||
size += result.value.byteLength;
|
||||
if (size > maxBytes) {
|
||||
await reader.cancel().catch(() => {});
|
||||
throw new Error("oversized");
|
||||
}
|
||||
chunks.push(result.value);
|
||||
}
|
||||
} finally {
|
||||
reader.releaseLock();
|
||||
}
|
||||
const bytes = new Uint8Array(size);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
bytes.set(chunk, offset);
|
||||
offset += chunk.byteLength;
|
||||
}
|
||||
try {
|
||||
return JSON.parse(new TextDecoder().decode(bytes));
|
||||
} catch {
|
||||
throw new Error("invalid_json");
|
||||
}
|
||||
}
|
||||
|
||||
export type DecisionPostFailure = {
|
||||
ok: false;
|
||||
reason: DecisionFailureReason;
|
||||
status?: number;
|
||||
latencyMs: number;
|
||||
};
|
||||
|
||||
export type DecisionPostResult =
|
||||
{ ok: true; data: unknown; latencyMs: number } | DecisionPostFailure;
|
||||
|
||||
export interface DecisionPostOptions {
|
||||
url: string;
|
||||
headers: Record<string, string>;
|
||||
body: unknown;
|
||||
timeoutMs: number;
|
||||
signal?: AbortSignal | null;
|
||||
transport?: DecisionTransport;
|
||||
now?: () => number;
|
||||
}
|
||||
|
||||
/** Map a thrown transport error to a reason; the message itself is never kept. */
|
||||
function reasonFor(error: unknown, controller: AbortController): DecisionFailureReason {
|
||||
if (error instanceof DecisionTransportError) return error.reason;
|
||||
if (controller.signal.aborted) return "timeout";
|
||||
const record = error as { name?: unknown; code?: unknown } | null;
|
||||
if (record?.name === "AbortError" || record?.code === "TIMEOUT") return "timeout";
|
||||
return "network_error";
|
||||
}
|
||||
|
||||
async function cancelBody(response: Response): Promise<void> {
|
||||
try {
|
||||
await response.body?.cancel();
|
||||
} catch {
|
||||
// The status is all the caller needs; a body that cannot be cancelled is dropped.
|
||||
}
|
||||
}
|
||||
|
||||
/** One decision round trip. Never throws. */
|
||||
export async function postDecisionJson(options: DecisionPostOptions): Promise<DecisionPostResult> {
|
||||
const now = options.now ?? Date.now;
|
||||
const startedAt = now();
|
||||
const elapsed = () => Math.max(0, now() - startedAt);
|
||||
if (options.signal?.aborted) return { ok: false, reason: "timeout", latencyMs: 0 };
|
||||
|
||||
const controller = new AbortController();
|
||||
let rejectStop: (error: DecisionTransportError) => void = () => {};
|
||||
const stopped = new Promise<never>((_, reject) => {
|
||||
rejectStop = reject;
|
||||
});
|
||||
// The race below observes the rejection; this keeps a late one from surfacing as unhandled.
|
||||
stopped.catch(() => {});
|
||||
const stop = (reason: DecisionFailureReason) => {
|
||||
controller.abort();
|
||||
rejectStop(new DecisionTransportError(reason));
|
||||
};
|
||||
const onCallerAbort = () => stop("timeout");
|
||||
options.signal?.addEventListener("abort", onCallerAbort, { once: true });
|
||||
// Callers pass a clamped value already; the explicit bound here keeps the timer delay
|
||||
// provably capped at the call site, whatever a future caller passes.
|
||||
const timeoutMs =
|
||||
options.timeoutMs > 0 && options.timeoutMs <= MAX_DECISION_TIMEOUT_MS
|
||||
? options.timeoutMs
|
||||
: DEFAULT_DECISION_TIMEOUT_MS;
|
||||
const timer = setTimeout(() => stop("timeout"), timeoutMs);
|
||||
|
||||
const operation = async (): Promise<unknown> => {
|
||||
const transport = options.transport ?? defaultDecisionTransport;
|
||||
const response = await transport(options.url, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
...options.headers,
|
||||
"Content-Type": "application/json",
|
||||
[DECISION_MODEL_REQUEST_HEADER]: "1",
|
||||
},
|
||||
body: JSON.stringify(options.body),
|
||||
timeoutMs,
|
||||
signal: controller.signal,
|
||||
redirect: "error",
|
||||
});
|
||||
if (!response.ok) {
|
||||
await cancelBody(response);
|
||||
throw Object.assign(new DecisionTransportError("http_error"), { status: response.status });
|
||||
}
|
||||
try {
|
||||
return await readBoundedJson(response);
|
||||
} catch {
|
||||
throw new DecisionTransportError(controller.signal.aborted ? "timeout" : "invalid_response");
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
const data = await Promise.race([operation(), stopped]);
|
||||
return { ok: true, data, latencyMs: elapsed() };
|
||||
} catch (error) {
|
||||
const status = (error as { status?: unknown }).status;
|
||||
return {
|
||||
ok: false,
|
||||
reason: reasonFor(error, controller),
|
||||
...(typeof status === "number" ? { status } : {}),
|
||||
latencyMs: elapsed(),
|
||||
};
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
options.signal?.removeEventListener("abort", onCallerAbort);
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/**
|
||||
* Shared contract for the `decision` auto-router strategy (autoCombo/decisionStrategy.ts).
|
||||
*
|
||||
* A decider answers one question: which entry of a menu of model ids should serve this
|
||||
* request. Every decider returns a `DecisionChoiceResult` and never throws; the strategy
|
||||
* turns any failure into the `rules` fallback with the reason in the log.
|
||||
*/
|
||||
|
||||
/** `systemone` = TypeSafe System One; `http` = an operator URL; `combo-model` = in process. */
|
||||
export const DECIDER_KINDS = ["systemone", "http", "combo-model"] as const;
|
||||
export type DeciderKind = (typeof DECIDER_KINDS)[number];
|
||||
|
||||
/** Wire format an `http` decider speaks. */
|
||||
export const DECISION_WIRES = ["systemone", "openai-chat"] as const;
|
||||
export type DecisionWire = (typeof DECISION_WIRES)[number];
|
||||
|
||||
/** Log-safe failure causes. None of them carries a URL, key, prompt or upstream body. */
|
||||
export const DECISION_FAILURE_REASONS = [
|
||||
"disabled",
|
||||
"not_configured",
|
||||
"missing_credential",
|
||||
"timeout",
|
||||
"http_error",
|
||||
"invalid_response",
|
||||
"out_of_menu",
|
||||
"refused",
|
||||
"cooldown",
|
||||
"network_error",
|
||||
"recursion",
|
||||
] as const;
|
||||
export type DecisionFailureReason = (typeof DECISION_FAILURE_REASONS)[number];
|
||||
|
||||
export interface DecisionChoiceRequest {
|
||||
/** Bounded user text (see menu.ts `extractDecisionUserText`). */
|
||||
state: string;
|
||||
/** Menu: model id → description sent to the decider. */
|
||||
options: Record<string, string>;
|
||||
instructions?: string;
|
||||
signal?: AbortSignal | null;
|
||||
}
|
||||
|
||||
export type DecisionChoiceSuccess = {
|
||||
ok: true;
|
||||
choice: string;
|
||||
/** 0..1; a decider that cannot report one returns 0 (fail-safe for `minConfidence`). */
|
||||
confidence: number;
|
||||
probabilities: Record<string, number>;
|
||||
/** Model that answered, truncated for logs. */
|
||||
backendModel?: string;
|
||||
latencyMs: number;
|
||||
};
|
||||
|
||||
export type DecisionChoiceFailure = {
|
||||
ok: false;
|
||||
reason: DecisionFailureReason;
|
||||
/** HTTP status for `http_error`. */
|
||||
status?: number | null;
|
||||
latencyMs?: number;
|
||||
};
|
||||
|
||||
export type DecisionChoiceResult = DecisionChoiceSuccess | DecisionChoiceFailure;
|
||||
|
||||
export type Decider = (request: DecisionChoiceRequest) => Promise<DecisionChoiceResult>;
|
||||
|
||||
/** Routing instruction shared by every decider. */
|
||||
export const DEFAULT_DECISION_INSTRUCTIONS =
|
||||
"Choose the cheapest model tier in this pool that can reliably complete the user's request. Use a more capable tier only when the task requires it.";
|
||||
|
||||
/**
|
||||
* Marks a request that is itself a decision call, so a gateway that receives it can skip
|
||||
* decision routing (#15641). Sent on every outbound decider request.
|
||||
*/
|
||||
export const DECISION_MODEL_REQUEST_HEADER = "x-omniroute-decision-model";
|
||||
|
||||
/** Longest upstream model name that may reach the log. */
|
||||
export const MAX_LOGGED_MODEL_CHARS = 100;
|
||||
|
||||
const LOGGABLE_MODEL_NAME = /^[A-Za-z0-9][\w.:/@+-]*$/;
|
||||
|
||||
/**
|
||||
* The upstream-reported model name, only when it looks like a model id (no spaces, at most
|
||||
* 100 characters). It comes from the decider's response body, so anything else is dropped
|
||||
* rather than logged.
|
||||
*/
|
||||
export function toLoggableModelName(value: unknown): string | undefined {
|
||||
if (typeof value !== "string") return undefined;
|
||||
const name = value.trim();
|
||||
return name.length <= MAX_LOGGED_MODEL_CHARS && LOGGABLE_MODEL_NAME.test(name) ? name : undefined;
|
||||
}
|
||||
|
||||
export function decisionFailure(
|
||||
reason: DecisionFailureReason,
|
||||
extra: { status?: number | null; latencyMs?: number } = {}
|
||||
): DecisionChoiceFailure {
|
||||
return { ok: false, reason, ...extra };
|
||||
}
|
||||
|
||||
/**
|
||||
* True when `headers` carries the decision-call marker. Reads both a `Headers` object and
|
||||
* the plain record a client request is often copied into (case-insensitive scan) (#15641).
|
||||
*/
|
||||
export function isDecisionModelRequest(
|
||||
headers: { get?: (name: string) => string | null } | Record<string, unknown> | null | undefined
|
||||
): boolean {
|
||||
if (!headers) return false;
|
||||
const get = (headers as { get?: (name: string) => string | null }).get;
|
||||
if (typeof get === "function") {
|
||||
try {
|
||||
if (get.call(headers, DECISION_MODEL_REQUEST_HEADER) === "1") return true;
|
||||
} catch {
|
||||
// fall through to the record scan
|
||||
}
|
||||
}
|
||||
for (const [name, value] of Object.entries(headers as Record<string, unknown>)) {
|
||||
if (name.toLowerCase() === DECISION_MODEL_REQUEST_HEADER && value === "1") return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
/**
|
||||
* Request bodies and answer parsing for the two decision wires.
|
||||
*
|
||||
* - `systemone`: POST `{base}/v1/systemone` with `{model, state, questions}` and an
|
||||
* `answers.route` choice back (TypeSafe System One contract, also served by
|
||||
* OmniRoute's own `/v1/systemone`).
|
||||
* - `openai-chat`: any OpenAI-compatible chat-completions endpoint. The question is
|
||||
* serialized into a strict JSON prompt and `choices[0].message.content` is parsed back
|
||||
* (#15641 adapters: `OPENAI_DECISION_SYSTEM_PROMPT`, `extractJsonObject`,
|
||||
* `normalizeAnswer`). The in-process `combo-model` decider uses the same prompt.
|
||||
*
|
||||
* Envelopes are validated with zod; anything unusable becomes `invalid_response`, a choice
|
||||
* outside the menu `out_of_menu`, an explicit refusal `refused`.
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
toLoggableModelName,
|
||||
type DecisionChoiceRequest,
|
||||
type DecisionChoiceResult,
|
||||
DEFAULT_DECISION_INSTRUCTIONS,
|
||||
} from "./types.ts";
|
||||
|
||||
/** Small answer budget: the decider only returns one JSON object. */
|
||||
export const DECISION_MAX_OUTPUT_TOKENS = 256;
|
||||
|
||||
export const OPENAI_DECISION_SYSTEM_PROMPT =
|
||||
"You are a decision oracle. Answer each atomic question about the provided state. " +
|
||||
"Respond with ONLY one JSON object of the form " +
|
||||
'{"answers":{"<question id>": <answer>}}. For a question of type "noul" the answer is ' +
|
||||
'{"noul": <probability between 0 and 1>}. For "choice" it is ' +
|
||||
'{"choice": "<one of the provided criteria keys>", "confidence": <0..1>}. For "score" it is ' +
|
||||
'{"score": <number>}. Include every question id. Never add prose, markdown fences, or extra keys.';
|
||||
|
||||
export type ParsedDecisionAnswer =
|
||||
| {
|
||||
kind: "choice";
|
||||
choice: string;
|
||||
confidence: number;
|
||||
probabilities: Record<string, number>;
|
||||
backendModel?: string;
|
||||
}
|
||||
| { kind: "refusal"; backendModel?: string }
|
||||
| null;
|
||||
|
||||
const numberMapSchema = z.record(z.string(), z.number().finite());
|
||||
|
||||
/** Clamp to [0, 1]; non-finite input yields null. */
|
||||
function clampUnit(value: unknown): number | null {
|
||||
const parsed = typeof value === "number" ? value : Number.NaN;
|
||||
if (!Number.isFinite(parsed)) return null;
|
||||
return Math.min(1, Math.max(0, parsed));
|
||||
}
|
||||
|
||||
function routeQuestion(request: DecisionChoiceRequest) {
|
||||
return {
|
||||
type: "choice",
|
||||
instructions: request.instructions?.trim() || DEFAULT_DECISION_INSTRUCTIONS,
|
||||
criteria: request.options,
|
||||
};
|
||||
}
|
||||
|
||||
function backendModelOf(value: unknown): string | undefined {
|
||||
return toLoggableModelName(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize one `route` answer. A missing `confidence` becomes 0, not 1: a decider that
|
||||
* cannot report confidence must never satisfy a confidence-gated decision (#15641).
|
||||
*/
|
||||
export function normalizeRouteAnswer(raw: unknown, model?: unknown): ParsedDecisionAnswer {
|
||||
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return null;
|
||||
const record = raw as Record<string, unknown>;
|
||||
const backendModel = backendModelOf(model);
|
||||
if (record.type === "refusal") return { kind: "refusal", ...(backendModel && { backendModel }) };
|
||||
if (record.type !== undefined && record.type !== "choice") return null;
|
||||
const choice = typeof record.choice === "string" ? record.choice.trim() : "";
|
||||
if (!choice) return null;
|
||||
const probabilities = numberMapSchema.safeParse(record.probabilities);
|
||||
return {
|
||||
kind: "choice",
|
||||
choice,
|
||||
confidence: clampUnit(record.confidence) ?? 0,
|
||||
probabilities: probabilities.success ? probabilities.data : {},
|
||||
...(backendModel && { backendModel }),
|
||||
};
|
||||
}
|
||||
|
||||
// ── systemone wire ──────────────────────────────────────────────────────────
|
||||
|
||||
export function buildSystemOneWireBody(model: string, request: DecisionChoiceRequest) {
|
||||
return { model, state: request.state, questions: { route: routeQuestion(request) } };
|
||||
}
|
||||
|
||||
const SystemOneEnvelopeSchema = z.object({
|
||||
model: z.unknown().optional(),
|
||||
answers: z.record(z.string(), z.unknown()),
|
||||
});
|
||||
|
||||
export function parseSystemOneWireAnswer(data: unknown): ParsedDecisionAnswer {
|
||||
const parsed = SystemOneEnvelopeSchema.safeParse(data);
|
||||
if (!parsed.success) return null;
|
||||
return normalizeRouteAnswer(parsed.data.answers.route, parsed.data.model);
|
||||
}
|
||||
|
||||
// ── openai-chat wire ────────────────────────────────────────────────────────
|
||||
|
||||
/** Chat-completions URL from an API root; tolerates a root ending in /v1 or the full path. */
|
||||
export function resolveChatCompletionsUrl(baseUrl: string): string {
|
||||
if (baseUrl.endsWith("/chat/completions")) return baseUrl;
|
||||
if (baseUrl.endsWith("/v1")) return `${baseUrl}/chat/completions`;
|
||||
return `${baseUrl}/v1/chat/completions`;
|
||||
}
|
||||
|
||||
/** Extract a JSON object from model text that may carry fences or surrounding prose. */
|
||||
export function extractJsonObject(text: string): unknown {
|
||||
const trimmed = text.trim();
|
||||
const fenced = trimmed.match(/```(?:json)?\s*([\s\S]*?)```/);
|
||||
const candidate = fenced ? fenced[1].trim() : trimmed;
|
||||
try {
|
||||
return JSON.parse(candidate);
|
||||
} catch {
|
||||
const start = candidate.indexOf("{");
|
||||
const end = candidate.lastIndexOf("}");
|
||||
if (start === -1 || end <= start) return null;
|
||||
try {
|
||||
return JSON.parse(candidate.slice(start, end + 1));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The two chat messages of a decision call: strict JSON system prompt + state and question. */
|
||||
export function buildOpenAiDecisionMessages(request: DecisionChoiceRequest) {
|
||||
const questions = JSON.stringify({ route: routeQuestion(request) }, null, 2);
|
||||
return [
|
||||
{ role: "system", content: OPENAI_DECISION_SYSTEM_PROMPT },
|
||||
{ role: "user", content: `STATE:\n${request.state}\n\nQUESTIONS:\n${questions}` },
|
||||
];
|
||||
}
|
||||
|
||||
/** Non-streaming, tool-free, deterministic chat body for a decision call. */
|
||||
export function buildOpenAiChatWireBody(model: string, request: DecisionChoiceRequest) {
|
||||
return {
|
||||
model,
|
||||
stream: false,
|
||||
temperature: 0,
|
||||
max_tokens: DECISION_MAX_OUTPUT_TOKENS,
|
||||
messages: buildOpenAiDecisionMessages(request),
|
||||
};
|
||||
}
|
||||
|
||||
const ContentPartSchema = z.union([z.string(), z.object({ text: z.string() })]);
|
||||
const OpenAiEnvelopeSchema = z.object({
|
||||
model: z.unknown().optional(),
|
||||
choices: z
|
||||
.array(
|
||||
z.object({
|
||||
message: z
|
||||
.object({ content: z.union([z.string(), z.array(ContentPartSchema)]).nullish() })
|
||||
.optional(),
|
||||
})
|
||||
)
|
||||
.min(1),
|
||||
});
|
||||
|
||||
/** Parse a decision answer out of assistant text (fences and prose tolerated). */
|
||||
export function parseDecisionAnswerText(text: string, model?: unknown): ParsedDecisionAnswer {
|
||||
const json = extractJsonObject(text) as { answers?: { route?: unknown } } | null;
|
||||
if (!json || typeof json !== "object") return null;
|
||||
return normalizeRouteAnswer(json.answers?.route, model);
|
||||
}
|
||||
|
||||
export function parseOpenAiChatWireAnswer(data: unknown): ParsedDecisionAnswer {
|
||||
const parsed = OpenAiEnvelopeSchema.safeParse(data);
|
||||
if (!parsed.success) return null;
|
||||
const content = parsed.data.choices[0].message?.content;
|
||||
const text =
|
||||
typeof content === "string"
|
||||
? content
|
||||
: Array.isArray(content)
|
||||
? content.map((part) => (typeof part === "string" ? part : part.text)).join("\n")
|
||||
: "";
|
||||
return text.trim() ? parseDecisionAnswerText(text, parsed.data.model) : null;
|
||||
}
|
||||
|
||||
// ── shared ──────────────────────────────────────────────────────────────────
|
||||
|
||||
/** Turn a parsed answer into the decider result; the choice must be a menu entry. */
|
||||
export function toDecisionChoiceResult(
|
||||
answer: ParsedDecisionAnswer,
|
||||
request: DecisionChoiceRequest,
|
||||
latencyMs: number
|
||||
): DecisionChoiceResult {
|
||||
if (!answer) return { ok: false, reason: "invalid_response", latencyMs };
|
||||
if (answer.kind === "refusal") return { ok: false, reason: "refused", latencyMs };
|
||||
if (!Object.prototype.hasOwnProperty.call(request.options, answer.choice)) {
|
||||
return { ok: false, reason: "out_of_menu", latencyMs };
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
choice: answer.choice,
|
||||
confidence: answer.confidence,
|
||||
probabilities: answer.probabilities,
|
||||
...(answer.backendModel && { backendModel: answer.backendModel }),
|
||||
latencyMs,
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
isDailyQuotaExhausted,
|
||||
isOAuthInvalidToken,
|
||||
} from "./accountFallback.ts";
|
||||
import { isSubscriptionQuotaForStatus } from "./quotaTextCooldowns.ts";
|
||||
import { isSubscriptionQuotaText } from "./quotaTextCooldowns.ts";
|
||||
import { isCreditsExhaustedForStatus } from "./accountFallback/creditsExhaustedForStatus.ts";
|
||||
import { isProviderSafetyRefusalBody } from "../utils/providerSafety.ts";
|
||||
import { isModelScopedAccessDenial } from "./accountFallback/modelScopedAccessDenial.ts";
|
||||
@@ -453,9 +453,8 @@ export function classifyProviderError(
|
||||
const bodyStr = responseBodyToString(responseBody);
|
||||
const creditsExhausted = isCreditsExhaustedForStatus(statusCode, provider, bodyStr);
|
||||
// Claude's native weekly 429 wording is provider-scoped; omitting provider
|
||||
// silently classified the long-window quota as a short RPM rate limit. On 400 the
|
||||
// phrase needs a structured code (same contract as the credit signal above).
|
||||
const subscriptionQuotaExhausted = isSubscriptionQuotaForStatus(statusCode, provider, bodyStr);
|
||||
// silently classified the long-window quota as a short RPM rate limit.
|
||||
const subscriptionQuotaExhausted = isSubscriptionQuotaText(bodyStr.toLowerCase(), provider);
|
||||
const accountDeactivated = isAccountDeactivated(bodyStr);
|
||||
const oauthInvalid = isOAuthInvalidToken(bodyStr);
|
||||
const preserveQuota429 = shouldPreserveQuotaSignalsFor429(provider);
|
||||
|
||||
@@ -26,11 +26,6 @@ import { FORMATS } from "../translator/formats.ts";
|
||||
type JsonRecord = Record<string, unknown>;
|
||||
|
||||
const SAMPLING_PARAMS = ["temperature", "top_p"] as const;
|
||||
// Terra additionally rejects log-probability controls when reasoning is active.
|
||||
// With effort "none" all four fields remain eligible for passthrough.
|
||||
const TERRA_REASONING_SAMPLING_PARAMS = [
|
||||
...SAMPLING_PARAMS, "top_logprobs", "logprobs",
|
||||
] as const;
|
||||
// Suffix that encodes an active (non-none) reasoning effort, e.g. `gpt-5.4-high`.
|
||||
const ACTIVE_EFFORT_SUFFIX = /-(low|medium|high|xhigh|minimal)$/i;
|
||||
// Suffix that encodes the explicit non-reasoning mode, e.g. `gpt-5.4-none`.
|
||||
@@ -73,9 +68,7 @@ export function stripGpt5SamplingWhenReasoning<T extends Record<string, unknown>
|
||||
if (!hasActiveReasoning(record, model)) return body;
|
||||
|
||||
const stripped: string[] = [];
|
||||
const params = model.toLowerCase() === "gpt-6.1-terra"
|
||||
? TERRA_REASONING_SAMPLING_PARAMS : SAMPLING_PARAMS;
|
||||
for (const param of params) {
|
||||
for (const param of SAMPLING_PARAMS) {
|
||||
if (Object.hasOwn(record, param)) stripped.push(param);
|
||||
}
|
||||
if (stripped.length === 0) return body;
|
||||
|
||||
@@ -111,13 +111,6 @@ export const CODEX_NATIVE_UNPREFIXED_MODELS = new Set([
|
||||
"gpt-6.1-sol-high",
|
||||
"gpt-6.1-sol-medium",
|
||||
"gpt-6.1-sol-low",
|
||||
"gpt-6.1-terra",
|
||||
"gpt-6.1-terra-ultra",
|
||||
"gpt-6.1-terra-max",
|
||||
"gpt-6.1-terra-xhigh",
|
||||
"gpt-6.1-terra-high",
|
||||
"gpt-6.1-terra-medium",
|
||||
"gpt-6.1-terra-low",
|
||||
"gpt-5.6-sol",
|
||||
"gpt-5.6-sol-ultra",
|
||||
"gpt-5.6-sol-max",
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
import { RateLimitReason } from "../config/constants.ts";
|
||||
import { parseDayGranularityResetMs, parseIsoDateTimeResetMs } from "./quotaResetParsing.ts";
|
||||
import { quotaTextSignalCountsForStatus } from "./accountFallback/creditsExhaustedForStatus.ts";
|
||||
|
||||
type RateLimitReasonValue = (typeof RateLimitReason)[keyof typeof RateLimitReason];
|
||||
|
||||
@@ -65,26 +64,6 @@ export function isSubscriptionQuotaText(lower: string, provider?: string | null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Status-aware form of isSubscriptionQuotaText, under the same contract as the
|
||||
* credit signal (creditsExhaustedForStatus.ts): a 400 often quotes the caller's
|
||||
* own input back in its message, so on 400 the phrase counts only with a
|
||||
* structured credit/quota code or for a provider whose documented 400 form is
|
||||
* message-only. Every other status keeps the plain text match.
|
||||
*/
|
||||
export function isSubscriptionQuotaForStatus(
|
||||
status: number,
|
||||
provider: string | null | undefined,
|
||||
errorText: string,
|
||||
structured?: unknown
|
||||
): boolean {
|
||||
const text = String(errorText || "");
|
||||
return (
|
||||
isSubscriptionQuotaText(text.toLowerCase(), provider) &&
|
||||
quotaTextSignalCountsForStatus(status, provider, text, structured)
|
||||
);
|
||||
}
|
||||
|
||||
export const SUBSCRIPTION_QUOTA_COOLDOWN_MS = 60 * 60 * 1000; // 1 hour
|
||||
|
||||
/** Same value space as accountFallback.ts's RetryHintProvenance (kept local to avoid a circular import). */
|
||||
|
||||
@@ -172,10 +172,8 @@ export function applySyntxProviderRules(
|
||||
settings: JsonRecord,
|
||||
ctx: { modelType: string; fileCount?: number }
|
||||
): void {
|
||||
// aiName comes from the caller's model id: only the table's own entries may run, never a
|
||||
// member inherited from Object.prototype ("constructor", "__proto__", ...). CodeQL #1392.
|
||||
if (!Object.hasOwn(PROVIDER_RULES, aiName)) return;
|
||||
const handler = PROVIDER_RULES[aiName];
|
||||
if (!handler) return;
|
||||
handler(ctx.modelType || "", ctx.fileCount ?? 0, settings);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,6 @@
|
||||
*/
|
||||
|
||||
import { sanitizeErrorMessage } from "../../utils/error.ts";
|
||||
import {
|
||||
postDecisionJson,
|
||||
type DecisionPostFailure,
|
||||
type DecisionTransport,
|
||||
} from "../decision/transport.ts";
|
||||
|
||||
export const TYPESAFE_PROVIDER_ID = "typesafe";
|
||||
export const TYPESAFE_SYSTEM_ONE_BASE_URL = "https://api.typesafe.ai";
|
||||
@@ -67,7 +62,6 @@ export type EvaluateSystemOneChoiceOptions = {
|
||||
instructions?: string;
|
||||
model?: string;
|
||||
timeoutMs?: number;
|
||||
/** Test seam. Production leaves through the guarded decision transport (safeOutboundFetch). */
|
||||
fetchImpl?: FetchLike;
|
||||
baseUrl?: string;
|
||||
/** Aborted when the caller cancels; combined with the timeout. */
|
||||
@@ -220,57 +214,63 @@ export async function evaluateSystemOneChoice(
|
||||
? options.timeoutMs
|
||||
: TYPESAFE_SYSTEM_ONE_TIMEOUT_MS;
|
||||
const baseUrl = (options.baseUrl || TYPESAFE_SYSTEM_ONE_BASE_URL).replace(/\/+$/, "");
|
||||
const fetchImpl = options.fetchImpl ?? fetch;
|
||||
|
||||
if (options.signal?.aborted) {
|
||||
return unavailable("timeout", "System One call aborted before it started");
|
||||
}
|
||||
|
||||
// Hardened (#14239 pattern): redirects refused, body capped at 64 KB, no retries, the
|
||||
// provider outbound guard on the production path; a test `fetchImpl` gets the same init.
|
||||
const fetchImpl = options.fetchImpl;
|
||||
const transport: DecisionTransport | undefined = fetchImpl
|
||||
? (url, init) =>
|
||||
fetchImpl(url, {
|
||||
method: init.method,
|
||||
headers: init.headers,
|
||||
body: init.body,
|
||||
signal: init.signal,
|
||||
redirect: init.redirect,
|
||||
})
|
||||
: undefined;
|
||||
const controller = new AbortController();
|
||||
const onAbort = () => controller.abort();
|
||||
options.signal?.addEventListener("abort", onAbort, { once: true });
|
||||
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
||||
|
||||
const result = await postDecisionJson({
|
||||
url: `${baseUrl}${TYPESAFE_SYSTEM_ONE_PATH}`,
|
||||
headers: { Authorization: `Bearer ${apiKey}` },
|
||||
body: {
|
||||
model,
|
||||
state,
|
||||
questions: {
|
||||
route: {
|
||||
type: "choice",
|
||||
instructions,
|
||||
criteria,
|
||||
},
|
||||
try {
|
||||
const response = await fetchImpl(`${baseUrl}${TYPESAFE_SYSTEM_ONE_PATH}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
},
|
||||
timeoutMs,
|
||||
signal: options.signal,
|
||||
transport,
|
||||
});
|
||||
body: JSON.stringify({
|
||||
model,
|
||||
state,
|
||||
questions: {
|
||||
route: {
|
||||
type: "choice",
|
||||
instructions,
|
||||
criteria,
|
||||
},
|
||||
},
|
||||
}),
|
||||
signal: controller.signal,
|
||||
});
|
||||
|
||||
if (result.ok) return parseSystemOneChoiceResponse(result.data);
|
||||
// `strict: false` does not narrow the `ok` union, so name the failure variant.
|
||||
const failure = result as DecisionPostFailure;
|
||||
// Status only. Upstream bodies can echo the state or the key.
|
||||
if (failure.reason === "http_error") {
|
||||
const status = failure.status ?? null;
|
||||
return unavailable("http_error", `System One returned HTTP ${status}`, status);
|
||||
if (!response.ok) {
|
||||
// Status only. Upstream bodies can echo the state or the key.
|
||||
return unavailable(
|
||||
"http_error",
|
||||
`System One returned HTTP ${response.status}`,
|
||||
response.status
|
||||
);
|
||||
}
|
||||
|
||||
let json: unknown;
|
||||
try {
|
||||
json = await response.json();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "invalid JSON";
|
||||
return unavailable("invalid_response", `System One response was not JSON: ${message}`);
|
||||
}
|
||||
|
||||
return parseSystemOneChoiceResponse(json);
|
||||
} catch (err) {
|
||||
if (err instanceof Error && err.name === "AbortError") {
|
||||
return unavailable("timeout", `System One timed out after ${timeoutMs}ms`);
|
||||
}
|
||||
return unavailable("network_error", "System One request failed");
|
||||
} finally {
|
||||
clearTimeout(timer);
|
||||
options.signal?.removeEventListener("abort", onAbort);
|
||||
}
|
||||
if (failure.reason === "timeout") {
|
||||
return unavailable("timeout", `System One timed out after ${timeoutMs}ms`);
|
||||
}
|
||||
if (failure.reason === "invalid_response") {
|
||||
return unavailable("invalid_response", "System One response was not bounded JSON");
|
||||
}
|
||||
return unavailable("network_error", "System One request failed");
|
||||
}
|
||||
|
||||
@@ -435,19 +435,10 @@ export function enforceCacheControlBlockLimit(
|
||||
body: ClaudeRequestBody,
|
||||
limit = MAX_CACHE_CONTROL_BLOCKS
|
||||
): number {
|
||||
const marked = markedCacheControlBlocks(body);
|
||||
if (marked.length <= limit) return 0;
|
||||
const toRemove = marked.length - limit;
|
||||
for (let i = 0; i < toRemove; i++) delete marked[i].cache_control;
|
||||
return toRemove;
|
||||
}
|
||||
|
||||
/** Blocks that carry a cache_control marker, in request order (system, tools, messages). */
|
||||
function markedCacheControlBlocks(body: ClaudeRequestBody): Array<Record<string, unknown>> {
|
||||
const marked: Array<Record<string, unknown>> = [];
|
||||
const holders: Array<{ obj: Record<string, unknown> }> = [];
|
||||
const push = (block: unknown) => {
|
||||
if (block && typeof block === "object" && (block as Record<string, unknown>).cache_control) {
|
||||
marked.push(block as Record<string, unknown>);
|
||||
if (block && typeof block === "object" && "cache_control" in block) {
|
||||
holders.push({ obj: block as Record<string, unknown> });
|
||||
}
|
||||
};
|
||||
if (Array.isArray(body?.system)) body.system.forEach(push);
|
||||
@@ -457,21 +448,11 @@ function markedCacheControlBlocks(body: ClaudeRequestBody): Array<Record<string,
|
||||
if (Array.isArray(msg?.content)) msg.content.forEach(push);
|
||||
}
|
||||
}
|
||||
return marked;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tool loop ends with the results of the last assistant turn's tool calls, after that
|
||||
* turn's breakpoint, so they are billed as fresh input. When the 4-marker budget has room,
|
||||
* mark the final user turn so the next request reads them from cache.
|
||||
*/
|
||||
function markFinalToolResults(body: ClaudeRequestBody, ttl?: string): void {
|
||||
const last = body.messages?.[body.messages.length - 1];
|
||||
if (last?.role !== "user" || !Array.isArray(last.content)) return;
|
||||
if (!last.content.some((block) => block.type === "tool_result")) return;
|
||||
if (last.content.some((block) => block.cache_control)) return;
|
||||
if (markedCacheControlBlocks(body).length >= MAX_CACHE_CONTROL_BLOCKS) return;
|
||||
markMessageCacheControl(last, ttl);
|
||||
const marked = holders.filter((h) => h.obj.cache_control !== undefined);
|
||||
if (marked.length <= limit) return 0;
|
||||
const toRemove = marked.length - limit;
|
||||
for (let i = 0; i < toRemove; i++) delete marked[i].obj.cache_control;
|
||||
return toRemove;
|
||||
}
|
||||
|
||||
function markMessageCacheControl(msg: ClaudeMessage, ttl?: string): boolean {
|
||||
@@ -1068,9 +1049,6 @@ export function prepareClaudeRequest(
|
||||
// the upstream API, not caching policy, so preserveCacheControl does not
|
||||
// exempt them (they were the 400 sources on claude 5.x since 2026-09-29).
|
||||
hoistToolResultCacheControl(body);
|
||||
if (!preserveCacheControl && supportsPromptCaching) {
|
||||
markFinalToolResults(body, createClaudeTailCacheControl(provider).ttl);
|
||||
}
|
||||
if (supportsPromptCaching) {
|
||||
enforceCacheControlBlockLimit(body);
|
||||
}
|
||||
|
||||
@@ -384,8 +384,6 @@ export function translateRequest(
|
||||
/** UA-detected GitHub Copilot client. Forwarded to translators via the
|
||||
* transient `_copilotClient` credential flag (see openai-responses → openai). */
|
||||
copilotClient?: boolean;
|
||||
/** Per-conversation key for the Antigravity upstream sessionId (prompt-cache scope). */
|
||||
antigravitySessionKey?: string | null;
|
||||
}
|
||||
) {
|
||||
// Only Anthropic holds message-thread state. A `thread` delta (the message-threads beta) omits
|
||||
@@ -572,12 +570,10 @@ export function translateRequest(
|
||||
// thoughtSignature on tool-use history (#8979 / #2504 parity with the hub path).
|
||||
const hasNs = options?.signatureNamespace != null;
|
||||
const hasProvider = provider != null;
|
||||
const agySessionKey = options?.antigravitySessionKey || null;
|
||||
const directCredentials =
|
||||
hasNs || hasProvider || agySessionKey
|
||||
hasNs || hasProvider
|
||||
? {
|
||||
...(credentials && typeof credentials === "object" ? credentials : {}),
|
||||
...(agySessionKey ? { _antigravitySessionKey: agySessionKey } : {}),
|
||||
...(hasProvider ? { _provider: provider } : {}),
|
||||
...(hasNs
|
||||
? {
|
||||
@@ -688,17 +684,10 @@ export function translateRequest(
|
||||
const hasCopilot = options?.copilotClient === true;
|
||||
const hasProvider = provider != null;
|
||||
const videoSensitive = options?.videoTranscriptSensitive === true;
|
||||
const agySessionKey = options?.antigravitySessionKey || null;
|
||||
const translationCredentials =
|
||||
hasNs ||
|
||||
hasPreCompression ||
|
||||
hasCopilot ||
|
||||
hasProvider ||
|
||||
videoSensitive ||
|
||||
agySessionKey
|
||||
hasNs || hasPreCompression || hasCopilot || hasProvider || videoSensitive
|
||||
? {
|
||||
...(credentials && typeof credentials === "object" ? credentials : {}),
|
||||
...(agySessionKey ? { _antigravitySessionKey: agySessionKey } : {}),
|
||||
...(hasNs
|
||||
? {
|
||||
_signatureNamespace: scopeGeminiThoughtSignatureNamespace(
|
||||
|
||||
@@ -57,7 +57,7 @@ export function imageUrlToText(value: unknown): string {
|
||||
}
|
||||
|
||||
const CODEX_MAX_EFFORT_MODEL_PATTERN =
|
||||
/^(?:gpt-5\.6-(?:sol|terra|luna)|gpt-6(?:\.1)?-(?:astra|sol|terra|luna))(?:-(?:none|low|medium|high|xhigh|max|ultra))?$/;
|
||||
/^(?:gpt-5\.6-(?:sol|terra|luna)|gpt-6(?:\.1)?-(?:astra|sol|luna))(?:-(?:none|low|medium|high|xhigh|max|ultra))?$/;
|
||||
const KIRO_GPT_5_6_MODEL_PATTERN =
|
||||
/^(?:kiro|kr)\/gpt-5\.6-(?:sol|terra|luna)(?:-(?:none|low|medium|high|xhigh|max))?$/;
|
||||
const KIRO_OPUS_5_5_MODEL_PATTERN = /^(?:kiro|kr)\/claude-opus-5(?:\.|-)5(?:-thinking)?$/;
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import {
|
||||
generateAntigravityRequestId,
|
||||
getAntigravityEnvelopeUserAgent,
|
||||
getAntigravityConversationSessionId,
|
||||
getAntigravitySessionId,
|
||||
} from "../../services/antigravityIdentity.ts";
|
||||
import { fixToolPairs } from "../../services/contextManager.ts";
|
||||
import {
|
||||
@@ -910,10 +910,7 @@ function wrapInCloudCodeEnvelope(model, cloudCodeRequest, credentials = null) {
|
||||
project: projectId,
|
||||
requestId: generateAntigravityRequestId(),
|
||||
request: {
|
||||
sessionId: getAntigravityConversationSessionId(
|
||||
credentials,
|
||||
(credentials as { _antigravitySessionKey?: string } | null)?._antigravitySessionKey
|
||||
),
|
||||
sessionId: getAntigravitySessionId(credentials),
|
||||
contents: cloudCodeRequest.contents,
|
||||
systemInstruction: cloudCodeRequest.systemInstruction,
|
||||
generationConfig: applyAntigravityGenerationDefaults(cloudCodeRequest.generationConfig),
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* Upper bounds for the polling knobs a caller may send to async media jobs
|
||||
* (`poll_interval_ms`, `timeout_ms`, `poll_timeout_ms`).
|
||||
*
|
||||
* Those values feed `sleep()` and the polling deadline. Without a ceiling one request could hold
|
||||
* a handler for days while the server kept polling the upstream with the operator's credential
|
||||
* (CodeQL #1389, js/resource-exhaustion). Same pattern as `resolveCursorImageTimeoutMs` in
|
||||
* handlers/imageGeneration/providers/cursorAgentImage.ts: only the untrusted request value is
|
||||
* clamped; the fallback (a built-in or operator-configured default) is trusted and kept as is.
|
||||
*/
|
||||
|
||||
/** Longest single wait between two polls; matches MAX_POLL_RETRY_DELAY_MS in pollRetry.ts. */
|
||||
export const MAX_CALLER_POLL_INTERVAL_MS = 30_000;
|
||||
|
||||
/** Longest total polling window a caller may ask for (10 minutes). */
|
||||
export const MAX_CALLER_POLL_TIMEOUT_MS = 600_000;
|
||||
|
||||
/** A whole number of milliseconds ≥ 1 from the request, or null when absent or unusable. */
|
||||
function positiveWholeMs(value: unknown): number | null {
|
||||
const n = Number(value);
|
||||
if (!Number.isFinite(n)) return null;
|
||||
const ms = Math.floor(n);
|
||||
return ms >= 1 ? ms : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The caller's value clamped to `ceiling`, or `fallback` when the caller sent none. A fallback
|
||||
* above the ceiling stays reachable, so a ceiling never shortens a default.
|
||||
*/
|
||||
export function clampCallerMs(value: unknown, fallback: number, ceiling: number): number {
|
||||
const requested = positiveWholeMs(value);
|
||||
if (requested === null) return fallback;
|
||||
return Math.min(requested, Math.max(ceiling, fallback));
|
||||
}
|
||||
|
||||
export function clampPollIntervalMs(value: unknown, fallback: number): number {
|
||||
return clampCallerMs(value, fallback, MAX_CALLER_POLL_INTERVAL_MS);
|
||||
}
|
||||
|
||||
export function clampPollTimeoutMs(value: unknown, fallback: number): number {
|
||||
return clampCallerMs(value, fallback, MAX_CALLER_POLL_TIMEOUT_MS);
|
||||
}
|
||||
16
package-lock.json
generated
16
package-lock.json
generated
@@ -157,7 +157,7 @@
|
||||
"dpdm": "^4.3.0",
|
||||
"esbuild": "0.28.2",
|
||||
"eslint": "^10.10.0",
|
||||
"eslint-config-next": "16.4.6",
|
||||
"eslint-config-next": "16.4.5",
|
||||
"eslint-plugin-react-hooks": "7.1.1",
|
||||
"eslint-plugin-sonarjs": "^4.1.0",
|
||||
"espree": "^11.2.0",
|
||||
@@ -6332,9 +6332,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@next/eslint-plugin-next": {
|
||||
"version": "16.4.6",
|
||||
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.6.tgz",
|
||||
"integrity": "sha512-HdqERVOafOD8JaUSAkwf9aSu/1rsHlkN8C5GcXYBH3C/z1MxBhZFxB5rz/xqMMRiIj7r9tIv8OCLQ9JWUxCvWA==",
|
||||
"version": "16.4.5",
|
||||
"resolved": "https://registry.npmjs.org/@next/eslint-plugin-next/-/eslint-plugin-next-16.4.5.tgz",
|
||||
"integrity": "sha512-dNmc4y4En/34tWxaBFF2tG/R9GeiRwVPf7v8Az/Pqk8FcT4Uv0ePmrZKvWBL2nFy1QprPgJW+6XjfyV6jbRV3Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -19439,13 +19439,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/eslint-config-next": {
|
||||
"version": "16.4.6",
|
||||
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.6.tgz",
|
||||
"integrity": "sha512-IBGGrVf9E6pL0NGL0hmeicVGeSyv1VEzIWq6IecDqkw+YFByhEtDJS9u1r6s6a1VxK6rssh69KyNFQUgfaacqw==",
|
||||
"version": "16.4.5",
|
||||
"resolved": "https://registry.npmjs.org/eslint-config-next/-/eslint-config-next-16.4.5.tgz",
|
||||
"integrity": "sha512-mvh39zYLoNjpT5tVmf8xZu7i5lEOb5jN5cW6qD9OpeCp4GEEOeYta0Z2XyKiD0pYdlvm5/Td6Bi890maPRlIjg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@next/eslint-plugin-next": "16.4.6",
|
||||
"@next/eslint-plugin-next": "16.4.5",
|
||||
"eslint-import-resolver-node": "^0.3.6",
|
||||
"eslint-import-resolver-typescript": "^3.5.2",
|
||||
"eslint-plugin-import": "^2.32.0",
|
||||
|
||||
@@ -159,7 +159,7 @@
|
||||
"test:plan3": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/plan3-p0.test.ts",
|
||||
"test:fixes": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/fixes-p1.test.ts",
|
||||
"test:security": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./open-sse/utils/setupPolyfill.ts --import ./tests/_setup/isolateDataDir.ts --test tests/unit/security-fase01.test.ts",
|
||||
"test:property": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --import ./tests/_setup/isolateDataDir.ts --test --test-force-exit tests/unit/correctness/*.property.test.ts",
|
||||
"test:property": "cross-env DISABLE_SQLITE_AUTO_BACKUP=true node --import tsx/esm --test --test-force-exit tests/unit/correctness/*.property.test.ts",
|
||||
"check:boundary": "node scripts/quality/measure-boundary.mjs",
|
||||
"check:boundary:ratchet": "node scripts/quality/measure-boundary.mjs --ratchet",
|
||||
"check:cycles": "node scripts/check/check-cycles.mjs",
|
||||
@@ -490,7 +490,7 @@
|
||||
"dpdm": "^4.3.0",
|
||||
"esbuild": "0.28.2",
|
||||
"eslint": "^10.10.0",
|
||||
"eslint-config-next": "16.4.6",
|
||||
"eslint-config-next": "16.4.5",
|
||||
"eslint-plugin-react-hooks": "7.1.1",
|
||||
"eslint-plugin-sonarjs": "^4.1.0",
|
||||
"espree": "^11.2.0",
|
||||
|
||||
@@ -17,9 +17,7 @@
|
||||
// `success` on pull_request.head.sha, context APPROVAL_CONTEXTS[kind],
|
||||
// description "approved by <login>" (App token, so the creator is `<appSlug>[bot]`);
|
||||
// labeled by a non-approver → comment once (key "not-approver"), no status
|
||||
// (in shadow mode no comment either: shadow writes nothing on a pull request). Always the
|
||||
// App's, whatever config.voice says: this job never receives the owner's token (the tick's
|
||||
// own "not-approver" comment then finds this one by its marker and posts nothing);
|
||||
// (in shadow mode no comment either: shadow writes nothing on a pull request);
|
||||
// unlabeled → status `failure` "approval withdrawn by <login>" on the same head/context;
|
||||
// in shadow mode (config.mode) nothing at all is written for a removal.
|
||||
//
|
||||
|
||||
@@ -8,16 +8,8 @@
|
||||
//
|
||||
// Nothing here force-pushes. Candidate refs are unique per SHA (contracts.candidateRef), so a
|
||||
// push either creates a new ref or finds it already at the same SHA.
|
||||
//
|
||||
// SIGNED MERGE COMMITS (config landing.signing "ssh"): composeCandidate signs each merge commit
|
||||
// with `commit-tree -S`, the SSH key file the workflow writes under RUNNER_TEMP
|
||||
// (signingKeyPath) given to git as configuration of that one command (gpg.format=ssh,
|
||||
// user.signingkey=<path>) through the environment, so neither the key nor its path is ever an
|
||||
// argument, a log line, an event or an error message. A missing key or a signature git cannot
|
||||
// make never blocks the queue: the commit is composed unsigned, exactly as without signing, and
|
||||
// the result says so (`signing`), for the tick to report once per batch.
|
||||
|
||||
import { existsSync, mkdirSync, readdirSync, statSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, readdirSync } from "node:fs";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import {
|
||||
@@ -51,55 +43,6 @@ import {
|
||||
* test or land; the tick drops it from the queue
|
||||
*/
|
||||
|
||||
/**
|
||||
* Where the tick job's "Write the merge-commit signing key" step leaves the key, under
|
||||
* RUNNER_TEMP (.github/workflows/omni-queue.yml; tests/unit/merge-queue/workflows.test.mjs pins
|
||||
* both). The step removes the directory at the end of the job, failed or cancelled included.
|
||||
*/
|
||||
export const SIGNING_KEY_DIR = "omni-queue-signing";
|
||||
export const SIGNING_KEY_FILE = "signing-key";
|
||||
|
||||
/** The signing key file of a job whose RUNNER_TEMP is `runnerTemp`; null without one. */
|
||||
export function signingKeyPath(runnerTemp) {
|
||||
if (typeof runnerTemp !== "string" || !runnerTemp) return null;
|
||||
return join(runnerTemp, SIGNING_KEY_DIR, SIGNING_KEY_FILE);
|
||||
}
|
||||
|
||||
/** Why a batch was composed unsigned although signing is asked for: no key in the job. */
|
||||
export const SIGNING_KEY_MISSING_CAUSE =
|
||||
"no signing key file in the job (is the OMNI_QUEUE_SIGNING_KEY secret set?)";
|
||||
|
||||
/**
|
||||
* The signer of one composition: `config` (git configuration of the commit-tree call) while
|
||||
* signing works, `cause` once it does not. Never holds anything but the path.
|
||||
* @param {{keyPath: string|null}} signing
|
||||
*/
|
||||
function createSigner(signing) {
|
||||
const keyPath = typeof signing?.keyPath === "string" ? signing.keyPath : null;
|
||||
let file = false;
|
||||
try {
|
||||
file = keyPath !== null && statSync(keyPath).isFile();
|
||||
} catch {
|
||||
file = false;
|
||||
}
|
||||
const report = { signed: 0, unsigned: 0, cause: file ? null : SIGNING_KEY_MISSING_CAUSE };
|
||||
return {
|
||||
report,
|
||||
/** The configuration that signs, or null once signing is known not to work. */
|
||||
config: () =>
|
||||
report.cause === null
|
||||
? [
|
||||
["gpg.format", "ssh"],
|
||||
["user.signingkey", keyPath],
|
||||
]
|
||||
: null,
|
||||
fail(code) {
|
||||
// The exit code only: git's message would carry the key path.
|
||||
report.cause = `git could not sign a merge commit (exit ${code})`;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Local refs of the scratch repository (never pushed anywhere). */
|
||||
export const LOCAL_BASE_REF = "refs/omni-queue/base";
|
||||
export const localPrRef = (n) => `refs/omni-queue/pr/${n}`;
|
||||
@@ -339,19 +282,11 @@ export function haveCommonAncestor(git, a, b) {
|
||||
* The merge commits take their author/committer identity from the Git runner (createGit
|
||||
* `identity`, the App bot). Their message is built only from validated fields.
|
||||
*
|
||||
* `signing` (config landing.signing "ssh"; absent = no signing, and no `signing` field in the
|
||||
* result): each merge commit is signed with the SSH key at `signing.keyPath`. A key that is not
|
||||
* there, or a signature git cannot make, leaves that commit and the rest of the batch unsigned,
|
||||
* byte for byte what the composition is without signing; the result's `signing` says how many
|
||||
* commits were signed and why the others were not ({signed, unsigned, cause}; cause null when
|
||||
* every one was signed). A signature changes nothing else: same tree, parents, identity, message.
|
||||
*
|
||||
* @param {{git: Git, base: string, baseSha: string, prs: PrRef[], batchId: string,
|
||||
* heads: Object<number, string|null>, signing?: {keyPath: string|null}|null}} input
|
||||
* heads = fetchInputs().heads
|
||||
* @returns {ComposeResult & {signing?: {signed: number, unsigned: number, cause: string|null}}}
|
||||
* heads: Object<number, string|null>}} input heads = fetchInputs().heads
|
||||
* @returns {ComposeResult}
|
||||
*/
|
||||
export function composeCandidate({ git, base, baseSha, prs, batchId, heads, signing = null }) {
|
||||
export function composeCandidate({ git, base, baseSha, prs, batchId, heads }) {
|
||||
if (!isSha(baseSha)) throw new Error("composeCandidate: invalid baseSha");
|
||||
const g = scratchGit(git);
|
||||
/** @type {ComposeResult} */
|
||||
@@ -366,23 +301,6 @@ export function composeCandidate({ git, base, baseSha, prs, batchId, heads, sign
|
||||
alreadyContained: [],
|
||||
alreadyInBase: [],
|
||||
};
|
||||
const signer = signing ? createSigner(signing) : null;
|
||||
/** commit-tree of one merge commit: signed while the signer works, else as without signing. */
|
||||
const commitMerge = (tree, ours, theirs, message) => {
|
||||
const config = signer?.config();
|
||||
if (config) {
|
||||
const args = ["commit-tree", tree, "-p", ours, "-p", theirs, "-S", "-F", "-"];
|
||||
const res = g.run(args, { input: message, config, allowFail: true });
|
||||
const sha = res.stdout.trim();
|
||||
if (res.code === 0 && isSha(sha)) {
|
||||
signer.report.signed += 1;
|
||||
return sha;
|
||||
}
|
||||
signer.fail(res.code);
|
||||
}
|
||||
if (signer) signer.report.unsigned += 1;
|
||||
return g.out(["commit-tree", tree, "-p", ours, "-p", theirs, "-F", "-"], { input: message });
|
||||
};
|
||||
let current = baseSha;
|
||||
for (const pr of prs ?? []) {
|
||||
const fetched = heads?.[pr.n] ?? null;
|
||||
@@ -411,7 +329,9 @@ export function composeCandidate({ git, base, baseSha, prs, batchId, heads, sign
|
||||
continue;
|
||||
}
|
||||
const message = buildMergeMessage({ pr, base, baseSha, batchId });
|
||||
current = commitMerge(merged.tree, current, pr.head, message);
|
||||
current = g.out(["commit-tree", merged.tree, "-p", current, "-p", pr.head, "-F", "-"], {
|
||||
input: message,
|
||||
});
|
||||
if (!isSha(current)) throw new Error("git commit-tree returned no commit id");
|
||||
result.included.push(pr);
|
||||
}
|
||||
@@ -422,7 +342,6 @@ export function composeCandidate({ git, base, baseSha, prs, batchId, heads, sign
|
||||
result.candidateSha = current;
|
||||
result.treeSha = g.out(["rev-parse", `${current}^{tree}`]);
|
||||
}
|
||||
if (signer) result.signing = { ...signer.report };
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,6 @@ export const DEFAULT_CONFIG_PATH = join(ROOT, "config", "merge-queue", "config.j
|
||||
export const LANDING_MODES = Object.freeze(["merge-ff", "squash-api"]);
|
||||
export const LANDING_ACTORS = Object.freeze(["app", "owner"]);
|
||||
export const QUEUE_MODES = Object.freeze(["shadow", "live"]);
|
||||
/**
|
||||
* Who performs the queue's human-visible writes (comments and label removals on pull requests,
|
||||
* the dashboard issue and its comments, comments on the base-red issue, the tree-divergence
|
||||
* issue): the App's token, or the owner's (OMNI_QUEUE_LAND_TOKEN), see voice.mjs.
|
||||
*/
|
||||
export const VOICES = Object.freeze(["app", "owner"]);
|
||||
/** `landing.signing`: "ssh" signs every merge commit the queue composes (compose.mjs). */
|
||||
export const SIGNING_MODES = Object.freeze(["none", "ssh"]);
|
||||
|
||||
const CONFIG_KEYS = [
|
||||
"schemaVersion",
|
||||
@@ -46,8 +38,7 @@ const CONFIG_KEYS = [
|
||||
];
|
||||
|
||||
/** Keys that may be left out: each one has a default (applied by validateConfig). */
|
||||
const OPTIONAL_CONFIG_KEYS = ["flakyReruns", "prChecksRequired", "lanes", "voice"];
|
||||
const DEFAULT_VOICE = "app";
|
||||
const OPTIONAL_CONFIG_KEYS = ["flakyReruns", "prChecksRequired", "lanes"];
|
||||
/** Keys of `lanes` (both required when `lanes` is present). */
|
||||
const LANE_KEYS = ["hotfixLabel", "baseRepairLabel"];
|
||||
/** Re-runs of a red candidate's failed jobs before it is classified (tick onRed): once. */
|
||||
@@ -69,9 +60,8 @@ const STATUS_CONTEXT_RE = /^[A-Za-z0-9._/-]{1,100}$/;
|
||||
*/
|
||||
const LAND_STATUS_PREFIX = "omni-queue/";
|
||||
const NOREPLY_EMAIL_RE = /^[^\s@]+@users\.noreply\.github\.com$/;
|
||||
const LANDING_KEYS = ["mode", "actor", "identity", "statusContext", "signing"];
|
||||
const LANDING_KEYS = ["mode", "actor", "identity", "statusContext"];
|
||||
const DEFAULT_LANDING_ACTOR = "app";
|
||||
const DEFAULT_SIGNING = "none";
|
||||
const DEFAULT_LAND_STATUS_CONTEXT = "omni-queue/land";
|
||||
|
||||
function stringList(value, path, errors, { min = 0, item = nonEmptyString } = {}) {
|
||||
@@ -90,10 +80,8 @@ function positiveInt(value, path, errors, { min = 1, max = Number.MAX_SAFE_INTEG
|
||||
|
||||
/**
|
||||
* Validate the `landing` block, push every problem onto `errors` and return the block with its
|
||||
* defaults applied (`actor: "app"`, `statusContext: "omni-queue/land"`, `signing: "none"`), or
|
||||
* null when `raw` is not an object. The returned block is only used when `errors` stays empty.
|
||||
* `signing: "ssh"` needs `actor: "owner"`: the signed commits carry `landing.identity`, and only
|
||||
* that account can hold the key GitHub verifies them with (an App's bot user has no signing keys).
|
||||
* defaults applied (`actor: "app"`, `statusContext: "omni-queue/land"`), or null when `raw` is not
|
||||
* an object. The returned block is only used when `errors` stays empty.
|
||||
*/
|
||||
function validateLanding(raw, errors) {
|
||||
if (!isRecord(raw)) {
|
||||
@@ -138,15 +126,7 @@ function validateLanding(raw, errors) {
|
||||
// An approval context as the land status would make a label approval a blessing.
|
||||
else if (Object.values(APPROVAL_CONTEXTS).includes(statusContext))
|
||||
errors.push("landing.statusContext: must not equal an approval context");
|
||||
const signing = Object.hasOwn(raw, "signing") ? raw.signing : DEFAULT_SIGNING;
|
||||
if (!SIGNING_MODES.includes(signing))
|
||||
errors.push(`landing.signing: expected one of ${SIGNING_MODES.join(", ")}`);
|
||||
else if (signing === "ssh" && actor !== "owner")
|
||||
errors.push(
|
||||
'landing.signing: "ssh" needs landing.actor "owner" (the signed merge commits carry ' +
|
||||
"landing.identity, whose account holds the signing key)"
|
||||
);
|
||||
return { ...raw, actor, statusContext, signing };
|
||||
return { ...raw, actor, statusContext };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,11 +183,9 @@ function validateLanes(raw, errors) {
|
||||
* startSize (optional, default maxSize), halves after
|
||||
* a red root batch and grows by one after a full one
|
||||
* lands; without it every batch is up to maxSize
|
||||
* @property {{mode: "merge-ff"|"squash-api", actor: "app"|"owner", identity?: {name: string, email: string}, statusContext: string, signing: "none"|"ssh"}} landing
|
||||
* @property {{mode: "merge-ff"|"squash-api", actor: "app"|"owner", identity?: {name: string, email: string}, statusContext: string}} landing
|
||||
* actor "owner" lands with `identity` (a noreply address);
|
||||
* statusContext is the commit status the queue publishes;
|
||||
* signing (optional, default "none"): "ssh" signs every
|
||||
* merge commit the queue composes (owner actor only)
|
||||
* statusContext is the commit status the queue publishes
|
||||
* @property {string[]} requiredChecks check names that must be `success` on the candidate
|
||||
* @property {string[]} advisoryChecks check names whose failure is tolerated
|
||||
* @property {string[]} aggregateChecks always() gate checks that fail whenever a job they
|
||||
@@ -227,8 +205,6 @@ function validateLanes(raw, errors) {
|
||||
* FIFO; a base-repair PR alone too, and it is the
|
||||
* only thing a base-red pause processes
|
||||
* @property {"shadow"|"live"} mode
|
||||
* @property {"app"|"owner"} voice optional, default "app": whose token posts the queue's
|
||||
* comments, removes its labels and writes its issues
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -344,8 +320,6 @@ export function validateConfig(raw) {
|
||||
const lanes = validateLanes(raw, errors);
|
||||
if (!QUEUE_MODES.includes(raw.mode))
|
||||
errors.push(`mode: expected one of ${QUEUE_MODES.join(", ")}`);
|
||||
const voice = Object.hasOwn(raw, "voice") ? raw.voice : DEFAULT_VOICE;
|
||||
if (!VOICES.includes(voice)) errors.push(`voice: expected one of ${VOICES.join(", ")}`);
|
||||
return errors.length
|
||||
? { ok: false, config: null, errors }
|
||||
: {
|
||||
@@ -357,7 +331,6 @@ export function validateConfig(raw) {
|
||||
flakyReruns,
|
||||
prChecksRequired,
|
||||
lanes,
|
||||
voice,
|
||||
}),
|
||||
errors: [],
|
||||
};
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
// - Credentials travel in the environment (GIT_CONFIG_COUNT/KEY/VALUE → http extraheader), never
|
||||
// in argv or in the remote URL, and every error message is redacted before it is thrown. The
|
||||
// tick's OMNI_QUEUE_TOKEN / OMNI_QUEUE_LAND_TOKEN are removed from every git child's environment.
|
||||
// - Configuration a single command needs (the signing key of a merge commit: compose.mjs) also
|
||||
// travels as GIT_CONFIG_* entries of that command's environment (run option `config`), never as
|
||||
// `-c` arguments: argv is logged, the environment is not.
|
||||
// - Synchronous: one tick is a short, sequential script.
|
||||
|
||||
import { spawnSync } from "node:child_process";
|
||||
@@ -50,25 +47,6 @@ function withoutTokens(env) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* `env` plus `entries` ([key, value] pairs) appended to its GIT_CONFIG_COUNT/KEY_n/VALUE_n list
|
||||
* (the token's http header, when there is one, keeps index 0). Git reads these as command-line
|
||||
* configuration of that one process.
|
||||
* @param {object} env
|
||||
* @param {[string, string][]} entries
|
||||
*/
|
||||
export function withConfigEntries(env, entries) {
|
||||
if (!entries?.length) return env;
|
||||
const count = Number.parseInt(env.GIT_CONFIG_COUNT ?? "", 10);
|
||||
const start = Number.isSafeInteger(count) && count > 0 ? count : 0;
|
||||
const out = { ...env, GIT_CONFIG_COUNT: String(start + entries.length) };
|
||||
entries.forEach(([key, value], i) => {
|
||||
out[`GIT_CONFIG_KEY_${start + i}`] = key;
|
||||
out[`GIT_CONFIG_VALUE_${start + i}`] = value;
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {object} GitResult
|
||||
* @property {number|null} code
|
||||
@@ -79,11 +57,8 @@ export function withConfigEntries(env, entries) {
|
||||
/**
|
||||
* @typedef {object} Git
|
||||
* @property {string} cwd
|
||||
* @property {(args: string[], opts?: {allowFail?: boolean, input?: string, env?: object,
|
||||
* config?: [string, string][]}) => GitResult} run config: git configuration of this
|
||||
* one command, passed through the environment (withConfigEntries), never logged
|
||||
* @property {(args: string[], opts?: {input?: string, env?: object,
|
||||
* config?: [string, string][]}) => string} out stdout trimmed; throws GitError
|
||||
* @property {(args: string[], opts?: {allowFail?: boolean, input?: string, env?: object}) => GitResult} run
|
||||
* @property {(args: string[], opts?: {input?: string, env?: object}) => string} out stdout trimmed; throws GitError
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -113,13 +88,12 @@ export function createGit({ cwd, token, env = {}, identity, log = () => {} }) {
|
||||
...env,
|
||||
});
|
||||
|
||||
function run(args, { allowFail = false, input, env: extra, config } = {}) {
|
||||
function run(args, { allowFail = false, input, env: extra } = {}) {
|
||||
const shown = args.map(redact);
|
||||
log(`git ${shown.join(" ")}`);
|
||||
const env = extra ? withoutTokens({ ...baseEnv, ...extra }) : baseEnv;
|
||||
const res = spawnSync("git", args, {
|
||||
cwd,
|
||||
env: withConfigEntries(env, config),
|
||||
env: extra ? withoutTokens({ ...baseEnv, ...extra }) : baseEnv,
|
||||
input,
|
||||
encoding: "utf8",
|
||||
maxBuffer: 256 * 1024 * 1024,
|
||||
|
||||
@@ -81,24 +81,18 @@ export class GitHubError extends Error {
|
||||
* @property {(n: number) => Promise<{id: number, body: string, author: string,
|
||||
* createdAt: string}[]>} listIssueComments
|
||||
* @property {(n: number, body: string) => Promise<{id: number}>} createIssueComment
|
||||
* @property {(n: number, key: string, body: string, opts?: {reader?: GitHubClient|null,
|
||||
* alsoLogins?: string[]}) => Promise<{posted: boolean}>} commentOnce
|
||||
* @property {(n: number, key: string, body: string) => Promise<{posted: boolean}>} commentOnce
|
||||
* posts `body + "\n\n" + contracts.commentMarker(key)` unless a comment on issue/PR n
|
||||
* already contains that marker (then {posted:false}). The ONLY way queue code comments.
|
||||
* After posting it re-reads the comments: when two writers raced (approval job + tick,
|
||||
* or a POST replayed after a 5xx), the lowest comment id wins and the newer duplicate
|
||||
* this call created is deleted ({posted:false}). opts (owner voice, voice.mjs):
|
||||
* `reader` = the client that lists the comments (the App's: every read stays the
|
||||
* App's), the POST and DELETE stay this client's; `alsoLogins` = more logins whose
|
||||
* markers count next to botLogin (the owner's login, read from the owner's token)
|
||||
* this call created is deleted ({posted:false}).
|
||||
* @property {(commentId: number) => Promise<void>} deleteIssueComment 404 = already gone
|
||||
* @property {(opts: {labels?: string[], state?: "open"|"closed"|"all"}) => Promise<{number: number,
|
||||
* title: string, body: string, labels: string[], state: string,
|
||||
* updatedAt: string}[]>} listIssues issues only (PRs filtered out)
|
||||
* @property {(input: {title: string, body: string, labels?: string[]}) => Promise<{number: number}>} createIssue
|
||||
* @property {(n: number, patch: {title?: string, body?: string, state?: string}) => Promise<void>} updateIssue
|
||||
* @property {() => Promise<string>} getAuthenticatedLogin GET /user: the login of the token's
|
||||
* own account ("" when the answer names none); voice.mjs reads the owner's with it
|
||||
*
|
||||
* — commits / checks / statuses —
|
||||
* @property {(branch: string) => Promise<string|null>} getBranchSha null when absent
|
||||
@@ -445,9 +439,7 @@ function errorMessage(data, fallback) {
|
||||
* baseDelayMs/maxDelayMs/nowMs tune the backoff (tests); maxDelayMs (default 120 s) is also
|
||||
* the longest Retry-After / rate-limit reset wait honored: a longer one throws at once;
|
||||
* botLogin, when set, makes commentOnce
|
||||
* count only markers in comments authored by that login, or by a login its caller adds
|
||||
* (`alsoLogins`: the owner's, read from the owner's own token): a third party cannot pre-post
|
||||
* one;
|
||||
* count only markers in comments authored by that login (a third party cannot pre-post one);
|
||||
* requestTimeoutMs (default 30 s) aborts a hung request, which then counts as a network error.
|
||||
* @returns {GitHubClient}
|
||||
*/
|
||||
@@ -690,25 +682,19 @@ export function createGitHubClient(options) {
|
||||
|
||||
deleteIssueComment,
|
||||
|
||||
async commentOnce(n, key, body, { reader = null, alsoLogins = [] } = {}) {
|
||||
async commentOnce(n, key, body) {
|
||||
const marker = commentMarker(key);
|
||||
// Logins whose markers are the queue's own: the App's, and the owner's under the owner
|
||||
// voice. Exact logins only, as GitHub returns them; nobody else's marker ever counts.
|
||||
const trusted = botLogin ? new Set([botLogin, ...alsoLogins.filter(Boolean)]) : null;
|
||||
const ours = (c) => c.body.includes(marker) && (!trusted || trusted.has(c.author));
|
||||
// Under the owner voice the App's client reads, this (the owner's) client writes.
|
||||
const list = reader ? (m) => reader.listIssueComments(m) : listIssueComments;
|
||||
if ((await list(n)).some(ours)) return { posted: false };
|
||||
const ours = (c) => c.body.includes(marker) && (!botLogin || c.author === botLogin);
|
||||
if ((await listIssueComments(n)).some(ours)) return { posted: false };
|
||||
const { id } = await createIssueComment(n, `${body}\n\n${marker}`);
|
||||
// Read-then-write is not atomic: another writer may have posted the same marker meanwhile,
|
||||
// and each POST replayed after a 5xx may have left one more copy. The lowest id wins; drop
|
||||
// every newer copy written by a trusted login (never a comment of someone else).
|
||||
const found = (await list(n)).filter(ours).sort((a, b) => a.id - b.id);
|
||||
// every newer copy written by our login (never a comment of someone else).
|
||||
const found = (await listIssueComments(n)).filter(ours).sort((a, b) => a.id - b.id);
|
||||
const winner = found[0]?.id;
|
||||
if (winner === undefined || id === undefined) return { posted: true };
|
||||
const self = found.find((c) => c.id === id)?.author;
|
||||
const mine = (c) => (trusted ? trusted.has(c.author) : c.author === self);
|
||||
const extra = found.filter((c) => c.id !== winner && (c.id === id || mine(c)));
|
||||
const self = botLogin ?? found.find((c) => c.id === id)?.author;
|
||||
const extra = found.filter((c) => c.id !== winner && (c.id === id || c.author === self));
|
||||
for (const c of extra) await deleteIssueComment(c.id);
|
||||
if (extra.length) {
|
||||
const ids = extra.map((c) => c.id).join(", ");
|
||||
@@ -736,11 +722,6 @@ export function createGitHubClient(options) {
|
||||
await request("PATCH", r(`/issues/${n}`), { body: patch });
|
||||
},
|
||||
|
||||
async getAuthenticatedLogin() {
|
||||
const { data } = await request("GET", "/user");
|
||||
return typeof data?.login === "string" ? data.login : "";
|
||||
},
|
||||
|
||||
async getBranchSha(branch) {
|
||||
const res = await request("GET", r(`/git/ref/heads/${encodePath(branch)}`), {
|
||||
allowStatuses: [404],
|
||||
|
||||
@@ -169,10 +169,6 @@ export function mergedPrsBetween(git, expectedBaseSha, candidateSha) {
|
||||
* key, in any paragraph, is refused rather than resolved). The chain is read with each commit's
|
||||
* whole message, as the CI reads it; output that cannot be split into whole commits is a
|
||||
* mismatch. The subject, the author trailer and the commit identity are not checked.
|
||||
* Nor is a signature (config landing.signing "ssh"): every read here is of the tree, the parents
|
||||
* and the message (%B, which never holds the gpgsig header), so a signed candidate verifies
|
||||
* exactly as the unsigned composition of the same inputs, and a signature never makes a commit
|
||||
* with another tree, parents or trailers pass.
|
||||
*
|
||||
* @param {{git: Git, expectedBaseSha: string, candidateSha: string, prs: PrRef[],
|
||||
* treeSha?: string|null, trees?: boolean}} input the commits must be in the scratch
|
||||
|
||||
@@ -14,13 +14,10 @@
|
||||
// pull-requests: write is used by a squash-api landing (mergePull) only:
|
||||
// labels and comments on a PR go through the issues endpoints
|
||||
// GITHUB_REPOSITORY owner/repo
|
||||
// OMNI_QUEUE_LAND_TOKEN the repository owner's token, used by the landing itself (the
|
||||
// merge-ff push or the squash-api merges) when landing.actor is "owner",
|
||||
// and, when config.voice is "owner", by the queue's human-visible writes
|
||||
// (voice.mjs: comments, label removals, the dashboard and other issues;
|
||||
// its GET /user names the owner's login). Everything else, the land
|
||||
// status included, uses OMNI_QUEUE_TOKEN. Optional: without it shadow
|
||||
// mode runs, a live landing pauses and the voice falls back to the App.
|
||||
// OMNI_QUEUE_LAND_TOKEN the repository owner's token, used ONLY by the landing itself (the
|
||||
// merge-ff push or the squash-api merges) when landing.actor is "owner";
|
||||
// everything else, the land status included, uses OMNI_QUEUE_TOKEN.
|
||||
// Optional: without it shadow mode runs and a live landing pauses.
|
||||
// OMNI_QUEUE_GIT_NAME, OMNI_QUEUE_GIT_EMAIL TESTS/SANDBOX ONLY: identity for queue merge
|
||||
// commits, over everything else. Without it: landing.identity when
|
||||
// landing.actor is "owner", else OMNI_QUEUE_BOT_NAME +
|
||||
@@ -30,11 +27,7 @@
|
||||
// it (the re-runner of a re-run, whose inputs stay the dispatcher's): a
|
||||
// bless is honoured only when BOTH are logins of config.approvers
|
||||
// OMNI_QUEUE_CONFIG optional path to an alternative config file (sandbox)
|
||||
// RUNNER_TEMP scratch directory for the bare compose repository; with
|
||||
// config.landing.signing "ssh", the merge-commit signing key is read
|
||||
// from compose.signingKeyPath(RUNNER_TEMP), written there by the
|
||||
// workflow from the OMNI_QUEUE_SIGNING_KEY secret (never this process's
|
||||
// environment); no file = the batch is composed unsigned, one `error` event
|
||||
// RUNNER_TEMP scratch directory for the bare compose repository
|
||||
// GITHUB_SERVER_URL, GITHUB_RUN_ID for run links in history/dashboard
|
||||
// GITHUB_API_URL REST API root (default https://api.github.com; GHES / tests)
|
||||
// OMNI_QUEUE_REMOTE_URL TESTS/SANDBOX ONLY: git remote of the repository instead of
|
||||
@@ -149,11 +142,6 @@
|
||||
// mode would have done is recorded instead: `culprit-found` (with a shadow note) and
|
||||
// `would-dequeue` events, and the head is remembered in state.shadow.processed so it is not
|
||||
// batched again. Issues the queue owns (dashboard, base-red notice) are still written.
|
||||
//
|
||||
// OWNER VOICE (config.voice "owner", voice.mjs): those two, every issue comment (comment) and the
|
||||
// dashboard and divergence issues go out with the owner's token, each retried with the App's on a
|
||||
// missing token or a 401/403, recorded once per tick (voiceFallback). Statuses, refs, the state
|
||||
// branch, re-runs and every read stay the App's.
|
||||
|
||||
import { mkdirSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
@@ -202,13 +190,6 @@ import { createGitHubClient } from "./github.mjs";
|
||||
import * as landModule from "./land.mjs";
|
||||
import { readQueueRefsProtection } from "./refs-guard.mjs";
|
||||
import { StateConflictError, createStateStore, updateStateWithRetry } from "./state.mjs";
|
||||
import {
|
||||
VOICE_FALLBACK_PREFIX,
|
||||
createOwnerLoginReader,
|
||||
createOwnerVoice,
|
||||
voiceFallbackDetail,
|
||||
voiceFallbackNote,
|
||||
} from "./voice.mjs";
|
||||
import { WATCHDOG_LIMIT_MINUTES } from "./watchdog.mjs";
|
||||
|
||||
export { StateConflictError };
|
||||
@@ -242,13 +223,6 @@ export class UnmanagedBaseError extends Error {}
|
||||
* OMNI_QUEUE_LAND_TOKEN, or null when that token is not set
|
||||
* @property {object|null} landGh client of the squash-api landing: gh itself when
|
||||
* landing.actor is "app"; with "owner", one with OMNI_QUEUE_LAND_TOKEN, or null without it
|
||||
* @property {object|null} [voiceGh] config.voice "owner": the client with
|
||||
* OMNI_QUEUE_LAND_TOKEN that performs the human-visible writes (voice.mjs); null otherwise or
|
||||
* without the token (the App writes, the fallback is recorded)
|
||||
* @property {(() => Promise<string>)|null} [ownerLogin] the owner's login read from that token
|
||||
* (voice.createOwnerLoginReader); null without voiceGh
|
||||
* @property {{keyPath: string|null}|null} [signing] config.landing.signing "ssh": the signing
|
||||
* key file of every merge commit (compose.composeCandidate `signing`); null = no signing
|
||||
* @property {string} repoDir scratch dir for the bare compose repository
|
||||
* @property {string} remoteUrl https://github.com/<owner>/<repo>.git
|
||||
* @property {string|null} [fetchFilter] partial-clone filter for the scratch repository
|
||||
@@ -606,25 +580,6 @@ class Tick {
|
||||
? readOnlyGitHub(landGh, this.violations)
|
||||
: landGh;
|
||||
this.landGit = null;
|
||||
/**
|
||||
* The client of the human-visible writes: the App's own (config.voice "app"), or the owner
|
||||
* voice (voice.mjs), whose fallbacks to the App's token are recorded by voiceFallback.
|
||||
*/
|
||||
this.voice =
|
||||
this.config.voice === "owner"
|
||||
? createOwnerVoice({
|
||||
app: this.gh,
|
||||
owner: deps.voiceGh
|
||||
? this.dryRun
|
||||
? readOnlyGitHub(deps.voiceGh, this.violations)
|
||||
: deps.voiceGh
|
||||
: null,
|
||||
ownerLogin: deps.ownerLogin ?? null,
|
||||
onFallback: (cause, what) => this.voiceFallback(cause, what),
|
||||
})
|
||||
: this.gh;
|
||||
/** True once this tick recorded a fallback of the owner voice (voiceFallback). */
|
||||
this.voiceFellBack = false;
|
||||
this.m = { ...DEFAULT_MODULES, ...(deps.modules ?? {}) };
|
||||
this.decisions = [];
|
||||
/** PRs whose queue label this tick removed (GitHub may still list them for a while). */
|
||||
@@ -783,30 +738,10 @@ class Tick {
|
||||
return this.s.history.some(predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Comment on an issue the queue owns (base-red notice, divergence, dashboard): written in every
|
||||
* mode, with the configured voice (this.voice).
|
||||
*/
|
||||
/** Comment on an issue the queue owns (base-red notice, divergence): written in every mode. */
|
||||
async comment(n, key, body) {
|
||||
if (this.dryRun) return this.note(`would comment on #${n} (${key})`);
|
||||
await this.voice.commentOnce(n, key, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* The owner voice wrote `what` with the App's token for `cause` (voice.mjs: no owner token, or
|
||||
* GitHub refused it). Every fallback is a note; the first of the tick is also an `error` event,
|
||||
* unless the newest such event already says exactly this (a token missing for days must not
|
||||
* add an event, and with it a dashboard change and one more fallback, on every tick).
|
||||
*/
|
||||
voiceFallback(cause, what) {
|
||||
this.note(voiceFallbackNote(what, cause));
|
||||
if (this.voiceFellBack || !this.s) return;
|
||||
this.voiceFellBack = true;
|
||||
const detail = voiceFallbackDetail(cause);
|
||||
const last = this.s.history.findLast(
|
||||
(e) => e.type === "error" && String(e.detail ?? "").startsWith(VOICE_FALLBACK_PREFIX)
|
||||
);
|
||||
if (last?.detail !== detail) this.event("error", { detail });
|
||||
await this.gh.commentOnce(n, key, body);
|
||||
}
|
||||
|
||||
/** Comment on a PULL REQUEST: never in shadow mode. */
|
||||
@@ -820,7 +755,7 @@ class Tick {
|
||||
if (this.shadow) return this.note(`shadow: label "${label}" kept on #${n}`);
|
||||
this.touched.add(n);
|
||||
if (this.dryRun) return this.note(`would remove label "${label}" from #${n}`);
|
||||
await this.voice.removeLabel(n, label);
|
||||
await this.gh.removeLabel(n, label);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2472,7 +2407,7 @@ class Tick {
|
||||
let issue = existing?.number ?? null;
|
||||
if (existing) await this.comment(existing.number, `divergence:${f.batchId}`, body);
|
||||
else if (this.dryRun) this.note(`would open issue "${title}"`);
|
||||
else issue = (await this.voice.createIssue({ title, body, labels: [DASHBOARD_LABEL] })).number;
|
||||
else issue = (await this.gh.createIssue({ title, body, labels: [DASHBOARD_LABEL] })).number;
|
||||
this.setPaused({
|
||||
reason: "tree-divergence",
|
||||
since: this.now(),
|
||||
@@ -3348,17 +3283,7 @@ class Tick {
|
||||
prs,
|
||||
batchId,
|
||||
heads,
|
||||
...(this.deps.signing ? { signing: this.deps.signing } : {}),
|
||||
});
|
||||
// Signing asked for and not (fully) done: the batch goes on unsigned (never blocked), and the
|
||||
// operator is told once per batch. The cause names no key material and no path.
|
||||
if (result.signing && result.signing.unsigned > 0) {
|
||||
const detail =
|
||||
`${batchId}: ${result.signing.unsigned} merge commit(s) composed unsigned: ` +
|
||||
String(result.signing.cause ?? "unknown cause");
|
||||
this.event("error", { batchId, detail });
|
||||
this.note(detail);
|
||||
}
|
||||
for (const pr of result.excludedBaseConflict ?? []) {
|
||||
if (this.shadow) {
|
||||
this.wouldDequeue(pr, "base-conflict", batchId);
|
||||
@@ -3926,7 +3851,7 @@ class Tick {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return await this.m.dashboard.upsertDashboard({ gh: this.voice, base: this.base, body });
|
||||
return await this.m.dashboard.upsertDashboard({ gh: this.gh, base: this.base, body });
|
||||
} catch (error) {
|
||||
// Cosmetic: never let the dashboard block the state save of real transitions.
|
||||
this.note(`dashboard update failed: ${error.message}`);
|
||||
@@ -4151,7 +4076,7 @@ export async function recordTickFailure(deps, base, detail, warn = () => {}, rec
|
||||
// A base whose stored withdrawals are its only work is found by the next scheduled tick
|
||||
// through its open dashboard issue (discoverBases): one is created when none is open.
|
||||
try {
|
||||
await dashboardIssueOf(deps, base, saved, voiceOf(deps, warn));
|
||||
await dashboardIssueOf(deps, base, saved);
|
||||
} catch (error) {
|
||||
warn(`dashboard of a base with stored withdrawals not created: ${error.message}`);
|
||||
}
|
||||
@@ -4536,7 +4461,7 @@ export function amendFailedTick(state, record, options) {
|
||||
* @param {QueueState} state
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
async function dashboardIssueOf(deps, base, state, voice = deps.gh) {
|
||||
async function dashboardIssueOf(deps, base, state) {
|
||||
const issue = await findDashboard({ gh: deps.gh, base });
|
||||
if (issue !== null) return issue;
|
||||
const body = renderDashboard({
|
||||
@@ -4548,23 +4473,7 @@ async function dashboardIssueOf(deps, base, state, voice = deps.gh) {
|
||||
runUrl: deps.runUrl ?? null,
|
||||
repository: deps.repository,
|
||||
});
|
||||
return createDashboard({ gh: voice, base, body });
|
||||
}
|
||||
|
||||
/**
|
||||
* The client of the human-visible writes outside a Tick (main()'s failure path): deps.gh with
|
||||
* config.voice "app", else the owner voice, whose fallbacks to the App's token go to `warn`.
|
||||
* @param {TickDeps} deps
|
||||
* @param {(message: string) => void} warn
|
||||
*/
|
||||
function voiceOf(deps, warn) {
|
||||
if (deps.config.voice !== "owner") return deps.gh;
|
||||
return createOwnerVoice({
|
||||
app: deps.gh,
|
||||
owner: deps.voiceGh ?? null,
|
||||
ownerLogin: deps.ownerLogin ?? null,
|
||||
onFallback: (cause, what) => warn(voiceFallbackNote(what, cause)),
|
||||
});
|
||||
return createDashboard({ gh: deps.gh, base, body });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -4583,10 +4492,9 @@ function voiceOf(deps, warn) {
|
||||
async function deliverStalledAlert(deps, base, state, warn) {
|
||||
const episode = state.stalled;
|
||||
const key = stalledKey(episode.since);
|
||||
const voice = voiceOf(deps, warn);
|
||||
try {
|
||||
const issue = await dashboardIssueOf(deps, base, state, voice);
|
||||
await voice.commentOnce(
|
||||
const issue = await dashboardIssueOf(deps, base, state);
|
||||
await deps.gh.commentOnce(
|
||||
issue,
|
||||
key,
|
||||
stalledComment({ base, stalled: episode, config: deps.config })
|
||||
@@ -4750,9 +4658,8 @@ export function parseArgs(argv) {
|
||||
|
||||
/**
|
||||
* Build the TickDeps exactly as the CLI does, from the environment (see the header). The GitHub
|
||||
* client counts only comment markers written by `${config.appSlug}[bot]` (and, with the owner
|
||||
* voice, by the owner's login read from OMNI_QUEUE_LAND_TOKEN itself), so a third party cannot
|
||||
* pre-post a marker to mute a queue comment.
|
||||
* client counts only comment markers written by `${config.appSlug}[bot]`, so a third party
|
||||
* cannot pre-post a marker to mute a queue comment.
|
||||
* @param {object} env process.env-like
|
||||
* @param {{now?: () => string, log?: (msg: string) => void, gitEnv?: object}} [overrides]
|
||||
* tests only: injected clock, logger and extra environment for every git process
|
||||
@@ -4793,28 +4700,25 @@ export function createTickDeps(env, overrides = {}) {
|
||||
const remoteUrl = env.OMNI_QUEUE_REMOTE_URL || `${serverUrl}/${repository}.git`;
|
||||
const gitEnv = overrides.gitEnv ?? {};
|
||||
const gitFor = (cwd) => createGit({ cwd, token, identity, log, env: gitEnv });
|
||||
// The owner's token, when landing as the owner or speaking as the owner: never an error here
|
||||
// (shadow runs without it, the voice falls back to the App); a live landing without it pauses
|
||||
// (Tick.landOrWouldLand).
|
||||
const ownerVoice = config.voice === "owner";
|
||||
const ownerToken = owner || ownerVoice ? env.OMNI_QUEUE_LAND_TOKEN || null : null;
|
||||
const landToken = owner ? ownerToken : null;
|
||||
// The owner's token, when landing as the owner: never an error here (shadow runs without it);
|
||||
// a live landing without it pauses (Tick.landOrWouldLand).
|
||||
const landToken = owner ? env.OMNI_QUEUE_LAND_TOKEN || null : null;
|
||||
const landGitFor = !owner
|
||||
? gitFor
|
||||
: landToken
|
||||
? (cwd) => createGit({ cwd, token: landToken, identity, log, env: gitEnv })
|
||||
: null;
|
||||
const ownerGh = ownerToken
|
||||
? createGitHubClient({
|
||||
token: ownerToken,
|
||||
repository,
|
||||
apiUrl: env.GITHUB_API_URL || undefined,
|
||||
botLogin: `${config.appSlug}[bot]`,
|
||||
log,
|
||||
})
|
||||
: null;
|
||||
const landGh = !owner ? gh : ownerGh;
|
||||
const voiceGh = ownerVoice ? ownerGh : null;
|
||||
const landGh = !owner
|
||||
? gh
|
||||
: landToken
|
||||
? createGitHubClient({
|
||||
token: landToken,
|
||||
repository,
|
||||
apiUrl: env.GITHUB_API_URL || undefined,
|
||||
botLogin: `${config.appSlug}[bot]`,
|
||||
log,
|
||||
})
|
||||
: null;
|
||||
return {
|
||||
config,
|
||||
gh,
|
||||
@@ -4822,13 +4726,6 @@ export function createTickDeps(env, overrides = {}) {
|
||||
gitFor,
|
||||
landGitFor,
|
||||
landGh,
|
||||
voiceGh,
|
||||
ownerLogin: createOwnerLoginReader(voiceGh),
|
||||
// The key file the workflow wrote (never the key itself); missing = composed unsigned.
|
||||
signing:
|
||||
config.landing.signing === "ssh"
|
||||
? { keyPath: composeModule.signingKeyPath(env.RUNNER_TEMP) }
|
||||
: null,
|
||||
repoDir,
|
||||
remoteUrl,
|
||||
// A local or file remote cannot serve a partial clone reliably: fetch everything.
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
// scripts/merge-queue/voice.mjs — who performs the queue's human-visible writes (config `voice`).
|
||||
//
|
||||
// With `voice: "app"` (the default) the tick uses the App's client for everything, as before; this
|
||||
// module is not involved. With `voice: "owner"` the writes people read on GitHub go out with the
|
||||
// owner's token (OMNI_QUEUE_LAND_TOKEN, the token the tick already holds for the landing):
|
||||
// - every comment the tick posts on a pull request, and every label it removes from one;
|
||||
// - the dashboard issue: opening it, updating its body, its comments (the stalled alert too);
|
||||
// - comments on the base-red issue, and the tree-divergence issue if the tick opens one.
|
||||
// Everything else stays the App's: commit statuses (omni-queue/land, the approvals, a bless),
|
||||
// candidate branches, the omni-queue-state branch, re-runs of workflow jobs, and every read.
|
||||
//
|
||||
// NEVER LOSE A MESSAGE. The owner's token absent, or a 401/403 from GitHub on an owner write (or
|
||||
// on reading the owner's login): the same write is made with the App's token, and the caller is
|
||||
// told through `onFallback` (the tick records it once per tick, see Tick.voiceFallback). Any other
|
||||
// error (a 5xx, a timeout) is thrown as the App's own errors are: the next tick redoes the write,
|
||||
// whose idempotence (commentOnce markers, an absent label, the dashboard upsert) is unchanged.
|
||||
//
|
||||
// The queue recognises its own comments by their marker AND their author (github.commentOnce).
|
||||
// Under the owner voice the owner's login counts too. That login is read from the owner's token
|
||||
// itself (GET /user, once per process), never from configuration or any other text.
|
||||
//
|
||||
// Zero-dependency on purpose, like every module the queue workflow runs.
|
||||
|
||||
import { VOICES } from "./config.mjs";
|
||||
|
||||
export { VOICES };
|
||||
|
||||
/** Start of the `error` event detail that records a fallback (one per tick, Tick.voiceFallback). */
|
||||
export const VOICE_FALLBACK_PREFIX = "owner voice unavailable";
|
||||
|
||||
/** The `error` event detail of a fallback whose cause is `cause`. */
|
||||
export const voiceFallbackDetail = (cause) =>
|
||||
`${VOICE_FALLBACK_PREFIX}, written with the App's token instead: ${cause}`;
|
||||
|
||||
/** The one-line note (log, decisions) of the write `what` that fell back for `cause`. */
|
||||
export const voiceFallbackNote = (what, cause) =>
|
||||
`owner voice: ${what} written with the App's token (${cause})`;
|
||||
|
||||
/** A user login (never a bot's: `[bot]` and anything else is refused). */
|
||||
const USER_LOGIN_RE = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/;
|
||||
|
||||
/** The owner's token is not there: the tick runs without OMNI_QUEUE_LAND_TOKEN. */
|
||||
export const NO_OWNER_TOKEN_CAUSE = "OMNI_QUEUE_LAND_TOKEN is not set";
|
||||
|
||||
/** GitHub's answer that a credential cannot make this call (bad token, missing permission). */
|
||||
const isRefusal = (error) => error?.status === 401 || error?.status === 403;
|
||||
|
||||
/** A reason to write as the App, carried from the login read to the write. */
|
||||
class Fallback extends Error {}
|
||||
|
||||
/**
|
||||
* The owner's login, read once from the owner's token (GET /user) and remembered for the life of
|
||||
* the process; a refusal (401/403) is remembered too, so a dead token is not asked again on every
|
||||
* write. Any other failure (a 5xx, a timeout) is not remembered: the next call reads again.
|
||||
* @param {{getAuthenticatedLogin: () => Promise<string>}|null} ownerGh
|
||||
* @returns {(() => Promise<string>)|null} null without a client
|
||||
*/
|
||||
export function createOwnerLoginReader(ownerGh) {
|
||||
if (!ownerGh) return null;
|
||||
let settled = null;
|
||||
return () => {
|
||||
if (!settled) {
|
||||
settled = ownerGh.getAuthenticatedLogin().catch((error) => {
|
||||
if (!isRefusal(error)) settled = null;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return settled;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The client of the owner voice: the writes listed above with the owner's client, each one
|
||||
* retried with the App's on a refusal; reads with the App's client.
|
||||
* @param {{app: object, owner: object|null, ownerLogin: (() => Promise<string>)|null,
|
||||
* onFallback?: (cause: string, what: string) => void}} input
|
||||
* app = the App's client (github.mjs); owner = the owner's, null when OMNI_QUEUE_LAND_TOKEN is
|
||||
* not set; ownerLogin = createOwnerLoginReader(owner)
|
||||
* @returns {{listIssues: Function, commentOnce: Function, removeLabel: Function,
|
||||
* createIssue: Function, updateIssue: Function}}
|
||||
*/
|
||||
export function createOwnerVoice({ app, owner, ownerLogin, onFallback = () => {} }) {
|
||||
/** The owner's login, or a Fallback naming why the App writes instead. */
|
||||
async function login() {
|
||||
if (!owner || !ownerLogin) throw new Fallback(NO_OWNER_TOKEN_CAUSE);
|
||||
let value;
|
||||
try {
|
||||
value = await ownerLogin();
|
||||
} catch (error) {
|
||||
if (!isRefusal(error)) throw error;
|
||||
throw new Fallback(`GitHub refused the owner's token reading its login (${error.status})`);
|
||||
}
|
||||
if (typeof value !== "string" || !USER_LOGIN_RE.test(value)) {
|
||||
throw new Fallback("the owner's token does not name a user account");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* One write: with the owner's client, else (no token, a refusal) with the App's. `asApp`
|
||||
* receives the owner's login when it is known (null otherwise).
|
||||
*/
|
||||
async function write(what, asOwner, asApp) {
|
||||
let known;
|
||||
try {
|
||||
known = await login();
|
||||
} catch (error) {
|
||||
if (!(error instanceof Fallback)) throw error;
|
||||
onFallback(error.message, what);
|
||||
return asApp(null);
|
||||
}
|
||||
try {
|
||||
return await asOwner(known);
|
||||
} catch (error) {
|
||||
if (!isRefusal(error)) throw error;
|
||||
onFallback(`GitHub refused the owner's token (${error.status})`, what);
|
||||
return asApp(known);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
listIssues: (...args) => app.listIssues(...args),
|
||||
|
||||
commentOnce: (n, key, body) =>
|
||||
write(
|
||||
`comment ${key} on #${n}`,
|
||||
(known) => owner.commentOnce(n, key, body, { reader: app, alsoLogins: [known] }),
|
||||
// The App's retry still counts the owner's earlier markers when the login is known.
|
||||
(known) =>
|
||||
known
|
||||
? app.commentOnce(n, key, body, { alsoLogins: [known] })
|
||||
: app.commentOnce(n, key, body)
|
||||
),
|
||||
|
||||
removeLabel: (n, label) =>
|
||||
write(
|
||||
`label "${label}" removed from #${n}`,
|
||||
() => owner.removeLabel(n, label),
|
||||
() => app.removeLabel(n, label)
|
||||
),
|
||||
|
||||
createIssue: (input) =>
|
||||
write(
|
||||
`issue "${input?.title ?? ""}" opened`,
|
||||
() => owner.createIssue(input),
|
||||
() => app.createIssue(input)
|
||||
),
|
||||
|
||||
updateIssue: (n, patch) =>
|
||||
write(
|
||||
`issue #${n} updated`,
|
||||
() => owner.updateIssue(n, patch),
|
||||
() => app.updateIssue(n, patch)
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { main as validateAcceptance } from "../validate-release-acceptance.mjs";
|
||||
import { gateKey } from "./types.mjs";
|
||||
|
||||
const GATE = "gate-manifest";
|
||||
const REPORT = "release-acceptance-report.json";
|
||||
|
||||
function identifyCheckout(env, cwd) {
|
||||
const { GITHUB_REPOSITORY, GITHUB_RUN_ID, GITHUB_EVENT_NAME, GITHUB_REF, GITHUB_SHA } = env;
|
||||
const attempt = Number(env.GITHUB_RUN_ATTEMPT);
|
||||
if (
|
||||
!/^[\w.-]+\/[\w.-]+$/.test(GITHUB_REPOSITORY ?? "") ||
|
||||
!/^[1-9]\d*$/.test(GITHUB_RUN_ID ?? "") ||
|
||||
!Number.isSafeInteger(attempt) ||
|
||||
attempt < 1 ||
|
||||
!GITHUB_REF?.startsWith("refs/heads/") ||
|
||||
!["push", "workflow_dispatch"].includes(GITHUB_EVENT_NAME) ||
|
||||
!/^[0-9a-f]{40}$/.test(GITHUB_SHA ?? "")
|
||||
) {
|
||||
throw new Error("Release acceptance requires a valid GitHub workflow identity");
|
||||
}
|
||||
const tested = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
|
||||
if (tested !== GITHUB_SHA) throw new Error("Release acceptance checkout SHA mismatch");
|
||||
execFileSync("git", ["diff", "--quiet", "HEAD", "--"], { cwd });
|
||||
return {
|
||||
repository: GITHUB_REPOSITORY,
|
||||
run_id: GITHUB_RUN_ID,
|
||||
run_attempt: attempt,
|
||||
workflow: "release-acceptance.yml",
|
||||
trigger: GITHUB_EVENT_NAME,
|
||||
scope: "release",
|
||||
requested_ref: GITHUB_REF,
|
||||
base_sha: tested,
|
||||
candidate_sha: tested,
|
||||
tested_sha: tested,
|
||||
};
|
||||
}
|
||||
|
||||
export async function runShadow(out, { env = process.env, cwd = process.cwd() } = {}) {
|
||||
const identity = identifyCheckout(env, cwd);
|
||||
const key = gateKey({ gate_id: GATE });
|
||||
const logs = join(out, "logs");
|
||||
const manifests = join(out, "manifests");
|
||||
const plan = join(out, "plan.json");
|
||||
mkdirSync(logs, { recursive: true });
|
||||
mkdirSync(manifests, { recursive: true });
|
||||
|
||||
const started = performance.now();
|
||||
const execution = spawnSync(process.execPath, ["scripts/quality/gate-manifest.mjs"], {
|
||||
cwd,
|
||||
env,
|
||||
encoding: "utf8",
|
||||
});
|
||||
const duration = Math.round(performance.now() - started);
|
||||
const output = Buffer.from(
|
||||
[execution.stdout, execution.stderr, execution.error?.message, execution.signal]
|
||||
.filter(Boolean)
|
||||
.join("\n")
|
||||
);
|
||||
const status =
|
||||
execution.error || execution.status == null
|
||||
? "INFRA_ERROR"
|
||||
: execution.status === 0
|
||||
? "PASS"
|
||||
: "FAIL";
|
||||
writeFileSync(join(logs, GATE + ".log"), output);
|
||||
writeFileSync(plan, JSON.stringify({ identity, required_gates: [key], artifact: null }) + "\n");
|
||||
writeFileSync(
|
||||
join(manifests, GATE + ".json"),
|
||||
JSON.stringify({
|
||||
...key,
|
||||
tested_sha: identity.tested_sha,
|
||||
run_id: identity.run_id,
|
||||
run_attempt: identity.run_attempt,
|
||||
command_id: "check:gate-manifest",
|
||||
gate_type: "static",
|
||||
status,
|
||||
cause: null,
|
||||
exit_code: execution.status,
|
||||
duration_ms: duration,
|
||||
evidence: [
|
||||
{
|
||||
artifact_id: "logs",
|
||||
member: GATE + ".log",
|
||||
algorithm: "sha256",
|
||||
digest: createHash("sha256").update(output).digest("hex"),
|
||||
},
|
||||
],
|
||||
}) + "\n"
|
||||
);
|
||||
const code = await validateAcceptance([
|
||||
process.execPath,
|
||||
"validate-release-acceptance.mjs",
|
||||
"--plan",
|
||||
plan,
|
||||
"--manifests",
|
||||
manifests,
|
||||
"--evidence-root",
|
||||
out,
|
||||
"--out",
|
||||
join(out, REPORT),
|
||||
]);
|
||||
console.log(
|
||||
`Release acceptance shadow validated ${identity.tested_sha} (exit ${code}, gate: ${GATE})`
|
||||
);
|
||||
return code;
|
||||
}
|
||||
|
||||
if (process.argv[1] && pathToFileURL(process.argv[1]).href === import.meta.url) {
|
||||
const out = process.argv[2];
|
||||
if (!out) throw new Error("Release acceptance shadow requires an artifact output directory");
|
||||
process.exitCode = await runShadow(out);
|
||||
}
|
||||
@@ -20,10 +20,8 @@ import {
|
||||
ROUTER_STRATEGY_OPTIONS,
|
||||
normalizeIntelligentRoutingConfig,
|
||||
} from "@/lib/combos/intelligentRouting";
|
||||
import { isDecisionRouterStrategy } from "@/lib/combos/decisionModelDraft";
|
||||
import { AI_PROVIDERS } from "@/shared/constants/providers";
|
||||
import { compareTr } from "@/shared/utils/turkishText";
|
||||
import DecisionModelSection from "./DecisionModelSection";
|
||||
|
||||
function getI18nOrFallback(
|
||||
t: any,
|
||||
@@ -194,15 +192,12 @@ export default function BuilderIntelligentStep({
|
||||
config,
|
||||
onChange,
|
||||
activeProviders,
|
||||
stepModels = [],
|
||||
strategy = "auto",
|
||||
}: {
|
||||
t: any;
|
||||
config: Record<string, unknown>;
|
||||
onChange: (nextConfig: Record<string, unknown>) => void;
|
||||
activeProviders: any[];
|
||||
/** Plain `provider/model` steps, for the decision router's menu and descriptions. */
|
||||
stepModels?: string[];
|
||||
strategy?: string;
|
||||
}) {
|
||||
const normalizedConfig = normalizeIntelligentRoutingConfig(config);
|
||||
@@ -431,15 +426,6 @@ export default function BuilderIntelligentStep({
|
||||
</Card.Section>
|
||||
)}
|
||||
|
||||
{isDecisionRouterStrategy(normalizedConfig.routerStrategy) && (
|
||||
<DecisionModelSection
|
||||
t={t}
|
||||
config={config}
|
||||
stepModels={stepModels}
|
||||
onChange={(decision) => updateConfig({ decision })}
|
||||
/>
|
||||
)}
|
||||
|
||||
{normalizedConfig.routerStrategy === "nadir" && (
|
||||
<NadirSettingsSection
|
||||
t={t}
|
||||
|
||||
@@ -1,529 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Button from "@/shared/components/Button";
|
||||
import Card from "@/shared/components/Card";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import Input from "@/shared/components/Input";
|
||||
import Select from "@/shared/components/Select";
|
||||
import Textarea from "@/shared/components/Textarea";
|
||||
import {
|
||||
DECISION_DECIDERS,
|
||||
MAX_DECISION_DESCRIPTIONS,
|
||||
MAX_DECISION_DESCRIPTION_CHARS,
|
||||
MAX_DECISION_DESCRIPTION_KEY_CHARS,
|
||||
MAX_DECISION_PROMPT_CHARS,
|
||||
decisionDescriptionRows,
|
||||
patchDecisionDraft,
|
||||
readDecisionDraft,
|
||||
setDecisionDescription,
|
||||
type DecisionDecider,
|
||||
type DecisionDraft,
|
||||
type DecisionWireOption,
|
||||
} from "@/lib/combos/decisionModelDraft";
|
||||
import type { DecisionPreviewResult, DecisionPreviewTest } from "@/lib/combos/decisionPreview";
|
||||
|
||||
/** Translate `key` when the message exists; otherwise (or on ICU errors) return `fallback`. */
|
||||
function getI18nOrFallback(t: any, key: string, fallback: string) {
|
||||
try {
|
||||
if (typeof t?.has === "function" && t.has(key)) return t(key);
|
||||
} catch {
|
||||
// A missing ICU value must not unmount the builder step; see BuilderIntelligentStep.
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/** POST to `/api/combos/decision-preview`; rejects on any non-2xx status. */
|
||||
async function postPreview(body: Record<string, unknown>): Promise<DecisionPreviewResult> {
|
||||
const response = await fetch("/api/combos/decision-preview", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
return response.json();
|
||||
}
|
||||
|
||||
/** Score rounded to three decimals for display; an en dash when absent. */
|
||||
function formatScore(value: number | undefined): string {
|
||||
return value === undefined ? "–" : String(Number(value.toFixed(3)));
|
||||
}
|
||||
|
||||
const DECIDER_FALLBACK_LABELS: Record<DecisionDecider, string> = {
|
||||
systemone: "TypeSafe System One",
|
||||
http: "Own decision URL",
|
||||
"combo-model": "One of this combo's models",
|
||||
};
|
||||
|
||||
const MODEL_PLACEHOLDERS: Record<DecisionDecider, string> = {
|
||||
systemone: "jev-latest",
|
||||
http: "decision-model",
|
||||
"combo-model": "openai/gpt-4o-mini",
|
||||
};
|
||||
|
||||
function TestResult({ t, result }: { t: any; result: DecisionPreviewTest }) {
|
||||
if (result.status !== "selected") {
|
||||
return (
|
||||
<p className="mt-2 text-xs text-warning">
|
||||
{result.status === "failed"
|
||||
? getI18nOrFallback(t, "decisionTestFailed", "Decision request failed:")
|
||||
: getI18nOrFallback(t, "decisionTestSkipped", "Not called:")}{" "}
|
||||
{result.reason}
|
||||
{result.httpStatus ? ` (HTTP ${result.httpStatus})` : ""}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
const probabilities = Object.entries(result.probabilities ?? {}).sort((a, b) => b[1] - a[1]);
|
||||
return (
|
||||
<div className="mt-2 rounded border border-border p-2 text-xs">
|
||||
<p className="text-text-main">
|
||||
→ <span className="font-mono font-semibold">{result.choice}</span>
|
||||
<span className="text-text-muted">
|
||||
{" "}
|
||||
{getI18nOrFallback(t, "decisionTestConfidence", "confidence")}{" "}
|
||||
{formatScore(result.confidence)} · {result.latencyMs} ms
|
||||
{result.backendModel ? ` · ${result.backendModel}` : ""}
|
||||
</span>
|
||||
</p>
|
||||
{probabilities.length > 0 && (
|
||||
<ul className="mt-1 space-y-0.5 text-text-muted">
|
||||
{probabilities.map(([label, probability]) => (
|
||||
<li key={label} className="flex justify-between gap-3 font-mono">
|
||||
<span className="truncate">{label}</span>
|
||||
<span>{formatScore(probability)}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
type UpdateDraft = (patch: Partial<DecisionDraft>) => void;
|
||||
|
||||
const numberOrUndefined = (value: string) => (value === "" ? undefined : Number(value));
|
||||
|
||||
/** `baseUrl` and wire format: only for the `http` decider. */
|
||||
function DecisionHttpFields({
|
||||
t,
|
||||
draft,
|
||||
update,
|
||||
}: {
|
||||
t: any;
|
||||
draft: DecisionDraft;
|
||||
update: UpdateDraft;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Input
|
||||
label={getI18nOrFallback(t, "decisionBaseUrlLabel", "Base URL")}
|
||||
type="url"
|
||||
maxLength={500}
|
||||
value={draft.baseUrl ?? ""}
|
||||
placeholder="https://decider.example.com"
|
||||
onChange={(event) => update({ baseUrl: event.target.value })}
|
||||
/>
|
||||
<Select
|
||||
native
|
||||
label={getI18nOrFallback(t, "decisionWireLabel", "Wire format")}
|
||||
value={draft.wire ?? "systemone"}
|
||||
onChange={(event) => update({ wire: event.target.value as DecisionWireOption })}
|
||||
options={[
|
||||
{ value: "systemone", label: "System One (/v1/systemone)" },
|
||||
{ value: "openai-chat", label: "OpenAI chat (/v1/chat/completions)" },
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** Timeout and minimum confidence. */
|
||||
function DecisionLimitFields({
|
||||
t,
|
||||
draft,
|
||||
update,
|
||||
}: {
|
||||
t: any;
|
||||
draft: DecisionDraft;
|
||||
update: UpdateDraft;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
<Input
|
||||
label={getI18nOrFallback(t, "decisionTimeoutLabel", "Timeout (ms)")}
|
||||
type="number"
|
||||
min="100"
|
||||
max="5000"
|
||||
step="100"
|
||||
value={draft.timeoutMs ?? ""}
|
||||
placeholder="2000"
|
||||
onChange={(event) => update({ timeoutMs: numberOrUndefined(event.target.value) })}
|
||||
/>
|
||||
<Input
|
||||
label={getI18nOrFallback(t, "decisionMinConfidenceLabel", "Minimum confidence")}
|
||||
type="number"
|
||||
min="0"
|
||||
max="1"
|
||||
step="0.05"
|
||||
value={draft.minConfidence ?? ""}
|
||||
placeholder="0"
|
||||
onChange={(event) => update({ minConfidence: numberOrUndefined(event.target.value) })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** Decider, model, endpoint, connection and limits, plus the credential hint. */
|
||||
function DecisionSettingsFields({
|
||||
t,
|
||||
draft,
|
||||
update,
|
||||
}: {
|
||||
t: any;
|
||||
draft: DecisionDraft;
|
||||
update: UpdateDraft;
|
||||
}) {
|
||||
const comboModel = draft.decider === "combo-model";
|
||||
return (
|
||||
<>
|
||||
<div className="mt-3 grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<Select
|
||||
native
|
||||
label={getI18nOrFallback(t, "decisionDeciderLabel", "Decider")}
|
||||
value={draft.decider}
|
||||
onChange={(event) => update({ decider: event.target.value as DecisionDecider })}
|
||||
options={DECISION_DECIDERS.map((decider) => ({
|
||||
value: decider,
|
||||
label: getI18nOrFallback(
|
||||
t,
|
||||
`decisionDecider_${decider.replace("-", "_")}`,
|
||||
DECIDER_FALLBACK_LABELS[decider]
|
||||
),
|
||||
}))}
|
||||
/>
|
||||
<Input
|
||||
label={getI18nOrFallback(t, "decisionModelLabel", "Decision model")}
|
||||
type="text"
|
||||
maxLength={200}
|
||||
value={draft.model ?? ""}
|
||||
placeholder={MODEL_PLACEHOLDERS[draft.decider]}
|
||||
onChange={(event) => update({ model: event.target.value })}
|
||||
/>
|
||||
{draft.decider === "http" && <DecisionHttpFields t={t} draft={draft} update={update} />}
|
||||
{!comboModel && (
|
||||
<Input
|
||||
label={getI18nOrFallback(t, "decisionConnectionLabel", "Connection ID (optional)")}
|
||||
type="text"
|
||||
maxLength={200}
|
||||
value={draft.connectionId ?? ""}
|
||||
placeholder="OMNIROUTE_DECISION_API_KEY"
|
||||
onChange={(event) => update({ connectionId: event.target.value })}
|
||||
/>
|
||||
)}
|
||||
<DecisionLimitFields t={t} draft={draft} update={update} />
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-text-muted">
|
||||
{comboModel
|
||||
? getI18nOrFallback(
|
||||
t,
|
||||
"decisionComboModelHint",
|
||||
"The decision runs in process on one of your provider models (provider/model). Combo names are refused."
|
||||
)
|
||||
: getI18nOrFallback(
|
||||
t,
|
||||
"decisionCredentialHint",
|
||||
"The key comes from the stored connection with this ID (within the API key's allowed connections) or from the OMNIROUTE_DECISION_API_KEY environment variable. No key is stored in the combo."
|
||||
)}
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** One description row: the model id (removable when outside the menu) and its text. */
|
||||
function DescriptionRow({
|
||||
t,
|
||||
rowKey,
|
||||
inMenu,
|
||||
draft,
|
||||
placeholder,
|
||||
full,
|
||||
onRemove,
|
||||
onChange,
|
||||
}: {
|
||||
t: any;
|
||||
rowKey: string;
|
||||
inMenu: boolean;
|
||||
draft: DecisionDraft;
|
||||
placeholder: string;
|
||||
full: boolean;
|
||||
onRemove: (key: string) => void;
|
||||
onChange: (decision: DecisionDraft) => void;
|
||||
}) {
|
||||
const removeLabel = getI18nOrFallback(t, "decisionRemoveDescription", "Remove");
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-[minmax(0,14rem)_1fr] gap-2">
|
||||
<div className="flex items-center gap-1 min-w-0">
|
||||
<span className="truncate font-mono text-xs text-text-main" title={rowKey}>
|
||||
{rowKey}
|
||||
</span>
|
||||
{!inMenu && (
|
||||
<Button
|
||||
size="icon-sm"
|
||||
variant="ghost"
|
||||
onClick={() => onRemove(rowKey)}
|
||||
title={removeLabel}
|
||||
aria-label={removeLabel}
|
||||
>
|
||||
<Icon name="close" size={14} />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<Input
|
||||
type="text"
|
||||
maxLength={MAX_DECISION_DESCRIPTION_CHARS}
|
||||
aria-label={rowKey}
|
||||
value={draft.descriptions?.[rowKey] ?? ""}
|
||||
placeholder={placeholder}
|
||||
disabled={draft.descriptions?.[rowKey] === undefined && full}
|
||||
onChange={(event) => onChange(setDecisionDescription(draft, rowKey, event.target.value))}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Input + button that add a description row for a model id outside the menu. */
|
||||
function AddDescriptionKey({
|
||||
t,
|
||||
value,
|
||||
onValue,
|
||||
onAdd,
|
||||
}: {
|
||||
t: any;
|
||||
value: string;
|
||||
onValue: (value: string) => void;
|
||||
onAdd: () => void;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
type="text"
|
||||
maxLength={MAX_DECISION_DESCRIPTION_KEY_CHARS}
|
||||
value={value}
|
||||
placeholder={getI18nOrFallback(
|
||||
t,
|
||||
"decisionAddKeyPlaceholder",
|
||||
"Add model ID or provider/model"
|
||||
)}
|
||||
onChange={(event) => onValue(event.target.value)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
onAdd();
|
||||
}
|
||||
}}
|
||||
className="flex-1"
|
||||
inputClassName="font-mono"
|
||||
/>
|
||||
<Button size="sm" variant="outline" onClick={onAdd} disabled={!value.trim()}>
|
||||
{getI18nOrFallback(t, "decisionAddKey", "Add")}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Per-model descriptions; generated cost-rank text is the placeholder, only typed text is stored. */
|
||||
function DecisionDescriptions({
|
||||
t,
|
||||
draft,
|
||||
preview,
|
||||
onChange,
|
||||
}: {
|
||||
t: any;
|
||||
draft: DecisionDraft;
|
||||
preview: DecisionPreviewResult | null;
|
||||
onChange: (decision: DecisionDraft) => void;
|
||||
}) {
|
||||
const [pendingKeys, setPendingKeys] = useState<string[]>([]);
|
||||
const [newKey, setNewKey] = useState("");
|
||||
const rows = decisionDescriptionRows(preview?.menu ?? [], draft.descriptions, pendingKeys);
|
||||
const descriptionCount = Object.keys(draft.descriptions ?? {}).length;
|
||||
const addKey = () => {
|
||||
const key = newKey.trim();
|
||||
if (!key || rows.some((row) => row.key === key)) return;
|
||||
setPendingKeys((keys) => [...keys, key]);
|
||||
setNewKey("");
|
||||
};
|
||||
const removeKey = (key: string) => {
|
||||
setPendingKeys((keys) => keys.filter((entry) => entry !== key));
|
||||
onChange(setDecisionDescription(draft, key, ""));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mt-4">
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<p className="text-xs font-semibold text-text-main">
|
||||
{getI18nOrFallback(t, "decisionDescriptionsLabel", "Model descriptions")}
|
||||
</p>
|
||||
<span className="text-xs text-text-muted">
|
||||
{descriptionCount}/{MAX_DECISION_DESCRIPTIONS}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-xs text-text-muted mt-1">
|
||||
{getI18nOrFallback(
|
||||
t,
|
||||
"decisionDescriptionsHint",
|
||||
"Tell the decider what each model is good at. Leave a row empty to send the generated text shown as placeholder."
|
||||
)}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-col gap-2">
|
||||
{rows.map(({ key, inMenu }) => (
|
||||
<DescriptionRow
|
||||
key={key}
|
||||
t={t}
|
||||
rowKey={key}
|
||||
inMenu={inMenu}
|
||||
draft={draft}
|
||||
placeholder={preview?.generated[key] ?? `Model ${key}`}
|
||||
full={descriptionCount >= MAX_DECISION_DESCRIPTIONS}
|
||||
onRemove={removeKey}
|
||||
onChange={onChange}
|
||||
/>
|
||||
))}
|
||||
<AddDescriptionKey t={t} value={newKey} onValue={setNewKey} onAdd={addKey} />
|
||||
</div>
|
||||
<p className="mt-2 text-xs text-warning">
|
||||
{getI18nOrFallback(
|
||||
t,
|
||||
"decisionPrivacyNote",
|
||||
"Each routed request sends its last user message (up to 8000 characters) and these descriptions to the decider. Do not put internal names or secrets in descriptions."
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** One-off live test with the unsaved settings, through the preview route. */
|
||||
function DecisionTestPanel({
|
||||
t,
|
||||
draft,
|
||||
stepModels,
|
||||
}: {
|
||||
t: any;
|
||||
draft: DecisionDraft;
|
||||
stepModels: string[];
|
||||
}) {
|
||||
const [prompt, setPrompt] = useState("");
|
||||
const [testing, setTesting] = useState(false);
|
||||
const [testResult, setTestResult] = useState<DecisionPreviewTest | null>(null);
|
||||
const [testError, setTestError] = useState(false);
|
||||
const runTest = async () => {
|
||||
setTesting(true);
|
||||
setTestError(false);
|
||||
setTestResult(null);
|
||||
try {
|
||||
const result = await postPreview({ models: stepModels, decision: draft, prompt });
|
||||
setTestResult(result.test ?? null);
|
||||
} catch {
|
||||
setTestError(true);
|
||||
} finally {
|
||||
setTesting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="mt-4">
|
||||
<p className="text-xs font-semibold text-text-main">
|
||||
{getI18nOrFallback(t, "decisionTestTitle", "Test decision")}
|
||||
</p>
|
||||
<p className="text-xs text-text-muted mt-1">
|
||||
{getI18nOrFallback(
|
||||
t,
|
||||
"decisionTestHint",
|
||||
"Sends the prompt and the current (unsaved) settings to the decider once. This is a real, possibly billed request."
|
||||
)}
|
||||
</p>
|
||||
<div className="mt-2 flex flex-col md:flex-row gap-2">
|
||||
<Textarea
|
||||
rows={2}
|
||||
maxLength={MAX_DECISION_PROMPT_CHARS}
|
||||
value={prompt}
|
||||
placeholder={getI18nOrFallback(t, "decisionTestPlaceholder", "Example prompt")}
|
||||
onChange={(event) => setPrompt(event.target.value)}
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button size="sm" onClick={runTest} loading={testing} disabled={testing || !prompt.trim()}>
|
||||
{getI18nOrFallback(t, "decisionTestButton", "Test")}
|
||||
</Button>
|
||||
</div>
|
||||
{testError && (
|
||||
<p className="mt-2 text-xs text-error">
|
||||
{getI18nOrFallback(t, "decisionTestError", "The preview request failed.")}
|
||||
</p>
|
||||
)}
|
||||
{testResult && <TestResult t={t} result={testResult} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Generated menu texts (cost rank), fetched after a short debounce and never stored. */
|
||||
function useDecisionPreview(stepModels: string[]): DecisionPreviewResult | null {
|
||||
const [preview, setPreview] = useState<DecisionPreviewResult | null>(null);
|
||||
const modelsKey = stepModels.join("\n");
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
const timer = setTimeout(() => {
|
||||
postPreview({ models: modelsKey ? modelsKey.split("\n") : [] })
|
||||
.then((result) => {
|
||||
if (!cancelled) setPreview(result);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setPreview(null);
|
||||
});
|
||||
}, 300);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}, [modelsKey]);
|
||||
return preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combo-builder section for the `decision` router: decider, endpoint, model, connection,
|
||||
* limits, per-model descriptions and a one-off live test. Stored as `config.decision`.
|
||||
*/
|
||||
export default function DecisionModelSection({
|
||||
t,
|
||||
config,
|
||||
stepModels,
|
||||
onChange,
|
||||
}: {
|
||||
t: any;
|
||||
config: Record<string, unknown>;
|
||||
/** Plain `provider/model` step strings of the combo being edited. */
|
||||
stepModels: string[];
|
||||
onChange: (decision: DecisionDraft) => void;
|
||||
}) {
|
||||
const draft = readDecisionDraft(config);
|
||||
const preview = useDecisionPreview(stepModels);
|
||||
const update: UpdateDraft = (patch) => onChange(patchDecisionDraft(draft, patch));
|
||||
|
||||
return (
|
||||
<Card.Section>
|
||||
<div>
|
||||
<p className="text-xs font-semibold text-text-main">
|
||||
{getI18nOrFallback(t, "decisionRouterTitle", "Decision router")}
|
||||
</p>
|
||||
<p className="text-xs text-text-muted mt-1">
|
||||
{getI18nOrFallback(
|
||||
t,
|
||||
"decisionRouterHint",
|
||||
"A decider picks one model per request from this combo's models; Rules then picks the account. Requires the COMBO_DECISION_ROUTER_ENABLED feature flag: while it is off, or on any failure, the combo routes with Rules."
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<DecisionSettingsFields t={t} draft={draft} update={update} />
|
||||
<DecisionDescriptions t={t} draft={draft} preview={preview} onChange={onChange} />
|
||||
<DecisionTestPanel t={t} draft={draft} stepModels={stepModels} />
|
||||
</Card.Section>
|
||||
);
|
||||
}
|
||||
@@ -121,7 +121,6 @@ import {
|
||||
normalizeIntelligentRoutingFilter,
|
||||
normalizeIntelligentRoutingConfig,
|
||||
} from "@/lib/combos/intelligentRouting";
|
||||
import { toDecisionPreviewModels } from "@/lib/combos/decisionModelDraft";
|
||||
import { getComboStepTarget } from "@/lib/combos/steps";
|
||||
import {
|
||||
findComboStepConnectionLabel,
|
||||
@@ -2592,7 +2591,6 @@ function ComboFormModal({
|
||||
);
|
||||
const usesIntelligentBuilderStage = isIntelligentBuilderStrategy(strategy);
|
||||
const intelligentConfig = useMemo(() => normalizeIntelligentRoutingConfig(config), [config]);
|
||||
const decisionStepModels = useMemo(() => toDecisionPreviewModels(models), [models]);
|
||||
|
||||
const resetFormForCombo = useCallback(
|
||||
(nextCombo, comboDefaults = null) => {
|
||||
@@ -3918,7 +3916,6 @@ function ComboFormModal({
|
||||
strategy={strategy}
|
||||
config={config}
|
||||
activeProviders={builderProviders}
|
||||
stepModels={decisionStepModels}
|
||||
onChange={(nextIntelligentConfig: any) =>
|
||||
setConfig((previousConfig) => ({
|
||||
...previousConfig,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Badge, Button, Card, Input, Select } from "@/shared/components";
|
||||
import { type ReactNode, useCallback, useEffect, useState } from "react";
|
||||
import { Button, Card, Select } from "@/shared/components";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { Spinner } from "@/shared/components/Loading";
|
||||
import { useNotificationStore } from "@/store/notificationStore";
|
||||
@@ -1130,28 +1130,12 @@ function CredentialHealthCheckCard({
|
||||
);
|
||||
}
|
||||
|
||||
// Mirrors `customBannedSignals: z.array(z.string().max(200))` in
|
||||
// src/shared/validation/settingsSchemas.ts — keep the two in sync.
|
||||
const MAX_BANNED_KEYWORD_LENGTH = 200;
|
||||
|
||||
export default function ResilienceTab() {
|
||||
const notify = useNotificationStore();
|
||||
const t = useTranslations("settings");
|
||||
const tc = useTranslations("common");
|
||||
const [data, setData] = useState<ResilienceResponse | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [savingSection, setSavingSection] = useState<string | null>(null);
|
||||
const [bannedKeywords, setBannedKeywords] = useState<string[]>([]);
|
||||
const [bannedKeywordInput, setBannedKeywordInput] = useState("");
|
||||
const [bannedKeywordsLoading, setBannedKeywordsLoading] = useState(true);
|
||||
const [bannedKeywordsLoadFailed, setBannedKeywordsLoadFailed] = useState(false);
|
||||
const [savingBannedKeywords, setSavingBannedKeywords] = useState(false);
|
||||
const [bannedKeywordsLoadToken, setBannedKeywordsLoadToken] = useState(0);
|
||||
// The ref is the single source of truth: it always holds the last list the
|
||||
// server confirmed. Rapid add/remove clicks therefore cannot build on a
|
||||
// stale closure value, and a failed PATCH never desyncs UI from server.
|
||||
const bannedKeywordsRef = useRef<string[]>([]);
|
||||
const bannedKeywordsSavingRef = useRef(false);
|
||||
const tx = useCallback(
|
||||
(key: string, fallback: string) => {
|
||||
if (typeof t.has === "function" && t.has(key as never)) {
|
||||
@@ -1162,102 +1146,6 @@ export default function ResilienceTab() {
|
||||
[t]
|
||||
);
|
||||
|
||||
// Custom banned keywords live in /api/settings, not in the resilience
|
||||
// payload, so this card loads and saves them independently. It belongs on
|
||||
// the Resilience page next to AutoDisableCard: it decides when an upstream
|
||||
// error permanently bans and disables a connection.
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
const load = async () => {
|
||||
setBannedKeywordsLoading(true);
|
||||
setBannedKeywordsLoadFailed(false);
|
||||
try {
|
||||
const res = await fetch("/api/settings");
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const settings = await res.json();
|
||||
if (!mounted) return;
|
||||
// The classifier lowercases the error body but NOT the signal itself, so
|
||||
// uppercase values imported elsewhere would never match. Normalise on
|
||||
// load (trim + lowercase + dedupe); keep long values rather than
|
||||
// silently discarding server-side data — adding is guarded separately.
|
||||
const list: string[] = Array.isArray(settings?.customBannedSignals)
|
||||
? Array.from(
|
||||
new Set(
|
||||
settings.customBannedSignals
|
||||
.filter((v: unknown) => typeof v === "string")
|
||||
.map((v: string) => v.trim().toLowerCase())
|
||||
.filter(Boolean)
|
||||
)
|
||||
)
|
||||
: [];
|
||||
bannedKeywordsRef.current = list;
|
||||
setBannedKeywords(list);
|
||||
} catch (error) {
|
||||
console.error("Failed to load custom banned signals:", error);
|
||||
// Never show the "no keywords" empty state when loading failed:
|
||||
// editing from there would overwrite the real server-side list.
|
||||
if (mounted) setBannedKeywordsLoadFailed(true);
|
||||
} finally {
|
||||
if (mounted) setBannedKeywordsLoading(false);
|
||||
}
|
||||
};
|
||||
void load();
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
}, [bannedKeywordsLoadToken]);
|
||||
|
||||
// Commit only after the server accepts the write. The synchronous ref lock
|
||||
// serialises edits so two quick clicks cannot race on a stale array.
|
||||
const saveBannedKeywords = async (next: string[]): Promise<boolean> => {
|
||||
if (bannedKeywordsSavingRef.current) return false;
|
||||
bannedKeywordsSavingRef.current = true;
|
||||
setSavingBannedKeywords(true);
|
||||
try {
|
||||
const res = await fetch("/api/settings", {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ customBannedSignals: next }),
|
||||
});
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
bannedKeywordsRef.current = next;
|
||||
setBannedKeywords(next);
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error("Failed to update custom banned signals:", error);
|
||||
notify.error(tx("saveFailed", "Failed to save banned keywords"));
|
||||
return false;
|
||||
} finally {
|
||||
bannedKeywordsSavingRef.current = false;
|
||||
setSavingBannedKeywords(false);
|
||||
}
|
||||
};
|
||||
|
||||
const bannedKeywordsBusy =
|
||||
bannedKeywordsLoading || bannedKeywordsLoadFailed || savingBannedKeywords;
|
||||
|
||||
const addBannedKeyword = async () => {
|
||||
if (bannedKeywordsBusy || bannedKeywordsSavingRef.current) return;
|
||||
const keyword = bannedKeywordInput.trim().toLowerCase();
|
||||
if (!keyword || bannedKeywordsRef.current.includes(keyword)) return;
|
||||
// Defence in depth for the Input's maxLength: the server rejects strings
|
||||
// longer than 200 chars (settingsSchemas.ts), which would otherwise be a
|
||||
// silent failure.
|
||||
if (keyword.length > MAX_BANNED_KEYWORD_LENGTH) {
|
||||
notify.error(tx("saveFailed", "Failed to save banned keywords"));
|
||||
return;
|
||||
}
|
||||
const saved = await saveBannedKeywords([...bannedKeywordsRef.current, keyword]);
|
||||
if (saved) setBannedKeywordInput("");
|
||||
};
|
||||
|
||||
// Remove by value, not by index: with an async save an index can go stale
|
||||
// between two quick clicks (and makes a stable React key).
|
||||
const removeBannedKeyword = (keyword: string) => {
|
||||
if (bannedKeywordsBusy || bannedKeywordsSavingRef.current) return;
|
||||
void saveBannedKeywords(bannedKeywordsRef.current.filter((k) => k !== keyword));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
@@ -1311,115 +1199,29 @@ export default function ResilienceTab() {
|
||||
}
|
||||
};
|
||||
|
||||
// The banned-keyword editor reads /api/settings, not /api/resilience.
|
||||
// Keep it outside the resilience-data guards: if /api/resilience fails,
|
||||
// keyword management must still work (SecurityTab no longer has an editor).
|
||||
const bannedKeywordsCard = (
|
||||
<Card
|
||||
icon="report"
|
||||
title={tx("customBannedSignals", "Banned Keywords")}
|
||||
subtitle={tx(
|
||||
"customBannedSignalsDesc",
|
||||
"Additional keywords that trigger permanent account ban detection. Built-in keywords always apply."
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-col sm:flex-row sm:items-start gap-2">
|
||||
<Input
|
||||
className="flex-1"
|
||||
aria-label={tx("customBannedSignals", "Banned Keywords")}
|
||||
placeholder={tx("customBannedSignalsPlaceholder", "e.g. api key revoked")}
|
||||
value={bannedKeywordInput}
|
||||
maxLength={MAX_BANNED_KEYWORD_LENGTH}
|
||||
disabled={bannedKeywordsBusy}
|
||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
||||
setBannedKeywordInput(e.target.value)
|
||||
}
|
||||
onKeyDown={(e: React.KeyboardEvent) => {
|
||||
if (e.key === "Enter") void addBannedKeyword();
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
icon="add"
|
||||
onClick={() => void addBannedKeyword()}
|
||||
disabled={bannedKeywordsBusy || !bannedKeywordInput.trim()}
|
||||
>
|
||||
{tc("add")}
|
||||
</Button>
|
||||
</div>
|
||||
{bannedKeywordsLoadFailed ? (
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-xs text-error">{tx("errorOccurred", "An error occurred")}</p>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
icon="refresh"
|
||||
onClick={() => setBannedKeywordsLoadToken((n) => n + 1)}
|
||||
>
|
||||
{tx("retry", "Retry")}
|
||||
</Button>
|
||||
</div>
|
||||
) : bannedKeywordsLoading ? (
|
||||
<Spinner decorative size="sm" />
|
||||
) : bannedKeywords.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{bannedKeywords.map((keyword) => (
|
||||
<Badge key={keyword} variant="error" className="gap-1 pr-1">
|
||||
{keyword}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="size-5"
|
||||
disabled={savingBannedKeywords}
|
||||
onClick={() => removeBannedKeyword(keyword)}
|
||||
aria-label={`${tx("remove", "Remove")} ${keyword}`}
|
||||
>
|
||||
<Icon name="close" size={12} />
|
||||
</Button>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-text-muted">
|
||||
{tx("noCustomBannedSignals", "No custom keywords. Only built-in keywords are active.")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
|
||||
if (loading && !data) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{bannedKeywordsCard}
|
||||
<Card className="p-6">
|
||||
<div role="status" className="flex items-center gap-2 text-sm text-text-muted">
|
||||
<Spinner decorative size="sm" />
|
||||
{tx("loadingResilience", "Loading resilience settings...")}
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
<Card className="p-6">
|
||||
<div role="status" className="flex items-center gap-2 text-sm text-text-muted">
|
||||
<Spinner decorative size="sm" />
|
||||
{tx("loadingResilience", "Loading resilience settings...")}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{bannedKeywordsCard}
|
||||
<Card className="p-6">
|
||||
<p className="text-sm text-text-muted">
|
||||
{tx("failedLoadResilience", "Unable to load resilience settings.")}
|
||||
</p>
|
||||
</Card>
|
||||
</div>
|
||||
<Card className="p-6">
|
||||
<p className="text-sm text-text-muted">
|
||||
{tx("failedLoadResilience", "Unable to load resilience settings.")}
|
||||
</p>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{bannedKeywordsCard}
|
||||
<AutoDisableCard />
|
||||
{data.preferredAccountFailover && (
|
||||
<PreferredAccountFailoverCard
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { Checkbox, CheckboxGroup } from "@omniroute/ui-kit/checkbox";
|
||||
import { Card, Button, Input, Toggle, Modal } from "@/shared/components";
|
||||
import { Card, Button, Input, Toggle, Modal, Badge } from "@/shared/components";
|
||||
import Icon from "@/shared/components/Icon";
|
||||
import { AI_PROVIDERS } from "@/shared/constants/providers";
|
||||
import ProviderIcon from "@/shared/components/ProviderIcon";
|
||||
@@ -32,6 +32,7 @@ export default function SecurityTab() {
|
||||
const [requireLoginPassword, setRequireLoginPassword] = useState("");
|
||||
const [requireLoginError, setRequireLoginError] = useState("");
|
||||
const [requireLoginLoading, setRequireLoginLoading] = useState(false);
|
||||
const [newBannedKeyword, setNewBannedKeyword] = useState("");
|
||||
|
||||
const t = useTranslations("settings");
|
||||
const tc = useTranslations("common");
|
||||
@@ -145,6 +146,20 @@ export default function SecurityTab() {
|
||||
updateSetting("blockedProviders", updated);
|
||||
};
|
||||
|
||||
const customBannedSignals: string[] = settings.customBannedSignals || [];
|
||||
|
||||
const addBannedKeyword = () => {
|
||||
const keyword = newBannedKeyword.trim().toLowerCase();
|
||||
if (!keyword || customBannedSignals.includes(keyword)) return;
|
||||
updateSetting("customBannedSignals", [...customBannedSignals, keyword]);
|
||||
setNewBannedKeyword("");
|
||||
};
|
||||
|
||||
const removeBannedKeyword = (index: number) => {
|
||||
const updated = customBannedSignals.filter((_, i) => i !== index);
|
||||
updateSetting("customBannedSignals", updated);
|
||||
};
|
||||
|
||||
const handlePasswordChange = async (e) => {
|
||||
e.preventDefault();
|
||||
if (passwords.new !== passwords.confirm) {
|
||||
@@ -394,6 +409,70 @@ export default function SecurityTab() {
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* Custom Banned Keywords */}
|
||||
<Card
|
||||
icon="report"
|
||||
title={getSettingsLabel("customBannedSignals", "Banned Keywords")}
|
||||
subtitle={getSettingsLabel(
|
||||
"customBannedSignalsDesc",
|
||||
"Additional keywords that trigger permanent account ban detection. Built-in keywords always apply."
|
||||
)}
|
||||
>
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-col sm:flex-row sm:items-start gap-2">
|
||||
<Input
|
||||
className="flex-1"
|
||||
aria-label={getSettingsLabel("customBannedSignals", "Banned Keywords")}
|
||||
placeholder={getSettingsLabel(
|
||||
"customBannedSignalsPlaceholder",
|
||||
"e.g. api key revoked"
|
||||
)}
|
||||
value={newBannedKeyword}
|
||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
|
||||
setNewBannedKeyword(e.target.value)
|
||||
}
|
||||
onKeyDown={(e: React.KeyboardEvent) => {
|
||||
if (e.key === "Enter") addBannedKeyword();
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
variant="secondary"
|
||||
size="sm"
|
||||
icon="add"
|
||||
onClick={addBannedKeyword}
|
||||
disabled={!newBannedKeyword.trim()}
|
||||
>
|
||||
{getSettingsLabel("add", "Add")}
|
||||
</Button>
|
||||
</div>
|
||||
{customBannedSignals.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{customBannedSignals.map((keyword, index) => (
|
||||
<Badge key={index} variant="error" className="gap-1 pr-1">
|
||||
{keyword}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
className="size-5"
|
||||
onClick={() => removeBannedKeyword(index)}
|
||||
aria-label={`${getSettingsLabel("remove", "Remove")} ${keyword}`}
|
||||
>
|
||||
<Icon name="close" size={12} />
|
||||
</Button>
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-text-muted">
|
||||
{getSettingsLabel(
|
||||
"noCustomBannedSignals",
|
||||
"No custom keywords. Only built-in keywords are active."
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
icon="shield"
|
||||
title={getSettingsLabel("credentialRedaction", "Credential Redaction")}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user