@anionex/dsh-computer-use 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +307 -0
- package/README.zh.md +307 -0
- package/assets/computer-use-fixture.png +0 -0
- package/assets/cursor.png +0 -0
- package/cordis.patch.yml +13 -0
- package/docs/interaction-policy.i18n.yaml +4 -0
- package/docs/interaction-policy.md +140 -0
- package/docs/interaction-policy.zh.md +140 -0
- package/lib/approval-policy.js +12 -0
- package/lib/approval-policy.js.map +1 -0
- package/lib/artifacts.js +79 -0
- package/lib/artifacts.js.map +1 -0
- package/lib/backend.js +3 -0
- package/lib/backend.js.map +1 -0
- package/lib/client.js +349 -0
- package/lib/client.js.map +1 -0
- package/lib/config.js +120 -0
- package/lib/config.js.map +1 -0
- package/lib/confirmations.js +99 -0
- package/lib/confirmations.js.map +1 -0
- package/lib/diff.js +58 -0
- package/lib/diff.js.map +1 -0
- package/lib/errors.js +22 -0
- package/lib/errors.js.map +1 -0
- package/lib/exposure.js +231 -0
- package/lib/exposure.js.map +1 -0
- package/lib/index.js +56 -0
- package/lib/index.js.map +1 -0
- package/lib/leases.js +259 -0
- package/lib/leases.js.map +1 -0
- package/lib/providers/macos.js +148 -0
- package/lib/providers/macos.js.map +1 -0
- package/lib/providers/native-helper.js +356 -0
- package/lib/providers/native-helper.js.map +1 -0
- package/lib/service.js +480 -0
- package/lib/service.js.map +1 -0
- package/lib/skill.js +119 -0
- package/lib/skill.js.map +1 -0
- package/lib/target-resolver.js +180 -0
- package/lib/target-resolver.js.map +1 -0
- package/lib/tools.js +493 -0
- package/lib/tools.js.map +1 -0
- package/lib/types/approval-policy.d.ts +13 -0
- package/lib/types/approval-policy.d.ts.map +1 -0
- package/lib/types/artifacts.d.ts +10 -0
- package/lib/types/artifacts.d.ts.map +1 -0
- package/lib/types/backend.d.ts +94 -0
- package/lib/types/backend.d.ts.map +1 -0
- package/lib/types/client/index.d.ts +78 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/config.d.ts +75 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/confirmations.d.ts +23 -0
- package/lib/types/confirmations.d.ts.map +1 -0
- package/lib/types/diff.d.ts +5 -0
- package/lib/types/diff.d.ts.map +1 -0
- package/lib/types/errors.d.ts +15 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/exposure.d.ts +30 -0
- package/lib/types/exposure.d.ts.map +1 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/leases.d.ts +80 -0
- package/lib/types/leases.d.ts.map +1 -0
- package/lib/types/providers/macos.d.ts +15 -0
- package/lib/types/providers/macos.d.ts.map +1 -0
- package/lib/types/providers/native-helper.d.ts +36 -0
- package/lib/types/providers/native-helper.d.ts.map +1 -0
- package/lib/types/service.d.ts +52 -0
- package/lib/types/service.d.ts.map +1 -0
- package/lib/types/skill.d.ts +9 -0
- package/lib/types/skill.d.ts.map +1 -0
- package/lib/types/target-resolver.d.ts +38 -0
- package/lib/types/target-resolver.d.ts.map +1 -0
- package/lib/types/tools.d.ts +6 -0
- package/lib/types/tools.d.ts.map +1 -0
- package/lib/types/types.d.ts +246 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/web.d.ts +32 -0
- package/lib/types/web.d.ts.map +1 -0
- package/lib/types.js +9 -0
- package/lib/types.js.map +1 -0
- package/lib/web.js +163 -0
- package/lib/web.js.map +1 -0
- package/native/macos/Sources/Fixture/main.swift +366 -0
- package/native/macos/Sources/Helper/CursorImage.swift +11 -0
- package/native/macos/Sources/Helper/CursorOverlay.swift +488 -0
- package/native/macos/Sources/Helper/TargetedPointer.swift +314 -0
- package/native/macos/Sources/Helper/main.swift +1140 -0
- package/native/macos/Sources/Monitor/main.swift +139 -0
- package/native/macos/bin/dsh-computer-use-helper +0 -0
- package/native/macos/manifest.json +14 -0
- package/package.json +128 -0
- package/scripts/build-client.mjs +24 -0
- package/scripts/build-native.mjs +158 -0
- package/scripts/check-native.mjs +92 -0
- package/scripts/model-e2e.mjs +291 -0
- package/scripts/session-transcript.mjs +117 -0
- package/scripts/validate.mjs +256 -0
- package/src/approval-policy.ts +16 -0
- package/src/artifacts.ts +93 -0
- package/src/backend.ts +103 -0
- package/src/client/index.tsx +539 -0
- package/src/config.ts +196 -0
- package/src/confirmations.ts +128 -0
- package/src/diff.ts +52 -0
- package/src/errors.ts +39 -0
- package/src/exposure.ts +236 -0
- package/src/index.ts +66 -0
- package/src/leases.ts +337 -0
- package/src/providers/macos.ts +185 -0
- package/src/providers/native-helper.ts +393 -0
- package/src/service.ts +583 -0
- package/src/skill.ts +123 -0
- package/src/target-resolver.ts +237 -0
- package/src/tools.ts +528 -0
- package/src/types.ts +299 -0
- package/src/web.ts +180 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Provider-independent, fail-closed element target resolution. */
|
|
2
|
+
import type { BackendElement, BackendObservation } from './backend.ts';
|
|
3
|
+
import type { ComputerRect, ComputerTargetResolutionResult } from './types.ts';
|
|
4
|
+
/** Fixed confidence values used by the deterministic resolver. */
|
|
5
|
+
export declare const TARGET_RESOLUTION_CONFIDENCE: {
|
|
6
|
+
readonly exactLocator: 1;
|
|
7
|
+
readonly nativeIdentifier: 1;
|
|
8
|
+
readonly semantic: 0.9;
|
|
9
|
+
readonly semanticThreshold: 0.9;
|
|
10
|
+
};
|
|
11
|
+
interface AncestorFingerprintEntry {
|
|
12
|
+
role: string;
|
|
13
|
+
subrole?: string;
|
|
14
|
+
accessibleName?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Normalized provider evidence stored behind an opaque target handle. */
|
|
17
|
+
export interface ComputerTargetDescriptor {
|
|
18
|
+
locator: number[];
|
|
19
|
+
nativeIdentifier?: string;
|
|
20
|
+
role: string;
|
|
21
|
+
subrole?: string;
|
|
22
|
+
accessibleName?: string;
|
|
23
|
+
ancestorFingerprint: AncestorFingerprintEntry[];
|
|
24
|
+
normalizedFrame?: ComputerRect;
|
|
25
|
+
availableActions: string[];
|
|
26
|
+
}
|
|
27
|
+
/** Successful resolution plus the fresh provider observation used for input. */
|
|
28
|
+
export interface ResolvedComputerTarget {
|
|
29
|
+
element: BackendElement;
|
|
30
|
+
observation: BackendObservation;
|
|
31
|
+
resolution: ComputerTargetResolutionResult;
|
|
32
|
+
}
|
|
33
|
+
/** Build the normalized descriptor stored behind one opaque handle. */
|
|
34
|
+
export declare function describeComputerTarget(element: BackendElement, observation: BackendObservation): ComputerTargetDescriptor;
|
|
35
|
+
/** Resolve one descriptor against a fresh provider observation without guessing. */
|
|
36
|
+
export declare function resolveComputerTarget(original: BackendObservation, fresh: BackendObservation, expected: ComputerTargetDescriptor, allowRebind: boolean): ResolvedComputerTarget;
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=target-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target-resolver.d.ts","sourceRoot":"","sources":["../../src/target-resolver.ts"],"names":[],"mappings":"AAAA,mEAAmE;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAA;AAE9E,kEAAkE;AAClE,eAAO,MAAM,4BAA4B;;;;;CAK/B,CAAA;AAEV,UAAU,wBAAwB;IAChC,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,0EAA0E;AAC1E,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,mBAAmB,EAAE,wBAAwB,EAAE,CAAA;IAC/C,eAAe,CAAC,EAAE,YAAY,CAAA;IAC9B,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAC3B;AAED,gFAAgF;AAChF,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,cAAc,CAAA;IACvB,WAAW,EAAE,kBAAkB,CAAA;IAC/B,UAAU,EAAE,8BAA8B,CAAA;CAC3C;AAmFD,uEAAuE;AACvE,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,cAAc,EACvB,WAAW,EAAE,kBAAkB,GAC9B,wBAAwB,CAmC1B;AAED,oFAAoF;AACpF,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,wBAAwB,EAClC,WAAW,EAAE,OAAO,GACnB,sBAAsB,CAqExB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Focused model-facing Computer Use Tool definitions. */
|
|
2
|
+
import { type ToolDefinition } from '@deepseek-ai/dsh-tools';
|
|
3
|
+
import type { ComputerUseService } from './service.ts';
|
|
4
|
+
/** Create the focused execution definitions bound to one active Service generation. */
|
|
5
|
+
export declare function createComputerUseTools(service: ComputerUseService): ToolDefinition[];
|
|
6
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/tools.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAG1D,OAAO,EAA8B,KAAK,cAAc,EAA6C,MAAM,wBAAwB,CAAA;AASnI,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAyStD,uFAAuF;AACvF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,kBAAkB,GAAG,cAAc,EAAE,CAyNpF"}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/** Public Computer Use types shared by the Service, provider, and Tool consumer. */
|
|
2
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
3
|
+
import type { Branded } from '@deepseek-ai/dsh-brand';
|
|
4
|
+
import type { CallId } from '@deepseek-ai/dsh-llm';
|
|
5
|
+
/** Opaque identifier for one immutable observed UI state. */
|
|
6
|
+
export type ComputerObservationId = Branded<'ComputerObservationId'>;
|
|
7
|
+
/** Brand a generated observation identifier. */
|
|
8
|
+
export declare const ComputerObservationId: (value: string) => ComputerObservationId;
|
|
9
|
+
/** Opaque reference to one element descriptor captured inside an observation. */
|
|
10
|
+
export type ComputerTargetHandle = Branded<'ComputerTargetHandle'>;
|
|
11
|
+
/** Brand a generated target handle. */
|
|
12
|
+
export declare const ComputerTargetHandle: (value: string) => ComputerTargetHandle;
|
|
13
|
+
/** Opaque one-use grant for one confirmed sensitive action. */
|
|
14
|
+
export type ComputerConfirmationToken = Branded<'ComputerConfirmationToken'>;
|
|
15
|
+
/** Brand a generated confirmation token. */
|
|
16
|
+
export declare const ComputerConfirmationToken: (value: string) => ComputerConfirmationToken;
|
|
17
|
+
/** Rectangle in screen-global point coordinates unless a containing type states otherwise. */
|
|
18
|
+
export interface ComputerRect {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}
|
|
24
|
+
/** macOS permission state reported without attempting to grant it. */
|
|
25
|
+
export type ComputerPermissionState = 'granted' | 'denied' | 'not-determined' | 'unavailable';
|
|
26
|
+
/** Stable identity of one running user-facing application. */
|
|
27
|
+
export interface ComputerAppIdentity {
|
|
28
|
+
bundleId: string;
|
|
29
|
+
pid: number;
|
|
30
|
+
name: string;
|
|
31
|
+
}
|
|
32
|
+
/** Application selector accepted from a model or caller. */
|
|
33
|
+
export interface ComputerAppSelector {
|
|
34
|
+
bundleId?: string;
|
|
35
|
+
pid?: number;
|
|
36
|
+
name?: string;
|
|
37
|
+
}
|
|
38
|
+
/** Bounded application row returned by discovery. */
|
|
39
|
+
export interface ComputerAppSummary extends ComputerAppIdentity {
|
|
40
|
+
frontmost: boolean;
|
|
41
|
+
accessibility: ComputerPermissionState;
|
|
42
|
+
screenRecording: ComputerPermissionState;
|
|
43
|
+
}
|
|
44
|
+
/** One model-addressable element. Its index and opaque handle belong only to the enclosing observation. */
|
|
45
|
+
export interface ComputerElement {
|
|
46
|
+
index: number;
|
|
47
|
+
targetHandle: ComputerTargetHandle;
|
|
48
|
+
role: string;
|
|
49
|
+
subrole?: string;
|
|
50
|
+
title?: string;
|
|
51
|
+
label?: string;
|
|
52
|
+
value?: string;
|
|
53
|
+
enabled?: boolean;
|
|
54
|
+
focused?: boolean;
|
|
55
|
+
selected?: boolean;
|
|
56
|
+
frame?: ComputerRect;
|
|
57
|
+
actions: string[];
|
|
58
|
+
}
|
|
59
|
+
/** Deterministic route used to resolve a target immediately before input. */
|
|
60
|
+
export type ComputerTargetResolutionMode = 'exact-locator' | 'native-identifier' | 'semantic-rebind';
|
|
61
|
+
/** Model-visible evidence describing how an element target was resolved. */
|
|
62
|
+
export interface ComputerTargetResolutionResult {
|
|
63
|
+
mode: ComputerTargetResolutionMode;
|
|
64
|
+
confidence: number;
|
|
65
|
+
candidateCount: number;
|
|
66
|
+
targetChanged: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** File artifact emitted by a Computer Use observation. */
|
|
69
|
+
export interface ComputerArtifact {
|
|
70
|
+
path: string;
|
|
71
|
+
filename: string;
|
|
72
|
+
mimeType: 'image/png';
|
|
73
|
+
kind: 'image';
|
|
74
|
+
description: string;
|
|
75
|
+
sourceTool: 'computer_observe' | 'computer_action';
|
|
76
|
+
previewIntent: 'image';
|
|
77
|
+
bytes: number;
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
}
|
|
81
|
+
/** Complete model-visible observation. */
|
|
82
|
+
export interface ComputerObservation {
|
|
83
|
+
observationId: ComputerObservationId;
|
|
84
|
+
app: ComputerAppIdentity;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
expiresAt: string;
|
|
87
|
+
frontmost: boolean;
|
|
88
|
+
window?: {
|
|
89
|
+
title?: string;
|
|
90
|
+
frame: ComputerRect;
|
|
91
|
+
id?: number;
|
|
92
|
+
};
|
|
93
|
+
tree: {
|
|
94
|
+
mode: 'full' | 'diff';
|
|
95
|
+
text: string;
|
|
96
|
+
truncated: boolean;
|
|
97
|
+
};
|
|
98
|
+
elements: ComputerElement[];
|
|
99
|
+
screenshot?: ComputerArtifact;
|
|
100
|
+
permissions: {
|
|
101
|
+
accessibility: ComputerPermissionState;
|
|
102
|
+
screenRecording: ComputerPermissionState;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Whether screenshot capture is omitted, best-effort, or required. */
|
|
106
|
+
export type ComputerScreenshotMode = 'none' | 'optional' | 'required';
|
|
107
|
+
/** Request for a fresh observation. */
|
|
108
|
+
export interface ComputerObserveRequest {
|
|
109
|
+
app: ComputerAppSelector;
|
|
110
|
+
screenshot?: ComputerScreenshotMode;
|
|
111
|
+
full?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/** Closed set of supported key modifiers. */
|
|
114
|
+
export type ComputerKeyModifier = 'command' | 'control' | 'option' | 'shift';
|
|
115
|
+
/** Closed set of supported mouse buttons. */
|
|
116
|
+
export type ComputerMouseButton = 'left' | 'right' | 'middle';
|
|
117
|
+
/** Coordinate space accepted by coordinate-based pointer actions. */
|
|
118
|
+
export type ComputerCoordinateSpace = 'window' | 'screen';
|
|
119
|
+
/** Shared fields carried by every action against an existing observation. */
|
|
120
|
+
export interface ComputerActionBase {
|
|
121
|
+
observationId: ComputerObservationId;
|
|
122
|
+
/** True only when the Skill has classified the action as requiring just-in-time confirmation. */
|
|
123
|
+
sensitive?: boolean;
|
|
124
|
+
/** One-use token returned by {@link ComputerUseService.confirm}. */
|
|
125
|
+
confirmationToken?: ComputerConfirmationToken;
|
|
126
|
+
}
|
|
127
|
+
/** Stable target selection fields shared by element-addressed actions. */
|
|
128
|
+
export interface ComputerElementTarget {
|
|
129
|
+
/** Observation-local compatibility index. It does not authorize rebinding by itself. */
|
|
130
|
+
elementIndex?: number;
|
|
131
|
+
/** Opaque handle returned on the selected observation element. */
|
|
132
|
+
targetHandle?: ComputerTargetHandle;
|
|
133
|
+
/** Permit deterministic native-identifier or unique semantic rebinding. */
|
|
134
|
+
allowRebind?: boolean;
|
|
135
|
+
}
|
|
136
|
+
/** Click an observed element or an observed-window coordinate. */
|
|
137
|
+
export interface ComputerClickAction extends ComputerActionBase, ComputerElementTarget {
|
|
138
|
+
kind: 'click';
|
|
139
|
+
x?: number;
|
|
140
|
+
y?: number;
|
|
141
|
+
/** `window` (default) resolves `x`/`y` inside the observed window frame; `screen` treats them as Quartz screen-global points. */
|
|
142
|
+
coordinateSpace?: ComputerCoordinateSpace;
|
|
143
|
+
button?: ComputerMouseButton;
|
|
144
|
+
clickCount?: number;
|
|
145
|
+
allowCoordinateFallback?: boolean;
|
|
146
|
+
}
|
|
147
|
+
/** Set the Accessibility value of an observed editable element. */
|
|
148
|
+
export interface ComputerSetValueAction extends ComputerActionBase, ComputerElementTarget {
|
|
149
|
+
kind: 'set-value';
|
|
150
|
+
value: string;
|
|
151
|
+
}
|
|
152
|
+
/** Insert Unicode into the currently focused control through Accessibility or keyboard fallback, without using the clipboard. */
|
|
153
|
+
export interface ComputerTypeTextAction extends ComputerActionBase {
|
|
154
|
+
kind: 'type-text';
|
|
155
|
+
text: string;
|
|
156
|
+
}
|
|
157
|
+
/** Press one validated key chord. */
|
|
158
|
+
export interface ComputerPressKeyAction extends ComputerActionBase {
|
|
159
|
+
kind: 'press-key';
|
|
160
|
+
key: string;
|
|
161
|
+
modifiers?: ComputerKeyModifier[];
|
|
162
|
+
}
|
|
163
|
+
/** Scroll at an observed element or coordinate. */
|
|
164
|
+
export interface ComputerScrollAction extends ComputerActionBase, ComputerElementTarget {
|
|
165
|
+
kind: 'scroll';
|
|
166
|
+
x?: number;
|
|
167
|
+
y?: number;
|
|
168
|
+
coordinateSpace?: ComputerCoordinateSpace;
|
|
169
|
+
direction: 'up' | 'down' | 'left' | 'right';
|
|
170
|
+
pages?: number;
|
|
171
|
+
}
|
|
172
|
+
/** Drag between two points in the observed window or screen coordinate space. */
|
|
173
|
+
export interface ComputerDragAction extends ComputerActionBase {
|
|
174
|
+
kind: 'drag';
|
|
175
|
+
fromX: number;
|
|
176
|
+
fromY: number;
|
|
177
|
+
toX: number;
|
|
178
|
+
toY: number;
|
|
179
|
+
coordinateSpace?: ComputerCoordinateSpace;
|
|
180
|
+
}
|
|
181
|
+
/** Perform one Accessibility action advertised by an observed element. */
|
|
182
|
+
export interface ComputerPerformAction extends ComputerActionBase, ComputerElementTarget {
|
|
183
|
+
kind: 'perform-action';
|
|
184
|
+
action: string;
|
|
185
|
+
}
|
|
186
|
+
/** Wait for a bounded UI condition without mutating state. */
|
|
187
|
+
export interface ComputerWaitAction extends ComputerActionBase {
|
|
188
|
+
kind: 'wait';
|
|
189
|
+
condition: {
|
|
190
|
+
text?: string;
|
|
191
|
+
elementRole?: string;
|
|
192
|
+
elementTitle?: string;
|
|
193
|
+
};
|
|
194
|
+
timeoutMs?: number;
|
|
195
|
+
}
|
|
196
|
+
/** Every model-accessible Computer Use action. */
|
|
197
|
+
export type ComputerActionRequest = ComputerClickAction | ComputerSetValueAction | ComputerTypeTextAction | ComputerPressKeyAction | ComputerScrollAction | ComputerDragAction | ComputerPerformAction | ComputerWaitAction;
|
|
198
|
+
/** Result of a successful action followed by a fresh observation. */
|
|
199
|
+
export interface ComputerActionResult {
|
|
200
|
+
action: ComputerActionRequest['kind'];
|
|
201
|
+
channel: 'accessibility' | 'coordinates' | 'keyboard' | 'wait';
|
|
202
|
+
/** Verifiable target-app foreground state transition requested by the helper for this action. */
|
|
203
|
+
activation: 'not-requested' | 'already-frontmost' | 'activated';
|
|
204
|
+
/** Whether the helper emitted mouse, drag, or scroll-wheel input to the target process. */
|
|
205
|
+
pointerInput: boolean;
|
|
206
|
+
/** Pointer-event route selected by the helper; global HID routing is not supported. */
|
|
207
|
+
pointerRouting: 'none' | 'target-process';
|
|
208
|
+
/** Present when the action addressed an observed element. */
|
|
209
|
+
resolution?: ComputerTargetResolutionResult;
|
|
210
|
+
observation: ComputerObservation;
|
|
211
|
+
}
|
|
212
|
+
/** Confirmation request binding an exact proposed action to human-readable impact. */
|
|
213
|
+
export interface ComputerConfirmRequest {
|
|
214
|
+
action: Omit<ComputerActionRequest, 'confirmationToken'>;
|
|
215
|
+
reason: string;
|
|
216
|
+
target: string;
|
|
217
|
+
dataSummary?: string;
|
|
218
|
+
}
|
|
219
|
+
/** One-use confirmation result. */
|
|
220
|
+
export interface ComputerConfirmation {
|
|
221
|
+
token: ComputerConfirmationToken;
|
|
222
|
+
observationId: ComputerObservationId;
|
|
223
|
+
app: ComputerAppIdentity;
|
|
224
|
+
expiresAt: string;
|
|
225
|
+
}
|
|
226
|
+
/** Caller context required for scoping, cancellation, approval audit, and artifact placement. */
|
|
227
|
+
export interface ComputerUseContext {
|
|
228
|
+
agent: Agent;
|
|
229
|
+
workspace: string;
|
|
230
|
+
callId?: CallId;
|
|
231
|
+
signal: AbortSignal;
|
|
232
|
+
}
|
|
233
|
+
/** Provider and permission diagnostics exposed to Settings. */
|
|
234
|
+
export interface ComputerUseStatus {
|
|
235
|
+
platform: NodeJS.Platform;
|
|
236
|
+
provider: 'macos-ax';
|
|
237
|
+
generation: number;
|
|
238
|
+
ready: boolean;
|
|
239
|
+
helperPath: string;
|
|
240
|
+
helperVersion?: string;
|
|
241
|
+
helperSha256?: string;
|
|
242
|
+
accessibility: ComputerPermissionState;
|
|
243
|
+
screenRecording: ComputerPermissionState;
|
|
244
|
+
lastError?: string;
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,oFAAoF;AAEpF,OAAO,KAAK,EAAE,KAAK,EAAE,MAA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ACzC,6DAA6D;IAC7D,UAAU,CAAC,EAAE,8BAA8B,CAAA;IAC3C,WAAW,EAAE,mBAAmB,CAAA;CACjC;AAED,sFAAsF;AACtF,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,IAAI,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,CAAA;IACxD,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,mCAAmC;AACnC,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,yBAAyB,CAAA;IAChC,aAAa,EAAE,qBAAqB,CAAA;IACpC,GAAG,EAAE,mBAAmB,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,iGAAiG;AACjG,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,WAAW,CAAA;CACpB;AAED,+DAA+D;AAC/D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAA;IACzB,QAAQ,EAAE,UAAU,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,OAAO,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,uBAAuB,CAAA;IACtC,eAAe,EAAE,uBAAuB,CAAA;IACxC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Optional Web Settings and provider-health route. */
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
4
|
+
import { type ComputerUseConfig } from './config.ts';
|
|
5
|
+
import type { ComputerUseStatus } from './types.ts';
|
|
6
|
+
/** Exact same-origin Settings endpoint. */
|
|
7
|
+
export declare const COMPUTER_USE_SETTINGS_ROUTE = "/_dsh/computer-use/settings";
|
|
8
|
+
/** Browser-safe Settings snapshot. */
|
|
9
|
+
export interface ComputerUseSettingsSnapshot {
|
|
10
|
+
schemaVersion: 1;
|
|
11
|
+
writable: boolean;
|
|
12
|
+
settings: {
|
|
13
|
+
value: ComputerUseConfig;
|
|
14
|
+
user?: unknown;
|
|
15
|
+
base?: unknown;
|
|
16
|
+
revision: number;
|
|
17
|
+
applies: 'live';
|
|
18
|
+
};
|
|
19
|
+
provider: ComputerUseStatus;
|
|
20
|
+
}
|
|
21
|
+
/** Same-origin backend used by the optional client Settings section. */
|
|
22
|
+
export declare class ComputerUseWebBackend {
|
|
23
|
+
private readonly ctx;
|
|
24
|
+
constructor(ctx: Context);
|
|
25
|
+
/** Current browser-safe Settings and health state. */
|
|
26
|
+
snapshot(): ComputerUseSettingsSnapshot;
|
|
27
|
+
/** Handle one Settings request. */
|
|
28
|
+
handle(req: IncomingMessage, res: ServerResponse): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/** Attach the optional route when a Web host is present. */
|
|
31
|
+
export declare function installComputerUseWeb(ctx: Context): void;
|
|
32
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,2CAA2C;AAC3C,eAAO,MAAM,2BAA2B,gCAAgC,CAAA;AAExE,sCAAsC;AACtC,MAAM,WAAW,2BAA2B;IAC1C,aAAa,EAAE,CAAC,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,EAAE;QACR,KAAK,EAAE,iBAAiB,CAAA;QACxB,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,IAAI,CAAC,EAAE,OAAO,CAAA;QACd,QAAQ,EAAE,MAAM,CAAA;QAChB,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;IACD,QAAQ,EAAE,iBAAiB,CAAA;CAC5B;AAiFD,wEAAwE;AACxE,qBAAa,qBAAqB;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG;gBAAH,GAAG,EAAE,OAAO;IAEzC,sDAAsD;IACtD,QAAQ,IAAI,2BAA2B;IAgBvC,mCAAmC;IAC7B,MAAM,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAqCvE;AAED,4DAA4D;AAC5D,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CASxD"}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Public Computer Use types shared by the Service, provider, and Tool consumer. */
|
|
2
|
+
/** Brand a generated observation identifier. */
|
|
3
|
+
export const ComputerObservationId = (value) => value;
|
|
4
|
+
/** Brand a generated target handle. */
|
|
5
|
+
export const ComputerTargetHandle = (value) => value;
|
|
6
|
+
/** Brand a generated confirmation token. */
|
|
7
|
+
export const ComputerConfirmationToken = (value) => value;
|
|
8
|
+
void 0;
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oFAAoF;AASpF,gDAAgD;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAAa,EAAyB,EAAE,CAAC,KAA8B,CAAA;AAK7G,uCAAuC;AACvC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,KAAa,EAAwB,EAAE,CAAC,KAA6B,CAAA;AAK1G,4CAA4C;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,KAAa,EAA6B,EAAE,CAAC,KAAkC,CAAA;AAoRzH,KAAM,CAA+C,CAAA"}
|
package/lib/web.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/** Optional Web Settings and provider-health route. */
|
|
2
|
+
import { SettingsConflictError } from '@deepseek-ai/dsh-settings';
|
|
3
|
+
import { COMPUTER_USE_SETTINGS_NAMESPACE, } from "./config.js";
|
|
4
|
+
/** Exact same-origin Settings endpoint. */
|
|
5
|
+
export const COMPUTER_USE_SETTINGS_ROUTE = '/_dsh/computer-use/settings';
|
|
6
|
+
function isRecord(value) {
|
|
7
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function descriptorOf(ctx) {
|
|
10
|
+
const descriptor = ctx.settings.describe().find(row => row.ns === COMPUTER_USE_SETTINGS_NAMESPACE);
|
|
11
|
+
if (descriptor === undefined)
|
|
12
|
+
throw new Error('computer-use Settings namespace is not registered');
|
|
13
|
+
return descriptor;
|
|
14
|
+
}
|
|
15
|
+
function responseJson(res, status, body) {
|
|
16
|
+
const bytes = Buffer.from(JSON.stringify(body));
|
|
17
|
+
res.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
18
|
+
res.setHeader('Content-Length', String(bytes.length));
|
|
19
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
20
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
21
|
+
res.setHeader('Content-Security-Policy', "default-src 'none'; frame-ancestors 'none'");
|
|
22
|
+
res.writeHead(status);
|
|
23
|
+
res.end(bytes);
|
|
24
|
+
}
|
|
25
|
+
function requestError(res, status, code, message) {
|
|
26
|
+
responseJson(res, status, { ok: false, error: { code, message } });
|
|
27
|
+
}
|
|
28
|
+
function sameOriginPost(req) {
|
|
29
|
+
const fetchSite = req.headers['sec-fetch-site'];
|
|
30
|
+
if (fetchSite === 'cross-site')
|
|
31
|
+
return false;
|
|
32
|
+
const origin = req.headers.origin;
|
|
33
|
+
if (origin === undefined)
|
|
34
|
+
return fetchSite === 'same-origin' || fetchSite === 'same-site' || fetchSite === 'none';
|
|
35
|
+
const host = req.headers.host;
|
|
36
|
+
if (host === undefined)
|
|
37
|
+
return false;
|
|
38
|
+
try {
|
|
39
|
+
const parsed = new URL(origin);
|
|
40
|
+
return (parsed.protocol === 'http:' || parsed.protocol === 'https:') && parsed.host === host;
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
async function readJson(req, maxBytes = 128 * 1024) {
|
|
47
|
+
const contentType = req.headers['content-type']?.split(';', 1)[0]?.trim().toLowerCase();
|
|
48
|
+
if (contentType !== 'application/json')
|
|
49
|
+
throw new TypeError('Content-Type must be application/json');
|
|
50
|
+
const chunks = [];
|
|
51
|
+
let bytes = 0;
|
|
52
|
+
for await (const chunk of req) {
|
|
53
|
+
const part = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
54
|
+
bytes += part.length;
|
|
55
|
+
if (bytes > maxBytes)
|
|
56
|
+
throw new RangeError(`request body exceeds ${maxBytes} bytes`);
|
|
57
|
+
chunks.push(part);
|
|
58
|
+
}
|
|
59
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
60
|
+
}
|
|
61
|
+
function parseRequest(value) {
|
|
62
|
+
if (!isRecord(value) || typeof value.action !== 'string')
|
|
63
|
+
throw new TypeError('request needs an action');
|
|
64
|
+
if (value.action === 'health')
|
|
65
|
+
return { action: 'health' };
|
|
66
|
+
if (value.action === 'open-settings') {
|
|
67
|
+
if (value.kind !== 'accessibility' && value.kind !== 'screen-recording')
|
|
68
|
+
throw new TypeError('open-settings needs a valid kind');
|
|
69
|
+
return { action: 'open-settings', kind: value.kind };
|
|
70
|
+
}
|
|
71
|
+
if (value.action === 'save') {
|
|
72
|
+
if (!Number.isInteger(value.expectedRevision) || !isRecord(value.value))
|
|
73
|
+
throw new TypeError('save needs expectedRevision and value');
|
|
74
|
+
return { action: 'save', expectedRevision: value.expectedRevision, value: value.value };
|
|
75
|
+
}
|
|
76
|
+
throw new TypeError(`unknown action: ${value.action}`);
|
|
77
|
+
}
|
|
78
|
+
function publicMessage(error) {
|
|
79
|
+
return error instanceof Error ? error.message.slice(0, 1000) : String(error).slice(0, 1000);
|
|
80
|
+
}
|
|
81
|
+
/** Same-origin backend used by the optional client Settings section. */
|
|
82
|
+
export class ComputerUseWebBackend {
|
|
83
|
+
ctx;
|
|
84
|
+
constructor(ctx) {
|
|
85
|
+
this.ctx = ctx;
|
|
86
|
+
}
|
|
87
|
+
/** Current browser-safe Settings and health state. */
|
|
88
|
+
snapshot() {
|
|
89
|
+
const descriptor = descriptorOf(this.ctx);
|
|
90
|
+
return {
|
|
91
|
+
schemaVersion: 1,
|
|
92
|
+
writable: this.ctx.settings.writable,
|
|
93
|
+
settings: {
|
|
94
|
+
value: descriptor.value,
|
|
95
|
+
...(descriptor.user === undefined ? {} : { user: descriptor.user }),
|
|
96
|
+
...(descriptor.base === undefined ? {} : { base: descriptor.base }),
|
|
97
|
+
revision: descriptor.revision,
|
|
98
|
+
applies: 'live',
|
|
99
|
+
},
|
|
100
|
+
provider: this.ctx.computerUse.status(),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Handle one Settings request. */
|
|
104
|
+
async handle(req, res) {
|
|
105
|
+
if (req.method === 'GET') {
|
|
106
|
+
try {
|
|
107
|
+
responseJson(res, 200, { ok: true, value: this.snapshot() });
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
requestError(res, 503, 'settings-unavailable', publicMessage(error));
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (req.method !== 'POST') {
|
|
115
|
+
res.setHeader('Allow', 'GET, POST');
|
|
116
|
+
requestError(res, 405, 'method-not-allowed', 'Use GET or POST');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!sameOriginPost(req)) {
|
|
120
|
+
requestError(res, 403, 'origin-rejected', 'The request must originate from this DSH Web application');
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
let parsed;
|
|
124
|
+
try {
|
|
125
|
+
parsed = parseRequest(await readJson(req));
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
requestError(res, error instanceof RangeError ? 413 : 400, 'invalid-request', publicMessage(error));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
if (parsed.action === 'save') {
|
|
133
|
+
if (!this.ctx.settings.writable)
|
|
134
|
+
throw new Error('settings provider is read-only');
|
|
135
|
+
await this.ctx.settings.replace(COMPUTER_USE_SETTINGS_NAMESPACE, parsed.value, parsed.expectedRevision);
|
|
136
|
+
}
|
|
137
|
+
else if (parsed.action === 'health') {
|
|
138
|
+
await this.ctx.computerUse.health(AbortSignal.timeout(30000));
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
await this.ctx.computerUse.openPermissionSettings(parsed.kind, AbortSignal.timeout(10000));
|
|
142
|
+
}
|
|
143
|
+
responseJson(res, 200, { ok: true, value: this.snapshot() });
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
const conflict = error instanceof SettingsConflictError;
|
|
147
|
+
this.ctx.logger.warn('dsh-computer-use Web action=%s failed: %s', parsed.action, publicMessage(error));
|
|
148
|
+
requestError(res, conflict ? 409 : 400, conflict ? 'settings-conflict' : 'action-failed', publicMessage(error));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/** Attach the optional route when a Web host is present. */
|
|
153
|
+
export function installComputerUseWeb(ctx) {
|
|
154
|
+
const backend = new ComputerUseWebBackend(ctx);
|
|
155
|
+
ctx.inject(['webServer'], (webCtx) => {
|
|
156
|
+
webCtx.effect(() => webCtx.webServer.register({
|
|
157
|
+
kind: 'exact',
|
|
158
|
+
path: COMPUTER_USE_SETTINGS_ROUTE,
|
|
159
|
+
handler: (req, res) => backend.handle(req, res),
|
|
160
|
+
}), 'dsh-computer-use: Web Settings route');
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=web.js.map
|
package/lib/web.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAIvD,OAAO,EAAE,qBAAqB,EAA2B,MAAM,2BAA2B,CAAA;AAE1F,OAAO,EACL,+BAA+B,GAEhC,MAAM,aAAa,CAAA;AAGpB,2CAA2C;AAC3C,MAAM,CAAC,MAAM,2BAA2B,GAAG,6BAA6B,CAAA;AAuBxE,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED,SAAS,YAAY,CAAC,GAAY;IAChC,MAAM,UAAU,GAAG,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,+BAA+B,CAAC,CAAA;IAClG,IAAI,UAAU,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IAClG,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,SAAS,YAAY,CAAI,GAAmB,EAAE,MAAc,EAAE,IAAqB;IACjF,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;IAC/C,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,iCAAiC,CA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