@bctrl/sdk 1.0.1

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.
Files changed (260) hide show
  1. package/README.md +75 -0
  2. package/dist/agents/browser-use/index.d.ts +1 -0
  3. package/dist/agents/browser-use/index.js +9 -0
  4. package/dist/agents/browser-use/namespace.d.ts +39 -0
  5. package/dist/agents/browser-use/namespace.js +93 -0
  6. package/dist/agents/index.d.ts +2 -0
  7. package/dist/agents/index.js +17 -0
  8. package/dist/agents/stagehand/core.d.ts +93 -0
  9. package/dist/agents/stagehand/core.js +144 -0
  10. package/dist/agents/stagehand/index.d.ts +3 -0
  11. package/dist/agents/stagehand/index.js +24 -0
  12. package/dist/agents/stagehand/namespace.d.ts +51 -0
  13. package/dist/agents/stagehand/namespace.js +65 -0
  14. package/dist/ai-credentials/client.d.ts +12 -0
  15. package/dist/ai-credentials/client.js +70 -0
  16. package/dist/ai-credentials/index.d.ts +1 -0
  17. package/dist/ai-credentials/index.js +1 -0
  18. package/dist/base/event-binding.d.ts +7 -0
  19. package/dist/base/event-binding.js +23 -0
  20. package/dist/base/types.d.ts +109 -0
  21. package/dist/base/types.js +4 -0
  22. package/dist/bctrl.d.ts +37 -0
  23. package/dist/bctrl.js +77 -0
  24. package/dist/browser-extensions/client.d.ts +15 -0
  25. package/dist/browser-extensions/client.js +72 -0
  26. package/dist/browser-extensions/index.d.ts +2 -0
  27. package/dist/browser-extensions/index.js +1 -0
  28. package/dist/browser-profiles/client.d.ts +11 -0
  29. package/dist/browser-profiles/client.js +63 -0
  30. package/dist/browser-profiles/index.d.ts +1 -0
  31. package/dist/browser-profiles/index.js +1 -0
  32. package/dist/captcha/index.d.ts +1 -0
  33. package/dist/captcha/index.js +1 -0
  34. package/dist/captcha/namespace.d.ts +34 -0
  35. package/dist/captcha/namespace.js +41 -0
  36. package/dist/client/index.d.ts +1 -0
  37. package/dist/client/index.js +1 -0
  38. package/dist/client/rpc.d.ts +83 -0
  39. package/dist/client/rpc.js +354 -0
  40. package/dist/config.d.ts +5 -0
  41. package/dist/config.js +28 -0
  42. package/dist/constants/browser.d.ts +2 -0
  43. package/dist/constants/browser.js +1 -0
  44. package/dist/contracts/agent-tools.d.ts +45 -0
  45. package/dist/contracts/agent-tools.js +31 -0
  46. package/dist/contracts/automation.d.ts +265 -0
  47. package/dist/contracts/automation.js +109 -0
  48. package/dist/contracts/browser-management.d.ts +179 -0
  49. package/dist/contracts/browser-management.js +95 -0
  50. package/dist/contracts/browser-use.d.ts +136 -0
  51. package/dist/contracts/browser-use.js +93 -0
  52. package/dist/contracts/captcha.d.ts +114 -0
  53. package/dist/contracts/captcha.js +40 -0
  54. package/dist/contracts/desktop.d.ts +223 -0
  55. package/dist/contracts/desktop.js +121 -0
  56. package/dist/contracts/drivers/playwright.d.ts +2008 -0
  57. package/dist/contracts/drivers/playwright.js +2033 -0
  58. package/dist/contracts/drivers/puppeteer.d.ts +1221 -0
  59. package/dist/contracts/drivers/puppeteer.js +941 -0
  60. package/dist/contracts/drivers/selenium.d.ts +156 -0
  61. package/dist/contracts/drivers/selenium.js +61 -0
  62. package/dist/contracts/drivers/stagehand.d.ts +155 -0
  63. package/dist/contracts/drivers/stagehand.js +7 -0
  64. package/dist/contracts/extensions.d.ts +13 -0
  65. package/dist/contracts/extensions.js +9 -0
  66. package/dist/contracts/index.d.ts +13 -0
  67. package/dist/contracts/index.js +13 -0
  68. package/dist/contracts/public-api.d.ts +360 -0
  69. package/dist/contracts/public-api.js +17 -0
  70. package/dist/contracts/runtime.d.ts +81 -0
  71. package/dist/contracts/runtime.js +16 -0
  72. package/dist/contracts/stagehand.d.ts +253 -0
  73. package/dist/contracts/stagehand.js +145 -0
  74. package/dist/contracts/storage.d.ts +51 -0
  75. package/dist/contracts/storage.js +56 -0
  76. package/dist/contracts/vault.d.ts +119 -0
  77. package/dist/contracts/vault.js +112 -0
  78. package/dist/contracts/version.d.ts +3 -0
  79. package/dist/contracts/version.js +16 -0
  80. package/dist/desktop.d.ts +2 -0
  81. package/dist/desktop.js +3 -0
  82. package/dist/drivers/desktop/index.d.ts +65 -0
  83. package/dist/drivers/desktop/index.js +68 -0
  84. package/dist/drivers/desktop/session.d.ts +313 -0
  85. package/dist/drivers/desktop/session.js +432 -0
  86. package/dist/drivers/playwright/event-emitter.d.ts +160 -0
  87. package/dist/drivers/playwright/event-emitter.js +297 -0
  88. package/dist/drivers/playwright/generated/api-request-context.d.ts +137 -0
  89. package/dist/drivers/playwright/generated/api-request-context.js +154 -0
  90. package/dist/drivers/playwright/generated/api-response.d.ts +119 -0
  91. package/dist/drivers/playwright/generated/api-response.js +123 -0
  92. package/dist/drivers/playwright/generated/browser-context.d.ts +284 -0
  93. package/dist/drivers/playwright/generated/browser-context.js +458 -0
  94. package/dist/drivers/playwright/generated/browser.d.ts +120 -0
  95. package/dist/drivers/playwright/generated/browser.js +151 -0
  96. package/dist/drivers/playwright/generated/clock.d.ts +80 -0
  97. package/dist/drivers/playwright/generated/clock.js +94 -0
  98. package/dist/drivers/playwright/generated/console-message.d.ts +94 -0
  99. package/dist/drivers/playwright/generated/console-message.js +89 -0
  100. package/dist/drivers/playwright/generated/coverage.d.ts +57 -0
  101. package/dist/drivers/playwright/generated/coverage.js +66 -0
  102. package/dist/drivers/playwright/generated/dialog.d.ts +79 -0
  103. package/dist/drivers/playwright/generated/dialog.js +80 -0
  104. package/dist/drivers/playwright/generated/element-handle.d.ts +399 -0
  105. package/dist/drivers/playwright/generated/element-handle.js +501 -0
  106. package/dist/drivers/playwright/generated/frame-locator.d.ts +34 -0
  107. package/dist/drivers/playwright/generated/frame-locator.js +63 -0
  108. package/dist/drivers/playwright/generated/frame.d.ts +557 -0
  109. package/dist/drivers/playwright/generated/frame.js +634 -0
  110. package/dist/drivers/playwright/generated/js-handle.d.ts +72 -0
  111. package/dist/drivers/playwright/generated/js-handle.js +92 -0
  112. package/dist/drivers/playwright/generated/keyboard.d.ts +103 -0
  113. package/dist/drivers/playwright/generated/keyboard.js +113 -0
  114. package/dist/drivers/playwright/generated/locator.d.ts +795 -0
  115. package/dist/drivers/playwright/generated/locator.js +974 -0
  116. package/dist/drivers/playwright/generated/mouse.d.ts +97 -0
  117. package/dist/drivers/playwright/generated/mouse.js +109 -0
  118. package/dist/drivers/playwright/generated/page.d.ts +762 -0
  119. package/dist/drivers/playwright/generated/page.js +988 -0
  120. package/dist/drivers/playwright/generated/touchscreen.d.ts +34 -0
  121. package/dist/drivers/playwright/generated/touchscreen.js +37 -0
  122. package/dist/drivers/playwright/generated/tracing.d.ts +78 -0
  123. package/dist/drivers/playwright/generated/tracing.js +80 -0
  124. package/dist/drivers/playwright/generated/worker.d.ts +53 -0
  125. package/dist/drivers/playwright/generated/worker.js +59 -0
  126. package/dist/drivers/playwright/index.d.ts +19 -0
  127. package/dist/drivers/playwright/index.js +20 -0
  128. package/dist/drivers/playwright/remote-base.d.ts +62 -0
  129. package/dist/drivers/playwright/remote-base.js +86 -0
  130. package/dist/drivers/playwright/types.d.ts +148 -0
  131. package/dist/drivers/playwright/types.js +8 -0
  132. package/dist/drivers/puppeteer/errors.d.ts +50 -0
  133. package/dist/drivers/puppeteer/errors.js +71 -0
  134. package/dist/drivers/puppeteer/event-emitter.d.ts +145 -0
  135. package/dist/drivers/puppeteer/event-emitter.js +259 -0
  136. package/dist/drivers/puppeteer/generated/accessibility.d.ts +77 -0
  137. package/dist/drivers/puppeteer/generated/accessibility.js +74 -0
  138. package/dist/drivers/puppeteer/generated/browser-context.d.ts +116 -0
  139. package/dist/drivers/puppeteer/generated/browser-context.js +168 -0
  140. package/dist/drivers/puppeteer/generated/browser.d.ts +169 -0
  141. package/dist/drivers/puppeteer/generated/browser.js +246 -0
  142. package/dist/drivers/puppeteer/generated/console-message.d.ts +54 -0
  143. package/dist/drivers/puppeteer/generated/console-message.js +69 -0
  144. package/dist/drivers/puppeteer/generated/coverage.d.ts +49 -0
  145. package/dist/drivers/puppeteer/generated/coverage.js +57 -0
  146. package/dist/drivers/puppeteer/generated/dialog.d.ts +46 -0
  147. package/dist/drivers/puppeteer/generated/dialog.js +60 -0
  148. package/dist/drivers/puppeteer/generated/element-handle.d.ts +261 -0
  149. package/dist/drivers/puppeteer/generated/element-handle.js +341 -0
  150. package/dist/drivers/puppeteer/generated/file-chooser.d.ts +34 -0
  151. package/dist/drivers/puppeteer/generated/file-chooser.js +43 -0
  152. package/dist/drivers/puppeteer/generated/frame.d.ts +221 -0
  153. package/dist/drivers/puppeteer/generated/frame.js +302 -0
  154. package/dist/drivers/puppeteer/generated/http-request.d.ts +195 -0
  155. package/dist/drivers/puppeteer/generated/http-request.js +243 -0
  156. package/dist/drivers/puppeteer/generated/http-response.d.ts +142 -0
  157. package/dist/drivers/puppeteer/generated/http-response.js +169 -0
  158. package/dist/drivers/puppeteer/generated/js-handle.d.ts +104 -0
  159. package/dist/drivers/puppeteer/generated/js-handle.js +125 -0
  160. package/dist/drivers/puppeteer/generated/keyboard.d.ts +79 -0
  161. package/dist/drivers/puppeteer/generated/keyboard.js +89 -0
  162. package/dist/drivers/puppeteer/generated/locator.d.ts +141 -0
  163. package/dist/drivers/puppeteer/generated/locator.js +164 -0
  164. package/dist/drivers/puppeteer/generated/mouse.d.ts +74 -0
  165. package/dist/drivers/puppeteer/generated/mouse.js +94 -0
  166. package/dist/drivers/puppeteer/generated/page.d.ts +604 -0
  167. package/dist/drivers/puppeteer/generated/page.js +776 -0
  168. package/dist/drivers/puppeteer/generated/target.d.ts +105 -0
  169. package/dist/drivers/puppeteer/generated/target.js +123 -0
  170. package/dist/drivers/puppeteer/generated/touchscreen.d.ts +87 -0
  171. package/dist/drivers/puppeteer/generated/touchscreen.js +103 -0
  172. package/dist/drivers/puppeteer/generated/tracing.d.ts +38 -0
  173. package/dist/drivers/puppeteer/generated/tracing.js +43 -0
  174. package/dist/drivers/puppeteer/generated/web-worker.d.ts +63 -0
  175. package/dist/drivers/puppeteer/generated/web-worker.js +73 -0
  176. package/dist/drivers/puppeteer/index.d.ts +21 -0
  177. package/dist/drivers/puppeteer/index.js +23 -0
  178. package/dist/drivers/puppeteer/remote-base.d.ts +57 -0
  179. package/dist/drivers/puppeteer/remote-base.js +79 -0
  180. package/dist/drivers/puppeteer/types.d.ts +178 -0
  181. package/dist/drivers/puppeteer/types.js +8 -0
  182. package/dist/drivers/selenium/driver.d.ts +28 -0
  183. package/dist/drivers/selenium/driver.js +169 -0
  184. package/dist/drivers/selenium/element.d.ts +34 -0
  185. package/dist/drivers/selenium/element.js +73 -0
  186. package/dist/drivers/selenium/index.d.ts +3 -0
  187. package/dist/drivers/selenium/index.js +5 -0
  188. package/dist/drivers/selenium/types.d.ts +2 -0
  189. package/dist/drivers/selenium/types.js +12 -0
  190. package/dist/drivers/stagehand/generated/context.d.ts +127 -0
  191. package/dist/drivers/stagehand/generated/context.js +153 -0
  192. package/dist/drivers/stagehand/generated/locator.d.ts +324 -0
  193. package/dist/drivers/stagehand/generated/locator.js +368 -0
  194. package/dist/drivers/stagehand/generated/page.d.ts +377 -0
  195. package/dist/drivers/stagehand/generated/page.js +439 -0
  196. package/dist/drivers/stagehand/generated/response.d.ts +197 -0
  197. package/dist/drivers/stagehand/generated/response.js +232 -0
  198. package/dist/drivers/stagehand/index.d.ts +5 -0
  199. package/dist/drivers/stagehand/index.js +8 -0
  200. package/dist/drivers/stagehand/types.d.ts +1 -0
  201. package/dist/drivers/stagehand/types.js +7 -0
  202. package/dist/errors.d.ts +47 -0
  203. package/dist/errors.js +157 -0
  204. package/dist/extensions/client.d.ts +47 -0
  205. package/dist/extensions/client.js +154 -0
  206. package/dist/extensions/index.d.ts +1 -0
  207. package/dist/extensions/index.js +1 -0
  208. package/dist/index.d.ts +12 -0
  209. package/dist/index.js +23 -0
  210. package/dist/internal/dev-client.d.ts +5 -0
  211. package/dist/internal/dev-client.js +9 -0
  212. package/dist/internal/rpc-targets.d.ts +17 -0
  213. package/dist/internal/rpc-targets.js +58 -0
  214. package/dist/internal/serialization.d.ts +32 -0
  215. package/dist/internal/serialization.js +42 -0
  216. package/dist/internal/transport.d.ts +24 -0
  217. package/dist/internal/transport.js +29 -0
  218. package/dist/playwright.d.ts +1 -0
  219. package/dist/playwright.js +2 -0
  220. package/dist/puppeteer.d.ts +1 -0
  221. package/dist/puppeteer.js +2 -0
  222. package/dist/selenium.d.ts +1 -0
  223. package/dist/selenium.js +2 -0
  224. package/dist/stagehand.d.ts +1 -0
  225. package/dist/stagehand.js +2 -0
  226. package/dist/storage/client.d.ts +151 -0
  227. package/dist/storage/client.js +329 -0
  228. package/dist/storage/index.d.ts +2 -0
  229. package/dist/storage/index.js +4 -0
  230. package/dist/telemetry.d.ts +18 -0
  231. package/dist/telemetry.js +93 -0
  232. package/dist/updates/client.d.ts +8 -0
  233. package/dist/updates/client.js +128 -0
  234. package/dist/updates/index.d.ts +1 -0
  235. package/dist/updates/index.js +1 -0
  236. package/dist/utils/http.d.ts +39 -0
  237. package/dist/utils/http.js +88 -0
  238. package/dist/utils/index.d.ts +4 -0
  239. package/dist/utils/index.js +4 -0
  240. package/dist/utils/logger.d.ts +27 -0
  241. package/dist/utils/logger.js +74 -0
  242. package/dist/utils/schema.d.ts +17 -0
  243. package/dist/utils/schema.js +31 -0
  244. package/dist/utils/url.d.ts +5 -0
  245. package/dist/utils/url.js +7 -0
  246. package/dist/vault/client.d.ts +43 -0
  247. package/dist/vault/client.js +123 -0
  248. package/dist/vault/index.d.ts +1 -0
  249. package/dist/vault/index.js +1 -0
  250. package/dist/version.d.ts +1 -0
  251. package/dist/version.js +4 -0
  252. package/dist/workspaces/browser-runtime.d.ts +251 -0
  253. package/dist/workspaces/browser-runtime.js +1025 -0
  254. package/dist/workspaces/client.d.ts +48 -0
  255. package/dist/workspaces/client.js +222 -0
  256. package/dist/workspaces/index.d.ts +2 -0
  257. package/dist/workspaces/index.js +2 -0
  258. package/dist/workspaces/runtime-event-pump.d.ts +65 -0
  259. package/dist/workspaces/runtime-event-pump.js +716 -0
  260. package/package.json +56 -0
@@ -0,0 +1,112 @@
1
+ import { z } from 'zod';
2
+ export const VaultSessionPolicySchema = z.object({
3
+ allow: z.array(z.string().min(1)).optional(),
4
+ deny: z.array(z.string().min(1)).optional(),
5
+ allowRawReads: z.boolean().optional(),
6
+ });
7
+ export const VaultAgentDefaultListFilterSchema = z.object({
8
+ prefix: z.string().min(1).optional(),
9
+ origin: z.string().min(1).optional(),
10
+ limit: z.number().int().positive().optional(),
11
+ });
12
+ export const VaultAgentAdapterConfigSchema = z.object({
13
+ toolPrefix: z.string().min(1).optional(),
14
+ defaultListFilter: VaultAgentDefaultListFilterSchema.optional(),
15
+ allowRawReads: z.boolean().optional(),
16
+ });
17
+ function dedupeStrings(values) {
18
+ if (!values || values.length === 0)
19
+ return undefined;
20
+ const seen = new Set();
21
+ const out = [];
22
+ for (const value of values) {
23
+ if (seen.has(value))
24
+ continue;
25
+ seen.add(value);
26
+ out.push(value);
27
+ }
28
+ return out.length > 0 ? out : undefined;
29
+ }
30
+ function splitMatchOrigins(matchOrigins) {
31
+ if (!matchOrigins || matchOrigins.length === 0)
32
+ return {};
33
+ const origins = [];
34
+ const originPatterns = [];
35
+ for (const entry of matchOrigins) {
36
+ if (entry.includes('*')) {
37
+ originPatterns.push(entry);
38
+ }
39
+ else {
40
+ origins.push(entry);
41
+ }
42
+ }
43
+ return {
44
+ ...(origins.length > 0 ? { origins } : {}),
45
+ ...(originPatterns.length > 0 ? { originPatterns } : {}),
46
+ };
47
+ }
48
+ export const VaultCredentialSchema = z.object({
49
+ label: z.string().optional(),
50
+ origins: z.array(z.string().min(1)).optional(),
51
+ originPatterns: z.array(z.string().min(1)).optional(),
52
+ username: z.string(),
53
+ password: z.string(),
54
+ totp: z.string().optional(),
55
+ notes: z.string().optional(),
56
+ });
57
+ const VaultCredentialInputRawSchema = z.object({
58
+ label: z.string().optional(),
59
+ origins: z.array(z.string().min(1)).optional(),
60
+ originPatterns: z.array(z.string().min(1)).optional(),
61
+ matchOrigins: z.array(z.string().min(1)).optional(),
62
+ username: z.string(),
63
+ password: z.string(),
64
+ totp: z.string().optional(),
65
+ notes: z.string().optional(),
66
+ });
67
+ export const VaultCredentialInputSchema = VaultCredentialInputRawSchema.transform((input) => {
68
+ const split = splitMatchOrigins(input.matchOrigins);
69
+ const mergedOrigins = dedupeStrings([...(input.origins ?? []), ...(split.origins ?? [])]);
70
+ const mergedOriginPatterns = dedupeStrings([
71
+ ...(input.originPatterns ?? []),
72
+ ...(split.originPatterns ?? []),
73
+ ]);
74
+ return {
75
+ ...(input.label !== undefined ? { label: input.label } : {}),
76
+ ...(mergedOrigins ? { origins: mergedOrigins } : {}),
77
+ ...(mergedOriginPatterns ? { originPatterns: mergedOriginPatterns } : {}),
78
+ username: input.username,
79
+ password: input.password,
80
+ ...(input.totp !== undefined ? { totp: input.totp } : {}),
81
+ ...(input.notes !== undefined ? { notes: input.notes } : {}),
82
+ };
83
+ });
84
+ export const VaultKeySchema = z
85
+ .string()
86
+ .min(1)
87
+ .max(256)
88
+ .regex(/^[\w@.-]+(\/[\w@.-]+)*$/, 'Vault key must be alphanumeric segments (allowing @, ., -, _) separated by slashes')
89
+ .refine((key) => !key.split('/').some((segment) => segment === '..' || segment === '.'), 'Vault key must not contain "." or ".." segments');
90
+ export const VaultCredentialSourceSchema = z.enum(['native', '1password']);
91
+ export const VaultCredentialMetaSchema = z.object({
92
+ key: z.string(),
93
+ label: z.string().optional(),
94
+ origins: z.array(z.string()).optional(),
95
+ originPatterns: z.array(z.string()).optional(),
96
+ hasTotp: z.boolean(),
97
+ source: VaultCredentialSourceSchema,
98
+ sourceDisplayName: z.string().optional(),
99
+ });
100
+ export const VaultListMetaOptionsSchema = z.object({
101
+ meta: z.literal(true),
102
+ prefix: z.string().optional(),
103
+ origin: z.string().optional(),
104
+ hasTotp: z.boolean().optional(),
105
+ limit: z.number().int().positive().optional(),
106
+ });
107
+ export const VaultListResultSchema = z.object({
108
+ keys: z.array(z.string()),
109
+ });
110
+ export const VaultListMetaResultSchema = z.object({
111
+ items: z.array(VaultCredentialMetaSchema),
112
+ });
@@ -0,0 +1,3 @@
1
+ export declare const PUBLIC_API_VERSION: "v1";
2
+ export declare const PUBLIC_API_PREFIX: "/v1";
3
+ export declare function withPublicApiPrefix(path: string): string;
@@ -0,0 +1,16 @@
1
+ export const PUBLIC_API_VERSION = 'v1';
2
+ export const PUBLIC_API_PREFIX = `/${PUBLIC_API_VERSION}`;
3
+ export function withPublicApiPrefix(path) {
4
+ if (typeof path !== 'string' || path.trim() === '') {
5
+ throw new Error('Public API path must be a non-empty string');
6
+ }
7
+ const normalizedPath = path.trim();
8
+ if (!normalizedPath.startsWith('/')) {
9
+ throw new Error(`Public API path must start with '/': ${normalizedPath}`);
10
+ }
11
+ if (normalizedPath === PUBLIC_API_PREFIX ||
12
+ normalizedPath.startsWith(`${PUBLIC_API_PREFIX}/`)) {
13
+ return normalizedPath;
14
+ }
15
+ return normalizedPath === '/' ? PUBLIC_API_PREFIX : `${PUBLIC_API_PREFIX}${normalizedPath}`;
16
+ }
@@ -0,0 +1,2 @@
1
+ export { default } from './drivers/desktop/index.js';
2
+ export * from './drivers/desktop/index.js';
@@ -0,0 +1,3 @@
1
+ // Desktop driver entrypoint.
2
+ export { default } from './drivers/desktop/index.js';
3
+ export * from './drivers/desktop/index.js';
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Desktop Driver - SDK for desktop automation
3
+ *
4
+ * Provides mouse, keyboard, screen, and window control via the desktop agent.
5
+ */
6
+ import { DesktopSession } from './session.js';
7
+ type InternalBctrlEnvironment = 'production' | 'development';
8
+ export { DesktopSession, DesktopMouse, DesktopKeyboard, DesktopScreen, DesktopWindow, DesktopClipboard, DesktopCua, } from './session.js';
9
+ export type { WindowInfo, Bounds, Point, Size, BrowserLaunchResult } from './session.js';
10
+ export type { CuaAgentConfig, CuaRunOptions, CuaRunResult, CuaPredictClickResult, CuaAction, } from '../../contracts/desktop.js';
11
+ export interface DesktopConnectOptions {
12
+ /** API key for authentication */
13
+ apiKey: string;
14
+ /**
15
+ * Target environment.
16
+ * Defaults to `production` (`https://api.bctrl.ai`).
17
+ * Use `development` for a local gateway on `http://localhost:8787`.
18
+ */
19
+ environment?: InternalBctrlEnvironment;
20
+ /**
21
+ * Gateway origin or API base URL.
22
+ * If you pass an origin, the SDK appends `/v1` automatically.
23
+ */
24
+ baseUrl?: string;
25
+ }
26
+ export declare const desktop: {
27
+ /**
28
+ * Connect to the desktop agent.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { desktop } from '@bctrl/sdk/desktop';
33
+ *
34
+ * const session = await desktop.connect({ apiKey: process.env.BCTRL_API_KEY! });
35
+ *
36
+ * // Mouse control
37
+ * await session.mouse.move(100, 200);
38
+ * await session.mouse.click();
39
+ *
40
+ * // Keyboard control
41
+ * await session.keyboard.type('Hello, World!');
42
+ * await session.keyboard.hotkey('Ctrl', 'C');
43
+ *
44
+ * // Screen capture
45
+ * const screenshot = await session.screen.capture();
46
+ *
47
+ * // Window management
48
+ * const windows = await session.window.list();
49
+ * await session.window.focus(windows[0].handle);
50
+ *
51
+ * // Launch browser for DOM control
52
+ * const browser = await session.launchBrowser();
53
+ * // Use browser.sessionId, browser.defaultContextId, browser.defaultPageId
54
+ *
55
+ * // CUA (Computer Use Agent) - AI-powered automation
56
+ * await session.cua.init();
57
+ * const result = await session.cua.run('Open Chrome and navigate to google.com');
58
+ * const { x, y } = await session.cua.predictClick('the search box');
59
+ * await session.mouse.move(x, y);
60
+ * await session.mouse.click();
61
+ * ```
62
+ */
63
+ connect(options: DesktopConnectOptions): Promise<DesktopSession>;
64
+ };
65
+ export default desktop;
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Desktop Driver - SDK for desktop automation
3
+ *
4
+ * Provides mouse, keyboard, screen, and window control via the desktop agent.
5
+ */
6
+ import { DesktopSession } from './session.js';
7
+ import { fetchWithTimeout, parseJsonResponse, DEFAULT_TIMEOUT_MS } from '../../utils/http.js';
8
+ import { BCTRL_DEVELOPMENT_ORIGIN, resolveApiKey, resolveInternalApiBaseUrl, } from '../../config.js';
9
+ // Export session and namespace classes
10
+ export { DesktopSession, DesktopMouse, DesktopKeyboard, DesktopScreen, DesktopWindow, DesktopClipboard, DesktopCua, } from './session.js';
11
+ export const desktop = {
12
+ /**
13
+ * Connect to the desktop agent.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { desktop } from '@bctrl/sdk/desktop';
18
+ *
19
+ * const session = await desktop.connect({ apiKey: process.env.BCTRL_API_KEY! });
20
+ *
21
+ * // Mouse control
22
+ * await session.mouse.move(100, 200);
23
+ * await session.mouse.click();
24
+ *
25
+ * // Keyboard control
26
+ * await session.keyboard.type('Hello, World!');
27
+ * await session.keyboard.hotkey('Ctrl', 'C');
28
+ *
29
+ * // Screen capture
30
+ * const screenshot = await session.screen.capture();
31
+ *
32
+ * // Window management
33
+ * const windows = await session.window.list();
34
+ * await session.window.focus(windows[0].handle);
35
+ *
36
+ * // Launch browser for DOM control
37
+ * const browser = await session.launchBrowser();
38
+ * // Use browser.sessionId, browser.defaultContextId, browser.defaultPageId
39
+ *
40
+ * // CUA (Computer Use Agent) - AI-powered automation
41
+ * await session.cua.init();
42
+ * const result = await session.cua.run('Open Chrome and navigate to google.com');
43
+ * const { x, y } = await session.cua.predictClick('the search box');
44
+ * await session.mouse.move(x, y);
45
+ * await session.mouse.click();
46
+ * ```
47
+ */
48
+ async connect(options) {
49
+ const apiKey = resolveApiKey(options.apiKey);
50
+ const baseUrl = resolveInternalApiBaseUrl(options.baseUrl ?? (options.environment === 'development' ? BCTRL_DEVELOPMENT_ORIGIN : undefined));
51
+ const headers = {
52
+ 'Content-Type': 'application/json',
53
+ Authorization: `Bearer ${apiKey}`,
54
+ };
55
+ const response = await fetchWithTimeout(`${baseUrl}/desktop/sessions`, {
56
+ method: 'POST',
57
+ headers,
58
+ body: JSON.stringify({}),
59
+ }, DEFAULT_TIMEOUT_MS);
60
+ if (!response.ok) {
61
+ const text = await response.text();
62
+ throw new Error(`Failed to create desktop session: ${text}`);
63
+ }
64
+ const data = await parseJsonResponse(response, 'Create desktop session');
65
+ return new DesktopSession(data.id, baseUrl, { apiKey });
66
+ },
67
+ };
68
+ export default desktop;
@@ -0,0 +1,313 @@
1
+ /**
2
+ * DesktopSession - SDK client for desktop automation
3
+ *
4
+ * Provides namespaced APIs for mouse, keyboard, screen, and window control.
5
+ * Can also launch browsers for DOM-level control via Playwright.
6
+ */
7
+ import type { WindowInfo, Bounds, Point, Size, CuaAgentConfig, CuaRunOptions, CuaRunResult, CuaPredictClickResult, BrowserLaunchResult } from '../../contracts/desktop.js';
8
+ export type { WindowInfo, Bounds, Point, Size, BrowserLaunchResult };
9
+ export declare class DesktopSession {
10
+ readonly id: string;
11
+ readonly baseUrl: string;
12
+ private readonly apiKey?;
13
+ private _mouse;
14
+ private _keyboard;
15
+ private _screen;
16
+ private _window;
17
+ private _clipboard;
18
+ private _cua;
19
+ constructor(sessionId: string, baseUrl: string, options?: {
20
+ apiKey?: string;
21
+ });
22
+ /** Mouse control (move, click, drag, scroll) */
23
+ get mouse(): DesktopMouse;
24
+ /** Keyboard control (type, press, hotkey) */
25
+ get keyboard(): DesktopKeyboard;
26
+ /** Screen capture and display info */
27
+ get screen(): DesktopScreen;
28
+ /** Window management (list, focus, resize) */
29
+ get window(): DesktopWindow;
30
+ /** Clipboard read/write */
31
+ get clipboard(): DesktopClipboard;
32
+ /**
33
+ * CUA (Computer Use Agent) - AI-powered desktop automation.
34
+ * Similar to Stagehand for browser automation.
35
+ */
36
+ get cua(): DesktopCua;
37
+ /**
38
+ * Launch a browser that can be controlled via Playwright-style API.
39
+ * The browser runs on the desktop agent's machine.
40
+ *
41
+ * @param options - Browser launch options
42
+ * @returns Browser launch result with session, context, and page IDs
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * const browser = await desktop.launchBrowser({ headless: false });
47
+ * // Use browser.sessionId, browser.defaultContextId, browser.defaultPageId
48
+ * ```
49
+ */
50
+ launchBrowser(options?: {
51
+ executablePath?: string;
52
+ headless?: boolean;
53
+ userDataDir?: string;
54
+ args?: string[];
55
+ }): Promise<BrowserLaunchResult>;
56
+ /**
57
+ * Close a launched browser.
58
+ */
59
+ closeBrowser(): Promise<void>;
60
+ /**
61
+ * Check if a browser is running.
62
+ */
63
+ isBrowserRunning(): Promise<boolean>;
64
+ /**
65
+ * Close the desktop session and clean up resources.
66
+ */
67
+ close(): Promise<void>;
68
+ /**
69
+ * Send an RPC call to the desktop agent.
70
+ * @internal
71
+ */
72
+ rpc<T>(method: string, args: unknown[], target?: 'desktop' | 'cua'): Promise<T>;
73
+ }
74
+ /**
75
+ * Mouse control for desktop automation.
76
+ * Provides move, click, drag, and scroll operations.
77
+ */
78
+ export declare class DesktopMouse {
79
+ private session;
80
+ constructor(session: DesktopSession);
81
+ /**
82
+ * Move the mouse to the specified coordinates.
83
+ * @param x - Horizontal position in pixels (0 = left edge of screen)
84
+ * @param y - Vertical position in pixels (0 = top edge of screen)
85
+ */
86
+ move(x: number, y: number): Promise<void>;
87
+ /**
88
+ * Click at the current mouse position.
89
+ * @param button - Which mouse button to click (default: 'left')
90
+ */
91
+ click(button?: 'left' | 'right' | 'middle'): Promise<void>;
92
+ /**
93
+ * Double-click at the current mouse position.
94
+ */
95
+ doubleClick(): Promise<void>;
96
+ /**
97
+ * Drag from one position to another.
98
+ * @param fromX - Starting horizontal position
99
+ * @param fromY - Starting vertical position
100
+ * @param toX - Ending horizontal position
101
+ * @param toY - Ending vertical position
102
+ */
103
+ drag(fromX: number, fromY: number, toX: number, toY: number): Promise<void>;
104
+ /**
105
+ * Scroll at the current mouse position.
106
+ * Positive values scroll down/right, negative scroll up/left.
107
+ * @param deltaX - Horizontal scroll amount in pixels
108
+ * @param deltaY - Vertical scroll amount in pixels
109
+ */
110
+ scroll(deltaX: number, deltaY: number): Promise<void>;
111
+ /**
112
+ * Get the current mouse position.
113
+ * @returns Object with x and y coordinates in pixels
114
+ */
115
+ position(): Promise<Point>;
116
+ }
117
+ /**
118
+ * Keyboard control for desktop automation.
119
+ * Provides typing, key presses, and hotkey combinations.
120
+ */
121
+ export declare class DesktopKeyboard {
122
+ private session;
123
+ constructor(session: DesktopSession);
124
+ /**
125
+ * Type a string of text.
126
+ * @param text - Text to type
127
+ */
128
+ type(text: string): Promise<void>;
129
+ /**
130
+ * Press a single key.
131
+ * @param key - Key to press (e.g., 'Enter', 'Tab', 'a')
132
+ */
133
+ press(key: string): Promise<void>;
134
+ /**
135
+ * Hold down a key.
136
+ * @param key - Key to hold down
137
+ */
138
+ down(key: string): Promise<void>;
139
+ /**
140
+ * Release a held key.
141
+ * @param key - Key to release
142
+ */
143
+ up(key: string): Promise<void>;
144
+ /**
145
+ * Press a hotkey combination.
146
+ * @param keys - Keys to press together (e.g., 'Ctrl', 'C')
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * await keyboard.hotkey('Ctrl', 'C'); // Copy
151
+ * await keyboard.hotkey('Ctrl', 'Shift', 'T'); // Reopen closed tab
152
+ * ```
153
+ */
154
+ hotkey(...keys: string[]): Promise<void>;
155
+ }
156
+ /**
157
+ * Screen control for desktop automation.
158
+ * Provides capture and display information.
159
+ */
160
+ export declare class DesktopScreen {
161
+ private session;
162
+ constructor(session: DesktopSession);
163
+ /**
164
+ * Capture the screen or a region.
165
+ * @param region - Optional region to capture
166
+ * @returns PNG image as Buffer
167
+ */
168
+ capture(region?: {
169
+ x: number;
170
+ y: number;
171
+ width: number;
172
+ height: number;
173
+ }): Promise<Buffer>;
174
+ /**
175
+ * Get the primary screen size.
176
+ * @returns Screen dimensions in pixels
177
+ */
178
+ size(): Promise<Size>;
179
+ }
180
+ /**
181
+ * Window management for desktop automation.
182
+ * Provides listing, focusing, and resizing windows.
183
+ */
184
+ export declare class DesktopWindow {
185
+ private session;
186
+ constructor(session: DesktopSession);
187
+ /**
188
+ * List all visible windows.
189
+ * @returns Array of window information
190
+ */
191
+ list(): Promise<WindowInfo[]>;
192
+ /**
193
+ * Get the currently active (focused) window.
194
+ * @returns Active window info or null if none
195
+ */
196
+ active(): Promise<WindowInfo | null>;
197
+ /**
198
+ * Focus a window by handle.
199
+ * @param handle - Window handle from list()
200
+ */
201
+ focus(handle: number): Promise<void>;
202
+ /**
203
+ * Get window bounds.
204
+ * @param handle - Window handle
205
+ * @returns Window position and size
206
+ */
207
+ bounds(handle: number): Promise<Bounds>;
208
+ /**
209
+ * Set window bounds.
210
+ * @param handle - Window handle
211
+ * @param bounds - Partial bounds to set
212
+ */
213
+ setBounds(handle: number, bounds: Partial<Bounds>): Promise<void>;
214
+ /**
215
+ * Minimize a window.
216
+ * @param handle - Window handle
217
+ */
218
+ minimize(handle: number): Promise<void>;
219
+ /**
220
+ * Maximize a window.
221
+ * @param handle - Window handle
222
+ */
223
+ maximize(handle: number): Promise<void>;
224
+ /**
225
+ * Restore a minimized/maximized window.
226
+ * @param handle - Window handle
227
+ */
228
+ restore(handle: number): Promise<void>;
229
+ /**
230
+ * Close a window.
231
+ * @param handle - Window handle
232
+ */
233
+ close(handle: number): Promise<void>;
234
+ }
235
+ /**
236
+ * Clipboard operations for desktop automation.
237
+ */
238
+ export declare class DesktopClipboard {
239
+ private session;
240
+ constructor(session: DesktopSession);
241
+ /**
242
+ * Read text from the clipboard.
243
+ * @returns Clipboard text content
244
+ */
245
+ read(): Promise<string>;
246
+ /**
247
+ * Write text to the clipboard.
248
+ * @param text - Text to write
249
+ */
250
+ write(text: string): Promise<void>;
251
+ }
252
+ /**
253
+ * CUA (Computer Use Agent) - AI-powered desktop automation.
254
+ *
255
+ * Similar to Stagehand for browser automation, CUA provides:
256
+ * - run(): Execute multi-step tasks with AI guidance
257
+ * - predictClick(): Find elements using vision
258
+ */
259
+ export declare class DesktopCua {
260
+ private session;
261
+ constructor(session: DesktopSession);
262
+ /**
263
+ * Initialize the CUA agent.
264
+ * Must be called before using run() or predictClick().
265
+ *
266
+ * @param config - Agent configuration
267
+ *
268
+ * @example
269
+ * ```ts
270
+ * await desktop.cua.init({ model: 'claude-sonnet-4-5-20250929' });
271
+ * ```
272
+ */
273
+ init(config?: CuaAgentConfig): Promise<{
274
+ success: boolean;
275
+ model: string;
276
+ }>;
277
+ /**
278
+ * Close the CUA agent and clean up resources.
279
+ */
280
+ close(): Promise<void>;
281
+ /**
282
+ * Run a computer-use task with AI guidance.
283
+ *
284
+ * Like Stagehand's act() but for desktop automation.
285
+ * The AI will analyze the screen and execute steps to complete the task.
286
+ *
287
+ * @param instruction - What task to perform
288
+ * @param options - Run options
289
+ *
290
+ * @example
291
+ * ```ts
292
+ * const result = await desktop.cua.run('Open Chrome and navigate to google.com');
293
+ * console.log(result.steps);
294
+ * ```
295
+ */
296
+ run(instruction: string, options?: CuaRunOptions): Promise<CuaRunResult>;
297
+ /**
298
+ * Predict where to click to accomplish a task.
299
+ *
300
+ * Uses vision model to find elements on screen.
301
+ * Returns coordinates that can be used with mouse.move() and mouse.click().
302
+ *
303
+ * @param instruction - What to find on screen
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * const { x, y } = await desktop.cua.predictClick('the submit button');
308
+ * await desktop.mouse.move(x, y);
309
+ * await desktop.mouse.click();
310
+ * ```
311
+ */
312
+ predictClick(instruction: string): Promise<CuaPredictClickResult>;
313
+ }