MAP Docs
SDKs

TypeScript

@l1fe/mind-wm and the MapClient family. Node 20+ / Bun 1.1+. Zod-validated payloads.

The TypeScript SDK lives in /Volumes/L1feAI/l1feosx/map/sdks/typescript/. The primary package is @l1fe/mind-wm; it bundles the general MapClient for dispatch and specialized clients for MIND (working memory, beliefs) and the common protocols.

Install

bun add @l1fe/mind-wm
# or
npm install @l1fe/mind-wm

Peer requirements:

  • Node 20+ or Bun 1.1+
  • A fetch implementation (built-in on both runtimes)

MapClient

import { MapClient } from '@l1fe/mind-wm/map';

const map = new MapClient({
  apiUrl: process.env.MAP_API_URL ?? 'https://api.multiagentic.dev',
  apiKey: process.env.MAP_API_KEY!,
  agentDid: process.env.MAP_AGENT_DID!,
  tenantId: 'org_acme'
});

const response = await map.dispatch({
  protocol:  'MARC',
  version:   'v1.0.0',
  operation: 'reasoning_task',
  input: {
    intent: 'is the treaty enforceable?',
    budget: { tokens: 8000, deadline_ms: 12000 }
  }
});

console.log(response.data, response.metadata);

MindWmClient

Working-memory bridge — feature-gated on the engine side (wm-bridge feature) and exposed only when bound to a real MIND backend.

import { MindWmClient } from '@l1fe/mind-wm';

const wm = new MindWmClient({
  apiUrl: process.env.MAP_API_URL!,
  capabilityProof: {
    agent_did: process.env.MAP_AGENT_DID!,
    capabilities: ['map.mind.wm.bridge']
  }
});

// Add a working-memory event
await wm.add({
  slot: 'visual.focus',
  payload: { kind: 'object', ref: 'mars://asset/0x...' },
  ts_ms: Date.now()
});

// Set focus
await wm.set_focus({ slot: 'visual.focus' });

// Query
const result = await wm.query({
  slot: 'visual.*',
  since_ms: Date.now() - 60_000,
  limit: 100
});

// Snapshot
const snap = await wm.snapshot();

Types

export type CapabilityProof = {
  agent_did: string;
  capabilities: string[];
};

export type SlotPath = string;  // dotted, supports wildcards

export type WorkingMemoryEvent = {
  slot: SlotPath;
  payload: unknown;
  ts_ms: number;
};

export type QueryRequest = {
  slot: SlotPath;
  since_ms?: number;
  until_ms?: number;
  limit?: number;
};

export type QueryResult = {
  events: WorkingMemoryEvent[];
  truncated: boolean;
};

export type Snapshot = {
  taken_at: number;
  slots: Record<SlotPath, unknown>;
};

Errors

import { MindWmError } from '@l1fe/mind-wm';

try {
  await wm.add(...);
} catch (err) {
  if (err instanceof MindWmError) {
    console.error(err.code, err.message, err.status);
    // err.code is one of: 'capability_denied' | 'invalid_payload' | 'rate_limited' | 'timeout' | 'internal'
  }
}

Validation

All payloads are validated with Zod at the SDK boundary. Type inference is shipped — your IDE shows the exact shape of every input and output:

import { ReasoningTaskInput, ReasoningTaskOutput } from '@l1fe/mind-wm/marc';

// Compile-time check; runtime validation runs automatically:
const input: ReasoningTaskInput = {
  intent: 'is the treaty enforceable?',
  budget: { tokens: 8000, deadline_ms: 12000 }
};

const output: ReasoningTaskOutput = await marc.reasoning_task(input);

If a payload doesn't match the schema, ZodError is thrown before the request is sent.

Retry & backoff

const map = new MapClient({
  ...,
  retry: {
    maxRetries: 3,
    onRateLimit: 'respect-header',  // honor Retry-After
    onCircuitOpen: { strategy: 'exponential', baseMs: 100, maxMs: 30_000 }
  }
});

Only idempotent operations retry. State-changing operations (writes) never auto-retry — build idempotency keys into your application.

Trace propagation

import { trace } from '@opentelemetry/api';

const span = trace.getActiveSpan();
const response = await map.dispatch(...).withSpan(span);

Or supply explicitly:

const response = await map.dispatch(...).withTraceparent('00-4f81b3a...-...-01');

Bun-specific

Bun's native fetch is used by default. To use a custom fetch (e.g. for proxy), pass it in:

const map = new MapClient({ ..., fetch: customFetch });

Bun's fetch supports HTTP/2 out of the box, so latency on dispatch is typically lower than Node 20 (which uses undici).

Cloudflare Workers

The SDK works in Cloudflare Workers — pass an explicit fetch:

import { MapClient } from '@l1fe/mind-wm/map';

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const map = new MapClient({
      apiUrl: env.MAP_API_URL,
      apiKey: env.MAP_API_KEY,
      agentDid: env.MAP_AGENT_DID,
      tenantId: 'org_acme',
      fetch: globalThis.fetch
    });
    const r = await map.dispatch(...);
    return Response.json(r.data);
  }
};

SSL/TLS is handled by the runtime. No certificate handling required.

See also

On this page