Skip to content

You are currently viewing documentation for0.1.0-alpha.3

Saved documentation for 0.1.0-alpha.3 (npm) / 0.1.0a2 (PyPI). Interactive tools use the current release. View latest documentation.

AGINDOW SDK for Node.js

Install

Integrate runtime API drift detection and verified repair into your Node.js application. Use Node 22+ and agindow@0.1.0-alpha.3. TypeScript declarations and ESM/CommonJS entry points are included. Embedded execution needs no separate AGINDOW key; vendor credentials stay in your existing client. This is a pre-alpha package; consult the release notice for publication status.

bash
npm install agindow@0.1.0-alpha.3

Initialize

createAgindow creates an SDK instance. Start in observe mode to keep original payloads and outcomes. Await sdk.ready before guarded calls: it resolves after the loading attempt, including a failed attempt. Loading/inspection failures surface as bypass events when a call runs. Readiness does not prove detection is configured; the default selection is empty.

initialize.mts · TypeScript
import { createAgindow } from 'agindow';
const sdk = createAgindow({ mode: 'observe' });
await sdk.ready; // Wait for the loading attempt before guarding calls.

Guard an existing API call

Use Node 22.6+ for the native TypeScript run command (the SDK itself supports Node 22+). Save this complete example as orders.mts. Set API_URL to an existing HTTPS JSON order endpoint and run node --experimental-strip-types orders.mts. If it needs authentication, preserve the headers and credential handling in your existing HTTP client. Replace the function inside sdk.guard with that client call. The guarded function returns the original API value; it does not add an outcome wrapper. Label writes as operation: write. This example makes one read and has no detector selection, so a successful call normally prints an empty event list.

orders.mts · TypeScript
import { createAgindow } from 'agindow';

const sdk = createAgindow({ mode: 'observe' });
await sdk.ready;
sdk.on('drift', event => console.log('Drift:', event.verdict));

const getOrder = sdk.guard(async () => {
  const url = process.env.API_URL;
  if (!url) throw new Error('Set API_URL to your order JSON endpoint.');
  const response = await fetch(url, { signal: AbortSignal.timeout(10_000) });
  if (!response.ok) throw new Error(`API returned ${response.status}`);
  const order: unknown = await response.json();
  return order;
}, { tool: 'orders.get', operation: 'read' });

const order = await getOrder();
console.log('API result:', order);
console.log('AGINDOW events:', sdk.recent().map(event => event.type));

Inspect events

sdk.on(kind, listener) subscribes to one event kind and returns an unsubscribe callback. Register listeners before running guarded calls. sdk.recent() returns the bounded local history, with a default capacity of 100. No event is emitted merely because a call succeeded; an empty list does not prove that an API is drift-free. These records are not a durable audit archive.

events.mts · TypeScript
import { createAgindow } from 'agindow';
const sdk = createAgindow({ mode: 'observe' });
await sdk.ready;
const unsubscribe = sdk.on('drift', event => {
  console.log(event.tool, event.phase, event.verdict?.findings);
});
sdk.on('repair', event => console.log('Applied repair:', event.byte_identical));
// Subscribe before your guarded calls, then inspect the bounded local history.
console.log(sdk.recent());
unsubscribe();
EventMeaning
driftConfigured inspection reported a finding. Observe preserves the call.
repairAn accepted payload repair was actually applied.
blockedPolicy halted a request or a completed response; inspect phase and retained outcome.
bypassInspection was unavailable or skipped; the original outcome is preserved.
errorInternal diagnostic metadata, separate from the upstream result or exception.

Configure detection

Supply selection to createAgindow at construction. Its scope identifies tenant, connection, vendor, operation and segment; selection.operation must match the guarded tool, such as orders.get. Each selected field supplies request/response side, JSON Pointer path, complete baseline and current live JSON documents, and an enumeration setting. Use independent comparable windows from that operation. There is no automatic baseline learning. Missing or insufficient evidence can produce no finding; bypass is a different outcome. The complete executable guide keeps window construction out of this integration example.

Enable verified repair

Selective repair is disabled by default. The local example below models a reviewed CRM top-level rename. Its verifier compares both payloads with an independently loaded application snapshot; a schema or matching values alone cannot establish migration intent. Replace the reviewed facts and local callable with your application-specific evidence and client. Begin in observe, evaluate the rule, then permit application with repair mode. selectiveRepair requires scoped rules, confidence and a synchronous verify callback; perform no network, database or LLM work inside it. Repair requires confidence at least 0.97, strict at least 0.99, complete supported captures and independent acceptance. These thresholds do not measure real-world accuracy. A repair event confirms application; a finding or proposed patch does not. Runtime payload repair does not modify repository source or create a pull request.

repair.mts · TypeScript
import { createAgindow } from 'agindow';
import type { RepairCheck } from 'agindow';
// Reviewed application snapshot, loaded independently before the call.
const names = new Map([['customer-123', 'Ada']]);
function verify(check: RepairCheck): boolean {
  const before = JSON.parse(check.before) as Record<string, unknown>;
  const after = JSON.parse(check.after) as Record<string, unknown>;
  return check.rule.migration === 'crm-name-v2-reviewed'
    && typeof after['id'] === 'string' && names.has(after['id'])
    && before['id'] === after['id']
    && before['contact_name'] === names.get(after['id'])
    && after['display_name'] === names.get(after['id']);
}
const sdk = createAgindow({ mode: 'observe', selectiveRepair: {
  rules: [{ tool: 'crm.customer', side: 'response', from: 'contact_name',
    to: 'display_name', migration: 'crm-name-v2-reviewed', confidence: 1 }], verify,
} });
await sdk.ready;
// Local illustration of a reviewed migration, not a vendor request.
const customer = sdk.guard(() => ({ id: 'customer-123', contact_name: 'Ada' }),
  { tool: 'crm.customer', operation: 'read' });
sdk.configure({ mode: 'repair' }); // After evaluating the rule in observe.
console.log(customer());
console.log(sdk.recent().filter(event => event.type === 'repair'));

Choose an integration API

Use an explicit boundary when you know the target shape. Keep one guard boundary around the operation you own. Supported adapters do not imply complete batch, streaming or framework coverage.

APIWhen to use itExample use case
sdk.guard(fn, options)One known callable; simplest place to start.A closure around client.orders.get(id).
sdk.wrap(target, options)Automatic selection when exactly one supported shape matches.A plain callable or unambiguous tool collection.
sdk.toolAdapter(target, options)A supported tool map/array or executor.Wrap a reviewed tool collection.
sdk.clientAdapter(target, options)A supported API client; preserve method receivers.A Pipedream-style proxy client.
sdk.httpAdapter(target, options)A supported HTTP-shaped callable/object.Fetch, Axios-like methods or a supported Express boundary.
guardRemote(original, envelope, options)Explicit HTTP execution against a host you configure.A self-hosted /v1/guard with application-owned fallback.

Advanced use and API reference

Use per-call options and sdk.configure for future-call policy. sdk.simulate evaluates recordings without contacting an API. sdk.drainAudit is an explicit off-path Node-only delivery seam and requires audit configuration; it cannot be combined with selectiveRepair. Capture and streaming limits can bypass inspection. Upstream exceptions propagate; policy can throw AgindowDriftError. A response-phase halt cannot undo a completed upstream write. There is no embedded sdk.close() API in Node; close separate remote-auth sessions when finished. The shared engine is an implementation detail; callers use the published TypeScript types.