@prefactor/sdk 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @prefactor/sdk
|
|
2
|
+
|
|
3
|
+
Unified SDK for Prefactor observability. This package re-exports everything from `@prefactor/core` and `@prefactor/langchain` for a single-import experience.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @prefactor/sdk
|
|
9
|
+
# or
|
|
10
|
+
bun add @prefactor/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## When to Use This Package
|
|
14
|
+
|
|
15
|
+
**Use `@prefactor/sdk`** (this package) when:
|
|
16
|
+
|
|
17
|
+
- You're building a LangChain.js application and want all Prefactor features
|
|
18
|
+
- You want a single import for both core primitives and LangChain integration
|
|
19
|
+
- You're not concerned about bundle size optimization
|
|
20
|
+
|
|
21
|
+
**Use individual packages** when:
|
|
22
|
+
|
|
23
|
+
- You need only core tracing without LangChain (`@prefactor/core`)
|
|
24
|
+
- You want to minimize dependencies in a LangChain project (`@prefactor/langchain`)
|
|
25
|
+
- You're building a custom framework integration (`@prefactor/core`)
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { createAgent, tool } from 'langchain';
|
|
31
|
+
import { z } from 'zod';
|
|
32
|
+
import { init, shutdown } from '@prefactor/sdk';
|
|
33
|
+
|
|
34
|
+
// Initialize Prefactor
|
|
35
|
+
const middleware = init();
|
|
36
|
+
|
|
37
|
+
// Create agent with middleware
|
|
38
|
+
const agent = createAgent({
|
|
39
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
40
|
+
tools: [],
|
|
41
|
+
systemPrompt: 'You are a helpful assistant.',
|
|
42
|
+
middleware: [middleware],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// All operations are automatically traced
|
|
46
|
+
const result = await agent.invoke({
|
|
47
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Graceful shutdown
|
|
51
|
+
await shutdown();
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## What's Included
|
|
55
|
+
|
|
56
|
+
This package re-exports everything from:
|
|
57
|
+
|
|
58
|
+
### From `@prefactor/langchain`
|
|
59
|
+
|
|
60
|
+
- `init()` - Initialize SDK and return middleware
|
|
61
|
+
- `shutdown()` - Flush spans and close connections
|
|
62
|
+
- `getTracer()` - Get tracer for manual instrumentation
|
|
63
|
+
- `PrefactorMiddleware` - LangChain.js middleware class
|
|
64
|
+
- `extractTokenUsage()` - Token usage extraction utility
|
|
65
|
+
|
|
66
|
+
### From `@prefactor/core`
|
|
67
|
+
|
|
68
|
+
- Configuration: `Config`, `createConfig`, `ConfigSchema`, `HttpTransportConfig`
|
|
69
|
+
- Tracing: `Tracer`, `SpanContext`, `Span`, `SpanType`, `SpanStatus`, `TokenUsage`, `ErrorInfo`
|
|
70
|
+
- Transports: `Transport`, `StdioTransport`, `HttpTransport`
|
|
71
|
+
- Utilities: `getLogger`, `configureLogging`, `serializeValue`, `truncateString`
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { init } from '@prefactor/sdk';
|
|
77
|
+
|
|
78
|
+
// STDIO transport (default, good for development)
|
|
79
|
+
const middleware = init();
|
|
80
|
+
|
|
81
|
+
// HTTP transport (for production)
|
|
82
|
+
const middleware = init({
|
|
83
|
+
transportType: 'http',
|
|
84
|
+
httpConfig: {
|
|
85
|
+
apiUrl: 'https://api.prefactor.ai',
|
|
86
|
+
apiToken: process.env.PREFACTOR_API_TOKEN!,
|
|
87
|
+
agentId: 'my-agent',
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Requirements
|
|
93
|
+
|
|
94
|
+
- Node.js >= 24.0.0
|
|
95
|
+
- LangChain.js >= 1.0.0 (peer dependency)
|
|
96
|
+
|
|
97
|
+
## Documentation
|
|
98
|
+
|
|
99
|
+
For detailed documentation, see the [main repository README](https://github.com/prefactor/typescript-sdk).
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
MIT
|