SDK API Reference

Complete API reference for the ContextGraph SDK.

ContextGraph Class

create()

static async create(config?: ContextGraphConfig): Promise<Result<ContextGraph>>

Creates a new ContextGraph client.

Parameters:

  • config - Optional configuration object

Returns: Result<ContextGraph>

Entity Methods

createEntity()

async createEntity(input: CreateEntityInput): Promise<Result<Entity>>

getEntity()

async getEntity(id: EntityId): Promise<Result<Entity | null>>

updateEntity()

async updateEntity(id: EntityId, updates: Partial<Entity>): Promise<Result<Entity>>

listEntities()

async listEntities(options?: ListEntitiesOptions): Promise<Result<Entity[]>>

Claim Methods

addClaim()

async addClaim(input: AddClaimInput): Promise<Result<Claim>>

getClaims()

async getClaims(entityId: EntityId, options?: ClaimQueryOptions): Promise<Result<Claim[]>>

revokeClaim()

async revokeClaim(id: ClaimId, reason?: string): Promise<Result<void>>

Agent Methods

createAgent()

async createAgent(input: CreateAgentInput): Promise<Result<Agent>>

getAgent()

async getAgent(id: AgentId): Promise<Result<Agent | null>>

getAgentByName()

async getAgentByName(name: string): Promise<Result<Agent | null>>

listAgents()

async listAgents(options?: ListAgentsOptions): Promise<Result<Agent[]>>

Execution Methods

registerHandler()

registerHandler(
  action: string,
  resourceType: string,
  handler: ActionHandler
): void

execute()

async execute(request: ActionRequest): Promise<Result<ActionResult>>

Decision Methods

recordDecision()

async recordDecision(input: RecordDecisionInput): Promise<Result<Decision>>

approveDecision()

async approveDecision(
  id: DecisionId,
  approverId: AgentId,
  comment?: string
): Promise<Result<Decision>>

rejectDecision()

async rejectDecision(
  id: DecisionId,
  rejecterId: AgentId,
  reason?: string
): Promise<Result<Decision>>

getPendingDecisions()

async getPendingDecisions(): Promise<Result<Decision[]>>

Policy Methods

createPolicy()

async createPolicy(input: CreatePolicyInput): Promise<Result<Policy>>

listPolicies()

async listPolicies(options?: ListPoliciesOptions): Promise<Result<Policy[]>>

Provenance Methods

verifyProvenance()

async verifyProvenance(): Promise<Result<VerificationResult>>

queryProvenance()

async queryProvenance(options?: ProvenanceQueryOptions): Promise<Result<ProvenanceEntry[]>>

Context Methods

assembleContext()

async assembleContext(
  entityId: EntityId,
  options?: AssemblyOptions
): Promise<Result<AssembledContext>>

Audit Methods

getAuditTrail()

async getAuditTrail(options?: AuditQueryOptions): Promise<Result<AuditEntry[]>>

Statistics

getStats()

async getStats(): Promise<Result<SystemStats>>

Import/Export

exportToJSON()

async exportToJSON(): Promise<Result<ExportData>>

importFromJSON()

async importFromJSON(
  data: ExportData,
  options?: ImportOptions
): Promise<Result<ImportResult>>

Events

on()

on(event: EventType, handler: EventHandler): void

off()

off(event: EventType, handler: EventHandler): void

Helper Functions

createTimestamp()

function createTimestamp(input?: string | Date): Timestamp

createScope()

function createScope(value: string): Scope

createJurisdiction()

function createJurisdiction(value: string): Jurisdiction

createConfidence()

function createConfidence(value: number): Confidence

ok()

function ok<T>(value: T): Result<T>

err()

function err<E = Error>(error: E): Result<never, E>