agentcassette 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/LICENSE +21 -0
- package/README.md +249 -0
- package/dist/cli.cjs +437 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +435 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-CgkW5WWa.d.cts +179 -0
- package/dist/client-CgkW5WWa.d.ts +179 -0
- package/dist/index.cjs +903 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +881 -0
- package/dist/index.js.map +1 -0
- package/dist/jest.cjs +500 -0
- package/dist/jest.cjs.map +1 -0
- package/dist/jest.d.cts +7 -0
- package/dist/jest.d.ts +7 -0
- package/dist/jest.js +498 -0
- package/dist/jest.js.map +1 -0
- package/dist/testing-Bj7F-tqU.d.ts +9 -0
- package/dist/testing-S6vBH_XM.d.cts +9 -0
- package/dist/vitest.cjs +500 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +7 -0
- package/dist/vitest.d.ts +7 -0
- package/dist/vitest.js +498 -0
- package/dist/vitest.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
type MessageRole = "system" | "user" | "assistant" | "tool";
|
|
6
|
+
type ContentPart = {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: "json";
|
|
11
|
+
value: JsonValue;
|
|
12
|
+
} | {
|
|
13
|
+
type: "image";
|
|
14
|
+
source: string;
|
|
15
|
+
};
|
|
16
|
+
interface SemanticMessage {
|
|
17
|
+
role: MessageRole;
|
|
18
|
+
content: ContentPart[];
|
|
19
|
+
name?: string;
|
|
20
|
+
toolCallId?: string;
|
|
21
|
+
toolCalls?: ToolCall[];
|
|
22
|
+
}
|
|
23
|
+
interface ToolDefinition {
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
inputSchema: JsonValue;
|
|
27
|
+
}
|
|
28
|
+
interface ToolCall {
|
|
29
|
+
id?: string;
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: JsonValue;
|
|
32
|
+
}
|
|
33
|
+
interface TokenUsage {
|
|
34
|
+
inputTokens: number;
|
|
35
|
+
outputTokens: number;
|
|
36
|
+
totalTokens: number;
|
|
37
|
+
costUsd?: number;
|
|
38
|
+
}
|
|
39
|
+
interface SemanticRequest {
|
|
40
|
+
messages: SemanticMessage[];
|
|
41
|
+
tools: ToolDefinition[];
|
|
42
|
+
model?: string;
|
|
43
|
+
}
|
|
44
|
+
type SemanticResponseItem = {
|
|
45
|
+
type: "content";
|
|
46
|
+
part: ContentPart;
|
|
47
|
+
} | {
|
|
48
|
+
type: "toolCall";
|
|
49
|
+
call: ToolCall;
|
|
50
|
+
};
|
|
51
|
+
interface SemanticResponse {
|
|
52
|
+
content: ContentPart[];
|
|
53
|
+
toolCalls: ToolCall[];
|
|
54
|
+
sequence?: SemanticResponseItem[];
|
|
55
|
+
id?: string;
|
|
56
|
+
model?: string;
|
|
57
|
+
finishReason?: string;
|
|
58
|
+
usage?: TokenUsage;
|
|
59
|
+
}
|
|
60
|
+
type SemanticEvent = {
|
|
61
|
+
type: "messages.sent";
|
|
62
|
+
messages: SemanticMessage[];
|
|
63
|
+
} | {
|
|
64
|
+
type: "tool.result.returned";
|
|
65
|
+
message: SemanticMessage;
|
|
66
|
+
} | {
|
|
67
|
+
type: "tool.call.proposed";
|
|
68
|
+
call: ToolCall;
|
|
69
|
+
} | {
|
|
70
|
+
type: "output.final";
|
|
71
|
+
content: ContentPart[];
|
|
72
|
+
};
|
|
73
|
+
interface RecordedTurn {
|
|
74
|
+
index: number;
|
|
75
|
+
fingerprint: string;
|
|
76
|
+
request: SemanticRequest;
|
|
77
|
+
events: SemanticEvent[];
|
|
78
|
+
response: SemanticResponse;
|
|
79
|
+
}
|
|
80
|
+
interface CassetteMetadata {
|
|
81
|
+
provider?: string;
|
|
82
|
+
testFile?: string;
|
|
83
|
+
tags?: string[];
|
|
84
|
+
fingerprint?: "default" | "custom";
|
|
85
|
+
}
|
|
86
|
+
interface Cassette {
|
|
87
|
+
schemaVersion: 1;
|
|
88
|
+
name: string;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
updatedAt: string;
|
|
91
|
+
turns: RecordedTurn[];
|
|
92
|
+
metadata?: CassetteMetadata;
|
|
93
|
+
}
|
|
94
|
+
type CassetteMode = "record" | "replay" | "auto";
|
|
95
|
+
interface ProviderAdapter<Request, Response> {
|
|
96
|
+
readonly provider: string;
|
|
97
|
+
normalizeRequest(request: Request): SemanticRequest;
|
|
98
|
+
normalizeResponse(response: Response): SemanticResponse;
|
|
99
|
+
replayResponse(response: SemanticResponse): Response;
|
|
100
|
+
}
|
|
101
|
+
type ClientBoundary<Request, Response> = (request: Request) => Promise<Response>;
|
|
102
|
+
type FingerprintFunction = (request: SemanticRequest) => string;
|
|
103
|
+
interface CostContext {
|
|
104
|
+
request: SemanticRequest;
|
|
105
|
+
response: SemanticResponse;
|
|
106
|
+
}
|
|
107
|
+
type CostCalculator = (context: CostContext) => number | undefined;
|
|
108
|
+
|
|
109
|
+
interface RedactionContext {
|
|
110
|
+
path: string;
|
|
111
|
+
key?: string;
|
|
112
|
+
value: JsonValue;
|
|
113
|
+
}
|
|
114
|
+
interface RedactionRule {
|
|
115
|
+
name: string;
|
|
116
|
+
match(context: RedactionContext): boolean;
|
|
117
|
+
replacement?: JsonValue;
|
|
118
|
+
}
|
|
119
|
+
interface RedactionOptions {
|
|
120
|
+
rules?: RedactionRule[];
|
|
121
|
+
includeDefaults?: boolean;
|
|
122
|
+
}
|
|
123
|
+
declare const defaultRedactionRules: RedactionRule[];
|
|
124
|
+
declare function redact<T>(value: T, options?: RedactionOptions): T;
|
|
125
|
+
|
|
126
|
+
interface CassetteStore {
|
|
127
|
+
exists(name: string): Promise<boolean>;
|
|
128
|
+
read(name: string): Promise<Cassette>;
|
|
129
|
+
write(cassette: Cassette): Promise<void>;
|
|
130
|
+
list(): Promise<string[]>;
|
|
131
|
+
remove(name: string): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
declare class FileCassetteStore implements CassetteStore {
|
|
134
|
+
readonly directory: string;
|
|
135
|
+
constructor(directory?: string);
|
|
136
|
+
exists(name: string): Promise<boolean>;
|
|
137
|
+
read(name: string): Promise<Cassette>;
|
|
138
|
+
write(cassette: Cassette): Promise<void>;
|
|
139
|
+
list(): Promise<string[]>;
|
|
140
|
+
remove(name: string): Promise<void>;
|
|
141
|
+
pathFor(name: string): string;
|
|
142
|
+
}
|
|
143
|
+
declare class MemoryCassetteStore implements CassetteStore {
|
|
144
|
+
readonly cassettes: Map<string, Cassette>;
|
|
145
|
+
exists(name: string): Promise<boolean>;
|
|
146
|
+
read(name: string): Promise<Cassette>;
|
|
147
|
+
write(cassette: Cassette): Promise<void>;
|
|
148
|
+
list(): Promise<string[]>;
|
|
149
|
+
remove(name: string): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
declare function parseCassette(source: string, expectedName?: string): Cassette;
|
|
152
|
+
|
|
153
|
+
interface ReplayContext {
|
|
154
|
+
cassette: string;
|
|
155
|
+
turn: number;
|
|
156
|
+
response: SemanticResponse;
|
|
157
|
+
}
|
|
158
|
+
interface CassetteClientOptions<Request, Response> {
|
|
159
|
+
name: string;
|
|
160
|
+
adapter: ProviderAdapter<Request, Response>;
|
|
161
|
+
client?: ClientBoundary<Request, Response>;
|
|
162
|
+
mode?: CassetteMode;
|
|
163
|
+
store?: CassetteStore;
|
|
164
|
+
fingerprint?: FingerprintFunction;
|
|
165
|
+
redaction?: RedactionOptions;
|
|
166
|
+
replayTurns?: number;
|
|
167
|
+
metadata?: CassetteMetadata;
|
|
168
|
+
calculateCost?: CostCalculator;
|
|
169
|
+
onReplay?: (context: ReplayContext) => void | Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
interface CassetteClient<Request, Response> {
|
|
172
|
+
(request: Request): Promise<Response>;
|
|
173
|
+
readonly cassetteName: string;
|
|
174
|
+
readonly mode: "record" | "replay";
|
|
175
|
+
readonly turn: number;
|
|
176
|
+
}
|
|
177
|
+
declare function createCassetteClient<Request, Response>(options: CassetteClientOptions<Request, Response>): Promise<CassetteClient<Request, Response>>;
|
|
178
|
+
|
|
179
|
+
export { type CassetteClient as C, type FingerprintFunction as F, type JsonValue as J, MemoryCassetteStore as M, type ProviderAdapter as P, type ReplayContext as R, type SemanticRequest as S, type TokenUsage as T, type CassetteClientOptions as a, type SemanticResponse as b, type Cassette as c, type CassetteMetadata as d, type CassetteMode as e, type CassetteStore as f, type ClientBoundary as g, type ContentPart as h, type CostCalculator as i, type CostContext as j, FileCassetteStore as k, type JsonPrimitive as l, type MessageRole as m, type RecordedTurn as n, type RedactionContext as o, type RedactionOptions as p, type RedactionRule as q, type SemanticEvent as r, type SemanticMessage as s, type SemanticResponseItem as t, type ToolCall as u, type ToolDefinition as v, createCassetteClient as w, defaultRedactionRules as x, parseCassette as y, redact as z };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
2
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
3
|
+
[key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
type MessageRole = "system" | "user" | "assistant" | "tool";
|
|
6
|
+
type ContentPart = {
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: "json";
|
|
11
|
+
value: JsonValue;
|
|
12
|
+
} | {
|
|
13
|
+
type: "image";
|
|
14
|
+
source: string;
|
|
15
|
+
};
|
|
16
|
+
interface SemanticMessage {
|
|
17
|
+
role: MessageRole;
|
|
18
|
+
content: ContentPart[];
|
|
19
|
+
name?: string;
|
|
20
|
+
toolCallId?: string;
|
|
21
|
+
toolCalls?: ToolCall[];
|
|
22
|
+
}
|
|
23
|
+
interface ToolDefinition {
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
inputSchema: JsonValue;
|
|
27
|
+
}
|
|
28
|
+
interface ToolCall {
|
|
29
|
+
id?: string;
|
|
30
|
+
name: string;
|
|
31
|
+
arguments: JsonValue;
|
|
32
|
+
}
|
|
33
|
+
interface TokenUsage {
|
|
34
|
+
inputTokens: number;
|
|
35
|
+
outputTokens: number;
|
|
36
|
+
totalTokens: number;
|
|
37
|
+
costUsd?: number;
|
|
38
|
+
}
|
|
39
|
+
interface SemanticRequest {
|
|
40
|
+
messages: SemanticMessage[];
|
|
41
|
+
tools: ToolDefinition[];
|
|
42
|
+
model?: string;
|
|
43
|
+
}
|
|
44
|
+
type SemanticResponseItem = {
|
|
45
|
+
type: "content";
|
|
46
|
+
part: ContentPart;
|
|
47
|
+
} | {
|
|
48
|
+
type: "toolCall";
|
|
49
|
+
call: ToolCall;
|
|
50
|
+
};
|
|
51
|
+
interface SemanticResponse {
|
|
52
|
+
content: ContentPart[];
|
|
53
|
+
toolCalls: ToolCall[];
|
|
54
|
+
sequence?: SemanticResponseItem[];
|
|
55
|
+
id?: string;
|
|
56
|
+
model?: string;
|
|
57
|
+
finishReason?: string;
|
|
58
|
+
usage?: TokenUsage;
|
|
59
|
+
}
|
|
60
|
+
type SemanticEvent = {
|
|
61
|
+
type: "messages.sent";
|
|
62
|
+
messages: SemanticMessage[];
|
|
63
|
+
} | {
|
|
64
|
+
type: "tool.result.returned";
|
|
65
|
+
message: SemanticMessage;
|
|
66
|
+
} | {
|
|
67
|
+
type: "tool.call.proposed";
|
|
68
|
+
call: ToolCall;
|
|
69
|
+
} | {
|
|
70
|
+
type: "output.final";
|
|
71
|
+
content: ContentPart[];
|
|
72
|
+
};
|
|
73
|
+
interface RecordedTurn {
|
|
74
|
+
index: number;
|
|
75
|
+
fingerprint: string;
|
|
76
|
+
request: SemanticRequest;
|
|
77
|
+
events: SemanticEvent[];
|
|
78
|
+
response: SemanticResponse;
|
|
79
|
+
}
|
|
80
|
+
interface CassetteMetadata {
|
|
81
|
+
provider?: string;
|
|
82
|
+
testFile?: string;
|
|
83
|
+
tags?: string[];
|
|
84
|
+
fingerprint?: "default" | "custom";
|
|
85
|
+
}
|
|
86
|
+
interface Cassette {
|
|
87
|
+
schemaVersion: 1;
|
|
88
|
+
name: string;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
updatedAt: string;
|
|
91
|
+
turns: RecordedTurn[];
|
|
92
|
+
metadata?: CassetteMetadata;
|
|
93
|
+
}
|
|
94
|
+
type CassetteMode = "record" | "replay" | "auto";
|
|
95
|
+
interface ProviderAdapter<Request, Response> {
|
|
96
|
+
readonly provider: string;
|
|
97
|
+
normalizeRequest(request: Request): SemanticRequest;
|
|
98
|
+
normalizeResponse(response: Response): SemanticResponse;
|
|
99
|
+
replayResponse(response: SemanticResponse): Response;
|
|
100
|
+
}
|
|
101
|
+
type ClientBoundary<Request, Response> = (request: Request) => Promise<Response>;
|
|
102
|
+
type FingerprintFunction = (request: SemanticRequest) => string;
|
|
103
|
+
interface CostContext {
|
|
104
|
+
request: SemanticRequest;
|
|
105
|
+
response: SemanticResponse;
|
|
106
|
+
}
|
|
107
|
+
type CostCalculator = (context: CostContext) => number | undefined;
|
|
108
|
+
|
|
109
|
+
interface RedactionContext {
|
|
110
|
+
path: string;
|
|
111
|
+
key?: string;
|
|
112
|
+
value: JsonValue;
|
|
113
|
+
}
|
|
114
|
+
interface RedactionRule {
|
|
115
|
+
name: string;
|
|
116
|
+
match(context: RedactionContext): boolean;
|
|
117
|
+
replacement?: JsonValue;
|
|
118
|
+
}
|
|
119
|
+
interface RedactionOptions {
|
|
120
|
+
rules?: RedactionRule[];
|
|
121
|
+
includeDefaults?: boolean;
|
|
122
|
+
}
|
|
123
|
+
declare const defaultRedactionRules: RedactionRule[];
|
|
124
|
+
declare function redact<T>(value: T, options?: RedactionOptions): T;
|
|
125
|
+
|
|
126
|
+
interface CassetteStore {
|
|
127
|
+
exists(name: string): Promise<boolean>;
|
|
128
|
+
read(name: string): Promise<Cassette>;
|
|
129
|
+
write(cassette: Cassette): Promise<void>;
|
|
130
|
+
list(): Promise<string[]>;
|
|
131
|
+
remove(name: string): Promise<void>;
|
|
132
|
+
}
|
|
133
|
+
declare class FileCassetteStore implements CassetteStore {
|
|
134
|
+
readonly directory: string;
|
|
135
|
+
constructor(directory?: string);
|
|
136
|
+
exists(name: string): Promise<boolean>;
|
|
137
|
+
read(name: string): Promise<Cassette>;
|
|
138
|
+
write(cassette: Cassette): Promise<void>;
|
|
139
|
+
list(): Promise<string[]>;
|
|
140
|
+
remove(name: string): Promise<void>;
|
|
141
|
+
pathFor(name: string): string;
|
|
142
|
+
}
|
|
143
|
+
declare class MemoryCassetteStore implements CassetteStore {
|
|
144
|
+
readonly cassettes: Map<string, Cassette>;
|
|
145
|
+
exists(name: string): Promise<boolean>;
|
|
146
|
+
read(name: string): Promise<Cassette>;
|
|
147
|
+
write(cassette: Cassette): Promise<void>;
|
|
148
|
+
list(): Promise<string[]>;
|
|
149
|
+
remove(name: string): Promise<void>;
|
|
150
|
+
}
|
|
151
|
+
declare function parseCassette(source: string, expectedName?: string): Cassette;
|
|
152
|
+
|
|
153
|
+
interface ReplayContext {
|
|
154
|
+
cassette: string;
|
|
155
|
+
turn: number;
|
|
156
|
+
response: SemanticResponse;
|
|
157
|
+
}
|
|
158
|
+
interface CassetteClientOptions<Request, Response> {
|
|
159
|
+
name: string;
|
|
160
|
+
adapter: ProviderAdapter<Request, Response>;
|
|
161
|
+
client?: ClientBoundary<Request, Response>;
|
|
162
|
+
mode?: CassetteMode;
|
|
163
|
+
store?: CassetteStore;
|
|
164
|
+
fingerprint?: FingerprintFunction;
|
|
165
|
+
redaction?: RedactionOptions;
|
|
166
|
+
replayTurns?: number;
|
|
167
|
+
metadata?: CassetteMetadata;
|
|
168
|
+
calculateCost?: CostCalculator;
|
|
169
|
+
onReplay?: (context: ReplayContext) => void | Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
interface CassetteClient<Request, Response> {
|
|
172
|
+
(request: Request): Promise<Response>;
|
|
173
|
+
readonly cassetteName: string;
|
|
174
|
+
readonly mode: "record" | "replay";
|
|
175
|
+
readonly turn: number;
|
|
176
|
+
}
|
|
177
|
+
declare function createCassetteClient<Request, Response>(options: CassetteClientOptions<Request, Response>): Promise<CassetteClient<Request, Response>>;
|
|
178
|
+
|
|
179
|
+
export { type CassetteClient as C, type FingerprintFunction as F, type JsonValue as J, MemoryCassetteStore as M, type ProviderAdapter as P, type ReplayContext as R, type SemanticRequest as S, type TokenUsage as T, type CassetteClientOptions as a, type SemanticResponse as b, type Cassette as c, type CassetteMetadata as d, type CassetteMode as e, type CassetteStore as f, type ClientBoundary as g, type ContentPart as h, type CostCalculator as i, type CostContext as j, FileCassetteStore as k, type JsonPrimitive as l, type MessageRole as m, type RecordedTurn as n, type RedactionContext as o, type RedactionOptions as p, type RedactionRule as q, type SemanticEvent as r, type SemanticMessage as s, type SemanticResponseItem as t, type ToolCall as u, type ToolDefinition as v, createCassetteClient as w, defaultRedactionRules as x, parseCassette as y, redact as z };
|