@aigne/afs-compute-abstraction 1.11.0-beta.10

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/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ # Proprietary License
2
+
3
+ Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
4
+
5
+ This software and associated documentation files (the "Software") are proprietary
6
+ and confidential. Unauthorized copying, modification, distribution, or use of
7
+ this Software, via any medium, is strictly prohibited.
8
+
9
+ The Software is provided for internal use only within ArcBlock, Inc. and its
10
+ authorized affiliates.
11
+
12
+ ## No License Granted
13
+
14
+ No license, express or implied, is granted to any party for any purpose.
15
+ All rights are reserved by ArcBlock, Inc.
16
+
17
+ ## Public Artifact Distribution
18
+
19
+ Portions of this Software may be released publicly under separate open-source
20
+ licenses (such as MIT License) through designated public repositories. Such
21
+ public releases are governed by their respective licenses and do not affect
22
+ the proprietary nature of this repository.
23
+
24
+ ## Contact
25
+
26
+ For licensing inquiries, contact: legal@arcblock.io
@@ -0,0 +1,30 @@
1
+ /**
2
+ * AFS Compute Abstraction
3
+ *
4
+ * Provides a unified interface for compute instances across cloud providers (EC2, GCE).
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { mapInstances, isInstance } from "@aigne/afs-compute-abstraction";
9
+ *
10
+ * // Get entries from AFS (EC2 or GCE providers)
11
+ * const entries = await afs.list("/modules/ec2/instances");
12
+ *
13
+ * // Filter to instances only
14
+ * const instanceEntries = entries.data.filter(isInstance);
15
+ *
16
+ * // Map to unified ComputeInstance format
17
+ * const instances = mapInstances(instanceEntries);
18
+ *
19
+ * // Now you can work with instances in a provider-agnostic way
20
+ * for (const instance of instances) {
21
+ * console.log(`${instance.name}: ${instance.state} (${instance.provider})`);
22
+ * }
23
+ * ```
24
+ */
25
+ export { isInstance, type MapInstancesOptions, mapInstance, mapInstances, } from "./instance-mapper.js";
26
+ export { mapEC2Instance } from "./providers/ec2.js";
27
+ export { mapGCEInstance } from "./providers/gce.js";
28
+ export type { ComputeInstance, ComputeInstanceState, ComputePlatformRef, ComputeProvider, } from "./types.js";
29
+ export { COMPUTE_PROVIDERS, COMPUTE_STATES, computeInstanceSchema, computePlatformRefSchema, EC2_STATE_MAP, GCE_STATE_MAP, } from "./types.js";
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EACL,UAAU,EACV,KAAK,mBAAmB,EACxB,WAAW,EACX,YAAY,GACb,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,YAAY,EACV,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,GAChB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,aAAa,EACb,aAAa,GACd,MAAM,YAAY,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * AFS Compute Abstraction
3
+ *
4
+ * Provides a unified interface for compute instances across cloud providers (EC2, GCE).
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { mapInstances, isInstance } from "@aigne/afs-compute-abstraction";
9
+ *
10
+ * // Get entries from AFS (EC2 or GCE providers)
11
+ * const entries = await afs.list("/modules/ec2/instances");
12
+ *
13
+ * // Filter to instances only
14
+ * const instanceEntries = entries.data.filter(isInstance);
15
+ *
16
+ * // Map to unified ComputeInstance format
17
+ * const instances = mapInstances(instanceEntries);
18
+ *
19
+ * // Now you can work with instances in a provider-agnostic way
20
+ * for (const instance of instances) {
21
+ * console.log(`${instance.name}: ${instance.state} (${instance.provider})`);
22
+ * }
23
+ * ```
24
+ */
25
+ // Re-export mapper functions
26
+ export { isInstance, mapInstance, mapInstances, } from "./instance-mapper.js";
27
+ // Re-export provider-specific mappers
28
+ export { mapEC2Instance } from "./providers/ec2.js";
29
+ export { mapGCEInstance } from "./providers/gce.js";
30
+ export { COMPUTE_PROVIDERS, COMPUTE_STATES, computeInstanceSchema, computePlatformRefSchema, EC2_STATE_MAP, GCE_STATE_MAP, } from "./types.js";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Instance Mapper
3
+ *
4
+ * Maps AFS entries to unified ComputeInstance format based on their kind.
5
+ */
6
+ import type { AFSEntry } from "@aigne/afs";
7
+ import type { ComputeInstance } from "./types.js";
8
+ /**
9
+ * Options for mapping instances
10
+ */
11
+ export interface MapInstancesOptions {
12
+ /** Skip unknown kinds instead of throwing errors */
13
+ skipUnknown?: boolean;
14
+ }
15
+ /**
16
+ * Check if entry is any supported instance type
17
+ */
18
+ export declare function isInstance(entry: AFSEntry): boolean;
19
+ /**
20
+ * Map a single AFS entry to ComputeInstance
21
+ *
22
+ * @param entry - AFS entry from any compute provider
23
+ * @returns Unified ComputeInstance
24
+ * @throws Error if the entry kind is not supported
25
+ */
26
+ export declare function mapInstance(entry: AFSEntry): ComputeInstance;
27
+ /**
28
+ * Map multiple AFS entries to ComputeInstances
29
+ *
30
+ * @param entries - AFS entries from compute providers
31
+ * @param options - Mapping options
32
+ * @returns Array of unified ComputeInstances
33
+ */
34
+ export declare function mapInstances(entries: AFSEntry[], options?: MapInstancesOptions): ComputeInstance[];
35
+ //# sourceMappingURL=instance-mapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance-mapper.d.ts","sourceRoot":"","sources":["../../src/instance-mapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,oDAAoD;IACpD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAgBD;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,CAU5D;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,QAAQ,EAAE,EACnB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,eAAe,EAAE,CAmBnB"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Instance Mapper
3
+ *
4
+ * Maps AFS entries to unified ComputeInstance format based on their kind.
5
+ */
6
+ import { mapEC2Instance } from "./providers/ec2.js";
7
+ import { mapGCEInstance } from "./providers/gce.js";
8
+ /**
9
+ * Check if entry is an EC2 instance
10
+ */
11
+ function isEC2Instance(entry) {
12
+ return entry.meta?.kind === "ec2:instance";
13
+ }
14
+ /**
15
+ * Check if entry is a GCE instance
16
+ */
17
+ function isGCEInstance(entry) {
18
+ return entry.meta?.kind === "gce:instance";
19
+ }
20
+ /**
21
+ * Check if entry is any supported instance type
22
+ */
23
+ export function isInstance(entry) {
24
+ return isEC2Instance(entry) || isGCEInstance(entry);
25
+ }
26
+ /**
27
+ * Map a single AFS entry to ComputeInstance
28
+ *
29
+ * @param entry - AFS entry from any compute provider
30
+ * @returns Unified ComputeInstance
31
+ * @throws Error if the entry kind is not supported
32
+ */
33
+ export function mapInstance(entry) {
34
+ if (isEC2Instance(entry)) {
35
+ return mapEC2Instance(entry);
36
+ }
37
+ if (isGCEInstance(entry)) {
38
+ return mapGCEInstance(entry);
39
+ }
40
+ throw new Error(`Unsupported instance kind: ${entry.meta?.kind}`);
41
+ }
42
+ /**
43
+ * Map multiple AFS entries to ComputeInstances
44
+ *
45
+ * @param entries - AFS entries from compute providers
46
+ * @param options - Mapping options
47
+ * @returns Array of unified ComputeInstances
48
+ */
49
+ export function mapInstances(entries, options) {
50
+ const result = [];
51
+ for (const entry of entries) {
52
+ if (options?.skipUnknown && !isInstance(entry)) {
53
+ continue;
54
+ }
55
+ try {
56
+ result.push(mapInstance(entry));
57
+ }
58
+ catch (error) {
59
+ if (!options?.skipUnknown) {
60
+ throw error;
61
+ }
62
+ // Skip unknown kinds when skipUnknown is true
63
+ }
64
+ }
65
+ return result;
66
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * EC2 Adapter
3
+ *
4
+ * Maps EC2 instance entries to unified ComputeInstance format.
5
+ */
6
+ import type { AFSEntry } from "@aigne/afs";
7
+ import type { ComputeInstance } from "../types.js";
8
+ /**
9
+ * Map EC2 instance entry to ComputeInstance
10
+ *
11
+ * @param entry - AFS entry from EC2 provider
12
+ * @returns Unified ComputeInstance
13
+ */
14
+ export declare function mapEC2Instance(entry: AFSEntry): ComputeInstance;
15
+ //# sourceMappingURL=ec2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ec2.d.ts","sourceRoot":"","sources":["../../../src/providers/ec2.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAqBzE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,CAoD/D"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * EC2 Adapter
3
+ *
4
+ * Maps EC2 instance entries to unified ComputeInstance format.
5
+ */
6
+ import { EC2_STATE_MAP } from "../types.js";
7
+ /**
8
+ * Extract instance name from path
9
+ *
10
+ * Path format: /instances/{name}
11
+ */
12
+ function extractInstanceName(path) {
13
+ const segments = path.split("/").filter(Boolean);
14
+ return segments[segments.length - 1] || "unknown";
15
+ }
16
+ /**
17
+ * Map EC2 state to unified state
18
+ */
19
+ function mapState(ec2State) {
20
+ if (!ec2State)
21
+ return "unknown";
22
+ return EC2_STATE_MAP[ec2State] || "unknown";
23
+ }
24
+ /**
25
+ * Map EC2 instance entry to ComputeInstance
26
+ *
27
+ * @param entry - AFS entry from EC2 provider
28
+ * @returns Unified ComputeInstance
29
+ */
30
+ export function mapEC2Instance(entry) {
31
+ const metadata = entry.meta || {};
32
+ // Extract AWS-specific metadata for passthrough
33
+ const aws = {};
34
+ const awsFields = [
35
+ "instanceId",
36
+ "availabilityZone",
37
+ "vpcId",
38
+ "subnetId",
39
+ "tags",
40
+ "securityGroups",
41
+ "iamInstanceProfile",
42
+ "ebsOptimized",
43
+ "architecture",
44
+ "hypervisor",
45
+ "rootDeviceType",
46
+ "rootDeviceName",
47
+ "blockDeviceMappings",
48
+ "networkInterfaces",
49
+ "placement",
50
+ ];
51
+ for (const field of awsFields) {
52
+ if (metadata[field] !== undefined) {
53
+ aws[field] = metadata[field];
54
+ }
55
+ }
56
+ // Parse launch time if present
57
+ let launchTime;
58
+ if (metadata.launchTime) {
59
+ launchTime = new Date(metadata.launchTime);
60
+ }
61
+ return {
62
+ id: metadata.instanceId || entry.id,
63
+ name: extractInstanceName(entry.path),
64
+ state: mapState(metadata.state),
65
+ provider: "ec2",
66
+ instanceType: metadata.instanceType || "unknown",
67
+ vcpus: metadata.vcpus,
68
+ memoryGb: metadata.memoryGb,
69
+ publicIp: metadata.publicIp,
70
+ privateIp: metadata.privateIp,
71
+ launchTime,
72
+ platformRef: {
73
+ consoleUrl: metadata.platformRef?.consoleUrl || "",
74
+ afsPath: entry.path,
75
+ },
76
+ aws: Object.keys(aws).length > 0 ? aws : undefined,
77
+ };
78
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * GCE Adapter
3
+ *
4
+ * Maps GCE instance entries to unified ComputeInstance format.
5
+ */
6
+ import type { AFSEntry } from "@aigne/afs";
7
+ import type { ComputeInstance } from "../types.js";
8
+ /**
9
+ * Map GCE instance entry to ComputeInstance
10
+ *
11
+ * @param entry - AFS entry from GCE provider
12
+ * @returns Unified ComputeInstance
13
+ */
14
+ export declare function mapGCEInstance(entry: AFSEntry): ComputeInstance;
15
+ //# sourceMappingURL=gce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gce.d.ts","sourceRoot":"","sources":["../../../src/providers/gce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAwB,MAAM,aAAa,CAAC;AAqBzE;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,CAgD/D"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * GCE Adapter
3
+ *
4
+ * Maps GCE instance entries to unified ComputeInstance format.
5
+ */
6
+ import { GCE_STATE_MAP } from "../types.js";
7
+ /**
8
+ * Extract instance name from path
9
+ *
10
+ * Path format: /instances/{name}
11
+ */
12
+ function extractInstanceName(path) {
13
+ const segments = path.split("/").filter(Boolean);
14
+ return segments[segments.length - 1] || "unknown";
15
+ }
16
+ /**
17
+ * Map GCE status to unified state
18
+ */
19
+ function mapState(gceStatus) {
20
+ if (!gceStatus)
21
+ return "unknown";
22
+ return GCE_STATE_MAP[gceStatus] || "unknown";
23
+ }
24
+ /**
25
+ * Map GCE instance entry to ComputeInstance
26
+ *
27
+ * @param entry - AFS entry from GCE provider
28
+ * @returns Unified ComputeInstance
29
+ */
30
+ export function mapGCEInstance(entry) {
31
+ const metadata = entry.meta || {};
32
+ // Extract GCP-specific metadata for passthrough
33
+ const gcp = {};
34
+ const gcpFields = [
35
+ "zone",
36
+ "labels",
37
+ "networkInterfaces",
38
+ "disks",
39
+ "serviceAccounts",
40
+ "scheduling",
41
+ "metadata",
42
+ "tags",
43
+ "canIpForward",
44
+ "startRestricted",
45
+ "deletionProtection",
46
+ ];
47
+ for (const field of gcpFields) {
48
+ if (metadata[field] !== undefined) {
49
+ gcp[field] = metadata[field];
50
+ }
51
+ }
52
+ // Parse creation time if present
53
+ let launchTime;
54
+ if (metadata.createdAt) {
55
+ launchTime = new Date(metadata.createdAt);
56
+ }
57
+ return {
58
+ id: entry.id,
59
+ name: extractInstanceName(entry.path),
60
+ state: mapState(metadata.status),
61
+ provider: "gce",
62
+ instanceType: metadata.machineType || "unknown",
63
+ vcpus: metadata.vcpus,
64
+ memoryGb: metadata.memoryGb,
65
+ publicIp: metadata.publicIp,
66
+ privateIp: metadata.privateIp,
67
+ launchTime,
68
+ platformRef: {
69
+ consoleUrl: metadata.platformRef?.consoleUrl || "",
70
+ afsPath: entry.path,
71
+ },
72
+ gcp: Object.keys(gcp).length > 0 ? gcp : undefined,
73
+ };
74
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Compute Abstraction Types
3
+ *
4
+ * Unified types for compute instances across cloud providers.
5
+ */
6
+ import { z } from "zod";
7
+ /**
8
+ * Supported cloud providers
9
+ */
10
+ export declare const COMPUTE_PROVIDERS: readonly ["ec2", "gce"];
11
+ export type ComputeProvider = (typeof COMPUTE_PROVIDERS)[number];
12
+ /**
13
+ * Unified instance states
14
+ */
15
+ export declare const COMPUTE_STATES: readonly ["running", "stopped", "pending", "terminated", "stopping", "unknown"];
16
+ export type ComputeInstanceState = (typeof COMPUTE_STATES)[number];
17
+ /**
18
+ * Platform reference for the original resource
19
+ */
20
+ export interface ComputePlatformRef {
21
+ /** URL to the cloud console for this resource */
22
+ consoleUrl: string;
23
+ /** Original AFS path in the provider */
24
+ afsPath: string;
25
+ }
26
+ /**
27
+ * Unified compute instance type
28
+ *
29
+ * Represents a compute instance from any supported cloud provider
30
+ * with normalized fields for easy comparison and manipulation.
31
+ */
32
+ export interface ComputeInstance {
33
+ /** Unique identifier (provider-specific) */
34
+ id: string;
35
+ /** Instance name */
36
+ name: string;
37
+ /** Normalized instance state */
38
+ state: ComputeInstanceState;
39
+ /** Source provider */
40
+ provider: ComputeProvider;
41
+ /** Instance type (original name, e.g., "t2.micro", "n1-standard-1") */
42
+ instanceType: string;
43
+ /** Number of vCPUs (if available) */
44
+ vcpus?: number;
45
+ /** Memory in GB (if available) */
46
+ memoryGb?: number;
47
+ /** Public IP address (if assigned) */
48
+ publicIp?: string;
49
+ /** Private IP address */
50
+ privateIp?: string;
51
+ /** Instance launch time */
52
+ launchTime?: Date;
53
+ /** Platform reference for console URL and original path */
54
+ platformRef: ComputePlatformRef;
55
+ /** AWS-specific metadata (passthrough) */
56
+ aws?: Record<string, unknown>;
57
+ /** GCP-specific metadata (passthrough) */
58
+ gcp?: Record<string, unknown>;
59
+ }
60
+ /**
61
+ * Zod schema for platform reference
62
+ */
63
+ export declare const computePlatformRefSchema: z.ZodObject<{
64
+ consoleUrl: z.ZodString;
65
+ afsPath: z.ZodString;
66
+ }, z.core.$strip>;
67
+ /**
68
+ * Zod schema for compute instance validation
69
+ */
70
+ export declare const computeInstanceSchema: z.ZodObject<{
71
+ id: z.ZodString;
72
+ name: z.ZodString;
73
+ state: z.ZodEnum<{
74
+ running: "running";
75
+ stopped: "stopped";
76
+ pending: "pending";
77
+ terminated: "terminated";
78
+ stopping: "stopping";
79
+ unknown: "unknown";
80
+ }>;
81
+ provider: z.ZodEnum<{
82
+ ec2: "ec2";
83
+ gce: "gce";
84
+ }>;
85
+ instanceType: z.ZodString;
86
+ vcpus: z.ZodOptional<z.ZodNumber>;
87
+ memoryGb: z.ZodOptional<z.ZodNumber>;
88
+ publicIp: z.ZodOptional<z.ZodString>;
89
+ privateIp: z.ZodOptional<z.ZodString>;
90
+ launchTime: z.ZodOptional<z.ZodDate>;
91
+ platformRef: z.ZodObject<{
92
+ consoleUrl: z.ZodString;
93
+ afsPath: z.ZodString;
94
+ }, z.core.$strip>;
95
+ aws: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
96
+ gcp: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
97
+ }, z.core.$strip>;
98
+ /**
99
+ * State mapping from EC2 states to unified states
100
+ */
101
+ export declare const EC2_STATE_MAP: Record<string, ComputeInstanceState>;
102
+ /**
103
+ * State mapping from GCE states to unified states
104
+ */
105
+ export declare const GCE_STATE_MAP: Record<string, ComputeInstanceState>;
106
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,eAAO,MAAM,iBAAiB,yBAA0B,CAAC;AACzD,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,cAAc,iFAOjB,CAAC;AACX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IAEX,oBAAoB;IACpB,IAAI,EAAE,MAAM,CAAC;IAEb,gCAAgC;IAChC,KAAK,EAAE,oBAAoB,CAAC;IAE5B,sBAAsB;IACtB,QAAQ,EAAE,eAAe,CAAC;IAE1B,uEAAuE;IACvE,YAAY,EAAE,MAAM,CAAC;IAErB,qCAAqC;IACrC,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,sCAAsC;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,yBAAyB;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,IAAI,CAAC;IAElB,2DAA2D;IAC3D,WAAW,EAAE,kBAAkB,CAAC;IAEhC,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE9B,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;iBAGnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAchC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAO9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAS9D,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Compute Abstraction Types
3
+ *
4
+ * Unified types for compute instances across cloud providers.
5
+ */
6
+ import { z } from "zod";
7
+ /**
8
+ * Supported cloud providers
9
+ */
10
+ export const COMPUTE_PROVIDERS = ["ec2", "gce"];
11
+ /**
12
+ * Unified instance states
13
+ */
14
+ export const COMPUTE_STATES = [
15
+ "running",
16
+ "stopped",
17
+ "pending",
18
+ "terminated",
19
+ "stopping",
20
+ "unknown",
21
+ ];
22
+ /**
23
+ * Zod schema for platform reference
24
+ */
25
+ export const computePlatformRefSchema = z.object({
26
+ consoleUrl: z.string(),
27
+ afsPath: z.string(),
28
+ });
29
+ /**
30
+ * Zod schema for compute instance validation
31
+ */
32
+ export const computeInstanceSchema = z.object({
33
+ id: z.string(),
34
+ name: z.string(),
35
+ state: z.enum(COMPUTE_STATES),
36
+ provider: z.enum(COMPUTE_PROVIDERS),
37
+ instanceType: z.string(),
38
+ vcpus: z.number().int().positive().optional(),
39
+ memoryGb: z.number().positive().optional(),
40
+ publicIp: z.string().optional(),
41
+ privateIp: z.string().optional(),
42
+ launchTime: z.date().optional(),
43
+ platformRef: computePlatformRefSchema,
44
+ aws: z.record(z.string(), z.unknown()).optional(),
45
+ gcp: z.record(z.string(), z.unknown()).optional(),
46
+ });
47
+ /**
48
+ * State mapping from EC2 states to unified states
49
+ */
50
+ export const EC2_STATE_MAP = {
51
+ running: "running",
52
+ stopped: "stopped",
53
+ pending: "pending",
54
+ terminated: "terminated",
55
+ stopping: "stopping",
56
+ "shutting-down": "stopping",
57
+ };
58
+ /**
59
+ * State mapping from GCE states to unified states
60
+ */
61
+ export const GCE_STATE_MAP = {
62
+ RUNNING: "running",
63
+ STOPPED: "stopped",
64
+ TERMINATED: "terminated",
65
+ PROVISIONING: "pending",
66
+ STAGING: "pending",
67
+ STOPPING: "stopping",
68
+ SUSPENDING: "stopping",
69
+ SUSPENDED: "stopped",
70
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Compute Abstraction Index Tests
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=index.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../test/index.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Compute Abstraction Index Tests
3
+ */
4
+ import { describe, expect, test } from "bun:test";
5
+ import { COMPUTE_PROVIDERS, COMPUTE_STATES, isInstance, mapInstance, mapInstances, } from "../src/index.js";
6
+ describe("Compute Abstraction exports", () => {
7
+ test("exports mapInstance function", () => {
8
+ expect(typeof mapInstance).toBe("function");
9
+ });
10
+ test("exports mapInstances function", () => {
11
+ expect(typeof mapInstances).toBe("function");
12
+ });
13
+ test("exports isInstance function", () => {
14
+ expect(typeof isInstance).toBe("function");
15
+ });
16
+ test("exports COMPUTE_STATES", () => {
17
+ expect(COMPUTE_STATES).toBeDefined();
18
+ expect(COMPUTE_STATES).toContain("running");
19
+ });
20
+ test("exports COMPUTE_PROVIDERS", () => {
21
+ expect(COMPUTE_PROVIDERS).toBeDefined();
22
+ expect(COMPUTE_PROVIDERS).toContain("ec2");
23
+ expect(COMPUTE_PROVIDERS).toContain("gce");
24
+ });
25
+ });
26
+ describe("Compute Abstraction integration", () => {
27
+ test("maps mixed provider instances", () => {
28
+ const entries = [
29
+ {
30
+ id: "ec2://us-east-1/i-123",
31
+ path: "/instances/ec2-1",
32
+ meta: {
33
+ kind: "ec2:instance",
34
+ instanceId: "i-123",
35
+ state: "running",
36
+ instanceType: "t2.micro",
37
+ platformRef: { consoleUrl: "https://aws.console" },
38
+ },
39
+ },
40
+ {
41
+ id: "gce://my-project/us-central1-a/gce-1",
42
+ path: "/instances/gce-1",
43
+ meta: {
44
+ kind: "gce:instance",
45
+ status: "RUNNING",
46
+ machineType: "n1-standard-1",
47
+ platformRef: { consoleUrl: "https://gcp.console" },
48
+ },
49
+ },
50
+ ];
51
+ const instances = mapInstances(entries);
52
+ expect(instances).toHaveLength(2);
53
+ // Both should be in "running" state
54
+ expect(instances[0].state).toBe("running");
55
+ expect(instances[1].state).toBe("running");
56
+ // Different providers
57
+ expect(instances[0].provider).toBe("ec2");
58
+ expect(instances[1].provider).toBe("gce");
59
+ });
60
+ test("filters instances with isInstance", () => {
61
+ const entries = [
62
+ {
63
+ id: "ec2://us-east-1/i-123",
64
+ path: "/instances/ec2-1",
65
+ meta: {
66
+ kind: "ec2:instance",
67
+ instanceId: "i-123",
68
+ state: "running",
69
+ instanceType: "t2.micro",
70
+ platformRef: { consoleUrl: "https://aws.console" },
71
+ },
72
+ },
73
+ {
74
+ id: "ec2://us-east-1/vol-123",
75
+ path: "/volumes/vol-1",
76
+ meta: {
77
+ kind: "ec2:volume",
78
+ },
79
+ },
80
+ {
81
+ id: "gce://my-project/us-central1-a/gce-1",
82
+ path: "/instances/gce-1",
83
+ meta: {
84
+ kind: "gce:instance",
85
+ status: "RUNNING",
86
+ machineType: "n1-standard-1",
87
+ platformRef: { consoleUrl: "https://gcp.console" },
88
+ },
89
+ },
90
+ ];
91
+ const instanceEntries = entries.filter(isInstance);
92
+ expect(instanceEntries).toHaveLength(2);
93
+ });
94
+ });