asteroid-odyssey 1.0.14 → 1.0.17

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 CHANGED
@@ -1,70 +1,101 @@
1
- import { OpenAPI as AgentsOpenAPI } from './generated/agents';
2
- import { OpenAPI as PlatformOpenAPI } from './generated/platform';
3
- import type { Agent } from './generated/agents/models/Agent';
4
- import type { CreateWorkflowRequest } from './generated/agents/models/CreateWorkflowRequest';
5
- import type { WorkflowExecutionRequest } from './generated/agents/models/WorkflowExecutionRequest';
6
- import type { WorkflowExecution } from './generated/agents/models/WorkflowExecution';
7
- import type { Status } from './generated/platform/models/Status';
8
- import type { FeedbackRequest } from './generated/platform/models/FeedbackRequest';
9
- import type { Feedback } from './generated/platform/models/Feedback';
1
+ import type { Client } from '@hey-api/client-fetch';
2
+ import type { CreateWorkflowRequest, WorkflowExecutionRequest, Execution } from './generated/agents/types.gen';
10
3
  /**
11
- * AgentsSDK provides a simple interface for interacting with the Asteroid Agents API.
12
- * It wraps the generated client services and exposes high-level methods.
4
+ * Create an API client with a provided API key.
5
+ *
6
+ * @param apiKey - Your API key.
7
+ * @returns A configured API client.
8
+ *
9
+ * @example
10
+ * const client = AsteroidClient('your-api-key');
13
11
  */
14
- export declare class AsteroidAgents {
15
- /**
16
- * Optionally pass a custom OpenAPI config. For instance, to change the API base URL.
17
- * @param config Partial OpenAPI config values.
18
- */
19
- constructor(apiKey: string, agentsConfig?: Partial<typeof AgentsOpenAPI>, platformConfig?: Partial<typeof PlatformOpenAPI>);
20
- /**
21
- * Retrieves the OpenAPI schema from the API.
22
- * @returns The OpenAPI specification.
23
- */
24
- getOpenApiSchema(): Promise<any>;
25
- /**
26
- * Checks the health of the API.
27
- * @returns An object containing the health status.
28
- */
29
- healthCheck(): Promise<{
30
- status?: string;
31
- }>;
32
- /**
33
- * Retrieves a list of all agents.
34
- * @returns An array of agents.
35
- */
36
- getAgents(): Promise<Agent[]>;
37
- /**
38
- * Creates a new workflow for a given agent.
39
- * @param agentName The name of the agent for which the workflow is created.
40
- * @param request The workflow creation request.
41
- * @returns The ID of the newly created workflow.
42
- */
43
- createWorkflow(agentName: string, request: CreateWorkflowRequest): Promise<string>;
44
- /**
45
- * Executes a saved workflow for an agent.
46
- * @param workflowId The ID of the workflow to execute.
47
- * @param request The execution request containing dynamic values.
48
- * @returns A string indicating that the job was queued.
49
- */
50
- runWorkflow(workflowId: string, request: WorkflowExecutionRequest): Promise<string>;
51
- /**
52
- * Retrieves all workflows along with their executions.
53
- * @returns An array containing workflow executions.
54
- */
55
- getWorkflowRuns(): Promise<WorkflowExecution[]>;
56
- /**
57
- * Retrieves the status of a run.
58
- * @param runId The ID of the run to retrieve the status for.
59
- * @returns The status of the run.
60
- */
61
- getRunStatus(runId: string): Promise<Status>;
62
- getRunResult(runId: string): Promise<string>;
63
- /**
64
- * Creates feedback for a run.
65
- * @param runId The ID of the run to create feedback for.
66
- * @param request The feedback request.
67
- * @returns The feedback created.
68
- */
69
- createRunFeedback(runId: string, request: FeedbackRequest): Promise<Feedback>;
70
- }
12
+ export declare const AsteroidClient: (apiKey: string) => Client;
13
+ /**
14
+ * Create a new workflow for a given agent.
15
+ *
16
+ * @param client - The API client.
17
+ * @param agentName - The name of the agent.
18
+ * @param workflowDetails - The workflow details.
19
+ * @returns The ID of the created workflow.
20
+ *
21
+ * @example
22
+ * const workflowId = await createNewWorkflow(client, 'my-agent', {
23
+ * name: "Example Workflow",
24
+ * result_schema: {},
25
+ * fields: { exampleField: "value" },
26
+ * prompts: ["Enter some data:"],
27
+ * provider: 'openai'
28
+ * });
29
+ */
30
+ export declare const createNewWorkflow: (client: Client, agentName: string, workflowDetails: CreateWorkflowRequest) => Promise<string>;
31
+ /**
32
+ * Execute an existing workflow.
33
+ *
34
+ * @param client - The API client.
35
+ * @param workflowId - The workflow identifier.
36
+ * @param executionData - The dynamic data to merge with the workflow.
37
+ * @returns The execution ID.
38
+ *
39
+ * @example
40
+ * const executionId = await executeWorkflowById(client, workflowId, { input: "some dynamic value" });
41
+ */
42
+ export declare const executeWorkflowById: (client: Client, workflowId: string, executionData: WorkflowExecutionRequest) => Promise<string>;
43
+ /**
44
+ * Get the current status and details for a workflow execution.
45
+ *
46
+ * @param client - The API client.
47
+ * @param executionId - The execution identifier.
48
+ * @returns The execution details.
49
+ *
50
+ * @example
51
+ * const execution = await getExecutionStatus(client, executionId);
52
+ * console.log(execution.status);
53
+ */
54
+ export declare const getExecutionStatus: (client: Client, executionId: string) => Promise<Execution>;
55
+ /**
56
+ * Get the progress updates for an execution.
57
+ *
58
+ * @param client - The API client.
59
+ * @param executionId - The execution identifier.
60
+ * @returns Array of progress update objects.
61
+ *
62
+ * @example
63
+ * const progressUpdates = await getWorkflowExecutionProgress(client, executionId);
64
+ * console.log(progressUpdates);
65
+ */
66
+ export declare const getWorkflowExecutionProgress: (client: Client, executionId: string) => Promise<Array<{
67
+ execution_id: string;
68
+ progress: string;
69
+ created_at: string;
70
+ }>>;
71
+ /**
72
+ * Get the final result of a workflow execution.
73
+ *
74
+ * @param client - The API client.
75
+ * @param executionId - The execution identifier.
76
+ * @returns The result object of the execution.
77
+ *
78
+ * @example
79
+ * const result = await getWorkflowResult(client, executionId);
80
+ * console.log(result);
81
+ */
82
+ export declare const getWorkflowResult: (client: Client, executionId: string) => Promise<Record<string, unknown>>;
83
+ /**
84
+ * Waits for a workflow execution to reach a terminal state and returns the result.
85
+ * Continuously polls the execution status until it's either "completed", "cancelled", or "failed".
86
+ *
87
+ * @param client - The API client.
88
+ * @param executionId - The execution identifier.
89
+ * @param interval - Polling interval in milliseconds (default is 1000ms).
90
+ * @returns A promise that resolves with the workflow execution result if completed.
91
+ * @throws An error if the execution ends as "cancelled" or "failed".
92
+ *
93
+ * @example
94
+ * const result = await waitForExecutionResult(client, executionId, 2000);
95
+ */
96
+ export declare const waitForExecutionResult: (client: Client, executionId: string, interval?: number, timeout?: number) => Promise<Record<string, unknown>>;
97
+ /**
98
+ * Optionally, re-export all generated functions and types.
99
+ */
100
+ export * from './generated/agents/sdk.gen';
101
+ export * from './generated/agents/types.gen';
package/dist/index.js CHANGED
@@ -1,104 +1,213 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AsteroidAgents = void 0;
4
- const agents_1 = require("./generated/agents");
5
- const platform_1 = require("./generated/platform");
39
+ exports.waitForExecutionResult = exports.getWorkflowResult = exports.getWorkflowExecutionProgress = exports.getExecutionStatus = exports.executeWorkflowById = exports.createNewWorkflow = exports.AsteroidClient = void 0;
40
+ const client_fetch_1 = require("@hey-api/client-fetch");
41
+ const AgentsSDK = __importStar(require("./generated/agents/sdk.gen"));
6
42
  /**
7
- * AgentsSDK provides a simple interface for interacting with the Asteroid Agents API.
8
- * It wraps the generated client services and exposes high-level methods.
43
+ * Create an API client with a provided API key.
44
+ *
45
+ * @param apiKey - Your API key.
46
+ * @returns A configured API client.
47
+ *
48
+ * @example
49
+ * const client = AsteroidClient('your-api-key');
9
50
  */
10
- class AsteroidAgents {
11
- /**
12
- * Optionally pass a custom OpenAPI config. For instance, to change the API base URL.
13
- * @param config Partial OpenAPI config values.
14
- */
15
- constructor(apiKey, agentsConfig, platformConfig) {
16
- // We use a custom headers for the API keys
17
- platform_1.OpenAPI.HEADERS = { 'X-Asteroid-Api-Key': apiKey };
18
- agents_1.OpenAPI.HEADERS = { 'X-Asteroid-Agents-Api-Key': apiKey };
19
- agents_1.OpenAPI.BASE = 'https://odyssey.asteroid.ai/api/v1';
20
- platform_1.OpenAPI.BASE = 'https://api.asteroid.ai/api/v1';
21
- if (agentsConfig) {
22
- Object.assign(agents_1.OpenAPI, agentsConfig);
23
- }
24
- if (platformConfig) {
25
- Object.assign(platform_1.OpenAPI, platformConfig);
51
+ const AsteroidClient = (apiKey) => {
52
+ return (0, client_fetch_1.createClient)({
53
+ baseUrl: 'https://odyssey.asteroid.ai/api/v1',
54
+ headers: {
55
+ 'X-Asteroid-Agents-Api-Key': apiKey
26
56
  }
57
+ });
58
+ };
59
+ exports.AsteroidClient = AsteroidClient;
60
+ /**
61
+ * Create a new workflow for a given agent.
62
+ *
63
+ * @param client - The API client.
64
+ * @param agentName - The name of the agent.
65
+ * @param workflowDetails - The workflow details.
66
+ * @returns The ID of the created workflow.
67
+ *
68
+ * @example
69
+ * const workflowId = await createNewWorkflow(client, 'my-agent', {
70
+ * name: "Example Workflow",
71
+ * result_schema: {},
72
+ * fields: { exampleField: "value" },
73
+ * prompts: ["Enter some data:"],
74
+ * provider: 'openai'
75
+ * });
76
+ */
77
+ const createNewWorkflow = async (client, agentName, workflowDetails) => {
78
+ // Add a workflow_name key to the workflowDetails.fields object
79
+ // This field is deprecated and will be removed in a future version.
80
+ workflowDetails.fields.workflow_name = workflowDetails.name;
81
+ const response = await AgentsSDK.createWorkflow({
82
+ client,
83
+ path: { agent_name: agentName },
84
+ body: workflowDetails,
85
+ });
86
+ if (response.error) {
87
+ console.log(response.error);
88
+ throw new Error(response.error);
27
89
  }
28
- /**
29
- * Retrieves the OpenAPI schema from the API.
30
- * @returns The OpenAPI specification.
31
- */
32
- async getOpenApiSchema() {
33
- return agents_1.ApiService.getOpenApi();
34
- }
35
- /**
36
- * Checks the health of the API.
37
- * @returns An object containing the health status.
38
- */
39
- async healthCheck() {
40
- return agents_1.DefaultService.healthCheck();
41
- }
42
- /**
43
- * Retrieves a list of all agents.
44
- * @returns An array of agents.
45
- */
46
- async getAgents() {
47
- return agents_1.AgentService.getAgents();
48
- }
49
- /**
50
- * Creates a new workflow for a given agent.
51
- * @param agentName The name of the agent for which the workflow is created.
52
- * @param request The workflow creation request.
53
- * @returns The ID of the newly created workflow.
54
- */
55
- async createWorkflow(agentName, request) {
56
- return agents_1.DefaultService.createWorkflow(agentName, request);
57
- }
58
- /**
59
- * Executes a saved workflow for an agent.
60
- * @param workflowId The ID of the workflow to execute.
61
- * @param request The execution request containing dynamic values.
62
- * @returns A string indicating that the job was queued.
63
- */
64
- async runWorkflow(workflowId, request) {
65
- return agents_1.WorkflowService.executeWorkflow(workflowId, request);
90
+ return response.data;
91
+ };
92
+ exports.createNewWorkflow = createNewWorkflow;
93
+ /**
94
+ * Execute an existing workflow.
95
+ *
96
+ * @param client - The API client.
97
+ * @param workflowId - The workflow identifier.
98
+ * @param executionData - The dynamic data to merge with the workflow.
99
+ * @returns The execution ID.
100
+ *
101
+ * @example
102
+ * const executionId = await executeWorkflowById(client, workflowId, { input: "some dynamic value" });
103
+ */
104
+ const executeWorkflowById = async (client, workflowId, executionData) => {
105
+ const response = await AgentsSDK.executeWorkflow({
106
+ client,
107
+ path: { workflow_id: workflowId },
108
+ body: executionData,
109
+ });
110
+ if (response.error) {
111
+ throw new Error(response.error);
66
112
  }
67
- /**
68
- * Retrieves all workflows along with their executions.
69
- * @returns An array containing workflow executions.
70
- */
71
- async getWorkflowRuns() {
72
- return agents_1.WorkflowService.getWorkflowExecutions("ceres");
113
+ return response.data;
114
+ };
115
+ exports.executeWorkflowById = executeWorkflowById;
116
+ /**
117
+ * Get the current status and details for a workflow execution.
118
+ *
119
+ * @param client - The API client.
120
+ * @param executionId - The execution identifier.
121
+ * @returns The execution details.
122
+ *
123
+ * @example
124
+ * const execution = await getExecutionStatus(client, executionId);
125
+ * console.log(execution.status);
126
+ */
127
+ const getExecutionStatus = async (client, executionId) => {
128
+ const execution = await AgentsSDK.getExecution({
129
+ client,
130
+ path: { id: executionId },
131
+ });
132
+ if (execution.error) {
133
+ throw new Error(execution.error);
73
134
  }
74
- /**
75
- * Retrieves the status of a run.
76
- * @param runId The ID of the run to retrieve the status for.
77
- * @returns The status of the run.
78
- */
79
- async getRunStatus(runId) {
80
- return platform_1.RunService.getRunStatus(runId);
135
+ return execution.data;
136
+ };
137
+ exports.getExecutionStatus = getExecutionStatus;
138
+ /**
139
+ * Get the progress updates for an execution.
140
+ *
141
+ * @param client - The API client.
142
+ * @param executionId - The execution identifier.
143
+ * @returns Array of progress update objects.
144
+ *
145
+ * @example
146
+ * const progressUpdates = await getWorkflowExecutionProgress(client, executionId);
147
+ * console.log(progressUpdates);
148
+ */
149
+ const getWorkflowExecutionProgress = async (client, executionId) => {
150
+ const progressUpdates = await AgentsSDK.getExecutionProgress({
151
+ client,
152
+ path: { id: executionId },
153
+ });
154
+ if (progressUpdates.error) {
155
+ throw new Error(progressUpdates.error);
81
156
  }
82
- async getRunResult(runId) {
83
- const run = await platform_1.RunService.getRun(runId);
84
- const metadata = run.metadata;
85
- if (!metadata) {
86
- throw new Error('Run metadata not found');
157
+ return progressUpdates.data;
158
+ };
159
+ exports.getWorkflowExecutionProgress = getWorkflowExecutionProgress;
160
+ /**
161
+ * Get the final result of a workflow execution.
162
+ *
163
+ * @param client - The API client.
164
+ * @param executionId - The execution identifier.
165
+ * @returns The result object of the execution.
166
+ *
167
+ * @example
168
+ * const result = await getWorkflowResult(client, executionId);
169
+ * console.log(result);
170
+ */
171
+ const getWorkflowResult = async (client, executionId) => {
172
+ const execution = await (0, exports.getExecutionStatus)(client, executionId);
173
+ return execution.result;
174
+ };
175
+ exports.getWorkflowResult = getWorkflowResult;
176
+ /**
177
+ * Waits for a workflow execution to reach a terminal state and returns the result.
178
+ * Continuously polls the execution status until it's either "completed", "cancelled", or "failed".
179
+ *
180
+ * @param client - The API client.
181
+ * @param executionId - The execution identifier.
182
+ * @param interval - Polling interval in milliseconds (default is 1000ms).
183
+ * @returns A promise that resolves with the workflow execution result if completed.
184
+ * @throws An error if the execution ends as "cancelled" or "failed".
185
+ *
186
+ * @example
187
+ * const result = await waitForExecutionResult(client, executionId, 2000);
188
+ */
189
+ const waitForExecutionResult = async (client, executionId, interval = 1000, timeout = 3600000 // 1 hour
190
+ ) => {
191
+ var steps = Math.floor(timeout / interval);
192
+ // Keep polling the execution status until it's either "completed", "cancelled", or "failed".
193
+ while (steps > 0) {
194
+ const execution = await (0, exports.getExecutionStatus)(client, executionId);
195
+ const currentStatus = execution.status?.status;
196
+ if (currentStatus === 'completed') {
197
+ return await (0, exports.getWorkflowResult)(client, executionId);
87
198
  }
88
- const result = metadata.final_result;
89
- if (!result) {
90
- throw new Error('Run result not found');
199
+ else if (currentStatus === 'failed' || currentStatus === 'cancelled') {
200
+ throw new Error(`Execution ${executionId} ended with status: ${currentStatus}${execution.status?.reason ? ' - ' + execution.status.reason : ''}`);
91
201
  }
92
- return result;
93
- }
94
- /**
95
- * Creates feedback for a run.
96
- * @param runId The ID of the run to create feedback for.
97
- * @param request The feedback request.
98
- * @returns The feedback created.
99
- */
100
- async createRunFeedback(runId, request) {
101
- return platform_1.ImproveService.createFeedback(runId, request);
202
+ // Wait for the specified interval before polling again
203
+ await new Promise(resolve => setTimeout(resolve, interval));
204
+ steps--;
102
205
  }
103
- }
104
- exports.AsteroidAgents = AsteroidAgents;
206
+ throw new Error(`Execution ${executionId} timed out after ${timeout}ms`);
207
+ };
208
+ exports.waitForExecutionResult = waitForExecutionResult;
209
+ /**
210
+ * Optionally, re-export all generated functions and types.
211
+ */
212
+ __exportStar(require("./generated/agents/sdk.gen"), exports);
213
+ __exportStar(require("./generated/agents/types.gen"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asteroid-odyssey",
3
- "version": "v1.0.14",
3
+ "version": "v1.0.17",
4
4
  "description": "SDK for interacting with Asteroid Agents API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,11 +8,9 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "generate-agents": "openapi -i ../agents/server/api/openapi.yaml -o src/generated/agents",
12
- "generate-platform": "openapi -i ../platform/server/openapi.yaml -o src/generated/platform",
13
- "generate": "npm run generate-agents && npm run generate-platform",
14
11
  "build": "tsc",
15
- "prepare": "npm run build"
12
+ "prepare": "npm run build",
13
+ "openapi-ts": "openapi-ts"
16
14
  },
17
15
  "keywords": [
18
16
  "asteroid",
@@ -23,8 +21,12 @@
23
21
  "author": "Asteroid",
24
22
  "license": "MIT",
25
23
  "devDependencies": {
24
+ "@hey-api/openapi-ts": "^0.64.12",
26
25
  "@types/node": "^22.13.4",
27
26
  "openapi-typescript-codegen": "^0.29.0",
28
27
  "typescript": "^5.7.3"
28
+ },
29
+ "dependencies": {
30
+ "@hey-api/client-fetch": "^0.8.3"
29
31
  }
30
32
  }