JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1403
  • Score
    100M100P100Q87926F
  • License Apache-2.0

The shared foundation of the Cendor stack: types, event bus, decimal-safe Money, price table, token counting, and instrument(). The TypeScript port of cendor.core.

Package Exports

  • @cendor/core

Readme

@cendor/core

The shared foundation of the Cendor stack — the TypeScript port of cendor.core. Types, an event bus, decimal-safe Money, an offline price table, provider-aware token counting, and instrument(). Zero orchestration; every other @cendor/* package cooperates through this.

npm i @cendor/core
# provider SDKs are optional peers — install the one(s) you use:
npm i openai @anthropic-ai/sdk

Killer example — wrap once, get cost + tokens on every call

import OpenAI from 'openai';
import { instrument, bus, LLMCall } from '@cendor/core';

const client = instrument(new OpenAI());

bus.subscribe((e) => {
  if (e instanceof LLMCall) console.log(e.model, e.usage?.totalTokens, e.cost?.toString());
});

await client.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'hello' }],
}); // → gpt-4o 152 0.000... USD

Streaming, the Responses API, Anthropic, interceptors (record/replay), and Reroute (model downgrade / message redaction) all flow through the same instrument().

Surface

Symbol Notes
instrument(client) wraps OpenAI (Chat + Responses) / Anthropic clients; idempotent; async + streaming
instrumentTool(fn) emits a ToolCall per invocation
Money, Usage, LLMCall, ToolCall the cross-language event vocabulary (events/1)
bus subscribe / unsubscribe / emit
prices estimate / models / refresh / staleness — exact Decimal, never floats (prices/1)
tokens count / method / family / register via js-tiktoken
trace(id, fn) / currentTraceId() ambient correlation (async-callback scope; inject AsyncLocalStorage via installTraceContext)
Reroute, addInterceptor, MISS pre-call interception seam used by @cendor/cassette & @cendor/acttrace

Parity & conformance

Field names map snake_case (Python) → camelCase (TS); type and error names are identical (UnknownModelError in both). Cost math, the model table, Money semantics, and token counts are verified against golden vectors generated from the Python reference — see fixtures/. Money is compared by exact decimal value.