@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/package.json
CHANGED
|
@@ -1,113 +1,146 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
2
|
+
"name": "@wener/mcps",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mcps": "./dist/mcps-cli.mjs"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.mjs",
|
|
11
|
+
"imports": {
|
|
12
|
+
"#/*": "./*"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./src/index.ts",
|
|
16
|
+
"./server": "./src/server/index.ts",
|
|
17
|
+
"./entities": "./src/audit/entities/index.ts",
|
|
18
|
+
"./contracts": "./src/contracts/index.ts",
|
|
19
|
+
"./chat": "./src/chat/index.ts",
|
|
20
|
+
"./providers": "./src/providers/McpServerHandlerDef.ts",
|
|
21
|
+
"./cli": "./src/cli.ts",
|
|
22
|
+
"./audit/server": "./src/audit/server/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"lib",
|
|
27
|
+
"src",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"keywords": [],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "bun run ./src/scripts/bundle.ts",
|
|
33
|
+
"dev": "pnpm tsx --watch src/mcps-cli.ts",
|
|
34
|
+
"dev:web": "vite",
|
|
35
|
+
"prepublishOnly": "make build",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"typecheck": "tsc --noEmit"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@mikro-orm/core": "*",
|
|
41
|
+
"@mikro-orm/decorators": "*",
|
|
42
|
+
"@mikro-orm/sql": "*",
|
|
43
|
+
"@wener/server": "*"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@mikro-orm/core": {
|
|
47
|
+
"optional": true
|
|
48
|
+
},
|
|
49
|
+
"@mikro-orm/decorators": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@mikro-orm/sql": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"@wener/server": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"emittery": "^1.2.0"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@ai-sdk/mcp": "^1.0.18",
|
|
64
|
+
"@ai-sdk/openai-compatible": "^2.0.26",
|
|
65
|
+
"@ai-sdk/react": "^3.0.71",
|
|
66
|
+
"@base-ui/react": "^1.1.0",
|
|
67
|
+
"@hono/mcp": "^0.2.3",
|
|
68
|
+
"@larksuiteoapi/node-sdk": "^1.59.0",
|
|
69
|
+
"@hono/node-server": "^1.19.9",
|
|
70
|
+
"@hono/vite-dev-server": "^0.24.1",
|
|
71
|
+
"@mikro-orm/core": "^7.0.0-rc.2",
|
|
72
|
+
"@mikro-orm/decorators": "^7.0.0-rc.2",
|
|
73
|
+
"@mikro-orm/sql": "^7.0.0-rc.2",
|
|
74
|
+
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
75
|
+
"@orpc/client": "^1.13.4",
|
|
76
|
+
"@orpc/contract": "^1.13.4",
|
|
77
|
+
"@orpc/json-schema": "^1.13.4",
|
|
78
|
+
"@orpc/openapi": "^1.13.4",
|
|
79
|
+
"@orpc/server": "^1.13.4",
|
|
80
|
+
"@orpc/zod": "^1.13.4",
|
|
81
|
+
"@streamdown/cjk": "^1.0.1",
|
|
82
|
+
"@streamdown/code": "^1.0.1",
|
|
83
|
+
"@streamdown/math": "^1.0.1",
|
|
84
|
+
"@streamdown/mermaid": "^1.0.1",
|
|
85
|
+
"@wener/ai": "workspace:*",
|
|
86
|
+
"@wener/client": "workspace:^1.0.26",
|
|
87
|
+
"@wener/common": "^2.0.3",
|
|
88
|
+
"@wener/server": "workspace:*",
|
|
89
|
+
"ai": "^6.0.69",
|
|
90
|
+
"commander": "^14.0.3",
|
|
91
|
+
"consola": "^3.4.2",
|
|
92
|
+
"hono": "^4.11.7",
|
|
93
|
+
"kysely": "^0.28.11",
|
|
94
|
+
"lru-cache": "^11.2.5",
|
|
95
|
+
"lucide-react": "^0.562.0",
|
|
96
|
+
"mysql2": "^3.16.3",
|
|
97
|
+
"openai": "^6.17.0",
|
|
98
|
+
"pg-query-stream": "^4.12.0",
|
|
99
|
+
"react": "^19.2.4",
|
|
100
|
+
"react-dom": "^19.2.4",
|
|
101
|
+
"react-markdown": "^10.1.0",
|
|
102
|
+
"react-router-dom": "^7.13.0",
|
|
103
|
+
"std-env": "^3.10.0",
|
|
104
|
+
"streamdown": "^2.1.0",
|
|
105
|
+
"tarn": "^3.0.2",
|
|
106
|
+
"tedious": "^19.2.0",
|
|
107
|
+
"yaml": "^2.8.2",
|
|
108
|
+
"zod": "^4.3.6"
|
|
109
|
+
},
|
|
110
|
+
"publishConfig": {
|
|
111
|
+
"exports": {
|
|
112
|
+
".": {
|
|
113
|
+
"types": "./src/index.ts",
|
|
114
|
+
"default": "./lib/index.js"
|
|
115
|
+
},
|
|
116
|
+
"./server": {
|
|
117
|
+
"types": "./src/server/index.ts",
|
|
118
|
+
"default": "./lib/server/index.js"
|
|
119
|
+
},
|
|
120
|
+
"./entities": {
|
|
121
|
+
"types": "./src/audit/entities/index.ts",
|
|
122
|
+
"default": "./lib/audit/entities/index.js"
|
|
123
|
+
},
|
|
124
|
+
"./contracts": {
|
|
125
|
+
"types": "./src/contracts/index.ts",
|
|
126
|
+
"default": "./lib/contracts/index.js"
|
|
127
|
+
},
|
|
128
|
+
"./chat": {
|
|
129
|
+
"types": "./src/chat/index.ts",
|
|
130
|
+
"default": "./lib/chat/index.js"
|
|
131
|
+
},
|
|
132
|
+
"./providers": {
|
|
133
|
+
"types": "./src/providers/McpServerHandlerDef.ts",
|
|
134
|
+
"default": "./lib/providers/McpServerHandlerDef.js"
|
|
135
|
+
},
|
|
136
|
+
"./cli": {
|
|
137
|
+
"types": "./src/cli.ts",
|
|
138
|
+
"default": "./lib/cli.js"
|
|
139
|
+
},
|
|
140
|
+
"./audit/server": {
|
|
141
|
+
"types": "./src/audit/server/index.ts",
|
|
142
|
+
"default": "./lib/audit/server/index.js"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { Context } from 'hono';
|
|
6
6
|
import consola from 'consola';
|
|
7
|
-
import type { ChatProtocolType, RequestStatus as RequestStatusType, ChatAuditStats } from '
|
|
7
|
+
import type { ChatProtocolType, RequestStatus as RequestStatusType, ChatAuditStats } from './types';
|
|
8
8
|
|
|
9
9
|
const log = consola.withTag('chat-audit');
|
|
10
10
|
|
|
@@ -77,7 +77,7 @@ export interface ChatAuditStore {
|
|
|
77
77
|
/**
|
|
78
78
|
* Get aggregate statistics
|
|
79
79
|
*/
|
|
80
|
-
getStats(options: { from?: Date; to?: Date }): Promise<
|
|
80
|
+
getStats(options: { from?: Date; to?: Date }): Promise<ChatAuditStats>;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export interface ChatAuditQueryOptions {
|
|
@@ -93,7 +93,7 @@ export interface ChatAuditQueryOptions {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// Re-export ChatAuditStats from entities
|
|
96
|
-
export type { ChatAuditStats } from '
|
|
96
|
+
export type { ChatAuditStats } from './types';
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* In-memory audit store implementation
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from '../types';
|
|
2
|
+
|
|
3
|
+
export { ChatRequestEntity, ChatProtocolType, RequestStatus } from './ChatRequestEntity';
|
|
4
|
+
export { McpRequestEntity, McpServerType, McpRequestType } from './McpRequestEntity';
|
|
5
|
+
export { RequestLogEntity } from './RequestLogEntity';
|
|
6
|
+
export { ResponseEntity } from './ResponseEntity';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MikroORM, type Options } from '@mikro-orm/core';
|
|
2
2
|
import { SqliteDriver } from '@mikro-orm/sql';
|
|
3
3
|
import { createSqliteDialect } from '@wener/server/mikro-orm';
|
|
4
|
+
import type { DbConfig } from '../../server/schema';
|
|
4
5
|
import { ChatRequestEntity } from '../entities/ChatRequestEntity';
|
|
5
6
|
import { McpRequestEntity } from '../entities/McpRequestEntity';
|
|
6
7
|
import { RequestLogEntity } from '../entities/RequestLogEntity';
|
|
7
8
|
import { ResponseEntity } from '../entities/ResponseEntity';
|
|
8
|
-
import type { DbConfig } from './schema';
|
|
9
9
|
|
|
10
10
|
export { RequestLogEntity };
|
|
11
11
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { implement } from '@orpc/server';
|
|
2
2
|
import { LRUCache } from 'lru-cache';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import type
|
|
3
|
+
import { McpsEventType } from '../../server/events';
|
|
4
|
+
import type { AuditConfig, DbConfig } from '../../server/schema';
|
|
5
|
+
import type { McpsServerContext } from '../../server/server';
|
|
6
|
+
import { AuditContract, type AuditEvent } from '../AuditContract';
|
|
7
7
|
|
|
8
8
|
function headersToRecord(headers: Headers): Record<string, string> {
|
|
9
9
|
const record: Record<string, string> = {};
|
|
@@ -27,7 +27,7 @@ async function persistToDb(event: AuditEvent, id: string): Promise<void> {
|
|
|
27
27
|
if (!dbConfigured) return;
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
|
-
const { ensureDbInitialized, RequestLogEntity } = await import('./
|
|
30
|
+
const { ensureDbInitialized, RequestLogEntity } = await import('./db.js');
|
|
31
31
|
const orm = await ensureDbInitialized(storedDbConfig);
|
|
32
32
|
const em = orm.em.fork();
|
|
33
33
|
|
package/src/chat/handler.ts
CHANGED
|
@@ -6,7 +6,7 @@ import consola from 'consola';
|
|
|
6
6
|
import { Hono } from 'hono';
|
|
7
7
|
import { streamSSE } from 'hono/streaming';
|
|
8
8
|
import type { ChatConfig, ModelConfig } from '../server/schema';
|
|
9
|
-
import { ChatProtocol, createAuditContext, extractClientIp } from '
|
|
9
|
+
import { ChatProtocol, createAuditContext, extractClientIp } from '../audit/chat';
|
|
10
10
|
import {
|
|
11
11
|
openaiToAnthropicRequest,
|
|
12
12
|
anthropicToOpenaiResponse,
|
|
@@ -747,8 +747,8 @@ export function createChatHandler(options: ChatHandlerOptions = {}) {
|
|
|
747
747
|
let previousContext: { input: unknown; output: unknown[] } | null = null;
|
|
748
748
|
if (request.previous_response_id) {
|
|
749
749
|
try {
|
|
750
|
-
const { isDbInitialized, getEntityManager } = await import('../server/
|
|
751
|
-
const { ResponseEntity } = await import('../entities');
|
|
750
|
+
const { isDbInitialized, getEntityManager } = await import('../audit/server/db');
|
|
751
|
+
const { ResponseEntity } = await import('../audit/entities');
|
|
752
752
|
if (isDbInitialized()) {
|
|
753
753
|
const em = getEntityManager().fork();
|
|
754
754
|
const prevResponse = await em.findOne(ResponseEntity, { responseId: request.previous_response_id });
|
|
@@ -840,8 +840,8 @@ export function createChatHandler(options: ChatHandlerOptions = {}) {
|
|
|
840
840
|
|
|
841
841
|
// Store response for future previous_response_id lookups
|
|
842
842
|
try {
|
|
843
|
-
const { isDbInitialized, getEntityManager } = await import('../server/
|
|
844
|
-
const { ResponseEntity } = await import('../entities');
|
|
843
|
+
const { isDbInitialized, getEntityManager } = await import('../audit/server/db');
|
|
844
|
+
const { ResponseEntity } = await import('../audit/entities');
|
|
845
845
|
if (isDbInitialized()) {
|
|
846
846
|
const em = getEntityManager().fork();
|
|
847
847
|
const responseEntity = new ResponseEntity();
|
package/src/chat/index.ts
CHANGED
package/src/contracts/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AuditContract, AuditEventSchema, AuditQuerySchema, AuditStatsSchema, type AuditEvent } from '
|
|
1
|
+
export { AuditContract, AuditEventSchema, AuditQuerySchema, AuditStatsSchema, type AuditEvent } from '../audit/AuditContract';
|
|
2
2
|
export {
|
|
3
3
|
McpsContract,
|
|
4
4
|
ServiceOverviewSchema,
|
package/src/dev.server.ts
CHANGED
package/src/entities/index.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* These are pure TypeScript types without decorators
|
|
4
|
-
* Can be used with any ORM or database layer
|
|
5
|
-
*/
|
|
6
|
-
export * from './types';
|
|
7
|
-
|
|
8
|
-
// MikroORM Entities
|
|
9
|
-
export { ChatRequestEntity, ChatProtocolType, RequestStatus } from './ChatRequestEntity';
|
|
10
|
-
export { McpRequestEntity, McpServerType, McpRequestType } from './McpRequestEntity';
|
|
11
|
-
export { RequestLogEntity } from './RequestLogEntity';
|
|
12
|
-
export { ResponseEntity } from './ResponseEntity';
|
|
1
|
+
// Re-export from new location for backward compatibility
|
|
2
|
+
export * from '../audit/entities/index';
|
package/src/mcps-cli.ts
CHANGED
|
@@ -6,7 +6,7 @@ const log = consola.withTag('mcps');
|
|
|
6
6
|
|
|
7
7
|
const program = createProgram({
|
|
8
8
|
setup: async (ctx) => {
|
|
9
|
-
const { setupAudit } = await import('./server/
|
|
9
|
+
const { setupAudit } = await import('./audit/server/plugin.js');
|
|
10
10
|
setupAudit(ctx);
|
|
11
11
|
},
|
|
12
12
|
});
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 陈杨文
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/lib/chat/audit.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/chat/audit.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 '../entities/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<import('../entities/types').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 '../entities/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","error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,IAAI,CAAC1F,MAAM,CAACO,MAAM,GAAGhB,cAAcE,OAAO;QAC1C,IAAI,CAACO,MAAM,CAAC0F,UAAU,GAAGA;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/contracts/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,MAAM,CAAC;IACxCC,IAAIH,EAAEI,MAAM;IACZC,WAAWL,EAAEI,MAAM;IACnBE,QAAQN,EAAEI,MAAM;IAChBG,MAAMP,EAAEI,MAAM;IACdI,YAAYR,EAAEI,MAAM,GAAGK,OAAO;IAC9BC,YAAYV,EAAEI,MAAM,GAAGK,OAAO;IAC9BE,QAAQX,EAAEY,MAAM,GAAGH,OAAO;IAC1BI,YAAYb,EAAEY,MAAM,GAAGH,OAAO;IAC9BK,gBAAgBd,EAAEe,MAAM,CAACf,EAAEI,MAAM,IAAIJ,EAAEI,MAAM,IAAIK,OAAO;IACxDO,iBAAiBhB,EAAEe,MAAM,CAACf,EAAEI,MAAM,IAAIJ,EAAEI,MAAM,IAAIK,OAAO;IACzDQ,aAAajB,EAAEkB,OAAO,GAAGT,OAAO;IAChCU,cAAcnB,EAAEkB,OAAO,GAAGT,OAAO;IACjCW,OAAOpB,EAAEI,MAAM,GAAGK,OAAO;IACz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oB;IAEjE,mBAAmB;IACnBC,KAAKlD,GACH4C,KAAK,CAAC3C,EAAEE,MAAM,CAAC;QAAEC,IAAIH,EAAEI,MAAM;IAAG,IAChCwC,MAAM,CAAC3C,iBAAiBiD,QAAQ,IAChCH,KAAK,CAAC;QAAEzC,QAAQ;QAAOC,MAAM;QAASyC,SAAS;IAAwB;IAEzE,YAAY;IACZG,OAAOpD,GACL4C,KAAK,CACL3C,EAAEE,MAAM,CAAC;QACR0B,MAAM5B,EAAEI,MAAM,GAAGK,OAAO;QACxBoB,IAAI7B,EAAEI,MAAM,GAAGK,OAAO;IACvB,IAEAmC,MAAM,CAACd,kBACPiB,KAAK,CAAC;QAAEzC,QAAQ;QAAOC,MAAM;QAAUyC,SAAS;IAAuB;IAEzE,mBAAmB;IACnBI,OAAOrD,GACL4C,KAAK,CACL3C,EAAEE,MAAM,CAAC;QACRmD,QAAQrD,EAAEI,MAAM,GAAGkD,QAAQ,CAAC;IAC7B,IAEAV,MAAM,CAAC5C,EAAEE,MAAM,CAAC;QAAEqD,SAASvD,EAAEY,MAAM;IAAG,IACtCmC,KAAK,CAAC;QAAEzC,QAAQ;QAAUC,MAAM;QAAKyC,SAAS;IAAqB;AACtE,GAAG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/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,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BC,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/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,kBAEA,uCAAuC,GACvC,AACAC,iBAEA,+BAA+B,GAC/B,AACAC,gBAEA,sCAAsC,GACtC,AACAC,mBAEA,kCAAkC,GAClC,AACAC,kBAEA,2BAA2B,GAC3B,AACAC,kBAEA,qBAAqB,GACrB,AACAC,kB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;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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/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,GACtB,AACAC,iBAEA,sBAAsB,GACtB,AACAC,iBAEA,gBAAgB,GAChB,AACAC,cAEA,iBAAiB,GACjB,AACAC,YAEA,uCAAuC,GACvC,AACAC,mBAEA,8CAA8C,GAC9C,AACAC,kBAEA,gBAAgB,GAChB,A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AIAC,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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/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,qBAAqB,GACrB,AACAC,aAMA,+BAA+B,GAC/B,AACAC,oBAEA,mDAAmD,GACnD,AACAC,0BAEA,wBAAwB,GACxB,AACAC,aAEA,gBAAgB,GAChB,AACAC,kBAEA,aAAa,GACb,AACAC,gBAEA,sBAAsB,GACtB,AAC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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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/entities/types.ts"],"sourcesContent":["/**\n * Entity Type Definitions\n * These types can be used with MikroORM or other ORMs\n * Avoids decorator issues in test environments\n */\n\n/**\n * Base entity fields\n */\nexport interface BaseEntity {\n\tid: number;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n}\n\n/**\n * Request status\n */\nexport type RequestStatus = 'pending' | 'success' | 'error' | 'timeout';\n\n/**\n * Chat protocol type\n */\nexport type ChatProtocolType = 'openai' | 'anthropic' | 'gemini';\n\n/**\n * MCP server type\n */\nexport type McpServerType = 'tencent-cls' | 'sql' | 'prometheus' | 'relay' | 'custom';\n\n/**\n * MCP request type\n */\nexport type McpRequestType =\n\t| 'initialize'\n\t| 'tools/list'\n\t| 'tools/call'\n\t| 'resources/list'\n\t| 'resources/read'\n\t| 'prompts/list'\n\t| 'prompts/get'\n\t| 'completion/complete'\n\t| 'logging/setLevel'\n\t| 'ping'\n\t| 'other';\n\n/**\n * Chat request entity for auditing and metering\n */\nexport interface ChatRequest extends BaseEntity {\n\t/** Unique request ID for tracing */\n\trequestId: string;\n\t/** Request timestamp */\n\trequestedAt: Date;\n\t/** Response timestamp */\n\tcompletedAt?: Date;\n\t/** Request status */\n\tstatus: RequestStatus;\n\t/** HTTP method */\n\tmethod: string;\n\t/** Request path/endpoint */\n\tendpoint: string;\n\t/** Input protocol (client-facing) */\n\tinputProtocol: ChatProtocolType;\n\t/** Output protocol (upstream provider) */\n\toutputProtocol: ChatProtocolType;\n\t/** Model name requested */\n\tmodel: string;\n\t/** Resolved model name */\n\tresolvedModel?: string;\n\t/** Provider name */\n\tprovider?: string;\n\t/** Upstream base URL */\n\tupstreamUrl?: string;\n\t/** Whether request was streaming */\n\tstreaming: boolean;\n\t/** Input token count */\n\tinputTokens?: number;\n\t/** Output token count */\n\toutputTokens?: number;\n\t/** Total token count */\n\ttotalTokens?: number;\n\t/** Request duration in ms */\n\tdurationMs?: number;\n\t/** Time to first token in ms */\n\tttftMs?: number;\n\t/** HTTP status code */\n\thttpStatus?: number;\n\t/** Error message */\n\terrorMessage?: string;\n\t/** Error code */\n\terrorCode?: string;\n\t/** Client IP */\n\tclientIp?: string;\n\t/** User agent */\n\tuserAgent?: string;\n\t/** User ID */\n\tuserId?: string;\n\t/** Organization ID */\n\torgId?: string;\n\t/** API key ID (not the actual key) */\n\tapiKeyId?: string;\n\t/** Request metadata */\n\trequestMeta?: Record<string, unknown>;\n\t/** Response metadata */\n\tresponseMeta?: Record<string, unknown>;\n\t/** Cost in credits */\n\tcost?: string;\n\t/** Currency */\n\tcurrency?: string;\n}\n\n/**\n * MCP request entity for auditing\n */\nexport interface McpRequest extends BaseEntity {\n\t/** Unique request ID */\n\trequestId: string;\n\t/** MCP session ID */\n\tsessionId?: string;\n\t/** Request timestamp */\n\trequestedAt: Date;\n\t/** Response timestamp */\n\tcompletedAt?: Date;\n\t/** Request status */\n\tstatus: RequestStatus;\n\t/** HTTP method */\n\tmethod: string;\n\t/** Request path */\n\tpath: string;\n\t/** MCP server name */\n\tserverName: string;\n\t/** MCP server type */\n\tserverType: McpServerType;\n\t/** MCP request type */\n\tmcpMethod: McpRequestType;\n\t/** Tool name (for tools/call) */\n\ttoolName?: string;\n\t/** Resource URI (for resources/read) */\n\tresourceUri?: string;\n\t/** Prompt name (for prompts/get) */\n\tpromptName?: string;\n\t/** Request duration in ms */\n\tdurationMs?: number;\n\t/** HTTP status code */\n\thttpStatus?: number;\n\t/** Error message */\n\terrorMessage?: string;\n\t/** Error code */\n\terrorCode?: string;\n\t/** Client IP */\n\tclientIp?: string;\n\t/** User agent */\n\tuserAgent?: string;\n\t/** User ID */\n\tuserId?: string;\n\t/** Request headers */\n\trequestHeaders?: Record<string, string>;\n\t/** Request body */\n\trequestBody?: Record<string, unknown>;\n\t/** Response metadata */\n\tresponseMeta?: Record<string, unknown>;\n}\n\n/**\n * Chat audit statistics\n */\nexport interface ChatAuditStats {\n\ttotalRequests: number;\n\tsuccessfulRequests: number;\n\tfailedRequests: number;\n\ttotalInputTokens: number;\n\ttotalOutputTokens: number;\n\tavgDurationMs: number;\n\tbyModel: { model: string; count: number; tokens: number }[];\n\tbyProvider: { provider: string; count: number; tokens: number }[];\n}\n\n/**\n * MCP audit statistics\n */\nexport interface McpAuditStats {\n\ttotalRequests: number;\n\ttotalErrors: number;\n\tavgDurationMs: number;\n\tbyServer: { name: string; count: number }[];\n\tbyMethod: { method: string; count: number }[];\n}\n"],"names":[],"mappings":"AAAA;;;;CAIC,GAED;;CAEC,GA0KD;;CAEC,GACD,WAMC"}
|