@wener/mcps 1.0.4 → 1.0.5
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.mjs +22 -22
- package/dist/mcps-cli.mjs +37 -37
- package/lib/audit/AuditContract.js.map +1 -0
- package/lib/{chat/audit.js → audit/chat.js} +1 -1
- package/lib/audit/chat.js.map +1 -0
- package/lib/audit/entities/ChatRequestEntity.js.map +1 -0
- package/lib/audit/entities/McpRequestEntity.js.map +1 -0
- package/lib/audit/entities/RequestLogEntity.js.map +1 -0
- package/lib/audit/entities/ResponseEntity.js.map +1 -0
- package/lib/audit/entities/index.js +6 -0
- package/lib/audit/entities/index.js.map +1 -0
- package/lib/{server/audit-db.js → audit/server/db.js} +1 -1
- package/lib/audit/server/db.js.map +1 -0
- package/lib/audit/server/index.js +2 -0
- package/lib/audit/server/index.js.map +1 -0
- package/lib/{server/audit-plugin.js → audit/server/plugin.js} +4 -4
- package/lib/audit/server/plugin.js.map +1 -0
- package/lib/audit/types.js.map +1 -0
- package/lib/chat/handler.js +5 -5
- package/lib/chat/handler.js.map +1 -1
- package/lib/chat/index.js +1 -1
- package/lib/chat/index.js.map +1 -1
- package/lib/contracts/index.js +1 -1
- package/lib/contracts/index.js.map +1 -1
- package/lib/dev.server.js +1 -1
- package/lib/dev.server.js.map +1 -1
- package/lib/entities/index.js +2 -10
- package/lib/entities/index.js.map +1 -1
- package/lib/mcps-cli.js +1 -1
- package/lib/mcps-cli.js.map +1 -1
- package/package.json +145 -112
- package/src/{chat/audit.ts → audit/chat.ts} +3 -3
- package/src/audit/entities/index.ts +6 -0
- package/src/{server/audit-db.ts → audit/server/db.ts} +1 -1
- package/src/audit/server/index.ts +8 -0
- package/src/{server/audit-plugin.ts → audit/server/plugin.ts} +5 -5
- package/src/chat/handler.ts +5 -5
- package/src/chat/index.ts +1 -1
- package/src/contracts/index.ts +1 -1
- package/src/dev.server.ts +1 -1
- package/src/entities/index.ts +2 -12
- package/src/mcps-cli.ts +1 -1
- package/LICENSE +0 -21
- package/lib/chat/audit.js.map +0 -1
- package/lib/contracts/AuditContract.js.map +0 -1
- package/lib/entities/ChatRequestEntity.js.map +0 -1
- package/lib/entities/McpRequestEntity.js.map +0 -1
- package/lib/entities/RequestLogEntity.js.map +0 -1
- package/lib/entities/ResponseEntity.js.map +0 -1
- package/lib/entities/types.js.map +0 -1
- package/lib/server/audit-db.js.map +0 -1
- package/lib/server/audit-plugin.js.map +0 -1
- /package/lib/{contracts → audit}/AuditContract.js +0 -0
- /package/lib/{entities → audit/entities}/ChatRequestEntity.js +0 -0
- /package/lib/{entities → audit/entities}/McpRequestEntity.js +0 -0
- /package/lib/{entities → audit/entities}/RequestLogEntity.js +0 -0
- /package/lib/{entities → audit/entities}/ResponseEntity.js +0 -0
- /package/lib/{entities → audit}/types.js +0 -0
- /package/src/{contracts → audit}/AuditContract.ts +0 -0
- /package/src/{entities → audit/entities}/ChatRequestEntity.ts +0 -0
- /package/src/{entities → audit/entities}/McpRequestEntity.ts +0 -0
- /package/src/{entities → audit/entities}/RequestLogEntity.ts +0 -0
- /package/src/{entities → audit/entities}/ResponseEntity.ts +0 -0
- /package/src/{entities → audit}/types.ts +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Bundled with esbuild
|
|
2
|
-
// @wener/mcps@1.0.
|
|
2
|
+
// @wener/mcps@1.0.5
|
|
3
3
|
|
|
4
4
|
var require,__filename,__dirname;
|
|
5
5
|
{
|
|
@@ -176079,9 +176079,9 @@ var init_es2 = __esm({
|
|
|
176079
176079
|
}
|
|
176080
176080
|
});
|
|
176081
176081
|
|
|
176082
|
-
// src/entities/ChatRequestEntity.ts
|
|
176082
|
+
// src/audit/entities/ChatRequestEntity.ts
|
|
176083
176083
|
var ChatProtocolType, RequestStatus2, _updatedAt_dec, _createdAt_dec, _currency_dec, _cost_dec, _responseMeta_dec, _requestMeta_dec, _apiKeyId_dec, _orgId_dec, _userId_dec, _userAgent_dec, _clientIp_dec, _errorCode_dec, _errorMessage_dec, _httpStatus_dec, _ttftMs_dec, _durationMs_dec, _totalTokens_dec, _outputTokens_dec, _inputTokens_dec, _streaming_dec, _upstreamUrl_dec, _provider_dec, _resolvedModel_dec, _model_dec, _outputProtocol_dec, _inputProtocol_dec, _endpoint_dec, _method_dec, _status_dec, _completedAt_dec, _requestedAt_dec, _requestId_dec, _id_dec, _ChatRequestEntity_decorators, _init, _ChatRequestEntity, ChatRequestEntity, init_ChatRequestEntity = __esm({
|
|
176084
|
-
"src/entities/ChatRequestEntity.ts"() {
|
|
176084
|
+
"src/audit/entities/ChatRequestEntity.ts"() {
|
|
176085
176085
|
"use strict";
|
|
176086
176086
|
init_es2();
|
|
176087
176087
|
ChatProtocolType = Object.freeze({
|
|
@@ -176137,9 +176137,9 @@ var ChatProtocolType, RequestStatus2, _updatedAt_dec, _createdAt_dec, _currency_
|
|
|
176137
176137
|
}
|
|
176138
176138
|
});
|
|
176139
176139
|
|
|
176140
|
-
// src/entities/McpRequestEntity.ts
|
|
176140
|
+
// src/audit/entities/McpRequestEntity.ts
|
|
176141
176141
|
var McpServerType, McpRequestType, RequestStatus3, _updatedAt_dec2, _createdAt_dec2, _responseMeta_dec2, _requestBody_dec, _requestHeaders_dec, _userId_dec2, _userAgent_dec2, _clientIp_dec2, _errorCode_dec2, _errorMessage_dec2, _httpStatus_dec2, _durationMs_dec2, _promptName_dec, _resourceUri_dec, _toolName_dec, _mcpMethod_dec, _serverType_dec, _serverName_dec, _path_dec, _method_dec2, _status_dec2, _completedAt_dec2, _requestedAt_dec2, _sessionId_dec, _requestId_dec2, _id_dec2, _McpRequestEntity_decorators, _init2, _McpRequestEntity, McpRequestEntity, init_McpRequestEntity = __esm({
|
|
176142
|
-
"src/entities/McpRequestEntity.ts"() {
|
|
176142
|
+
"src/audit/entities/McpRequestEntity.ts"() {
|
|
176143
176143
|
"use strict";
|
|
176144
176144
|
init_es2();
|
|
176145
176145
|
McpServerType = Object.freeze({
|
|
@@ -176202,9 +176202,9 @@ var McpServerType, McpRequestType, RequestStatus3, _updatedAt_dec2, _createdAt_d
|
|
|
176202
176202
|
}
|
|
176203
176203
|
});
|
|
176204
176204
|
|
|
176205
|
-
// src/entities/RequestLogEntity.ts
|
|
176205
|
+
// src/audit/entities/RequestLogEntity.ts
|
|
176206
176206
|
var _createdAt_dec3, _metadata_dec, _responseBody_dec, _requestBody_dec2, _requestHeaders_dec2, _userAgent_dec3, _clientIp_dec3, _error_dec, _durationMs_dec3, _status_dec3, _serverType_dec2, _serverName_dec2, _requestType_dec, _path_dec2, _method_dec3, _timestamp_dec, _requestId_dec3, _id_dec3, _RequestLogEntity_decorators, _init3, _RequestLogEntity, RequestLogEntity, init_RequestLogEntity = __esm({
|
|
176207
|
-
"src/entities/RequestLogEntity.ts"() {
|
|
176207
|
+
"src/audit/entities/RequestLogEntity.ts"() {
|
|
176208
176208
|
"use strict";
|
|
176209
176209
|
init_es2();
|
|
176210
176210
|
_RequestLogEntity_decorators = [Entity2({ tableName: "request_log" })], _id_dec3 = [PrimaryKey2({ type: "integer" })], _requestId_dec3 = [Property2({ type: "string" })], _timestamp_dec = [Property2({ type: "datetime" })], _method_dec3 = [Property2({ type: "string" })], _path_dec2 = [Property2({ type: "string" })], _requestType_dec = [Property2({ type: "string", nullable: !0 })], _serverName_dec2 = [Property2({ type: "string", nullable: !0 })], _serverType_dec2 = [Property2({ type: "string", nullable: !0 })], _status_dec3 = [Property2({ type: "integer", nullable: !0 })], _durationMs_dec3 = [Property2({ type: "integer", nullable: !0 })], _error_dec = [Property2({ type: "text", nullable: !0 })], _clientIp_dec3 = [Property2({ type: "string", nullable: !0 })], _userAgent_dec3 = [Property2({ type: "string", nullable: !0 })], _requestHeaders_dec2 = [Property2({ type: "json", nullable: !0 })], _requestBody_dec2 = [Property2({ type: "json", nullable: !0 })], _responseBody_dec = [Property2({ type: "json", nullable: !0 })], _metadata_dec = [Property2({ type: "json", nullable: !0 })], _createdAt_dec3 = [Property2({ type: "datetime" })];
|
|
@@ -176235,9 +176235,9 @@ var _createdAt_dec3, _metadata_dec, _responseBody_dec, _requestBody_dec2, _reque
|
|
|
176235
176235
|
}
|
|
176236
176236
|
});
|
|
176237
176237
|
|
|
176238
|
-
// src/entities/ResponseEntity.ts
|
|
176238
|
+
// src/audit/entities/ResponseEntity.ts
|
|
176239
176239
|
var _durationMs_dec4, _createdAt_dec4, _error_dec2, _metadata_dec2, _toolChoice_dec, _tools_dec, _previousResponseId_dec, _instructions_dec, _usage_dec, _output_dec, _input_dec, _status_dec4, _model_dec2, _responseId_dec, _id_dec4, _ResponseEntity_decorators, _init4, _ResponseEntity, ResponseEntity, init_ResponseEntity = __esm({
|
|
176240
|
-
"src/entities/ResponseEntity.ts"() {
|
|
176240
|
+
"src/audit/entities/ResponseEntity.ts"() {
|
|
176241
176241
|
"use strict";
|
|
176242
176242
|
init_es2();
|
|
176243
176243
|
_ResponseEntity_decorators = [Entity2({ tableName: "response" })], _id_dec4 = [PrimaryKey2({ type: "integer" })], _responseId_dec = [Property2({ type: "string", unique: !0 })], _model_dec2 = [Property2({ type: "string" })], _status_dec4 = [Property2({ type: "string" })], _input_dec = [Property2({ type: "json" })], _output_dec = [Property2({ type: "json" })], _usage_dec = [Property2({ type: "json", nullable: !0 })], _instructions_dec = [Property2({ type: "text", nullable: !0 })], _previousResponseId_dec = [Property2({ type: "string", nullable: !0 })], _tools_dec = [Property2({ type: "json", nullable: !0 })], _toolChoice_dec = [Property2({ type: "json", nullable: !0 })], _metadata_dec2 = [Property2({ type: "json", nullable: !0 })], _error_dec2 = [Property2({ type: "json", nullable: !0 })], _createdAt_dec4 = [Property2({ type: "datetime" })], _durationMs_dec4 = [Property2({ type: "integer", nullable: !0 })];
|
|
@@ -176265,9 +176265,9 @@ var _durationMs_dec4, _createdAt_dec4, _error_dec2, _metadata_dec2, _toolChoice_
|
|
|
176265
176265
|
}
|
|
176266
176266
|
});
|
|
176267
176267
|
|
|
176268
|
-
// src/server/
|
|
176269
|
-
var
|
|
176270
|
-
__export(
|
|
176268
|
+
// src/audit/server/db.ts
|
|
176269
|
+
var db_exports = {};
|
|
176270
|
+
__export(db_exports, {
|
|
176271
176271
|
RequestLogEntity: () => RequestLogEntity,
|
|
176272
176272
|
closeDb: () => closeDb,
|
|
176273
176273
|
ensureDbInitialized: () => ensureDbInitialized,
|
|
@@ -176312,8 +176312,8 @@ async function closeDb() {
|
|
|
176312
176312
|
function isDbInitialized() {
|
|
176313
176313
|
return orm !== null;
|
|
176314
176314
|
}
|
|
176315
|
-
var orm, initPromise,
|
|
176316
|
-
"src/server/
|
|
176315
|
+
var orm, initPromise, init_db = __esm({
|
|
176316
|
+
"src/audit/server/db.ts"() {
|
|
176317
176317
|
"use strict";
|
|
176318
176318
|
init_core3();
|
|
176319
176319
|
init_sql2();
|
|
@@ -176332,14 +176332,14 @@ var orm, initPromise, init_audit_db = __esm({
|
|
|
176332
176332
|
}
|
|
176333
176333
|
});
|
|
176334
176334
|
|
|
176335
|
-
// src/
|
|
176335
|
+
// src/audit/types.ts
|
|
176336
176336
|
var init_types5 = __esm({
|
|
176337
|
-
"src/
|
|
176337
|
+
"src/audit/types.ts"() {
|
|
176338
176338
|
"use strict";
|
|
176339
176339
|
}
|
|
176340
176340
|
});
|
|
176341
176341
|
|
|
176342
|
-
// src/entities/index.ts
|
|
176342
|
+
// src/audit/entities/index.ts
|
|
176343
176343
|
var entities_exports = {};
|
|
176344
176344
|
__export(entities_exports, {
|
|
176345
176345
|
ChatProtocolType: () => ChatProtocolType,
|
|
@@ -176352,7 +176352,7 @@ __export(entities_exports, {
|
|
|
176352
176352
|
ResponseEntity: () => ResponseEntity
|
|
176353
176353
|
});
|
|
176354
176354
|
var init_entities = __esm({
|
|
176355
|
-
"src/entities/index.ts"() {
|
|
176355
|
+
"src/audit/entities/index.ts"() {
|
|
176356
176356
|
"use strict";
|
|
176357
176357
|
init_types5();
|
|
176358
176358
|
init_ChatRequestEntity();
|
|
@@ -200583,7 +200583,7 @@ var html = /* @__PURE__ */ __name((strings, ...values) => {
|
|
|
200583
200583
|
return buffer[0] += strings.at(-1), buffer.length === 1 ? "callbacks" in buffer ? raw(resolveCallbackSync(raw(buffer[0], buffer.callbacks))) : raw(buffer[0]) : stringBufferToString(buffer, buffer.callbacks);
|
|
200584
200584
|
}, "html");
|
|
200585
200585
|
|
|
200586
|
-
// src/
|
|
200586
|
+
// src/audit/AuditContract.ts
|
|
200587
200587
|
init_zod();
|
|
200588
200588
|
var AuditEventSchema = external_exports3.object({
|
|
200589
200589
|
id: external_exports3.string(),
|
|
@@ -201186,7 +201186,7 @@ function geminiToOpenaiResponse(res, model) {
|
|
|
201186
201186
|
}
|
|
201187
201187
|
__name(geminiToOpenaiResponse, "geminiToOpenaiResponse");
|
|
201188
201188
|
|
|
201189
|
-
// src/chat
|
|
201189
|
+
// src/audit/chat.ts
|
|
201190
201190
|
var log4 = consola.withTag("chat-audit"), ChatProtocol = {
|
|
201191
201191
|
OPENAI: "openai",
|
|
201192
201192
|
ANTHROPIC: "anthropic",
|
|
@@ -202413,7 +202413,7 @@ function createChatHandler(options = {}) {
|
|
|
202413
202413
|
let request2 = parseResult.data, previousContext = null;
|
|
202414
202414
|
if (request2.previous_response_id)
|
|
202415
202415
|
try {
|
|
202416
|
-
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (
|
|
202416
|
+
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (init_db(), db_exports)), { ResponseEntity: ResponseEntity2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
|
|
202417
202417
|
if (isDbInitialized2()) {
|
|
202418
202418
|
let prevResponse = await getEntityManager3().fork().findOne(ResponseEntity2, { responseId: request2.previous_response_id });
|
|
202419
202419
|
prevResponse ? (previousContext = {
|
|
@@ -202464,7 +202464,7 @@ function createChatHandler(options = {}) {
|
|
|
202464
202464
|
return handleResponsesStreamingRequest(c4, upstreamUrl, chatRequest, upstreamHeaders, request2.model, auditCtx);
|
|
202465
202465
|
let chatResponse = await (await makeUpstreamRequest(upstreamUrl, chatRequest, upstreamHeaders)).json(), result = chatCompletionsToResponses(chatResponse, request2.model);
|
|
202466
202466
|
try {
|
|
202467
|
-
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (
|
|
202467
|
+
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (init_db(), db_exports)), { ResponseEntity: ResponseEntity2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
|
|
202468
202468
|
if (isDbInitialized2()) {
|
|
202469
202469
|
let em = getEntityManager3().fork(), responseEntity = new ResponseEntity2();
|
|
202470
202470
|
responseEntity.responseId = result.id, responseEntity.model = result.model, responseEntity.status = result.status, responseEntity.input = request2.input, responseEntity.output = result.output, responseEntity.usage = result.usage, responseEntity.instructions = request2.instructions ?? void 0, responseEntity.previousResponseId = request2.previous_response_id ?? void 0, responseEntity.tools = request2.tools ?? void 0, responseEntity.toolChoice = request2.tool_choice ?? void 0, responseEntity.metadata = request2.metadata, responseEntity.durationMs = auditCtx?.getDuration(), em.persist(responseEntity), await em.flush(), log6.debug(`Stored response: ${result.id}`);
|
package/dist/mcps-cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Bundled with esbuild
|
|
3
|
-
// @wener/mcps@1.0.
|
|
3
|
+
// @wener/mcps@1.0.5
|
|
4
4
|
|
|
5
5
|
var require,__filename,__dirname;
|
|
6
6
|
{
|
|
@@ -131820,9 +131820,9 @@ var html, init_html2 = __esm({
|
|
|
131820
131820
|
}
|
|
131821
131821
|
});
|
|
131822
131822
|
|
|
131823
|
-
// src/
|
|
131823
|
+
// src/audit/AuditContract.ts
|
|
131824
131824
|
var AuditEventSchema, AuditQuerySchema, AuditStatsSchema, AuditContract, init_AuditContract = __esm({
|
|
131825
|
-
"src/
|
|
131825
|
+
"src/audit/AuditContract.ts"() {
|
|
131826
131826
|
"use strict";
|
|
131827
131827
|
init_dist11();
|
|
131828
131828
|
init_zod();
|
|
@@ -132475,7 +132475,7 @@ var init_converters = __esm({
|
|
|
132475
132475
|
}
|
|
132476
132476
|
});
|
|
132477
132477
|
|
|
132478
|
-
// src/chat
|
|
132478
|
+
// src/audit/chat.ts
|
|
132479
132479
|
function generateRequestId() {
|
|
132480
132480
|
return `chat-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
132481
132481
|
}
|
|
@@ -132485,8 +132485,8 @@ function createAuditContext(options) {
|
|
|
132485
132485
|
function extractClientIp(c4) {
|
|
132486
132486
|
return c4.req.header("x-forwarded-for")?.split(",")[0]?.trim() || c4.req.header("x-real-ip") || c4.req.header("cf-connecting-ip");
|
|
132487
132487
|
}
|
|
132488
|
-
var log4, ChatProtocol, RequestStatus, InMemoryChatAuditStore, auditStore, ChatAuditContext,
|
|
132489
|
-
"src/chat
|
|
132488
|
+
var log4, ChatProtocol, RequestStatus, InMemoryChatAuditStore, auditStore, ChatAuditContext, init_chat = __esm({
|
|
132489
|
+
"src/audit/chat.ts"() {
|
|
132490
132490
|
"use strict";
|
|
132491
132491
|
init_dist();
|
|
132492
132492
|
log4 = consola.withTag("chat-audit"), ChatProtocol = {
|
|
@@ -196237,9 +196237,9 @@ var init_es2 = __esm({
|
|
|
196237
196237
|
}
|
|
196238
196238
|
});
|
|
196239
196239
|
|
|
196240
|
-
// src/entities/ChatRequestEntity.ts
|
|
196240
|
+
// src/audit/entities/ChatRequestEntity.ts
|
|
196241
196241
|
var ChatProtocolType, RequestStatus2, _updatedAt_dec, _createdAt_dec, _currency_dec, _cost_dec, _responseMeta_dec, _requestMeta_dec, _apiKeyId_dec, _orgId_dec, _userId_dec, _userAgent_dec, _clientIp_dec, _errorCode_dec, _errorMessage_dec, _httpStatus_dec, _ttftMs_dec, _durationMs_dec, _totalTokens_dec, _outputTokens_dec, _inputTokens_dec, _streaming_dec, _upstreamUrl_dec, _provider_dec, _resolvedModel_dec, _model_dec, _outputProtocol_dec, _inputProtocol_dec, _endpoint_dec, _method_dec, _status_dec, _completedAt_dec, _requestedAt_dec, _requestId_dec, _id_dec, _ChatRequestEntity_decorators, _init, _ChatRequestEntity, ChatRequestEntity, init_ChatRequestEntity = __esm({
|
|
196242
|
-
"src/entities/ChatRequestEntity.ts"() {
|
|
196242
|
+
"src/audit/entities/ChatRequestEntity.ts"() {
|
|
196243
196243
|
"use strict";
|
|
196244
196244
|
init_es2();
|
|
196245
196245
|
ChatProtocolType = Object.freeze({
|
|
@@ -196295,9 +196295,9 @@ var ChatProtocolType, RequestStatus2, _updatedAt_dec, _createdAt_dec, _currency_
|
|
|
196295
196295
|
}
|
|
196296
196296
|
});
|
|
196297
196297
|
|
|
196298
|
-
// src/entities/McpRequestEntity.ts
|
|
196298
|
+
// src/audit/entities/McpRequestEntity.ts
|
|
196299
196299
|
var McpServerType, McpRequestType, RequestStatus3, _updatedAt_dec2, _createdAt_dec2, _responseMeta_dec2, _requestBody_dec, _requestHeaders_dec, _userId_dec2, _userAgent_dec2, _clientIp_dec2, _errorCode_dec2, _errorMessage_dec2, _httpStatus_dec2, _durationMs_dec2, _promptName_dec, _resourceUri_dec, _toolName_dec, _mcpMethod_dec, _serverType_dec, _serverName_dec, _path_dec, _method_dec2, _status_dec2, _completedAt_dec2, _requestedAt_dec2, _sessionId_dec, _requestId_dec2, _id_dec2, _McpRequestEntity_decorators, _init2, _McpRequestEntity, McpRequestEntity, init_McpRequestEntity = __esm({
|
|
196300
|
-
"src/entities/McpRequestEntity.ts"() {
|
|
196300
|
+
"src/audit/entities/McpRequestEntity.ts"() {
|
|
196301
196301
|
"use strict";
|
|
196302
196302
|
init_es2();
|
|
196303
196303
|
McpServerType = Object.freeze({
|
|
@@ -196360,9 +196360,9 @@ var McpServerType, McpRequestType, RequestStatus3, _updatedAt_dec2, _createdAt_d
|
|
|
196360
196360
|
}
|
|
196361
196361
|
});
|
|
196362
196362
|
|
|
196363
|
-
// src/entities/RequestLogEntity.ts
|
|
196363
|
+
// src/audit/entities/RequestLogEntity.ts
|
|
196364
196364
|
var _createdAt_dec3, _metadata_dec, _responseBody_dec, _requestBody_dec2, _requestHeaders_dec2, _userAgent_dec3, _clientIp_dec3, _error_dec, _durationMs_dec3, _status_dec3, _serverType_dec2, _serverName_dec2, _requestType_dec, _path_dec2, _method_dec3, _timestamp_dec, _requestId_dec3, _id_dec3, _RequestLogEntity_decorators, _init3, _RequestLogEntity, RequestLogEntity, init_RequestLogEntity = __esm({
|
|
196365
|
-
"src/entities/RequestLogEntity.ts"() {
|
|
196365
|
+
"src/audit/entities/RequestLogEntity.ts"() {
|
|
196366
196366
|
"use strict";
|
|
196367
196367
|
init_es2();
|
|
196368
196368
|
_RequestLogEntity_decorators = [Entity2({ tableName: "request_log" })], _id_dec3 = [PrimaryKey2({ type: "integer" })], _requestId_dec3 = [Property2({ type: "string" })], _timestamp_dec = [Property2({ type: "datetime" })], _method_dec3 = [Property2({ type: "string" })], _path_dec2 = [Property2({ type: "string" })], _requestType_dec = [Property2({ type: "string", nullable: !0 })], _serverName_dec2 = [Property2({ type: "string", nullable: !0 })], _serverType_dec2 = [Property2({ type: "string", nullable: !0 })], _status_dec3 = [Property2({ type: "integer", nullable: !0 })], _durationMs_dec3 = [Property2({ type: "integer", nullable: !0 })], _error_dec = [Property2({ type: "text", nullable: !0 })], _clientIp_dec3 = [Property2({ type: "string", nullable: !0 })], _userAgent_dec3 = [Property2({ type: "string", nullable: !0 })], _requestHeaders_dec2 = [Property2({ type: "json", nullable: !0 })], _requestBody_dec2 = [Property2({ type: "json", nullable: !0 })], _responseBody_dec = [Property2({ type: "json", nullable: !0 })], _metadata_dec = [Property2({ type: "json", nullable: !0 })], _createdAt_dec3 = [Property2({ type: "datetime" })];
|
|
@@ -196393,9 +196393,9 @@ var _createdAt_dec3, _metadata_dec, _responseBody_dec, _requestBody_dec2, _reque
|
|
|
196393
196393
|
}
|
|
196394
196394
|
});
|
|
196395
196395
|
|
|
196396
|
-
// src/entities/ResponseEntity.ts
|
|
196396
|
+
// src/audit/entities/ResponseEntity.ts
|
|
196397
196397
|
var _durationMs_dec4, _createdAt_dec4, _error_dec2, _metadata_dec2, _toolChoice_dec, _tools_dec, _previousResponseId_dec, _instructions_dec, _usage_dec, _output_dec, _input_dec, _status_dec4, _model_dec2, _responseId_dec, _id_dec4, _ResponseEntity_decorators, _init4, _ResponseEntity, ResponseEntity, init_ResponseEntity = __esm({
|
|
196398
|
-
"src/entities/ResponseEntity.ts"() {
|
|
196398
|
+
"src/audit/entities/ResponseEntity.ts"() {
|
|
196399
196399
|
"use strict";
|
|
196400
196400
|
init_es2();
|
|
196401
196401
|
_ResponseEntity_decorators = [Entity2({ tableName: "response" })], _id_dec4 = [PrimaryKey2({ type: "integer" })], _responseId_dec = [Property2({ type: "string", unique: !0 })], _model_dec2 = [Property2({ type: "string" })], _status_dec4 = [Property2({ type: "string" })], _input_dec = [Property2({ type: "json" })], _output_dec = [Property2({ type: "json" })], _usage_dec = [Property2({ type: "json", nullable: !0 })], _instructions_dec = [Property2({ type: "text", nullable: !0 })], _previousResponseId_dec = [Property2({ type: "string", nullable: !0 })], _tools_dec = [Property2({ type: "json", nullable: !0 })], _toolChoice_dec = [Property2({ type: "json", nullable: !0 })], _metadata_dec2 = [Property2({ type: "json", nullable: !0 })], _error_dec2 = [Property2({ type: "json", nullable: !0 })], _createdAt_dec4 = [Property2({ type: "datetime" })], _durationMs_dec4 = [Property2({ type: "integer", nullable: !0 })];
|
|
@@ -196423,9 +196423,9 @@ var _durationMs_dec4, _createdAt_dec4, _error_dec2, _metadata_dec2, _toolChoice_
|
|
|
196423
196423
|
}
|
|
196424
196424
|
});
|
|
196425
196425
|
|
|
196426
|
-
// src/server/
|
|
196427
|
-
var
|
|
196428
|
-
__export(
|
|
196426
|
+
// src/audit/server/db.ts
|
|
196427
|
+
var db_exports = {};
|
|
196428
|
+
__export(db_exports, {
|
|
196429
196429
|
RequestLogEntity: () => RequestLogEntity,
|
|
196430
196430
|
closeDb: () => closeDb,
|
|
196431
196431
|
ensureDbInitialized: () => ensureDbInitialized,
|
|
@@ -196470,8 +196470,8 @@ async function closeDb() {
|
|
|
196470
196470
|
function isDbInitialized() {
|
|
196471
196471
|
return orm !== null;
|
|
196472
196472
|
}
|
|
196473
|
-
var orm, initPromise,
|
|
196474
|
-
"src/server/
|
|
196473
|
+
var orm, initPromise, init_db = __esm({
|
|
196474
|
+
"src/audit/server/db.ts"() {
|
|
196475
196475
|
"use strict";
|
|
196476
196476
|
init_core4();
|
|
196477
196477
|
init_sql3();
|
|
@@ -196490,14 +196490,14 @@ var orm, initPromise, init_audit_db = __esm({
|
|
|
196490
196490
|
}
|
|
196491
196491
|
});
|
|
196492
196492
|
|
|
196493
|
-
// src/
|
|
196493
|
+
// src/audit/types.ts
|
|
196494
196494
|
var init_types6 = __esm({
|
|
196495
|
-
"src/
|
|
196495
|
+
"src/audit/types.ts"() {
|
|
196496
196496
|
"use strict";
|
|
196497
196497
|
}
|
|
196498
196498
|
});
|
|
196499
196499
|
|
|
196500
|
-
// src/entities/index.ts
|
|
196500
|
+
// src/audit/entities/index.ts
|
|
196501
196501
|
var entities_exports = {};
|
|
196502
196502
|
__export(entities_exports, {
|
|
196503
196503
|
ChatProtocolType: () => ChatProtocolType,
|
|
@@ -196510,7 +196510,7 @@ __export(entities_exports, {
|
|
|
196510
196510
|
ResponseEntity: () => ResponseEntity
|
|
196511
196511
|
});
|
|
196512
196512
|
var init_entities = __esm({
|
|
196513
|
-
"src/entities/index.ts"() {
|
|
196513
|
+
"src/audit/entities/index.ts"() {
|
|
196514
196514
|
"use strict";
|
|
196515
196515
|
init_types6();
|
|
196516
196516
|
init_ChatRequestEntity();
|
|
@@ -196918,7 +196918,7 @@ function createChatHandler(options = {}) {
|
|
|
196918
196918
|
let request2 = parseResult.data, previousContext = null;
|
|
196919
196919
|
if (request2.previous_response_id)
|
|
196920
196920
|
try {
|
|
196921
|
-
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (
|
|
196921
|
+
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (init_db(), db_exports)), { ResponseEntity: ResponseEntity2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
|
|
196922
196922
|
if (isDbInitialized2()) {
|
|
196923
196923
|
let prevResponse = await getEntityManager3().fork().findOne(ResponseEntity2, { responseId: request2.previous_response_id });
|
|
196924
196924
|
prevResponse ? (previousContext = {
|
|
@@ -196969,7 +196969,7 @@ function createChatHandler(options = {}) {
|
|
|
196969
196969
|
return handleResponsesStreamingRequest(c4, upstreamUrl, chatRequest, upstreamHeaders, request2.model, auditCtx);
|
|
196970
196970
|
let chatResponse = await (await makeUpstreamRequest(upstreamUrl, chatRequest, upstreamHeaders)).json(), result = chatCompletionsToResponses(chatResponse, request2.model);
|
|
196971
196971
|
try {
|
|
196972
|
-
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (
|
|
196972
|
+
let { isDbInitialized: isDbInitialized2, getEntityManager: getEntityManager3 } = await Promise.resolve().then(() => (init_db(), db_exports)), { ResponseEntity: ResponseEntity2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
|
|
196973
196973
|
if (isDbInitialized2()) {
|
|
196974
196974
|
let em = getEntityManager3().fork(), responseEntity = new ResponseEntity2();
|
|
196975
196975
|
responseEntity.responseId = result.id, responseEntity.model = result.model, responseEntity.status = result.status, responseEntity.input = request2.input, responseEntity.output = result.output, responseEntity.usage = result.usage, responseEntity.instructions = request2.instructions ?? void 0, responseEntity.previousResponseId = request2.previous_response_id ?? void 0, responseEntity.tools = request2.tools ?? void 0, responseEntity.toolChoice = request2.tool_choice ?? void 0, responseEntity.metadata = request2.metadata, responseEntity.durationMs = auditCtx?.getDuration(), em.persist(responseEntity), await em.flush(), log6.debug(`Stored response: ${result.id}`);
|
|
@@ -197210,7 +197210,7 @@ var log6, init_handler = __esm({
|
|
|
197210
197210
|
init_dist();
|
|
197211
197211
|
init_dist3();
|
|
197212
197212
|
init_streaming();
|
|
197213
|
-
|
|
197213
|
+
init_chat();
|
|
197214
197214
|
init_converters();
|
|
197215
197215
|
init_openai();
|
|
197216
197216
|
init_anthropic();
|
|
@@ -197221,12 +197221,12 @@ var log6, init_handler = __esm({
|
|
|
197221
197221
|
});
|
|
197222
197222
|
|
|
197223
197223
|
// src/chat/index.ts
|
|
197224
|
-
var
|
|
197224
|
+
var init_chat2 = __esm({
|
|
197225
197225
|
"src/chat/index.ts"() {
|
|
197226
197226
|
"use strict";
|
|
197227
197227
|
init_types3();
|
|
197228
197228
|
init_converters();
|
|
197229
|
-
|
|
197229
|
+
init_chat();
|
|
197230
197230
|
init_handler();
|
|
197231
197231
|
}
|
|
197232
197232
|
});
|
|
@@ -210999,7 +210999,7 @@ var log8, init_chat_routes = __esm({
|
|
|
210999
210999
|
"src/server/chat-routes.ts"() {
|
|
211000
211000
|
"use strict";
|
|
211001
211001
|
init_dist();
|
|
211002
|
-
|
|
211002
|
+
init_chat2();
|
|
211003
211003
|
init_agent();
|
|
211004
211004
|
log8 = consola.withTag("mcps");
|
|
211005
211005
|
__name(registerChatRoutes, "registerChatRoutes");
|
|
@@ -217761,9 +217761,9 @@ var log12, serverHandle, init_cli_start = __esm({
|
|
|
217761
217761
|
}
|
|
217762
217762
|
});
|
|
217763
217763
|
|
|
217764
|
-
// src/server/
|
|
217765
|
-
var
|
|
217766
|
-
__export(
|
|
217764
|
+
// src/audit/server/plugin.ts
|
|
217765
|
+
var plugin_exports = {};
|
|
217766
|
+
__export(plugin_exports, {
|
|
217767
217767
|
AuditRouter: () => AuditRouter,
|
|
217768
217768
|
addAuditEvent: () => addAuditEvent,
|
|
217769
217769
|
clearAuditEvents: () => clearAuditEvents,
|
|
@@ -217774,7 +217774,7 @@ __export(audit_plugin_exports, {
|
|
|
217774
217774
|
async function persistToDb(event, id) {
|
|
217775
217775
|
if (dbConfigured)
|
|
217776
217776
|
try {
|
|
217777
|
-
let { ensureDbInitialized: ensureDbInitialized2, RequestLogEntity: RequestLogEntity2 } = await Promise.resolve().then(() => (
|
|
217777
|
+
let { ensureDbInitialized: ensureDbInitialized2, RequestLogEntity: RequestLogEntity2 } = await Promise.resolve().then(() => (init_db(), db_exports)), em = (await ensureDbInitialized2(storedDbConfig)).em.fork(), logEntry = new RequestLogEntity2();
|
|
217778
217778
|
logEntry.requestId = id, logEntry.timestamp = new Date(event.timestamp), logEntry.method = event.method, logEntry.path = event.path, logEntry.serverName = event.serverName ?? void 0, logEntry.serverType = event.serverType ?? void 0, logEntry.status = event.status ?? void 0, logEntry.durationMs = event.durationMs ?? void 0, logEntry.error = event.error ?? void 0, logEntry.requestHeaders = event.requestHeaders ?? void 0, event.path.startsWith("/mcp/") ? logEntry.requestType = "mcp" : event.path.startsWith("/v1/") ? logEntry.requestType = "chat" : logEntry.requestType = "api", em.persist(logEntry), await em.flush();
|
|
217779
217779
|
} catch (e2) {
|
|
217780
217780
|
console.error("Failed to persist audit log:", e2);
|
|
@@ -217855,13 +217855,13 @@ function setupAudit(ctx, options) {
|
|
|
217855
217855
|
}, "queryEvents")
|
|
217856
217856
|
};
|
|
217857
217857
|
}
|
|
217858
|
-
var auditStore2, eventCounter, dbConfigured, storedAuditConfig, storedDbConfig, AuditRouter,
|
|
217859
|
-
"src/server/
|
|
217858
|
+
var auditStore2, eventCounter, dbConfigured, storedAuditConfig, storedDbConfig, AuditRouter, init_plugin2 = __esm({
|
|
217859
|
+
"src/audit/server/plugin.ts"() {
|
|
217860
217860
|
"use strict";
|
|
217861
217861
|
init_dist12();
|
|
217862
217862
|
init_esm();
|
|
217863
|
-
init_contracts();
|
|
217864
217863
|
init_events2();
|
|
217864
|
+
init_AuditContract();
|
|
217865
217865
|
auditStore2 = new LRUCache({
|
|
217866
217866
|
max: 1e4,
|
|
217867
217867
|
ttl: 1e3 * 60 * 60 * 24
|
|
@@ -217921,7 +217921,7 @@ __name(createProgram, "createProgram");
|
|
|
217921
217921
|
// src/mcps-cli.ts
|
|
217922
217922
|
var log13 = consola.withTag("mcps"), program2 = createProgram({
|
|
217923
217923
|
setup: /* @__PURE__ */ __name(async (ctx) => {
|
|
217924
|
-
let { setupAudit: setupAudit2 } = await Promise.resolve().then(() => (
|
|
217924
|
+
let { setupAudit: setupAudit2 } = await Promise.resolve().then(() => (init_plugin2(), plugin_exports));
|
|
217925
217925
|
setupAudit2(ctx);
|
|
217926
217926
|
}, "setup")
|
|
217927
217927
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/audit/AuditContract.ts"],"sourcesContent":["import { oc } from '@orpc/contract';\nimport { z } from 'zod';\n\n// Audit event schema\nexport const AuditEventSchema = z.object({\n\tid: z.string(),\n\ttimestamp: z.string(),\n\tmethod: z.string(),\n\tpath: z.string(),\n\tserverName: z.string().nullish(),\n\tserverType: z.string().nullish(),\n\tstatus: z.number().nullish(),\n\tdurationMs: z.number().nullish(),\n\trequestHeaders: z.record(z.string(), z.string()).nullish(),\n\tresponseHeaders: z.record(z.string(), z.string()).nullish(),\n\trequestBody: z.unknown().nullish(),\n\tresponseBody: z.unknown().nullish(),\n\terror: z.string().nullish(),\n\ttoolName: z.string().nullish(),\n\ttoolArgs: z.unknown().nullish(),\n});\nexport type AuditEvent = z.infer<typeof AuditEventSchema>;\n\n// Query params\nexport const AuditQuerySchema = z.object({\n\tlimit: z.coerce.number().default(50),\n\toffset: z.coerce.number().default(0),\n\tserverName: z.string().nullish(),\n\tserverType: z.string().nullish(),\n\tmethod: z.string().nullish(),\n\tfrom: z.string().nullish(),\n\tto: z.string().nullish(),\n});\n\n// Audit stats\nexport const AuditStatsSchema = z.object({\n\ttotalRequests: z.number(),\n\ttotalErrors: z.number(),\n\tavgDurationMs: z.number(),\n\tbyServer: z.array(\n\t\tz.object({\n\t\t\tname: z.string(),\n\t\t\tcount: z.number(),\n\t\t}),\n\t),\n\tbyMethod: z.array(\n\t\tz.object({\n\t\t\tmethod: z.string(),\n\t\t\tcount: z.number(),\n\t\t}),\n\t),\n});\n\n// Contract definition\nexport const AuditContract = oc.prefix('/audit').router({\n\t// List audit events\n\tlist: oc\n\t\t.input(AuditQuerySchema)\n\t\t.output(\n\t\t\tz.object({\n\t\t\t\tevents: z.array(AuditEventSchema),\n\t\t\t\ttotal: z.number(),\n\t\t\t}),\n\t\t)\n\t\t.route({ method: 'GET', path: '/', summary: 'List audit events' }),\n\n\t// Get single event\n\tget: oc\n\t\t.input(z.object({ id: z.string() }))\n\t\t.output(AuditEventSchema.nullable())\n\t\t.route({ method: 'GET', path: '/{id}', summary: 'Get audit event by ID' }),\n\n\t// Get stats\n\tstats: oc\n\t\t.input(\n\t\t\tz.object({\n\t\t\t\tfrom: z.string().nullish(),\n\t\t\t\tto: z.string().nullish(),\n\t\t\t}),\n\t\t)\n\t\t.output(AuditStatsSchema)\n\t\t.route({ method: 'GET', path: '/stats', summary: 'Get audit statistics' }),\n\n\t// Clear old events\n\tclear: oc\n\t\t.input(\n\t\t\tz.object({\n\t\t\t\tbefore: z.string().describe('Clear events before this timestamp'),\n\t\t\t}),\n\t\t)\n\t\t.output(z.object({ deleted: z.number() }))\n\t\t.route({ method: 'DELETE', path: '/', summary: 'Clear audit events' }),\n});\n"],"names":["oc","z","AuditEventSchema","object","id","string","timestamp","method","path","serverName","nullish","serverType","status","number","durationMs","requestHeaders","record","responseHeaders","requestBody","unknown","responseBody","error","toolName","toolArgs","AuditQuerySchema","limit","coerce","default","offset","from","to","AuditStatsSchema","totalRequests","totalErrors","avgDurationMs","byServer","array","name","count","byMethod","AuditContract","prefix","router","list","input","output","events","total","route","summary","get","nullable","stats","clear","before","describe","deleted"],"mappings":"AAAA,SAASA,EAAE,QAAQ,iBAAiB;AACpC,SAASC,CAAC,QAAQ,MAAM;AAExB,qBAAqB;AACrB,OAAO,MAAMC,mBAAmBD,EAAEE,M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EqD,SAASvD,EAAEY,MAAM;IAAG,IACtCmC,KAAK,CAAC;QAAEzC,QAAQ;QAAUC,MAAM;QAAKyC,SAAS;IAAqB;AACtE,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/audit/chat.ts"],"sourcesContent":["/**\n * Chat Request Audit Service\n * Records all chat/LLM API requests for auditing and metering\n */\nimport type { Context } from 'hono';\nimport consola from 'consola';\nimport type { ChatProtocolType, RequestStatus as RequestStatusType, ChatAuditStats } from './types';\n\nconst log = consola.withTag('chat-audit');\n\n/**\n * Re-export protocol and status constants for convenience\n */\nexport const ChatProtocol = {\n\tOPENAI: 'openai' as ChatProtocolType,\n\tANTHROPIC: 'anthropic' as ChatProtocolType,\n\tGEMINI: 'gemini' as ChatProtocolType,\n};\n\nexport const RequestStatus = {\n\tPENDING: 'pending' as RequestStatusType,\n\tSUCCESS: 'success' as RequestStatusType,\n\tERROR: 'error' as RequestStatusType,\n\tTIMEOUT: 'timeout' as RequestStatusType,\n};\n\n/**\n * Chat audit record (in-memory representation)\n */\nexport interface ChatAuditRecord {\n\trequestId: string;\n\trequestedAt: Date;\n\tcompletedAt?: Date;\n\tstatus: RequestStatusType;\n\tmethod: string;\n\tendpoint: string;\n\tinputProtocol: ChatProtocolType;\n\toutputProtocol: ChatProtocolType;\n\tmodel: string;\n\tresolvedModel?: string;\n\tprovider?: string;\n\tupstreamUrl?: string;\n\tstreaming: boolean;\n\tinputTokens?: number;\n\toutputTokens?: number;\n\ttotalTokens?: number;\n\tdurationMs?: number;\n\tttftMs?: number;\n\thttpStatus?: number;\n\terrorMessage?: string;\n\terrorCode?: string;\n\tclientIp?: string;\n\tuserAgent?: string;\n\tuserId?: string;\n\torgId?: string;\n\tapiKeyId?: string;\n\trequestMeta?: Record<string, unknown>;\n\tresponseMeta?: Record<string, unknown>;\n\tcost?: string;\n\tcurrency?: string;\n}\n\n/**\n * Audit store interface\n */\nexport interface ChatAuditStore {\n\t/**\n\t * Save a chat audit record\n\t */\n\tsave(record: ChatAuditRecord): Promise<void>;\n\n\t/**\n\t * Query audit records\n\t */\n\tquery(options: ChatAuditQueryOptions): Promise<{ records: ChatAuditRecord[]; total: number }>;\n\n\t/**\n\t * Get aggregate statistics\n\t */\n\tgetStats(options: { from?: Date; to?: Date }): Promise<ChatAuditStats>;\n}\n\nexport interface ChatAuditQueryOptions {\n\tlimit?: number;\n\toffset?: number;\n\tmodel?: string;\n\tprovider?: string;\n\tstatus?: RequestStatusType;\n\tfrom?: Date;\n\tto?: Date;\n\tuserId?: string;\n\torgId?: string;\n}\n\n// Re-export ChatAuditStats from entities\nexport type { ChatAuditStats } from './types';\n\n/**\n * In-memory audit store implementation\n */\nexport class InMemoryChatAuditStore implements ChatAuditStore {\n\tprivate records: ChatAuditRecord[] = [];\n\tprivate maxSize: number;\n\n\tconstructor(maxSize = 10000) {\n\t\tthis.maxSize = maxSize;\n\t}\n\n\tasync save(record: ChatAuditRecord): Promise<void> {\n\t\tthis.records.unshift(record);\n\n\t\t// Trim to max size\n\t\tif (this.records.length > this.maxSize) {\n\t\t\tthis.records = this.records.slice(0, this.maxSize);\n\t\t}\n\n\t\tlog.debug(`Saved audit record: ${record.requestId} model=${record.model} status=${record.status}`);\n\t}\n\n\tasync query(options: ChatAuditQueryOptions): Promise<{ records: ChatAuditRecord[]; total: number }> {\n\t\tlet filtered = [...this.records];\n\n\t\tif (options.model) {\n\t\t\tfiltered = filtered.filter((r) => r.model === options.model);\n\t\t}\n\t\tif (options.provider) {\n\t\t\tfiltered = filtered.filter((r) => r.provider === options.provider);\n\t\t}\n\t\tif (options.status) {\n\t\t\tfiltered = filtered.filter((r) => r.status === options.status);\n\t\t}\n\t\tif (options.userId) {\n\t\t\tfiltered = filtered.filter((r) => r.userId === options.userId);\n\t\t}\n\t\tif (options.orgId) {\n\t\t\tfiltered = filtered.filter((r) => r.orgId === options.orgId);\n\t\t}\n\t\tif (options.from) {\n\t\t\tconst from = options.from;\n\t\t\tfiltered = filtered.filter((r) => r.requestedAt >= from);\n\t\t}\n\t\tif (options.to) {\n\t\t\tconst to = options.to;\n\t\t\tfiltered = filtered.filter((r) => r.requestedAt <= to);\n\t\t}\n\n\t\tconst total = filtered.length;\n\t\tconst offset = options.offset || 0;\n\t\tconst limit = options.limit || 50;\n\n\t\treturn {\n\t\t\trecords: filtered.slice(offset, offset + limit),\n\t\t\ttotal,\n\t\t};\n\t}\n\n\tasync getStats(options: { from?: Date; to?: Date }): Promise<ChatAuditStats> {\n\t\tlet filtered = [...this.records];\n\n\t\tif (options.from) {\n\t\t\tconst from = options.from;\n\t\t\tfiltered = filtered.filter((r) => r.requestedAt >= from);\n\t\t}\n\t\tif (options.to) {\n\t\t\tconst to = options.to;\n\t\t\tfiltered = filtered.filter((r) => r.requestedAt <= to);\n\t\t}\n\n\t\tconst totalRequests = filtered.length;\n\t\tconst successfulRequests = filtered.filter((r) => r.status === RequestStatus.SUCCESS).length;\n\t\tconst failedRequests = filtered.filter((r) => r.status === RequestStatus.ERROR).length;\n\n\t\tconst totalInputTokens = filtered.reduce((sum, r) => sum + (r.inputTokens || 0), 0);\n\t\tconst totalOutputTokens = filtered.reduce((sum, r) => sum + (r.outputTokens || 0), 0);\n\n\t\tconst durations = filtered.map((r) => r.durationMs).filter((d): d is number => d != null);\n\t\tconst avgDurationMs = durations.length > 0 ? durations.reduce((a, b) => a + b, 0) / durations.length : 0;\n\n\t\t// Group by model\n\t\tconst modelMap = new Map<string, { count: number; tokens: number }>();\n\t\tfor (const r of filtered) {\n\t\t\tconst existing = modelMap.get(r.model) || { count: 0, tokens: 0 };\n\t\t\texisting.count++;\n\t\t\texisting.tokens += (r.inputTokens || 0) + (r.outputTokens || 0);\n\t\t\tmodelMap.set(r.model, existing);\n\t\t}\n\t\tconst byModel = Array.from(modelMap.entries())\n\t\t\t.map(([model, data]) => ({ model, ...data }))\n\t\t\t.sort((a, b) => b.count - a.count);\n\n\t\t// Group by provider\n\t\tconst providerMap = new Map<string, { count: number; tokens: number }>();\n\t\tfor (const r of filtered) {\n\t\t\tconst provider = r.provider || 'unknown';\n\t\t\tconst existing = providerMap.get(provider) || { count: 0, tokens: 0 };\n\t\t\texisting.count++;\n\t\t\texisting.tokens += (r.inputTokens || 0) + (r.outputTokens || 0);\n\t\t\tproviderMap.set(provider, existing);\n\t\t}\n\t\tconst byProvider = Array.from(providerMap.entries())\n\t\t\t.map(([provider, data]) => ({ provider, ...data }))\n\t\t\t.sort((a, b) => b.count - a.count);\n\n\t\treturn {\n\t\t\ttotalRequests,\n\t\t\tsuccessfulRequests,\n\t\t\tfailedRequests,\n\t\t\ttotalInputTokens,\n\t\t\ttotalOutputTokens,\n\t\t\tavgDurationMs,\n\t\t\tbyModel,\n\t\t\tbyProvider,\n\t\t};\n\t}\n}\n\n// Global audit store instance\nlet auditStore: ChatAuditStore = new InMemoryChatAuditStore();\n\n/**\n * Set the audit store implementation\n */\nexport function setChatAuditStore(store: ChatAuditStore) {\n\tauditStore = store;\n}\n\n/**\n * Get the current audit store\n */\nexport function getChatAuditStore(): ChatAuditStore {\n\treturn auditStore;\n}\n\n/**\n * Generate a unique request ID\n */\nexport function generateRequestId(): string {\n\treturn `chat-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;\n}\n\n/**\n * Create an audit context for tracking a request\n */\nexport function createAuditContext(options: {\n\tmethod: string;\n\tendpoint: string;\n\tmodel: string;\n\tinputProtocol: ChatProtocolType;\n\toutputProtocol: ChatProtocolType;\n\tstreaming: boolean;\n\tclientIp?: string;\n\tuserAgent?: string;\n\tuserId?: string;\n\trequestMeta?: Record<string, unknown>;\n}): ChatAuditContext {\n\treturn new ChatAuditContext(options);\n}\n\n/**\n * Audit context for tracking a single request lifecycle\n */\nexport class ChatAuditContext {\n\tprivate record: ChatAuditRecord;\n\tprivate startTime: number;\n\tprivate firstTokenTime?: number;\n\n\tconstructor(options: {\n\t\tmethod: string;\n\t\tendpoint: string;\n\t\tmodel: string;\n\t\tinputProtocol: ChatProtocolType;\n\t\toutputProtocol: ChatProtocolType;\n\t\tstreaming: boolean;\n\t\tclientIp?: string;\n\t\tuserAgent?: string;\n\t\tuserId?: string;\n\t\trequestMeta?: Record<string, unknown>;\n\t}) {\n\t\tthis.startTime = Date.now();\n\t\tthis.record = {\n\t\t\trequestId: generateRequestId(),\n\t\t\trequestedAt: new Date(),\n\t\t\tstatus: RequestStatus.PENDING,\n\t\t\tmethod: options.method,\n\t\t\tendpoint: options.endpoint,\n\t\t\tinputProtocol: options.inputProtocol,\n\t\t\toutputProtocol: options.outputProtocol,\n\t\t\tmodel: options.model,\n\t\t\tstreaming: options.streaming,\n\t\t\tclientIp: options.clientIp,\n\t\t\tuserAgent: options.userAgent,\n\t\t\tuserId: options.userId,\n\t\t\trequestMeta: options.requestMeta,\n\t\t};\n\t}\n\n\tget requestId(): string {\n\t\treturn this.record.requestId;\n\t}\n\n\t/**\n\t * Set the resolved model and provider info\n\t */\n\tsetProvider(options: { resolvedModel?: string; provider?: string; upstreamUrl?: string }) {\n\t\tObject.assign(this.record, options);\n\t}\n\n\t/**\n\t * Record first token received (for TTFT)\n\t */\n\trecordFirstToken() {\n\t\tif (!this.firstTokenTime) {\n\t\t\tthis.firstTokenTime = Date.now();\n\t\t\tthis.record.ttftMs = this.firstTokenTime - this.startTime;\n\t\t}\n\t}\n\n\t/**\n\t * Record token usage\n\t */\n\tsetTokenUsage(input: number, output: number) {\n\t\tthis.record.inputTokens = input;\n\t\tthis.record.outputTokens = output;\n\t\tthis.record.totalTokens = input + output;\n\t}\n\n\t/**\n\t * Set response metadata\n\t */\n\tsetResponseMeta(meta: Record<string, unknown>) {\n\t\tthis.record.responseMeta = meta;\n\t}\n\n\t/**\n\t * Get current duration in ms\n\t */\n\tgetDuration(): number {\n\t\treturn Date.now() - this.startTime;\n\t}\n\n\t/**\n\t * Complete the request successfully\n\t */\n\tasync complete(httpStatus: number = 200) {\n\t\tthis.record.status = RequestStatus.SUCCESS;\n\t\tthis.record.httpStatus = httpStatus;\n\t\tthis.record.completedAt = new Date();\n\t\tthis.record.durationMs = Date.now() - this.startTime;\n\n\t\tawait auditStore.save(this.record);\n\t}\n\n\t/**\n\t * Complete the request with an error\n\t */\n\tasync error(errorMessage: string, errorCode?: string, httpStatus: number = 500) {\n\t\tthis.record.status = RequestStatus.ERROR;\n\t\tthis.record.httpStatus = httpStatus;\n\t\tthis.record.errorMessage = errorMessage;\n\t\tthis.record.errorCode = errorCode;\n\t\tthis.record.completedAt = new Date();\n\t\tthis.record.durationMs = Date.now() - this.startTime;\n\n\t\tawait auditStore.save(this.record);\n\t}\n}\n\n/**\n * Extract client IP from Hono context\n */\nexport function extractClientIp(c: Context): string | undefined {\n\treturn (\n\t\tc.req.header('x-forwarded-for')?.split(',')[0]?.trim() ||\n\t\tc.req.header('x-real-ip') ||\n\t\tc.req.header('cf-connecting-ip')\n\t);\n}\n"],"names":["consola","log","withTag","ChatProtocol","OPENAI","ANTHROPIC","GEMINI","RequestStatus","PENDING","SUCCESS","ERROR","TIMEOUT","InMemoryChatAuditStore","records","maxSize","save","record","unshift","length","slice","debug","requestId","model","status","query","options","filtered","filter","r","provider","userId","orgId","from","requestedAt","to","total","offset","limit","getStats","totalRequests","successfulRequests","failedRequests","totalInputTokens","reduce","sum","inputTokens","totalOutputTokens","outputTokens","durations","map","durationMs","d","avgDurationMs","a","b","modelMap","Map","existing","get","count","tokens","set","byModel","Array","entries","data","sort","providerMap","byProvider","auditStore","setChatAuditStore","store","getChatAuditStore","generateRequestId","Date","now","Math","random","toString","substring","createAuditContext","ChatAuditContext","startTime","firstTokenTime","method","endpoint","inputProtocol","outputProtocol","streaming","clientIp","userAgent","requestMeta","setProvider","Object","assign","recordFirstToken","ttftMs","setTokenUsage","input","output","totalTokens","setResponseMeta","meta","responseMeta","getDuration","complete","httpStatus","completedAt","error","errorMessage","errorCode","extractClientIp","c","req","header","split","trim"],"mappings":"AAAA;;;CAGC,GAED,OAAOA,aAAa,UAAU;AAG9B,MAAMC,MAAMD,QAA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AGA;QACzB,IAAI,CAAC1F,MAAM,CAAC2F,WAAW,GAAG,IAAIjC;QAC9B,IAAI,CAAC1D,MAAM,CAACkC,UAAU,GAAGwB,KAAKC,GAAG,KAAK,IAAI,CAACO,SAAS;QAEpD,MAAMb,WAAWtD,IAAI,CAAC,IAAI,CAACC,MAAM;IAClC;IAEA;;EAEC,GACD,MAAM4F,MAAMC,YAAoB,EAAEC,SAAkB,EAAEJ,aAAqB,GAAG,EAAE;QAC/E,IAAI,CAAC1F,MAAM,CAACO,MAAM,GAAGhB,cAAcG,KAAK;QACxC,IAAI,CAACM,MAAM,CAAC0F,UAAU,GAAGA;QACzB,IAAI,CAAC1F,MAAM,CAAC6F,YAAY,GAAGA;QAC3B,IAAI,CAAC7F,MAAM,CAAC8F,SAAS,GAAGA;QACxB,IAAI,CAAC9F,MAAM,CAAC2F,WAAW,GAAG,IAAIjC;QAC9B,IAAI,CAAC1D,MAAM,CAACkC,UAAU,GAAGwB,KAAKC,GAAG,KAAK,IAAI,CAACO,SAAS;QAEpD,MAAMb,WAAWtD,IAAI,CAAC,IAAI,CAACC,MAAM;IAClC;AACD;AAEA;;CAEC,GACD,OAAO,SAAS+F,gBAAgBC,CAAU;IACzC,OACCA,EAAEC,GAAG,CAACC,MAAM,CAAC,oBAAoBC,MAAM,IAAI,CAAC,EAAE,EAAEC,UAChDJ,EAAEC,GAAG,CAACC,MAAM,CAAC,gBACbF,EAAEC,GAAG,CAACC,MAAM,CAAC;AAEf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/entities/ChatRequestEntity.ts"],"sourcesContent":["import { Entity, Enum, PrimaryKey, Property } from '@mikro-orm/decorators/es';\n\n/**\n * Chat protocol type\n */\nexport const ChatProtocolType = Object.freeze({\n\tOpenAI: 'openai',\n\tAnthropic: 'anthropic',\n\tGemini: 'gemini',\n} as const);\nexport type ChatProtocolType = (typeof ChatProtocolType)[keyof typeof ChatProtocolType];\n\n/**\n * Request status\n */\nexport const RequestStatus = Object.freeze({\n\tPending: 'pending',\n\tSuccess: 'success',\n\tError: 'error',\n\tTimeout: 'timeout',\n} as const);\nexport type RequestStatus = (typeof RequestStatus)[keyof typeof RequestStatus];\n\n/**\n * Chat Request Entity for auditing and metering\n */\n@Entity({ tableName: 'chat_request' })\nexport class ChatRequestEntity {\n\t@PrimaryKey({ type: 'integer' })\n\tid!: number;\n\n\t/** Unique request ID for tracing */\n\t@Property({ type: 'string', unique: true })\n\trequestId!: string;\n\n\t/** Request timestamp */\n\t@Property({ type: 'datetime' })\n\trequestedAt: Date = new Date();\n\n\t/** Response timestamp */\n\t@Property({ type: 'datetime', nullable: true })\n\tcompletedAt?: Date;\n\n\t/** Request status */\n\t@Enum(() => RequestStatus)\n\tstatus: RequestStatus = RequestStatus.Pending;\n\n\t/** HTTP method */\n\t@Property({ type: 'string' })\n\tmethod!: string;\n\n\t/** Request path/endpoint */\n\t@Property({ type: 'string' })\n\tendpoint!: string;\n\n\t/** Input protocol (client-facing) */\n\t@Enum(() => ChatProtocolType)\n\tinputProtocol!: ChatProtocolType;\n\n\t/** Output protocol (upstream provider) */\n\t@Enum(() => ChatProtocolType)\n\toutputProtocol!: ChatProtocolType;\n\n\t/** Model name requested */\n\t@Property({ type: 'string' })\n\tmodel!: string;\n\n\t/** Resolved model name */\n\t@Property({ type: 'string', nullable: true })\n\tresolvedModel?: string;\n\n\t/** Provider name */\n\t@Property({ type: 'string', nullable: true })\n\tprovider?: string;\n\n\t/** Upstream base URL */\n\t@Property({ type: 'string', nullable: true })\n\tupstreamUrl?: string;\n\n\t/** Whether request was streaming */\n\t@Property({ type: 'boolean', default: false })\n\tstreaming: boolean = false;\n\n\t/** Input token count */\n\t@Property({ type: 'integer', nullable: true })\n\tinputTokens?: number;\n\n\t/** Output token count */\n\t@Property({ type: 'integer', nullable: true })\n\toutputTokens?: number;\n\n\t/** Total token count */\n\t@Property({ type: 'integer', nullable: true })\n\ttotalTokens?: number;\n\n\t/** Request duration in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tdurationMs?: number;\n\n\t/** Time to first token in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tttftMs?: number;\n\n\t/** HTTP status code */\n\t@Property({ type: 'integer', nullable: true })\n\thttpStatus?: number;\n\n\t/** Error message */\n\t@Property({ type: 'text', nullable: true })\n\terrorMessage?: string;\n\n\t/** Error code */\n\t@Property({ type: 'string', nullable: true })\n\terrorCode?: string;\n\n\t/** Client IP */\n\t@Property({ type: 'string', nullable: true })\n\tclientIp?: string;\n\n\t/** User agent */\n\t@Property({ type: 'string', nullable: true })\n\tuserAgent?: string;\n\n\t/** User ID */\n\t@Property({ type: 'string', nullable: true })\n\tuserId?: string;\n\n\t/** Organization ID */\n\t@Property({ type: 'string', nullable: true })\n\torgId?: string;\n\n\t/** API key ID (not the actual key) */\n\t@Property({ type: 'string', nullable: true })\n\tapiKeyId?: string;\n\n\t/** Request metadata (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestMeta?: Record<string, unknown>;\n\n\t/** Response metadata (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\tresponseMeta?: Record<string, unknown>;\n\n\t/** Cost in credits (decimal string) */\n\t@Property({ type: 'string', nullable: true })\n\tcost?: string;\n\n\t/** Currency */\n\t@Property({ type: 'string', nullable: true })\n\tcurrency?: string;\n\n\t@Property({ type: 'datetime' })\n\tcreatedAt: Date = new Date();\n\n\t@Property({ type: 'datetime', onUpdate: () => new Date() })\n\tupdatedAt: Date = new Date();\n}\n"],"names":["id","requestId","requestedAt","completedAt","status","method","endpoint","inputProtocol","outputProtocol","model","resolvedModel","provider","upstreamUrl","streaming","inputTokens","outputTokens","totalTokens","durationMs","ttftMs","httpStatus","errorMessage","errorCode","clientIp","userAgent","userId","orgId","apiKeyId","requestMeta","responseMeta","cost","currency","createdAt","updatedAt","Entity","Enum","PrimaryKey","Property","ChatProtocolType","Object","freeze","OpenAI","Anthropic","Gemini","RequestStatus","Pending","Success","Error","Timeout","tableName","type","unique","nullable","default","onUpdate","Date","ChatRequestEntity"],"mappings":";qRA4BC,AACAA,UAEA,kCAAkC,GAClC,AACAC,iBAEA,sBAAsB,GACtB,AACAC,mBAEA,uBAAuB,GACvB,AACAC,mBAEA,mBAAmB,GACnB,AACAC,cAEA,gBAAgB,GAChB,AACAC,cAEA,0BAA0B,GAC1B,AACAC,gBAEA,mCAAmC,GACnC,AACAC,qBAEA,wCAAwC,GACxC,AACAC,sBAEA,yBAAyB,GACzB,AACAC,aAEA,wBAAwB,GACxB,AACAC,qBAEA,kBAAkB,GAClB,AACAC,gBAEA,sBAAsB,GACtB,AACAC,mBAEA,kCAAkC,GAClC,AACAC,iBAEA,sBAAsB,GACtB,AACAC,mBAEA,uBAAuB,GACvB,AACAC,oBAEA,sBAAsB,GACtB,AACAC,mBAEA,2BAA2B,GAC3B,AACAC,kBAEA,8BAA8B,GAC9B,AACAC,cAEA,qBAAqB,GACrB,AACAC,kBAEA,kBAAkB,GAClB,AACAC,oBAEA,eAAe,GACf,AACAC,iBAEA,cAAc,GACd,AACAC,gBAEA,eAAe,GACf,AACAC,iBAEA,YAAY,GACZ,AACAC,cAEA,oBAAoB,GACpB,AACAC,aAEA,oCAAoC,GACpC,AACAC,gBAEA,4BAA4B,GAC5B,AACAC,mBAEA,6BAA6B,GAC7B,AACAC,oBAEA,qCAAqC,GACrC,AACAC,YAEA,aAAa,GACb,AACAC,gBAEA,AACAC,iBAEA,AACAC;AA3JD,SAASC,MAAM,EAAEC,IAAI,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,2BAA2B;AAE9E;;CAEC,GACD,OAAO,MAAMC,mBAAmBC,OAAOC,MAAM,CAAC;IAC7CC,QAAQ;IACRC,WAAW;IACXC,QAAQ;AACT,GAAY;AAGZ;;CAEC,GACD,OAAO,MAAMC,gBAAgBL,OAAOC,MAAM,CAAC;IAC1CK,SAAS;IACTC,SAAS;IACTC,OAAO;IACPC,SAAS;AACV,GAAY;;OAMXd,OAAO;IAAEe,WA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A,kBAAe;IAIfC,gBAAAA,0BAAuB;IAIvBC,WAAAA,qBAAkB;IAIlBC,cAAAA,wBAAqB;IAIrBC,YAAAA,sBAAqB,OAAM;IAI3BC,cAAAA,wBAAqB;IAIrBC,eAAAA,yBAAsB;IAItBC,cAAAA,wBAAqB;IAIrBC,aAAAA,uBAAoB;IAIpBC,SAAAA,mBAAgB;IAIhBC,aAAAA,uBAAoB;IAIpBC,eAAAA,yBAAsB;IAItBC,YAAAA,sBAAmB;IAInBC,WAAAA,qBAAkB;IAIlBC,YAAAA,sBAAmB;IAInBC,SAAAA,mBAAgB;IAIhBC,QAAAA,kBAAe;IAIfC,WAAAA,qBAAkB;IAIlBC,cAAAA,wBAAsC;IAItCC,eAAAA,yBAAuC;IAIvCC,OAAAA,iBAAc;IAIdC,WAAAA,qBAAkB;IAGlBC,YAAAA,sBAAkB,IAAIuB,QAAO;IAG7BtB,YAAAA,sBAAkB,IAAIsB,QAAO;;;;AAC9B;SAjIA,AAAaC,sBAAAA,iBAiIZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/entities/McpRequestEntity.ts"],"sourcesContent":["import { Entity, Enum, PrimaryKey, Property } from '@mikro-orm/decorators/es';\n\n/**\n * MCP server type\n */\nexport const McpServerType = Object.freeze({\n\tTencentCls: 'tencent-cls',\n\tSql: 'sql',\n\tPrometheus: 'prometheus',\n\tRelay: 'relay',\n\tCustom: 'custom',\n} as const);\nexport type McpServerType = (typeof McpServerType)[keyof typeof McpServerType];\n\n/**\n * MCP request type (JSON-RPC method)\n */\nexport const McpRequestType = Object.freeze({\n\tInitialize: 'initialize',\n\tToolsList: 'tools/list',\n\tToolsCall: 'tools/call',\n\tResourcesList: 'resources/list',\n\tResourcesRead: 'resources/read',\n\tPromptsList: 'prompts/list',\n\tPromptsGet: 'prompts/get',\n\tCompletionComplete: 'completion/complete',\n\tLoggingSetLevel: 'logging/setLevel',\n\tPing: 'ping',\n\tOther: 'other',\n} as const);\nexport type McpRequestType = (typeof McpRequestType)[keyof typeof McpRequestType];\n\n/**\n * Request status\n */\nexport const RequestStatus = Object.freeze({\n\tPending: 'pending',\n\tSuccess: 'success',\n\tError: 'error',\n\tTimeout: 'timeout',\n} as const);\nexport type RequestStatus = (typeof RequestStatus)[keyof typeof RequestStatus];\n\n/**\n * MCP Request Entity for auditing\n */\n@Entity({ tableName: 'mcp_request' })\nexport class McpRequestEntity {\n\t@PrimaryKey({ type: 'integer' })\n\tid!: number;\n\n\t/** Unique request ID */\n\t@Property({ type: 'string' })\n\trequestId!: string;\n\n\t/** MCP session ID */\n\t@Property({ type: 'string', nullable: true })\n\tsessionId?: string;\n\n\t/** Request timestamp */\n\t@Property({ type: 'datetime' })\n\trequestedAt: Date = new Date();\n\n\t/** Response timestamp */\n\t@Property({ type: 'datetime', nullable: true })\n\tcompletedAt?: Date;\n\n\t/** Request status */\n\t@Enum(() => RequestStatus)\n\tstatus: RequestStatus = RequestStatus.Pending;\n\n\t/** HTTP method */\n\t@Property({ type: 'string' })\n\tmethod!: string;\n\n\t/** Request path */\n\t@Property({ type: 'string' })\n\tpath!: string;\n\n\t/** MCP server name */\n\t@Property({ type: 'string' })\n\tserverName!: string;\n\n\t/** MCP server type */\n\t@Enum(() => McpServerType)\n\tserverType: McpServerType = McpServerType.Custom;\n\n\t/** MCP request type (JSON-RPC method) */\n\t@Enum(() => McpRequestType)\n\tmcpMethod: McpRequestType = McpRequestType.Other;\n\n\t/** Tool name (for tools/call) */\n\t@Property({ type: 'string', nullable: true })\n\ttoolName?: string;\n\n\t/** Resource URI (for resources/read) */\n\t@Property({ type: 'string', nullable: true })\n\tresourceUri?: string;\n\n\t/** Prompt name (for prompts/get) */\n\t@Property({ type: 'string', nullable: true })\n\tpromptName?: string;\n\n\t/** Request duration in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tdurationMs?: number;\n\n\t/** HTTP status code */\n\t@Property({ type: 'integer', nullable: true })\n\thttpStatus?: number;\n\n\t/** Error message */\n\t@Property({ type: 'text', nullable: true })\n\terrorMessage?: string;\n\n\t/** Error code */\n\t@Property({ type: 'string', nullable: true })\n\terrorCode?: string;\n\n\t/** Client IP */\n\t@Property({ type: 'string', nullable: true })\n\tclientIp?: string;\n\n\t/** User agent */\n\t@Property({ type: 'string', nullable: true })\n\tuserAgent?: string;\n\n\t/** User ID */\n\t@Property({ type: 'string', nullable: true })\n\tuserId?: string;\n\n\t/** Request headers (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestHeaders?: Record<string, string>;\n\n\t/** Request body (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestBody?: Record<string, unknown>;\n\n\t/** Response metadata (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\tresponseMeta?: Record<string, unknown>;\n\n\t@Property({ type: 'datetime' })\n\tcreatedAt: Date = new Date();\n\n\t@Property({ type: 'datetime', onUpdate: () => new Date() })\n\tupdatedAt: Date = new Date();\n}\n"],"names":["id","requestId","sessionId","requestedAt","completedAt","status","method","path","serverName","serverType","mcpMethod","toolName","resourceUri","promptName","durationMs","httpStatus","errorMessage","errorCode","clientIp","userAgent","userId","requestHeaders","requestBody","responseMeta","createdAt","updatedAt","Entity","Enum","PrimaryKey","Property","McpServerType","Object","freeze","TencentCls","Sql","Prometheus","Relay","Custom","McpRequestType","Initialize","ToolsList","ToolsCall","ResourcesList","ResourcesRead","PromptsList","PromptsGet","CompletionComplete","LoggingSetLevel","Ping","Other","RequestStatus","Pending","Success","Error","Timeout","tableName","type","nullable","onUpdate","Date","McpRequestEntity"],"mappings":";6NAgDC,AACAA,UAEA,sBAAsB,GACtB,AACAC,iBAEA,mBAAmB,GACnB,AACAC,iBAEA,sBAAsB,GACtB,AACAC,mBAEA,uBAAuB,GACvB,AACAC,mBAEA,mBAAmB,GACnB,AACAC,cAEA,gBAAgB,GAChB,AACAC,cAEA,iBAAiB,GACjB,AACAC,YAEA,oBAAoB,GACpB,AACAC,kBAEA,oBAAoB,GACpB,AACAC,kB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AIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAGAC;;;;;gBAGAC;;;;;;IAlGAzB,wBAAAA,gBAAY;IAIZC,YAAAA,sBAAmB;IAInBC,YAAAA,sBAAmB;IAInBC,cAAAA,wBAAoB,IAAIwD,QAAO;IAI/BvD,cAAAA,wBAAmB;IAInBC,SAAAA,mBAAwB6C,cAAcC,OAAO,EAAC;IAI9C7C,SAAAA,mBAAgB;IAIhBC,OAAAA,iBAAc;IAIdC,aAAAA,uBAAoB;IAIpBC,aAAAA,uBAA4BqB,cAAcO,MAAM,EAAC;IAIjD3B,YAAAA,sBAA4B4B,eAAeW,KAAK,EAAC;IAIjDtC,WAAAA,qBAAkB;IAIlBC,cAAAA,wBAAqB;IAIrBC,aAAAA,uBAAoB;IAIpBC,aAAAA,uBAAoB;IAIpBC,aAAAA,uBAAoB;IAIpBC,eAAAA,yBAAsB;IAItBC,YAAAA,sBAAmB;IAInBC,WAAAA,qBAAkB;IAIlBC,YAAAA,sBAAmB;IAInBC,SAAAA,mBAAgB;IAIhBC,iBAAAA,2BAAwC;IAIxCC,cAAAA,wBAAsC;IAItCC,eAAAA,yBAAuC;IAGvCC,YAAAA,sBAAkB,IAAImC,QAAO;IAG7BlC,YAAAA,sBAAkB,IAAIkC,QAAO;;;;AAC9B;SArGA,AAAaC,qBAAAA,gBAqGZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/entities/RequestLogEntity.ts"],"sourcesContent":["import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/es';\n\n/**\n * Generic HTTP Request Log Entity\n * For general request auditing\n */\n@Entity({ tableName: 'request_log' })\nexport class RequestLogEntity {\n\t@PrimaryKey({ type: 'integer' })\n\tid!: number;\n\n\t/** Unique request ID */\n\t@Property({ type: 'string' })\n\trequestId!: string;\n\n\t/** Request timestamp */\n\t@Property({ type: 'datetime' })\n\ttimestamp: Date = new Date();\n\n\t/** HTTP method */\n\t@Property({ type: 'string' })\n\tmethod!: string;\n\n\t/** Request path */\n\t@Property({ type: 'string' })\n\tpath!: string;\n\n\t/** Request type (chat, mcp, api, etc) */\n\t@Property({ type: 'string', nullable: true })\n\trequestType?: string;\n\n\t/** Server name (for MCP) or model (for Chat) */\n\t@Property({ type: 'string', nullable: true })\n\tserverName?: string;\n\n\t/** Server type */\n\t@Property({ type: 'string', nullable: true })\n\tserverType?: string;\n\n\t/** HTTP status code */\n\t@Property({ type: 'integer', nullable: true })\n\tstatus?: number;\n\n\t/** Request duration in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tdurationMs?: number;\n\n\t/** Error message */\n\t@Property({ type: 'text', nullable: true })\n\terror?: string;\n\n\t/** Client IP */\n\t@Property({ type: 'string', nullable: true })\n\tclientIp?: string;\n\n\t/** User agent */\n\t@Property({ type: 'string', nullable: true })\n\tuserAgent?: string;\n\n\t/** Request headers (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestHeaders?: Record<string, string>;\n\n\t/** Request body summary (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\trequestBody?: Record<string, unknown>;\n\n\t/** Response body summary (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\tresponseBody?: Record<string, unknown>;\n\n\t/** Additional metadata (JSON) */\n\t@Property({ type: 'json', nullable: true })\n\tmetadata?: Record<string, unknown>;\n\n\t@Property({ type: 'datetime' })\n\tcreatedAt: Date = new Date();\n}\n"],"names":["id","requestId","timestamp","method","path","requestType","serverName","serverType","status","durationMs","error","clientIp","userAgent","requestHeaders","requestBody","responseBody","metadata","createdAt","Entity","PrimaryKey","Property","tableName","type","nullable","RequestLogEntity","Date"],"mappings":";6JAQC,AACAA,UAEA,sBAAsB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AAEE,MAAM;IAAQC,UAAU;AAAK,aAGxCH,SAAS;IAAEE,MAAM;AAAW;AApEvB,IAAA,AAAME,mBAAN,MAAMA;;eAEZxB,UAIAC,iBAIAC,iBAIAC,cAIAC,YAIAC,mBAIAC,kBAIAC,kBAIAC,cAIAC,kBAIAC,aAIAC,gBAIAC,iBAIAC,sBAIAC,mBAIAC,oBAIAC,gBAGAC;;;;gBAnEAjB;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAGAC;;;;;;IAnEAjB,wBAAAA,gBAAY;IAIZC,YAAAA,sBAAmB;IAInBC,YAAAA,sBAAkB,IAAIuB,QAAO;IAI7BtB,SAAAA,mBAAgB;IAIhBC,OAAAA,iBAAc;IAIdC,cAAAA,wBAAqB;IAIrBC,aAAAA,uBAAoB;IAIpBC,aAAAA,uBAAoB;IAIpBC,SAAAA,mBAAgB;IAIhBC,aAAAA,uBAAoB;IAIpBC,QAAAA,kBAAe;IAIfC,WAAAA,qBAAkB;IAIlBC,YAAAA,sBAAmB;IAInBC,iBAAAA,2BAAwC;IAIxCC,cAAAA,wBAAsC;IAItCC,eAAAA,yBAAuC;IAIvCC,WAAAA,qBAAmC;IAGnCC,YAAAA,sBAAkB,IAAIQ,QAAO;;;;AAC9B;SAtEA,AAAaD,qBAAAA,gBAsEZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/entities/ResponseEntity.ts"],"sourcesContent":["import { Entity, PrimaryKey, Property } from '@mikro-orm/decorators/es';\n\n/**\n * Response Entity for storing Responses API responses\n * Enables previous_response_id support\n */\n@Entity({ tableName: 'response' })\nexport class ResponseEntity {\n\t@PrimaryKey({ type: 'integer' })\n\tid!: number;\n\n\t/** Response ID (e.g., resp_xxx) */\n\t@Property({ type: 'string', unique: true })\n\tresponseId!: string;\n\n\t/** Model name */\n\t@Property({ type: 'string' })\n\tmodel!: string;\n\n\t/** Response status */\n\t@Property({ type: 'string' })\n\tstatus!: string;\n\n\t/** Input (request) - stored as JSON */\n\t@Property({ type: 'json' })\n\tinput!: unknown;\n\n\t/** Output items - stored as JSON */\n\t@Property({ type: 'json' })\n\toutput!: unknown[];\n\n\t/** Usage statistics */\n\t@Property({ type: 'json', nullable: true })\n\tusage?: {\n\t\tprompt_tokens?: number;\n\t\tcompletion_tokens?: number;\n\t\ttotal_tokens?: number;\n\t};\n\n\t/** Instructions/system prompt */\n\t@Property({ type: 'text', nullable: true })\n\tinstructions?: string;\n\n\t/** Previous response ID for conversation chaining */\n\t@Property({ type: 'string', nullable: true })\n\tpreviousResponseId?: string;\n\n\t/** Tools configuration */\n\t@Property({ type: 'json', nullable: true })\n\ttools?: unknown[];\n\n\t/** Tool choice */\n\t@Property({ type: 'json', nullable: true })\n\ttoolChoice?: unknown;\n\n\t/** Metadata */\n\t@Property({ type: 'json', nullable: true })\n\tmetadata?: Record<string, unknown>;\n\n\t/** Error information */\n\t@Property({ type: 'json', nullable: true })\n\terror?: {\n\t\ttype?: string;\n\t\tmessage?: string;\n\t\tcode?: string;\n\t};\n\n\t/** Created timestamp */\n\t@Property({ type: 'datetime' })\n\tcreatedAt: Date = new Date();\n\n\t/** Request duration in ms */\n\t@Property({ type: 'integer', nullable: true })\n\tdurationMs?: number;\n}\n"],"names":["id","responseId","model","status","input","output","usage","instructions","previousResponseId","tools","toolChoice","metadata","error","createdAt","durationMs","Entity","PrimaryKey","Property","tableName","type","unique","nullable","ResponseEntity","Date"],"mappings":";qIAQC,AACAA,UAEA,iCAAiC,GACjC,AACAC,kBAEA,eAAe,GACf,AACAC,aAEA,oBAAoB,GACpB,AACAC,cAEA,qCAAqC,GACrC,AACAC,aAEA,kCAAkC,GAClC,AACAC,cAEA,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gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAIAC;;;;;gBAQAC;;;;;gBAIAC;;;;;;IAhEAd,wBAAAA,gBAAY;IAIZC,aAAAA,uBAAoB;IAIpBC,QAAAA,kBAAe;IAIfC,SAAAA,mBAAgB;IAIhBC,QAAAA,kBAAgB;IAIhBC,SAAAA,mBAAmB;IAInBC,QAAAA,kBAIE;IAIFC,eAAAA,yBAAsB;IAItBC,qBAAAA,+BAA4B;IAI5BC,QAAAA,kBAAkB;IAIlBC,aAAAA,uBAAqB;IAIrBC,WAAAA,qBAAmC;IAInCC,QAAAA,kBAIE;IAIFC,YAAAA,sBAAkB,IAAIU,QAAO;IAI7BT,aAAAA,uBAAoB;;;;AACrB;SAnEA,AAAaQ,mBAAAA,cAmEZ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "../types.js";
|
|
2
|
+
export { ChatRequestEntity, ChatProtocolType, RequestStatus } from "./ChatRequestEntity.js";
|
|
3
|
+
export { McpRequestEntity, McpServerType, McpRequestType } from "./McpRequestEntity.js";
|
|
4
|
+
export { RequestLogEntity } from "./RequestLogEntity.js";
|
|
5
|
+
export { ResponseEntity } from "./ResponseEntity.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/entities/index.ts"],"sourcesContent":["export * from '../types';\n\nexport { ChatRequestEntity, ChatProtocolType, RequestStatus } from './ChatRequestEntity';\nexport { McpRequestEntity, McpServerType, McpRequestType } from './McpRequestEntity';\nexport { RequestLogEntity } from './RequestLogEntity';\nexport { ResponseEntity } from './ResponseEntity';\n"],"names":["ChatRequestEntity","ChatProtocolType","RequestStatus","McpRequestEntity","McpServerType","McpRequestType","RequestLogEntity","ResponseEntity"],"mappings":"AAAA,cAAc,WAAW;AAEzB,SAASA,iBAAiB,EAAEC,gBAAgB,EAAEC,aAAa,QAAQ,sBAAsB;AACzF,SAASC,gBAAgB,EAAEC,aAAa,EAAEC,cAAc,QAAQ,qBAAqB;AACrF,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,cAAc,QAAQ,mBAAmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/server/db.ts"],"sourcesContent":["import { MikroORM, type Options } from '@mikro-orm/core';\nimport { SqliteDriver } from '@mikro-orm/sql';\nimport { createSqliteDialect } from '@wener/server/mikro-orm';\nimport type { DbConfig } from '../../server/schema';\nimport { ChatRequestEntity } from '../entities/ChatRequestEntity';\nimport { McpRequestEntity } from '../entities/McpRequestEntity';\nimport { RequestLogEntity } from '../entities/RequestLogEntity';\nimport { ResponseEntity } from '../entities/ResponseEntity';\n\nexport { RequestLogEntity };\n\nlet orm: MikroORM<SqliteDriver> | null = null;\nlet initPromise: Promise<MikroORM<SqliteDriver>> | null = null;\n\nasync function getOrmConfig(dbConfig?: DbConfig): Promise<Options<SqliteDriver>> {\n\tconst dbPath = dbConfig?.path || '.mcps.db';\n\treturn {\n\t\tdriver: SqliteDriver,\n\t\tdbName: dbPath,\n\t\tentities: [ChatRequestEntity, McpRequestEntity, RequestLogEntity, ResponseEntity],\n\t\tdriverOptions: await createSqliteDialect(dbPath),\n\t\tdebug: process.env.NODE_ENV === 'development',\n\t\tallowGlobalContext: true,\n\t};\n}\n\nexport async function ensureDbInitialized(dbConfig?: DbConfig): Promise<MikroORM<SqliteDriver>> {\n\tif (orm) return orm;\n\tif (initPromise) return initPromise;\n\n\tinitPromise = (async () => {\n\t\tconst config = await getOrmConfig(dbConfig);\n\t\torm = await MikroORM.init(config);\n\t\tawait orm.schema.update();\n\t\treturn orm;\n\t})();\n\n\ttry {\n\t\treturn await initPromise;\n\t} catch (e) {\n\t\tinitPromise = null;\n\t\tthrow e;\n\t}\n}\n\nexport function getOrm(): MikroORM<SqliteDriver> {\n\tif (!orm) throw new Error('Database not initialized');\n\treturn orm;\n}\n\nexport function getEntityManager() {\n\treturn getOrm().em;\n}\n\nexport async function closeDb(): Promise<void> {\n\tif (orm) {\n\t\tawait orm.close();\n\t\torm = null;\n\t\tinitPromise = null;\n\t}\n}\n\nexport function isDbInitialized(): boolean {\n\treturn orm !== null;\n}\n"],"names":["MikroORM","SqliteDriver","createSqliteDialect","ChatRequestEntity","McpRequestEntity","RequestLogEntity","ResponseEntity","orm","initPromise","getOrmConfig","dbConfig","dbPath","path","driver","dbName","entities","driverOptions","debug","process","env","NODE_ENV","allowGlobalContext","ensureDbInitialized","config","init","schema","update","e","getOrm","Error","getEntityManager","em","closeDb","close","isDbInitialized"],"mappings":"AAAA,SAASA,QAAQ,QAAsB,kBAAkB;AACzD,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,mBAAmB,QAAQ,0BAA0B;AAE9D,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,cAAc,QAAQ,6BAA6B;AAE5D,SAASD,gBAAgB,GAAG;AAE5B,IAAIE,MAAqC;AACzC,IAAIC,cAAsD;AAE1D,eAAeC,aAAaC,QAAmB;IAC9C,MAAMC,SAASD,UAAUE,QAAQ;IACjC,OAAO;QACNC,QAAQZ;QACRa,QAAQH;QACRI,UAAU;YAACZ;YAAmBC;YAAkBC;YAAkBC;SAAe;QACjFU,eAAe,MAAMd,oBAAoBS;QACzCM,OAAOC,QAAQC,GAAG,CAACC,QAAQ,KAAK;QAChCC,oBAAoB;IACrB;AACD;AAEA,OAAO,eAAeC,oBAAoBZ,QAAmB;IAC5D,IAAIH,KAAK,OAAOA;IAChB,IAAIC,aAAa,OAAOA;IAExBA,cAAc,AAAC,CAAA;QACd,MAAMe,SAAS,MAAMd,aAAaC;QAClCH,MAAM,MAAMP,SAASwB,IAAI,CAACD;QAC1B,MAAMhB,IAAIkB,MAAM,CAACC,MAAM;QACvB,OAAOnB;IACR,CAAA;IAEA,IAAI;QACH,OAAO,MAAMC;IACd,EAAE,OAAOmB,GAAG;QACXnB,cAAc;QACd,MAAMmB;IACP;AACD;AAEA,OAAO,SAASC;IACf,IAAI,CAACrB,KAAK,MAAM,IAAIsB,MAAM;IAC1B,OAAOtB;AACR;AAEA,OAAO,SAASuB;IACf,OAAOF,SAASG,EAAE;AACnB;AAEA,OAAO,eAAeC;IACrB,IAAIzB,KAAK;QACR,MAAMA,IAAI0B,KAAK;QACf1B,MAAM;QACNC,cAAc;IACf;AACD;AAEA,OAAO,SAAS0B;IACf,OAAO3B,QAAQ;AAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/audit/server/index.ts"],"sourcesContent":["export {\n\tsetupAudit,\n\tAuditRouter,\n\taddAuditEvent,\n\tqueryAuditEvents,\n\tgetAuditStats,\n\tclearAuditEvents,\n} from './plugin';\n"],"names":["setupAudit","AuditRouter","addAuditEvent","queryAuditEvents","getAuditStats","clearAuditEvents"],"mappings":"AAAA,SACCA,UAAU,EACVC,WAAW,EACXC,aAAa,EACbC,gBAAgB,EAChBC,aAAa,EACbC,gBAAgB,QACV,WAAW"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { implement } from "@orpc/server";
|
|
2
2
|
import { LRUCache } from "lru-cache";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { McpsEventType } from "../../server/events.js";
|
|
4
|
+
import { AuditContract } from "../AuditContract.js";
|
|
5
5
|
function headersToRecord(headers) {
|
|
6
6
|
const record = {};
|
|
7
7
|
headers.forEach((value, key) => {
|
|
@@ -21,7 +21,7 @@ async function persistToDb(event, id) {
|
|
|
21
21
|
if (!dbConfigured)
|
|
22
22
|
return;
|
|
23
23
|
try {
|
|
24
|
-
const { ensureDbInitialized, RequestLogEntity } = await import("./
|
|
24
|
+
const { ensureDbInitialized, RequestLogEntity } = await import("./db.js");
|
|
25
25
|
const orm = await ensureDbInitialized(storedDbConfig);
|
|
26
26
|
const em = orm.em.fork();
|
|
27
27
|
const logEntry = new RequestLogEntity();
|
|
@@ -217,4 +217,4 @@ export const AuditRouter = implement(AuditContract).router({
|
|
|
217
217
|
}
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
|
-
//# sourceMappingURL=
|
|
220
|
+
//# sourceMappingURL=plugin.js.map
|