@axonflow/sdk 1.0.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 +386 -0
- package/dist/cjs/client.d.ts +60 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +364 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interceptors/anthropic.d.ts +16 -0
- package/dist/cjs/interceptors/anthropic.d.ts.map +1 -0
- package/dist/cjs/interceptors/anthropic.js +74 -0
- package/dist/cjs/interceptors/anthropic.js.map +1 -0
- package/dist/cjs/interceptors/base.d.ts +23 -0
- package/dist/cjs/interceptors/base.d.ts.map +1 -0
- package/dist/cjs/interceptors/base.js +10 -0
- package/dist/cjs/interceptors/base.js.map +1 -0
- package/dist/cjs/interceptors/openai.d.ts +16 -0
- package/dist/cjs/interceptors/openai.d.ts.map +1 -0
- package/dist/cjs/interceptors/openai.js +73 -0
- package/dist/cjs/interceptors/openai.js.map +1 -0
- package/dist/cjs/types/config.d.ts +62 -0
- package/dist/cjs/types/config.d.ts.map +1 -0
- package/dist/cjs/types/config.js +3 -0
- package/dist/cjs/types/config.js.map +1 -0
- package/dist/cjs/types/connector.d.ts +31 -0
- package/dist/cjs/types/connector.d.ts.map +1 -0
- package/dist/cjs/types/connector.js +6 -0
- package/dist/cjs/types/connector.js.map +1 -0
- package/dist/cjs/types/index.d.ts +7 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/index.js +23 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/planning.d.ts +29 -0
- package/dist/cjs/types/planning.d.ts.map +1 -0
- package/dist/cjs/types/planning.js +6 -0
- package/dist/cjs/types/planning.js.map +1 -0
- package/dist/cjs/types/policy.d.ts +48 -0
- package/dist/cjs/types/policy.d.ts.map +1 -0
- package/dist/cjs/types/policy.js +3 -0
- package/dist/cjs/types/policy.js.map +1 -0
- package/dist/cjs/types/request.d.ts +56 -0
- package/dist/cjs/types/request.d.ts.map +1 -0
- package/dist/cjs/types/request.js +3 -0
- package/dist/cjs/types/request.js.map +1 -0
- package/dist/cjs/types/response.d.ts +82 -0
- package/dist/cjs/types/response.d.ts.map +1 -0
- package/dist/cjs/types/response.js +3 -0
- package/dist/cjs/types/response.js.map +1 -0
- package/dist/cjs/utils/helpers.d.ts +25 -0
- package/dist/cjs/utils/helpers.d.ts.map +1 -0
- package/dist/cjs/utils/helpers.js +54 -0
- package/dist/cjs/utils/helpers.js.map +1 -0
- package/dist/esm/client.d.ts +60 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +360 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interceptors/anthropic.d.ts +16 -0
- package/dist/esm/interceptors/anthropic.d.ts.map +1 -0
- package/dist/esm/interceptors/anthropic.js +69 -0
- package/dist/esm/interceptors/anthropic.js.map +1 -0
- package/dist/esm/interceptors/base.d.ts +23 -0
- package/dist/esm/interceptors/base.d.ts.map +1 -0
- package/dist/esm/interceptors/base.js +6 -0
- package/dist/esm/interceptors/base.js.map +1 -0
- package/dist/esm/interceptors/openai.d.ts +16 -0
- package/dist/esm/interceptors/openai.d.ts.map +1 -0
- package/dist/esm/interceptors/openai.js +68 -0
- package/dist/esm/interceptors/openai.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/types/config.d.ts +62 -0
- package/dist/esm/types/config.d.ts.map +1 -0
- package/dist/esm/types/config.js +2 -0
- package/dist/esm/types/config.js.map +1 -0
- package/dist/esm/types/connector.d.ts +31 -0
- package/dist/esm/types/connector.d.ts.map +1 -0
- package/dist/esm/types/connector.js +5 -0
- package/dist/esm/types/connector.js.map +1 -0
- package/dist/esm/types/index.d.ts +7 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/index.js +7 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/planning.d.ts +29 -0
- package/dist/esm/types/planning.d.ts.map +1 -0
- package/dist/esm/types/planning.js +5 -0
- package/dist/esm/types/planning.js.map +1 -0
- package/dist/esm/types/policy.d.ts +48 -0
- package/dist/esm/types/policy.d.ts.map +1 -0
- package/dist/esm/types/policy.js +2 -0
- package/dist/esm/types/policy.js.map +1 -0
- package/dist/esm/types/request.d.ts +56 -0
- package/dist/esm/types/request.d.ts.map +1 -0
- package/dist/esm/types/request.js +2 -0
- package/dist/esm/types/request.js.map +1 -0
- package/dist/esm/types/response.d.ts +82 -0
- package/dist/esm/types/response.d.ts.map +1 -0
- package/dist/esm/types/response.js +2 -0
- package/dist/esm/types/response.js.map +1 -0
- package/dist/esm/utils/helpers.d.ts +25 -0
- package/dist/esm/utils/helpers.d.ts.map +1 -0
- package/dist/esm/utils/helpers.js +46 -0
- package/dist/esm/utils/helpers.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAId,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAMjB;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,YAAY,CAAyB;gBAEjC,MAAM,EAAE,cAAc;IAwBlC;;;;OAIG;IACG,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAqD5D;;OAEG;YACW,cAAc;IAiB5B;;OAEG;YACW,aAAa;IAuD3B;;OAEG;YACW,QAAQ;IAYtB;;OAEG;IACH,OAAO,CAAC,eAAe;IAMvB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,MAAM,GAAE,MAAmB,GAAG,QAAQ;IASrD;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAqBpD;;OAEG;IACG,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBvE;;OAEG;IACG,cAAc,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC;IA0CpG;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IA6CzE;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAyCjE;;OAEG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAwBpE"}
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { OpenAIInterceptor } from './interceptors/openai.js';
|
|
2
|
+
import { AnthropicInterceptor } from './interceptors/anthropic.js';
|
|
3
|
+
import { generateRequestId, debugLog } from './utils/helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Main AxonFlow client for invisible AI governance
|
|
6
|
+
*/
|
|
7
|
+
export class AxonFlow {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.interceptors = [];
|
|
10
|
+
// Set defaults
|
|
11
|
+
this.config = {
|
|
12
|
+
apiKey: config.apiKey,
|
|
13
|
+
endpoint: config.endpoint || 'https://staging-eu.getaxonflow.com',
|
|
14
|
+
mode: config.mode || 'production',
|
|
15
|
+
tenant: config.tenant || 'default',
|
|
16
|
+
debug: config.debug || false,
|
|
17
|
+
timeout: config.timeout || 30000,
|
|
18
|
+
retry: config.retry || { enabled: true, maxAttempts: 3, delay: 1000 },
|
|
19
|
+
cache: config.cache || { enabled: true, ttl: 60000 }
|
|
20
|
+
};
|
|
21
|
+
// Initialize interceptors
|
|
22
|
+
this.interceptors = [
|
|
23
|
+
new OpenAIInterceptor(),
|
|
24
|
+
new AnthropicInterceptor()
|
|
25
|
+
];
|
|
26
|
+
if (this.config.debug) {
|
|
27
|
+
debugLog('AxonFlow initialized', { mode: this.config.mode, endpoint: this.config.endpoint });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Main method to protect AI calls with governance
|
|
32
|
+
* @param aiCall The AI call to protect
|
|
33
|
+
* @returns The AI response after governance
|
|
34
|
+
*/
|
|
35
|
+
async protect(aiCall) {
|
|
36
|
+
try {
|
|
37
|
+
// Extract request details from the AI call
|
|
38
|
+
const aiRequest = await this.extractRequest(aiCall);
|
|
39
|
+
if (this.config.debug) {
|
|
40
|
+
debugLog('Protecting AI call', { provider: aiRequest.provider, model: aiRequest.model });
|
|
41
|
+
}
|
|
42
|
+
// Create governance request
|
|
43
|
+
const governanceRequest = {
|
|
44
|
+
requestId: generateRequestId(),
|
|
45
|
+
timestamp: Date.now(),
|
|
46
|
+
aiRequest,
|
|
47
|
+
mode: this.config.mode,
|
|
48
|
+
tenant: this.config.tenant
|
|
49
|
+
};
|
|
50
|
+
// Check policies with AxonFlow Agent
|
|
51
|
+
const governanceResponse = await this.checkPolicies(governanceRequest);
|
|
52
|
+
// If denied, throw error
|
|
53
|
+
if (!governanceResponse.allowed) {
|
|
54
|
+
const violation = governanceResponse.violations?.[0];
|
|
55
|
+
throw new Error(`Request blocked by AxonFlow: ${violation?.description || 'Policy violation'}`);
|
|
56
|
+
}
|
|
57
|
+
// Execute the AI call (possibly with modifications)
|
|
58
|
+
const modifiedCall = governanceResponse.modifiedRequest
|
|
59
|
+
? () => Promise.resolve(governanceResponse.modifiedRequest)
|
|
60
|
+
: aiCall;
|
|
61
|
+
const result = await modifiedCall();
|
|
62
|
+
// Log audit trail
|
|
63
|
+
await this.logAudit(governanceResponse);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (this.config.debug) {
|
|
68
|
+
debugLog('Error in protect()', error);
|
|
69
|
+
}
|
|
70
|
+
// In production, fail open (allow the call) if AxonFlow is unavailable
|
|
71
|
+
if (this.config.mode === 'production' && this.isAxonFlowError(error)) {
|
|
72
|
+
console.warn('AxonFlow unavailable, failing open');
|
|
73
|
+
return aiCall();
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Extract request details from an AI call
|
|
80
|
+
*/
|
|
81
|
+
async extractRequest(aiCall) {
|
|
82
|
+
// Try each interceptor to see if it can handle this call
|
|
83
|
+
for (const interceptor of this.interceptors) {
|
|
84
|
+
if (interceptor.canHandle(aiCall)) {
|
|
85
|
+
return interceptor.extractRequest(aiCall);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Generic extraction if no specific interceptor matches
|
|
89
|
+
return {
|
|
90
|
+
provider: 'unknown',
|
|
91
|
+
model: 'unknown',
|
|
92
|
+
prompt: aiCall.toString(),
|
|
93
|
+
parameters: {}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Check policies with AxonFlow Agent
|
|
98
|
+
*/
|
|
99
|
+
async checkPolicies(request) {
|
|
100
|
+
const url = `${this.config.endpoint}/api/request`;
|
|
101
|
+
// Transform SDK request to Agent API format
|
|
102
|
+
const agentRequest = {
|
|
103
|
+
query: request.aiRequest.prompt,
|
|
104
|
+
user_token: this.config.apiKey,
|
|
105
|
+
client_id: this.config.tenant,
|
|
106
|
+
request_type: 'llm_chat',
|
|
107
|
+
context: {
|
|
108
|
+
provider: request.aiRequest.provider,
|
|
109
|
+
model: request.aiRequest.model,
|
|
110
|
+
parameters: request.aiRequest.parameters,
|
|
111
|
+
requestId: request.requestId,
|
|
112
|
+
mode: this.config.mode
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const response = await fetch(url, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
headers: {
|
|
118
|
+
'Content-Type': 'application/json'
|
|
119
|
+
},
|
|
120
|
+
body: JSON.stringify(agentRequest),
|
|
121
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
122
|
+
});
|
|
123
|
+
if (!response.ok) {
|
|
124
|
+
const errorText = await response.text();
|
|
125
|
+
throw new Error(`AxonFlow API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
126
|
+
}
|
|
127
|
+
const agentResponse = await response.json();
|
|
128
|
+
// Transform Agent API response to SDK format
|
|
129
|
+
return {
|
|
130
|
+
requestId: request.requestId,
|
|
131
|
+
allowed: !agentResponse.blocked,
|
|
132
|
+
violations: agentResponse.blocked ? [{
|
|
133
|
+
type: 'security',
|
|
134
|
+
severity: 'high',
|
|
135
|
+
description: agentResponse.block_reason || 'Request blocked by policy',
|
|
136
|
+
policy: 'agent-policy',
|
|
137
|
+
action: 'blocked'
|
|
138
|
+
}] : [],
|
|
139
|
+
modifiedRequest: agentResponse.data,
|
|
140
|
+
policies: [],
|
|
141
|
+
audit: {
|
|
142
|
+
timestamp: Date.now(),
|
|
143
|
+
duration: parseInt(agentResponse.policy_info?.processing_time?.replace('ms', '') || '0'),
|
|
144
|
+
tenant: this.config.tenant
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Log audit trail
|
|
150
|
+
*/
|
|
151
|
+
async logAudit(response) {
|
|
152
|
+
// Audit logging is handled server-side by the Agent
|
|
153
|
+
// Just log locally if debug mode is enabled
|
|
154
|
+
if (this.config.debug) {
|
|
155
|
+
debugLog('Request processed', {
|
|
156
|
+
allowed: response.allowed,
|
|
157
|
+
violations: response.violations?.length || 0,
|
|
158
|
+
duration: response.audit.duration
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Check if an error is from AxonFlow (vs the AI provider)
|
|
164
|
+
*/
|
|
165
|
+
isAxonFlowError(error) {
|
|
166
|
+
return error?.message?.includes('AxonFlow') ||
|
|
167
|
+
error?.message?.includes('governance') ||
|
|
168
|
+
error?.message?.includes('fetch');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Create a sandbox client for testing
|
|
172
|
+
*/
|
|
173
|
+
static sandbox(apiKey = 'demo-key') {
|
|
174
|
+
return new AxonFlow({
|
|
175
|
+
apiKey,
|
|
176
|
+
mode: 'sandbox',
|
|
177
|
+
endpoint: 'https://staging-eu.getaxonflow.com',
|
|
178
|
+
debug: true
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* List all available MCP connectors from the marketplace
|
|
183
|
+
*/
|
|
184
|
+
async listConnectors() {
|
|
185
|
+
const url = `${this.config.endpoint}/api/connectors`;
|
|
186
|
+
const response = await fetch(url, {
|
|
187
|
+
method: 'GET',
|
|
188
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
189
|
+
});
|
|
190
|
+
if (!response.ok) {
|
|
191
|
+
throw new Error(`Failed to list connectors: ${response.status} ${response.statusText}`);
|
|
192
|
+
}
|
|
193
|
+
const connectors = await response.json();
|
|
194
|
+
if (this.config.debug) {
|
|
195
|
+
debugLog('Listed connectors', { count: connectors.length });
|
|
196
|
+
}
|
|
197
|
+
return connectors;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Install an MCP connector from the marketplace
|
|
201
|
+
*/
|
|
202
|
+
async installConnector(request) {
|
|
203
|
+
const url = `${this.config.endpoint}/api/connectors/install`;
|
|
204
|
+
const response = await fetch(url, {
|
|
205
|
+
method: 'POST',
|
|
206
|
+
headers: {
|
|
207
|
+
'Content-Type': 'application/json',
|
|
208
|
+
'X-Client-Secret': this.config.apiKey
|
|
209
|
+
},
|
|
210
|
+
body: JSON.stringify(request),
|
|
211
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
212
|
+
});
|
|
213
|
+
if (!response.ok) {
|
|
214
|
+
const errorText = await response.text();
|
|
215
|
+
throw new Error(`Failed to install connector: ${response.status} ${response.statusText} - ${errorText}`);
|
|
216
|
+
}
|
|
217
|
+
if (this.config.debug) {
|
|
218
|
+
debugLog('Connector installed', { name: request.name });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Execute a query against an installed MCP connector
|
|
223
|
+
*/
|
|
224
|
+
async queryConnector(connectorName, query, params) {
|
|
225
|
+
const agentRequest = {
|
|
226
|
+
query,
|
|
227
|
+
user_token: this.config.apiKey,
|
|
228
|
+
client_id: this.config.tenant,
|
|
229
|
+
request_type: 'mcp-query',
|
|
230
|
+
context: {
|
|
231
|
+
connector: connectorName,
|
|
232
|
+
params: params || {}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
const url = `${this.config.endpoint}/api/request`;
|
|
236
|
+
const response = await fetch(url, {
|
|
237
|
+
method: 'POST',
|
|
238
|
+
headers: {
|
|
239
|
+
'Content-Type': 'application/json'
|
|
240
|
+
},
|
|
241
|
+
body: JSON.stringify(agentRequest),
|
|
242
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
243
|
+
});
|
|
244
|
+
if (!response.ok) {
|
|
245
|
+
const errorText = await response.text();
|
|
246
|
+
throw new Error(`Connector query failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
247
|
+
}
|
|
248
|
+
const agentResponse = await response.json();
|
|
249
|
+
if (this.config.debug) {
|
|
250
|
+
debugLog('Connector query executed', { connector: connectorName });
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
success: agentResponse.success,
|
|
254
|
+
data: agentResponse.data,
|
|
255
|
+
error: agentResponse.error,
|
|
256
|
+
meta: agentResponse.metadata
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Generate a multi-agent execution plan from a natural language query
|
|
261
|
+
*/
|
|
262
|
+
async generatePlan(query, domain) {
|
|
263
|
+
const agentRequest = {
|
|
264
|
+
query,
|
|
265
|
+
user_token: this.config.apiKey,
|
|
266
|
+
client_id: this.config.tenant,
|
|
267
|
+
request_type: 'multi-agent-plan',
|
|
268
|
+
context: domain ? { domain } : {}
|
|
269
|
+
};
|
|
270
|
+
const url = `${this.config.endpoint}/api/request`;
|
|
271
|
+
const response = await fetch(url, {
|
|
272
|
+
method: 'POST',
|
|
273
|
+
headers: {
|
|
274
|
+
'Content-Type': 'application/json'
|
|
275
|
+
},
|
|
276
|
+
body: JSON.stringify(agentRequest),
|
|
277
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
278
|
+
});
|
|
279
|
+
if (!response.ok) {
|
|
280
|
+
const errorText = await response.text();
|
|
281
|
+
throw new Error(`Plan generation failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
282
|
+
}
|
|
283
|
+
const agentResponse = await response.json();
|
|
284
|
+
if (!agentResponse.success) {
|
|
285
|
+
throw new Error(`Plan generation failed: ${agentResponse.error}`);
|
|
286
|
+
}
|
|
287
|
+
if (this.config.debug) {
|
|
288
|
+
debugLog('Plan generated', { planId: agentResponse.plan_id });
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
planId: agentResponse.plan_id,
|
|
292
|
+
steps: agentResponse.data?.steps || [],
|
|
293
|
+
domain: agentResponse.data?.domain || domain || 'generic',
|
|
294
|
+
complexity: agentResponse.data?.complexity || 0,
|
|
295
|
+
parallel: agentResponse.data?.parallel || false,
|
|
296
|
+
metadata: agentResponse.metadata || {}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Execute a previously generated multi-agent plan
|
|
301
|
+
*/
|
|
302
|
+
async executePlan(planId) {
|
|
303
|
+
const agentRequest = {
|
|
304
|
+
query: '',
|
|
305
|
+
user_token: this.config.apiKey,
|
|
306
|
+
client_id: this.config.tenant,
|
|
307
|
+
request_type: 'execute-plan',
|
|
308
|
+
context: { plan_id: planId }
|
|
309
|
+
};
|
|
310
|
+
const url = `${this.config.endpoint}/api/request`;
|
|
311
|
+
const response = await fetch(url, {
|
|
312
|
+
method: 'POST',
|
|
313
|
+
headers: {
|
|
314
|
+
'Content-Type': 'application/json'
|
|
315
|
+
},
|
|
316
|
+
body: JSON.stringify(agentRequest),
|
|
317
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
318
|
+
});
|
|
319
|
+
if (!response.ok) {
|
|
320
|
+
const errorText = await response.text();
|
|
321
|
+
throw new Error(`Plan execution failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
322
|
+
}
|
|
323
|
+
const agentResponse = await response.json();
|
|
324
|
+
if (this.config.debug) {
|
|
325
|
+
debugLog('Plan executed', { planId, success: agentResponse.success });
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
planId,
|
|
329
|
+
status: agentResponse.success ? 'completed' : 'failed',
|
|
330
|
+
result: agentResponse.result,
|
|
331
|
+
stepResults: agentResponse.metadata?.step_results,
|
|
332
|
+
error: agentResponse.error,
|
|
333
|
+
duration: agentResponse.metadata?.duration
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get the status of a running or completed plan
|
|
338
|
+
*/
|
|
339
|
+
async getPlanStatus(planId) {
|
|
340
|
+
const url = `${this.config.endpoint}/api/plans/${planId}`;
|
|
341
|
+
const response = await fetch(url, {
|
|
342
|
+
method: 'GET',
|
|
343
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
344
|
+
});
|
|
345
|
+
if (!response.ok) {
|
|
346
|
+
const errorText = await response.text();
|
|
347
|
+
throw new Error(`Get plan status failed: ${response.status} ${response.statusText} - ${errorText}`);
|
|
348
|
+
}
|
|
349
|
+
const status = await response.json();
|
|
350
|
+
return {
|
|
351
|
+
planId,
|
|
352
|
+
status: status.status,
|
|
353
|
+
result: status.result,
|
|
354
|
+
stepResults: status.step_results,
|
|
355
|
+
error: status.error,
|
|
356
|
+
duration: status.duration
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,QAAQ;IAInB,YAAY,MAAsB;QAF1B,iBAAY,GAAsB,EAAE,CAAC;QAG3C,eAAe;QACf,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,oCAAoC;YACjE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,YAAY;YACjC,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,SAAS;YAClC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,KAAK;YAC5B,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK;YAChC,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE;YACrE,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE;SACrD,CAAC;QAEF,0BAA0B;QAC1B,IAAI,CAAC,YAAY,GAAG;YAClB,IAAI,iBAAiB,EAAE;YACvB,IAAI,oBAAoB,EAAE;SAC3B,CAAC;QAEF,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,QAAQ,C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C,OAAO,CAAC;SACjD,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,2BAA2B,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,MAAM,SAAS,EAAE,CAAC,CAAC;QACtG,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAErC,OAAO;YACL,MAAM;YACN,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,WAAW,EAAE,MAAM,CAAC,YAAY;YAChC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,QAAQ,EAAE,MAAM,CAAC,QAAQ;SAC1B,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AxonFlow SDK - Invisible AI Governance Layer
|
|
3
|
+
*
|
|
4
|
+
* Add enterprise-grade governance to your AI applications with just 3 lines of code.
|
|
5
|
+
* No UI changes. No user training. Just drop-in protection.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { AxonFlow } from '@axonflow/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const axonflow = new AxonFlow({ apiKey: 'your-key' });
|
|
12
|
+
* const response = await axonflow.protect(() => openai.complete(prompt));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { AxonFlow } from './client';
|
|
16
|
+
export { wrapOpenAIClient } from './interceptors/openai';
|
|
17
|
+
export { wrapAnthropicClient } from './interceptors/anthropic';
|
|
18
|
+
export type { AxonFlowConfig, AIRequest, GovernanceRequest, GovernanceResponse, PolicyDecision, Violation, Policy, PolicyRule } from './types';
|
|
19
|
+
export declare const VERSION = "0.1.0";
|
|
20
|
+
import { AxonFlow } from './client';
|
|
21
|
+
export default AxonFlow;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EACV,cAAc,EACd,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,MAAM,EACN,UAAU,EACX,MAAM,SAAS,CAAC;AAGjB,eAAO,MAAM,OAAO,UAAU,CAAC;AAG/B,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AxonFlow SDK - Invisible AI Governance Layer
|
|
3
|
+
*
|
|
4
|
+
* Add enterprise-grade governance to your AI applications with just 3 lines of code.
|
|
5
|
+
* No UI changes. No user training. Just drop-in protection.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { AxonFlow } from '@axonflow/sdk';
|
|
10
|
+
*
|
|
11
|
+
* const axonflow = new AxonFlow({ apiKey: 'your-key' });
|
|
12
|
+
* const response = await axonflow.protect(() => openai.complete(prompt));
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export { AxonFlow } from './client.js';
|
|
16
|
+
export { wrapOpenAIClient } from './interceptors/openai.js';
|
|
17
|
+
export { wrapAnthropicClient } from './interceptors/anthropic.js';
|
|
18
|
+
// Export version
|
|
19
|
+
export const VERSION = '0.1.0';
|
|
20
|
+
// Default export for convenience
|
|
21
|
+
import { AxonFlow } from './client.js';
|
|
22
|
+
export default AxonFlow;
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAc/D,iBAAiB;AACjB,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC;AAE/B,iCAAiC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseInterceptor } from './base';
|
|
2
|
+
import { AIRequest } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Interceptor for Anthropic Claude API calls
|
|
5
|
+
*/
|
|
6
|
+
export declare class AnthropicInterceptor extends BaseInterceptor {
|
|
7
|
+
canHandle(aiCall: any): boolean;
|
|
8
|
+
extractRequest(aiCall: any): AIRequest;
|
|
9
|
+
executeWithModifications(aiCall: any, modifications: any): Promise<any>;
|
|
10
|
+
getProvider(): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Helper to wrap Anthropic client for easier interception
|
|
14
|
+
*/
|
|
15
|
+
export declare function wrapAnthropicClient(anthropicClient: any, axonflow: any): any;
|
|
16
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/interceptors/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,eAAe;IACvD,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO;IAQ/B,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS;IAsBtC,wBAAwB,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAKvE,WAAW,IAAI,MAAM;CAGtB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,GAAG,CA4B5E"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { BaseInterceptor } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interceptor for Anthropic Claude API calls
|
|
4
|
+
*/
|
|
5
|
+
export class AnthropicInterceptor extends BaseInterceptor {
|
|
6
|
+
canHandle(aiCall) {
|
|
7
|
+
// Check if this looks like an Anthropic call
|
|
8
|
+
const callString = aiCall.toString();
|
|
9
|
+
return callString.includes('anthropic') ||
|
|
10
|
+
callString.includes('claude') ||
|
|
11
|
+
callString.includes('messages.create');
|
|
12
|
+
}
|
|
13
|
+
extractRequest(aiCall) {
|
|
14
|
+
// Try to extract Anthropic-specific details
|
|
15
|
+
const callString = aiCall.toString();
|
|
16
|
+
// Try to detect model
|
|
17
|
+
let model = 'unknown';
|
|
18
|
+
if (callString.includes('claude-3')) {
|
|
19
|
+
model = 'claude-3';
|
|
20
|
+
}
|
|
21
|
+
else if (callString.includes('claude-2')) {
|
|
22
|
+
model = 'claude-2';
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
provider: 'anthropic',
|
|
26
|
+
model,
|
|
27
|
+
prompt: callString,
|
|
28
|
+
parameters: {
|
|
29
|
+
// Would extract max_tokens, temperature, etc. in production
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
executeWithModifications(aiCall, modifications) {
|
|
34
|
+
// Execute the call with any modifications from governance
|
|
35
|
+
return aiCall();
|
|
36
|
+
}
|
|
37
|
+
getProvider() {
|
|
38
|
+
return 'anthropic';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Helper to wrap Anthropic client for easier interception
|
|
43
|
+
*/
|
|
44
|
+
export function wrapAnthropicClient(anthropicClient, axonflow) {
|
|
45
|
+
// Create a proxy that intercepts method calls
|
|
46
|
+
return new Proxy(anthropicClient, {
|
|
47
|
+
get(target, prop, receiver) {
|
|
48
|
+
const original = Reflect.get(target, prop, receiver);
|
|
49
|
+
// If it's the messages object
|
|
50
|
+
if (prop === 'messages' && typeof original === 'object') {
|
|
51
|
+
return new Proxy(original, {
|
|
52
|
+
get(messagesTarget, messagesProp) {
|
|
53
|
+
const messagesOriginal = Reflect.get(messagesTarget, messagesProp);
|
|
54
|
+
// If it's the create method
|
|
55
|
+
if (messagesProp === 'create' && typeof messagesOriginal === 'function') {
|
|
56
|
+
return async (...args) => {
|
|
57
|
+
// Protect the call with AxonFlow
|
|
58
|
+
return axonflow.protect(() => messagesOriginal.apply(messagesTarget, args));
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return messagesOriginal;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return original;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/interceptors/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAGzC;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,eAAe;IACvD,SAAS,CAAC,MAAW;QACnB,6CAA6C;QAC7C,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC;YAChC,UAAU,CAAC,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,CAAC;wBAEnE,4BAA4B;wBAC5B,IAAI,YAAY,KAAK,QAAQ,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE,CAAC;4BACxE,OAAO,KAAK,EAAE,GAAG,IAAW,EAAE,EAAE;gCAC9B,iCAAiC;gCACjC,OAAO,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC;4BAC9E,CAAC,CAAC;wBACJ,CAAC;wBAED,OAAO,gBAAgB,CAAC;oBAC1B,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;YAED,OAAO,QAAQ,CAAC;QAClB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AIRequest } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Base interceptor interface for different AI providers
|
|
4
|
+
*/
|
|
5
|
+
export declare abstract class BaseInterceptor {
|
|
6
|
+
/**
|
|
7
|
+
* Check if this interceptor can handle the given AI call
|
|
8
|
+
*/
|
|
9
|
+
abstract canHandle(aiCall: any): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Extract request details from the AI call
|
|
12
|
+
*/
|
|
13
|
+
abstract extractRequest(aiCall: any): AIRequest;
|
|
14
|
+
/**
|
|
15
|
+
* Execute the AI call with modifications
|
|
16
|
+
*/
|
|
17
|
+
abstract executeWithModifications(aiCall: any, modifications: any): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the provider name
|
|
20
|
+
*/
|
|
21
|
+
abstract getProvider(): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/interceptors/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,8BAAsB,eAAe;IACnC;;OAEG;IACH,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO;IAExC;;OAEG;IACH,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS;IAE/C;;OAEG;IACH,QAAQ,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAEhF;;OAEG;IACH,QAAQ,CAAC,WAAW,IAAI,MAAM;CAC/B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/interceptors/base.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAgB,eAAe;CAoBpC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseInterceptor } from './base';
|
|
2
|
+
import { AIRequest } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Interceptor for OpenAI API calls
|
|
5
|
+
*/
|
|
6
|
+
export declare class OpenAIInterceptor extends BaseInterceptor {
|
|
7
|
+
canHandle(aiCall: any): boolean;
|
|
8
|
+
extractRequest(aiCall: any): AIRequest;
|
|
9
|
+
executeWithModifications(aiCall: any, modifications: any): Promise<any>;
|
|
10
|
+
getProvider(): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Helper to wrap OpenAI client for easier interception
|
|
14
|
+
*/
|
|
15
|
+
export declare function wrapOpenAIClient(openaiClient: any, axonflow: any): any;
|
|
16
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/interceptors/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;IACpD,SAAS,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO;IAS/B,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS;IAuBtC,wBAAwB,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IAMvE,WAAW,IAAI,MAAM;CAGtB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,GAAG,CAwBtE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { BaseInterceptor } from './base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Interceptor for OpenAI API calls
|
|
4
|
+
*/
|
|
5
|
+
export class OpenAIInterceptor extends BaseInterceptor {
|
|
6
|
+
canHandle(aiCall) {
|
|
7
|
+
// Check if this looks like an OpenAI call
|
|
8
|
+
const callString = aiCall.toString();
|
|
9
|
+
return callString.includes('openai') ||
|
|
10
|
+
callString.includes('createCompletion') ||
|
|
11
|
+
callString.includes('createChatCompletion') ||
|
|
12
|
+
callString.includes('gpt');
|
|
13
|
+
}
|
|
14
|
+
extractRequest(aiCall) {
|
|
15
|
+
// Try to extract OpenAI-specific details
|
|
16
|
+
// This is simplified - in production, we'd use more sophisticated parsing
|
|
17
|
+
const callString = aiCall.toString();
|
|
18
|
+
// Try to detect model
|
|
19
|
+
let model = 'unknown';
|
|
20
|
+
if (callString.includes('gpt-4')) {
|
|
21
|
+
model = 'gpt-4';
|
|
22
|
+
}
|
|
23
|
+
else if (callString.includes('gpt-3.5')) {
|
|
24
|
+
model = 'gpt-3.5-turbo';
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
provider: 'openai',
|
|
28
|
+
model,
|
|
29
|
+
prompt: callString,
|
|
30
|
+
parameters: {
|
|
31
|
+
// Would extract temperature, max_tokens, etc. in production
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
executeWithModifications(aiCall, modifications) {
|
|
36
|
+
// Execute the call with any modifications from governance
|
|
37
|
+
// In production, this would apply actual modifications
|
|
38
|
+
return aiCall();
|
|
39
|
+
}
|
|
40
|
+
getProvider() {
|
|
41
|
+
return 'openai';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Helper to wrap OpenAI client for easier interception
|
|
46
|
+
*/
|
|
47
|
+
export function wrapOpenAIClient(openaiClient, axonflow) {
|
|
48
|
+
// Create a proxy that intercepts method calls
|
|
49
|
+
return new Proxy(openaiClient, {
|
|
50
|
+
get(target, prop, receiver) {
|
|
51
|
+
const original = Reflect.get(target, prop, receiver);
|
|
52
|
+
// If it's a function that makes API calls
|
|
53
|
+
if (typeof original === 'function' &&
|
|
54
|
+
['createCompletion', 'createChatCompletion', 'createEdit'].includes(prop.toString())) {
|
|
55
|
+
return async (...args) => {
|
|
56
|
+
// Protect the call with AxonFlow
|
|
57
|
+
return axonflow.protect(() => original.apply(target, args));
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// For nested objects (like openai.chat.completions)
|
|
61
|
+
if (typeof original === 'object' && original !== null) {
|
|
62
|
+
return wrapOpenAIClient(original, axonflow);
|
|
63
|
+
}
|
|
64
|
+
return original;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=openai.js.map
|