cloudcruise 0.0.6 → 1.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/package.json +7 -7
- package/dist/CloudCruise.d.ts +0 -29
- package/dist/CloudCruise.js +0 -111
- package/dist/events/types.d.ts +0 -153
- package/dist/events/types.js +0 -22
- package/dist/index.d.ts +0 -18
- package/dist/index.js +0 -13
- package/dist/runs/RunsClient.d.ts +0 -42
- package/dist/runs/RunsClient.js +0 -200
- package/dist/runs/types.d.ts +0 -157
- package/dist/runs/types.js +0 -4
- package/dist/utils/asyncQueue.d.ts +0 -9
- package/dist/utils/asyncQueue.js +0 -43
- package/dist/utils/connectionManager.d.ts +0 -29
- package/dist/utils/connectionManager.js +0 -234
- package/dist/utils/env.d.ts +0 -2
- package/dist/utils/env.js +0 -9
- package/dist/utils/events.d.ts +0 -24
- package/dist/utils/events.js +0 -40
- package/dist/utils/sse.d.ts +0 -24
- package/dist/utils/sse.js +0 -122
- package/dist/vault/VaultClient.d.ts +0 -42
- package/dist/vault/VaultClient.js +0 -91
- package/dist/vault/types.d.ts +0 -50
- package/dist/vault/types.js +0 -4
- package/dist/vault/utils.d.ts +0 -33
- package/dist/vault/utils.js +0 -99
- package/dist/webhook/WebhookClient.d.ts +0 -15
- package/dist/webhook/WebhookClient.js +0 -18
- package/dist/webhook/types.d.ts +0 -7
- package/dist/webhook/types.js +0 -8
- package/dist/webhook/utils.d.ts +0 -3
- package/dist/webhook/utils.js +0 -49
- package/dist/workflows/WorkflowsClient.d.ts +0 -19
- package/dist/workflows/WorkflowsClient.js +0 -97
- package/dist/workflows/types.d.ts +0 -41
- package/dist/workflows/types.js +0 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcruise",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "The official CloudCruise JS/TS client.",
|
|
5
5
|
"homepage": "https://github.com/CloudCruise/cloudcruise-js#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"files": [
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"dev": "tsc --watch",
|
|
24
|
+
"test": "pnpm build && node --test test/*.test.js"
|
|
25
|
+
},
|
|
21
26
|
"devDependencies": {
|
|
22
27
|
"@types/node": "^20.0.0",
|
|
23
28
|
"typescript": "^5.0.0"
|
|
24
29
|
},
|
|
25
30
|
"engines": {
|
|
26
31
|
"node": ">=18.0.0"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "tsc",
|
|
30
|
-
"dev": "tsc --watch",
|
|
31
|
-
"test": "pnpm build && node --test test/*.test.js"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
package/dist/CloudCruise.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { VaultClient } from './vault/VaultClient.js';
|
|
2
|
-
import { WorkflowsClient } from './workflows/WorkflowsClient.js';
|
|
3
|
-
import { RunsClient } from './runs/RunsClient.js';
|
|
4
|
-
import { WebhookClient } from './webhook/WebhookClient.js';
|
|
5
|
-
export interface CloudCruiseParams {
|
|
6
|
-
apiKey?: string;
|
|
7
|
-
/**
|
|
8
|
-
* CloudCruise API base URL. Authenticated requests are restricted to the
|
|
9
|
-
* production CloudCruise API origin.
|
|
10
|
-
*/
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
encryptionKey?: string;
|
|
13
|
-
}
|
|
14
|
-
export declare class CloudCruise {
|
|
15
|
-
private readonly apiKey;
|
|
16
|
-
private readonly baseUrl;
|
|
17
|
-
private readonly encryptionKey;
|
|
18
|
-
readonly vault: VaultClient;
|
|
19
|
-
readonly workflows: WorkflowsClient;
|
|
20
|
-
readonly runs: RunsClient;
|
|
21
|
-
readonly webhook: WebhookClient;
|
|
22
|
-
private readonly connectionManager;
|
|
23
|
-
constructor(params?: CloudCruiseParams);
|
|
24
|
-
/**
|
|
25
|
-
* Makes an HTTP request to the CloudCruise API
|
|
26
|
-
* Automatically adds the cc-key header for authentication
|
|
27
|
-
*/
|
|
28
|
-
private makeRequest;
|
|
29
|
-
}
|
package/dist/CloudCruise.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { getEnv } from './utils/env.js';
|
|
2
|
-
import { VaultClient } from './vault/VaultClient.js';
|
|
3
|
-
import { WorkflowsClient } from './workflows/WorkflowsClient.js';
|
|
4
|
-
import { RunsClient } from './runs/RunsClient.js';
|
|
5
|
-
import { WebhookClient } from './webhook/WebhookClient.js';
|
|
6
|
-
import { ConnectionManager } from './utils/connectionManager.js';
|
|
7
|
-
const DEFAULT_BASE_URL = 'https://api.cloudcruise.com';
|
|
8
|
-
const DEFAULT_API_HOST = new URL(DEFAULT_BASE_URL).host.toLowerCase();
|
|
9
|
-
function normalizeBaseUrl(baseUrl) {
|
|
10
|
-
let url;
|
|
11
|
-
try {
|
|
12
|
-
url = new URL(baseUrl);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
throw new Error(`Invalid baseUrl: ${baseUrl}`);
|
|
16
|
-
}
|
|
17
|
-
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
18
|
-
throw new Error(`Invalid baseUrl protocol: ${url.protocol}. Use https: or http:.`);
|
|
19
|
-
}
|
|
20
|
-
url.search = '';
|
|
21
|
-
url.hash = '';
|
|
22
|
-
return url.toString().replace(/\/+$/, '');
|
|
23
|
-
}
|
|
24
|
-
function assertBaseUrlAllowed(baseUrl) {
|
|
25
|
-
const url = new URL(baseUrl);
|
|
26
|
-
const host = url.host.toLowerCase();
|
|
27
|
-
if (host === DEFAULT_API_HOST && url.protocol !== 'https:') {
|
|
28
|
-
throw new Error(`Refusing to send CloudCruise API key to "${baseUrl}". The default CloudCruise API host requires https:.`);
|
|
29
|
-
}
|
|
30
|
-
if (baseUrl !== DEFAULT_BASE_URL) {
|
|
31
|
-
throw new Error(`Refusing to send CloudCruise API key to unapproved baseUrl "${baseUrl}". ` +
|
|
32
|
-
`Authenticated requests are restricted to ${DEFAULT_BASE_URL}.`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export class CloudCruise {
|
|
36
|
-
apiKey;
|
|
37
|
-
baseUrl;
|
|
38
|
-
encryptionKey;
|
|
39
|
-
vault;
|
|
40
|
-
workflows;
|
|
41
|
-
runs;
|
|
42
|
-
webhook;
|
|
43
|
-
connectionManager;
|
|
44
|
-
constructor(params) {
|
|
45
|
-
const apiKey = params?.apiKey ?? getEnv('CLOUDCRUISE_API_KEY');
|
|
46
|
-
const baseUrl = params?.baseUrl ?? getEnv('CLOUDCRUISE_BASE_URL') ?? DEFAULT_BASE_URL;
|
|
47
|
-
const encryptionKey = params?.encryptionKey ?? getEnv('CLOUDCRUISE_ENCRYPTION_KEY');
|
|
48
|
-
if (!apiKey) {
|
|
49
|
-
throw new Error('Missing apiKey. Provide via params.apiKey or CLOUDCRUISE_API_KEY env var.');
|
|
50
|
-
}
|
|
51
|
-
if (!encryptionKey) {
|
|
52
|
-
throw new Error('Missing encryptionKey. Provide via params.encryptionKey or CLOUDCRUISE_ENCRYPTION_KEY env var.');
|
|
53
|
-
}
|
|
54
|
-
const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
|
|
55
|
-
assertBaseUrlAllowed(normalizedBaseUrl);
|
|
56
|
-
this.apiKey = apiKey;
|
|
57
|
-
this.baseUrl = normalizedBaseUrl;
|
|
58
|
-
this.encryptionKey = encryptionKey;
|
|
59
|
-
// Initialize namespace clients
|
|
60
|
-
this.connectionManager = new ConnectionManager(this.baseUrl, this.apiKey);
|
|
61
|
-
this.vault = new VaultClient(this.makeRequest.bind(this), this.encryptionKey);
|
|
62
|
-
this.workflows = new WorkflowsClient(this.makeRequest.bind(this));
|
|
63
|
-
this.runs = new RunsClient(this.connectionManager, this.makeRequest.bind(this), this.workflows);
|
|
64
|
-
this.webhook = new WebhookClient();
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Makes an HTTP request to the CloudCruise API
|
|
68
|
-
* Automatically adds the cc-key header for authentication
|
|
69
|
-
*/
|
|
70
|
-
async makeRequest(method, path, body) {
|
|
71
|
-
const url = `${this.baseUrl}${path}`;
|
|
72
|
-
const headers = {
|
|
73
|
-
'Content-Type': 'application/json',
|
|
74
|
-
'cc-key': this.apiKey
|
|
75
|
-
};
|
|
76
|
-
try {
|
|
77
|
-
const response = await fetch(url, {
|
|
78
|
-
method,
|
|
79
|
-
headers,
|
|
80
|
-
body: body ? JSON.stringify(body) : undefined
|
|
81
|
-
});
|
|
82
|
-
if (!response.ok) {
|
|
83
|
-
const errorText = await response.text();
|
|
84
|
-
let errorMessage = `HTTP ${response.status}: ${response.statusText}`;
|
|
85
|
-
try {
|
|
86
|
-
const errorJson = JSON.parse(errorText);
|
|
87
|
-
errorMessage = errorJson.message || errorJson.error || errorMessage;
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// Use HTTP status if we can't parse error response
|
|
91
|
-
}
|
|
92
|
-
throw new Error(errorMessage);
|
|
93
|
-
}
|
|
94
|
-
const contentType = response.headers.get('content-type');
|
|
95
|
-
if (contentType && contentType.includes('application/json')) {
|
|
96
|
-
return await response.json();
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
return await response.text();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
if (error instanceof Error) {
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
throw new Error(`Request failed: ${String(error)}`);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
package/dist/events/types.d.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Event Type Definitions
|
|
3
|
-
* Used by both Webhook and SSE Run event handlers
|
|
4
|
-
*/
|
|
5
|
-
export declare enum EventType {
|
|
6
|
-
ExecutionQueued = "execution.queued",
|
|
7
|
-
ExecutionStart = "execution.start",
|
|
8
|
-
ExecutionStep = "execution.step",
|
|
9
|
-
ExecutionPause = "execution.pause",
|
|
10
|
-
ExecutionStopped = "execution.stopped",
|
|
11
|
-
ExecutionFailed = "execution.failed",
|
|
12
|
-
ExecutionSuccess = "execution.success",
|
|
13
|
-
ExecutionRequeued = "execution.requeued",
|
|
14
|
-
FileUploaded = "file.uploaded",
|
|
15
|
-
ScreenshotUploaded = "screenshot.uploaded",
|
|
16
|
-
VideoUploaded = "video.uploaded",
|
|
17
|
-
InteractionWaiting = "interaction.waiting",
|
|
18
|
-
InteractionFinished = "interaction.finished",
|
|
19
|
-
InteractionFailed = "interaction.failed",
|
|
20
|
-
AgentErrorAnalysis = "agent.error_analysis"
|
|
21
|
-
}
|
|
22
|
-
export interface ExecutionQueuedPayload {
|
|
23
|
-
session_id: string;
|
|
24
|
-
workflow_id: string;
|
|
25
|
-
}
|
|
26
|
-
export interface ExecutionStartPayload {
|
|
27
|
-
session_id: string;
|
|
28
|
-
workflow_id: string;
|
|
29
|
-
live_view_url?: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ExecutionStepPayload {
|
|
32
|
-
session_id: string;
|
|
33
|
-
workflow_id: string;
|
|
34
|
-
current_step: string;
|
|
35
|
-
next_step: string;
|
|
36
|
-
}
|
|
37
|
-
export interface InteractionWaitingPayload {
|
|
38
|
-
session_id: string;
|
|
39
|
-
workflow_id: string;
|
|
40
|
-
current_step: string;
|
|
41
|
-
missing_properties: string[];
|
|
42
|
-
expected_json_schema_datamodel: Record<string, any>;
|
|
43
|
-
message: string;
|
|
44
|
-
}
|
|
45
|
-
export type InteractionFinishedPayload = {
|
|
46
|
-
session_id: string;
|
|
47
|
-
workflow_id: string;
|
|
48
|
-
current_step: string;
|
|
49
|
-
missing_properties: [];
|
|
50
|
-
expected_json_schema_datamodel: Record<string, any>;
|
|
51
|
-
message: string;
|
|
52
|
-
} | {
|
|
53
|
-
session_id: string;
|
|
54
|
-
workflow_id: string;
|
|
55
|
-
provided_input: any;
|
|
56
|
-
message?: string;
|
|
57
|
-
expected_json_schema_datamodel: Record<string, any>;
|
|
58
|
-
};
|
|
59
|
-
export interface AgentErrorAnalysisPayload {
|
|
60
|
-
analysis_step_name: string;
|
|
61
|
-
ai_analysis?: string;
|
|
62
|
-
root_cause_analysis?: string;
|
|
63
|
-
error_category?: string;
|
|
64
|
-
}
|
|
65
|
-
export interface ExecutionRequeuedPayload {
|
|
66
|
-
session_id: string;
|
|
67
|
-
workflow_id: string;
|
|
68
|
-
retry_attempt: number;
|
|
69
|
-
max_retries?: number;
|
|
70
|
-
next_execution_time: string;
|
|
71
|
-
delay_ms: number;
|
|
72
|
-
}
|
|
73
|
-
export interface EndRunError {
|
|
74
|
-
message: string;
|
|
75
|
-
error_id: string;
|
|
76
|
-
full_url?: string;
|
|
77
|
-
created_at: string;
|
|
78
|
-
error_code?: string;
|
|
79
|
-
action_type?: string;
|
|
80
|
-
action_display_name?: string;
|
|
81
|
-
llm_error_category?: string;
|
|
82
|
-
}
|
|
83
|
-
export interface EndRunPayload {
|
|
84
|
-
session_id: string;
|
|
85
|
-
workflow_id: string;
|
|
86
|
-
data: any;
|
|
87
|
-
input_variables: Record<string, any>;
|
|
88
|
-
errors: EndRunError[];
|
|
89
|
-
status: EventType.ExecutionSuccess | EventType.ExecutionFailed | EventType.ExecutionStopped;
|
|
90
|
-
encrypted_variables: string[] | null;
|
|
91
|
-
file_urls: any[] | null;
|
|
92
|
-
vault_entries: Record<string, any> | null;
|
|
93
|
-
}
|
|
94
|
-
export interface ExecutionStoppedEarlyPayload {
|
|
95
|
-
message: string;
|
|
96
|
-
error_code: string;
|
|
97
|
-
session_id: string;
|
|
98
|
-
}
|
|
99
|
-
export interface FileUploadedPayload {
|
|
100
|
-
signed_file_url: string;
|
|
101
|
-
file_name: string;
|
|
102
|
-
timestamp: string;
|
|
103
|
-
signed_file_url_expires: string;
|
|
104
|
-
metadata: Record<string, any>;
|
|
105
|
-
session_id: string;
|
|
106
|
-
}
|
|
107
|
-
export interface ScreenshotUploadedPayload {
|
|
108
|
-
screenshot_id: string;
|
|
109
|
-
signed_screenshot_url: string;
|
|
110
|
-
node_display_name: string;
|
|
111
|
-
node_id: string;
|
|
112
|
-
timestamp: string;
|
|
113
|
-
signed_screenshot_url_expires: string;
|
|
114
|
-
error_screenshot: boolean;
|
|
115
|
-
retry_index: number;
|
|
116
|
-
full_length_screenshot: boolean;
|
|
117
|
-
session_id: string;
|
|
118
|
-
}
|
|
119
|
-
export type EventPayloadMap = {
|
|
120
|
-
[EventType.ExecutionQueued]: ExecutionQueuedPayload;
|
|
121
|
-
[EventType.ExecutionStart]: ExecutionStartPayload;
|
|
122
|
-
[EventType.ExecutionStep]: ExecutionStepPayload;
|
|
123
|
-
[EventType.InteractionWaiting]: InteractionWaitingPayload;
|
|
124
|
-
[EventType.InteractionFinished]: InteractionFinishedPayload;
|
|
125
|
-
[EventType.AgentErrorAnalysis]: AgentErrorAnalysisPayload;
|
|
126
|
-
[EventType.ExecutionRequeued]: ExecutionRequeuedPayload;
|
|
127
|
-
[EventType.ExecutionSuccess]: EndRunPayload;
|
|
128
|
-
[EventType.ExecutionFailed]: EndRunPayload;
|
|
129
|
-
[EventType.ExecutionStopped]: EndRunPayload | ExecutionStoppedEarlyPayload;
|
|
130
|
-
[EventType.FileUploaded]: FileUploadedPayload;
|
|
131
|
-
[EventType.ScreenshotUploaded]: ScreenshotUploadedPayload;
|
|
132
|
-
[EventType.VideoUploaded]: never;
|
|
133
|
-
[EventType.ExecutionPause]: never;
|
|
134
|
-
[EventType.InteractionFailed]: never;
|
|
135
|
-
};
|
|
136
|
-
export type WebhookMessage<E extends EventType = EventType> = {
|
|
137
|
-
event: E;
|
|
138
|
-
timestamp: number;
|
|
139
|
-
expires_at: number;
|
|
140
|
-
payload: EventPayloadMap[E];
|
|
141
|
-
metadata?: Record<string, any>;
|
|
142
|
-
};
|
|
143
|
-
export type RunEventMessage<E extends EventType = EventType> = {
|
|
144
|
-
event: "run.event";
|
|
145
|
-
data: {
|
|
146
|
-
event: E;
|
|
147
|
-
payload: EventPayloadMap[E];
|
|
148
|
-
timestamp: number;
|
|
149
|
-
expires_at: number;
|
|
150
|
-
};
|
|
151
|
-
timestamp: string;
|
|
152
|
-
expires_at: string;
|
|
153
|
-
};
|
package/dist/events/types.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Event Type Definitions
|
|
3
|
-
* Used by both Webhook and SSE Run event handlers
|
|
4
|
-
*/
|
|
5
|
-
export var EventType;
|
|
6
|
-
(function (EventType) {
|
|
7
|
-
EventType["ExecutionQueued"] = "execution.queued";
|
|
8
|
-
EventType["ExecutionStart"] = "execution.start";
|
|
9
|
-
EventType["ExecutionStep"] = "execution.step";
|
|
10
|
-
EventType["ExecutionPause"] = "execution.pause";
|
|
11
|
-
EventType["ExecutionStopped"] = "execution.stopped";
|
|
12
|
-
EventType["ExecutionFailed"] = "execution.failed";
|
|
13
|
-
EventType["ExecutionSuccess"] = "execution.success";
|
|
14
|
-
EventType["ExecutionRequeued"] = "execution.requeued";
|
|
15
|
-
EventType["FileUploaded"] = "file.uploaded";
|
|
16
|
-
EventType["ScreenshotUploaded"] = "screenshot.uploaded";
|
|
17
|
-
EventType["VideoUploaded"] = "video.uploaded";
|
|
18
|
-
EventType["InteractionWaiting"] = "interaction.waiting";
|
|
19
|
-
EventType["InteractionFinished"] = "interaction.finished";
|
|
20
|
-
EventType["InteractionFailed"] = "interaction.failed";
|
|
21
|
-
EventType["AgentErrorAnalysis"] = "agent.error_analysis";
|
|
22
|
-
})(EventType || (EventType = {}));
|
package/dist/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CloudCruise JavaScript/TypeScript SDK
|
|
3
|
-
* Official client library for the CloudCruise Platform
|
|
4
|
-
*/
|
|
5
|
-
export { CloudCruise } from './CloudCruise.js';
|
|
6
|
-
export type { CloudCruiseParams } from './CloudCruise.js';
|
|
7
|
-
export { VaultClient } from './vault/VaultClient.js';
|
|
8
|
-
export { WorkflowsClient } from './workflows/WorkflowsClient.js';
|
|
9
|
-
export { RunsClient } from './runs/RunsClient.js';
|
|
10
|
-
export { WebhookClient } from './webhook/WebhookClient.js';
|
|
11
|
-
export type { VaultEntry, GetVaultEntriesFilters, ProxyConfig, VaultPostPutHeadersInBody } from './vault/types.js';
|
|
12
|
-
export type { Workflow, WorkflowInputSchema, WorkflowMetadata } from './workflows/types.js';
|
|
13
|
-
export type { DryRun, Metadata, RunSpecificWebhook, PayloadWebhook, StartRunRequest, StartRunResponse, UserInteractionData, VideoUrl, SignedFileUrl, SignedScreenshotUrl, RunError, WorkflowError, RunResult, GetRunResult, WebhookEvent, WebhookReplayResponse, RunHandle, RunStreamOptions, SseEventName, SseMessage, RunEventEnvelope, RunHandleEventMap } from './runs/types.js';
|
|
14
|
-
export { EventType } from './events/types.js';
|
|
15
|
-
export type { WebhookMessage, RunEventMessage } from './events/types.js';
|
|
16
|
-
export type { WebhookVerificationOptions } from './webhook/types.js';
|
|
17
|
-
export { VerificationError } from './webhook/types.js';
|
|
18
|
-
export { InputValidationError } from './workflows/types.js';
|
package/dist/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CloudCruise JavaScript/TypeScript SDK
|
|
3
|
-
* Official client library for the CloudCruise Platform
|
|
4
|
-
*/
|
|
5
|
-
export { CloudCruise } from './CloudCruise.js';
|
|
6
|
-
export { VaultClient } from './vault/VaultClient.js';
|
|
7
|
-
export { WorkflowsClient } from './workflows/WorkflowsClient.js';
|
|
8
|
-
export { RunsClient } from './runs/RunsClient.js';
|
|
9
|
-
export { WebhookClient } from './webhook/WebhookClient.js';
|
|
10
|
-
// Export shared event types
|
|
11
|
-
export { EventType } from './events/types.js';
|
|
12
|
-
export { VerificationError } from './webhook/types.js';
|
|
13
|
-
export { InputValidationError } from './workflows/types.js';
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { StartRunRequest, UserInteractionData, GetRunResult, WebhookReplayResponse, RunHandle, RunStreamOptions } from './types.js';
|
|
2
|
-
import { ConnectionManager } from '../utils/connectionManager.js';
|
|
3
|
-
export declare class RunsClient {
|
|
4
|
-
private readonly makeRequest;
|
|
5
|
-
private readonly workflows?;
|
|
6
|
-
private readonly connectionManager;
|
|
7
|
-
constructor(connectionManager: ConnectionManager, makeRequest: <T = any>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', path: string, body?: any) => Promise<T>, workflows?: {
|
|
8
|
-
validateWorkflowInput: (workflowId: string, payload: Record<string, any>) => Promise<void>;
|
|
9
|
-
});
|
|
10
|
-
/**
|
|
11
|
-
* Queues a new run and returns a RunHandle.
|
|
12
|
-
* The handle exposes sessionId immediately and subscribes to SSE under the hood.
|
|
13
|
-
*/
|
|
14
|
-
start(request: StartRunRequest, options?: RunStreamOptions): Promise<RunHandle>;
|
|
15
|
-
/**
|
|
16
|
-
* Subscribes to SSE events for a given session. Returns a handle with helpers.
|
|
17
|
-
*/
|
|
18
|
-
subscribeToSession(sessionId: string, options?: RunStreamOptions): RunHandle;
|
|
19
|
-
/**
|
|
20
|
-
* Submits user interaction data during an active run
|
|
21
|
-
* @param sessionId - The unique identifier for the workflow execution session
|
|
22
|
-
* @param data - User input data as key-value pairs
|
|
23
|
-
*/
|
|
24
|
-
submitUserInteraction(sessionId: string, data: UserInteractionData): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves comprehensive results and execution details for a specific run
|
|
27
|
-
* @param sessionId - The unique identifier for the workflow execution session
|
|
28
|
-
* @returns Promise resolving to complete run results
|
|
29
|
-
*/
|
|
30
|
-
getResults(sessionId: string): Promise<GetRunResult>;
|
|
31
|
-
/**
|
|
32
|
-
* Interrupts a running browser agent run
|
|
33
|
-
* @param sessionId - The unique identifier for the workflow execution session
|
|
34
|
-
*/
|
|
35
|
-
interrupt(sessionId: string): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Replays all webhooks that were sent during a session
|
|
38
|
-
* @param sessionId - The ID of the session to replay webhooks for
|
|
39
|
-
* @returns Promise resolving to webhook replay results
|
|
40
|
-
*/
|
|
41
|
-
replayWebhooks(sessionId: string): Promise<WebhookReplayResponse>;
|
|
42
|
-
}
|
package/dist/runs/RunsClient.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import { EventType } from '../events/types.js';
|
|
2
|
-
import { AsyncEventQueue } from '../utils/asyncQueue.js';
|
|
3
|
-
import { SimpleEventEmitter } from '../utils/events.js';
|
|
4
|
-
export class RunsClient {
|
|
5
|
-
makeRequest;
|
|
6
|
-
workflows;
|
|
7
|
-
connectionManager;
|
|
8
|
-
constructor(connectionManager, makeRequest, workflows) {
|
|
9
|
-
this.makeRequest = makeRequest;
|
|
10
|
-
this.workflows = workflows;
|
|
11
|
-
this.connectionManager = connectionManager;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Queues a new run and returns a RunHandle.
|
|
15
|
-
* The handle exposes sessionId immediately and subscribes to SSE under the hood.
|
|
16
|
-
*/
|
|
17
|
-
async start(request, options) {
|
|
18
|
-
if (this.workflows) {
|
|
19
|
-
await this.workflows.validateWorkflowInput(request.workflow_id, request.run_input_variables);
|
|
20
|
-
}
|
|
21
|
-
// Ensure client_id and connection are ready to avoid missing early events
|
|
22
|
-
const clientId = await this.connectionManager.ensureClientId();
|
|
23
|
-
await this.connectionManager.connectIfNeeded();
|
|
24
|
-
request.client_id = clientId;
|
|
25
|
-
const { session_id } = await this.makeRequest('POST', '/run', request);
|
|
26
|
-
return this.subscribeToSession(session_id, options);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Subscribes to SSE events for a given session. Returns a handle with helpers.
|
|
30
|
-
*/
|
|
31
|
-
subscribeToSession(sessionId, options) {
|
|
32
|
-
const emitter = new SimpleEventEmitter();
|
|
33
|
-
const stream = new AsyncEventQueue();
|
|
34
|
-
let ended = false;
|
|
35
|
-
let closed = false;
|
|
36
|
-
let sub = null;
|
|
37
|
-
const reconnectCfg = {
|
|
38
|
-
enabled: options?.reconnect?.enabled ?? true,
|
|
39
|
-
delays: options?.reconnect?.delays ?? [1000, 3000, 10000],
|
|
40
|
-
};
|
|
41
|
-
const isTerminalEvent = (status) => status === EventType.ExecutionSuccess ||
|
|
42
|
-
status === EventType.ExecutionFailed ||
|
|
43
|
-
status === EventType.ExecutionStopped;
|
|
44
|
-
const emit = (event, payload) => {
|
|
45
|
-
emitter.emit(event, payload);
|
|
46
|
-
// Mirror only SSE messages to 'message' for catch-all consumers
|
|
47
|
-
if (event === 'run.event' || event === 'ping') {
|
|
48
|
-
emitter.emit('message', payload);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const endAndCleanup = (status) => {
|
|
52
|
-
if (ended)
|
|
53
|
-
return;
|
|
54
|
-
ended = true;
|
|
55
|
-
closed = true;
|
|
56
|
-
try {
|
|
57
|
-
sub?.close();
|
|
58
|
-
}
|
|
59
|
-
catch { }
|
|
60
|
-
emit('end', { type: status });
|
|
61
|
-
stream.close();
|
|
62
|
-
emitter.clear();
|
|
63
|
-
};
|
|
64
|
-
const connect = () => {
|
|
65
|
-
sub = this.connectionManager.subscribe(sessionId, { signal: options?.signal });
|
|
66
|
-
const s = sub;
|
|
67
|
-
s.on('open', () => emit('open', undefined));
|
|
68
|
-
s.on('ping', (evt) => emit('ping', evt));
|
|
69
|
-
s.on('run.event', (msg) => {
|
|
70
|
-
const sseMsg = msg;
|
|
71
|
-
if (sseMsg.event !== 'run.event')
|
|
72
|
-
return;
|
|
73
|
-
stream.push(sseMsg);
|
|
74
|
-
emit('run.event', sseMsg);
|
|
75
|
-
// Emit typed per-event key for better DX
|
|
76
|
-
try {
|
|
77
|
-
emitter.emit(sseMsg.data.event, sseMsg);
|
|
78
|
-
}
|
|
79
|
-
catch { }
|
|
80
|
-
const eventType = sseMsg.data.event;
|
|
81
|
-
if (typeof eventType === 'string' && isTerminalEvent(eventType)) {
|
|
82
|
-
endAndCleanup(eventType);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
s.on('error', (err) => {
|
|
86
|
-
emit('error', err);
|
|
87
|
-
if (!reconnectCfg.enabled || ended || closed)
|
|
88
|
-
return;
|
|
89
|
-
(async () => {
|
|
90
|
-
for (const base of reconnectCfg.delays) {
|
|
91
|
-
if (ended || closed)
|
|
92
|
-
return;
|
|
93
|
-
await new Promise(r => setTimeout(r, base));
|
|
94
|
-
if (ended || closed)
|
|
95
|
-
return;
|
|
96
|
-
try {
|
|
97
|
-
const snapshot = await this.getResults(sessionId);
|
|
98
|
-
const status = snapshot?.status;
|
|
99
|
-
if (isTerminalEvent(status)) {
|
|
100
|
-
endAndCleanup(status);
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
catch { }
|
|
105
|
-
emit('reconnect', { attemptDelayMs: base });
|
|
106
|
-
return; // manager handles reconnect of mux
|
|
107
|
-
}
|
|
108
|
-
})();
|
|
109
|
-
});
|
|
110
|
-
s.on('reconnect', (e) => emit('reconnect', e));
|
|
111
|
-
s.on('end', (e) => {
|
|
112
|
-
const t = e?.type;
|
|
113
|
-
if (t && typeof t === 'string' && isTerminalEvent(t)) {
|
|
114
|
-
endAndCleanup(t);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
// End without explicit type; still clean up
|
|
118
|
-
endAndCleanup(EventType.ExecutionStopped);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
connect();
|
|
123
|
-
const client = this;
|
|
124
|
-
const handle = {
|
|
125
|
-
sessionId,
|
|
126
|
-
on: (event, handler) => emitter.on(event, handler),
|
|
127
|
-
async wait() {
|
|
128
|
-
if (ended) {
|
|
129
|
-
return await client.getResults(sessionId);
|
|
130
|
-
}
|
|
131
|
-
return await new Promise((resolve, reject) => {
|
|
132
|
-
const offEnd = handle.on('end', async () => {
|
|
133
|
-
offErr();
|
|
134
|
-
try {
|
|
135
|
-
const result = await client.getResults(sessionId);
|
|
136
|
-
resolve(result);
|
|
137
|
-
}
|
|
138
|
-
catch (e) {
|
|
139
|
-
reject(e);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
const offErr = handle.on('error', (e) => {
|
|
143
|
-
offEnd();
|
|
144
|
-
reject(e instanceof Error ? e : new Error('SSE error'));
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
},
|
|
148
|
-
close() {
|
|
149
|
-
closed = true;
|
|
150
|
-
try {
|
|
151
|
-
sub?.close();
|
|
152
|
-
}
|
|
153
|
-
catch { }
|
|
154
|
-
stream.close();
|
|
155
|
-
emitter.clear();
|
|
156
|
-
},
|
|
157
|
-
async *[Symbol.asyncIterator]() {
|
|
158
|
-
for await (const msg of stream) {
|
|
159
|
-
yield msg;
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
return handle;
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Submits user interaction data during an active run
|
|
167
|
-
* @param sessionId - The unique identifier for the workflow execution session
|
|
168
|
-
* @param data - User input data as key-value pairs
|
|
169
|
-
*/
|
|
170
|
-
async submitUserInteraction(sessionId, data) {
|
|
171
|
-
const path = `/run/${sessionId}/user_interaction`;
|
|
172
|
-
await this.makeRequest('POST', path, data);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Retrieves comprehensive results and execution details for a specific run
|
|
176
|
-
* @param sessionId - The unique identifier for the workflow execution session
|
|
177
|
-
* @returns Promise resolving to complete run results
|
|
178
|
-
*/
|
|
179
|
-
async getResults(sessionId) {
|
|
180
|
-
const path = `/run/${sessionId}`;
|
|
181
|
-
return await this.makeRequest('GET', path);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Interrupts a running browser agent run
|
|
185
|
-
* @param sessionId - The unique identifier for the workflow execution session
|
|
186
|
-
*/
|
|
187
|
-
async interrupt(sessionId) {
|
|
188
|
-
const path = `/run/${sessionId}/interrupt`;
|
|
189
|
-
await this.makeRequest('POST', path);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Replays all webhooks that were sent during a session
|
|
193
|
-
* @param sessionId - The ID of the session to replay webhooks for
|
|
194
|
-
* @returns Promise resolving to webhook replay results
|
|
195
|
-
*/
|
|
196
|
-
async replayWebhooks(sessionId) {
|
|
197
|
-
const path = `/webhooks/${sessionId}/replay`;
|
|
198
|
-
return await this.makeRequest('POST', path);
|
|
199
|
-
}
|
|
200
|
-
}
|