cloudcruise 0.0.3 → 0.0.6
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/CloudCruise.d.ts +4 -0
- package/dist/CloudCruise.js +32 -2
- package/dist/events/types.d.ts +153 -0
- package/dist/events/types.js +22 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/runs/RunsClient.js +10 -2
- package/dist/runs/types.d.ts +25 -17
- package/dist/utils/connectionManager.js +13 -3
- package/dist/utils/events.d.ts +20 -3
- package/dist/utils/events.js +17 -0
- package/dist/webhook/WebhookClient.d.ts +3 -2
- package/dist/webhook/types.d.ts +0 -108
- package/dist/webhook/types.js +0 -13
- package/dist/webhook/utils.d.ts +3 -2
- package/package.json +7 -7
package/dist/CloudCruise.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ import { RunsClient } from './runs/RunsClient.js';
|
|
|
4
4
|
import { WebhookClient } from './webhook/WebhookClient.js';
|
|
5
5
|
export interface CloudCruiseParams {
|
|
6
6
|
apiKey?: string;
|
|
7
|
+
/**
|
|
8
|
+
* CloudCruise API base URL. Authenticated requests are restricted to the
|
|
9
|
+
* production CloudCruise API origin.
|
|
10
|
+
*/
|
|
7
11
|
baseUrl?: string;
|
|
8
12
|
encryptionKey?: string;
|
|
9
13
|
}
|
package/dist/CloudCruise.js
CHANGED
|
@@ -4,6 +4,34 @@ import { WorkflowsClient } from './workflows/WorkflowsClient.js';
|
|
|
4
4
|
import { RunsClient } from './runs/RunsClient.js';
|
|
5
5
|
import { WebhookClient } from './webhook/WebhookClient.js';
|
|
6
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
|
+
}
|
|
7
35
|
export class CloudCruise {
|
|
8
36
|
apiKey;
|
|
9
37
|
baseUrl;
|
|
@@ -15,7 +43,7 @@ export class CloudCruise {
|
|
|
15
43
|
connectionManager;
|
|
16
44
|
constructor(params) {
|
|
17
45
|
const apiKey = params?.apiKey ?? getEnv('CLOUDCRUISE_API_KEY');
|
|
18
|
-
const baseUrl = params?.baseUrl ?? getEnv('CLOUDCRUISE_BASE_URL') ??
|
|
46
|
+
const baseUrl = params?.baseUrl ?? getEnv('CLOUDCRUISE_BASE_URL') ?? DEFAULT_BASE_URL;
|
|
19
47
|
const encryptionKey = params?.encryptionKey ?? getEnv('CLOUDCRUISE_ENCRYPTION_KEY');
|
|
20
48
|
if (!apiKey) {
|
|
21
49
|
throw new Error('Missing apiKey. Provide via params.apiKey or CLOUDCRUISE_API_KEY env var.');
|
|
@@ -23,8 +51,10 @@ export class CloudCruise {
|
|
|
23
51
|
if (!encryptionKey) {
|
|
24
52
|
throw new Error('Missing encryptionKey. Provide via params.encryptionKey or CLOUDCRUISE_ENCRYPTION_KEY env var.');
|
|
25
53
|
}
|
|
54
|
+
const normalizedBaseUrl = normalizeBaseUrl(baseUrl);
|
|
55
|
+
assertBaseUrlAllowed(normalizedBaseUrl);
|
|
26
56
|
this.apiKey = apiKey;
|
|
27
|
-
this.baseUrl =
|
|
57
|
+
this.baseUrl = normalizedBaseUrl;
|
|
28
58
|
this.encryptionKey = encryptionKey;
|
|
29
59
|
// Initialize namespace clients
|
|
30
60
|
this.connectionManager = new ConnectionManager(this.baseUrl, this.apiKey);
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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
CHANGED
|
@@ -10,8 +10,9 @@ export { RunsClient } from './runs/RunsClient.js';
|
|
|
10
10
|
export { WebhookClient } from './webhook/WebhookClient.js';
|
|
11
11
|
export type { VaultEntry, GetVaultEntriesFilters, ProxyConfig, VaultPostPutHeadersInBody } from './vault/types.js';
|
|
12
12
|
export type { Workflow, WorkflowInputSchema, WorkflowMetadata } from './workflows/types.js';
|
|
13
|
-
export type {
|
|
14
|
-
export {
|
|
15
|
-
export type {
|
|
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';
|
|
16
17
|
export { VerificationError } from './webhook/types.js';
|
|
17
18
|
export { InputValidationError } from './workflows/types.js';
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { VaultClient } from './vault/VaultClient.js';
|
|
|
7
7
|
export { WorkflowsClient } from './workflows/WorkflowsClient.js';
|
|
8
8
|
export { RunsClient } from './runs/RunsClient.js';
|
|
9
9
|
export { WebhookClient } from './webhook/WebhookClient.js';
|
|
10
|
-
|
|
10
|
+
// Export shared event types
|
|
11
|
+
export { EventType } from './events/types.js';
|
|
11
12
|
export { VerificationError } from './webhook/types.js';
|
|
12
13
|
export { InputValidationError } from './workflows/types.js';
|
package/dist/runs/RunsClient.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventType } from '../events/types.js';
|
|
1
2
|
import { AsyncEventQueue } from '../utils/asyncQueue.js';
|
|
2
3
|
import { SimpleEventEmitter } from '../utils/events.js';
|
|
3
4
|
export class RunsClient {
|
|
@@ -37,7 +38,9 @@ export class RunsClient {
|
|
|
37
38
|
enabled: options?.reconnect?.enabled ?? true,
|
|
38
39
|
delays: options?.reconnect?.delays ?? [1000, 3000, 10000],
|
|
39
40
|
};
|
|
40
|
-
const isTerminalEvent = (status) => status ===
|
|
41
|
+
const isTerminalEvent = (status) => status === EventType.ExecutionSuccess ||
|
|
42
|
+
status === EventType.ExecutionFailed ||
|
|
43
|
+
status === EventType.ExecutionStopped;
|
|
41
44
|
const emit = (event, payload) => {
|
|
42
45
|
emitter.emit(event, payload);
|
|
43
46
|
// Mirror only SSE messages to 'message' for catch-all consumers
|
|
@@ -69,6 +72,11 @@ export class RunsClient {
|
|
|
69
72
|
return;
|
|
70
73
|
stream.push(sseMsg);
|
|
71
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 { }
|
|
72
80
|
const eventType = sseMsg.data.event;
|
|
73
81
|
if (typeof eventType === 'string' && isTerminalEvent(eventType)) {
|
|
74
82
|
endAndCleanup(eventType);
|
|
@@ -107,7 +115,7 @@ export class RunsClient {
|
|
|
107
115
|
}
|
|
108
116
|
else {
|
|
109
117
|
// End without explicit type; still clean up
|
|
110
|
-
endAndCleanup(
|
|
118
|
+
endAndCleanup(EventType.ExecutionStopped);
|
|
111
119
|
}
|
|
112
120
|
});
|
|
113
121
|
};
|
package/dist/runs/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CloudCruise Runs API Type Definitions
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import type { EventType, RunEventMessage, EventPayloadMap, ExecutionQueuedPayload, ExecutionStartPayload, ExecutionStepPayload, InteractionWaitingPayload, InteractionFinishedPayload, AgentErrorAnalysisPayload, ExecutionRequeuedPayload, EndRunPayload, EndRunError, ExecutionStoppedEarlyPayload, FileUploadedPayload, ScreenshotUploadedPayload } from '../events/types.js';
|
|
5
|
+
export type { EventType };
|
|
6
|
+
export type { ExecutionQueuedPayload, ExecutionStartPayload, ExecutionStepPayload, InteractionWaitingPayload, InteractionFinishedPayload, AgentErrorAnalysisPayload, ExecutionRequeuedPayload, EndRunPayload, EndRunError, ExecutionStoppedEarlyPayload, FileUploadedPayload, ScreenshotUploadedPayload, EventPayloadMap, };
|
|
5
7
|
export interface DryRun {
|
|
6
8
|
enabled: boolean;
|
|
7
9
|
add_to_output?: Record<string, any>;
|
|
@@ -69,6 +71,8 @@ export interface WorkflowError {
|
|
|
69
71
|
error_code?: string | null;
|
|
70
72
|
action_type?: string | null;
|
|
71
73
|
action_display_name?: string | null;
|
|
74
|
+
llm_error_category?: string | null;
|
|
75
|
+
original_error?: string | null;
|
|
72
76
|
}
|
|
73
77
|
export interface RunResult {
|
|
74
78
|
session_id: string;
|
|
@@ -109,27 +113,14 @@ export interface WebhookReplayResponse {
|
|
|
109
113
|
* Streaming (SSE) types
|
|
110
114
|
*/
|
|
111
115
|
export type SseEventName = 'run.event' | 'ping';
|
|
112
|
-
export
|
|
113
|
-
event: 'run.event';
|
|
114
|
-
data: {
|
|
115
|
-
event: EventType | string;
|
|
116
|
-
payload: {
|
|
117
|
-
session_id: string;
|
|
118
|
-
[key: string]: any;
|
|
119
|
-
};
|
|
120
|
-
expires_at: number;
|
|
121
|
-
timestamp: number;
|
|
122
|
-
};
|
|
123
|
-
timestamp?: string;
|
|
124
|
-
expires_at?: string;
|
|
125
|
-
}
|
|
116
|
+
export type RunEventEnvelope<E extends EventType = EventType> = RunEventMessage<E>;
|
|
126
117
|
export interface PingEnvelope {
|
|
127
118
|
event: 'ping';
|
|
128
119
|
data: {
|
|
129
120
|
ts: number;
|
|
130
121
|
} | Record<string, any>;
|
|
131
122
|
}
|
|
132
|
-
export type SseMessage = RunEventEnvelope | PingEnvelope;
|
|
123
|
+
export type SseMessage<E extends EventType = EventType> = RunEventEnvelope<E> | PingEnvelope;
|
|
133
124
|
export interface RunStreamOptions {
|
|
134
125
|
signal?: AbortSignal;
|
|
135
126
|
withCredentials?: boolean;
|
|
@@ -140,9 +131,26 @@ export interface RunStreamOptions {
|
|
|
140
131
|
jitter?: number;
|
|
141
132
|
};
|
|
142
133
|
}
|
|
134
|
+
export type RunEventMap = {
|
|
135
|
+
[K in EventType]: RunEventEnvelope<K>;
|
|
136
|
+
};
|
|
137
|
+
export type RunHandleEventMap = {
|
|
138
|
+
'open': undefined;
|
|
139
|
+
'close': undefined;
|
|
140
|
+
'reconnect': {
|
|
141
|
+
attemptDelayMs: number;
|
|
142
|
+
};
|
|
143
|
+
'error': unknown;
|
|
144
|
+
'end': {
|
|
145
|
+
type: EventType;
|
|
146
|
+
};
|
|
147
|
+
'run.event': SseMessage;
|
|
148
|
+
'ping': PingEnvelope;
|
|
149
|
+
'message': SseMessage | PingEnvelope;
|
|
150
|
+
} & RunEventMap;
|
|
143
151
|
export interface RunHandle {
|
|
144
152
|
sessionId: string;
|
|
145
|
-
on(event:
|
|
153
|
+
on<K extends keyof RunHandleEventMap>(event: K, handler: (e: RunHandleEventMap[K]) => void): () => void;
|
|
146
154
|
wait(): Promise<GetRunResult>;
|
|
147
155
|
close(): void;
|
|
148
156
|
[Symbol.asyncIterator](): AsyncIterator<SseMessage>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { openSSE } from './sse.js';
|
|
2
2
|
import { SimpleEventEmitter } from './events.js';
|
|
3
3
|
import { AsyncEventQueue } from './asyncQueue.js';
|
|
4
|
+
import { EventType } from '../events/types.js';
|
|
4
5
|
function isFinalEvent(eventType) {
|
|
5
|
-
return eventType ===
|
|
6
|
+
return (eventType === EventType.ExecutionSuccess ||
|
|
7
|
+
eventType === EventType.ExecutionFailed ||
|
|
8
|
+
eventType === EventType.ExecutionStopped);
|
|
6
9
|
}
|
|
7
10
|
export class ConnectionManager {
|
|
8
11
|
baseUrl;
|
|
@@ -144,7 +147,9 @@ export class ConnectionManager {
|
|
|
144
147
|
if (!data) {
|
|
145
148
|
return;
|
|
146
149
|
}
|
|
147
|
-
|
|
150
|
+
// Extract session_id - it's always present in payload
|
|
151
|
+
const payload = data.payload;
|
|
152
|
+
const sessionId = payload?.session_id;
|
|
148
153
|
if (!sessionId) {
|
|
149
154
|
return;
|
|
150
155
|
}
|
|
@@ -152,7 +157,12 @@ export class ConnectionManager {
|
|
|
152
157
|
if (!channel) {
|
|
153
158
|
return;
|
|
154
159
|
}
|
|
155
|
-
const msg = {
|
|
160
|
+
const msg = {
|
|
161
|
+
event: 'run.event',
|
|
162
|
+
data: data,
|
|
163
|
+
timestamp: raw.timestamp || new Date().toISOString(),
|
|
164
|
+
expires_at: raw.expires_at || new Date(Date.now() + 3600000).toISOString()
|
|
165
|
+
};
|
|
156
166
|
// fan-out to all subscribers
|
|
157
167
|
for (const q of channel.subscribers)
|
|
158
168
|
q.push(msg);
|
package/dist/utils/events.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
export type EventHandler<T = unknown> = (event: T) => void;
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Event emitter that supports both typed and untyped usage.
|
|
4
|
+
*
|
|
5
|
+
* - Use without type parameter for untyped events (backward compatible)
|
|
6
|
+
* - Use with EventMap type parameter for type-safe events
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Untyped usage
|
|
10
|
+
* const emitter = new SimpleEventEmitter();
|
|
11
|
+
* emitter.on('foo', (data) => console.log(data));
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Typed usage
|
|
15
|
+
* type Events = { foo: string; bar: number };
|
|
16
|
+
* const emitter = new SimpleEventEmitter<Events>();
|
|
17
|
+
* emitter.on('foo', (data) => console.log(data)); // data is string
|
|
18
|
+
*/
|
|
19
|
+
export declare class SimpleEventEmitter<EventMap extends Record<string, any> = Record<string, unknown>> {
|
|
3
20
|
private listeners;
|
|
4
|
-
on(event:
|
|
5
|
-
emit(event:
|
|
21
|
+
on<K extends keyof EventMap>(event: K, handler: EventHandler<EventMap[K]>): () => void;
|
|
22
|
+
emit<K extends keyof EventMap>(event: K, payload: EventMap[K]): void;
|
|
6
23
|
clear(): void;
|
|
7
24
|
}
|
package/dist/utils/events.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event emitter that supports both typed and untyped usage.
|
|
3
|
+
*
|
|
4
|
+
* - Use without type parameter for untyped events (backward compatible)
|
|
5
|
+
* - Use with EventMap type parameter for type-safe events
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* // Untyped usage
|
|
9
|
+
* const emitter = new SimpleEventEmitter();
|
|
10
|
+
* emitter.on('foo', (data) => console.log(data));
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Typed usage
|
|
14
|
+
* type Events = { foo: string; bar: number };
|
|
15
|
+
* const emitter = new SimpleEventEmitter<Events>();
|
|
16
|
+
* emitter.on('foo', (data) => console.log(data)); // data is string
|
|
17
|
+
*/
|
|
1
18
|
export class SimpleEventEmitter {
|
|
2
19
|
listeners = new Map();
|
|
3
20
|
on(event, handler) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { WebhookVerificationOptions } from './types.js';
|
|
2
|
+
import type { EventType, WebhookMessage } from '../events/types.js';
|
|
2
3
|
export declare class WebhookClient {
|
|
3
4
|
constructor();
|
|
4
5
|
/**
|
|
@@ -10,5 +11,5 @@ export declare class WebhookClient {
|
|
|
10
11
|
* @param options - Optional overrides controlling signature verification behavior.
|
|
11
12
|
* @returns Verified webhook payload when the signature matches.
|
|
12
13
|
*/
|
|
13
|
-
verifySignature<E extends
|
|
14
|
+
verifySignature<E extends EventType = EventType>(receivedData: any, receivedSignature: string, secretKey: string, options?: WebhookVerificationOptions): WebhookMessage<E>;
|
|
14
15
|
}
|
package/dist/webhook/types.d.ts
CHANGED
|
@@ -5,111 +5,3 @@ export declare class VerificationError extends Error {
|
|
|
5
5
|
export interface WebhookVerificationOptions {
|
|
6
6
|
allowExpired?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare enum WebhookEventType {
|
|
9
|
-
ExecutionQueued = "execution.queued",
|
|
10
|
-
ExecutionStart = "execution.start",
|
|
11
|
-
ExecutionStep = "execution.step",
|
|
12
|
-
InteractionWaiting = "interaction.waiting",
|
|
13
|
-
InteractionFinished = "interaction.finished",
|
|
14
|
-
AgentErrorAnalysis = "agent.error_analysis",
|
|
15
|
-
ExecutionRequeued = "execution.requeued",
|
|
16
|
-
ExecutionSuccess = "execution.success",
|
|
17
|
-
ExecutionFailed = "execution.failed",
|
|
18
|
-
ExecutionStopped = "execution.stopped"
|
|
19
|
-
}
|
|
20
|
-
export interface ExecutionQueuedPayload {
|
|
21
|
-
session_id: string;
|
|
22
|
-
workflow_id: string;
|
|
23
|
-
}
|
|
24
|
-
export interface ExecutionStartPayload {
|
|
25
|
-
session_id: string;
|
|
26
|
-
workflow_id: string;
|
|
27
|
-
live_view_url?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface ExecutionStepPayload {
|
|
30
|
-
session_id: string;
|
|
31
|
-
workflow_id: string;
|
|
32
|
-
current_step: string;
|
|
33
|
-
next_step: string;
|
|
34
|
-
}
|
|
35
|
-
export interface InteractionWaitingPayload {
|
|
36
|
-
session_id: string;
|
|
37
|
-
workflow_id: string;
|
|
38
|
-
current_step: string;
|
|
39
|
-
missing_properties: string[];
|
|
40
|
-
expected_json_schema_datamodel: Record<string, any>;
|
|
41
|
-
message: string;
|
|
42
|
-
}
|
|
43
|
-
export type InteractionFinishedPayload = {
|
|
44
|
-
session_id: string;
|
|
45
|
-
workflow_id: string;
|
|
46
|
-
current_step: string;
|
|
47
|
-
missing_properties: [];
|
|
48
|
-
expected_json_schema_datamodel: Record<string, any>;
|
|
49
|
-
message: string;
|
|
50
|
-
} | {
|
|
51
|
-
session_id: string;
|
|
52
|
-
workflow_id: string;
|
|
53
|
-
provided_input: any;
|
|
54
|
-
message?: string;
|
|
55
|
-
expected_json_schema_datamodel: Record<string, any>;
|
|
56
|
-
};
|
|
57
|
-
export interface AgentErrorAnalysisPayload {
|
|
58
|
-
analysis_step_name: string;
|
|
59
|
-
ai_analysis?: string;
|
|
60
|
-
root_cause_analysis?: string;
|
|
61
|
-
error_category?: string;
|
|
62
|
-
}
|
|
63
|
-
export interface ExecutionRequeuedPayload {
|
|
64
|
-
session_id: string;
|
|
65
|
-
workflow_id: string;
|
|
66
|
-
retry_attempt: number;
|
|
67
|
-
max_retries?: number;
|
|
68
|
-
next_execution_time: string;
|
|
69
|
-
delay_ms: number;
|
|
70
|
-
}
|
|
71
|
-
export interface EndRunError {
|
|
72
|
-
message: string;
|
|
73
|
-
error_id: string;
|
|
74
|
-
full_url?: string;
|
|
75
|
-
created_at: string;
|
|
76
|
-
error_code?: string;
|
|
77
|
-
action_type?: string;
|
|
78
|
-
action_display_name?: string;
|
|
79
|
-
llm_error_category?: string;
|
|
80
|
-
}
|
|
81
|
-
export interface EndRunPayload {
|
|
82
|
-
session_id: string;
|
|
83
|
-
workflow_id: string;
|
|
84
|
-
data: any;
|
|
85
|
-
input_variables: Record<string, any>;
|
|
86
|
-
errors: EndRunError[];
|
|
87
|
-
status: "execution.success" | "execution.failed" | "execution.stopped";
|
|
88
|
-
encrypted_variables: string[] | null;
|
|
89
|
-
file_urls: any[] | null;
|
|
90
|
-
}
|
|
91
|
-
export interface ExecutionStoppedEarlyPayload {
|
|
92
|
-
message: string;
|
|
93
|
-
error_code: string;
|
|
94
|
-
session_id: string;
|
|
95
|
-
}
|
|
96
|
-
export interface WebhookEnvelope<E extends WebhookEventType, P> {
|
|
97
|
-
event: E;
|
|
98
|
-
timestamp: number;
|
|
99
|
-
expires_at: number;
|
|
100
|
-
payload: P;
|
|
101
|
-
metadata?: Record<string, any>;
|
|
102
|
-
}
|
|
103
|
-
export type WebhookPayloadMap = {
|
|
104
|
-
[WebhookEventType.ExecutionQueued]: ExecutionQueuedPayload;
|
|
105
|
-
[WebhookEventType.ExecutionStart]: ExecutionStartPayload;
|
|
106
|
-
[WebhookEventType.ExecutionStep]: ExecutionStepPayload;
|
|
107
|
-
[WebhookEventType.InteractionWaiting]: InteractionWaitingPayload;
|
|
108
|
-
[WebhookEventType.InteractionFinished]: InteractionFinishedPayload;
|
|
109
|
-
[WebhookEventType.AgentErrorAnalysis]: AgentErrorAnalysisPayload;
|
|
110
|
-
[WebhookEventType.ExecutionRequeued]: ExecutionRequeuedPayload;
|
|
111
|
-
[WebhookEventType.ExecutionSuccess]: EndRunPayload;
|
|
112
|
-
[WebhookEventType.ExecutionFailed]: EndRunPayload;
|
|
113
|
-
[WebhookEventType.ExecutionStopped]: EndRunPayload | ExecutionStoppedEarlyPayload;
|
|
114
|
-
};
|
|
115
|
-
export type WebhookPayload<E extends WebhookEventType = WebhookEventType> = E extends WebhookEventType ? WebhookEnvelope<E, WebhookPayloadMap[E]> : never;
|
package/dist/webhook/types.js
CHANGED
|
@@ -6,16 +6,3 @@ export class VerificationError extends Error {
|
|
|
6
6
|
this.name = "VerificationError";
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export var WebhookEventType;
|
|
10
|
-
(function (WebhookEventType) {
|
|
11
|
-
WebhookEventType["ExecutionQueued"] = "execution.queued";
|
|
12
|
-
WebhookEventType["ExecutionStart"] = "execution.start";
|
|
13
|
-
WebhookEventType["ExecutionStep"] = "execution.step";
|
|
14
|
-
WebhookEventType["InteractionWaiting"] = "interaction.waiting";
|
|
15
|
-
WebhookEventType["InteractionFinished"] = "interaction.finished";
|
|
16
|
-
WebhookEventType["AgentErrorAnalysis"] = "agent.error_analysis";
|
|
17
|
-
WebhookEventType["ExecutionRequeued"] = "execution.requeued";
|
|
18
|
-
WebhookEventType["ExecutionSuccess"] = "execution.success";
|
|
19
|
-
WebhookEventType["ExecutionFailed"] = "execution.failed";
|
|
20
|
-
WebhookEventType["ExecutionStopped"] = "execution.stopped";
|
|
21
|
-
})(WebhookEventType || (WebhookEventType = {}));
|
package/dist/webhook/utils.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { EventType, WebhookMessage } from '../events/types.js';
|
|
2
|
+
import { type WebhookVerificationOptions } from './types.js';
|
|
3
|
+
export declare function verifyMessage<E extends EventType = EventType>(receivedData: any, receivedSignature: string, secretKey: string, options?: WebhookVerificationOptions): WebhookMessage<E>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudcruise",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
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
|
-
},
|
|
26
21
|
"devDependencies": {
|
|
27
22
|
"@types/node": "^20.0.0",
|
|
28
23
|
"typescript": "^5.0.0"
|
|
29
24
|
},
|
|
30
25
|
"engines": {
|
|
31
26
|
"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
|
+
}
|