Releases: Hilbras/Hilbras-ai-sdk
Release list
v0.9.3: Hardening — 6 P0 fixes, SSRF guard, streaming budget, error redaction
What's new
Hardening release closing all 6 P0 defects from the v0.9.2 audit. 820 → 878 passing tests, no breaking API changes.
Fixed (P0)
_totalEstimatedgrew monotonically forever —BudgetTracker.release()now decrements_totalEstimatedalongside_totalReserved.settle()correctly preserves the estimate (it has committed to actual).stream()was not budget-enforced —client.stream()now reserves before the retry loop, settles on the firstusagechunk, settles at end-of-stream if no usage chunk arrived, and releases on abort/throw/fallback. The v0.9.0 "Hard Budget Enforcement" headline now actually covers streams.ProviderRequestErrorechoed raw provider error bodies, leaking API keys — constructor now redactssk-…,sk-proj-…,sk-ant-…,Bearer …, and JSON secret fields.- No SSRF protection on
baseUrl—addProvider()now validates throughvalidateBaseUrl(). Default rejectshttp://; loopback is always allowed whenallowInsecure: true; private network ranges requireallowPrivateNetwork: true. AWS instance metadata is always blocked. - Budget callback order was inverted —
onBudgetWarningnow fires beforeonBudgetExceededwhen a singlesettle()crosses 100%. extractJsoncould return garbage on truncated input — fallback now scans forward looking for a balanced, JSON.parse-valid substring.
Added
src/security/url-guard.tswithvalidateBaseUrl(url, opts)exported from the public API- 58 new tests (820 → 878)
- New test files:
tests/security/url-guard.test.ts(27),tests/security/ssrf-integration.test.ts(8) allowInsecure?: booleanfield onProviderConfigallowInsecureUrls?: booleanandallowPrivateNetwork?: booleanonHilbrasClientConfigConfigurationErroris now used at the budget-rejection paths in bothstream()andcomplete()redact()exported fromsrc/logging/logger.ts
Documentation
README.mdrewritten as a clean landing page with feature matrix and links- New docs:
docs/security.md,docs/cost-and-budget.md,docs/providers.md,docs/observability.md - Removed:
docs/STRATEGY.md,docs/EXECUTION-ENGINE-THESIS.md, old v0.1→v0.2 and v0.2→v0.3 migration files CHANGELOG.mdupdated with v0.9.3 entrypackage.json: added keywords, homepage, repository, bugs fields for npm search discoverability
Verification
npm run build— cleannpm test— 878/878 passing- No breaking changes; all 820 pre-existing tests pass without modification
Risk
Low. The hardening changes are surgical and additive. The only non-additive change is the SSRF guard default behavior (http:// rejected). Ollama users get allowInsecure: true to opt back in. AWS metadata was previously reachable through misconfiguration; that path is now closed even with allowInsecure.
Follow-ups (separate PRs)
- v0.10.0-PR-1: God-file refactor (
RequestPipelineextraction) - v0.10.0-PR-2: API surface cleanup (wire
sdkLogger, dead-code removal, merge twoProviderConfigtypes) - v0.10.0-PR-3: Circuit-breaker scoping (per-client registry)
- v0.10.0-PR-4:
SDKConfigwiring (new HilbrasClient({ sdkConfig })actually works) - v0.10.0-PR-5: README architecture diagram refresh
v0.9.2 — Duplicate Reservation ID Fix
v0.9.2 — Reservation Identity & Accounting Integrity Patch
🐛 Bug Fixed
Duplicate reservation IDs could silently overwrite active reservations.
Previously:
reserve("r1", 0.50) → Map["r1"] = 0.50, _totalReserved += 0.50
reserve("r1", 0.25) → Map["r1"] = 0.25, _totalReserved += 0.25
// Result: Map has 0.25, but _totalReserved = 0.75
// The 0.50 reservation is orphaned — cannot be settled or released
Now: reserve() rejects duplicate IDs, preserving accounting integrity.
🛡️ Regression Tests
11 new tests covering:
- Duplicate ID rejection (returns null)
- No modification to existing reservation amount
- No increase in totalReserved
- Release/settle after rejected duplicate
- Repeated duplicate attempts (100×)
- Duplicate IDs under concurrency (1000 calls)
- Random collision scenarios (1000 iterations, 4-ID pool)
- Reserve after settle/release frees the ID
- Client-generated IDs are verified unique
772 Tests Passing
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.9.1 — Reservation Accounting Audit
v0.9.1 — Hard Budget Enforcement Audit
🐛 Bugs Found & Fixed (3 real production bugs)
| Bug | Severity | Root Cause | Fix |
|---|---|---|---|
reserve() accepted NaN amounts |
HIGH | NaN < 0 is false, bypassed guard |
Added !Number.isFinite() check |
settle() with negative/NaN cost corrupted totals |
HIGH | No input validation on actualCost |
Clamps negative/NaN to 0, Infinity to session budget |
settle() with Infinity didn't exhaust budget |
MEDIUM | Math.max(0, Infinity) = Infinity but isBudgetExhausted used >= which Infinity satisfies, yet Infinity wasn't clamped |
Now correctly caps Infinity at session budget |
🛡️ 55 Adversarial Reservation Tests
| Area | Tests |
|---|---|
| Lifecycle (reserve→settle, reserve→release) | 2 |
| Double settlement/release safety | 5 |
| Settle after release / release after settle | 2 |
| Reservation ID collision | 3 |
| Negative/NaN/Infinity amounts | 4 |
| Over-settlement (actual > reserved) | 3 |
| Under-settlement with random cycles | 2 |
| Concurrent reservations (1000+ calls) | 5 |
| Floating point attacks | 3 |
| Retry accounting | 2 |
| Fallback accounting | 1 |
| Client isolation | 2 |
| Memory safety (leak prevention) | 3 |
| Security (no secrets) | 2 |
| API abuse (rapid cycles) | 3 |
| Cost report reconciliation | 4 |
| Fuzz testing (1000 scenarios) | 1 |
| Performance (100K+ ops) | 2 |
| Callback safety | 2 |
731 Tests Passing
55 new adversarial tests added (676 → 731 total).
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.9.0 — Hard Budget Enforcement
v0.9.0 — Hard Budget Enforcement & Atomic Cost Control
💰 The Problem v0.8.x Had
v0.8.x tracked costs but had a check-then-act race under concurrency:
sessionBudget = $1.00
Request A: checks remaining = $0.60 → allowed
Request B: checks remaining = $0.60 → allowed
Both execute. Total = $1.20. Budget violated.
🔒 The v0.9.0 Solution
Atomic Reservation System — check + reserve happens synchronously in one event loop tick:
Request A: reserve $0.60 → ✅ committed $0.60
Request B: reserve $0.60 → ❌ rejected (only $0.40 available)
How It Works
const client = new HilbrasClient({
budget: {
sessionBudget: 1.00,
perRequestBudget: 0.10,
},
});
// Reservation lifecycle: RESERVE → EXECUTE → SETTLE/RELEASE
const reservation = client.cost.reserve("req_1", 0.60);
if (!reservation) throw new Error("Budget exceeded");
// After execution:
client.cost.settle("req_1", 0.45); // actual < reserved → refund $0.15
// Or on failure:
client.cost.release("req_1"); // free the reservationCommitted Cost Tracking
const report = client.costReport();
report.totalReserved; // Pending reservations
report.committedCost; // actual + reserved
report.remainingBudget; // sessionBudget - committedWhat's New
| Feature | Description |
|---|---|
| Atomic reservation | Synchronous check+reserve (JS event loop safe) |
| Committed cost | actual + reserved = true spending ceiling |
| Reservation lifecycle | reserve → settle (actual cost) or release (failure) |
| Over-reservation | Actual > reserved is allowed (settles to actual) |
| Under-reservation | Unused budget returns to available pool |
| No leaked reservations | Guaranteed after terminal execution |
| Backward compatible | record() API still works |
676 Tests Passing
36 new reservation tests covering lifecycle, concurrency, integrity, adversarial, and invariants.
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.8.1 — Cost & Budget Safety Audit
v0.8.1 — Cost & Budget Safety Audit
🐛 Bugs Found & Fixed
| Bug | Severity | Fix |
|---|---|---|
estimateCost() produced negative cost with negative token counts |
MEDIUM | Added Math.max(0, ...) guard |
BudgetTracker callbacks not wrapped in try/catch — throwing callback corrupted budget accounting |
HIGH | Wrapped in try/catch (notification-only semantics) |
🛡️ 74 Deep Cost Audit Tests
| Area | Tests |
|---|---|
| Money correctness (NaN, Infinity, negative, floating point) | 10 |
| Budget boundary enforcement (exact limits) | 8 |
| Session budget enforcement | 6 |
| Per-request budget enforcement | 4 |
| Model pricing integrity | 7 |
| Estimated vs actual cost semantics | 3 |
| Callback safety | 3 |
| Cost report integrity | 5 |
| Client lifecycle | 4 |
| Router + cost integration | 3 |
| Security | 2 |
| Adversarial inputs | 7 |
| Determinism | 2 |
| Invariant testing | 7 |
7 Invariants Verified
totalActual >= 0for all valid inputstotalActualequals sum of recorded actual costsbyProvidertotals reconcile withtotalActualbyPhasetotals reconcile withtotalActualremainingBudget=sessionBudget - totalActual- No NaN in any report field
- No Infinity in any report field
640 Tests Passing
74 new audit tests added (566 → 640 total).
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.8.0 — Cost-Aware Execution
v0.8.0 — Cost-Aware Execution
💰 The Problem
AI costs are unpredictable. Developers set a model and pray. OpenAI SDK and Vercel AI SDK don't provide budget enforcement or cost tracking.
🎯 The Solution
Hilbras SDK now provides automatic cost tracking with budget enforcement:
const client = new HilbrasClient({
budget: {
sessionBudget: 1.00, // Max total cost for the session
perRequestBudget: 0.10, // Max cost per individual request
onBudgetWarning: (report) => console.warn(`80% budget used`),
onBudgetExceeded: (report) => console.error(`Budget exhausted`),
},
});
// After requests — full cost visibility
const report = client.costReport();
console.log(`Total spent: $${report.totalActual}`);
console.log(`By provider:`, report.byProvider);What's Included
- BudgetTracker — session and per-request budget enforcement
- Cost lifecycle — estimate → execute → actual tracking
- Budget callbacks — warning at 80%, exceeded at 100%
- Cost reporting — by provider, by phase, remaining budget
- Zero overhead — no cost when budget not configured
- Backward compatible — existing code works unchanged
How It Differentiates
| Capability | OpenAI SDK | Vercel AI SDK | Hilbras SDK |
|---|---|---|---|
| Provider abstraction | OpenAI only | Multi-provider | Multi-provider |
| Model routing | None | Basic | 9-dimension scoring |
| Structured output | Limited | Limited | Schema + auto-repair |
| Fallback | None | None | Automatic, policy-driven |
| Budget enforcement | None | None | Session + per-request |
| Cost tracking | None | None | Full lifecycle |
| Cost reporting | None | None | By provider, by phase |
| Execution policies | None | None | 5 presets + custom |
| Observability | Limited | Limited | 9 lifecycle events |
566 Tests Passing
29 new tests covering BudgetTracker, cost enforcement, client integration, concurrency, and adversarial inputs.
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.7.1 — Execution Security & Deep Audit
v0.7.1 — Execution Security, Reliability & Deep Audit
PATCH CERTIFIED — Hardening of the v0.7.0 execution optimization layer.
🛡️ Deep Audit — 78 Adversarial Tests
| Area | What was tested |
|---|---|
| Plan Consistency | plan() vs best() vs explain() produce identical results |
| Determinism | 1,000 identical evaluations, score breakdowns, candidate ordering |
| Hard Constraints | needsVision, needsTools, maxCost, minContextWindow, excludeModels |
| Cost Security | Total cost estimates, maxFallbackCost, budget alignment |
| Retry/Fallback | Independent dimensions, bounded execution |
| Infinite Loop Defense | One model, empty registry, bounded fallback list |
| Fallback Safety | Respects vision, tools, cost, context constraints |
| Provider Failures | HTTP 400-503, network errors, timeouts |
| Streaming Safety | Failure before/after first chunk, maxRetries=0 |
| Policy Isolation | Independent copies, per-request overrides |
| State Isolation | Separate clients, provider removal |
| Observability | Event ordering, requestId consistency, listener safety |
| Security | API keys not in errors/routing/execution plans |
| Prompt Injection | Malicious task strings handled safely |
| Plan Immutability | Mutating plan doesn't affect router |
| Backward Compat | Explicit provider+model still works |
Finding
Circuit breaker state leaks between independent test runs — the global CircuitBreakerRegistry singleton accumulates failures across test cases. Tests now disable circuit breakers via policy when testing error paths. This is a test infrastructure concern, not a production bug.
500 Tests Passing
78 new audit tests added (422 → 500 total).
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.7.0 — Execution Optimization
v0.7.0 — Execution Optimization
🧠 Execution Plan
New plan() method returns the full execution decision:
const plan = client.plan({ task: "coding", messages, policy: { allowFallback: true } });
console.log(plan.primary.model); // Best model
console.log(plan.estimatedTotalCost); // Primary + retry + repair estimate
console.log(plan.fallbacks); // Alternative models📊 9-Dimension Scoring
Enhanced explainability with detailed score breakdown:
result.scoreBreakdown = {
capabilityFit: 83, taskFit: 95, contextFit: 80,
costEfficiency: 70, latency: 65, budgetAlignment: 75,
providerPreference: 5, structuredOutputFit: 0, toolFit: 10,
finalScore: 82.4
}⬇️ Automatic Fallback
Policy-driven model fallback on failure:
await client.complete({
task: "coding",
messages,
policy: { allowFallback: true, maxCost: 0.05 },
});Fallback respects all constraints — capabilities, cost, budget, context.
📡 Fallback Observability
client.on("fallback.started", (event) => {
console.log(`Falling back: ${event.originalModel} → ${event.fallbackModel}`);
});422 Tests Passing
31 new tests covering execution plan, scoring, fallback, determinism, and adversarial inputs.
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.6.2 — Provider Contract Certification
v0.6.2 — Provider Contract & Integration Certification
🐛 Bug Fixed
OpenAI adapter complete() crash on non-JSON responses — res.json() on non-JSON body threw SyntaxError. Now gracefully returns empty string.
🔌 Provider Contract Certified
116 contract tests verify that every adapter produces consistent canonical output:
| What was tested | How many tests |
|---|---|
| AIProvider contract compliance | 12 |
| Canonical response (complete) | 8 |
| Canonical response (stream) | 3 |
| complete() errors across all 6 providers | 18 |
| complete() edge cases | 3 |
| stream() errors across all 6 providers | 12 |
| Tool calling (native + text-embedded + malformed) | 4 |
| Error normalization (status, provider, body) | 18 |
| Timeout behavior (complete + stream) | 12 |
| Malformed/adversarial responses | 4 |
| Provider isolation | 2 |
| Failure injection (HTTP 400-503) | 20 |
Provider Matrix
| Provider | complete() | stream() | Tools | Errors | Timeout | Status |
|---|---|---|---|---|---|---|
| OpenAI | ✅ PASS | ✅ PASS | ✅ PASS | ✅ PASS | ✅ PASS | ✅ |
| Anthropic | ✅ PASS | ✅ PASS | ✅ PASS | ✅ PASS | ✅ PASS | ✅ |
| Google GenAI | ✅ PASS | ✅ PASS | — | ✅ PASS | ✅ PASS | ✅ |
| Azure | ✅ PASS | ✅ PASS | — | ✅ PASS | ✅ PASS | ✅ |
| Groq | ✅ PASS | ✅ PASS | — | ✅ PASS | ✅ PASS | ✅ |
| Ollama | ✅ PASS | ✅ PASS | — | ✅ PASS | ✅ PASS | ✅ |
391 Tests Passing
116 new contract tests added (275 → 391 total).
Package Verified
- 183 files
- 93.5 kB compressed
- Zero runtime dependencies
- Clean install verified from tarball
- All subpath imports resolve
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md
v0.6.1 — Production Audit & Bug Fix
v0.6.1 — Production Audit & Bug Fix
🐛 Bug Fixed
Router crash on invalid task type — passing an unknown string as task caused:
TypeError: Cannot read properties of undefined (reading 'reasoning')
Now gracefully falls back to TASK_WEIGHTS.general.
🧪 69 Production Audit Tests
Full adversarial test suite covering every phase of the audit spec:
| Phase | What was tested |
|---|---|
| Client Edge Cases | Missing provider/model, empty messages, dispose |
| Router Destruction | maxCost=0, exclude all, contradictory requirements |
| Scoring Audit | NaN/Infinity checks, bounds, hard > soft |
| Structured Output | Empty/null/BOM/escaped/nested JSON |
| Schema Safety | Throwing validators, missing safeParse |
| Observability | Listener errors don't break SDK |
| Concurrency | 10 concurrent requests, state isolation |
| Security | API key not in errors, injection |
| Fuzz Testing | Extreme values, negative budgets |
| Policy Safety | Independent copies (no mutation) |
| State Isolation | Separate clients, provider removal |
✅ Clean Install Verified
- Package installs from tarball ✓
- All imports resolve ✓
- Zero runtime dependencies ✓
- No test files shipped ✓
275 Tests Passing
69 new adversarial tests added (206 → 275 total).
Changelog: https://github.com/Hilbras/Hilbras-ai-sdk/blob/main/CHANGELOG.md