返回 CodeWhale
index.mjs
1 export const name = 'remote-pair'
2 export const inject = ['tools', 'remote']
3
4 const outcome = async (call) => {
5 try {
6 return { ok: await call() }
7 } catch (error) {
8 return { failed: { name: error.name, code: error.code ?? null, message: error.message } }
9 }
10 }
11
12 export function apply(ctx) {
13 ctx.tools.register({
14 name: 'remote_call',
15 description: 'Call one method of the remote service and report the outcome.',
16 parameters: {
17 type: 'object',
18 properties: { method: { type: 'string' }, label: { type: 'string' }, grant: { type: 'string' } },
19 required: ['method'],
20 additionalProperties: false,
21 },
22 execute: ({ method, label, grant }) => outcome(() => {
23 if (method === 'status') return ctx.remote.status()
24 if (method === 'pair') return ctx.remote.pair(label === undefined ? undefined : { label })
25 if (method === 'clients') return ctx.remote.clients()
26 if (method === 'revoke') return ctx.remote.revoke(grant)
27 throw new Error(`the fixture has no remote method ${method}`)
28 }),
29 })
30 }
31
31 lines Plain Text