@reduck-ai/sdk 1.0.1 → 1.0.2
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/dist/client.d.ts +4 -3
- package/dist/client.js +31 -6
- package/dist/index.d.ts +1 -1
- package/dist/run.d.ts +3 -3
- package/dist/run.js +6 -7
- package/dist/types.d.ts +6 -1
- package/dist/types.js +5 -1
- package/package.json +6 -6
package/dist/client.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReduckClientOptions, type RunOptions } from "./types.js";
|
|
2
2
|
import { Run } from "./run.js";
|
|
3
3
|
export declare class ReduckClient {
|
|
4
|
-
private readonly
|
|
4
|
+
private readonly _auth;
|
|
5
5
|
private readonly _deviceId;
|
|
6
6
|
private readonly _baseUrl;
|
|
7
|
-
constructor({
|
|
7
|
+
constructor({ auth, deviceId, baseUrl }: ReduckClientOptions);
|
|
8
|
+
consentNotice(): Promise<void>;
|
|
8
9
|
run(prompt: string, { startUrl, mount }?: RunOptions): Run;
|
|
9
10
|
interrupt(runId: string): Promise<void>;
|
|
10
11
|
private _createRun;
|
package/dist/client.js
CHANGED
|
@@ -1,31 +1,56 @@
|
|
|
1
1
|
import { cp, mkdir } from "node:fs/promises";
|
|
2
|
+
import { createInterface } from "node:readline";
|
|
2
3
|
import { basename, join } from "node:path";
|
|
3
4
|
import { homedir } from "node:os";
|
|
5
|
+
import { authHeader } from "./types.js";
|
|
4
6
|
import { Run } from "./run.js";
|
|
5
7
|
const DEFAULT_BASE_URL = "https://runner.pointandclick.ai";
|
|
6
8
|
export class ReduckClient {
|
|
7
|
-
|
|
9
|
+
_auth;
|
|
8
10
|
_deviceId;
|
|
9
11
|
_baseUrl;
|
|
10
|
-
constructor({
|
|
12
|
+
constructor({ auth, deviceId, baseUrl = DEFAULT_BASE_URL }) {
|
|
11
13
|
const resolvedDeviceId = deviceId ?? process.env.REDUCK_DEVICE_ID;
|
|
12
14
|
if (!resolvedDeviceId)
|
|
13
15
|
throw new Error("deviceId is required (or set REDUCK_DEVICE_ID)");
|
|
14
|
-
this.
|
|
16
|
+
this._auth = auth;
|
|
15
17
|
this._deviceId = resolvedDeviceId;
|
|
16
18
|
this._baseUrl = baseUrl.replace(/\/$/, "");
|
|
17
19
|
}
|
|
20
|
+
async consentNotice() {
|
|
21
|
+
const res = await fetch(`${this._baseUrl}/consent-notice`, {
|
|
22
|
+
headers: authHeader(this._auth),
|
|
23
|
+
});
|
|
24
|
+
if (!res.ok)
|
|
25
|
+
throw new Error(`GET /consent-notice failed: ${res.status}`);
|
|
26
|
+
const data = (await res.json());
|
|
27
|
+
if (!data.content)
|
|
28
|
+
return;
|
|
29
|
+
const answer = await new Promise((resolve) => {
|
|
30
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
31
|
+
rl.question(`${data.content} (y/n) `, (a) => { rl.close(); resolve(a.trim().toLowerCase()); });
|
|
32
|
+
});
|
|
33
|
+
if (answer !== "y" && answer !== "yes")
|
|
34
|
+
throw new Error("Consent not given");
|
|
35
|
+
const post = await fetch(`${this._baseUrl}/consent-notice`, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "Content-Type": "application/json", ...authHeader(this._auth) },
|
|
38
|
+
body: JSON.stringify({ version: data.version }),
|
|
39
|
+
});
|
|
40
|
+
if (!post.ok)
|
|
41
|
+
throw new Error(`POST /consent-notice failed: ${post.status}`);
|
|
42
|
+
}
|
|
18
43
|
run(prompt, { startUrl, mount } = {}) {
|
|
19
44
|
const runIdPromise = this._createRun(prompt, startUrl, mount);
|
|
20
45
|
const wsBase = this._baseUrl
|
|
21
46
|
.replace("https://", "wss://")
|
|
22
47
|
.replace("http://", "ws://");
|
|
23
|
-
return new Run(runIdPromise, wsBase, this.
|
|
48
|
+
return new Run(runIdPromise, wsBase, this._auth);
|
|
24
49
|
}
|
|
25
50
|
async interrupt(runId) {
|
|
26
51
|
await fetch(`${this._baseUrl}/run/${runId}/cancel`, {
|
|
27
52
|
method: "POST",
|
|
28
|
-
headers:
|
|
53
|
+
headers: authHeader(this._auth),
|
|
29
54
|
});
|
|
30
55
|
}
|
|
31
56
|
async _createRun(prompt, startUrl, mount) {
|
|
@@ -34,7 +59,7 @@ export class ReduckClient {
|
|
|
34
59
|
method: "POST",
|
|
35
60
|
headers: {
|
|
36
61
|
"Content-Type": "application/json",
|
|
37
|
-
|
|
62
|
+
...authHeader(this._auth),
|
|
38
63
|
},
|
|
39
64
|
body: JSON.stringify({
|
|
40
65
|
prompt,
|
package/dist/index.d.ts
CHANGED
package/dist/run.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AuthConfig, 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
|
|
5
|
+
private readonly _auth;
|
|
6
6
|
private _ws;
|
|
7
|
-
constructor(runIdPromise: Promise<string>, wsBase: string,
|
|
7
|
+
constructor(runIdPromise: Promise<string>, wsBase: string, auth: AuthConfig);
|
|
8
8
|
get id(): Promise<string>;
|
|
9
9
|
[Symbol.asyncIterator](): AsyncGenerator<RunEvent>;
|
|
10
10
|
private _stream;
|
package/dist/run.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
|
+
import { authHeader } from "./types.js";
|
|
2
3
|
export class Run {
|
|
3
4
|
_runIdPromise;
|
|
4
5
|
_wsBase;
|
|
5
|
-
|
|
6
|
+
_auth;
|
|
6
7
|
_ws = null;
|
|
7
|
-
constructor(runIdPromise, wsBase,
|
|
8
|
+
constructor(runIdPromise, wsBase, auth) {
|
|
8
9
|
this._runIdPromise = runIdPromise;
|
|
9
10
|
this._wsBase = wsBase;
|
|
10
|
-
this.
|
|
11
|
+
this._auth = auth;
|
|
11
12
|
}
|
|
12
13
|
get id() {
|
|
13
14
|
return this._runIdPromise;
|
|
@@ -18,9 +19,7 @@ export class Run {
|
|
|
18
19
|
async *_stream() {
|
|
19
20
|
const runId = await this._runIdPromise;
|
|
20
21
|
const wsUrl = `${this._wsBase}/run/${runId}/events`;
|
|
21
|
-
const ws = new WebSocket(wsUrl, {
|
|
22
|
-
headers: { Authorization: `Bearer ${this._apiKey}` },
|
|
23
|
-
});
|
|
22
|
+
const ws = new WebSocket(wsUrl, { headers: authHeader(this._auth) });
|
|
24
23
|
this._ws = ws;
|
|
25
24
|
const queue = [];
|
|
26
25
|
let resolve = null;
|
|
@@ -66,7 +65,7 @@ export class Run {
|
|
|
66
65
|
.replace("ws://", "http://");
|
|
67
66
|
await fetch(`${baseUrl}/run/${runId}/cancel`, {
|
|
68
67
|
method: "POST",
|
|
69
|
-
headers:
|
|
68
|
+
headers: authHeader(this._auth),
|
|
70
69
|
});
|
|
71
70
|
}
|
|
72
71
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -29,8 +29,13 @@ export interface RunOptions {
|
|
|
29
29
|
startUrl?: string;
|
|
30
30
|
mount?: string[];
|
|
31
31
|
}
|
|
32
|
+
export interface AuthConfig {
|
|
33
|
+
type: "oauth" | "api_key";
|
|
34
|
+
value: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function authHeader(auth: AuthConfig): Record<string, string>;
|
|
32
37
|
export interface ReduckClientOptions {
|
|
33
|
-
|
|
38
|
+
auth: AuthConfig;
|
|
34
39
|
deviceId?: string;
|
|
35
40
|
baseUrl?: string;
|
|
36
41
|
}
|
package/dist/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reduck-ai/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -17,15 +17,15 @@
|
|
|
17
17
|
"publishConfig": {
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "pnpm exec tsc",
|
|
22
|
-
"dev": "pnpm exec tsc --watch"
|
|
23
|
-
},
|
|
24
20
|
"dependencies": {
|
|
25
21
|
"ws": "^8.0.0"
|
|
26
22
|
},
|
|
27
23
|
"devDependencies": {
|
|
28
24
|
"@types/ws": "^8.0.0",
|
|
29
25
|
"typescript": "^5.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "pnpm exec tsc",
|
|
29
|
+
"dev": "pnpm exec tsc --watch"
|
|
30
30
|
}
|
|
31
|
-
}
|
|
31
|
+
}
|