asteroid-odyssey 1.0.24 → 1.0.25
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/generated/agents/client.gen.js +3 -1
- package/dist/generated/agents/sdk.gen.d.ts +8 -91
- package/dist/generated/agents/sdk.gen.js +31 -226
- package/dist/generated/agents/types.gen.d.ts +71 -741
- package/dist/index.d.ts +16 -58
- package/dist/index.js +36 -97
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Client } from '@hey-api/client-fetch';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AgentExecutionRequest, ExecutionStatusResponse } from './generated/agents/types.gen';
|
|
3
3
|
/**
|
|
4
4
|
* Create an API client with a provided API key.
|
|
5
5
|
*
|
|
@@ -13,91 +13,49 @@ export declare const AsteroidClient: (apiKey: string, options?: {
|
|
|
13
13
|
baseUrl?: string;
|
|
14
14
|
}) => Client;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Execute an agent with the provided parameters.
|
|
17
17
|
*
|
|
18
18
|
* @param client - The API client.
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @returns The ID of the created workflow.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const workflowId = await createNewWorkflow(client, 'my-agent', {
|
|
25
|
-
* name: "Example Workflow",
|
|
26
|
-
* start_url: "https://google.com",
|
|
27
|
-
* prompts: ["On Google, search for {{.website}} and sign in with {{.credentials}}"],
|
|
28
|
-
* result_schema: {},
|
|
29
|
-
* provider: 'openai'
|
|
30
|
-
* });
|
|
31
|
-
*/
|
|
32
|
-
export declare const createNewWorkflow: (client: Client, agentName: string, workflowDetails: CreateWorkflowRequest) => Promise<string>;
|
|
33
|
-
/**
|
|
34
|
-
* Execute an existing workflow.
|
|
35
|
-
*
|
|
36
|
-
* @param client - The API client.
|
|
37
|
-
* @param workflowId - The workflow identifier.
|
|
38
|
-
* @param executionData - The dynamic data to merge with the workflow.
|
|
19
|
+
* @param agentId - The ID of the agent to execute.
|
|
20
|
+
* @param executionData - The execution parameters.
|
|
39
21
|
* @returns The execution ID.
|
|
40
22
|
*
|
|
41
23
|
* @example
|
|
42
|
-
* const executionId = await
|
|
43
|
-
*/
|
|
44
|
-
export declare const executeWorkflowById: (client: Client, workflowId: string, executionData: WorkflowExecutionRequest) => Promise<string>;
|
|
45
|
-
/**
|
|
46
|
-
* Get the current status and details for a workflow execution.
|
|
47
|
-
*
|
|
48
|
-
* @param client - The API client.
|
|
49
|
-
* @param executionId - The execution identifier.
|
|
50
|
-
* @returns The execution details.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* const execution = await getExecutionStatus(client, executionId);
|
|
54
|
-
* console.log(execution.status);
|
|
24
|
+
* const executionId = await executeAgent(client, 'my-agent-id', { input: "some dynamic value" });
|
|
55
25
|
*/
|
|
56
|
-
export declare const
|
|
26
|
+
export declare const executeAgent: (client: Client, agentId: string, executionData: AgentExecutionRequest) => Promise<string>;
|
|
57
27
|
/**
|
|
58
|
-
* Get the
|
|
28
|
+
* Get the current status for an execution.
|
|
59
29
|
*
|
|
60
30
|
* @param client - The API client.
|
|
61
31
|
* @param executionId - The execution identifier.
|
|
62
|
-
* @returns
|
|
32
|
+
* @returns The execution status details.
|
|
63
33
|
*
|
|
64
34
|
* @example
|
|
65
|
-
* const
|
|
66
|
-
* console.log(
|
|
35
|
+
* const status = await getExecutionStatus(client, executionId);
|
|
36
|
+
* console.log(status.status);
|
|
67
37
|
*/
|
|
68
|
-
export declare const
|
|
69
|
-
execution_id: string;
|
|
70
|
-
progress: string;
|
|
71
|
-
created_at: string;
|
|
72
|
-
}>>;
|
|
38
|
+
export declare const getExecutionStatus: (client: Client, executionId: string) => Promise<ExecutionStatusResponse>;
|
|
73
39
|
/**
|
|
74
|
-
* Get the final result of
|
|
40
|
+
* Get the final result of an execution.
|
|
75
41
|
*
|
|
76
42
|
* @param client - The API client.
|
|
77
43
|
* @param executionId - The execution identifier.
|
|
78
44
|
* @returns The result object of the execution.
|
|
79
45
|
*
|
|
80
46
|
* @example
|
|
81
|
-
* const result = await
|
|
47
|
+
* const result = await getExecutionResult(client, executionId);
|
|
82
48
|
* console.log(result);
|
|
83
49
|
*/
|
|
84
|
-
export declare const
|
|
85
|
-
/**
|
|
86
|
-
* Get the browser session for an execution.
|
|
87
|
-
*
|
|
88
|
-
* @param client - The API client.
|
|
89
|
-
* @param executionId - The execution identifier.
|
|
90
|
-
* @returns The browser session.
|
|
91
|
-
*/
|
|
92
|
-
export declare const getBrowserSession: (client: Client, executionId: string) => Promise<BrowserSession>;
|
|
50
|
+
export declare const getExecutionResult: (client: Client, executionId: string) => Promise<Record<string, unknown>>;
|
|
93
51
|
/**
|
|
94
|
-
* Waits for
|
|
52
|
+
* Waits for an execution to reach a terminal state and returns the result.
|
|
95
53
|
* Continuously polls the execution status until it's either "completed", "cancelled", or "failed".
|
|
96
54
|
*
|
|
97
55
|
* @param client - The API client.
|
|
98
56
|
* @param executionId - The execution identifier.
|
|
99
57
|
* @param interval - Polling interval in milliseconds (default is 1000ms).
|
|
100
|
-
* @returns A promise that resolves with the
|
|
58
|
+
* @returns A promise that resolves with the execution result if completed.
|
|
101
59
|
* @throws An error if the execution ends as "cancelled" or "failed".
|
|
102
60
|
*
|
|
103
61
|
* @example
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
36
36
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.waitForExecutionResult = exports.
|
|
39
|
+
exports.waitForExecutionResult = exports.getExecutionResult = exports.getExecutionStatus = exports.executeAgent = exports.AsteroidClient = void 0;
|
|
40
40
|
const client_fetch_1 = require("@hey-api/client-fetch");
|
|
41
41
|
const AgentsSDK = __importStar(require("./generated/agents/sdk.gen"));
|
|
42
42
|
/**
|
|
@@ -58,144 +58,83 @@ const AsteroidClient = (apiKey, options) => {
|
|
|
58
58
|
};
|
|
59
59
|
exports.AsteroidClient = AsteroidClient;
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* Execute an agent with the provided parameters.
|
|
62
62
|
*
|
|
63
63
|
* @param client - The API client.
|
|
64
|
-
* @param
|
|
65
|
-
* @param
|
|
66
|
-
* @returns The ID of the created workflow.
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* const workflowId = await createNewWorkflow(client, 'my-agent', {
|
|
70
|
-
* name: "Example Workflow",
|
|
71
|
-
* start_url: "https://google.com",
|
|
72
|
-
* prompts: ["On Google, search for {{.website}} and sign in with {{.credentials}}"],
|
|
73
|
-
* result_schema: {},
|
|
74
|
-
* provider: 'openai'
|
|
75
|
-
* });
|
|
76
|
-
*/
|
|
77
|
-
const createNewWorkflow = async (client, agentName, workflowDetails) => {
|
|
78
|
-
const response = await AgentsSDK.createWorkflow({
|
|
79
|
-
client,
|
|
80
|
-
path: { agent_name: agentName },
|
|
81
|
-
body: workflowDetails,
|
|
82
|
-
});
|
|
83
|
-
if (response.error) {
|
|
84
|
-
console.log(response.error);
|
|
85
|
-
throw new Error(response.error);
|
|
86
|
-
}
|
|
87
|
-
return response.data;
|
|
88
|
-
};
|
|
89
|
-
exports.createNewWorkflow = createNewWorkflow;
|
|
90
|
-
/**
|
|
91
|
-
* Execute an existing workflow.
|
|
92
|
-
*
|
|
93
|
-
* @param client - The API client.
|
|
94
|
-
* @param workflowId - The workflow identifier.
|
|
95
|
-
* @param executionData - The dynamic data to merge with the workflow.
|
|
64
|
+
* @param agentId - The ID of the agent to execute.
|
|
65
|
+
* @param executionData - The execution parameters.
|
|
96
66
|
* @returns The execution ID.
|
|
97
67
|
*
|
|
98
68
|
* @example
|
|
99
|
-
* const executionId = await
|
|
69
|
+
* const executionId = await executeAgent(client, 'my-agent-id', { input: "some dynamic value" });
|
|
100
70
|
*/
|
|
101
|
-
const
|
|
102
|
-
const response = await AgentsSDK.
|
|
71
|
+
const executeAgent = async (client, agentId, executionData) => {
|
|
72
|
+
const response = await AgentsSDK.executeAgent({
|
|
103
73
|
client,
|
|
104
|
-
path: {
|
|
74
|
+
path: { id: agentId },
|
|
105
75
|
body: executionData,
|
|
106
76
|
});
|
|
107
77
|
if (response.error) {
|
|
108
|
-
throw new Error(response.error);
|
|
78
|
+
throw new Error(response.error.error);
|
|
109
79
|
}
|
|
110
|
-
return response.data;
|
|
80
|
+
return response.data.execution_id;
|
|
111
81
|
};
|
|
112
|
-
exports.
|
|
82
|
+
exports.executeAgent = executeAgent;
|
|
113
83
|
/**
|
|
114
|
-
* Get the current status
|
|
84
|
+
* Get the current status for an execution.
|
|
115
85
|
*
|
|
116
86
|
* @param client - The API client.
|
|
117
87
|
* @param executionId - The execution identifier.
|
|
118
|
-
* @returns The execution details.
|
|
88
|
+
* @returns The execution status details.
|
|
119
89
|
*
|
|
120
90
|
* @example
|
|
121
|
-
* const
|
|
122
|
-
* console.log(
|
|
91
|
+
* const status = await getExecutionStatus(client, executionId);
|
|
92
|
+
* console.log(status.status);
|
|
123
93
|
*/
|
|
124
94
|
const getExecutionStatus = async (client, executionId) => {
|
|
125
|
-
const
|
|
95
|
+
const response = await AgentsSDK.getExecutionStatus({
|
|
126
96
|
client,
|
|
127
97
|
path: { id: executionId },
|
|
128
98
|
});
|
|
129
|
-
if (
|
|
130
|
-
throw new Error(
|
|
99
|
+
if (response.error) {
|
|
100
|
+
throw new Error(response.error.error);
|
|
131
101
|
}
|
|
132
|
-
return
|
|
102
|
+
return response.data;
|
|
133
103
|
};
|
|
134
104
|
exports.getExecutionStatus = getExecutionStatus;
|
|
135
105
|
/**
|
|
136
|
-
* Get the
|
|
137
|
-
*
|
|
138
|
-
* @param client - The API client.
|
|
139
|
-
* @param executionId - The execution identifier.
|
|
140
|
-
* @returns Array of progress update objects.
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* const progressUpdates = await getWorkflowExecutionProgress(client, executionId);
|
|
144
|
-
* console.log(progressUpdates);
|
|
145
|
-
*/
|
|
146
|
-
const getWorkflowExecutionProgress = async (client, executionId) => {
|
|
147
|
-
const progressUpdates = await AgentsSDK.getExecutionProgress({
|
|
148
|
-
client,
|
|
149
|
-
path: { id: executionId },
|
|
150
|
-
});
|
|
151
|
-
if (progressUpdates.error) {
|
|
152
|
-
throw new Error(progressUpdates.error);
|
|
153
|
-
}
|
|
154
|
-
return progressUpdates.data;
|
|
155
|
-
};
|
|
156
|
-
exports.getWorkflowExecutionProgress = getWorkflowExecutionProgress;
|
|
157
|
-
/**
|
|
158
|
-
* Get the final result of a workflow execution.
|
|
106
|
+
* Get the final result of an execution.
|
|
159
107
|
*
|
|
160
108
|
* @param client - The API client.
|
|
161
109
|
* @param executionId - The execution identifier.
|
|
162
110
|
* @returns The result object of the execution.
|
|
163
111
|
*
|
|
164
112
|
* @example
|
|
165
|
-
* const result = await
|
|
113
|
+
* const result = await getExecutionResult(client, executionId);
|
|
166
114
|
* console.log(result);
|
|
167
115
|
*/
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
return execution.result;
|
|
171
|
-
};
|
|
172
|
-
exports.getWorkflowResult = getWorkflowResult;
|
|
173
|
-
/**
|
|
174
|
-
* Get the browser session for an execution.
|
|
175
|
-
*
|
|
176
|
-
* @param client - The API client.
|
|
177
|
-
* @param executionId - The execution identifier.
|
|
178
|
-
* @returns The browser session.
|
|
179
|
-
*/
|
|
180
|
-
const getBrowserSession = async (client, executionId) => {
|
|
181
|
-
const browserSession = await AgentsSDK.getBrowserSession({
|
|
116
|
+
const getExecutionResult = async (client, executionId) => {
|
|
117
|
+
const response = await AgentsSDK.getExecutionResult({
|
|
182
118
|
client,
|
|
183
119
|
path: { id: executionId },
|
|
184
120
|
});
|
|
185
|
-
if (
|
|
186
|
-
throw new Error(
|
|
121
|
+
if (response.error) {
|
|
122
|
+
throw new Error(response.error.error);
|
|
123
|
+
}
|
|
124
|
+
if (response.data.error) {
|
|
125
|
+
throw new Error(response.data.error);
|
|
187
126
|
}
|
|
188
|
-
return
|
|
127
|
+
return response.data.result || {};
|
|
189
128
|
};
|
|
190
|
-
exports.
|
|
129
|
+
exports.getExecutionResult = getExecutionResult;
|
|
191
130
|
/**
|
|
192
|
-
* Waits for
|
|
131
|
+
* Waits for an execution to reach a terminal state and returns the result.
|
|
193
132
|
* Continuously polls the execution status until it's either "completed", "cancelled", or "failed".
|
|
194
133
|
*
|
|
195
134
|
* @param client - The API client.
|
|
196
135
|
* @param executionId - The execution identifier.
|
|
197
136
|
* @param interval - Polling interval in milliseconds (default is 1000ms).
|
|
198
|
-
* @returns A promise that resolves with the
|
|
137
|
+
* @returns A promise that resolves with the execution result if completed.
|
|
199
138
|
* @throws An error if the execution ends as "cancelled" or "failed".
|
|
200
139
|
*
|
|
201
140
|
* @example
|
|
@@ -206,13 +145,13 @@ const waitForExecutionResult = async (client, executionId, interval = 1000, time
|
|
|
206
145
|
var steps = Math.floor(timeout / interval);
|
|
207
146
|
// Keep polling the execution status until it's either "completed", "cancelled", or "failed".
|
|
208
147
|
while (steps > 0) {
|
|
209
|
-
const
|
|
210
|
-
const currentStatus =
|
|
148
|
+
const status = await (0, exports.getExecutionStatus)(client, executionId);
|
|
149
|
+
const currentStatus = status.status;
|
|
211
150
|
if (currentStatus === 'completed') {
|
|
212
|
-
return await (0, exports.
|
|
151
|
+
return await (0, exports.getExecutionResult)(client, executionId);
|
|
213
152
|
}
|
|
214
153
|
else if (currentStatus === 'failed' || currentStatus === 'cancelled') {
|
|
215
|
-
throw new Error(`Execution ${executionId} ended with status: ${currentStatus}${
|
|
154
|
+
throw new Error(`Execution ${executionId} ended with status: ${currentStatus}${status.reason ? ' - ' + status.reason : ''}`);
|
|
216
155
|
}
|
|
217
156
|
// Wait for the specified interval before polling again
|
|
218
157
|
await new Promise(resolve => setTimeout(resolve, interval));
|