@jterrazz/test 6.5.1 → 7.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/dist/index.cjs +22 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -8
- package/dist/index.d.ts +10 -8
- package/dist/index.js +22 -8
- package/dist/index.js.map +1 -1
- package/dist/intercept.cjs +143 -129
- package/dist/intercept.cjs.map +1 -1
- package/dist/intercept.d.cts +39 -53
- package/dist/intercept.d.ts +39 -53
- package/dist/intercept.js +143 -129
- package/dist/intercept.js.map +1 -1
- package/dist/types.d.cts +8 -1
- package/dist/types.d.ts +8 -1
- package/package.json +1 -1
package/dist/intercept.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#region src/builder/common/intercept/adapters/anthropic.ts
|
|
3
3
|
const ANTHROPIC_MESSAGES_URL = "https://api.anthropic.com/v1/messages";
|
|
4
|
-
function matchesFilter
|
|
4
|
+
function matchesFilter(body, filter) {
|
|
5
5
|
if (filter.model) {
|
|
6
6
|
const model = body?.model;
|
|
7
7
|
if (typeof filter.model === "string" && model !== filter.model) return false;
|
|
@@ -19,42 +19,45 @@ function matchesFilter$1(body, filter) {
|
|
|
19
19
|
if (filter.user instanceof RegExp && !filter.user.test(text)) return false;
|
|
20
20
|
}
|
|
21
21
|
if (filter.tools) {
|
|
22
|
-
const
|
|
23
|
-
if (!filter.tools.every((t) =>
|
|
22
|
+
const names = body?.tools?.map((t) => t.name).filter(Boolean) ?? [];
|
|
23
|
+
if (!filter.tools.every((t) => names.includes(t))) return false;
|
|
24
24
|
}
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
|
+
function buildReply(data) {
|
|
28
|
+
return {
|
|
29
|
+
status: 200,
|
|
30
|
+
body: {
|
|
31
|
+
id: "msg-test",
|
|
32
|
+
type: "message",
|
|
33
|
+
role: "assistant",
|
|
34
|
+
content: [{
|
|
35
|
+
type: "text",
|
|
36
|
+
text: typeof data === "string" ? data : JSON.stringify(data)
|
|
37
|
+
}],
|
|
38
|
+
model: "claude-sonnet-4-20250514",
|
|
39
|
+
stop_reason: "end_turn",
|
|
40
|
+
usage: {
|
|
41
|
+
input_tokens: 10,
|
|
42
|
+
output_tokens: 10
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
27
47
|
/**
|
|
28
48
|
* Anthropic API intercept helpers.
|
|
29
49
|
*/
|
|
30
50
|
const anthropic = {
|
|
31
|
-
|
|
51
|
+
request(filter) {
|
|
32
52
|
return {
|
|
53
|
+
adapter: "anthropic",
|
|
33
54
|
method: "POST",
|
|
34
55
|
url: ANTHROPIC_MESSAGES_URL,
|
|
35
|
-
match: filter ? (body) => matchesFilter
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
response(data) {
|
|
39
|
-
return {
|
|
40
|
-
status: 200,
|
|
41
|
-
body: {
|
|
42
|
-
id: "msg-test",
|
|
43
|
-
type: "message",
|
|
44
|
-
role: "assistant",
|
|
45
|
-
content: [{
|
|
46
|
-
type: "text",
|
|
47
|
-
text: typeof data === "string" ? data : JSON.stringify(data)
|
|
48
|
-
}],
|
|
49
|
-
model: "claude-sonnet-4-20250514",
|
|
50
|
-
stop_reason: "end_turn",
|
|
51
|
-
usage: {
|
|
52
|
-
input_tokens: 10,
|
|
53
|
-
output_tokens: 10
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
+
match: filter ? (body) => matchesFilter(body, filter) : void 0,
|
|
57
|
+
wrap: buildReply
|
|
56
58
|
};
|
|
57
59
|
},
|
|
60
|
+
reply: buildReply,
|
|
58
61
|
error(status, message) {
|
|
59
62
|
return {
|
|
60
63
|
status,
|
|
@@ -73,46 +76,65 @@ const anthropic = {
|
|
|
73
76
|
body: {},
|
|
74
77
|
delay: 3e4
|
|
75
78
|
};
|
|
76
|
-
}
|
|
79
|
+
},
|
|
80
|
+
messages(filter) {
|
|
81
|
+
return anthropic.request(filter);
|
|
82
|
+
},
|
|
83
|
+
response: buildReply
|
|
77
84
|
};
|
|
78
85
|
//#endregion
|
|
79
86
|
//#region src/builder/common/intercept/adapters/http.ts
|
|
87
|
+
function wrapJson(data) {
|
|
88
|
+
return {
|
|
89
|
+
status: 200,
|
|
90
|
+
body: data
|
|
91
|
+
};
|
|
92
|
+
}
|
|
80
93
|
/**
|
|
81
94
|
* Generic HTTP intercept helpers for any URL.
|
|
82
95
|
*
|
|
83
96
|
* @example
|
|
84
|
-
* .intercept(http.get('https://api.example.com/data'),
|
|
85
|
-
* .intercept(http.post('https://api.stripe.com/v1/charges'), { body: { id: 'ch_...' } })
|
|
97
|
+
* .intercept(http.get('https://api.example.com/data'), 'http/response.json')
|
|
86
98
|
*/
|
|
87
99
|
const http = {
|
|
88
100
|
get(url) {
|
|
89
101
|
return {
|
|
102
|
+
adapter: "http",
|
|
90
103
|
method: "GET",
|
|
91
|
-
url
|
|
104
|
+
url,
|
|
105
|
+
wrap: wrapJson
|
|
92
106
|
};
|
|
93
107
|
},
|
|
94
108
|
post(url) {
|
|
95
109
|
return {
|
|
110
|
+
adapter: "http",
|
|
96
111
|
method: "POST",
|
|
97
|
-
url
|
|
112
|
+
url,
|
|
113
|
+
wrap: wrapJson
|
|
98
114
|
};
|
|
99
115
|
},
|
|
100
116
|
put(url) {
|
|
101
117
|
return {
|
|
118
|
+
adapter: "http",
|
|
102
119
|
method: "PUT",
|
|
103
|
-
url
|
|
120
|
+
url,
|
|
121
|
+
wrap: wrapJson
|
|
104
122
|
};
|
|
105
123
|
},
|
|
106
124
|
delete(url) {
|
|
107
125
|
return {
|
|
126
|
+
adapter: "http",
|
|
108
127
|
method: "DELETE",
|
|
109
|
-
url
|
|
128
|
+
url,
|
|
129
|
+
wrap: wrapJson
|
|
110
130
|
};
|
|
111
131
|
},
|
|
112
132
|
any(url) {
|
|
113
133
|
return {
|
|
134
|
+
adapter: "http",
|
|
114
135
|
method: "*",
|
|
115
|
-
url
|
|
136
|
+
url,
|
|
137
|
+
wrap: wrapJson
|
|
116
138
|
};
|
|
117
139
|
},
|
|
118
140
|
json(data, status = 200) {
|
|
@@ -132,25 +154,25 @@ const http = {
|
|
|
132
154
|
//#region src/builder/common/intercept/adapters/openai.ts
|
|
133
155
|
const OPENAI_CHAT_URL = "https://api.openai.com/v1/chat/completions";
|
|
134
156
|
const OPENAI_RESPONSES_URL = "https://api.openai.com/v1/responses";
|
|
135
|
-
function
|
|
157
|
+
function matchesChatFilter(body, filter) {
|
|
136
158
|
if (filter.model) {
|
|
137
159
|
const model = body?.model;
|
|
138
160
|
if (typeof filter.model === "string" && model !== filter.model) return false;
|
|
139
161
|
if (filter.model instanceof RegExp && !filter.model.test(model ?? "")) return false;
|
|
140
162
|
}
|
|
141
163
|
if (filter.system) {
|
|
142
|
-
const
|
|
143
|
-
if (typeof filter.system === "string" && !
|
|
144
|
-
if (filter.system instanceof RegExp && !filter.system.test(
|
|
164
|
+
const msg = body?.messages?.find((m) => m.role === "system")?.content ?? "";
|
|
165
|
+
if (typeof filter.system === "string" && !msg.includes(filter.system)) return false;
|
|
166
|
+
if (filter.system instanceof RegExp && !filter.system.test(msg)) return false;
|
|
145
167
|
}
|
|
146
168
|
if (filter.user) {
|
|
147
|
-
const
|
|
148
|
-
if (typeof filter.user === "string" && !
|
|
149
|
-
if (filter.user instanceof RegExp && !filter.user.test(
|
|
169
|
+
const msg = body?.messages?.find((m) => m.role === "user")?.content ?? "";
|
|
170
|
+
if (typeof filter.user === "string" && !msg.includes(filter.user)) return false;
|
|
171
|
+
if (filter.user instanceof RegExp && !filter.user.test(msg)) return false;
|
|
150
172
|
}
|
|
151
173
|
if (filter.tools) {
|
|
152
|
-
const
|
|
153
|
-
if (!filter.tools.every((t) =>
|
|
174
|
+
const names = body?.tools?.map((t) => t.function?.name).filter(Boolean) ?? [];
|
|
175
|
+
if (!filter.tools.every((t) => names.includes(t))) return false;
|
|
154
176
|
}
|
|
155
177
|
if (filter.temperature !== void 0 && body?.temperature !== filter.temperature) return false;
|
|
156
178
|
return true;
|
|
@@ -164,91 +186,96 @@ function matchesResponsesFilter(body, filter) {
|
|
|
164
186
|
if (filter.system) {
|
|
165
187
|
const instructions = body?.instructions ?? "";
|
|
166
188
|
const systemInput = body?.input?.find?.((m) => m.role === "system")?.content ?? "";
|
|
167
|
-
const
|
|
168
|
-
if (typeof filter.system === "string" && !
|
|
169
|
-
if (filter.system instanceof RegExp && !filter.system.test(
|
|
189
|
+
const text = instructions || systemInput;
|
|
190
|
+
if (typeof filter.system === "string" && !text.includes(filter.system)) return false;
|
|
191
|
+
if (filter.system instanceof RegExp && !filter.system.test(text)) return false;
|
|
170
192
|
}
|
|
171
193
|
if (filter.user) {
|
|
172
|
-
const
|
|
173
|
-
if (typeof filter.user === "string" && !
|
|
174
|
-
if (filter.user instanceof RegExp && !filter.user.test(
|
|
194
|
+
const msgs = (body?.input ?? []).filter((m) => m.role === "user").map((m) => typeof m.content === "string" ? m.content : JSON.stringify(m.content)).join(" ");
|
|
195
|
+
if (typeof filter.user === "string" && !msgs.includes(filter.user)) return false;
|
|
196
|
+
if (filter.user instanceof RegExp && !filter.user.test(msgs)) return false;
|
|
175
197
|
}
|
|
176
198
|
if (filter.tools) {
|
|
177
|
-
const
|
|
178
|
-
if (!filter.tools.every((t) =>
|
|
199
|
+
const names = body?.tools?.map((t) => t.name ?? t.function?.name).filter(Boolean) ?? [];
|
|
200
|
+
if (!filter.tools.every((t) => names.includes(t))) return false;
|
|
179
201
|
}
|
|
180
202
|
return true;
|
|
181
203
|
}
|
|
204
|
+
function buildChatReply(data) {
|
|
205
|
+
const content = typeof data === "string" ? data : JSON.stringify(data);
|
|
206
|
+
return {
|
|
207
|
+
status: 200,
|
|
208
|
+
body: {
|
|
209
|
+
id: "chatcmpl-test",
|
|
210
|
+
object: "chat.completion",
|
|
211
|
+
created: Math.floor(Date.now() / 1e3),
|
|
212
|
+
model: "gpt-4o-test",
|
|
213
|
+
choices: [{
|
|
214
|
+
index: 0,
|
|
215
|
+
message: {
|
|
216
|
+
role: "assistant",
|
|
217
|
+
content
|
|
218
|
+
},
|
|
219
|
+
finish_reason: "stop"
|
|
220
|
+
}],
|
|
221
|
+
usage: {
|
|
222
|
+
prompt_tokens: 10,
|
|
223
|
+
completion_tokens: 10,
|
|
224
|
+
total_tokens: 20
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function buildResponsesReply(data) {
|
|
230
|
+
const text = typeof data === "string" ? data : JSON.stringify(data);
|
|
231
|
+
return {
|
|
232
|
+
status: 200,
|
|
233
|
+
body: {
|
|
234
|
+
id: "resp-test",
|
|
235
|
+
object: "response",
|
|
236
|
+
created_at: Math.floor(Date.now() / 1e3),
|
|
237
|
+
model: "gpt-4o-test",
|
|
238
|
+
output: [{
|
|
239
|
+
type: "message",
|
|
240
|
+
id: "msg-test",
|
|
241
|
+
role: "assistant",
|
|
242
|
+
content: [{
|
|
243
|
+
type: "output_text",
|
|
244
|
+
text,
|
|
245
|
+
annotations: []
|
|
246
|
+
}]
|
|
247
|
+
}],
|
|
248
|
+
usage: {
|
|
249
|
+
input_tokens: 10,
|
|
250
|
+
output_tokens: 10,
|
|
251
|
+
total_tokens: 20
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
182
256
|
/**
|
|
183
257
|
* OpenAI API intercept helpers.
|
|
184
258
|
*/
|
|
185
259
|
const openai = {
|
|
186
|
-
|
|
260
|
+
request(filter) {
|
|
187
261
|
return {
|
|
262
|
+
adapter: "openai",
|
|
188
263
|
method: "POST",
|
|
189
264
|
url: OPENAI_CHAT_URL,
|
|
190
|
-
match: filter ? (body) =>
|
|
265
|
+
match: filter ? (body) => matchesChatFilter(body, filter) : void 0,
|
|
266
|
+
wrap: buildChatReply
|
|
191
267
|
};
|
|
192
268
|
},
|
|
193
|
-
|
|
269
|
+
agent(filter, url) {
|
|
194
270
|
return {
|
|
271
|
+
adapter: "openai",
|
|
195
272
|
method: "POST",
|
|
196
273
|
url: url ?? OPENAI_RESPONSES_URL,
|
|
197
|
-
match: filter ? (body) => matchesResponsesFilter(body, filter) : void 0
|
|
198
|
-
|
|
199
|
-
},
|
|
200
|
-
responsesResponse(data) {
|
|
201
|
-
const text = typeof data === "string" ? data : JSON.stringify(data);
|
|
202
|
-
return {
|
|
203
|
-
status: 200,
|
|
204
|
-
body: {
|
|
205
|
-
id: "resp-test",
|
|
206
|
-
object: "response",
|
|
207
|
-
created_at: Math.floor(Date.now() / 1e3),
|
|
208
|
-
model: "gpt-4o-test",
|
|
209
|
-
output: [{
|
|
210
|
-
type: "message",
|
|
211
|
-
id: "msg-test",
|
|
212
|
-
role: "assistant",
|
|
213
|
-
content: [{
|
|
214
|
-
type: "output_text",
|
|
215
|
-
text,
|
|
216
|
-
annotations: []
|
|
217
|
-
}]
|
|
218
|
-
}],
|
|
219
|
-
usage: {
|
|
220
|
-
input_tokens: 10,
|
|
221
|
-
output_tokens: 10,
|
|
222
|
-
total_tokens: 20
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
},
|
|
227
|
-
response(data) {
|
|
228
|
-
const content = typeof data === "string" ? data : JSON.stringify(data);
|
|
229
|
-
return {
|
|
230
|
-
status: 200,
|
|
231
|
-
body: {
|
|
232
|
-
id: "chatcmpl-test",
|
|
233
|
-
object: "chat.completion",
|
|
234
|
-
created: Math.floor(Date.now() / 1e3),
|
|
235
|
-
model: "gpt-4o-test",
|
|
236
|
-
choices: [{
|
|
237
|
-
index: 0,
|
|
238
|
-
message: {
|
|
239
|
-
role: "assistant",
|
|
240
|
-
content
|
|
241
|
-
},
|
|
242
|
-
finish_reason: "stop"
|
|
243
|
-
}],
|
|
244
|
-
usage: {
|
|
245
|
-
prompt_tokens: 10,
|
|
246
|
-
completion_tokens: 10,
|
|
247
|
-
total_tokens: 20
|
|
248
|
-
}
|
|
249
|
-
}
|
|
274
|
+
match: filter ? (body) => matchesResponsesFilter(body, filter) : void 0,
|
|
275
|
+
wrap: buildResponsesReply
|
|
250
276
|
};
|
|
251
277
|
},
|
|
278
|
+
reply: buildChatReply,
|
|
252
279
|
error(status, message) {
|
|
253
280
|
return {
|
|
254
281
|
status,
|
|
@@ -260,28 +287,7 @@ const openai = {
|
|
|
260
287
|
};
|
|
261
288
|
},
|
|
262
289
|
malformed(content) {
|
|
263
|
-
return
|
|
264
|
-
status: 200,
|
|
265
|
-
body: {
|
|
266
|
-
id: "chatcmpl-test",
|
|
267
|
-
object: "chat.completion",
|
|
268
|
-
created: Math.floor(Date.now() / 1e3),
|
|
269
|
-
model: "gpt-4o-test",
|
|
270
|
-
choices: [{
|
|
271
|
-
index: 0,
|
|
272
|
-
message: {
|
|
273
|
-
role: "assistant",
|
|
274
|
-
content
|
|
275
|
-
},
|
|
276
|
-
finish_reason: "stop"
|
|
277
|
-
}],
|
|
278
|
-
usage: {
|
|
279
|
-
prompt_tokens: 10,
|
|
280
|
-
completion_tokens: 10,
|
|
281
|
-
total_tokens: 20
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
};
|
|
290
|
+
return buildChatReply(content);
|
|
285
291
|
},
|
|
286
292
|
timeout() {
|
|
287
293
|
return {
|
|
@@ -289,7 +295,15 @@ const openai = {
|
|
|
289
295
|
body: {},
|
|
290
296
|
delay: 3e4
|
|
291
297
|
};
|
|
292
|
-
}
|
|
298
|
+
},
|
|
299
|
+
chat(filter) {
|
|
300
|
+
return openai.request(filter);
|
|
301
|
+
},
|
|
302
|
+
response: buildChatReply,
|
|
303
|
+
responses(filter, url) {
|
|
304
|
+
return openai.agent(filter, url);
|
|
305
|
+
},
|
|
306
|
+
responsesResponse: buildResponsesReply
|
|
293
307
|
};
|
|
294
308
|
//#endregion
|
|
295
309
|
exports.anthropic = anthropic;
|
package/dist/intercept.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intercept.cjs","names":["matchesFilter"],"sources":["../src/builder/common/intercept/adapters/anthropic.ts","../src/builder/common/intercept/adapters/http.ts","../src/builder/common/intercept/adapters/openai.ts"],"sourcesContent":["import type { InterceptResponse, InterceptTrigger } from '../types.js';\n\nconst ANTHROPIC_MESSAGES_URL = 'https://api.anthropic.com/v1/messages';\n\nexport interface AnthropicMessagesFilter {\n /** Match by model name. */\n model?: RegExp | string;\n /** Match by system message content. */\n system?: RegExp | string;\n /** Match by user message content. */\n user?: RegExp | string;\n /** Match by tool names. */\n tools?: string[];\n}\n\nfunction matchesFilter(body: any, filter: AnthropicMessagesFilter): boolean {\n if (filter.model) {\n const model = body?.model;\n if (typeof filter.model === 'string' && model !== filter.model) {\n return false;\n }\n if (filter.model instanceof RegExp && !filter.model.test(model ?? '')) {\n return false;\n }\n }\n\n if (filter.system) {\n const system = typeof body?.system === 'string' ? body.system : '';\n if (typeof filter.system === 'string' && !system.includes(filter.system)) {\n return false;\n }\n if (filter.system instanceof RegExp && !filter.system.test(system)) {\n return false;\n }\n }\n\n if (filter.user) {\n const userMsg = body?.messages?.find((m: any) => m.role === 'user')?.content ?? '';\n const text = typeof userMsg === 'string' ? userMsg : JSON.stringify(userMsg);\n if (typeof filter.user === 'string' && !text.includes(filter.user)) {\n return false;\n }\n if (filter.user instanceof RegExp && !filter.user.test(text)) {\n return false;\n }\n }\n\n if (filter.tools) {\n const requestTools = body?.tools?.map((t: any) => t.name).filter(Boolean) ?? [];\n if (!filter.tools.every((t) => requestTools.includes(t))) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Anthropic API intercept helpers.\n */\nexport const anthropic = {\n /**\n * Trigger: match Anthropic messages API requests.\n */\n messages(filter?: AnthropicMessagesFilter): InterceptTrigger {\n return {\n method: 'POST',\n url: ANTHROPIC_MESSAGES_URL,\n match: filter ? (body: unknown) => matchesFilter(body, filter) : undefined,\n };\n },\n\n /** Response: wrap data in Anthropic messages format. */\n response(data: unknown): InterceptResponse {\n const content = typeof data === 'string' ? data : JSON.stringify(data);\n return {\n status: 200,\n body: {\n id: 'msg-test',\n type: 'message',\n role: 'assistant',\n content: [{ type: 'text', text: content }],\n model: 'claude-sonnet-4-20250514',\n stop_reason: 'end_turn',\n usage: { input_tokens: 10, output_tokens: 10 },\n },\n };\n },\n\n /** Response: return an Anthropic error. */\n error(status: number, message?: string): InterceptResponse {\n return {\n status,\n body: {\n type: 'error',\n error: {\n type: status === 429 ? 'rate_limit_error' : 'api_error',\n message: message ?? `Anthropic error (${status})`,\n },\n },\n };\n },\n\n /** Response: simulate a timeout. */\n timeout(): InterceptResponse {\n return { status: 200, body: {}, delay: 30_000 };\n },\n};\n","import type { InterceptResponse, InterceptTrigger } from '../types.js';\n\n/**\n * Generic HTTP intercept helpers for any URL.\n *\n * @example\n * .intercept(http.get('https://api.example.com/data'), { body: [...] })\n * .intercept(http.post('https://api.stripe.com/v1/charges'), { body: { id: 'ch_...' } })\n */\nexport const http = {\n /** Trigger: match GET requests to a URL pattern. */\n get(url: RegExp | string): InterceptTrigger {\n return { method: 'GET', url };\n },\n\n /** Trigger: match POST requests to a URL pattern. */\n post(url: RegExp | string): InterceptTrigger {\n return { method: 'POST', url };\n },\n\n /** Trigger: match PUT requests to a URL pattern. */\n put(url: RegExp | string): InterceptTrigger {\n return { method: 'PUT', url };\n },\n\n /** Trigger: match DELETE requests to a URL pattern. */\n delete(url: RegExp | string): InterceptTrigger {\n return { method: 'DELETE', url };\n },\n\n /** Trigger: match any method to a URL pattern. */\n any(url: RegExp | string): InterceptTrigger {\n return { method: '*', url };\n },\n\n /** Response: simple JSON success. */\n json(data: unknown, status = 200): InterceptResponse {\n return { status, body: data };\n },\n\n /** Response: error with message. */\n error(status: number, message?: string): InterceptResponse {\n return { status, body: { error: message ?? `HTTP ${status}` } };\n },\n};\n","import type { InterceptResponse, InterceptTrigger } from '../types.js';\n\nconst OPENAI_CHAT_URL = 'https://api.openai.com/v1/chat/completions';\nconst OPENAI_RESPONSES_URL = 'https://api.openai.com/v1/responses';\n\nexport interface OpenAIChatFilter {\n /** Match by model name (exact string or regex). */\n model?: RegExp | string;\n /** Match by system message content (regex or substring). */\n system?: RegExp | string;\n /** Match by user message content (regex or substring). */\n user?: RegExp | string;\n /** Match by tool/function names present in the request. */\n tools?: string[];\n /** Match by temperature value. */\n temperature?: number;\n}\n\nfunction matchesFilter(body: any, filter: OpenAIChatFilter): boolean {\n if (filter.model) {\n const model = body?.model;\n if (typeof filter.model === 'string' && model !== filter.model) {\n return false;\n }\n if (filter.model instanceof RegExp && !filter.model.test(model ?? '')) {\n return false;\n }\n }\n\n if (filter.system) {\n const systemMsg = body?.messages?.find((m: any) => m.role === 'system')?.content ?? '';\n if (typeof filter.system === 'string' && !systemMsg.includes(filter.system)) {\n return false;\n }\n if (filter.system instanceof RegExp && !filter.system.test(systemMsg)) {\n return false;\n }\n }\n\n if (filter.user) {\n const userMsg = body?.messages?.find((m: any) => m.role === 'user')?.content ?? '';\n if (typeof filter.user === 'string' && !userMsg.includes(filter.user)) {\n return false;\n }\n if (filter.user instanceof RegExp && !filter.user.test(userMsg)) {\n return false;\n }\n }\n\n if (filter.tools) {\n const requestTools = body?.tools?.map((t: any) => t.function?.name).filter(Boolean) ?? [];\n if (!filter.tools.every((t) => requestTools.includes(t))) {\n return false;\n }\n }\n\n if (filter.temperature !== undefined && body?.temperature !== filter.temperature) {\n return false;\n }\n\n return true;\n}\n\n/** Responses API filter — uses `input` array instead of `messages`. */\nexport interface OpenAIResponsesFilter {\n /** Match by model name. */\n model?: RegExp | string;\n /** Match by system instruction content. */\n system?: RegExp | string;\n /** Match by user input content. */\n user?: RegExp | string;\n /** Match by tool names. */\n tools?: string[];\n}\n\nfunction matchesResponsesFilter(body: any, filter: OpenAIResponsesFilter): boolean {\n if (filter.model) {\n const model = body?.model;\n if (typeof filter.model === 'string' && model !== filter.model) {\n return false;\n }\n if (filter.model instanceof RegExp && !filter.model.test(model ?? '')) {\n return false;\n }\n }\n\n if (filter.system) {\n const instructions = body?.instructions ?? '';\n const systemInput = body?.input?.find?.((m: any) => m.role === 'system')?.content ?? '';\n const systemText = instructions || systemInput;\n if (typeof filter.system === 'string' && !systemText.includes(filter.system)) {\n return false;\n }\n if (filter.system instanceof RegExp && !filter.system.test(systemText)) {\n return false;\n }\n }\n\n if (filter.user) {\n const userInputs = (body?.input ?? [])\n .filter((m: any) => m.role === 'user')\n .map((m: any) =>\n typeof m.content === 'string' ? m.content : JSON.stringify(m.content),\n )\n .join(' ');\n if (typeof filter.user === 'string' && !userInputs.includes(filter.user)) {\n return false;\n }\n if (filter.user instanceof RegExp && !filter.user.test(userInputs)) {\n return false;\n }\n }\n\n if (filter.tools) {\n const requestTools =\n body?.tools?.map((t: any) => t.name ?? t.function?.name).filter(Boolean) ?? [];\n if (!filter.tools.every((t) => requestTools.includes(t))) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * OpenAI API intercept helpers.\n */\nexport const openai = {\n /**\n * Trigger: match OpenAI chat completion requests.\n *\n * @param filter - Optional filters to narrow which requests match.\n *\n * @example\n * openai.chat() // any chat call\n * openai.chat({ model: 'gpt-4o' }) // specific model\n * openai.chat({ system: /classify/ }) // system prompt contains \"classify\"\n * openai.chat({ tools: ['extract_facts'] }) // function calling\n */\n chat(filter?: OpenAIChatFilter): InterceptTrigger {\n return {\n method: 'POST',\n url: OPENAI_CHAT_URL,\n match: filter ? (body: unknown) => matchesFilter(body, filter) : undefined,\n };\n },\n\n /**\n * Trigger: match OpenAI Responses API requests (AI SDK v5+).\n *\n * @param filter - Optional filters. Supports custom gateway URLs.\n * @param url - Override URL for custom gateways (e.g. 'https://gateway.example.com/v1/responses').\n *\n * @example\n * openai.responses() // default URL\n * openai.responses({ user: /Report Ingestion/ }) // match by prompt content\n * openai.responses({ model: 'gpt-4o' }, 'https://my-gateway/v1/responses') // custom gateway\n */\n responses(filter?: OpenAIResponsesFilter, url?: string): InterceptTrigger {\n return {\n method: 'POST',\n url: url ?? OPENAI_RESPONSES_URL,\n match: filter ? (body: unknown) => matchesResponsesFilter(body, filter) : undefined,\n };\n },\n\n /**\n * Response: wrap data in OpenAI Responses API format (AI SDK v5+).\n *\n * @example\n * openai.responsesResponse({ categories: ['TECH'] })\n */\n responsesResponse(data: unknown): InterceptResponse {\n const text = typeof data === 'string' ? data : JSON.stringify(data);\n return {\n status: 200,\n body: {\n id: 'resp-test',\n object: 'response',\n created_at: Math.floor(Date.now() / 1000),\n model: 'gpt-4o-test',\n output: [\n {\n type: 'message',\n id: 'msg-test',\n role: 'assistant',\n content: [{ type: 'output_text', text, annotations: [] }],\n },\n ],\n usage: {\n input_tokens: 10,\n output_tokens: 10,\n total_tokens: 20,\n },\n },\n };\n },\n\n /**\n * Response: wrap data in OpenAI chat completion format.\n *\n * @param data - The content to return (will be JSON.stringified if not a string).\n *\n * @example\n * openai.response({ categories: ['TECH'] })\n */\n response(data: unknown): InterceptResponse {\n const content = typeof data === 'string' ? data : JSON.stringify(data);\n return {\n status: 200,\n body: {\n id: 'chatcmpl-test',\n object: 'chat.completion',\n created: Math.floor(Date.now() / 1000),\n model: 'gpt-4o-test',\n choices: [\n {\n index: 0,\n message: { role: 'assistant', content },\n finish_reason: 'stop',\n },\n ],\n usage: { prompt_tokens: 10, completion_tokens: 10, total_tokens: 20 },\n },\n };\n },\n\n /** Response: return an OpenAI error. */\n error(status: number, message?: string): InterceptResponse {\n return {\n status,\n body: {\n error: {\n message: message ?? `OpenAI error (${status})`,\n type: status === 429 ? 'rate_limit_error' : 'api_error',\n code: status === 429 ? 'rate_limit_exceeded' : null,\n },\n },\n };\n },\n\n /** Response: return malformed (non-JSON) content. */\n malformed(content: string): InterceptResponse {\n return {\n status: 200,\n body: {\n id: 'chatcmpl-test',\n object: 'chat.completion',\n created: Math.floor(Date.now() / 1000),\n model: 'gpt-4o-test',\n choices: [\n {\n index: 0,\n message: { role: 'assistant', content },\n finish_reason: 'stop',\n },\n ],\n usage: { prompt_tokens: 10, completion_tokens: 10, total_tokens: 20 },\n },\n };\n },\n\n /** Response: simulate a timeout (30s delay). */\n timeout(): InterceptResponse {\n return {\n status: 200,\n body: {},\n delay: 30_000,\n };\n },\n};\n"],"mappings":";;AAEA,MAAM,yBAAyB;AAa/B,SAASA,gBAAc,MAAW,QAA0C;AACxE,KAAI,OAAO,OAAO;EACd,MAAM,QAAQ,MAAM;AACpB,MAAI,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,MACrD,QAAO;AAEX,MAAI,OAAO,iBAAiB,UAAU,CAAC,OAAO,MAAM,KAAK,SAAS,GAAG,CACjE,QAAO;;AAIf,KAAI,OAAO,QAAQ;EACf,MAAM,SAAS,OAAO,MAAM,WAAW,WAAW,KAAK,SAAS;AAChE,MAAI,OAAO,OAAO,WAAW,YAAY,CAAC,OAAO,SAAS,OAAO,OAAO,CACpE,QAAO;AAEX,MAAI,OAAO,kBAAkB,UAAU,CAAC,OAAO,OAAO,KAAK,OAAO,CAC9D,QAAO;;AAIf,KAAI,OAAO,MAAM;EACb,MAAM,UAAU,MAAM,UAAU,MAAM,MAAW,EAAE,SAAS,OAAO,EAAE,WAAW;EAChF,MAAM,OAAO,OAAO,YAAY,WAAW,UAAU,KAAK,UAAU,QAAQ;AAC5E,MAAI,OAAO,OAAO,SAAS,YAAY,CAAC,KAAK,SAAS,OAAO,KAAK,CAC9D,QAAO;AAEX,MAAI,OAAO,gBAAgB,UAAU,CAAC,OAAO,KAAK,KAAK,KAAK,CACxD,QAAO;;AAIf,KAAI,OAAO,OAAO;EACd,MAAM,eAAe,MAAM,OAAO,KAAK,MAAW,EAAE,KAAK,CAAC,OAAO,QAAQ,IAAI,EAAE;AAC/E,MAAI,CAAC,OAAO,MAAM,OAAO,MAAM,aAAa,SAAS,EAAE,CAAC,CACpD,QAAO;;AAIf,QAAO;;;;;AAMX,MAAa,YAAY;CAIrB,SAAS,QAAoD;AACzD,SAAO;GACH,QAAQ;GACR,KAAK;GACL,OAAO,UAAU,SAAkBA,gBAAc,MAAM,OAAO,GAAG,KA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AAM;KACN,SAAS,CAAC;MAAE,MAAM;MAAe;MAAM,aAAa,EAAE;MAAE,CAAC;KAC5D,CACJ;IACD,OAAO;KACH,cAAc;KACd,eAAe;KACf,cAAc;KACjB;IACJ;GACJ;;CAWL,SAAS,MAAkC;EACvC,MAAM,UAAU,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,KAAK;AACtE,SAAO;GACH,QAAQ;GACR,MAAM;IACF,IAAI;IACJ,QAAQ;IACR,SAAS,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;IACtC,OAAO;IACP,SAAS,CACL;KACI,OAAO;KACP,SAAS;MAAE,MAAM;MAAa;MAAS;KACvC,eAAe;KAClB,CACJ;IACD,OAAO;KAAE,eAAe;KAAI,mBAAmB;KAAI,cAAc;KAAI;IACxE;GACJ;;CAIL,MAAM,QAAgB,SAAqC;AACvD,SAAO;GACH;GACA,MAAM,EACF,OAAO;IACH,SAAS,WAAW,iBAAiB,OAAO;IAC5C,MAAM,WAAW,MAAM,qBAAqB;IAC5C,MAAM,WAAW,MAAM,wBAAwB;IAClD,EACJ;GACJ;;CAIL,UAAU,SAAoC;AAC1C,SAAO;GACH,QAAQ;GACR,MAAM;IACF,IAAI;IACJ,QAAQ;IACR,SAAS,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;IACtC,OAAO;IACP,SAAS,CACL;KACI,OAAO;KACP,SAAS;MAAE,MAAM;MAAa;MAAS;KACvC,eAAe;KAClB,CACJ;IACD,OAAO;KAAE,eAAe;KAAI,mBAAmB;KAAI,cAAc;KAAI;IACxE;GACJ;;CAIL,UAA6B;AACzB,SAAO;GACH,QAAQ;GACR,MAAM,EAAE;GACR,OAAO;GACV;;CAER"}
|
|
1
|
+
{"version":3,"file":"intercept.cjs","names":[],"sources":["../src/builder/common/intercept/adapters/anthropic.ts","../src/builder/common/intercept/adapters/http.ts","../src/builder/common/intercept/adapters/openai.ts"],"sourcesContent":["import type { InterceptResponse, InterceptTrigger } from '../types.js';\n\nconst ANTHROPIC_MESSAGES_URL = 'https://api.anthropic.com/v1/messages';\n\nexport interface AnthropicMessagesFilter {\n model?: RegExp | string;\n system?: RegExp | string;\n user?: RegExp | string;\n tools?: string[];\n}\n\nfunction matchesFilter(body: any, filter: AnthropicMessagesFilter): boolean {\n if (filter.model) {\n const model = body?.model;\n if (typeof filter.model === 'string' && model !== filter.model) {\n return false;\n }\n if (filter.model instanceof RegExp && !filter.model.test(model ?? '')) {\n return false;\n }\n }\n if (filter.system) {\n const system = typeof body?.system === 'string' ? body.system : '';\n if (typeof filter.system === 'string' && !system.includes(filter.system)) {\n return false;\n }\n if (filter.system instanceof RegExp && !filter.system.test(system)) {\n return false;\n }\n }\n if (filter.user) {\n const userMsg = body?.messages?.find((m: any) => m.role === 'user')?.content ?? '';\n const text = typeof userMsg === 'string' ? userMsg : JSON.stringify(userMsg);\n if (typeof filter.user === 'string' && !text.includes(filter.user)) {\n return false;\n }\n if (filter.user instanceof RegExp && !filter.user.test(text)) {\n return false;\n }\n }\n if (filter.tools) {\n const names = body?.tools?.map((t: any) => t.name).filter(Boolean) ?? [];\n if (!filter.tools.every((t) => names.includes(t))) {\n return false;\n }\n }\n return true;\n}\n\nfunction buildReply(data: unknown): InterceptResponse {\n const content = typeof data === 'string' ? data : JSON.stringify(data);\n return {\n status: 200,\n body: {\n id: 'msg-test',\n type: 'message',\n role: 'assistant',\n content: [{ type: 'text', text: content }],\n model: 'claude-sonnet-4-20250514',\n stop_reason: 'end_turn',\n usage: { input_tokens: 10, output_tokens: 10 },\n },\n };\n}\n\n/**\n * Anthropic API intercept helpers.\n */\nexport const anthropic = {\n /**\n * Trigger: match Anthropic messages API requests.\n *\n * @example\n * anthropic.request()\n * anthropic.request({ system: /classify/ })\n */\n request(filter?: AnthropicMessagesFilter): InterceptTrigger {\n return {\n adapter: 'anthropic',\n method: 'POST',\n url: ANTHROPIC_MESSAGES_URL,\n match: filter ? (body: unknown) => matchesFilter(body, filter) : undefined,\n wrap: buildReply,\n };\n },\n\n /** Response: wrap data in Anthropic messages format. */\n reply: buildReply,\n\n /** Response: return an Anthropic error. */\n error(status: number, message?: string): InterceptResponse {\n return {\n status,\n body: {\n type: 'error',\n error: {\n type: status === 429 ? 'rate_limit_error' : 'api_error',\n message: message ?? `Anthropic error (${status})`,\n },\n },\n };\n },\n\n /** Response: simulate a timeout. */\n timeout(): InterceptResponse {\n return { status: 200, body: {}, delay: 30_000 };\n },\n\n // Legacy aliases\n /** @deprecated Use anthropic.request() instead. */\n messages(filter?: AnthropicMessagesFilter): InterceptTrigger {\n return anthropic.request(filter);\n },\n /** @deprecated Use anthropic.reply() instead. */\n response: buildReply,\n};\n","import type { InterceptResponse, InterceptTrigger } from '../types.js';\n\nfunction wrapJson(data: unknown): InterceptResponse {\n return { status: 200, body: data };\n}\n\n/**\n * Generic HTTP intercept helpers for any URL.\n *\n * @example\n * .intercept(http.get('https://api.example.com/data'), 'http/response.json')\n */\nexport const http = {\n get(url: RegExp | string): InterceptTrigger {\n return { adapter: 'http', method: 'GET', url, wrap: wrapJson };\n },\n\n post(url: RegExp | string): InterceptTrigger {\n return { adapter: 'http', method: 'POST', url, wrap: wrapJson };\n },\n\n put(url: RegExp | string): InterceptTrigger {\n return { adapter: 'http', method: 'PUT', url, wrap: wrapJson };\n },\n\n delete(url: RegExp | string): InterceptTrigger {\n return { adapter: 'http', method: 'DELETE', url, wrap: wrapJson };\n },\n\n any(url: RegExp | string): InterceptTrigger {\n return { adapter: 'http', method: '*', url, wrap: wrapJson };\n },\n\n /** Response: simple JSON success. */\n json(data: unknown, status = 200): InterceptResponse {\n return { status, body: data };\n },\n\n /** Response: error with message. */\n error(status: number, message?: string): InterceptResponse {\n return { status, body: { error: message ?? `HTTP ${status}` } };\n },\n};\n","import type { InterceptResponse, InterceptTrigger } from '../types.js';\n\nconst OPENAI_CHAT_URL = 'https://api.openai.com/v1/chat/completions';\nconst OPENAI_RESPONSES_URL = 'https://api.openai.com/v1/responses';\n\n// ── Chat Completions filters ──\n\nexport interface OpenAIChatFilter {\n model?: RegExp | string;\n system?: RegExp | string;\n user?: RegExp | string;\n tools?: string[];\n temperature?: number;\n}\n\nfunction matchesChatFilter(body: any, filter: OpenAIChatFilter): boolean {\n if (filter.model) {\n const model = body?.model;\n if (typeof filter.model === 'string' && model !== filter.model) {\n return false;\n }\n if (filter.model instanceof RegExp && !filter.model.test(model ?? '')) {\n return false;\n }\n }\n if (filter.system) {\n const msg = body?.messages?.find((m: any) => m.role === 'system')?.content ?? '';\n if (typeof filter.system === 'string' && !msg.includes(filter.system)) {\n return false;\n }\n if (filter.system instanceof RegExp && !filter.system.test(msg)) {\n return false;\n }\n }\n if (filter.user) {\n const msg = body?.messages?.find((m: any) => m.role === 'user')?.content ?? '';\n if (typeof filter.user === 'string' && !msg.includes(filter.user)) {\n return false;\n }\n if (filter.user instanceof RegExp && !filter.user.test(msg)) {\n return false;\n }\n }\n if (filter.tools) {\n const names = body?.tools?.map((t: any) => t.function?.name).filter(Boolean) ?? [];\n if (!filter.tools.every((t) => names.includes(t))) {\n return false;\n }\n }\n if (filter.temperature !== undefined && body?.temperature !== filter.temperature) {\n return false;\n }\n return true;\n}\n\n// ── Responses API filters ──\n\nexport interface OpenAIResponsesFilter {\n model?: RegExp | string;\n system?: RegExp | string;\n user?: RegExp | string;\n tools?: string[];\n}\n\nfunction matchesResponsesFilter(body: any, filter: OpenAIResponsesFilter): boolean {\n if (filter.model) {\n const model = body?.model;\n if (typeof filter.model === 'string' && model !== filter.model) {\n return false;\n }\n if (filter.model instanceof RegExp && !filter.model.test(model ?? '')) {\n return false;\n }\n }\n if (filter.system) {\n const instructions = body?.instructions ?? '';\n const systemInput = body?.input?.find?.((m: any) => m.role === 'system')?.content ?? '';\n const text = instructions || systemInput;\n if (typeof filter.system === 'string' && !text.includes(filter.system)) {\n return false;\n }\n if (filter.system instanceof RegExp && !filter.system.test(text)) {\n return false;\n }\n }\n if (filter.user) {\n const msgs = (body?.input ?? [])\n .filter((m: any) => m.role === 'user')\n .map((m: any) =>\n typeof m.content === 'string' ? m.content : JSON.stringify(m.content),\n )\n .join(' ');\n if (typeof filter.user === 'string' && !msgs.includes(filter.user)) {\n return false;\n }\n if (filter.user instanceof RegExp && !filter.user.test(msgs)) {\n return false;\n }\n }\n if (filter.tools) {\n const names =\n body?.tools?.map((t: any) => t.name ?? t.function?.name).filter(Boolean) ?? [];\n if (!filter.tools.every((t) => names.includes(t))) {\n return false;\n }\n }\n return true;\n}\n\n// ── Response builders ──\n\nfunction buildChatReply(data: unknown): InterceptResponse {\n const content = typeof data === 'string' ? data : JSON.stringify(data);\n return {\n status: 200,\n body: {\n id: 'chatcmpl-test',\n object: 'chat.completion',\n created: Math.floor(Date.now() / 1000),\n model: 'gpt-4o-test',\n choices: [{ index: 0, message: { role: 'assistant', content }, finish_reason: 'stop' }],\n usage: { prompt_tokens: 10, completion_tokens: 10, total_tokens: 20 },\n },\n };\n}\n\nfunction buildResponsesReply(data: unknown): InterceptResponse {\n const text = typeof data === 'string' ? data : JSON.stringify(data);\n return {\n status: 200,\n body: {\n id: 'resp-test',\n object: 'response',\n created_at: Math.floor(Date.now() / 1000),\n model: 'gpt-4o-test',\n output: [\n {\n type: 'message',\n id: 'msg-test',\n role: 'assistant',\n content: [{ type: 'output_text', text, annotations: [] }],\n },\n ],\n usage: { input_tokens: 10, output_tokens: 10, total_tokens: 20 },\n },\n };\n}\n\n// ── Public API ──\n\n/**\n * OpenAI API intercept helpers.\n */\nexport const openai = {\n /**\n * Trigger: match Chat Completions API requests.\n *\n * @example\n * openai.request() // any chat call\n * openai.request({ model: 'gpt-4o' }) // specific model\n * openai.request({ system: /classify/ }) // system prompt match\n */\n request(filter?: OpenAIChatFilter): InterceptTrigger {\n return {\n adapter: 'openai',\n method: 'POST',\n url: OPENAI_CHAT_URL,\n match: filter ? (body: unknown) => matchesChatFilter(body, filter) : undefined,\n wrap: buildChatReply,\n };\n },\n\n /**\n * Trigger: match Responses API requests (AI SDK v5+) with auto-wrapping.\n * When used with a JSON file, the data is automatically wrapped in the\n * Responses API envelope.\n *\n * @param filter - Optional body filters.\n * @param url - Custom gateway URL (default: api.openai.com).\n *\n * @example\n * openai.agent({ user: /Report Ingestion/ }, GATEWAY)\n */\n agent(filter?: OpenAIResponsesFilter, url?: string): InterceptTrigger {\n return {\n adapter: 'openai',\n method: 'POST',\n url: url ?? OPENAI_RESPONSES_URL,\n match: filter ? (body: unknown) => matchesResponsesFilter(body, filter) : undefined,\n wrap: buildResponsesReply,\n };\n },\n\n /**\n * Response: wrap data in Chat Completions format.\n *\n * @example\n * openai.reply({ categories: ['TECH'] })\n */\n reply: buildChatReply,\n\n /** Response: return an OpenAI error. */\n error(status: number, message?: string): InterceptResponse {\n return {\n status,\n body: {\n error: {\n message: message ?? `OpenAI error (${status})`,\n type: status === 429 ? 'rate_limit_error' : 'api_error',\n code: status === 429 ? 'rate_limit_exceeded' : null,\n },\n },\n };\n },\n\n /** Response: return malformed content. */\n malformed(content: string): InterceptResponse {\n return buildChatReply(content);\n },\n\n /** Response: simulate a timeout. */\n timeout(): InterceptResponse {\n return { status: 200, body: {}, delay: 30_000 };\n },\n\n // ── Legacy aliases ──\n\n /** @deprecated Use openai.request() instead. */\n chat(filter?: OpenAIChatFilter): InterceptTrigger {\n return openai.request(filter);\n },\n\n /** @deprecated Use openai.reply() instead. */\n response: buildChatReply,\n\n /** @deprecated Use openai.agent() instead. */\n responses(filter?: OpenAIResponsesFilter, url?: string): InterceptTrigger {\n return openai.agent(filter, url);\n },\n\n /** @deprecated Use openai.reply() or .intercept(trigger, 'file.json') instead. */\n responsesResponse: buildResponsesReply,\n};\n"],"mappings":";;AAEA,MAAM,yBAAyB;AAS/B,SAAS,cAAc,MAAW,QAA0C;AACxE,KAAI,OAAO,OAAO;EACd,MAAM,QAAQ,MAAM;AACpB,MAAI,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,MACrD,QAAO;AAEX,MAAI,OAAO,iBAAiB,UAAU,CAAC,OAAO,MAAM,KAAK,SAAS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K,GAAG,IAAK;GACzC,OAAO;GACP,QAAQ,CACJ;IACI,MAAM;IACN,IAAI;IACJ,MAAM;IACN,SAAS,CAAC;KAAE,MAAM;KAAe;KAAM,aAAa,EAAE;KAAE,CAAC;IAC5D,CACJ;GACD,OAAO;IAAE,cAAc;IAAI,eAAe;IAAI,cAAc;IAAI;GACnE;EACJ;;;;;AAQL,MAAa,SAAS;CASlB,QAAQ,QAA6C;AACjD,SAAO;GACH,SAAS;GACT,QAAQ;GACR,KAAK;GACL,OAAO,UAAU,SAAkB,kBAAkB,MAAM,OAAO,GAAG,KAAA;GACrE,MAAM;GACT;;CAcL,MAAM,QAAgC,KAAgC;AAClE,SAAO;GACH,SAAS;GACT,QAAQ;GACR,KAAK,OAAO;GACZ,OAAO,UAAU,SAAkB,uBAAuB,MAAM,OAAO,GAAG,KAAA;GAC1E,MAAM;GACT;;CASL,OAAO;CAGP,MAAM,QAAgB,SAAqC;AACvD,SAAO;GACH;GACA,MAAM,EACF,OAAO;IACH,SAAS,WAAW,iBAAiB,OAAO;IAC5C,MAAM,WAAW,MAAM,qBAAqB;IAC5C,MAAM,WAAW,MAAM,wBAAwB;IAClD,EACJ;GACJ;;CAIL,UAAU,SAAoC;AAC1C,SAAO,eAAe,QAAQ;;CAIlC,UAA6B;AACzB,SAAO;GAAE,QAAQ;GAAK,MAAM,EAAE;GAAE,OAAO;GAAQ;;CAMnD,KAAK,QAA6C;AAC9C,SAAO,OAAO,QAAQ,OAAO;;CAIjC,UAAU;CAGV,UAAU,QAAgC,KAAgC;AACtE,SAAO,OAAO,MAAM,QAAQ,IAAI;;CAIpC,mBAAmB;CACtB"}
|
package/dist/intercept.d.cts
CHANGED
|
@@ -2,26 +2,29 @@ import { n as InterceptResponse, r as InterceptTrigger, t as InterceptEntry } fr
|
|
|
2
2
|
|
|
3
3
|
//#region src/builder/common/intercept/adapters/anthropic.d.ts
|
|
4
4
|
interface AnthropicMessagesFilter {
|
|
5
|
-
/** Match by model name. */
|
|
6
5
|
model?: RegExp | string;
|
|
7
|
-
/** Match by system message content. */
|
|
8
6
|
system?: RegExp | string;
|
|
9
|
-
/** Match by user message content. */
|
|
10
7
|
user?: RegExp | string;
|
|
11
|
-
/** Match by tool names. */
|
|
12
8
|
tools?: string[];
|
|
13
9
|
}
|
|
10
|
+
declare function buildReply(data: unknown): InterceptResponse;
|
|
14
11
|
/**
|
|
15
12
|
* Anthropic API intercept helpers.
|
|
16
13
|
*/
|
|
17
14
|
declare const anthropic: {
|
|
18
15
|
/**
|
|
19
16
|
* Trigger: match Anthropic messages API requests.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* anthropic.request()
|
|
20
|
+
* anthropic.request({ system: /classify/ })
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
request(filter?: AnthropicMessagesFilter): InterceptTrigger; /** Response: wrap data in Anthropic messages format. */
|
|
23
|
+
reply: typeof buildReply; /** Response: return an Anthropic error. */
|
|
23
24
|
error(status: number, message?: string): InterceptResponse; /** Response: simulate a timeout. */
|
|
24
|
-
timeout(): InterceptResponse;
|
|
25
|
+
timeout(): InterceptResponse; /** @deprecated Use anthropic.request() instead. */
|
|
26
|
+
messages(filter?: AnthropicMessagesFilter): InterceptTrigger; /** @deprecated Use anthropic.reply() instead. */
|
|
27
|
+
response: typeof buildReply;
|
|
25
28
|
};
|
|
26
29
|
//#endregion
|
|
27
30
|
//#region src/builder/common/intercept/adapters/http.d.ts
|
|
@@ -29,14 +32,13 @@ declare const anthropic: {
|
|
|
29
32
|
* Generic HTTP intercept helpers for any URL.
|
|
30
33
|
*
|
|
31
34
|
* @example
|
|
32
|
-
* .intercept(http.get('https://api.example.com/data'),
|
|
33
|
-
* .intercept(http.post('https://api.stripe.com/v1/charges'), { body: { id: 'ch_...' } })
|
|
35
|
+
* .intercept(http.get('https://api.example.com/data'), 'http/response.json')
|
|
34
36
|
*/
|
|
35
37
|
declare const http: {
|
|
36
|
-
|
|
37
|
-
post(url: RegExp | string): InterceptTrigger;
|
|
38
|
-
put(url: RegExp | string): InterceptTrigger;
|
|
39
|
-
delete(url: RegExp | string): InterceptTrigger;
|
|
38
|
+
get(url: RegExp | string): InterceptTrigger;
|
|
39
|
+
post(url: RegExp | string): InterceptTrigger;
|
|
40
|
+
put(url: RegExp | string): InterceptTrigger;
|
|
41
|
+
delete(url: RegExp | string): InterceptTrigger;
|
|
40
42
|
any(url: RegExp | string): InterceptTrigger; /** Response: simple JSON success. */
|
|
41
43
|
json(data: unknown, status?: number): InterceptResponse; /** Response: error with message. */
|
|
42
44
|
error(status: number, message?: string): InterceptResponse;
|
|
@@ -44,75 +46,59 @@ declare const http: {
|
|
|
44
46
|
//#endregion
|
|
45
47
|
//#region src/builder/common/intercept/adapters/openai.d.ts
|
|
46
48
|
interface OpenAIChatFilter {
|
|
47
|
-
/** Match by model name (exact string or regex). */
|
|
48
49
|
model?: RegExp | string;
|
|
49
|
-
/** Match by system message content (regex or substring). */
|
|
50
50
|
system?: RegExp | string;
|
|
51
|
-
/** Match by user message content (regex or substring). */
|
|
52
51
|
user?: RegExp | string;
|
|
53
|
-
/** Match by tool/function names present in the request. */
|
|
54
52
|
tools?: string[];
|
|
55
|
-
/** Match by temperature value. */
|
|
56
53
|
temperature?: number;
|
|
57
54
|
}
|
|
58
|
-
/** Responses API filter — uses `input` array instead of `messages`. */
|
|
59
55
|
interface OpenAIResponsesFilter {
|
|
60
|
-
/** Match by model name. */
|
|
61
56
|
model?: RegExp | string;
|
|
62
|
-
/** Match by system instruction content. */
|
|
63
57
|
system?: RegExp | string;
|
|
64
|
-
/** Match by user input content. */
|
|
65
58
|
user?: RegExp | string;
|
|
66
|
-
/** Match by tool names. */
|
|
67
59
|
tools?: string[];
|
|
68
60
|
}
|
|
61
|
+
declare function buildChatReply(data: unknown): InterceptResponse;
|
|
62
|
+
declare function buildResponsesReply(data: unknown): InterceptResponse;
|
|
69
63
|
/**
|
|
70
64
|
* OpenAI API intercept helpers.
|
|
71
65
|
*/
|
|
72
66
|
declare const openai: {
|
|
73
67
|
/**
|
|
74
|
-
* Trigger: match
|
|
75
|
-
*
|
|
76
|
-
* @param filter - Optional filters to narrow which requests match.
|
|
68
|
+
* Trigger: match Chat Completions API requests.
|
|
77
69
|
*
|
|
78
70
|
* @example
|
|
79
|
-
* openai.
|
|
80
|
-
* openai.
|
|
81
|
-
* openai.
|
|
82
|
-
* openai.chat({ tools: ['extract_facts'] }) // function calling
|
|
71
|
+
* openai.request() // any chat call
|
|
72
|
+
* openai.request({ model: 'gpt-4o' }) // specific model
|
|
73
|
+
* openai.request({ system: /classify/ }) // system prompt match
|
|
83
74
|
*/
|
|
84
|
-
|
|
75
|
+
request(filter?: OpenAIChatFilter): InterceptTrigger;
|
|
85
76
|
/**
|
|
86
|
-
* Trigger: match
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @param url - Override URL for custom gateways (e.g. 'https://gateway.example.com/v1/responses').
|
|
77
|
+
* Trigger: match Responses API requests (AI SDK v5+) with auto-wrapping.
|
|
78
|
+
* When used with a JSON file, the data is automatically wrapped in the
|
|
79
|
+
* Responses API envelope.
|
|
90
80
|
*
|
|
91
|
-
* @
|
|
92
|
-
*
|
|
93
|
-
* openai.responses({ user: /Report Ingestion/ }) // match by prompt content
|
|
94
|
-
* openai.responses({ model: 'gpt-4o' }, 'https://my-gateway/v1/responses') // custom gateway
|
|
95
|
-
*/
|
|
96
|
-
responses(filter?: OpenAIResponsesFilter, url?: string): InterceptTrigger;
|
|
97
|
-
/**
|
|
98
|
-
* Response: wrap data in OpenAI Responses API format (AI SDK v5+).
|
|
81
|
+
* @param filter - Optional body filters.
|
|
82
|
+
* @param url - Custom gateway URL (default: api.openai.com).
|
|
99
83
|
*
|
|
100
84
|
* @example
|
|
101
|
-
* openai.
|
|
85
|
+
* openai.agent({ user: /Report Ingestion/ }, GATEWAY)
|
|
102
86
|
*/
|
|
103
|
-
|
|
87
|
+
agent(filter?: OpenAIResponsesFilter, url?: string): InterceptTrigger;
|
|
104
88
|
/**
|
|
105
|
-
* Response: wrap data in
|
|
106
|
-
*
|
|
107
|
-
* @param data - The content to return (will be JSON.stringified if not a string).
|
|
89
|
+
* Response: wrap data in Chat Completions format.
|
|
108
90
|
*
|
|
109
91
|
* @example
|
|
110
|
-
* openai.
|
|
92
|
+
* openai.reply({ categories: ['TECH'] })
|
|
111
93
|
*/
|
|
112
|
-
|
|
113
|
-
error(status: number, message?: string): InterceptResponse; /** Response: return malformed
|
|
114
|
-
malformed(content: string): InterceptResponse; /** Response: simulate a timeout
|
|
115
|
-
timeout(): InterceptResponse;
|
|
94
|
+
reply: typeof buildChatReply; /** Response: return an OpenAI error. */
|
|
95
|
+
error(status: number, message?: string): InterceptResponse; /** Response: return malformed content. */
|
|
96
|
+
malformed(content: string): InterceptResponse; /** Response: simulate a timeout. */
|
|
97
|
+
timeout(): InterceptResponse; /** @deprecated Use openai.request() instead. */
|
|
98
|
+
chat(filter?: OpenAIChatFilter): InterceptTrigger; /** @deprecated Use openai.reply() instead. */
|
|
99
|
+
response: typeof buildChatReply; /** @deprecated Use openai.agent() instead. */
|
|
100
|
+
responses(filter?: OpenAIResponsesFilter, url?: string): InterceptTrigger; /** @deprecated Use openai.reply() or .intercept(trigger, 'file.json') instead. */
|
|
101
|
+
responsesResponse: typeof buildResponsesReply;
|
|
116
102
|
};
|
|
117
103
|
//#endregion
|
|
118
104
|
export { type InterceptEntry, type InterceptResponse, type InterceptTrigger, anthropic, http, openai };
|