---
title: "@prefactor/core"
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

[**Prefactor TypeScript SDK**](../index.md)

***

[Prefactor TypeScript SDK](../modules.md) / @prefactor/core

# @prefactor/core

Shared runtime, tracing primitives, and transport abstractions for Prefactor SDK adapters.

## `@prefactor/core` overview

`@prefactor/core` is the foundation for Prefactor integrations. Use it when you want direct
control over tracing lifecycle, transport behavior, and custom instrumentation in your app.

The package supports validated runtime configuration through `createConfig`, runtime
initialization through `createCore`, manual instrumentation through `withSpan` and
`Tracer.startSpan`, and graceful lifecycle handling with `shutdown` and
`registerShutdownHandler`.

## Quick start: initialize runtime directly

```ts
import { createConfig, createCore } from '@prefactor/core';

const config = createConfig({
  transportType: 'http',
  httpConfig: {
    apiUrl: 'https://api.prefactor.ai',
    apiToken: process.env.PREFACTOR_API_TOKEN!,
    agentIdentifier: '1.0.0',
  },
});

const core = createCore(config);
// core.tracer, core.agentManager, core.shutdown()
```

## Example: instrument custom work

```ts
import { withSpan } from '@prefactor/core';

const result = await withSpan(
  {
    name: 'custom-operation',
    spanType: 'app:task',
    inputs: { jobId: 'job-123' },
  },
  async () => {
    return { ok: true };
  }
);
```

## Functions

- [getClient](functions/getClient.md)
- [init](functions/init.md)
- [createConfig](functions/createConfig.md)
- [createCore](functions/createCore.md)
- [registerShutdownHandler](functions/registerShutdownHandler.md)
- [shutdown](functions/shutdown.md)
- [normalizeAgentToolSchemas](functions/normalizeAgentToolSchemas.md)
- [resolveMappedSpanType](functions/resolveMappedSpanType.md)
- [createSpanTypePrefixer](functions/createSpanTypePrefixer.md)
- [withSpan](functions/withSpan.md)
- [configureLogging](functions/configureLogging.md)
- [getLogger](functions/getLogger.md)
- [serializeValue](functions/serializeValue.md)
- [truncateString](functions/truncateString.md)

## Classes

- [AgentInstanceManager](classes/AgentInstanceManager.md)
- [PrefactorClient](classes/PrefactorClient.md)
- [PrefactorFatalError](classes/PrefactorFatalError.md)
- [PrefactorShutdownError](classes/PrefactorShutdownError.md)
- [SpanContext](classes/SpanContext.md)
- [Tracer](classes/Tracer.md)
- [AgentInstanceClient](classes/AgentInstanceClient.md)
- [AgentSpanClient](classes/AgentSpanClient.md)
- [HttpClient](classes/HttpClient.md)
- [HttpClientError](classes/HttpClientError.md)
- [HttpTransport](classes/HttpTransport.md)

## Enumerations

- [SpanStatus](enumerations/SpanStatus.md)

## Interfaces

- [ManualSpanOptions](interfaces/ManualSpanOptions.md)
- [PrefactorOptions](interfaces/PrefactorOptions.md)
- [PrefactorProvider](interfaces/PrefactorProvider.md)
- [FailureHandlingConfig](interfaces/FailureHandlingConfig.md)
- [ToolSchemaConfig](interfaces/ToolSchemaConfig.md)
- [ActionProfile](interfaces/ActionProfile.md)
- [DataCategories](interfaces/DataCategories.md)
- [DataRisk](interfaces/DataRisk.md)
- [ErrorInfo](interfaces/ErrorInfo.md)
- [Span](interfaces/Span.md)
- [TokenUsage](interfaces/TokenUsage.md)
- [AgentSchemaVersion](interfaces/AgentSchemaVersion.md)
- [SpanTypeSchema](interfaces/SpanTypeSchema.md)
- [EndSpanOptions](interfaces/EndSpanOptions.md)
- [StartSpanOptions](interfaces/StartSpanOptions.md)
- [HttpRequester](interfaces/HttpRequester.md)
- [Transport](interfaces/Transport.md)

## Type Aliases

- [MiddlewareLike](type-aliases/MiddlewareLike.md)
- [Config](type-aliases/Config.md)
- [HttpTransportConfig](type-aliases/HttpTransportConfig.md)
- [PartialHttpConfig](type-aliases/PartialHttpConfig.md)
- [CoreRuntime](type-aliases/CoreRuntime.md)
- [CreateCoreOptions](type-aliases/CreateCoreOptions.md)
- [PrefactorFatalErrorKind](type-aliases/PrefactorFatalErrorKind.md)
- [PrefactorShutdownDetails](type-aliases/PrefactorShutdownDetails.md)
- [PrefactorShutdownErrorKind](type-aliases/PrefactorShutdownErrorKind.md)
- [PrefactorTransportHealthState](type-aliases/PrefactorTransportHealthState.md)
- [PrefactorTransportOperation](type-aliases/PrefactorTransportOperation.md)
- [JsonSchema](type-aliases/JsonSchema.md)
- [ActionProfileValue](type-aliases/ActionProfileValue.md)
- [DataCategoryValue](type-aliases/DataCategoryValue.md)
- [DataClassification](type-aliases/DataClassification.md)
- [SpanType](type-aliases/SpanType.md)
- [AgentInstanceFinishOptions](type-aliases/AgentInstanceFinishOptions.md)
- [AgentInstanceRegisterPayload](type-aliases/AgentInstanceRegisterPayload.md)
- [AgentInstanceResponse](type-aliases/AgentInstanceResponse.md)
- [AgentInstanceStartOptions](type-aliases/AgentInstanceStartOptions.md)
- [AgentSpanCreatePayload](type-aliases/AgentSpanCreatePayload.md)
- [AgentSpanFinishOptions](type-aliases/AgentSpanFinishOptions.md)
- [AgentSpanResponse](type-aliases/AgentSpanResponse.md)
- [AgentSpanStatus](type-aliases/AgentSpanStatus.md)
- [AgentInstanceOptions](type-aliases/AgentInstanceOptions.md)

## Variables

- [ConfigSchema](variables/ConfigSchema.md)
- [HttpTransportConfigSchema](variables/HttpTransportConfigSchema.md)
- [PartialHttpConfigSchema](variables/PartialHttpConfigSchema.md)
- [SpanType](variables/SpanType.md)