screenhand 0.1.1 → 0.2.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/README.md +458 -93
- package/dist/.audit-log.jsonl +55 -0
- package/dist/.screenhand/memory/.lock +1 -0
- package/dist/.screenhand/memory/actions.jsonl +85 -0
- package/dist/.screenhand/memory/errors.jsonl +5 -0
- package/dist/.screenhand/memory/errors.jsonl.bak +4 -0
- package/dist/.screenhand/memory/state.json +35 -0
- package/dist/.screenhand/memory/state.json.bak +35 -0
- package/dist/.screenhand/memory/strategies.jsonl +12 -0
- package/dist/agent/cli.js +73 -0
- package/dist/agent/loop.js +258 -0
- package/dist/config.js +9 -0
- package/dist/index.js +56 -0
- package/dist/logging/timeline-logger.js +29 -0
- package/dist/mcp/mcp-stdio-server.js +448 -0
- package/dist/mcp/server.js +347 -0
- package/dist/mcp-desktop.js +2731 -0
- package/dist/mcp-entry.js +59 -0
- package/dist/memory/recall.js +160 -0
- package/dist/memory/research.js +98 -0
- package/dist/memory/seeds.js +89 -0
- package/dist/memory/session.js +161 -0
- package/dist/memory/store.js +391 -0
- package/dist/memory/types.js +4 -0
- package/dist/monitor/codex-monitor.js +377 -0
- package/dist/monitor/task-queue.js +84 -0
- package/dist/monitor/types.js +49 -0
- package/dist/native/bridge-client.js +174 -0
- package/dist/native/macos-bridge-client.js +5 -0
- package/dist/npm-publish-helper.js +117 -0
- package/dist/npm-token-cdp.js +113 -0
- package/dist/npm-token-create.js +135 -0
- package/dist/npm-token-finish.js +126 -0
- package/dist/playbook/engine.js +193 -0
- package/dist/playbook/index.js +4 -0
- package/dist/playbook/recorder.js +519 -0
- package/dist/playbook/runner.js +392 -0
- package/dist/playbook/store.js +166 -0
- package/dist/playbook/types.js +4 -0
- package/dist/runtime/accessibility-adapter.js +377 -0
- package/dist/runtime/app-adapter.js +48 -0
- package/dist/runtime/applescript-adapter.js +283 -0
- package/dist/runtime/ax-role-map.js +80 -0
- package/dist/runtime/browser-adapter.js +36 -0
- package/dist/runtime/cdp-chrome-adapter.js +505 -0
- package/dist/runtime/composite-adapter.js +205 -0
- package/dist/runtime/executor.js +250 -0
- package/dist/runtime/locator-cache.js +12 -0
- package/dist/runtime/planning-loop.js +47 -0
- package/dist/runtime/service.js +372 -0
- package/dist/runtime/session-manager.js +28 -0
- package/dist/runtime/state-observer.js +105 -0
- package/dist/runtime/vision-adapter.js +208 -0
- package/dist/scripts/codex-monitor-daemon.js +335 -0
- package/dist/scripts/supervisor-daemon.js +272 -0
- package/dist/scripts/worker-daemon.js +228 -0
- package/dist/src/agent/cli.js +82 -0
- package/dist/src/agent/loop.js +274 -0
- package/{src/config.ts → dist/src/config.js} +5 -10
- package/{src/index.ts → dist/src/index.js} +32 -52
- package/dist/src/jobs/manager.js +237 -0
- package/dist/src/jobs/runner.js +683 -0
- package/dist/src/jobs/store.js +102 -0
- package/dist/src/jobs/types.js +30 -0
- package/dist/src/jobs/worker.js +97 -0
- package/dist/src/logging/timeline-logger.js +45 -0
- package/dist/src/mcp/mcp-stdio-server.js +464 -0
- package/dist/src/mcp/server.js +363 -0
- package/dist/src/mcp-entry.js +60 -0
- package/dist/src/memory/recall.js +170 -0
- package/dist/src/memory/research.js +104 -0
- package/dist/src/memory/seeds.js +101 -0
- package/dist/src/memory/service.js +421 -0
- package/dist/src/memory/session.js +169 -0
- package/dist/src/memory/store.js +422 -0
- package/dist/src/memory/types.js +17 -0
- package/dist/src/monitor/codex-monitor.js +382 -0
- package/dist/src/monitor/task-queue.js +97 -0
- package/dist/src/monitor/types.js +62 -0
- package/dist/src/native/bridge-client.js +190 -0
- package/{src/native/macos-bridge-client.ts → dist/src/native/macos-bridge-client.js} +0 -1
- package/dist/src/playbook/engine.js +201 -0
- package/dist/src/playbook/index.js +20 -0
- package/dist/src/playbook/recorder.js +535 -0
- package/dist/src/playbook/runner.js +408 -0
- package/dist/src/playbook/store.js +183 -0
- package/dist/src/playbook/types.js +17 -0
- package/dist/src/runtime/accessibility-adapter.js +393 -0
- package/dist/src/runtime/app-adapter.js +64 -0
- package/dist/src/runtime/applescript-adapter.js +299 -0
- package/dist/src/runtime/ax-role-map.js +96 -0
- package/dist/src/runtime/browser-adapter.js +52 -0
- package/dist/src/runtime/cdp-chrome-adapter.js +521 -0
- package/dist/src/runtime/composite-adapter.js +221 -0
- package/dist/src/runtime/execution-contract.js +159 -0
- package/dist/src/runtime/executor.js +266 -0
- package/{src/runtime/locator-cache.ts → dist/src/runtime/locator-cache.js} +10 -15
- package/dist/src/runtime/planning-loop.js +63 -0
- package/dist/src/runtime/service.js +388 -0
- package/dist/src/runtime/session-manager.js +60 -0
- package/dist/src/runtime/state-observer.js +121 -0
- package/dist/src/runtime/vision-adapter.js +224 -0
- package/dist/src/supervisor/locks.js +186 -0
- package/dist/src/supervisor/supervisor.js +403 -0
- package/dist/src/supervisor/types.js +30 -0
- package/dist/src/test-mcp-protocol.js +154 -0
- package/dist/src/types.js +17 -0
- package/dist/src/util/atomic-write.js +118 -0
- package/dist/test-mcp-protocol.js +138 -0
- package/dist/types.js +1 -0
- package/package.json +18 -4
- package/.claude/commands/automate.md +0 -28
- package/.claude/commands/debug-ui.md +0 -19
- package/.claude/commands/screenshot.md +0 -15
- package/.github/FUNDING.yml +0 -1
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -27
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.mcp.json +0 -8
- package/DESKTOP_MCP_GUIDE.md +0 -92
- package/SECURITY.md +0 -44
- package/docs/architecture.md +0 -47
- package/install-skills.sh +0 -19
- package/mcp-bridge.ts +0 -271
- package/mcp-desktop.ts +0 -1221
- package/native/macos-bridge/Package.swift +0 -21
- package/native/macos-bridge/Sources/AccessibilityBridge.swift +0 -261
- package/native/macos-bridge/Sources/AppManagement.swift +0 -129
- package/native/macos-bridge/Sources/CoreGraphicsBridge.swift +0 -242
- package/native/macos-bridge/Sources/ObserverBridge.swift +0 -120
- package/native/macos-bridge/Sources/VisionBridge.swift +0 -80
- package/native/macos-bridge/Sources/main.swift +0 -345
- package/native/windows-bridge/AppManagement.cs +0 -234
- package/native/windows-bridge/InputBridge.cs +0 -436
- package/native/windows-bridge/Program.cs +0 -265
- package/native/windows-bridge/ScreenCapture.cs +0 -329
- package/native/windows-bridge/UIAutomationBridge.cs +0 -571
- package/native/windows-bridge/WindowsBridge.csproj +0 -17
- package/playbooks/devpost.json +0 -186
- package/playbooks/instagram.json +0 -41
- package/playbooks/instagram_v2.json +0 -201
- package/playbooks/x_v1.json +0 -211
- package/scripts/devpost-live-loop.mjs +0 -421
- package/src/logging/timeline-logger.ts +0 -55
- package/src/mcp/server.ts +0 -449
- package/src/memory/recall.ts +0 -191
- package/src/memory/research.ts +0 -146
- package/src/memory/seeds.ts +0 -123
- package/src/memory/session.ts +0 -201
- package/src/memory/store.ts +0 -434
- package/src/memory/types.ts +0 -69
- package/src/native/bridge-client.ts +0 -239
- package/src/runtime/accessibility-adapter.ts +0 -487
- package/src/runtime/app-adapter.ts +0 -169
- package/src/runtime/applescript-adapter.ts +0 -376
- package/src/runtime/ax-role-map.ts +0 -102
- package/src/runtime/browser-adapter.ts +0 -129
- package/src/runtime/cdp-chrome-adapter.ts +0 -676
- package/src/runtime/composite-adapter.ts +0 -274
- package/src/runtime/executor.ts +0 -396
- package/src/runtime/planning-loop.ts +0 -81
- package/src/runtime/service.ts +0 -448
- package/src/runtime/session-manager.ts +0 -50
- package/src/runtime/state-observer.ts +0 -136
- package/src/runtime/vision-adapter.ts +0 -297
- package/src/types.ts +0 -297
- package/tests/bridge-client.test.ts +0 -176
- package/tests/browser-stealth.test.ts +0 -210
- package/tests/composite-adapter.test.ts +0 -64
- package/tests/mcp-server.test.ts +0 -151
- package/tests/memory-recall.test.ts +0 -339
- package/tests/memory-research.test.ts +0 -159
- package/tests/memory-seeds.test.ts +0 -120
- package/tests/memory-store.test.ts +0 -392
- package/tests/types.test.ts +0 -92
- package/tsconfig.check.json +0 -17
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -8
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
export class MvpMcpServer {
|
|
2
|
+
runtime;
|
|
3
|
+
constructor(runtime) {
|
|
4
|
+
this.runtime = runtime;
|
|
5
|
+
}
|
|
6
|
+
async invoke(request) {
|
|
7
|
+
switch (request.tool) {
|
|
8
|
+
case "session_start":
|
|
9
|
+
return this.runtime.sessionStart(optionalString(request.args, "profile"));
|
|
10
|
+
case "navigate": {
|
|
11
|
+
const timeoutMs = optionalNumber(request.args, "timeoutMs");
|
|
12
|
+
const input = {
|
|
13
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
14
|
+
url: requiredString(request.args, "url"),
|
|
15
|
+
};
|
|
16
|
+
if (typeof timeoutMs === "number") {
|
|
17
|
+
input.timeoutMs = timeoutMs;
|
|
18
|
+
}
|
|
19
|
+
return this.runtime.navigate(input);
|
|
20
|
+
}
|
|
21
|
+
case "press": {
|
|
22
|
+
const verify = parseOptionalWaitCondition(request.args.verify);
|
|
23
|
+
const input = {
|
|
24
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
25
|
+
target: parseTarget(request.args.target),
|
|
26
|
+
};
|
|
27
|
+
if (verify) {
|
|
28
|
+
input.verify = verify;
|
|
29
|
+
}
|
|
30
|
+
return this.runtime.press(input);
|
|
31
|
+
}
|
|
32
|
+
case "type_into": {
|
|
33
|
+
const clear = optionalBoolean(request.args, "clear");
|
|
34
|
+
const verify = parseOptionalWaitCondition(request.args.verify);
|
|
35
|
+
const input = {
|
|
36
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
37
|
+
target: parseTarget(request.args.target),
|
|
38
|
+
text: requiredString(request.args, "text"),
|
|
39
|
+
};
|
|
40
|
+
if (typeof clear === "boolean") {
|
|
41
|
+
input.clear = clear;
|
|
42
|
+
}
|
|
43
|
+
if (verify) {
|
|
44
|
+
input.verify = verify;
|
|
45
|
+
}
|
|
46
|
+
return this.runtime.typeInto(input);
|
|
47
|
+
}
|
|
48
|
+
case "wait_for": {
|
|
49
|
+
const timeoutMs = optionalNumber(request.args, "timeoutMs");
|
|
50
|
+
const input = {
|
|
51
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
52
|
+
condition: parseWaitCondition(request.args.condition),
|
|
53
|
+
};
|
|
54
|
+
if (typeof timeoutMs === "number") {
|
|
55
|
+
input.timeoutMs = timeoutMs;
|
|
56
|
+
}
|
|
57
|
+
return this.runtime.waitFor(input);
|
|
58
|
+
}
|
|
59
|
+
case "extract":
|
|
60
|
+
return this.runtime.extract({
|
|
61
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
62
|
+
target: parseTarget(request.args.target),
|
|
63
|
+
format: parseExtractFormat(request.args.format),
|
|
64
|
+
});
|
|
65
|
+
case "screenshot": {
|
|
66
|
+
const region = parseOptionalRegion(request.args.region);
|
|
67
|
+
const input = {
|
|
68
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
69
|
+
};
|
|
70
|
+
if (region) {
|
|
71
|
+
input.region = region;
|
|
72
|
+
}
|
|
73
|
+
return this.runtime.screenshot(input);
|
|
74
|
+
}
|
|
75
|
+
// ── Desktop automation tools ──
|
|
76
|
+
case "app_launch":
|
|
77
|
+
return this.runtime.appLaunch({
|
|
78
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
79
|
+
bundleId: requiredString(request.args, "bundleId"),
|
|
80
|
+
});
|
|
81
|
+
case "app_focus":
|
|
82
|
+
return this.runtime.appFocus({
|
|
83
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
84
|
+
bundleId: requiredString(request.args, "bundleId"),
|
|
85
|
+
});
|
|
86
|
+
case "app_list":
|
|
87
|
+
return this.runtime.appList(requiredString(request.args, "sessionId"));
|
|
88
|
+
case "window_list":
|
|
89
|
+
return this.runtime.windowList(requiredString(request.args, "sessionId"));
|
|
90
|
+
case "menu_click":
|
|
91
|
+
return this.runtime.menuClick({
|
|
92
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
93
|
+
menuPath: requiredStringArray(request.args, "menuPath"),
|
|
94
|
+
});
|
|
95
|
+
case "key_combo":
|
|
96
|
+
return this.runtime.keyCombo({
|
|
97
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
98
|
+
keys: requiredStringArray(request.args, "keys"),
|
|
99
|
+
});
|
|
100
|
+
case "element_tree": {
|
|
101
|
+
const maxDepth = optionalNumber(request.args, "maxDepth");
|
|
102
|
+
const root = request.args.root ? parseTarget(request.args.root) : undefined;
|
|
103
|
+
const etInput = {
|
|
104
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
105
|
+
};
|
|
106
|
+
if (typeof maxDepth === "number")
|
|
107
|
+
etInput.maxDepth = maxDepth;
|
|
108
|
+
if (root)
|
|
109
|
+
etInput.root = root;
|
|
110
|
+
return this.runtime.elementTree(etInput);
|
|
111
|
+
}
|
|
112
|
+
case "observe_start": {
|
|
113
|
+
const events = request.args.events;
|
|
114
|
+
const osInput = {
|
|
115
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
116
|
+
};
|
|
117
|
+
if (Array.isArray(events)) {
|
|
118
|
+
osInput.events = events;
|
|
119
|
+
}
|
|
120
|
+
return this.runtime.observeStart(osInput);
|
|
121
|
+
}
|
|
122
|
+
case "observe_stop":
|
|
123
|
+
return this.runtime.observeStop({
|
|
124
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
125
|
+
});
|
|
126
|
+
case "drag":
|
|
127
|
+
return this.runtime.drag({
|
|
128
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
129
|
+
from: parseTarget(request.args.from),
|
|
130
|
+
to: parseTarget(request.args.to),
|
|
131
|
+
});
|
|
132
|
+
case "scroll": {
|
|
133
|
+
const scrollTarget = request.args.target ? parseTarget(request.args.target) : undefined;
|
|
134
|
+
const scrollAmount = optionalNumber(request.args, "amount");
|
|
135
|
+
const scrollInput = {
|
|
136
|
+
sessionId: requiredString(request.args, "sessionId"),
|
|
137
|
+
direction: requiredString(request.args, "direction"),
|
|
138
|
+
};
|
|
139
|
+
if (scrollTarget)
|
|
140
|
+
scrollInput.target = scrollTarget;
|
|
141
|
+
if (typeof scrollAmount === "number")
|
|
142
|
+
scrollInput.amount = scrollAmount;
|
|
143
|
+
return this.runtime.scroll(scrollInput);
|
|
144
|
+
}
|
|
145
|
+
default:
|
|
146
|
+
throw new Error(`Unsupported tool: ${String(request.tool)}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function parseTarget(input) {
|
|
151
|
+
if (typeof input === "string") {
|
|
152
|
+
if (input.startsWith("css=")) {
|
|
153
|
+
return { type: "selector", value: input.slice(4) };
|
|
154
|
+
}
|
|
155
|
+
if (input.startsWith("text=")) {
|
|
156
|
+
return { type: "text", value: input.slice(5), exact: true };
|
|
157
|
+
}
|
|
158
|
+
if (input.startsWith("ax_id=")) {
|
|
159
|
+
return { type: "ax_attribute", attribute: "identifier", value: input.slice(6) };
|
|
160
|
+
}
|
|
161
|
+
return { type: "text", value: input };
|
|
162
|
+
}
|
|
163
|
+
if (!isRecord(input)) {
|
|
164
|
+
throw new Error("target must be a string or object");
|
|
165
|
+
}
|
|
166
|
+
if (typeof input.selector === "string") {
|
|
167
|
+
return { type: "selector", value: input.selector };
|
|
168
|
+
}
|
|
169
|
+
if (typeof input.text === "string") {
|
|
170
|
+
return {
|
|
171
|
+
type: "text",
|
|
172
|
+
value: input.text,
|
|
173
|
+
exact: input.exact === true,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
if (typeof input.role === "string" && typeof input.name === "string") {
|
|
177
|
+
return {
|
|
178
|
+
type: "role",
|
|
179
|
+
role: input.role,
|
|
180
|
+
name: input.name,
|
|
181
|
+
exact: input.exact === true,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(input.path)) {
|
|
185
|
+
return { type: "ax_path", path: input.path };
|
|
186
|
+
}
|
|
187
|
+
if (typeof input.attribute === "string" && typeof input.value === "string") {
|
|
188
|
+
return { type: "ax_attribute", attribute: input.attribute, value: input.value };
|
|
189
|
+
}
|
|
190
|
+
if (typeof input.x === "number" && typeof input.y === "number") {
|
|
191
|
+
return { type: "coordinates", x: input.x, y: input.y };
|
|
192
|
+
}
|
|
193
|
+
if (typeof input.base64 === "string") {
|
|
194
|
+
const target = { type: "image", base64: input.base64 };
|
|
195
|
+
if (typeof input.confidence === "number") {
|
|
196
|
+
target.confidence = input.confidence;
|
|
197
|
+
}
|
|
198
|
+
return target;
|
|
199
|
+
}
|
|
200
|
+
throw new Error("target object must contain selector, text, role+name, path, attribute+value, x+y, or base64");
|
|
201
|
+
}
|
|
202
|
+
function parseWaitCondition(input) {
|
|
203
|
+
if (!isRecord(input) || typeof input.type !== "string") {
|
|
204
|
+
throw new Error("condition must be an object with a type");
|
|
205
|
+
}
|
|
206
|
+
switch (input.type) {
|
|
207
|
+
case "selector_visible":
|
|
208
|
+
return {
|
|
209
|
+
type: "selector_visible",
|
|
210
|
+
selector: requiredObjectString(input, "selector"),
|
|
211
|
+
};
|
|
212
|
+
case "selector_hidden":
|
|
213
|
+
return {
|
|
214
|
+
type: "selector_hidden",
|
|
215
|
+
selector: requiredObjectString(input, "selector"),
|
|
216
|
+
};
|
|
217
|
+
case "url_matches":
|
|
218
|
+
return {
|
|
219
|
+
type: "url_matches",
|
|
220
|
+
regex: requiredObjectString(input, "regex"),
|
|
221
|
+
};
|
|
222
|
+
case "text_appears":
|
|
223
|
+
return {
|
|
224
|
+
type: "text_appears",
|
|
225
|
+
text: requiredObjectString(input, "text"),
|
|
226
|
+
};
|
|
227
|
+
case "spinner_disappears":
|
|
228
|
+
return {
|
|
229
|
+
type: "spinner_disappears",
|
|
230
|
+
selector: requiredObjectString(input, "selector"),
|
|
231
|
+
};
|
|
232
|
+
case "element_exists":
|
|
233
|
+
return {
|
|
234
|
+
type: "element_exists",
|
|
235
|
+
target: parseTarget(input.target),
|
|
236
|
+
};
|
|
237
|
+
case "element_gone":
|
|
238
|
+
return {
|
|
239
|
+
type: "element_gone",
|
|
240
|
+
target: parseTarget(input.target),
|
|
241
|
+
};
|
|
242
|
+
case "window_title_matches":
|
|
243
|
+
return {
|
|
244
|
+
type: "window_title_matches",
|
|
245
|
+
regex: requiredObjectString(input, "regex"),
|
|
246
|
+
};
|
|
247
|
+
case "app_idle": {
|
|
248
|
+
const cond = {
|
|
249
|
+
type: "app_idle",
|
|
250
|
+
bundleId: requiredObjectString(input, "bundleId"),
|
|
251
|
+
};
|
|
252
|
+
if (typeof input.timeoutMs === "number") {
|
|
253
|
+
cond.timeoutMs = input.timeoutMs;
|
|
254
|
+
}
|
|
255
|
+
return cond;
|
|
256
|
+
}
|
|
257
|
+
default:
|
|
258
|
+
throw new Error(`Unsupported condition type: ${input.type}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function parseOptionalWaitCondition(input) {
|
|
262
|
+
if (typeof input === "undefined") {
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
return parseWaitCondition(input);
|
|
266
|
+
}
|
|
267
|
+
function parseExtractFormat(input) {
|
|
268
|
+
if (input === "text" || input === "table" || input === "json") {
|
|
269
|
+
return input;
|
|
270
|
+
}
|
|
271
|
+
throw new Error("format must be one of: text, table, json");
|
|
272
|
+
}
|
|
273
|
+
function parseOptionalRegion(input) {
|
|
274
|
+
if (typeof input === "undefined") {
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
if (!isRecord(input)) {
|
|
278
|
+
throw new Error("region must be an object");
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
x: requiredObjectNumber(input, "x"),
|
|
282
|
+
y: requiredObjectNumber(input, "y"),
|
|
283
|
+
width: requiredObjectNumber(input, "width"),
|
|
284
|
+
height: requiredObjectNumber(input, "height"),
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function requiredString(input, key) {
|
|
288
|
+
const value = input[key];
|
|
289
|
+
if (typeof value !== "string") {
|
|
290
|
+
throw new Error(`${key} must be a string`);
|
|
291
|
+
}
|
|
292
|
+
return value;
|
|
293
|
+
}
|
|
294
|
+
function requiredStringArray(input, key) {
|
|
295
|
+
const value = input[key];
|
|
296
|
+
if (!Array.isArray(value) || !value.every((v) => typeof v === "string")) {
|
|
297
|
+
throw new Error(`${key} must be an array of strings`);
|
|
298
|
+
}
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
function optionalString(input, key) {
|
|
302
|
+
const value = input[key];
|
|
303
|
+
if (typeof value === "undefined") {
|
|
304
|
+
return undefined;
|
|
305
|
+
}
|
|
306
|
+
if (typeof value !== "string") {
|
|
307
|
+
throw new Error(`${key} must be a string`);
|
|
308
|
+
}
|
|
309
|
+
return value;
|
|
310
|
+
}
|
|
311
|
+
function optionalNumber(input, key) {
|
|
312
|
+
const value = input[key];
|
|
313
|
+
if (typeof value === "undefined") {
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
if (typeof value !== "number") {
|
|
317
|
+
throw new Error(`${key} must be a number`);
|
|
318
|
+
}
|
|
319
|
+
return value;
|
|
320
|
+
}
|
|
321
|
+
function optionalBoolean(input, key) {
|
|
322
|
+
const value = input[key];
|
|
323
|
+
if (typeof value === "undefined") {
|
|
324
|
+
return undefined;
|
|
325
|
+
}
|
|
326
|
+
if (typeof value !== "boolean") {
|
|
327
|
+
throw new Error(`${key} must be a boolean`);
|
|
328
|
+
}
|
|
329
|
+
return value;
|
|
330
|
+
}
|
|
331
|
+
function requiredObjectString(input, key) {
|
|
332
|
+
const value = input[key];
|
|
333
|
+
if (typeof value !== "string") {
|
|
334
|
+
throw new Error(`${key} must be a string`);
|
|
335
|
+
}
|
|
336
|
+
return value;
|
|
337
|
+
}
|
|
338
|
+
function requiredObjectNumber(input, key) {
|
|
339
|
+
const value = input[key];
|
|
340
|
+
if (typeof value !== "number") {
|
|
341
|
+
throw new Error(`${key} must be a number`);
|
|
342
|
+
}
|
|
343
|
+
return value;
|
|
344
|
+
}
|
|
345
|
+
function isRecord(input) {
|
|
346
|
+
return typeof input === "object" && input !== null;
|
|
347
|
+
}
|