@rezti/dsh-rez-suite 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +13 -0
- package/README.md +9 -0
- package/README.zh.md +11 -0
- package/cordis.patch.yml +68 -0
- package/lib/client.d.ts +7479 -0
- package/lib/client.js +1190 -0
- package/lib/index.d.ts +1726 -0
- package/lib/index.js +7659 -0
- package/lib/style.css +309 -0
- package/package.json +103 -0
- package/servers/fs-mcp-server.mjs +71 -0
- package/servers/sqlite-mcp-server.mjs +50 -0
- package/src/client/api.ts +75 -0
- package/src/client/css-modules.d.ts +4 -0
- package/src/client/index.ts +45 -0
- package/src/client/locales.ts +176 -0
- package/src/client/mount.tsx +97 -0
- package/src/client/panel/AuditTab.tsx +87 -0
- package/src/client/panel/ConfigTab.tsx +223 -0
- package/src/client/panel/RezPanel.tsx +50 -0
- package/src/client/panel/StatusTab.tsx +66 -0
- package/src/client/panel/controller.ts +42 -0
- package/src/client/panel/helpers.ts +21 -0
- package/src/client/panel/panel.module.css +316 -0
- package/src/client/sidebar-entry.ts +80 -0
- package/src/index.ts +166 -0
- package/src/mcp-host.ts +418 -0
- package/src/presets.ts +125 -0
- package/src/protocol.ts +133 -0
- package/src/routes.ts +191 -0
- package/src/store.ts +152 -0
- package/src/token-manager.ts +252 -0
- package/src/tools.ts +167 -0
package/src/tools.ts
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent-facing suite tools: status, configuration view, connectivity test,
|
|
3
|
+
* and audit ledger. MCP tools themselves are registered by mcp-host.ts.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { defineTool as defineToolOriginal } from '@deepseek-ai/dsh-tools'
|
|
7
|
+
|
|
8
|
+
/** Loosen the typed helper for the suite's small fixed tools. */
|
|
9
|
+
const defineTool = defineToolOriginal as unknown as (options: any) => any
|
|
10
|
+
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
|
|
11
|
+
import type { RezConfig, RezTestResult } from './protocol.ts'
|
|
12
|
+
import type { McpHost } from './mcp-host.ts'
|
|
13
|
+
import type { TokenManager } from './token-manager.ts'
|
|
14
|
+
import { publicConfig } from './store.ts'
|
|
15
|
+
|
|
16
|
+
function text(value: string): ContentBlock[] {
|
|
17
|
+
return [{ type: 'text', text: value }]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function renderTest(results: RezTestResult[]): string {
|
|
21
|
+
if (results.length === 0) return 'no servers enabled'
|
|
22
|
+
return results.map(result => {
|
|
23
|
+
const head = result.server + ': ' + (result.ok ? 'ok' : 'failed')
|
|
24
|
+
const detail = result.ok
|
|
25
|
+
? 'tools=' + (result.toolCount ?? 0) + ' latency=' + (result.latencyMs ?? 0) + 'ms'
|
|
26
|
+
: 'error=' + (result.error ?? 'unknown')
|
|
27
|
+
return head + ' (' + detail + ')'
|
|
28
|
+
}).join('\n')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function rezStatusTool(host: McpHost, config: () => RezConfig) {
|
|
32
|
+
return defineTool({
|
|
33
|
+
name: 'rez_status',
|
|
34
|
+
description: 'List the dsh-rez-suite MCP server statuses and how many tools each server registered for the current role. Triggers: rez, MCP, 连接状态.',
|
|
35
|
+
parameters: {},
|
|
36
|
+
output: {
|
|
37
|
+
schema: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
role: { type: 'string', required: true },
|
|
41
|
+
servers: {
|
|
42
|
+
type: 'array',
|
|
43
|
+
required: true,
|
|
44
|
+
items: {
|
|
45
|
+
type: 'object',
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
properties: {
|
|
48
|
+
server: { type: 'string', required: true },
|
|
49
|
+
enabled: { type: 'boolean', required: true },
|
|
50
|
+
state: { type: 'string', required: true },
|
|
51
|
+
toolCount: { type: 'integer', required: true },
|
|
52
|
+
registeredTools: { type: 'integer', required: true },
|
|
53
|
+
lastError: { type: 'string' },
|
|
54
|
+
startedAt: { type: 'integer' },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
additionalProperties: false,
|
|
60
|
+
},
|
|
61
|
+
render: (_args: any, value: { role?: string; servers?: Array<Record<string, unknown>> }) => {
|
|
62
|
+
const rows = (value.servers ?? []).map(server => [
|
|
63
|
+
server.server,
|
|
64
|
+
server.state,
|
|
65
|
+
server.toolCount,
|
|
66
|
+
server.registeredTools,
|
|
67
|
+
server.lastError ?? '',
|
|
68
|
+
].join(' | '))
|
|
69
|
+
return text('role: ' + (value.role ?? '') + '\n' + ['server | state | discovered | registered | error', '--- | --- | --- | --- | ---', ...rows].join('\n'))
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
async execute() {
|
|
73
|
+
const servers = host.status().map(server => {
|
|
74
|
+
const clean: Record<string, unknown> = { ...server }
|
|
75
|
+
if (clean.lastError === undefined) delete clean.lastError
|
|
76
|
+
if (clean.startedAt === undefined) delete clean.startedAt
|
|
77
|
+
return clean
|
|
78
|
+
})
|
|
79
|
+
return { role: config().role, servers }
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function rezConfigTool(config: () => RezConfig) {
|
|
85
|
+
return defineTool({
|
|
86
|
+
name: 'rez_config',
|
|
87
|
+
description: 'Show the current dsh-rez-suite configuration with secrets masked. Use the web GUI Rez panel to change credentials.',
|
|
88
|
+
parameters: {},
|
|
89
|
+
output: {
|
|
90
|
+
schema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {
|
|
93
|
+
config: { type: 'json', required: true },
|
|
94
|
+
},
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
},
|
|
97
|
+
render: (_args: any, value: { config?: unknown }) => text(JSON.stringify(value.config ?? {}, null, 2)),
|
|
98
|
+
},
|
|
99
|
+
async execute() {
|
|
100
|
+
return { config: publicConfig(config()) }
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function rezTestTool(host: McpHost, config: () => RezConfig) {
|
|
106
|
+
return defineTool({
|
|
107
|
+
name: 'rez_test_connections',
|
|
108
|
+
description: 'Test connectivity to every enabled dsh-rez-suite MCP server with a throwaway connection. Triggers: 测试 MCP 连接.',
|
|
109
|
+
parameters: {},
|
|
110
|
+
output: {
|
|
111
|
+
schema: {
|
|
112
|
+
type: 'object',
|
|
113
|
+
properties: {
|
|
114
|
+
results: { type: 'array', required: true, items: { type: 'json' } },
|
|
115
|
+
},
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
},
|
|
118
|
+
render: (_args: any, value: { results?: RezTestResult[] }) => text(renderTest(value.results ?? [])),
|
|
119
|
+
},
|
|
120
|
+
async execute() {
|
|
121
|
+
return { results: await host.test(config()) }
|
|
122
|
+
},
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function rezAuditTool(tokens: TokenManager, config: () => RezConfig) {
|
|
127
|
+
return defineTool({
|
|
128
|
+
name: 'rez_audit',
|
|
129
|
+
description: 'Read the dsh-rez-suite token/audit ledger: total calls, tokens, cost, per-server breakdown, and recent records.',
|
|
130
|
+
parameters: {},
|
|
131
|
+
output: {
|
|
132
|
+
schema: {
|
|
133
|
+
type: 'object',
|
|
134
|
+
properties: {
|
|
135
|
+
audit: { type: 'json', required: true },
|
|
136
|
+
},
|
|
137
|
+
additionalProperties: false,
|
|
138
|
+
},
|
|
139
|
+
render: (_args: any, value: { audit?: unknown }) => text(JSON.stringify(value.audit ?? {}, null, 2)),
|
|
140
|
+
},
|
|
141
|
+
async execute() {
|
|
142
|
+
return { audit: tokens.summary(config().billing.monthlyBudget) }
|
|
143
|
+
},
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function rezAuditResetTool(tokens: TokenManager) {
|
|
148
|
+
return defineTool({
|
|
149
|
+
name: 'rez_audit_reset',
|
|
150
|
+
description: 'Clear the dsh-rez-suite audit ledger. Destructive; use only when the user asks to reset usage records.',
|
|
151
|
+
parameters: {},
|
|
152
|
+
output: {
|
|
153
|
+
schema: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: {
|
|
156
|
+
ok: { type: 'boolean', required: true },
|
|
157
|
+
},
|
|
158
|
+
additionalProperties: false,
|
|
159
|
+
},
|
|
160
|
+
render: (_args: any, value: { ok?: boolean }) => text(value.ok === true ? 'audit ledger reset' : 'audit reset failed'),
|
|
161
|
+
},
|
|
162
|
+
async execute() {
|
|
163
|
+
tokens.reset()
|
|
164
|
+
return { ok: true }
|
|
165
|
+
},
|
|
166
|
+
})
|
|
167
|
+
}
|