asteroid-odyssey 1.2.3 → 1.2.4

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.
@@ -1,5 +1,5 @@
1
1
  import { type Options as ClientOptions, type TDataShape, type Client } from '@hey-api/client-fetch';
2
- import type { GetOpenApiData, UploadExecutionFilesData, HealthCheckData, ExecuteAgentData, ExecuteAgentStructuredData, GetExecutionStatusData, GetExecutionResultData, GetBrowserSessionRecordingData, GetAgentProfilesData, CreateAgentProfileData, DeleteAgentProfileData, GetAgentProfileData, UpdateAgentProfileData } from './types.gen';
2
+ import type { GetOpenApiData, UploadExecutionFilesData, HealthCheckData, ExecuteAgentData, ExecuteAgentStructuredData, GetExecutionStatusData, GetExecutionResultData, GetBrowserSessionRecordingData, GetAgentProfilesData, CreateAgentProfileData, DeleteAgentProfileData, GetAgentProfileData, UpdateAgentProfileData, GetCredentialsPublicKeyData } from './types.gen';
3
3
  export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
4
4
  /**
5
5
  * You can provide a client instance returned by `createClient()` instead of
@@ -83,3 +83,7 @@ export declare const getAgentProfile: <ThrowOnError extends boolean = false>(opt
83
83
  * Updates an agent profile including metadata and/or credentials
84
84
  */
85
85
  export declare const updateAgentProfile: <ThrowOnError extends boolean = false>(options: Options<UpdateAgentProfileData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<import("./types.gen").AgentProfile, import("./types.gen").ErrorResponse, ThrowOnError>;
86
+ /**
87
+ * Get the public key for credentials
88
+ */
89
+ export declare const getCredentialsPublicKey: <ThrowOnError extends boolean = false>(options?: Options<GetCredentialsPublicKeyData, ThrowOnError>) => import("@hey-api/client-fetch").RequestResult<string, unknown, ThrowOnError>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // This file is auto-generated by @hey-api/openapi-ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.updateAgentProfile = exports.getAgentProfile = exports.deleteAgentProfile = exports.createAgentProfile = exports.getAgentProfiles = exports.getBrowserSessionRecording = exports.getExecutionResult = exports.getExecutionStatus = exports.executeAgentStructured = exports.executeAgent = exports.healthCheck = exports.uploadExecutionFiles = exports.getOpenApi = void 0;
4
+ exports.getCredentialsPublicKey = exports.updateAgentProfile = exports.getAgentProfile = exports.deleteAgentProfile = exports.createAgentProfile = exports.getAgentProfiles = exports.getBrowserSessionRecording = exports.getExecutionResult = exports.getExecutionStatus = exports.executeAgentStructured = exports.executeAgent = exports.healthCheck = exports.uploadExecutionFiles = exports.getOpenApi = void 0;
5
5
  const client_fetch_1 = require("@hey-api/client-fetch");
6
6
  const client_gen_1 = require("./client.gen");
7
7
  /**
@@ -230,3 +230,19 @@ const updateAgentProfile = (options) => {
230
230
  });
231
231
  };
232
232
  exports.updateAgentProfile = updateAgentProfile;
233
+ /**
234
+ * Get the public key for credentials
235
+ */
236
+ const getCredentialsPublicKey = (options) => {
237
+ return (options?.client ?? client_gen_1.client).get({
238
+ security: [
239
+ {
240
+ name: 'X-Asteroid-Agents-Api-Key',
241
+ type: 'apiKey'
242
+ }
243
+ ],
244
+ url: '/credentials/public_key',
245
+ ...options
246
+ });
247
+ };
248
+ exports.getCredentialsPublicKey = getCredentialsPublicKey;
@@ -182,9 +182,13 @@ export type UpdateAgentProfileRequest = {
182
182
  */
183
183
  sticky_ip?: boolean;
184
184
  /**
185
- * Complete list of credentials (replaces existing)
185
+ * List of credentials to add to the profile
186
186
  */
187
- credentials?: Array<Credential>;
187
+ credentials_to_add?: Array<Credential>;
188
+ /**
189
+ * List of credential IDs to delete from the profile
190
+ */
191
+ credentials_to_delete?: Array<string>;
188
192
  };
189
193
  /**
190
194
  * Two-letter country code for proxy location
@@ -636,6 +640,25 @@ export type UpdateAgentProfileResponses = {
636
640
  200: AgentProfile;
637
641
  };
638
642
  export type UpdateAgentProfileResponse = UpdateAgentProfileResponses[keyof UpdateAgentProfileResponses];
643
+ export type GetCredentialsPublicKeyData = {
644
+ body?: never;
645
+ path?: never;
646
+ query?: never;
647
+ url: '/credentials/public_key';
648
+ };
649
+ export type GetCredentialsPublicKeyErrors = {
650
+ /**
651
+ * Public key not found
652
+ */
653
+ 404: unknown;
654
+ };
655
+ export type GetCredentialsPublicKeyResponses = {
656
+ /**
657
+ * The public key for credentials
658
+ */
659
+ 200: string;
660
+ };
661
+ export type GetCredentialsPublicKeyResponse = GetCredentialsPublicKeyResponses[keyof GetCredentialsPublicKeyResponses];
639
662
  export type ClientOptions = {
640
663
  baseUrl: 'https://odyssey.asteroid.ai/api/v1' | `${string}://${string}/api/v1` | (string & {});
641
664
  };
package/dist/index.d.ts CHANGED
@@ -106,6 +106,16 @@ export declare const uploadExecutionFiles: (client: Client, executionId: string,
106
106
  * const profiles = await getAgentProfiles(client, 'org_123');
107
107
  */
108
108
  export declare const getAgentProfiles: (client: Client, organizationId?: string) => Promise<AgentProfile[]>;
109
+ /**
110
+ * Get the public key for encrypting credentials.
111
+ *
112
+ * @param client - The API client.
113
+ * @returns The PEM-formatted public key.
114
+ *
115
+ * @example
116
+ * const publicKey = await getCredentialsPublicKey(client);
117
+ */
118
+ export declare const getCredentialsPublicKey: (client: Client) => Promise<string>;
109
119
  /**
110
120
  * Create a new agent profile.
111
121
  *
@@ -146,7 +156,11 @@ export declare const getAgentProfile: (client: Client, profileId: string) => Pro
146
156
  * @returns The updated agent profile.
147
157
  *
148
158
  * @example
149
- * const updated = await updateAgentProfile(client, 'profile_123', { name: 'New Name' });
159
+ * const updated = await updateAgentProfile(client, 'profile_123', {
160
+ * name: 'New Name',
161
+ * credentials_to_add: [{ name: 'API_KEY', data: 'secret-key' }],
162
+ * credentials_to_delete: ['cred_456']
163
+ * });
150
164
  */
151
165
  export declare const updateAgentProfile: (client: Client, profileId: string, payload: UpdateAgentProfileRequest) => Promise<AgentProfile>;
152
166
  /**
package/dist/index.js CHANGED
@@ -36,9 +36,10 @@ 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.deleteAgentProfile = exports.updateAgentProfile = exports.getAgentProfile = exports.createAgentProfile = exports.getAgentProfiles = exports.uploadExecutionFiles = exports.getBrowserSessionRecording = exports.waitForExecutionResult = exports.getExecutionResult = exports.getExecutionStatus = exports.executeAgent = exports.AsteroidClient = void 0;
39
+ exports.deleteAgentProfile = exports.updateAgentProfile = exports.getAgentProfile = exports.createAgentProfile = exports.getCredentialsPublicKey = exports.getAgentProfiles = exports.uploadExecutionFiles = exports.getBrowserSessionRecording = 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
+ const encryption_1 = require("./utils/encryption");
42
43
  /**
43
44
  * Create an API client with a provided API key.
44
45
  *
@@ -232,6 +233,33 @@ const getAgentProfiles = async (client, organizationId) => {
232
233
  return response.data;
233
234
  };
234
235
  exports.getAgentProfiles = getAgentProfiles;
236
+ /**
237
+ * Get the public key for encrypting credentials.
238
+ *
239
+ * @param client - The API client.
240
+ * @returns The PEM-formatted public key.
241
+ *
242
+ * @example
243
+ * const publicKey = await getCredentialsPublicKey(client);
244
+ */
245
+ const getCredentialsPublicKey = async (client) => {
246
+ const response = await AgentsSDK.getCredentialsPublicKey({
247
+ client,
248
+ });
249
+ if (response.error) {
250
+ const errorMessage = typeof response.error === 'object' && 'error' in response.error
251
+ ? response.error.error
252
+ : typeof response.error === 'string'
253
+ ? response.error
254
+ : JSON.stringify(response.error);
255
+ throw new Error(errorMessage || 'Unknown error');
256
+ }
257
+ if (!response.data) {
258
+ throw new Error('Public key not found');
259
+ }
260
+ return response.data;
261
+ };
262
+ exports.getCredentialsPublicKey = getCredentialsPublicKey;
235
263
  /**
236
264
  * Create a new agent profile.
237
265
  *
@@ -252,9 +280,20 @@ exports.getAgentProfiles = getAgentProfiles;
252
280
  * });
253
281
  */
254
282
  const createAgentProfile = async (client, payload) => {
283
+ // If credentials are provided, encrypt them before sending
284
+ let processedPayload = { ...payload };
285
+ if (payload.credentials && payload.credentials.length > 0) {
286
+ // Get the public key for encryption
287
+ const publicKey = await (0, exports.getCredentialsPublicKey)(client);
288
+ // Encrypt each credential's data field
289
+ processedPayload.credentials = payload.credentials.map(credential => ({
290
+ ...credential,
291
+ data: (0, encryption_1.encryptWithPublicKey)(credential.data, publicKey)
292
+ }));
293
+ }
255
294
  const response = await AgentsSDK.createAgentProfile({
256
295
  client,
257
- body: payload,
296
+ body: processedPayload,
258
297
  });
259
298
  if (response.error) {
260
299
  throw new Error(response.error.error);
@@ -292,13 +331,28 @@ exports.getAgentProfile = getAgentProfile;
292
331
  * @returns The updated agent profile.
293
332
  *
294
333
  * @example
295
- * const updated = await updateAgentProfile(client, 'profile_123', { name: 'New Name' });
334
+ * const updated = await updateAgentProfile(client, 'profile_123', {
335
+ * name: 'New Name',
336
+ * credentials_to_add: [{ name: 'API_KEY', data: 'secret-key' }],
337
+ * credentials_to_delete: ['cred_456']
338
+ * });
296
339
  */
297
340
  const updateAgentProfile = async (client, profileId, payload) => {
341
+ // If credentials_to_add are provided, encrypt them before sending
342
+ let processedPayload = { ...payload };
343
+ if (payload.credentials_to_add && payload.credentials_to_add.length > 0) {
344
+ // Get the public key for encryption
345
+ const publicKey = await (0, exports.getCredentialsPublicKey)(client);
346
+ // Encrypt the data field of each credential to add
347
+ processedPayload.credentials_to_add = payload.credentials_to_add.map(credential => ({
348
+ ...credential,
349
+ data: (0, encryption_1.encryptWithPublicKey)(credential.data, publicKey)
350
+ }));
351
+ }
298
352
  const response = await AgentsSDK.updateAgentProfile({
299
353
  client,
300
354
  path: { profile_id: profileId },
301
- body: payload,
355
+ body: processedPayload,
302
356
  });
303
357
  if (response.error) {
304
358
  throw new Error(response.error.error);
@@ -0,0 +1 @@
1
+ export declare function encryptWithPublicKey(plaintext: string, pemPublicKey: string): string;
@@ -0,0 +1,54 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.encryptWithPublicKey = encryptWithPublicKey;
37
+ const forge = __importStar(require("node-forge"));
38
+ // Utility function to encrypt a plaintext value using a PEM public key
39
+ function encryptWithPublicKey(plaintext, pemPublicKey) {
40
+ try {
41
+ // The public key is already in PEM format from the API
42
+ // Parse the public key using node-forge
43
+ const publicKey = forge.pki.publicKeyFromPem(pemPublicKey);
44
+ // Encrypt the plaintext using RSA
45
+ const encrypted = publicKey.encrypt(plaintext, "RSAES-PKCS1-V1_5");
46
+ // Convert to base64 for transmission
47
+ return forge.util.encode64(encrypted);
48
+ }
49
+ catch (error) {
50
+ console.error("Encryption failed:", error);
51
+ throw new Error("Failed to encrypt: " +
52
+ (error instanceof Error ? error.message : "unknown error"));
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asteroid-odyssey",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "SDK for interacting with Asteroid Agents API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,11 +18,14 @@
18
18
  "devDependencies": {
19
19
  "@hey-api/openapi-ts": "^0.64.12",
20
20
  "@types/node": "^22.13.4",
21
+ "@types/node-forge": "^1.3.11",
21
22
  "openapi-typescript-codegen": "^0.29.0",
23
+ "ts-node": "^10.9.2",
22
24
  "typescript": "^5.7.3"
23
25
  },
24
26
  "dependencies": {
25
- "@hey-api/client-fetch": "^0.8.3"
27
+ "@hey-api/client-fetch": "^0.8.3",
28
+ "node-forge": "^1.3.1"
26
29
  },
27
30
  "scripts": {
28
31
  "build": "tsc",