Repository navigation
Conversation
… surface Adds @starlight-intelligence/agent-runtime so apps stop re-deriving the model, tool and attribution layers by hand. Five product repos were each doing it separately, which is how model ids drifted between them, how tool exposure grew ungoverned, and how nothing in the estate ever emitted a cost record despite an accepted architecture decision requiring one. - model.ts: capability routes resolve through the Vercel AI Gateway, so Anthropic, OpenAI, Google and xAI are reachable with one key and no vendor SDK. Unknown routes fail at resolution with a named error. - tools.ts: MCP tools via the official AI SDK MCP client, plus the two controls the client leaves to the app: approval (only an explicit readOnlyHint runs unattended) and drift detection against an approved fingerprint baseline. - attribution.ts: emits the eleven dimensions the estate observability contract requires. Cost and latency come from the gateway's own accounting, never a local price table. - packages/core: adds the provider-neutral attribution types the JSON Schemas already described but never declared. Stays zero-dependency. Wired into pnpm-workspace, the release audit targets and the npm consumer check, so it publishes through the existing OIDC workflow.
frankxai
force-pushed
the
agent/opencode/provider-neutral-agent-runtime
branch
from
November 12, 2026 18:39
7590e91 to
7aa8bcc
Compare
… defects An independent Codex review of PR #577 returned FAIL. It confirmed the Gateway routing, the spacexai/ namespace and the dependency-alignment rationale, and found eight real defects. All are closed here. Release: - build:packages and test:packages omitted agent-runtime, so CI never built or tested it and pnpm pack shipped no dist/. Added to both filters. - the consumer check rewrites only ../dist/index.js, so the runtime test's subpath imports failed in the installed tarball. The tests now import the package's public entry point, which is also the better boundary. - the foundry lock pinned digests of pnpm-lock.yaml and package.json, both of which this change modifies. Refreshed, as the lock's own updatePolicy requires a reviewed pull request. Safety: - requiresApproval accepted an omitted openWorldHint as closed-domain. The MCP spec defines openWorldHint's default as TRUE, so an omitted hint now means open-world and needs a human. - the drift guard was skipped whenever no baseline was supplied, so a forgotten baseline silently disabled it. A baseline is now required unless the caller opts out explicitly, and that state is reported. - redaction cleaned only provider, model, agent_id and workflow_id, so a credential in brand_id or product_id survived. Every string field is cleaned now, and the bearer pattern covers the full base64url alphabet. Correctness: - an explicit route validated only the id's syntax, so an unrouted vendor resolved successfully. The namespace is now checked at resolution. - vendorOf read inherited object properties, so 'constructor/model' resolved to a function. It is an own-property lookup now. - a multi-step run reported only its last generation's cost, and every run was recorded as completed. Calls are accumulated and the terminal state is taken from onEnd/onAbort/onError. - a failed gateway lookup substituted a zero cost, indistinguishable from a free generation. Such a record now carries cost_known: false. - tools were cast to Record<string, never>, suppressing type checking at the public boundary. They are typed as the SDK's ToolSet now. Tests: 19 in the package (up from 14), each able to fail against the defective behaviour.
…le defects A second independent Codex review of PR #577 returned FAIL: the first review's finding 8 was still open, and the fixes had introduced defects of their own. All are closed here. Attribution: - a multi-step run was costed from its LAST generation alone. A run whose steps cost USD 0.10 and USD 0.20 was reported as USD 0.20. The run's cost is now the sum of every generation, and the Gateway token counts are summed the same way. - cost_known was emitted only on the failure path, so a successfully priced generation was indistinguishable from an unpriced one. It is now emitted on both paths, and a partly priced run is a lower bound, not a known total. - the Gateway response type was re-declared locally and cast. It now comes from the SDK own signature, so a field this module reads cannot drift from the field the Gateway returns. Lifecycle: - run state was allocated once per runtime, so a second run inherited the first run tokens and a failure survived into the next run. onStart fires exactly once per run and now starts a fresh accumulator. - every run was recorded as completed. The terminal state now comes from onEnd, onError and onAbort. - a run that failed before its first model call produced no record. It now produces a failed record, because it happened. - two overlapping runs on one runtime cannot be attributed. The runtime says so rather than reporting a blended number. Tools: - the approval reason said a tool was "not read-only" even when it was read-only but open-world. It now names the condition that triggered it. - the drift policy was inline in loadMcpTools and untested. It is now applyToolReviewPolicy, with the missing-baseline refusal, the explicit opt-out, and the added-tool case each covered. Evidence and claims: - the vendor test asserted constants against identical constants. It now checks the Gateway live catalog, and scripts/verify-gateway-models.mjs checks that the estate ids are served. - the README example supplied MCP servers without a baseline, so it now rejects. It carries a baseline, and says what to do without one. - the README and ADR claimed the MCP client handles "session reattach". The installed client does not; it does protocol negotiation, header mirroring and elicitation. Both documents now say that. - the ADR claimed core gains the types its JSON Schemas already describe. Those schemas describe different shapes. The ADR now says what was added. - the ADR code example used a route and scope shape that does not exist. Tests: 42 in the package, up from 19. Each new test can fail against the defective behaviour.
Collaborator
Author
|
Cross-stream integration handoff: https://github.com/frankxai/agentic-ops/pull/608, head d921dd5ef8058d63eef062f6563aa9ef948e17a1. Keep this PR as runtime owner. Before hosted execution integration: bind trusted tenant/workspace/principal, reuse web job/ticket/admission + atomic reservation; preserve protected API containment. Current USD attribution is not the existing EUR run-receipt schema: retain original currency and explicit conversion provenance, unknown cost stays unknown. Shared synthetic binding tests are in the integration PR; native runtime/crypto/live tests remain required. This is coordination, not approval or a permission grant. |
Committed by storage maintenance so this work exists on a remote instead of only on one laptop. Not reviewed, not merged. Branch preserved.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
@starlight-intelligence/agent-runtime: one provider-neutral runtime so the estate stops re-deriving the model, tool and attribution layers by hand in every app.Five product repos were each doing this separately. That is how model ids drifted between them, how tool exposure grew ungoverned, and how nothing in the estate ever emitted a cost record despite an accepted architecture decision requiring one.
model.ts— provider-neutral routingA route names a capability, not a vendor SDK call. It resolves through the Vercel AI Gateway, so Anthropic, OpenAI, Google and xAI are all reachable with one key and zero vendor-specific dependencies.
anthropic/claude-opus-5.5openai/gpt-6-astragoogle/gemini-4-argonspacexai/grok-4.7Note the
spacexai/prefix on Grok: it is notxai/. An unknown route fails at resolution with a named error rather than at call time as an opaque provider failure.tools.ts— MCP tools with the two controls the client leaves to the app@ai-sdk/mcpalready handles what three estate repos re-implemented by hand: 2026-07-28 discovery with legacy fallback,Mcp-Param-*header mirroring, elicitation, session reattach. What it does not do is decide whether a tool may run, or notice a server changed a tool after approval. This package supplies both:readOnlyHint: trueruns unattended; a destructive or open-world tool never does, whatever the hint claims.fingerprintToolsanddetectToolDriftdetect a server that mutated a tool's description or schema after a human approved it. Drifted tools are refused before they reach the model.Tool exposure is bounded by an explicit allowlist. There is no implicit "allow everything".
attribution.ts— the contract nothing emittedEvery run produces a record carrying the eleven dimensions the estate's
architecture_observability_and_cost_contractrequires:brand_id,product_id,agent_id,workflow_id,provider,model,input_tokens,output_tokens,estimated_cost,latency_ms,outcome_status.Cost and latency come from the gateway's own accounting for the generation, not from a local price table. A price table goes stale the day a vendor changes pricing and then quietly reports the wrong number, which is worse than reporting nothing.
Records are validated before they leave the process and passed through a credential redactor, because they are meant to be committed or shipped to a ledger.
packages/core— the types the JSON Schemas never declaredpackages/core/schemas/cost-record.schema.jsonandagent-run.schema.jsonalready described these shapes, butpackages/core/srchad no TypeScript declaration for them and no producer anywhere in the estate emitted one. The provider-neutral attribution types now live there.packages/corestays zero-dependency, which the release audit enforces.Evidence
packages/agent-runtime: 14 tests, 14 passnpm-artifact-audit,npm-ecosystem-release): 26 tests, 26 passtscbuild: clean understrictwithnoUnusedLocalsWired into
pnpm-workspace.yaml, the release audittargetsand the npm consumer check, so it publishes through the existing OIDC workflow rather than a new mechanism.Boundaries
Review notes
anthropic/claude-sonnet-5.5; that is a judgement call worth overriding if you prefer a different default.aiis pinned to7.0.170in devDependencies because that is the version whose@ai-sdk/provider-utilsmatches@ai-sdk/mcp@2.0.97. Two copies ofprovider-utilsproduce incompatible nominalSchematypes and a compile error that a cast would have hidden.docs/architecture/ADR-2026-11-12-provider-neutral-agent-runtime.mdrecords the alternatives compared, including@arcanea/model-runtime, and why this one wins.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.