返回 CodeWhale
remote.ts
根目录 / crates / engine / extension-host / src / dsh / remote.ts
1 import { Service } from '@deepseek-ai/cordis'
2 import { ErrorCode } from '../protocol.ts'
3 import { RpcError } from '../rpc.ts'
4 import type { DshAdapter } from './adapters.ts'
5
6 function label(value: unknown): string | undefined {
7 if (value === undefined) return undefined
8 if (typeof value !== 'string') throw new RpcError(ErrorCode.InvalidParams, 'remote.pair label must be a string')
9 return value
10 }
11
12 function grant(value: unknown): string {
13 if (typeof value !== 'string' || value.length === 0 || value.length > 128) throw new RpcError(ErrorCode.InvalidParams, 'remote.revoke needs the grant id remote.pair returned')
14 return value
15 }
16
17 export const remoteAdapter: DshAdapter = {
18 service: 'remote',
19 define(host) {
20 class RemoteService extends Service {
21 constructor(ctx: any) { super(ctx, 'remote') }
22 status() { return host.broker(this.ctx, 'remote', 'status', {}) }
23 pair(options?: { label?: unknown }) {
24 const value = label(options?.label)
25 return host.broker(this.ctx, 'remote', 'pair', value === undefined ? {} : { label: value })
26 }
27 clients() { return host.broker(this.ctx, 'remote', 'clients', {}) }
28 revoke(id: unknown) { return host.broker(this.ctx, 'remote', 'revoke', { grant: grant(id) }) }
29 }
30 Object.freeze(RemoteService.prototype)
31 return RemoteService
32 },
33 }
34
34 lines TYPESCRIPT