@framers/agentos-ext-cloud-flyio 0.1.0
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 +98 -0
- package/dist/FlyService.d.ts +123 -0
- package/dist/FlyService.d.ts.map +1 -0
- package/dist/FlyService.js +251 -0
- package/dist/FlyService.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/createVolume.d.ts +54 -0
- package/dist/tools/createVolume.d.ts.map +1 -0
- package/dist/tools/createVolume.js +43 -0
- package/dist/tools/createVolume.js.map +1 -0
- package/dist/tools/deployApp.d.ts +88 -0
- package/dist/tools/deployApp.d.ts.map +1 -0
- package/dist/tools/deployApp.js +86 -0
- package/dist/tools/deployApp.js.map +1 -0
- package/dist/tools/listApps.d.ts +39 -0
- package/dist/tools/listApps.d.ts.map +1 -0
- package/dist/tools/listApps.js +53 -0
- package/dist/tools/listApps.js.map +1 -0
- package/dist/tools/scaleApp.d.ts +65 -0
- package/dist/tools/scaleApp.d.ts.map +1 -0
- package/dist/tools/scaleApp.js +95 -0
- package/dist/tools/scaleApp.js.map +1 -0
- package/manifest.json +31 -0
- package/package.json +66 -0
- package/src/FlyService.ts +364 -0
- package/src/index.ts +109 -0
- package/src/tools/createVolume.ts +53 -0
- package/src/tools/deployApp.ts +104 -0
- package/src/tools/listApps.ts +62 -0
- package/src/tools/scaleApp.ts +116 -0
- package/test/FlyService.test.ts +484 -0
- package/test/index.test.ts +49 -0
- package/test/tools.test.ts +407 -0
- package/tsconfig.json +22 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License.
|
|
30
|
+
|
|
31
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License.
|
|
34
|
+
|
|
35
|
+
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
36
|
+
|
|
37
|
+
4. Redistribution.
|
|
38
|
+
|
|
39
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
40
|
+
|
|
41
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
42
|
+
|
|
43
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
44
|
+
|
|
45
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
46
|
+
|
|
47
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
48
|
+
|
|
49
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
50
|
+
|
|
51
|
+
5. Submission of Contributions.
|
|
52
|
+
|
|
53
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
54
|
+
|
|
55
|
+
6. Trademarks.
|
|
56
|
+
|
|
57
|
+
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
58
|
+
|
|
59
|
+
7. Disclaimer of Warranty.
|
|
60
|
+
|
|
61
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
62
|
+
|
|
63
|
+
8. Limitation of Liability.
|
|
64
|
+
|
|
65
|
+
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
66
|
+
|
|
67
|
+
9. Accepting Warranty or Additional Liability.
|
|
68
|
+
|
|
69
|
+
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
70
|
+
|
|
71
|
+
END OF TERMS AND CONDITIONS
|
|
72
|
+
|
|
73
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
74
|
+
|
|
75
|
+
To apply the Apache License to your work, attach the following
|
|
76
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
77
|
+
replaced with your own identifying information. (Don't include
|
|
78
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
79
|
+
comment syntax for the file format. We also recommend that a
|
|
80
|
+
file or class name and description of purpose be included on the
|
|
81
|
+
same "printed page" as the copyright notice for easier
|
|
82
|
+
identification within third-party archives.
|
|
83
|
+
|
|
84
|
+
Copyright (c) 2025 Framers
|
|
85
|
+
|
|
86
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
87
|
+
you may not use this file except in compliance with the License.
|
|
88
|
+
You may obtain a copy of the License at
|
|
89
|
+
|
|
90
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
91
|
+
|
|
92
|
+
Unless required by applicable law or agreed to in writing, software
|
|
93
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
94
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
95
|
+
See the License for the specific language governing permissions and
|
|
96
|
+
limitations under the License.
|
|
97
|
+
|
|
98
|
+
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Fly.io Machines API service layer.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the Fly Machines API for app creation, machine management,
|
|
5
|
+
* scaling, and volume provisioning. Uses the GraphQL API for listing
|
|
6
|
+
* apps (organization-scoped) and the Machines REST API for everything else.
|
|
7
|
+
*/
|
|
8
|
+
export interface FlyConfig {
|
|
9
|
+
/** Fly.io API token (from `flyctl tokens create`) */
|
|
10
|
+
token: string;
|
|
11
|
+
/** Machines API base URL (defaults to https://api.machines.dev/v1) */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** GraphQL API base URL for org-level queries (defaults to https://api.fly.io/graphql) */
|
|
14
|
+
graphqlUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface FlyApp {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
organization: string;
|
|
20
|
+
status: string;
|
|
21
|
+
hostname: string;
|
|
22
|
+
createdAt?: string;
|
|
23
|
+
machines?: FlyMachine[];
|
|
24
|
+
}
|
|
25
|
+
export interface FlyMachine {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
state: string;
|
|
29
|
+
region: string;
|
|
30
|
+
instanceId: string;
|
|
31
|
+
privateIp: string;
|
|
32
|
+
config: FlyMachineConfig;
|
|
33
|
+
imageRef?: {
|
|
34
|
+
repository: string;
|
|
35
|
+
tag: string;
|
|
36
|
+
digest: string;
|
|
37
|
+
};
|
|
38
|
+
createdAt: string;
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
}
|
|
41
|
+
export interface FlyMachineConfig {
|
|
42
|
+
image: string;
|
|
43
|
+
env?: Record<string, string>;
|
|
44
|
+
services?: FlyMachineService[];
|
|
45
|
+
guest?: {
|
|
46
|
+
cpus: number;
|
|
47
|
+
cpu_kind: string;
|
|
48
|
+
memory_mb: number;
|
|
49
|
+
};
|
|
50
|
+
size?: string;
|
|
51
|
+
auto_destroy?: boolean;
|
|
52
|
+
restart?: {
|
|
53
|
+
policy: string;
|
|
54
|
+
max_retries?: number;
|
|
55
|
+
};
|
|
56
|
+
mounts?: Array<{
|
|
57
|
+
volume: string;
|
|
58
|
+
path: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
|
61
|
+
export interface FlyMachineService {
|
|
62
|
+
ports: Array<{
|
|
63
|
+
port: number;
|
|
64
|
+
handlers: string[];
|
|
65
|
+
force_https?: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
protocol: string;
|
|
68
|
+
internal_port: number;
|
|
69
|
+
autostop?: boolean;
|
|
70
|
+
autostart?: boolean;
|
|
71
|
+
min_machines_running?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface FlyVolume {
|
|
74
|
+
id: string;
|
|
75
|
+
name: string;
|
|
76
|
+
state: string;
|
|
77
|
+
sizeGb: number;
|
|
78
|
+
region: string;
|
|
79
|
+
encrypted: boolean;
|
|
80
|
+
createdAt: string;
|
|
81
|
+
attachedMachineId?: string;
|
|
82
|
+
attachedAllocId?: string;
|
|
83
|
+
}
|
|
84
|
+
export declare class FlyService {
|
|
85
|
+
private config;
|
|
86
|
+
private running;
|
|
87
|
+
constructor(config: FlyConfig);
|
|
88
|
+
initialize(): Promise<void>;
|
|
89
|
+
shutdown(): Promise<void>;
|
|
90
|
+
get isRunning(): boolean;
|
|
91
|
+
/** Create a new Fly app. */
|
|
92
|
+
createApp(name: string, org?: string): Promise<FlyApp>;
|
|
93
|
+
/** Get an app by name. */
|
|
94
|
+
getApp(appName: string): Promise<FlyApp>;
|
|
95
|
+
/** List all apps in the personal org (via GraphQL). */
|
|
96
|
+
listApps(): Promise<FlyApp[]>;
|
|
97
|
+
/** Create a machine in an app. */
|
|
98
|
+
createMachine(appName: string, config: FlyMachineConfig, opts?: {
|
|
99
|
+
name?: string;
|
|
100
|
+
region?: string;
|
|
101
|
+
}): Promise<FlyMachine>;
|
|
102
|
+
/** List all machines in an app. */
|
|
103
|
+
listMachines(appName: string): Promise<FlyMachine[]>;
|
|
104
|
+
/** Stop and destroy a machine. */
|
|
105
|
+
destroyMachine(appName: string, machineId: string, force?: boolean): Promise<void>;
|
|
106
|
+
/** Update machine config (e.g. to change size/image). */
|
|
107
|
+
updateMachine(appName: string, machineId: string, config: Partial<FlyMachineConfig>): Promise<FlyMachine>;
|
|
108
|
+
/** Create a persistent volume. */
|
|
109
|
+
createVolume(appName: string, opts: {
|
|
110
|
+
name: string;
|
|
111
|
+
region: string;
|
|
112
|
+
sizeGb: number;
|
|
113
|
+
encrypted?: boolean;
|
|
114
|
+
}): Promise<FlyVolume>;
|
|
115
|
+
/** List volumes for an app. */
|
|
116
|
+
listVolumes(appName: string): Promise<FlyVolume[]>;
|
|
117
|
+
private fetch;
|
|
118
|
+
private json;
|
|
119
|
+
private gql;
|
|
120
|
+
private mapMachine;
|
|
121
|
+
private mapVolume;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=FlyService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlyService.d.ts","sourceRoot":"","sources":["../src/FlyService.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAMH,MAAM,WAAW,SAAS;IACxB,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,UAAU,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE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C,IAAI,CAAC;IAmBtF,yDAAyD;IACnD,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAc/G,kCAAkC;IAC5B,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE;QACxC,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,CAAC,EAAE,OAAO,CAAC;KACrB,GAAG,OAAO,CAAC,SAAS,CAAC;IActB,+BAA+B;IACzB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YAQ1C,KAAK;YAYL,IAAI;YAQJ,GAAG;IAwBjB,OAAO,CAAC,UAAU;IA4BlB,OAAO,CAAC,SAAS;CAalB"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Fly.io Machines API service layer.
|
|
4
|
+
*
|
|
5
|
+
* Wraps the Fly Machines API for app creation, machine management,
|
|
6
|
+
* scaling, and volume provisioning. Uses the GraphQL API for listing
|
|
7
|
+
* apps (organization-scoped) and the Machines REST API for everything else.
|
|
8
|
+
*/
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
// Service
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
export class FlyService {
|
|
13
|
+
config;
|
|
14
|
+
running = false;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.config = {
|
|
17
|
+
...config,
|
|
18
|
+
baseUrl: config.baseUrl ?? 'https://api.machines.dev/v1',
|
|
19
|
+
graphqlUrl: config.graphqlUrl ?? 'https://api.fly.io/graphql',
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
async initialize() {
|
|
23
|
+
// Validate token by listing apps (lightweight org query)
|
|
24
|
+
const res = await this.gql(`
|
|
25
|
+
query { currentUser { id email } }
|
|
26
|
+
`);
|
|
27
|
+
if (!res.currentUser?.id) {
|
|
28
|
+
throw new Error('Fly.io auth failed: could not retrieve user');
|
|
29
|
+
}
|
|
30
|
+
this.running = true;
|
|
31
|
+
}
|
|
32
|
+
async shutdown() {
|
|
33
|
+
this.running = false;
|
|
34
|
+
}
|
|
35
|
+
get isRunning() {
|
|
36
|
+
return this.running;
|
|
37
|
+
}
|
|
38
|
+
// ── Apps ─────────────────────────────────────────────────────────────────
|
|
39
|
+
/** Create a new Fly app. */
|
|
40
|
+
async createApp(name, org) {
|
|
41
|
+
const body = {
|
|
42
|
+
app_name: name,
|
|
43
|
+
org_slug: org ?? 'personal',
|
|
44
|
+
};
|
|
45
|
+
const res = await this.fetch('/apps', {
|
|
46
|
+
method: 'POST',
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
});
|
|
49
|
+
// Machines API returns minimal data on create; fetch full app
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
const text = await res.text();
|
|
52
|
+
throw new Error(`Fly.io API ${res.status}: ${text.slice(0, 500)}`);
|
|
53
|
+
}
|
|
54
|
+
return this.getApp(name);
|
|
55
|
+
}
|
|
56
|
+
/** Get an app by name. */
|
|
57
|
+
async getApp(appName) {
|
|
58
|
+
const result = await this.gql(`
|
|
59
|
+
query($name: String!) {
|
|
60
|
+
app(name: $name) {
|
|
61
|
+
id
|
|
62
|
+
name
|
|
63
|
+
organization { slug }
|
|
64
|
+
status
|
|
65
|
+
hostname
|
|
66
|
+
createdAt
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`, { name: appName });
|
|
70
|
+
const a = result.app;
|
|
71
|
+
return {
|
|
72
|
+
id: a.id,
|
|
73
|
+
name: a.name,
|
|
74
|
+
organization: a.organization?.slug ?? '',
|
|
75
|
+
status: a.status ?? 'pending',
|
|
76
|
+
hostname: a.hostname ?? `${a.name}.fly.dev`,
|
|
77
|
+
createdAt: a.createdAt,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** List all apps in the personal org (via GraphQL). */
|
|
81
|
+
async listApps() {
|
|
82
|
+
const result = await this.gql(`
|
|
83
|
+
query {
|
|
84
|
+
apps {
|
|
85
|
+
nodes {
|
|
86
|
+
id
|
|
87
|
+
name
|
|
88
|
+
organization { slug }
|
|
89
|
+
status
|
|
90
|
+
hostname
|
|
91
|
+
createdAt
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
`);
|
|
96
|
+
return (result.apps?.nodes ?? []).map((a) => ({
|
|
97
|
+
id: a.id,
|
|
98
|
+
name: a.name,
|
|
99
|
+
organization: a.organization?.slug ?? '',
|
|
100
|
+
status: a.status ?? 'pending',
|
|
101
|
+
hostname: a.hostname ?? `${a.name}.fly.dev`,
|
|
102
|
+
createdAt: a.createdAt,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
// ── Machines ─────────────────────────────────────────────────────────────
|
|
106
|
+
/** Create a machine in an app. */
|
|
107
|
+
async createMachine(appName, config, opts) {
|
|
108
|
+
const body = { config };
|
|
109
|
+
if (opts?.name)
|
|
110
|
+
body.name = opts.name;
|
|
111
|
+
if (opts?.region)
|
|
112
|
+
body.region = opts.region;
|
|
113
|
+
const res = await this.fetch(`/apps/${encodeURIComponent(appName)}/machines`, {
|
|
114
|
+
method: 'POST',
|
|
115
|
+
body: JSON.stringify(body),
|
|
116
|
+
});
|
|
117
|
+
const data = await this.json(res);
|
|
118
|
+
return this.mapMachine(data);
|
|
119
|
+
}
|
|
120
|
+
/** List all machines in an app. */
|
|
121
|
+
async listMachines(appName) {
|
|
122
|
+
const res = await this.fetch(`/apps/${encodeURIComponent(appName)}/machines`);
|
|
123
|
+
const data = await this.json(res);
|
|
124
|
+
return data.map((m) => this.mapMachine(m));
|
|
125
|
+
}
|
|
126
|
+
/** Stop and destroy a machine. */
|
|
127
|
+
async destroyMachine(appName, machineId, force = false) {
|
|
128
|
+
// Stop first
|
|
129
|
+
try {
|
|
130
|
+
await this.fetch(`/apps/${encodeURIComponent(appName)}/machines/${machineId}/stop`, { method: 'POST', body: JSON.stringify({}) });
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Machine may already be stopped
|
|
134
|
+
}
|
|
135
|
+
const url = `/apps/${encodeURIComponent(appName)}/machines/${machineId}${force ? '?force=true' : ''}`;
|
|
136
|
+
const res = await this.fetch(url, { method: 'DELETE' });
|
|
137
|
+
if (!res.ok && res.status !== 404) {
|
|
138
|
+
const text = await res.text();
|
|
139
|
+
throw new Error(`Fly.io API ${res.status}: ${text.slice(0, 500)}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** Update machine config (e.g. to change size/image). */
|
|
143
|
+
async updateMachine(appName, machineId, config) {
|
|
144
|
+
const res = await this.fetch(`/apps/${encodeURIComponent(appName)}/machines/${machineId}`, {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
body: JSON.stringify({ config }),
|
|
147
|
+
});
|
|
148
|
+
const data = await this.json(res);
|
|
149
|
+
return this.mapMachine(data);
|
|
150
|
+
}
|
|
151
|
+
// ── Volumes ──────────────────────────────────────────────────────────────
|
|
152
|
+
/** Create a persistent volume. */
|
|
153
|
+
async createVolume(appName, opts) {
|
|
154
|
+
const res = await this.fetch(`/apps/${encodeURIComponent(appName)}/volumes`, {
|
|
155
|
+
method: 'POST',
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
name: opts.name,
|
|
158
|
+
region: opts.region,
|
|
159
|
+
size_gb: opts.sizeGb,
|
|
160
|
+
encrypted: opts.encrypted ?? true,
|
|
161
|
+
}),
|
|
162
|
+
});
|
|
163
|
+
const data = await this.json(res);
|
|
164
|
+
return this.mapVolume(data);
|
|
165
|
+
}
|
|
166
|
+
/** List volumes for an app. */
|
|
167
|
+
async listVolumes(appName) {
|
|
168
|
+
const res = await this.fetch(`/apps/${encodeURIComponent(appName)}/volumes`);
|
|
169
|
+
const data = await this.json(res);
|
|
170
|
+
return data.map((v) => this.mapVolume(v));
|
|
171
|
+
}
|
|
172
|
+
// ── Helpers ──────────────────────────────────────────────────────────────
|
|
173
|
+
async fetch(path, init) {
|
|
174
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
175
|
+
return globalThis.fetch(url, {
|
|
176
|
+
...init,
|
|
177
|
+
headers: {
|
|
178
|
+
'Authorization': `Bearer ${this.config.token}`,
|
|
179
|
+
'Content-Type': 'application/json',
|
|
180
|
+
...(init?.headers ?? {}),
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
async json(res) {
|
|
185
|
+
if (!res.ok) {
|
|
186
|
+
const text = await res.text();
|
|
187
|
+
throw new Error(`Fly.io API ${res.status}: ${text.slice(0, 500)}`);
|
|
188
|
+
}
|
|
189
|
+
return res.json();
|
|
190
|
+
}
|
|
191
|
+
async gql(query, variables) {
|
|
192
|
+
const res = await globalThis.fetch(this.config.graphqlUrl, {
|
|
193
|
+
method: 'POST',
|
|
194
|
+
headers: {
|
|
195
|
+
'Authorization': `Bearer ${this.config.token}`,
|
|
196
|
+
'Content-Type': 'application/json',
|
|
197
|
+
},
|
|
198
|
+
body: JSON.stringify({ query, variables }),
|
|
199
|
+
});
|
|
200
|
+
if (!res.ok) {
|
|
201
|
+
const text = await res.text();
|
|
202
|
+
throw new Error(`Fly.io GraphQL ${res.status}: ${text.slice(0, 500)}`);
|
|
203
|
+
}
|
|
204
|
+
const json = await res.json();
|
|
205
|
+
if (json.errors && json.errors.length > 0) {
|
|
206
|
+
throw new Error(`Fly.io GraphQL: ${json.errors.map(e => e.message).join('; ')}`);
|
|
207
|
+
}
|
|
208
|
+
return json.data;
|
|
209
|
+
}
|
|
210
|
+
mapMachine(data) {
|
|
211
|
+
return {
|
|
212
|
+
id: data.id,
|
|
213
|
+
name: data.name ?? '',
|
|
214
|
+
state: data.state ?? 'unknown',
|
|
215
|
+
region: data.region ?? '',
|
|
216
|
+
instanceId: data.instance_id ?? '',
|
|
217
|
+
privateIp: data.private_ip ?? '',
|
|
218
|
+
config: {
|
|
219
|
+
image: data.config?.image ?? '',
|
|
220
|
+
env: data.config?.env,
|
|
221
|
+
services: data.config?.services,
|
|
222
|
+
guest: data.config?.guest,
|
|
223
|
+
size: data.config?.size,
|
|
224
|
+
auto_destroy: data.config?.auto_destroy,
|
|
225
|
+
restart: data.config?.restart,
|
|
226
|
+
mounts: data.config?.mounts,
|
|
227
|
+
},
|
|
228
|
+
imageRef: data.image_ref ? {
|
|
229
|
+
repository: data.image_ref.repository ?? '',
|
|
230
|
+
tag: data.image_ref.tag ?? '',
|
|
231
|
+
digest: data.image_ref.digest ?? '',
|
|
232
|
+
} : undefined,
|
|
233
|
+
createdAt: data.created_at ?? '',
|
|
234
|
+
updatedAt: data.updated_at ?? '',
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
mapVolume(data) {
|
|
238
|
+
return {
|
|
239
|
+
id: data.id,
|
|
240
|
+
name: data.name ?? '',
|
|
241
|
+
state: data.state ?? 'created',
|
|
242
|
+
sizeGb: data.size_gb ?? 0,
|
|
243
|
+
region: data.region ?? '',
|
|
244
|
+
encrypted: data.encrypted ?? true,
|
|
245
|
+
createdAt: data.created_at ?? '',
|
|
246
|
+
attachedMachineId: data.attached_machine_id,
|
|
247
|
+
attachedAllocId: data.attached_alloc_id,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=FlyService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlyService.js","sourceRoot":"","sources":["../src/FlyService.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;GAMG;AAsEH,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,MAAM,OAAO,UAAU;IACb,MAAM,CAAY;IAClB,OAAO,GAAG,KAAK,CAAC;IAExB,YAAY,MAAiB;QAC3B,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,MAAM;Y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ACrB,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS;YAC9B,MAAM,EAAE,IAAI,CAAC,OAAO,IAAI,CAAC;YACzB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,EAAE;YACzB,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI;YACjC,SAAS,EAAE,IAAI,CAAC,UAAU,IAAI,EAAE;YAChC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB;YAC3C,eAAe,EAAE,IAAI,CAAC,iBAAiB;SACxC,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Fly.io Cloud Extension for AgentOS.
|
|
3
|
+
*
|
|
4
|
+
* Provides 4 tools for deploying apps, listing apps/machines, scaling
|
|
5
|
+
* instances, and creating persistent volumes via the Fly Machines API.
|
|
6
|
+
*
|
|
7
|
+
* @module @framers/agentos-ext-cloud-flyio
|
|
8
|
+
*/
|
|
9
|
+
export interface FlyCloudOptions {
|
|
10
|
+
token?: string;
|
|
11
|
+
secrets?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
export interface ExtensionContext {
|
|
14
|
+
options?: Record<string, unknown>;
|
|
15
|
+
secrets?: Record<string, string>;
|
|
16
|
+
getSecret?: (key: string) => string | undefined;
|
|
17
|
+
logger?: {
|
|
18
|
+
info: (msg: string) => void;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface ExtensionPack {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
descriptors: Array<{
|
|
25
|
+
id: string;
|
|
26
|
+
kind: string;
|
|
27
|
+
priority?: number;
|
|
28
|
+
payload: unknown;
|
|
29
|
+
}>;
|
|
30
|
+
onActivate?: () => Promise<void>;
|
|
31
|
+
onDeactivate?: () => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare function createExtensionPack(context: ExtensionContext): ExtensionPack;
|
|
34
|
+
export { FlyService } from './FlyService.js';
|
|
35
|
+
export type { FlyConfig, FlyApp, FlyMachine, FlyMachineConfig, FlyMachineService, FlyVolume } from './FlyService.js';
|
|
36
|
+
export { FlyDeployAppTool } from './tools/deployApp.js';
|
|
37
|
+
export { FlyListAppsTool } from './tools/listApps.js';
|
|
38
|
+
export { FlyScaleAppTool } from './tools/scaleApp.js';
|
|
39
|
+
export { FlyCreateVolumeTool } from './tools/createVolume.js';
|
|
40
|
+
export default createExtensionPack;
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAaH,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAkBD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAChD,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACtF,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAMD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAkC5E;AAMD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACrH,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D,eAAe,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Fly.io Cloud Extension for AgentOS.
|
|
4
|
+
*
|
|
5
|
+
* Provides 4 tools for deploying apps, listing apps/machines, scaling
|
|
6
|
+
* instances, and creating persistent volumes via the Fly Machines API.
|
|
7
|
+
*
|
|
8
|
+
* @module @framers/agentos-ext-cloud-flyio
|
|
9
|
+
*/
|
|
10
|
+
import { FlyService } from './FlyService.js';
|
|
11
|
+
import { FlyDeployAppTool } from './tools/deployApp.js';
|
|
12
|
+
import { FlyListAppsTool } from './tools/listApps.js';
|
|
13
|
+
import { FlyScaleAppTool } from './tools/scaleApp.js';
|
|
14
|
+
import { FlyCreateVolumeTool } from './tools/createVolume.js';
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Secret Resolution
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
function resolveConfig(opts, secrets) {
|
|
19
|
+
return {
|
|
20
|
+
token: opts.token ?? secrets['fly.token']
|
|
21
|
+
?? process.env.FLY_API_TOKEN ?? '',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Factory
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
export function createExtensionPack(context) {
|
|
28
|
+
const opts = (context.options ?? {});
|
|
29
|
+
const secrets = opts.secrets ?? context.secrets ?? {};
|
|
30
|
+
const config = resolveConfig(opts, secrets);
|
|
31
|
+
const service = new FlyService(config);
|
|
32
|
+
const deployAppTool = new FlyDeployAppTool(service);
|
|
33
|
+
const listAppsTool = new FlyListAppsTool(service);
|
|
34
|
+
const scaleAppTool = new FlyScaleAppTool(service);
|
|
35
|
+
const createVolumeTool = new FlyCreateVolumeTool(service);
|
|
36
|
+
return {
|
|
37
|
+
name: '@framers/agentos-ext-cloud-flyio',
|
|
38
|
+
version: '0.1.0',
|
|
39
|
+
descriptors: [
|
|
40
|
+
{ id: 'flyDeployApp', kind: 'tool', priority: 40, payload: deployAppTool },
|
|
41
|
+
{ id: 'flyListApps', kind: 'tool', priority: 40, payload: listAppsTool },
|
|
42
|
+
{ id: 'flyScaleApp', kind: 'tool', priority: 40, payload: scaleAppTool },
|
|
43
|
+
{ id: 'flyCreateVolume', kind: 'tool', priority: 40, payload: createVolumeTool },
|
|
44
|
+
],
|
|
45
|
+
onActivate: async () => {
|
|
46
|
+
if (!config.token) {
|
|
47
|
+
throw new Error('Fly.io: no API token provided. Set FLY_API_TOKEN environment variable, '
|
|
48
|
+
+ 'or provide it via secrets["fly.token"].');
|
|
49
|
+
}
|
|
50
|
+
await service.initialize();
|
|
51
|
+
},
|
|
52
|
+
onDeactivate: async () => {
|
|
53
|
+
await service.shutdown();
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// Public exports
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
export { FlyService } from './FlyService.js';
|
|
61
|
+
export { FlyDeployAppTool } from './tools/deployApp.js';
|
|
62
|
+
export { FlyListAppsTool } from './tools/listApps.js';
|
|
63
|
+
export { FlyScaleAppTool } from './tools/scaleApp.js';
|
|
64
|
+
export { FlyCreateVolumeTool } from './tools/createVolume.js';
|
|
65
|
+
export default createExtensionPack;
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAW9D,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,SAAS,aAAa,CAAC,IAAqB,EAAE,OAA+B;IAC3E,OAAO;QACL,KAAK,EACH,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,WAAW,CAAC;eAC/B,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE;KACrC,CAAC;AACJ,CAAC;AAqBD,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,MAAM,UAAU,mBAAmB,CAAC,OAAyB;IAC3D,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAoB,CAAC;IACxD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;IACtD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE5C,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IAEvC,MAAM,aA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