返回源码地图

packages/computer-use/computer-use/src/index.ts

main snapshot · da00f7f5358f · 正文引用章节 12;完整原文可核对,不声称全文件人工逐行审计

完整原文供逐行核对;页面收录不代表每行都经过人工语义审核。MIT 许可见 许可证。

1/**
2 * Exclusive named registration for the computer-use capability.
3 * @module @deepseek-ai/dsh-computer-use
4 */
5
6import { Context, Service } from '@deepseek-ai/cordis'
7import type { ComputerUseProviderName } from './brand.ts'
8
9declare module '@deepseek-ai/cordis' {
10 interface Context {
11 computerUse: ComputerUseRegistry
12 }
13}
14
15/** Owns one optional provider registration in the shared computer-use service. */
16export class ComputerUseRegistry extends Service {
17 private registration: ComputerUseProviderName | undefined
18
19 constructor(ctx: Context) {
20 super(ctx, 'computerUse')
21 }
22
23 /** Name of the registered provider, including while its resources are closing. */
24 get providerName(): ComputerUseProviderName | undefined {
25 return this.registration
26 }
27
28 /**
29 * Reserve the sole provider slot until the contribution is disposed.
30 * A second registration fails even when it repeats the current name. Providers
31 * must stop their tools and await owned work before releasing this registration.
32 * @param name - provider-owned name used in registration diagnostics.
33 * @returns the effect disposer for this exact registration.
34 */
35 register(name: ComputerUseProviderName): () => Promise<void> {
36 if (this.registration !== undefined) {
37 throw new Error(`computer use provider "${this.registration}" is already registered`)
38 }
39 return this.ctx.effect(() => {
40 this.registration = name
41 return () => {
42 this.registration = undefined
43 }
44 }, 'computerUse.register()')
45 }
46}
47
48export default ComputerUseRegistry