This commit is contained in:
1 parent
d5022d2d59
commit
cd2394dd22
19 files changed
+1757
-32
No files matched your search
+19
-3
@@ -1,6 +1,10 @@
|
||||
const { randomUUID } = require('node:crypto');
|
||||
const { McpAccessError, resolveGrantedFile } = require('./mcp-access');
|
||||
const { createMcpFiles } = require('./mcp-files');
|
||||
const { createMcpTransfers } = require('./mcp-transfers');
|
||||
const { createMcpDiagnostics } = require('./mcp-diagnostics');
|
||||
const { createMcpSanitizer } = require('./mcp-security');
|
||||
const { redactLogText, collectSecretValues } = require('./support-bundle');
|
||||
|
||||
function page(items, args) {
|
||||
const offset = args.offset || 0;
|
||||
@@ -8,7 +12,10 @@ function page(items, args) {
|
||||
return { total: items.length, offset, items: items.slice(offset, offset + limit), nextOffset: offset + limit < items.length ? offset + limit : null };
|
||||
}
|
||||
|
||||
function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...args) => invoke(channel, ...args), renderer, collectors, getGrants, trashFile, canWrite }) {
|
||||
function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel, ...args) => invoke(channel, ...args), renderer, collectors, getGrants, trashFile, canWrite,
|
||||
getCapabilities, getProtectedPaths, getInstallationId, getDiagnosticSources, getRuntimeDiagnostics = () => null }) {
|
||||
const transfers = createMcpTransfers({ getGrants, getCapabilities, getProtectedPaths, getInstallationId });
|
||||
const sanitize = createMcpSanitizer(loadConfig);
|
||||
const guard = context => {
|
||||
if (context.signal?.aborted || Date.now() >= context.deadline) throw new McpAccessError('REQUEST_EXPIRED');
|
||||
};
|
||||
@@ -45,11 +52,14 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
await refresh(context);
|
||||
return { saved: true };
|
||||
};
|
||||
return {
|
||||
const handlers = {
|
||||
...createMcpFiles({ getGrants, trashFile }),
|
||||
...transfers.handlers,
|
||||
...createMcpDiagnostics({ getSources: getDiagnosticSources, redact: text => sanitize(redactLogText(text, collectSecretValues(loadConfig()))) }),
|
||||
mhu_app_info: () => invoke('get-app-info'),
|
||||
mhu_app_state: async (args, context) => ({ ...(await renderer('state', {}, context)), automation: await invoke('automation:get-status') }),
|
||||
mhu_queue_list: (args, context) => renderer('queue-list', args, context),
|
||||
mhu_queue_job_log: async args => page(await invoke('get-job-log', args.jobId), args),
|
||||
mhu_queue_add: async (args, context) => {
|
||||
if (!args.paths.length || !args.hosters.length) throw new McpAccessError('INVALID_ARGUMENTS');
|
||||
const files = [];
|
||||
@@ -65,6 +75,10 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
mhu_queue_remove: (args, context) => renderer('queue-remove', args, context),
|
||||
mhu_queue_clear: (args, context) => renderer('queue-clear', args, context),
|
||||
mhu_accounts_list: args => page(accounts().filter(account => !args.hoster || args.hoster === account.hoster), args),
|
||||
mhu_accounts_runtime: async args => {
|
||||
const state = await invoke('get-session-failed-account-states');
|
||||
return { revision: state.revision, now: state.now, ...page(state.accounts.filter(account => !args.hoster || account.hoster === args.hoster), args) };
|
||||
},
|
||||
mhu_accounts_check: (args, context) => { if (!args.accountIds.length) throw new McpAccessError('INVALID_ARGUMENTS'); return check(args.accountIds, context); },
|
||||
mhu_accounts_add: async (args, context) => {
|
||||
canWrite(); guard(context);
|
||||
@@ -128,7 +142,7 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
mhu_history_prune: args => invoke('prune-history', { retention: args.retention, dryRun: false }),
|
||||
mhu_history_summary: args => collectors.getHistory({ limit: args.limit || 20 }),
|
||||
mhu_history_clear: () => invoke('clear-history'),
|
||||
mhu_diagnostics_summary: () => ({ system: collectors.getSystemInfo(), health: collectors.getHealth(), rotation: collectors.getRotationState(), server: collectors.serverHealth({ errorLimit: 20 }) }),
|
||||
mhu_diagnostics_summary: () => ({ system: collectors.getSystemInfo(), health: collectors.getHealth(), rotation: collectors.getRotationState(), server: collectors.serverHealth({ errorLimit: 20 }), runtime: getRuntimeDiagnostics() }),
|
||||
mhu_app_events: args => collectors.getAppEvents(args),
|
||||
mhu_errors: args => collectors.listErrors(args),
|
||||
mhu_logs_list: () => collectors.listLogs(),
|
||||
@@ -146,6 +160,8 @@ function createMcpApp({ loadConfig, invoke, invokeGuarded = (_context, channel,
|
||||
mhu_app_quit: () => invoke('app:quit'),
|
||||
mhu_secrets_read: args => { const { password, apiKey } = find(args.accountId); return { accountId: args.accountId, password: password || '', apiKey: apiKey || '' }; }
|
||||
};
|
||||
Object.defineProperty(handlers, 'dispose', { value: () => transfers.dispose() });
|
||||
return handlers;
|
||||
}
|
||||
|
||||
module.exports = { createMcpApp, page };
|
||||
Reference in new issue
Block a user