@reduck-ai/sdk 1.0.2 → 1.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 ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2025 Conception AI
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
+ <p align="center">
2
+ <img src="https://cdn.reduck.ai/logo-full-dark.png" alt="Reduck" width="300" />
3
+ </p>
4
+
1
5
  # @reduck-ai/sdk
2
6
 
3
- TypeScript SDK for the reduck.ai automation platform.
7
+ TypeScript SDK for [Reduck](https://reduck.ai) — run browser automations programmatically.
4
8
 
5
9
  ## Installation
6
10
 
@@ -8,50 +12,140 @@ TypeScript SDK for the reduck.ai automation platform.
8
12
  npm install @reduck-ai/sdk
9
13
  ```
10
14
 
11
- ## Usage
15
+ ## Quick Start
12
16
 
13
17
  ```typescript
14
18
  import { ReduckClient } from "@reduck-ai/sdk"
15
19
 
16
20
  const client = new ReduckClient({
17
21
  apiKey: "your-api-key",
18
- deviceId: "your-device-id", // or set REDUCK_DEVICE_ID env var
19
22
  })
20
23
 
21
- const run = client.run("Go to google and search for cats", {
22
- startUrl: "https://google.com",
24
+ const devices = await client.listDevices()
25
+
26
+ const run = client.run("Go to google.com and search for 'reduck ai'", {
27
+ deviceId: devices[0].id,
23
28
  })
24
29
 
25
30
  for await (const event of run) {
26
- console.log(event)
31
+ if (event.type === "progress") console.log(event.text)
32
+ if (event.type === "done") console.log(event.success ? "Done" : "Failed")
27
33
  }
28
34
  ```
29
35
 
36
+ ## Authentication
37
+
38
+ Pass either an API key or an OAuth token:
39
+
40
+ ```typescript
41
+ // API key (recommended for server-side)
42
+ const client = new ReduckClient({ apiKey: "rk_..." })
43
+
44
+ // OAuth token (for user-facing apps)
45
+ const client = new ReduckClient({ oauthToken: "..." })
46
+ ```
47
+
48
+ Generate an API key from your [Reduck dashboard](https://reduck.ai).
49
+
30
50
  ## API
31
51
 
32
52
  ### `new ReduckClient(options)`
33
53
 
34
- `apiKey` : Your reduck.ai API key
35
- `deviceId` : The device ID to run automations on (or set `REDUCK_DEVICE_ID` env var)
54
+ | Option | Type | Description |
55
+ |---|---|---|
56
+ | `apiKey` | `string` | API key authentication |
57
+ | `oauthToken` | `string` | OAuth bearer token authentication |
36
58
 
37
- ### `client.run(prompt, options?)`
59
+ One of `apiKey` or `oauthToken` is required.
38
60
 
39
- Returns a `Run` object that is an `AsyncIterable<RunEvent>`.
61
+ ### `client.listDevices()`
40
62
 
41
- `startUrl` : URL to navigate to before running the automation
42
- `mount` : Local file paths to make available to the automation
63
+ Returns `Promise<Device[]>` — all devices for the authenticated user.
64
+
65
+ ```typescript
66
+ interface Device {
67
+ id: string
68
+ name: string | null
69
+ browser: string | null
70
+ os: string | null
71
+ reachable: boolean
72
+ created_at: string
73
+ }
74
+ ```
75
+
76
+ ### `client.run(prompt, options)`
77
+
78
+ Starts an automation and returns a `Run` — an `AsyncIterable<RunEvent>` that streams events in real-time via WebSocket.
79
+
80
+ | Option | Type | Description |
81
+ |---|---|---|
82
+ | `deviceId` | `string` | Target device ID (required) |
83
+ | `mount` | `string[]` | Local file paths to upload and make available |
43
84
 
44
85
  ### `run.id`
45
86
 
46
- `Promise<string>` — resolves to the run ID once created.
87
+ `Promise<string>` — resolves to the run ID once the server accepts it.
47
88
 
48
89
  ### `run.cancel()`
49
90
 
50
- Cancels the run.
91
+ Cancels the running automation.
92
+
93
+ ### `client.listRuns(page?)`
94
+
95
+ Returns `Promise<RunsPage>` — a paginated list of runs (sessions) for the authenticated user.
96
+
97
+ ```typescript
98
+ interface RunsPage {
99
+ data: RunRecord[]
100
+ hasNextPage: boolean
101
+ }
102
+ ```
103
+
104
+ | Option | Type | Default | Description |
105
+ |---|---|---|---|
106
+ | `page` | `number` | `0` | Zero-based page index |
107
+
108
+ ### `client.getRun(runId)`
109
+
110
+ Returns `Promise<RunRecord>` — a single run by ID.
111
+
112
+ ```typescript
113
+ interface RunRecord {
114
+ id: string
115
+ started_at: string
116
+ finished_at: string | null
117
+ result: {
118
+ success?: boolean
119
+ cancelled?: boolean
120
+ reason?: string
121
+ output?: string
122
+ } | null
123
+ resolved: {
124
+ url?: string
125
+ prompt?: string
126
+ } | null
127
+ }
128
+ ```
129
+
130
+ ### `client.interrupt(runId)`
131
+
132
+ Interrupts a run by ID.
51
133
 
52
134
  ## Events
53
135
 
54
- `progress` : Automation progress update |
55
- `done` : Run completed successfully |
56
- `failure` : Run failed, includes `error` field |
57
- `cancel` : Run was cancelled |
136
+ The `run` async iterable yields these events:
137
+
138
+ | Type | Fields | Description |
139
+ |---|---|---|
140
+ | `run_started` | `timestamp` | Automation has started |
141
+ | `progress` | `text`, `timestamp` | Step-by-step progress update |
142
+ | `assistant` | `text`, `timestamp` | Assistant message |
143
+ | `turn_completed` | `timestamp` | Agent turn completed |
144
+ | `run_completed` | `timestamp` | Automation finished executing |
145
+ | `done` | `success`, `output?` | Final result |
146
+ | `failure` | `error` | Automation failed |
147
+ | `cancel` | — | Automation was cancelled |
148
+
149
+ ## License
150
+
151
+ Apache-2.0
@@ -0,0 +1,3 @@
1
+ export declare const BUILD_ENV: "production" | "staging" | "local";
2
+ export declare const APP_URL = "https://reduck.ai";
3
+ export declare const RUNNER_URL = "https://runner.pointandclick.ai";
@@ -0,0 +1,4 @@
1
+ // Auto-generated by scripts/generate-build-env.mjs — do not edit
2
+ export const BUILD_ENV = "production";
3
+ export const APP_URL = "https://reduck.ai";
4
+ export const RUNNER_URL = "https://runner.pointandclick.ai";
package/dist/client.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { type ReduckClientOptions, type RunOptions } from "./types.js";
1
+ import { type Device, type ReduckClientOptions, type RunOptions, type RunRecord, type RunsPage } from "./types.js";
2
2
  import { Run } from "./run.js";
3
3
  export declare class ReduckClient {
4
- private readonly _auth;
5
- private readonly _deviceId;
6
- private readonly _baseUrl;
7
- constructor({ auth, deviceId, baseUrl }: ReduckClientOptions);
4
+ private readonly _runnerBaseUrl;
5
+ private readonly _appBaseUrl;
6
+ private readonly _headers;
7
+ constructor(opts: ReduckClientOptions);
8
8
  consentNotice(): Promise<void>;
9
- run(prompt: string, { startUrl, mount }?: RunOptions): Run;
9
+ run(prompt: string, { mount, deviceId }: RunOptions): Run;
10
+ listDevices(): Promise<Device[]>;
11
+ listRuns(page?: number): Promise<RunsPage>;
12
+ getRun(runId: string): Promise<RunRecord>;
10
13
  interrupt(runId: string): Promise<void>;
11
14
  private _createRun;
12
15
  private _mount;
package/dist/client.js CHANGED
@@ -2,27 +2,27 @@ import { cp, mkdir } from "node:fs/promises";
2
2
  import { createInterface } from "node:readline";
3
3
  import { basename, join } from "node:path";
4
4
  import { homedir } from "node:os";
5
+ import { ReduckError } from "./errors.js";
5
6
  import { authHeader } from "./types.js";
6
7
  import { Run } from "./run.js";
7
- const DEFAULT_BASE_URL = "https://runner.pointandclick.ai";
8
+ import { fetchDevices } from "./device.js";
9
+ import { fetchRun, fetchRuns } from "./session.js";
10
+ import { RUNNER_URL, APP_URL } from "./build-env.generated.js";
8
11
  export class ReduckClient {
9
- _auth;
10
- _deviceId;
11
- _baseUrl;
12
- constructor({ auth, deviceId, baseUrl = DEFAULT_BASE_URL }) {
13
- const resolvedDeviceId = deviceId ?? process.env.REDUCK_DEVICE_ID;
14
- if (!resolvedDeviceId)
15
- throw new Error("deviceId is required (or set REDUCK_DEVICE_ID)");
16
- this._auth = auth;
17
- this._deviceId = resolvedDeviceId;
18
- this._baseUrl = baseUrl.replace(/\/$/, "");
12
+ _runnerBaseUrl;
13
+ _appBaseUrl;
14
+ _headers;
15
+ constructor(opts) {
16
+ this._runnerBaseUrl = (opts.runnerBaseUrl ?? RUNNER_URL).replace(/\/$/, "");
17
+ this._appBaseUrl = (opts.appBaseUrl ?? APP_URL).replace(/\/$/, "");
18
+ this._headers = { ...opts.headers, ...authHeader(opts) };
19
19
  }
20
20
  async consentNotice() {
21
- const res = await fetch(`${this._baseUrl}/consent-notice`, {
22
- headers: authHeader(this._auth),
21
+ const res = await fetch(`${this._runnerBaseUrl}/consent-notice`, {
22
+ headers: this._headers,
23
23
  });
24
24
  if (!res.ok)
25
- throw new Error(`GET /consent-notice failed: ${res.status}`);
25
+ throw ReduckError.fromResponse("GET /consent-notice", res.status);
26
26
  const data = (await res.json());
27
27
  if (!data.content)
28
28
  return;
@@ -31,45 +31,55 @@ export class ReduckClient {
31
31
  rl.question(`${data.content} (y/n) `, (a) => { rl.close(); resolve(a.trim().toLowerCase()); });
32
32
  });
33
33
  if (answer !== "y" && answer !== "yes")
34
- throw new Error("Consent not given");
35
- const post = await fetch(`${this._baseUrl}/consent-notice`, {
34
+ throw new ReduckError("Consent not accepted", { code: "CONSENT_REFUSED" });
35
+ const post = await fetch(`${this._runnerBaseUrl}/consent-notice`, {
36
36
  method: "POST",
37
- headers: { "Content-Type": "application/json", ...authHeader(this._auth) },
37
+ headers: { "Content-Type": "application/json", ...this._headers },
38
38
  body: JSON.stringify({ version: data.version }),
39
39
  });
40
40
  if (!post.ok)
41
- throw new Error(`POST /consent-notice failed: ${post.status}`);
41
+ throw ReduckError.fromResponse("POST /consent-notice", post.status);
42
42
  }
43
- run(prompt, { startUrl, mount } = {}) {
44
- const runIdPromise = this._createRun(prompt, startUrl, mount);
45
- const wsBase = this._baseUrl
43
+ run(prompt, { mount, deviceId }) {
44
+ if (!deviceId)
45
+ throw new ReduckError("deviceId is required to start a run", { code: "MISSING_DEVICE" });
46
+ const runIdPromise = this._createRun(deviceId, prompt, mount);
47
+ const wsBase = this._runnerBaseUrl
46
48
  .replace("https://", "wss://")
47
49
  .replace("http://", "ws://");
48
- return new Run(runIdPromise, wsBase, this._auth);
50
+ return new Run(runIdPromise, wsBase, this._headers);
51
+ }
52
+ async listDevices() {
53
+ return fetchDevices(this._appBaseUrl, this._headers);
54
+ }
55
+ async listRuns(page = 0) {
56
+ return fetchRuns(this._appBaseUrl, this._headers, page);
57
+ }
58
+ async getRun(runId) {
59
+ return fetchRun(this._appBaseUrl, this._headers, runId);
49
60
  }
50
61
  async interrupt(runId) {
51
- await fetch(`${this._baseUrl}/run/${runId}/cancel`, {
62
+ await fetch(`${this._runnerBaseUrl}/run/${runId}/cancel`, {
52
63
  method: "POST",
53
- headers: authHeader(this._auth),
64
+ headers: this._headers,
54
65
  });
55
66
  }
56
- async _createRun(prompt, startUrl, mount) {
67
+ async _createRun(deviceId, prompt, mount) {
57
68
  const mountedPaths = mount?.length ? await this._mount(mount) : undefined;
58
- const res = await fetch(`${this._baseUrl}/query`, {
69
+ const res = await fetch(`${this._runnerBaseUrl}/query`, {
59
70
  method: "POST",
60
71
  headers: {
61
72
  "Content-Type": "application/json",
62
- ...authHeader(this._auth),
73
+ ...this._headers,
63
74
  },
64
75
  body: JSON.stringify({
65
76
  prompt,
66
- device_id: this._deviceId,
67
- ...(startUrl ? { start_url: startUrl } : {}),
77
+ device_id: deviceId,
68
78
  ...(mountedPaths?.length ? { mount: mountedPaths } : {}),
69
79
  }),
70
80
  });
71
81
  if (!res.ok)
72
- throw new Error(`POST /query failed: ${res.status}`);
82
+ throw ReduckError.fromResponse("POST /query", res.status);
73
83
  const data = (await res.json());
74
84
  return data.run_id;
75
85
  }
@@ -0,0 +1,3 @@
1
+ import type { Device } from "./types.js";
2
+ export type { Device };
3
+ export declare function fetchDevices(appBaseUrl: string, headers: Record<string, string>): Promise<Device[]>;
package/dist/device.js ADDED
@@ -0,0 +1,7 @@
1
+ import { ReduckError } from "./errors.js";
2
+ export async function fetchDevices(appBaseUrl, headers) {
3
+ const res = await fetch(`${appBaseUrl}/api/devices`, { headers });
4
+ if (!res.ok)
5
+ throw ReduckError.fromResponse("GET /api/devices", res.status);
6
+ return (await res.json());
7
+ }
@@ -0,0 +1,9 @@
1
+ export declare class ReduckError extends Error {
2
+ readonly code: string;
3
+ readonly status?: number;
4
+ constructor(message: string, opts?: {
5
+ code?: string;
6
+ status?: number;
7
+ });
8
+ static fromResponse(endpoint: string, status: number): ReduckError;
9
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,20 @@
1
+ const STATUS_MESSAGES = {
2
+ 401: "Not authenticated. Run `reduck login` or provide --api-key.",
3
+ 403: "Access denied.",
4
+ 404: "Resource not found.",
5
+ 429: "Rate limited. Try again later.",
6
+ };
7
+ export class ReduckError extends Error {
8
+ code;
9
+ status;
10
+ constructor(message, opts = {}) {
11
+ super(message);
12
+ this.name = "ReduckError";
13
+ this.code = opts.code ?? "INTERNAL_ERROR";
14
+ this.status = opts.status;
15
+ }
16
+ static fromResponse(endpoint, status) {
17
+ const hint = STATUS_MESSAGES[status] ?? `HTTP ${status}`;
18
+ return new ReduckError(`${endpoint}: ${hint}`, { code: "HTTP_ERROR", status });
19
+ }
20
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { ReduckClient } from "./client.js";
2
+ export { ReduckError } from "./errors.js";
2
3
  export { Run } from "./run.js";
3
- export type { AuthConfig, RunEvent, RunOptions, ReduckClientOptions } from "./types.js";
4
+ export type { Device, RunEvent, RunOptions, RunRecord, RunsPage, ReduckClientOptions } from "./types.js";
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export { ReduckClient } from "./client.js";
2
+ export { ReduckError } from "./errors.js";
2
3
  export { Run } from "./run.js";
package/dist/run.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { type AuthConfig, type RunEvent } from "./types.js";
1
+ import type { RunEvent } from "./types.js";
2
2
  export declare class Run implements AsyncIterable<RunEvent> {
3
3
  private readonly _runIdPromise;
4
4
  private readonly _wsBase;
5
- private readonly _auth;
5
+ private readonly _headers;
6
6
  private _ws;
7
- constructor(runIdPromise: Promise<string>, wsBase: string, auth: AuthConfig);
7
+ constructor(runIdPromise: Promise<string>, wsBase: string, headers: Record<string, string>);
8
8
  get id(): Promise<string>;
9
9
  [Symbol.asyncIterator](): AsyncGenerator<RunEvent>;
10
10
  private _stream;
package/dist/run.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import WebSocket from "ws";
2
- import { authHeader } from "./types.js";
2
+ import { ReduckError } from "./errors.js";
3
3
  export class Run {
4
4
  _runIdPromise;
5
5
  _wsBase;
6
- _auth;
6
+ _headers;
7
7
  _ws = null;
8
- constructor(runIdPromise, wsBase, auth) {
8
+ constructor(runIdPromise, wsBase, headers) {
9
9
  this._runIdPromise = runIdPromise;
10
10
  this._wsBase = wsBase;
11
- this._auth = auth;
11
+ this._headers = headers;
12
12
  }
13
13
  get id() {
14
14
  return this._runIdPromise;
@@ -19,7 +19,7 @@ export class Run {
19
19
  async *_stream() {
20
20
  const runId = await this._runIdPromise;
21
21
  const wsUrl = `${this._wsBase}/run/${runId}/events`;
22
- const ws = new WebSocket(wsUrl, { headers: authHeader(this._auth) });
22
+ const ws = new WebSocket(wsUrl, { headers: this._headers });
23
23
  this._ws = ws;
24
24
  const queue = [];
25
25
  let resolve = null;
@@ -31,7 +31,7 @@ export class Run {
31
31
  resolve?.();
32
32
  });
33
33
  ws.on("error", (err) => {
34
- error = err;
34
+ error = new ReduckError(err.message, { code: "CONNECTION_LOST" });
35
35
  done = true;
36
36
  resolve?.();
37
37
  });
@@ -65,7 +65,7 @@ export class Run {
65
65
  .replace("ws://", "http://");
66
66
  await fetch(`${baseUrl}/run/${runId}/cancel`, {
67
67
  method: "POST",
68
- headers: authHeader(this._auth),
68
+ headers: this._headers,
69
69
  });
70
70
  }
71
71
  }
@@ -0,0 +1,3 @@
1
+ import type { RunRecord, RunsPage } from "./types.js";
2
+ export declare function fetchRuns(appBaseUrl: string, headers: Record<string, string>, page?: number): Promise<RunsPage>;
3
+ export declare function fetchRun(appBaseUrl: string, headers: Record<string, string>, runId: string): Promise<RunRecord>;
@@ -0,0 +1,14 @@
1
+ import { ReduckError } from "./errors.js";
2
+ export async function fetchRuns(appBaseUrl, headers, page = 0) {
3
+ const params = new URLSearchParams({ page: String(page) });
4
+ const res = await fetch(`${appBaseUrl}/api/runs?${params}`, { headers });
5
+ if (!res.ok)
6
+ throw ReduckError.fromResponse("GET /api/runs", res.status);
7
+ return (await res.json());
8
+ }
9
+ export async function fetchRun(appBaseUrl, headers, runId) {
10
+ const res = await fetch(`${appBaseUrl}/api/runs/${encodeURIComponent(runId)}`, { headers });
11
+ if (!res.ok)
12
+ throw ReduckError.fromResponse(`GET /api/runs/${runId}`, res.status);
13
+ return (await res.json());
14
+ }
package/dist/types.d.ts CHANGED
@@ -26,16 +26,41 @@ export type RunEvent = {
26
26
  type: "cancel";
27
27
  };
28
28
  export interface RunOptions {
29
- startUrl?: string;
29
+ deviceId: string;
30
30
  mount?: string[];
31
31
  }
32
- export interface AuthConfig {
33
- type: "oauth" | "api_key";
34
- value: string;
32
+ export declare function authHeader(opts: ReduckClientOptions): Record<string, string>;
33
+ export interface Device {
34
+ id: string;
35
+ name: string | null;
36
+ browser: string | null;
37
+ os: string | null;
38
+ reachable: boolean;
39
+ created_at: string;
40
+ }
41
+ export interface RunRecord {
42
+ id: string;
43
+ started_at: string;
44
+ finished_at: string | null;
45
+ result: {
46
+ success?: boolean;
47
+ cancelled?: boolean;
48
+ reason?: string;
49
+ output?: string;
50
+ } | null;
51
+ resolved: {
52
+ url?: string;
53
+ prompt?: string;
54
+ } | null;
55
+ }
56
+ export interface RunsPage {
57
+ data: RunRecord[];
58
+ hasNextPage: boolean;
35
59
  }
36
- export declare function authHeader(auth: AuthConfig): Record<string, string>;
37
60
  export interface ReduckClientOptions {
38
- auth: AuthConfig;
39
- deviceId?: string;
40
- baseUrl?: string;
61
+ oauthToken?: string;
62
+ apiKey?: string;
63
+ runnerBaseUrl?: string;
64
+ appBaseUrl?: string;
65
+ headers?: Record<string, string>;
41
66
  }
package/dist/types.js CHANGED
@@ -1,5 +1,8 @@
1
- export function authHeader(auth) {
2
- return auth.type === "oauth"
3
- ? { Authorization: `Bearer ${auth.value}` }
4
- : { "X-API-Key": auth.value };
1
+ import { ReduckError } from "./errors.js";
2
+ export function authHeader(opts) {
3
+ if (opts.oauthToken)
4
+ return { Authorization: `Bearer ${opts.oauthToken}` };
5
+ if (opts.apiKey)
6
+ return { "X-API-Key": opts.apiKey };
7
+ throw new ReduckError("Either oauthToken or apiKey is required", { code: "MISSING_CREDENTIALS" });
5
8
  }
package/package.json CHANGED
@@ -1,6 +1,19 @@
1
1
  {
2
2
  "name": "@reduck-ai/sdk",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
+ "description": "TypeScript SDK for Reduck — run browser automations programmatically.",
5
+ "license": "Apache-2.0",
6
+ "author": "Reduck AI <contact@reduck.ai> (https://reduck.ai)",
7
+ "homepage": "https://reduck.ai",
8
+ "keywords": [
9
+ "reduck",
10
+ "browser-automation",
11
+ "sdk",
12
+ "ai",
13
+ "rpa"
14
+ ],
15
+ "funding": "https://reduck.ai",
16
+ "sideEffects": false,
4
17
  "type": "module",
5
18
  "main": "./dist/index.js",
6
19
  "types": "./dist/index.d.ts",
@@ -14,6 +27,9 @@
14
27
  "dist/",
15
28
  "README.md"
16
29
  ],
30
+ "engines": {
31
+ "node": ">=22"
32
+ },
17
33
  "publishConfig": {
18
34
  "access": "public"
19
35
  },
@@ -25,7 +41,13 @@
25
41
  "typescript": "^5.0.0"
26
42
  },
27
43
  "scripts": {
44
+ "generate-env": "node ../scripts/generate-build-env.mjs ./src/build-env.generated.ts",
45
+ "prebuild": "pnpm generate-env",
28
46
  "build": "pnpm exec tsc",
47
+ "build:production": "REDUCK_BUILD_ENV=production pnpm build",
48
+ "build:staging": "REDUCK_BUILD_ENV=staging pnpm build",
49
+ "precheck": "pnpm generate-env",
50
+ "check": "pnpm exec tsc --noEmit",
29
51
  "dev": "pnpm exec tsc --watch"
30
52
  }
31
53
  }