diff --git a/lib/index.js b/lib/index.js index 1455779..364f4ae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -96,6 +96,7 @@ function apply(ctx, config) { params = params || {}; if (method === 'harness.status') return computeStatus(); if (method === 'harness.prompt') return harnessPrompt(params); + if (method === 'harness.cancel') return harnessCancel(); const dot = method.indexOf('.'); if (dot <= 0) throw new Error('unknown method ' + method); const domain = method.slice(0, dot); @@ -129,6 +130,13 @@ function apply(ctx, config) { }); } + async function harnessCancel() { + const status = await computeStatus(); + const sessionId = status.activeSessionId; + if (!sessionId) throw new Error('no active session to cancel'); + return api.sessions.cancel({ sessionId }); + } + function handleRequest(msg, respond) { invoke(msg.method || '', msg.params || {}).then((result) => { respond({ type: 'response', requestId: msg.requestId, ok: true, result });