@aimf/shared

v0.1.1

Published

Shared utilities, types, and constants for AIMF

Downloads

456

Readme

@aimf/shared

Core utilities, types, and constants for the AI-MCP Framework (AIMF).

Installation

pnpm add @aimf/shared

Usage

Types

import type { 
  // NCP Protocol
  NcpRequest, 
  NcpResponse, 
  NcpEnvelope,
  NcpEndpoint,
  
  // Storage
  StorageRecord,
  NeuralHash,
  MerkleProof,
  VerificationResult,
  
  // Security
  ZtniIdentity,
  AuthRequest,
  AuthResponse,
  
  // Events
  NeuralEvent,
  EventSubscription,
  
  // Manifest
  NeuralManifest,
} from "@aimf/shared";

const request: NcpRequest = {
  jsonrpc: "2.0",
  id: "1",
  method: "neural.store",
  params: { content: "Hello, World!" },
};

Error Handling

import { AimfError, ErrorCode } from "@aimf/shared";

throw new AimfError(
  ErrorCode.VALIDATION_ERROR,
  "Invalid input",
  { field: "name" }
);

Utilities

import { 
  generateId, 
  computeHash, 
  isNcpRequest,
  encodeBase64,
  decodeBase64,
  encodeFloat32Array,
  decodeFloat32Array,
} from "@aimf/shared";

const id = generateId();
const hash = computeHash("content");
const isValid = isNcpRequest(message);

// Encode/decode embeddings
const embedding = new Float32Array([0.1, 0.2, 0.3]);
const encoded = encodeFloat32Array(embedding);
const decoded = decodeFloat32Array(encoded);

Constants

import { NCP_METHODS, DEFAULT_TIMEOUTS } from "@aimf/shared";

console.log(NCP_METHODS.STORE); // "neural.store"
console.log(DEFAULT_TIMEOUTS.REQUEST); // 30000

Type Categories

NCP Protocol Types

  • NcpRequest, NcpResponse, NcpNotification - JSON-RPC 2.0 messages
  • NcpEnvelope - Enterprise message wrapper with neural verification
  • NcpEndpoint, NcpHop - Routing types
  • NcpTransportConfig - Transport configuration

Storage Types

  • StorageRecord - Neural-verified storage record
  • NeuralHash - Dual-hash verification structure
  • MerkleProof - Merkle tree proof for verification
  • StorageQuery, StorageResult - Query types
  • VerificationResult - Verification operation result

Security Types

  • ZtniIdentity - Zero-Trust Neural Identity
  • Role, Permission, Policy - RBAC types
  • AuthRequest, AuthResponse - Authentication types
  • Certificate, VerificationProof - Credential types

Event Types

  • NeuralEvent - Neural-verified event
  • EventSubscription - Subscription configuration
  • EventSchema - Event schema with compatibility
  • EventTopic, ConsumerGroup - Topic management

Manifest Types

  • NeuralManifest - Full package manifest
  • ManifestCapabilities, NeuralRequirements - Capability declarations
  • PackageRegistryEntry - Registry types

Exports

  • Types: NCP, Storage, Security, Events, Manifest, Common
  • Errors: AimfError class, ErrorCode enum, error factories
  • Constants: Protocol constants, default configuration values
  • Utilities: Hash, ID, validation, encoding helpers

License

MIT