@replayci/replay 0.1.0
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 +75 -0
- package/dist/index.cjs +2197 -0
- package/dist/index.d.cts +55 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +2184 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# `@replayci/replay`
|
|
2
|
+
|
|
3
|
+
ReplayCI's Node.js SDK for deterministic contract validation and passive capture of tool-calling responses.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the SDK with the provider you use:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @replayci/replay openai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @replayci/replay @anthropic-ai/sdk
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`re2` is optional. If installed, regex invariants run with RE2.
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import OpenAI from "openai";
|
|
23
|
+
import {
|
|
24
|
+
observe,
|
|
25
|
+
prepareContracts,
|
|
26
|
+
validate,
|
|
27
|
+
} from "@replayci/replay";
|
|
28
|
+
|
|
29
|
+
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
30
|
+
|
|
31
|
+
const observed = observe(client, {
|
|
32
|
+
apiKey: process.env.REPLAYCI_API_KEY,
|
|
33
|
+
agent: "support-bot",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const contracts = prepareContracts("./contracts");
|
|
37
|
+
|
|
38
|
+
const response = await client.chat.completions.create({
|
|
39
|
+
model: "gpt-4o-mini",
|
|
40
|
+
messages: [
|
|
41
|
+
{ role: "user", content: "What's the weather in San Francisco?" },
|
|
42
|
+
],
|
|
43
|
+
tools: [
|
|
44
|
+
{
|
|
45
|
+
type: "function",
|
|
46
|
+
function: {
|
|
47
|
+
name: "get_weather",
|
|
48
|
+
description: "Fetch the weather for a city.",
|
|
49
|
+
parameters: {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
location: { type: "string" },
|
|
53
|
+
},
|
|
54
|
+
required: ["location"],
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const result = validate(response, { contracts });
|
|
62
|
+
|
|
63
|
+
if (!result.pass) {
|
|
64
|
+
console.error(result.failures);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
observed.restore();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- `validate()` checks a single response against your prepared contracts.
|
|
71
|
+
- `observe()` passively captures calls for ReplayCI ingest without changing model behavior.
|
|
72
|
+
|
|
73
|
+
## Docs
|
|
74
|
+
|
|
75
|
+
Full documentation lives at [docs.replayci.com](https://docs.replayci.com).
|