@drawcall/run 0.0.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/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +16 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type { JobStatus, RunResult, RunRequest, JobCreatedResponse, JobResponse, RunOptions, RunFinalResult, } from './types.js';
|
|
2
|
+
import type { RunOptions, RunFinalResult } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Error thrown when run fails
|
|
5
|
+
*/
|
|
6
|
+
export declare class RunError extends Error {
|
|
7
|
+
readonly jobId?: string | undefined;
|
|
8
|
+
readonly cause?: unknown | undefined;
|
|
9
|
+
constructor(message: string, jobId?: string | undefined, cause?: unknown | undefined);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when run times out
|
|
13
|
+
*/
|
|
14
|
+
export declare class TimeoutError extends RunError {
|
|
15
|
+
constructor(jobId: string, timeoutMs: number);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Run a web app through RunPod
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { run } from '@drawcall/run'
|
|
23
|
+
*
|
|
24
|
+
* const result = await run({
|
|
25
|
+
* url: 'https://example.com/app',
|
|
26
|
+
* maxDuration: 30,
|
|
27
|
+
* timeoutMs: 60000,
|
|
28
|
+
* pollIntervalMs: 2000,
|
|
29
|
+
* })
|
|
30
|
+
*
|
|
31
|
+
* console.log(result.logs) // Browser console logs with screenshot URLs
|
|
32
|
+
* console.log(result.stopCause) // "signal_complete", "max_duration_reached", or "error: ..."
|
|
33
|
+
* console.log(result.jobId) // Job ID for reference
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function run(options: RunOptions): Promise<RunFinalResult>;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,YAAY,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,cAAc,GACf,MAAM,YAAY,CAAA;AAEnB,OAAO,KAAK,EAA+C,UAAU,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEzG;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;aACY,KAAK,CAAC,EAAE,MAAM;aAAkB,KAAK,CAAC,EAAE,OAAO;gBAAhF,OAAO,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,MAAM,YAAA,EAAkB,KAAK,CAAC,EAAE,OAAO,YAAA;CAI7F;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,QAAQ;gBAC5B,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAI7C;AAOD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC,CAqEtE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @drawcall/run - Client Package
|
|
3
|
+
// ============================================================================
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when run fails
|
|
6
|
+
*/
|
|
7
|
+
export class RunError extends Error {
|
|
8
|
+
jobId;
|
|
9
|
+
cause;
|
|
10
|
+
constructor(message, jobId, cause) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.jobId = jobId;
|
|
13
|
+
this.cause = cause;
|
|
14
|
+
this.name = 'RunError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Error thrown when run times out
|
|
19
|
+
*/
|
|
20
|
+
export class TimeoutError extends RunError {
|
|
21
|
+
constructor(jobId, timeoutMs) {
|
|
22
|
+
super(`Run timed out after ${timeoutMs}ms`, jobId);
|
|
23
|
+
this.name = 'TimeoutError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sleep for a given number of milliseconds
|
|
28
|
+
*/
|
|
29
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
30
|
+
/**
|
|
31
|
+
* Run a web app through RunPod
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { run } from '@drawcall/run'
|
|
36
|
+
*
|
|
37
|
+
* const result = await run({
|
|
38
|
+
* url: 'https://example.com/app',
|
|
39
|
+
* maxDuration: 30,
|
|
40
|
+
* timeoutMs: 60000,
|
|
41
|
+
* pollIntervalMs: 2000,
|
|
42
|
+
* })
|
|
43
|
+
*
|
|
44
|
+
* console.log(result.logs) // Browser console logs with screenshot URLs
|
|
45
|
+
* console.log(result.stopCause) // "signal_complete", "max_duration_reached", or "error: ..."
|
|
46
|
+
* console.log(result.jobId) // Job ID for reference
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export async function run(options) {
|
|
50
|
+
const { url: targetUrl, maxDuration, assetMap, baseUrl = 'https://v1.run.api.drawcall.ai', timeoutMs = 600_000, // 10 minutes default
|
|
51
|
+
pollIntervalMs = 2000, } = options;
|
|
52
|
+
const url = new URL('/run', baseUrl);
|
|
53
|
+
// Create the job
|
|
54
|
+
const payload = {
|
|
55
|
+
url: targetUrl,
|
|
56
|
+
...(maxDuration !== undefined && { maxDuration }),
|
|
57
|
+
...(assetMap !== undefined && { assetMap }),
|
|
58
|
+
};
|
|
59
|
+
const createResponse = await fetch(url, {
|
|
60
|
+
method: 'POST',
|
|
61
|
+
headers: { 'Content-Type': 'application/json' },
|
|
62
|
+
body: JSON.stringify(payload),
|
|
63
|
+
});
|
|
64
|
+
if (!createResponse.ok) {
|
|
65
|
+
const errorBody = await createResponse.text();
|
|
66
|
+
throw new RunError(`Failed to create job: ${createResponse.status} ${errorBody}`);
|
|
67
|
+
}
|
|
68
|
+
const { jobId } = (await createResponse.json());
|
|
69
|
+
// Poll for completion
|
|
70
|
+
const startTime = Date.now();
|
|
71
|
+
const jobUrl = new URL(`/job/${jobId}`, baseUrl);
|
|
72
|
+
while (true) {
|
|
73
|
+
if (Date.now() - startTime > timeoutMs) {
|
|
74
|
+
throw new TimeoutError(jobId, timeoutMs);
|
|
75
|
+
}
|
|
76
|
+
const statusResponse = await fetch(jobUrl);
|
|
77
|
+
if (!statusResponse.ok) {
|
|
78
|
+
throw new RunError(`Failed to get job status: ${statusResponse.status}`, jobId);
|
|
79
|
+
}
|
|
80
|
+
const job = (await statusResponse.json());
|
|
81
|
+
switch (job.status) {
|
|
82
|
+
case 'completed':
|
|
83
|
+
if (!job.result) {
|
|
84
|
+
throw new RunError('Job completed but no result', jobId);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
jobId,
|
|
88
|
+
logs: job.result.logs,
|
|
89
|
+
stopCause: job.result.stopCause,
|
|
90
|
+
};
|
|
91
|
+
case 'failed':
|
|
92
|
+
throw new RunError(job.error ?? 'Job failed', jobId);
|
|
93
|
+
case 'pending':
|
|
94
|
+
case 'running':
|
|
95
|
+
await sleep(pollIntervalMs);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,iCAAiC;AACjC,+EAA+E;AAc/E;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IACY;IAAgC;IAA7E,YAAY,OAAe,EAAkB,KAAc,EAAkB,KAA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,CAAC,MAAM,CAAC,SAAS;iBAChC,CAAA;YAEH,KAAK,QAAQ;gBACX,MAAM,IAAI,QAAQ,CAAC,GAAG,CAAC,KAAK,IAAI,YAAY,EAAE,KAAK,CAAC,CAAA;YAEtD,KAAK,SAAS,CAAC;YACf,KAAK,SAAS;gBACZ,MAAM,KAAK,CAAC,cAAc,CAAC,CAAA;gBAC3B,MAAK;QACT,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Status of a run job
|
|
3
|
+
*/
|
|
4
|
+
export type JobStatus = 'pending' | 'running' | 'completed' | 'failed';
|
|
5
|
+
/**
|
|
6
|
+
* Request payload for running a web app
|
|
7
|
+
*/
|
|
8
|
+
export interface RunRequest {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
readonly maxDuration?: number;
|
|
11
|
+
readonly assetMap?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Result of a successful run
|
|
15
|
+
*/
|
|
16
|
+
export interface RunResult {
|
|
17
|
+
readonly logs: readonly string[];
|
|
18
|
+
readonly stopCause: 'signal_complete' | 'max_duration_reached' | `error: ${string}`;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Response when a job is created (202 Accepted)
|
|
22
|
+
*/
|
|
23
|
+
export interface JobCreatedResponse {
|
|
24
|
+
readonly jobId: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Full job status response
|
|
28
|
+
*/
|
|
29
|
+
export interface JobResponse {
|
|
30
|
+
readonly jobId: string;
|
|
31
|
+
readonly status: JobStatus;
|
|
32
|
+
readonly result?: RunResult;
|
|
33
|
+
readonly error?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Options for the run function
|
|
37
|
+
*/
|
|
38
|
+
export interface RunOptions {
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly maxDuration?: number;
|
|
41
|
+
readonly assetMap?: Record<string, string>;
|
|
42
|
+
readonly baseUrl?: string;
|
|
43
|
+
readonly timeoutMs?: number;
|
|
44
|
+
readonly pollIntervalMs?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Final result returned by the run function
|
|
48
|
+
*/
|
|
49
|
+
export interface RunFinalResult {
|
|
50
|
+
readonly jobId: string;
|
|
51
|
+
readonly logs: readonly string[];
|
|
52
|
+
readonly stopCause: string;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAA;AAEtE;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,iBAAiB,GAAG,sBAAsB,GAAG,UAAU,MAAM,EAAE,CAAA;CACpF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @drawcall/run - Client Types (Source of Truth)
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// These plain TypeScript types define the API contract.
|
|
5
|
+
// The server imports these and wraps them with Effect Schema for runtime validation.
|
|
6
|
+
// All properties are readonly to match Effect Schema's immutable output.
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,iDAAiD;AACjD,+EAA+E;AAC/E,wDAAwD;AACxD,qFAAqF;AACrF,yEAAyE"}
|
package/package.json
ADDED