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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,20 @@ first publish and later OIDC releases.

## Where things stand

All five synchronized packages and exact internal Support pins are published
and strictly verified at `0.2.11`; the root stays private at `0.0.0`. This release
The current source candidate is synchronized `0.2.12`, adding explicit opt-in
provider-group routing for learning and engineering independent checks. All
five source package versions, exact internal Support pins and root Support
development pins select `0.2.12`; the root stays private at `0.0.0`. External
dependency selections are unchanged. Route, static allowlist and Admin approval
must agree on group scope, with a newly hash-bound price policy and current
qualification/privacy evidence. Azure group selection does not guarantee a
region or activate a host. See the [source preparation](docs/RELEASING.md#source-version-0212)
and [candidate notes](docs/RELEASE_NOTES.md#0212-opt-in-provider-group-checks).
Normal Node 22/24, review, CI and protected release gates remain required;
the candidate is not a published dependency.

The latest verified public synchronized release remains `0.2.11`, with exact
internal Support pins at `0.2.11`; the root stays private at `0.0.0`. This release
corrects the trusted independent-check policy boundary and selects wire v2.
Exact KB `0.1.8`, `zod@4.6.7` and other external selections are unchanged. See
[release notes](docs/RELEASE_NOTES.md#0211-trusted-independent-check-policy) and
Expand Down
11 changes: 11 additions & 0 deletions docs/AI_OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ version, verification time, and expiry. Typed references alone do not verify
the provider's settings. Disabled, expired, unavailable, or changed proof holds
new work. There is no implicit provider or retention-mode fallback.

The source-only [provider-group checker option](../packages/ai/README.md#opt-in-provider-group-checks-source-only)
requires explicit route, static allowlist and Admin-approval scope selections,
plus a newly hash-bound price policy and current group privacy/qualification
evidence. It does not extend the published `0.2.11` contract or enable a host.
An Azure group may include eligible regions and variants; it does not establish
the exact region of a previous endpoint approval. Preserve ZDR-only routing,
disabled input/output logging and no-other-provider fallback. The prompt and
completion price filters are USD per million tokens, separate from total
spending caps and actual native charges. Retain durable unknown-usage holds and
require the host's independent approval and activation gates before live use.

## Bounded workers and durable recovery

Persist a separate opaque cursor for each scheduled scan loop and purpose.
Expand Down
41 changes: 41 additions & 0 deletions docs/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# Release notes

<a id="0212-opt-in-provider-group-checks"></a>

<a id="0212-source-candidate--opt-in-provider-group-checks"></a>

## 0.2.12 source candidate — opt-in provider-group checks

Source preparation dated 2026-11-14 synchronizes all five package versions,
exact internal Support pins, root Support development pins and lock importers
at `0.2.12`. The root stays private at `0.0.0`; all external dependency
selections remain unchanged. This candidate is not published. The verified
`0.2.11` release and its original artifacts/receipts remain unchanged; see the
[source checkpoint](RELEASING.md#source-version-0212).

Learning and engineering independent checks may explicitly opt into
`providerSelectionScope: "provider_group"` on the route, matching static
allowlist entry and Admin approval. The route requires
`providerMaxPrice: { prompt, completion, request: 0 }`; scope and prices bind
the newly approved route-policy hash. Leaving these keys absent retains existing
selector policy, refusals, request bodies and hashes. Explicit `undefined`
properties are refused as incomplete policy, even where optional authoring types
can represent them; omit unused keys entirely. Group mode uses a
bare provider slug such as `azure`, which can include eligible variants and
regions; it does not guarantee Sweden or another endpoint's location. The
release follow-up checker refuses group mode before funding; answering and
generation policies are unchanged.

ZDR-only routing, no-other-provider fallback, disabled input/output logging,
current evidence/expiry, token limits and durable spending caps remain in
force. Prompt and completion price ceilings are USD per million text tokens,
separate from total request cost and actual native charges. Missing request
price metadata is not proven zero by `request: 0`: the host must review eligible
endpoint metadata and non-token charges under its current verified evidence.
No metadata network port, automatic paid retry, permission or durable layout
is added. Unknown usage retains conservative accounting.

See the [adapter contract](../packages/ai/README.md#opt-in-provider-group-checks-source-only)
for approval and qualification requirements. Normal source/release gates,
actual provider privacy and price enforcement, model quality and each host's
deployment, client and activation acceptance remain required. Structural
support does not authorize a live call.

<a id="0211-trusted-independent-check-policy"></a>

<a id="0211-source-candidate--trusted-independent-check-policy"></a>
Expand Down
31 changes: 31 additions & 0 deletions docs/RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Release operations

<a id="source-version-0212"></a>

<a id="0212-source-preparation-2026-11-14"></a>

## 0.2.12 source preparation: 2026-11-14

The synchronized source candidate selects `0.2.12` for all five package
versions and exact internal Support pins, including root Support development
pins and matching workspace lock importers. The root remains private at
`0.0.0`. Exact KB application/contracts `0.1.8`, `zod@4.6.7` and every other
external dependency selection are unchanged.

This candidate adds explicit opt-in provider-group routing for learning and
engineering independent checks. The route, static allowlist and Admin approval
must agree on group scope; scope and explicit price ceilings enter the route
policy hash. Existing exact mode, request bodies and hashes remain unchanged
when the new fields are omitted. See the
[candidate notes](RELEASE_NOTES.md#0212-opt-in-provider-group-checks) and
[adapter contract](../packages/ai/README.md#opt-in-provider-group-checks-source-only).

This is source preparation, not publication or host activation. The latest
verified public release remains `0.2.11`, recorded below. Before release, the
final source must pass the normal Node 22/24 format, types, complete runtime
tests, examples, release metadata, clean release-pack and consumer gates,
configured review and CI, then the protected signed-tag/OIDC workflow in this
guide. Unpublished candidate archives are not production dependencies. Actual
group privacy, endpoint/price eligibility, wire/model/tokenizer qualification,
native accounting, model quality and each host's deployment and activation
gates remain separate. Historical receipts, anchors and release policy below
remain unchanged.

<a id="verified-0211-publication-2026-11-14"></a>

## Verified 0.2.11 publication: 2026-11-14
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"@pegma/spine": "0.1.2",
"@pegma/storage-azure-tables": "0.4.0",
"@pegma/storage-core": "0.4.0",
"@pegma/support-desk-ai": "0.2.11",
"@pegma/support-desk-application": "0.2.11",
"@pegma/support-desk-templates": "0.2.11",
"@pegma/support-desk-ai": "0.2.12",
"@pegma/support-desk-application": "0.2.12",
"@pegma/support-desk-templates": "0.2.12",
"@types/node": "^26.6.6",
"azurite": "^3.37.0",
"prettier": "^3.9.10",
Expand Down
55 changes: 55 additions & 0 deletions packages/ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,61 @@ written. Expiry redaction removes request text and retains the attempt and its
proof reservation. Retain these finite limits in host scheduling and funding
plans.

### Opt-in provider-group checks (source only)

The source addition permits an explicitly approved provider group for learning
and engineering independent checks. It is not part of the published `0.2.11`
contract. Structural support does not activate a host or authorize a live call.
Answering and generation routes retain their existing policies; the release
follow-up checker refuses group mode before funding.

The host must set `providerSelectionScope: "provider_group"` in all three places:
the independent-check route, its matching static allowlist entry, and
`route.approval`. The route also requires
`providerMaxPrice: { prompt, completion, request: 0 }`. Group `endpointTag` is a
bare base-provider slug, such as `azure`, rather than a region-suffixed selector.
Leaving the new property keys absent preserves the existing selector policy,
refusals, request body and route-policy hashes; there is no inferred group or
default. A present key whose value is `undefined` is not absent: verified routes
refuse it before credentials or admission, including after schema parsing.
Optional authoring types can represent that incomplete object, but verification
still fails closed. Omit unused keys entirely; conditional spreads should add
no group keys when disabled rather than assigning `undefined`.

Build the complete new route base and calculate
`independentCheckRoutePolicyHash(base)` before obtaining fresh Admin-approved
evidence. The scope and price object participate in that hash;
`approval.requestPolicySha256` must match it and the approval's scope must match
the route and allowlist. An old exact-route approval cannot authorize a group
route. Requalify the actual wire, model, token counter, response identity and
provider-group privacy evidence before returning ready configuration.

OpenRouter's [base-slug matching](https://openrouter.ai/docs/guides/routing/provider-selection#base-slug-matching)
can include eligible variants and regions. Selecting `azure` therefore does
not guarantee Sweden, another particular region or a previously observed
endpoint. Approve the actual group scope rather than reusing an exact regional
attestation. The request still restricts `provider.only` to that group with
`allow_fallbacks: false`, `zdr: true`, `data_collection: "deny"` and
`require_parameters: true`. No other provider or retention-mode fallback is
enabled. Existing verified controls keep SafetyRetention, input/output logging
and use, broadcast and response caching off; current evidence, expiry and
implicit-cache approval checks still apply.

The group's `providerMaxPrice` is serialized as `provider.max_price`.
OpenRouter's [price filter](https://openrouter.ai/docs/guides/routing/provider-selection#max-price)
uses USD per **million** text tokens for `prompt` and `completion`;
`request` is a separate per-request price ceiling. This mode requires and sends
`request: 0`; actual provider eligibility and enforcement still need live
qualification. Missing request-price metadata is not proof of zero charges.
The host must review eligible endpoint metadata and non-token charges before
admission under its current verified features, exceptions and evaluation
references; the SDK adds no metadata network port. These unit-price ceilings do
not replace `maxCostMicros`, token limits, durable reservation/spending caps or
actual native-charge accounting.
Unknown or over-limit native usage remains conservatively held, never recorded
as free or retried automatically. SDK qualification and publication, then each
host's current privacy, evaluation and activation gates, remain separate.

### Release follow-up provider ports

Published `0.2.9` adds `createSupportReleaseFollowupModel(options,
Expand Down
4 changes: 2 additions & 2 deletions packages/ai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pegma/support-desk-ai",
"version": "0.2.11",
"version": "0.2.12",
"description": "Optional bounded, provider-neutral Support Desk answer coordinator.",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -42,7 +42,7 @@
"@pegma/knowledge-base-application": "0.1.8",
"@pegma/knowledge-base-contracts": "0.1.8",
"@pegma/spine": "0.1.2",
"@pegma/support-desk-application": "0.2.11",
"@pegma/support-desk-application": "0.2.12",
"@pegma/storage-core": "0.4.0",
"zod": "4.6.7"
}
Expand Down
98 changes: 98 additions & 0 deletions packages/ai/src/openrouter/provider-selection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { z } from "zod";

/** Provider pricing filters, not a total-request budget. The host must verify
* eligible metadata and non-token charges; missing pricing is not zero. */
export const providerMaxPrice = z
.object({
/** USD per million text input tokens. */
prompt: z.number().finite().nonnegative().max(Number.MAX_SAFE_INTEGER),
/** USD per million billed completion tokens, including reasoning. */
completion: z.number().finite().nonnegative().max(Number.MAX_SAFE_INTEGER),
/** No per-request charge is approved. This filter is not metadata proof. */
request: z.literal(0),
})
.strict();

export type SupportProviderMaxPrice = z.infer<typeof providerMaxPrice>;

interface Selection {
readonly endpointTag: string;
readonly providerSelectionScope?: "provider_group" | undefined;
readonly providerMaxPrice?: SupportProviderMaxPrice | undefined;
readonly approval: {
readonly providerSelectionScope?: "provider_group" | undefined;
};
}

interface PriceBudget {
readonly maxInputTokens: number;
readonly maxOutputTokens: number;
readonly maxCostMicros: number;
readonly currency: string;
}

function decimal(value: number): { digits: bigint; scale: number } {
const [mantissa, exponent = "0"] = value.toString().split("e");
const [whole, fraction = ""] = mantissa!.split(".");
return {
digits: BigInt(whole! + fraction),
scale: fraction.length - Number(exponent),
};
}

/** Token price USD/million is numerically microUSD/token. Add exact decimal
* terms before rounding once; binary multiplication must not lower the bound. */
function fitsPriceBudget(price: SupportProviderMaxPrice, budget: PriceBudget) {
if (
budget.currency !== "USD" ||
!Number.isSafeInteger(budget.maxInputTokens) ||
budget.maxInputTokens < 1 ||
!Number.isSafeInteger(budget.maxOutputTokens) ||
budget.maxOutputTokens < 1 ||
!Number.isSafeInteger(budget.maxCostMicros) ||
budget.maxCostMicros < 0
)
return false;
const prompt = decimal(price.prompt);
const completion = decimal(price.completion);
const scale = Math.max(0, prompt.scale, completion.scale);
const denominator = 10n ** BigInt(scale);
const numerator =
BigInt(budget.maxInputTokens) *
prompt.digits *
10n ** BigInt(scale - prompt.scale) +
BigInt(budget.maxOutputTokens) *
completion.digits *
10n ** BigInt(scale - completion.scale);
const micros = (numerator + denominator - 1n) / denominator;
return micros <= BigInt(budget.maxCostMicros);
}

/** New policy is opt-in. Absence means no own property, not a property set to
* undefined. Incomplete policy objects fail closed even when authoring types
* can describe them. Truly absent keys add no wire property and retain the
* generic transport's existing selector contract. */
export function selectedProviderMaxPrice(
route: Selection,
budget: PriceBudget,
allowProviderGroup: boolean,
): SupportProviderMaxPrice | undefined {
const scoped = Object.hasOwn(route, "providerSelectionScope");
Comment thread
FlyOverCoderKY marked this conversation as resolved.
Resolved
const priced = Object.hasOwn(route, "providerMaxPrice");
const approved = Object.hasOwn(route.approval, "providerSelectionScope");
if (!scoped && !priced && !approved) return undefined;
if (
!allowProviderGroup ||
!scoped ||
!priced ||
!approved ||
route.providerSelectionScope !== "provider_group" ||
route.approval.providerSelectionScope !== "provider_group" ||
!/^[a-z0-9-]+$/u.test(route.endpointTag)
)
throw new TypeError("Provider-group policy unavailable");
const price = providerMaxPrice.parse(route.providerMaxPrice);
if (!fitsPriceBudget(price, budget))
throw new TypeError("Provider-group price exceeds total budget");
return price;
}
Loading
Loading