@relayplane/proxy 1.7.2 → 1.7.3
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/agent-tracker.d.ts +82 -0
- package/dist/agent-tracker.d.ts.map +1 -0
- package/dist/agent-tracker.js +281 -0
- package/dist/agent-tracker.js.map +1 -0
- package/dist/standalone-proxy.d.ts +18 -0
- package/dist/standalone-proxy.d.ts.map +1 -1
- package/dist/standalone-proxy.js +245 -18
- package/dist/standalone-proxy.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-Agent Cost Tracking
|
|
3
|
+
*
|
|
4
|
+
* Fingerprints agents by hashing the first 500 chars of their system prompt
|
|
5
|
+
* (SHA-256, first 12 hex chars). Maintains an agent registry at ~/.relayplane/agents.json.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export interface AgentRegistryEntry {
|
|
10
|
+
name: string;
|
|
11
|
+
fingerprint: string;
|
|
12
|
+
firstSeen: string;
|
|
13
|
+
lastSeen: string;
|
|
14
|
+
systemPromptPreview: string;
|
|
15
|
+
totalRequests: number;
|
|
16
|
+
totalCost: number;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentRegistry {
|
|
19
|
+
[fingerprint: string]: AgentRegistryEntry;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compute agent fingerprint from system prompt content.
|
|
23
|
+
* Uses first 500 chars → SHA-256 → first 12 hex chars.
|
|
24
|
+
*/
|
|
25
|
+
export declare function computeFingerprint(systemPrompt: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Extract system message text from a messages array.
|
|
28
|
+
* Returns empty string if no system message found.
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractSystemPrompt(messages: Array<{
|
|
31
|
+
role?: string;
|
|
32
|
+
content?: unknown;
|
|
33
|
+
}>): string;
|
|
34
|
+
/**
|
|
35
|
+
* Extract system prompt from an Anthropic-style request body
|
|
36
|
+
* where system is a top-level field rather than in messages.
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractSystemPromptFromBody(body: Record<string, unknown>): string;
|
|
39
|
+
/**
|
|
40
|
+
* Load agent registry from disk.
|
|
41
|
+
*/
|
|
42
|
+
export declare function loadAgentRegistry(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Flush agent registry to disk immediately.
|
|
45
|
+
*/
|
|
46
|
+
export declare function flushAgentRegistry(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Record a request for an agent. Creates registry entry if new.
|
|
49
|
+
* Returns the fingerprint and resolved agentId.
|
|
50
|
+
*/
|
|
51
|
+
export declare function trackAgent(systemPrompt: string, costUsd: number, explicitAgentId?: string): {
|
|
52
|
+
fingerprint: string;
|
|
53
|
+
agentId: string | undefined;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Update cost for an agent after response is received.
|
|
57
|
+
*/
|
|
58
|
+
export declare function updateAgentCost(fingerprint: string, costUsd: number): void;
|
|
59
|
+
/**
|
|
60
|
+
* Rename an agent in the registry.
|
|
61
|
+
*/
|
|
62
|
+
export declare function renameAgent(fingerprint: string, newName: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Get the full agent registry.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getAgentRegistry(): AgentRegistry;
|
|
67
|
+
/**
|
|
68
|
+
* Get agent registry with cost summaries from request history.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getAgentSummaries(requestHistory: Array<{
|
|
71
|
+
agentFingerprint?: string;
|
|
72
|
+
costUsd: number;
|
|
73
|
+
timestamp: string;
|
|
74
|
+
}>): Array<AgentRegistryEntry & {
|
|
75
|
+
costFromHistory: number;
|
|
76
|
+
requestsFromHistory: number;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Reset registry (for testing).
|
|
80
|
+
*/
|
|
81
|
+
export declare function _resetForTesting(): void;
|
|
82
|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AM,GAAG,IAAI,CAM1E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAMzE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,KAAK,CAAC;IAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,GACvF,KAAK,CAAC,kBAAkB,GAAG;IAAE,eAAe,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,CAAC,CA0CtF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAKvC"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Per-Agent Cost Tracking
|
|
4
|
+
*
|
|
5
|
+
* Fingerprints agents by hashing the first 500 chars of their system prompt
|
|
6
|
+
* (SHA-256, first 12 hex chars). Maintains an agent registry at ~/.relayplane/agents.json.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
22
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
23
|
+
}) : function(o, v) {
|
|
24
|
+
o["default"] = v;
|
|
25
|
+
});
|
|
26
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
27
|
+
var ownKeys = function(o) {
|
|
28
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
29
|
+
var ar = [];
|
|
30
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
31
|
+
return ar;
|
|
32
|
+
};
|
|
33
|
+
return ownKeys(o);
|
|
34
|
+
};
|
|
35
|
+
return function (mod) {
|
|
36
|
+
if (mod && mod.__esModule) return mod;
|
|
37
|
+
var result = {};
|
|
38
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
39
|
+
__setModuleDefault(result, mod);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
})();
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.computeFingerprint = computeFingerprint;
|
|
45
|
+
exports.extractSystemPrompt = extractSystemPrompt;
|
|
46
|
+
exports.extractSystemPromptFromBody = extractSystemPromptFromBody;
|
|
47
|
+
exports.loadAgentRegistry = loadAgentRegistry;
|
|
48
|
+
exports.flushAgentRegistry = flushAgentRegistry;
|
|
49
|
+
exports.trackAgent = trackAgent;
|
|
50
|
+
exports.updateAgentCost = updateAgentCost;
|
|
51
|
+
exports.renameAgent = renameAgent;
|
|
52
|
+
exports.getAgentRegistry = getAgentRegistry;
|
|
53
|
+
exports.getAgentSummaries = getAgentSummaries;
|
|
54
|
+
exports._resetForTesting = _resetForTesting;
|
|
55
|
+
const crypto = __importStar(require("node:crypto"));
|
|
56
|
+
const fs = __importStar(require("node:fs"));
|
|
57
|
+
const path = __importStar(require("node:path"));
|
|
58
|
+
const os = __importStar(require("node:os"));
|
|
59
|
+
const REGISTRY_DIR = path.join(os.homedir(), '.relayplane');
|
|
60
|
+
const REGISTRY_FILE = path.join(REGISTRY_DIR, 'agents.json');
|
|
61
|
+
let agentRegistry = {};
|
|
62
|
+
let nextAgentNumber = 1;
|
|
63
|
+
let registryDirty = false;
|
|
64
|
+
let flushTimer = null;
|
|
65
|
+
/**
|
|
66
|
+
* Compute agent fingerprint from system prompt content.
|
|
67
|
+
* Uses first 500 chars → SHA-256 → first 12 hex chars.
|
|
68
|
+
*/
|
|
69
|
+
function computeFingerprint(systemPrompt) {
|
|
70
|
+
const input = systemPrompt.slice(0, 500);
|
|
71
|
+
const hash = crypto.createHash('sha256').update(input).digest('hex');
|
|
72
|
+
return hash.slice(0, 12);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Extract system message text from a messages array.
|
|
76
|
+
* Returns empty string if no system message found.
|
|
77
|
+
*/
|
|
78
|
+
function extractSystemPrompt(messages) {
|
|
79
|
+
if (!messages || !Array.isArray(messages))
|
|
80
|
+
return '';
|
|
81
|
+
for (const msg of messages) {
|
|
82
|
+
if (msg.role === 'system') {
|
|
83
|
+
if (typeof msg.content === 'string')
|
|
84
|
+
return msg.content;
|
|
85
|
+
if (Array.isArray(msg.content)) {
|
|
86
|
+
return msg.content
|
|
87
|
+
.map((part) => {
|
|
88
|
+
const p = part;
|
|
89
|
+
return p.type === 'text' ? (p.text ?? '') : '';
|
|
90
|
+
})
|
|
91
|
+
.join('');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Extract system prompt from an Anthropic-style request body
|
|
99
|
+
* where system is a top-level field rather than in messages.
|
|
100
|
+
*/
|
|
101
|
+
function extractSystemPromptFromBody(body) {
|
|
102
|
+
// Check top-level 'system' field (Anthropic native format)
|
|
103
|
+
if (typeof body.system === 'string')
|
|
104
|
+
return body.system;
|
|
105
|
+
if (Array.isArray(body.system)) {
|
|
106
|
+
return body.system
|
|
107
|
+
.map(p => p.type === 'text' ? (p.text ?? '') : (typeof p === 'string' ? p : ''))
|
|
108
|
+
.join('');
|
|
109
|
+
}
|
|
110
|
+
// Check messages array (OpenAI format)
|
|
111
|
+
if (Array.isArray(body.messages)) {
|
|
112
|
+
return extractSystemPrompt(body.messages);
|
|
113
|
+
}
|
|
114
|
+
return '';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Load agent registry from disk.
|
|
118
|
+
*/
|
|
119
|
+
function loadAgentRegistry() {
|
|
120
|
+
try {
|
|
121
|
+
if (fs.existsSync(REGISTRY_FILE)) {
|
|
122
|
+
const data = fs.readFileSync(REGISTRY_FILE, 'utf-8');
|
|
123
|
+
agentRegistry = JSON.parse(data);
|
|
124
|
+
// Compute next agent number from existing names
|
|
125
|
+
for (const entry of Object.values(agentRegistry)) {
|
|
126
|
+
const match = entry.name.match(/^Agent (\d+)$/);
|
|
127
|
+
if (match) {
|
|
128
|
+
const num = parseInt(match[1], 10);
|
|
129
|
+
if (num >= nextAgentNumber)
|
|
130
|
+
nextAgentNumber = num + 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
agentRegistry = {};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Save agent registry to disk (debounced).
|
|
141
|
+
*/
|
|
142
|
+
function scheduleFlush() {
|
|
143
|
+
registryDirty = true;
|
|
144
|
+
if (flushTimer)
|
|
145
|
+
return;
|
|
146
|
+
flushTimer = setTimeout(() => {
|
|
147
|
+
flushTimer = null;
|
|
148
|
+
flushAgentRegistry();
|
|
149
|
+
}, 5000);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Flush agent registry to disk immediately.
|
|
153
|
+
*/
|
|
154
|
+
function flushAgentRegistry() {
|
|
155
|
+
if (!registryDirty)
|
|
156
|
+
return;
|
|
157
|
+
try {
|
|
158
|
+
fs.mkdirSync(REGISTRY_DIR, { recursive: true });
|
|
159
|
+
fs.writeFileSync(REGISTRY_FILE, JSON.stringify(agentRegistry, null, 2), 'utf-8');
|
|
160
|
+
registryDirty = false;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// Silent failure — don't break the proxy
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Record a request for an agent. Creates registry entry if new.
|
|
168
|
+
* Returns the fingerprint and resolved agentId.
|
|
169
|
+
*/
|
|
170
|
+
function trackAgent(systemPrompt, costUsd, explicitAgentId) {
|
|
171
|
+
if (!systemPrompt) {
|
|
172
|
+
return { fingerprint: 'unknown', agentId: explicitAgentId };
|
|
173
|
+
}
|
|
174
|
+
const fingerprint = computeFingerprint(systemPrompt);
|
|
175
|
+
const now = new Date().toISOString();
|
|
176
|
+
if (!agentRegistry[fingerprint]) {
|
|
177
|
+
agentRegistry[fingerprint] = {
|
|
178
|
+
name: `Agent ${nextAgentNumber++}`,
|
|
179
|
+
fingerprint,
|
|
180
|
+
firstSeen: now,
|
|
181
|
+
lastSeen: now,
|
|
182
|
+
systemPromptPreview: systemPrompt.slice(0, 80),
|
|
183
|
+
totalRequests: 0,
|
|
184
|
+
totalCost: 0,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const entry = agentRegistry[fingerprint];
|
|
188
|
+
entry.lastSeen = now;
|
|
189
|
+
entry.totalRequests++;
|
|
190
|
+
entry.totalCost += costUsd;
|
|
191
|
+
// If explicit agentId provided, use it as the name (first time only, don't override user renames)
|
|
192
|
+
if (explicitAgentId && entry.name.startsWith('Agent ')) {
|
|
193
|
+
entry.name = explicitAgentId;
|
|
194
|
+
}
|
|
195
|
+
scheduleFlush();
|
|
196
|
+
return { fingerprint, agentId: explicitAgentId };
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Update cost for an agent after response is received.
|
|
200
|
+
*/
|
|
201
|
+
function updateAgentCost(fingerprint, costUsd) {
|
|
202
|
+
const entry = agentRegistry[fingerprint];
|
|
203
|
+
if (entry) {
|
|
204
|
+
entry.totalCost += costUsd;
|
|
205
|
+
scheduleFlush();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Rename an agent in the registry.
|
|
210
|
+
*/
|
|
211
|
+
function renameAgent(fingerprint, newName) {
|
|
212
|
+
const entry = agentRegistry[fingerprint];
|
|
213
|
+
if (!entry)
|
|
214
|
+
return false;
|
|
215
|
+
entry.name = newName;
|
|
216
|
+
scheduleFlush();
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Get the full agent registry.
|
|
221
|
+
*/
|
|
222
|
+
function getAgentRegistry() {
|
|
223
|
+
return agentRegistry;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Get agent registry with cost summaries from request history.
|
|
227
|
+
*/
|
|
228
|
+
function getAgentSummaries(requestHistory) {
|
|
229
|
+
// Aggregate from history
|
|
230
|
+
const historyStats = new Map();
|
|
231
|
+
for (const r of requestHistory) {
|
|
232
|
+
const fp = r.agentFingerprint ?? 'unknown';
|
|
233
|
+
const existing = historyStats.get(fp) ?? { cost: 0, requests: 0, lastActive: '' };
|
|
234
|
+
existing.cost += r.costUsd;
|
|
235
|
+
existing.requests++;
|
|
236
|
+
if (r.timestamp > existing.lastActive)
|
|
237
|
+
existing.lastActive = r.timestamp;
|
|
238
|
+
historyStats.set(fp, existing);
|
|
239
|
+
}
|
|
240
|
+
const results = [];
|
|
241
|
+
// Include all registered agents
|
|
242
|
+
for (const [fp, entry] of Object.entries(agentRegistry)) {
|
|
243
|
+
const hs = historyStats.get(fp) ?? { cost: 0, requests: 0, lastActive: '' };
|
|
244
|
+
results.push({
|
|
245
|
+
...entry,
|
|
246
|
+
costFromHistory: hs.cost,
|
|
247
|
+
requestsFromHistory: hs.requests,
|
|
248
|
+
});
|
|
249
|
+
historyStats.delete(fp);
|
|
250
|
+
}
|
|
251
|
+
// Include unregistered fingerprints from history
|
|
252
|
+
for (const [fp, hs] of historyStats) {
|
|
253
|
+
if (fp === 'unknown')
|
|
254
|
+
continue;
|
|
255
|
+
results.push({
|
|
256
|
+
name: fp,
|
|
257
|
+
fingerprint: fp,
|
|
258
|
+
firstSeen: hs.lastActive,
|
|
259
|
+
lastSeen: hs.lastActive,
|
|
260
|
+
systemPromptPreview: '',
|
|
261
|
+
totalRequests: hs.requests,
|
|
262
|
+
totalCost: hs.cost,
|
|
263
|
+
costFromHistory: hs.cost,
|
|
264
|
+
requestsFromHistory: hs.requests,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
return results;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Reset registry (for testing).
|
|
271
|
+
*/
|
|
272
|
+
function _resetForTesting() {
|
|
273
|
+
agentRegistry = {};
|
|
274
|
+
nextAgentNumber = 1;
|
|
275
|
+
registryDirty = false;
|
|
276
|
+
if (flushTimer) {
|
|
277
|
+
clearTimeout(flushTimer);
|
|
278
|
+
flushTimer = null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=agent-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tracker.js","sourceRoot":"","sources":["../src/agent-tracker.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCH,gDAIC;AAMD,kDAgBC;AAMD,kEAaC;AAKD,8CAiBC;AAiBD,gDASC;AAMD,gCAqCC;AAKD,0CAMC;AAKD,kCAMC;AAKD,4CAEC;AAKD,8CA4CC;AAKD,4CAKC;AA/PD,oDAAsC;AACtC,4CAA8B;AAC9B,gDAAkC;AAClC,4CAA8B;AAgB9B,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,aAAa,CAAC,CAAC;AAC5D,MAAM,aAAa,GAAG,IAAI,CA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AM,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED,iDAAiD;IACjD,KAAK,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,YAAY,EAAE,CAAC;QACpC,IAAI,EAAE,KAAK,SAAS;YAAE,SAAS;QAC/B,OAAO,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,EAAE;YACR,WAAW,EAAE,EAAE;YACf,SAAS,EAAE,EAAE,CAAC,UAAU;YACxB,QAAQ,EAAE,EAAE,CAAC,UAAU;YACvB,mBAAmB,EAAE,EAAE;YACvB,aAAa,EAAE,EAAE,CAAC,QAAQ;YAC1B,SAAS,EAAE,EAAE,CAAC,IAAI;YAClB,eAAe,EAAE,EAAE,CAAC,IAAI;YACxB,mBAAmB,EAAE,EAAE,CAAC,QAAQ;SACjC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,aAAa,GAAG,EAAE,CAAC;IACnB,eAAe,GAAG,CAAC,CAAC;IACpB,aAAa,GAAG,KAAK,CAAC;IACtB,IAAI,UAAU,EAAE,CAAC;QAAC,YAAY,CAAC,UAAU,CAAC,CAAC;QAAC,UAAU,GAAG,IAAI,CAAC;IAAC,CAAC;AAClE,CAAC"}
|
|
@@ -92,6 +92,24 @@ export interface ProxyConfig {
|
|
|
92
92
|
*/
|
|
93
93
|
anthropicAuth?: 'passthrough' | 'env' | 'auto';
|
|
94
94
|
}
|
|
95
|
+
/** Rolling request history for telemetry endpoints (max 10000 entries) */
|
|
96
|
+
export interface RequestContentData {
|
|
97
|
+
systemPrompt?: string;
|
|
98
|
+
userMessage?: string;
|
|
99
|
+
responsePreview?: string;
|
|
100
|
+
fullResponse?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Extract request content for logging. Handles Anthropic and OpenAI formats.
|
|
104
|
+
*/
|
|
105
|
+
export declare function extractRequestContent(body: Record<string, unknown>, isAnthropic: boolean): {
|
|
106
|
+
systemPrompt?: string;
|
|
107
|
+
userMessage?: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Extract assistant response text from response payload.
|
|
111
|
+
*/
|
|
112
|
+
export declare function extractResponseText(responseData: Record<string, unknown>, isAnthropic: boolean): string;
|
|
95
113
|
export declare function parseModelSuffix(model: string): ParsedModel;
|
|
96
114
|
export declare function classifyComplexity(messages: Array<{
|
|
97
115
|
role?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone-proxy.d.ts","sourceRoot":"","sources":["../src/standalone-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAOlC,OAAO,KAAK,EAAE,QAAQ,IAAI,YAAY,EAAY,MAAM,kBAAkB,CAAC;AAE3E,KAAK,QAAQ,GAAG,YAAY,GACxB,YAAY,GACZ,UAAU,GACV,MAAM,GACN,SAAS,GACT,UAAU,GACV,WAAW,GACX,YAAY,CAAC;AAMjB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"standalone-proxy.d.ts","sourceRoot":"","sources":["../src/standalone-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAOlC,OAAO,KAAK,EAAE,QAAQ,IAAI,YAAY,EAAY,MAAM,kBAAkB,CAAC;AAE3E,KAAK,QAAQ,GAAG,YAAY,GACxB,YAAY,GACZ,UAAU,GACV,MAAM,GACN,SAAS,GACT,UAAU,GACV,WAAW,GACX,YAAY,CAAC;AAMjB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAkD5C,2DAA2D;AAC3D,eAAO,MAAM,mBAAmB,gBAAuB,CAAC;AAuBxD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAA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