@project-ajax/sdk 0.0.28
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/README.md +22 -0
- package/dist/block.d.ts +321 -0
- package/dist/block.d.ts.map +1 -0
- package/dist/block.js +0 -0
- package/dist/builder.d.ts +12 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +22 -0
- package/dist/capabilities/slashCommand.d.ts +56 -0
- package/dist/capabilities/slashCommand.d.ts.map +1 -0
- package/dist/capabilities/slashCommand.js +32 -0
- package/dist/capabilities/sync.d.ts +58 -0
- package/dist/capabilities/sync.d.ts.map +1 -0
- package/dist/capabilities/sync.js +26 -0
- package/dist/capabilities/tool.d.ts +69 -0
- package/dist/capabilities/tool.d.ts.map +1 -0
- package/dist/capabilities/tool.js +75 -0
- package/dist/capabilities/tool.test.d.ts +2 -0
- package/dist/capabilities/tool.test.d.ts.map +1 -0
- package/dist/cli/api/client.d.ts +185 -0
- package/dist/cli/api/client.d.ts.map +1 -0
- package/dist/cli/api/client.js +315 -0
- package/dist/cli/api/result.d.ts +43 -0
- package/dist/cli/api/result.d.ts.map +1 -0
- package/dist/cli/api/result.js +43 -0
- package/dist/cli/bin/cli.d.ts +3 -0
- package/dist/cli/bin/cli.d.ts.map +1 -0
- package/dist/cli/bin/cli.js +5 -0
- package/dist/cli/commands/auth.d.ts +2 -0
- package/dist/cli/commands/auth.d.ts.map +1 -0
- package/dist/cli/commands/auth.impl.d.ts +10 -0
- package/dist/cli/commands/auth.impl.d.ts.map +1 -0
- package/dist/cli/commands/auth.impl.js +68 -0
- package/dist/cli/commands/auth.js +71 -0
- package/dist/cli/commands/bundle.d.ts +2 -0
- package/dist/cli/commands/bundle.d.ts.map +1 -0
- package/dist/cli/commands/bundle.impl.d.ts +2 -0
- package/dist/cli/commands/bundle.impl.d.ts.map +1 -0
- package/dist/cli/commands/bundle.impl.js +21 -0
- package/dist/cli/commands/bundle.js +23 -0
- package/dist/cli/commands/capabilities.d.ts +2 -0
- package/dist/cli/commands/capabilities.d.ts.map +1 -0
- package/dist/cli/commands/capabilities.impl.d.ts +3 -0
- package/dist/cli/commands/capabilities.impl.d.ts.map +1 -0
- package/dist/cli/commands/capabilities.impl.js +40 -0
- package/dist/cli/commands/capabilities.js +24 -0
- package/dist/cli/commands/deploy.d.ts +3 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.impl.d.ts +2 -0
- package/dist/cli/commands/deploy.impl.d.ts.map +1 -0
- package/dist/cli/commands/deploy.impl.js +31 -0
- package/dist/cli/commands/deploy.js +16 -0
- package/dist/cli/commands/exec.d.ts +3 -0
- package/dist/cli/commands/exec.d.ts.map +1 -0
- package/dist/cli/commands/exec.impl.d.ts +7 -0
- package/dist/cli/commands/exec.impl.d.ts.map +1 -0
- package/dist/cli/commands/exec.impl.js +122 -0
- package/dist/cli/commands/exec.js +30 -0
- package/dist/cli/commands/runs.d.ts +2 -0
- package/dist/cli/commands/runs.d.ts.map +1 -0
- package/dist/cli/commands/runs.impl.d.ts +4 -0
- package/dist/cli/commands/runs.impl.d.ts.map +1 -0
- package/dist/cli/commands/runs.impl.js +71 -0
- package/dist/cli/commands/runs.js +45 -0
- package/dist/cli/commands/secrets.d.ts +2 -0
- package/dist/cli/commands/secrets.d.ts.map +1 -0
- package/dist/cli/commands/secrets.impl.d.ts +5 -0
- package/dist/cli/commands/secrets.impl.d.ts.map +1 -0
- package/dist/cli/commands/secrets.impl.js +93 -0
- package/dist/cli/commands/secrets.js +64 -0
- package/dist/cli/config.d.ts +38 -0
- package/dist/cli/config.d.ts.map +1 -0
- package/dist/cli/config.js +133 -0
- package/dist/cli/context.d.ts +15 -0
- package/dist/cli/context.d.ts.map +1 -0
- package/dist/cli/context.js +16 -0
- package/dist/cli/deploy.d.ts +25 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +101 -0
- package/dist/cli/flags.d.ts +16 -0
- package/dist/cli/flags.d.ts.map +1 -0
- package/dist/cli/flags.js +24 -0
- package/dist/cli/handler.d.ts +14 -0
- package/dist/cli/handler.d.ts.map +1 -0
- package/dist/cli/handler.js +30 -0
- package/dist/cli/routes.d.ts +2 -0
- package/dist/cli/routes.d.ts.map +1 -0
- package/dist/cli/routes.js +44 -0
- package/dist/cli/utils/array.d.ts +2 -0
- package/dist/cli/utils/array.d.ts.map +1 -0
- package/dist/cli/utils/array.js +10 -0
- package/dist/cli/utils/string.d.ts +2 -0
- package/dist/cli/utils/string.d.ts.map +1 -0
- package/dist/cli/utils/string.js +12 -0
- package/dist/cli/writer.d.ts +48 -0
- package/dist/cli/writer.d.ts.map +1 -0
- package/dist/cli/writer.js +73 -0
- package/dist/error.d.ts +8 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +11 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/schema.d.ts +45 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +14 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +0 -0
- package/package.json +79 -0
- package/src/block.ts +529 -0
- package/src/builder.ts +26 -0
- package/src/capabilities/slashCommand.ts +71 -0
- package/src/capabilities/sync.ts +76 -0
- package/src/capabilities/tool.test.ts +181 -0
- package/src/capabilities/tool.ts +145 -0
- package/src/cli/api/client.ts +588 -0
- package/src/cli/api/result.ts +71 -0
- package/src/cli/bin/cli.ts +7 -0
- package/src/cli/commands/auth.impl.ts +92 -0
- package/src/cli/commands/auth.ts +77 -0
- package/src/cli/commands/bundle.impl.ts +21 -0
- package/src/cli/commands/bundle.ts +23 -0
- package/src/cli/commands/capabilities.impl.ts +47 -0
- package/src/cli/commands/capabilities.ts +25 -0
- package/src/cli/commands/deploy.impl.ts +34 -0
- package/src/cli/commands/deploy.ts +16 -0
- package/src/cli/commands/exec.impl.ts +169 -0
- package/src/cli/commands/exec.ts +32 -0
- package/src/cli/commands/runs.impl.ts +87 -0
- package/src/cli/commands/runs.ts +49 -0
- package/src/cli/commands/secrets.impl.ts +124 -0
- package/src/cli/commands/secrets.ts +73 -0
- package/src/cli/config.ts +175 -0
- package/src/cli/context.ts +26 -0
- package/src/cli/deploy.ts +175 -0
- package/src/cli/flags.ts +43 -0
- package/src/cli/handler.ts +62 -0
- package/src/cli/routes.ts +43 -0
- package/src/cli/utils/array.ts +7 -0
- package/src/cli/utils/string.ts +9 -0
- package/src/cli/writer.ts +97 -0
- package/src/error.ts +12 -0
- package/src/index.ts +3 -0
- package/src/schema.ts +54 -0
- package/src/types.ts +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/auth.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,wEAwEvB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Environment } from "../config.js";
|
|
2
|
+
interface LoginFlags {
|
|
3
|
+
env?: Environment;
|
|
4
|
+
"base-url"?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const login: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & LoginFlags, token?: string | undefined) => Promise<void>;
|
|
7
|
+
export declare const show: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags) => Promise<void>;
|
|
8
|
+
export declare const logout: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags) => Promise<void>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=auth.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/auth.impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,UAAU,UAAU;IACnB,GAAG,CAAC,EAAE,WAAW,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAqCD,eAAO,MAAM,KAAK,kJAqChB,CAAC;AAEH,eAAO,MAAM,IAAI,yGAEf,CAAC;AAEH,eAAO,MAAM,MAAM,yGAEjB,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { exec } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { baseUrl } from "../api/client.js";
|
|
4
|
+
import { buildHandler } from "../handler.js";
|
|
5
|
+
async function openUrl(env, url) {
|
|
6
|
+
const platform = process.platform;
|
|
7
|
+
try {
|
|
8
|
+
if (platform === "darwin") {
|
|
9
|
+
let notionAppName = null;
|
|
10
|
+
if (env === "prod" && existsSync("/Applications/Notion.app")) {
|
|
11
|
+
notionAppName = "Notion";
|
|
12
|
+
} else if (env === "dev" && existsSync("/Applications/Notion Dev.app")) {
|
|
13
|
+
notionAppName = "Notion Dev";
|
|
14
|
+
}
|
|
15
|
+
if (notionAppName) {
|
|
16
|
+
exec(`open -a "${notionAppName}" "${url}"`);
|
|
17
|
+
} else {
|
|
18
|
+
exec(`open "${url}"`);
|
|
19
|
+
}
|
|
20
|
+
} else if (platform === "win32") {
|
|
21
|
+
exec(`start "" "${url}"`);
|
|
22
|
+
} else {
|
|
23
|
+
exec(`xdg-open "${url}"`);
|
|
24
|
+
}
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error(`Failed to open browser: ${error}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const login = buildHandler(async function(flags, token) {
|
|
30
|
+
const environment = flags.env ?? "prod";
|
|
31
|
+
if (flags["base-url"]) {
|
|
32
|
+
await this.config.setBaseUrl(flags["base-url"]);
|
|
33
|
+
}
|
|
34
|
+
if (!token) {
|
|
35
|
+
const url = `${baseUrl({
|
|
36
|
+
environment,
|
|
37
|
+
override: this.config.baseUrl
|
|
38
|
+
})}/__workers__?createToken=true`;
|
|
39
|
+
this.writer.writeErr(`Opening browser to create a token...
|
|
40
|
+
${url}
|
|
41
|
+
`);
|
|
42
|
+
this.writer.writeErr("After creating a token, run:");
|
|
43
|
+
this.writer.writeErr(" npx workers auth login <token>");
|
|
44
|
+
try {
|
|
45
|
+
await openUrl(environment, url);
|
|
46
|
+
} catch (_error) {
|
|
47
|
+
this.writer.writeErr(
|
|
48
|
+
`Failed to open browser automatically. Please visit:
|
|
49
|
+
${url}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await this.config.setEnvironment(environment);
|
|
55
|
+
await this.config.setToken(token);
|
|
56
|
+
this.writer.writeErr("Successfully logged in!");
|
|
57
|
+
});
|
|
58
|
+
const show = buildHandler(function() {
|
|
59
|
+
this.writer.writeOut(`${this.config.token ?? ""}`);
|
|
60
|
+
});
|
|
61
|
+
const logout = buildHandler(async function() {
|
|
62
|
+
await this.config.setToken(null);
|
|
63
|
+
});
|
|
64
|
+
export {
|
|
65
|
+
login,
|
|
66
|
+
logout,
|
|
67
|
+
show
|
|
68
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { Environments } from "../config.js";
|
|
3
|
+
import { globalFlags } from "../flags.js";
|
|
4
|
+
const authCommands = buildRouteMap({
|
|
5
|
+
docs: {
|
|
6
|
+
brief: "Commands for managing the CLI context"
|
|
7
|
+
},
|
|
8
|
+
routes: {
|
|
9
|
+
login: buildCommand({
|
|
10
|
+
docs: {
|
|
11
|
+
brief: "Login to the Project Ajax platform using a Workers API token"
|
|
12
|
+
},
|
|
13
|
+
parameters: {
|
|
14
|
+
positional: {
|
|
15
|
+
kind: "tuple",
|
|
16
|
+
parameters: [
|
|
17
|
+
{
|
|
18
|
+
brief: "A Workers API token",
|
|
19
|
+
parse: String,
|
|
20
|
+
placeholder: "api-token",
|
|
21
|
+
optional: true
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
flags: {
|
|
26
|
+
env: {
|
|
27
|
+
kind: "enum",
|
|
28
|
+
values: Environments,
|
|
29
|
+
brief: "The environment to use for the command",
|
|
30
|
+
optional: true,
|
|
31
|
+
hidden: true
|
|
32
|
+
},
|
|
33
|
+
"base-url": {
|
|
34
|
+
kind: "parsed",
|
|
35
|
+
parse: String,
|
|
36
|
+
brief: "The base URL to use for all API requests",
|
|
37
|
+
optional: true,
|
|
38
|
+
hidden: true
|
|
39
|
+
},
|
|
40
|
+
...globalFlags
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
loader: () => import("./auth.impl.js").then((m) => m.login)
|
|
44
|
+
}),
|
|
45
|
+
show: buildCommand({
|
|
46
|
+
docs: {
|
|
47
|
+
brief: "Get the token for the CLI"
|
|
48
|
+
},
|
|
49
|
+
parameters: {
|
|
50
|
+
flags: {
|
|
51
|
+
...globalFlags
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
loader: () => import("./auth.impl.js").then((m) => m.show)
|
|
55
|
+
}),
|
|
56
|
+
logout: buildCommand({
|
|
57
|
+
docs: {
|
|
58
|
+
brief: "Unset the token for the CLI"
|
|
59
|
+
},
|
|
60
|
+
parameters: {
|
|
61
|
+
flags: {
|
|
62
|
+
...globalFlags
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
loader: () => import("./auth.impl.js").then((m) => m.logout)
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
export {
|
|
70
|
+
authCommands
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/bundle.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,wEAmBzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/bundle.impl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,yGAgBzB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { Result } from "../api/result.js";
|
|
3
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
+
const downloadBundle = buildAuthedHandler(async function() {
|
|
5
|
+
const { workerId } = this.config;
|
|
6
|
+
if (!workerId) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const result = await this.apiClient.downloadWorkerBundle(workerId);
|
|
12
|
+
if (Result.isFail(result)) {
|
|
13
|
+
this.writer.writeErr(`\u2717 Failed to download bundle`);
|
|
14
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
Readable.fromWeb(result.value).pipe(this.process.stdout);
|
|
18
|
+
});
|
|
19
|
+
export {
|
|
20
|
+
downloadBundle
|
|
21
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { globalFlags } from "../flags.js";
|
|
3
|
+
const bundleCommands = buildRouteMap({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Commands for managing worker bundles"
|
|
6
|
+
},
|
|
7
|
+
routes: {
|
|
8
|
+
download: buildCommand({
|
|
9
|
+
docs: {
|
|
10
|
+
brief: "Download the bundle for the worker"
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
flags: {
|
|
14
|
+
...globalFlags
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
loader: () => import("./bundle.impl.js").then((m) => m.downloadBundle)
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
export {
|
|
22
|
+
bundleCommands
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/capabilities.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,wEAqB/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/capabilities.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,eAAO,MAAM,gBAAgB,uHA0C3B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Result } from "../api/result.js";
|
|
2
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
+
const listCapabilities = buildAuthedHandler(async function(flags) {
|
|
4
|
+
const { workerId } = this.config;
|
|
5
|
+
if (!workerId) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
this.process.stderr.write(`Fetching capabilities...`);
|
|
11
|
+
const result = await this.apiClient.listCapabilities(workerId);
|
|
12
|
+
if (Result.isSuccess(result)) {
|
|
13
|
+
this.process.stderr.write("OK\n\n");
|
|
14
|
+
const data = Result.unwrap(result);
|
|
15
|
+
if (data.capabilities.length === 0) {
|
|
16
|
+
this.writer.writeErr("No capabilities found for this worker.");
|
|
17
|
+
} else {
|
|
18
|
+
this.writer.writeTableOut({
|
|
19
|
+
headers: ["Key", "Tag"],
|
|
20
|
+
rows: data.capabilities.map((capability) => [
|
|
21
|
+
capability.key,
|
|
22
|
+
capability._tag
|
|
23
|
+
]),
|
|
24
|
+
plain: flags.plain
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
} else {
|
|
28
|
+
this.process.stderr.write("ERROR\n\n");
|
|
29
|
+
if (result.error.validationError) {
|
|
30
|
+
this.writer.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
31
|
+
throw new Error(result.error.validationError.debugMessage);
|
|
32
|
+
} else {
|
|
33
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
34
|
+
throw new Error(result.error.message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
export {
|
|
39
|
+
listCapabilities
|
|
40
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
+
const capabilitiesCommands = buildRouteMap({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Commands for managing worker capabilities"
|
|
6
|
+
},
|
|
7
|
+
routes: {
|
|
8
|
+
list: buildCommand({
|
|
9
|
+
docs: {
|
|
10
|
+
brief: "List all capabilities for a worker"
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
flags: {
|
|
14
|
+
...globalFlags,
|
|
15
|
+
...formatFlags
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
loader: () => import("./capabilities.impl.js").then((m) => m.listCapabilities)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export {
|
|
23
|
+
capabilitiesCommands
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAYG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM,yGA6BjB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Result } from "../api/result.js";
|
|
2
|
+
import { deployWorker } from "../deploy.js";
|
|
3
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
4
|
+
const deploy = buildAuthedHandler(async function() {
|
|
5
|
+
const { token } = this.config.tokenInfo;
|
|
6
|
+
const workerId = this.config.workerId;
|
|
7
|
+
const environment = this.config.environment;
|
|
8
|
+
if (!environment) {
|
|
9
|
+
throw new Error("Unexpected error: Environment not set");
|
|
10
|
+
}
|
|
11
|
+
const workerPath = this.process.cwd();
|
|
12
|
+
this.writer.writeErr("Deploying worker...");
|
|
13
|
+
const result = await deployWorker(this, {
|
|
14
|
+
workerPath,
|
|
15
|
+
workerId,
|
|
16
|
+
token,
|
|
17
|
+
environment
|
|
18
|
+
});
|
|
19
|
+
if (Result.isSuccess(result)) {
|
|
20
|
+
const { workerId: workerId2 } = Result.unwrap(result);
|
|
21
|
+
await this.config.setWorkerId(workerId2);
|
|
22
|
+
this.writer.writeErr("\u2713 Successfully deployed worker");
|
|
23
|
+
} else {
|
|
24
|
+
this.writer.writeErr("\u2717 Failed to deploy worker");
|
|
25
|
+
this.writer.writeErr(result.error.message);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
export {
|
|
30
|
+
deploy
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { buildCommand } from "@stricli/core";
|
|
2
|
+
import { globalFlags } from "../flags.js";
|
|
3
|
+
var deploy_default = buildCommand({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Deploy a worker to the Project Ajax platform"
|
|
6
|
+
},
|
|
7
|
+
parameters: {
|
|
8
|
+
flags: {
|
|
9
|
+
...globalFlags
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
loader: () => import("./deploy.impl.js").then((m) => m.deploy)
|
|
13
|
+
});
|
|
14
|
+
export {
|
|
15
|
+
deploy_default as default
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/exec.ts"],"names":[],"mappings":";AAGA,wBA4BG"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GlobalFlags } from "../flags.js";
|
|
2
|
+
interface ExecFlags extends GlobalFlags {
|
|
3
|
+
stream: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const exec: (this: import("../context.js").LocalContext, flags: GlobalFlags & ExecFlags, ...args: readonly string[]) => Promise<void>;
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=exec.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exec.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/exec.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAM/C,UAAU,SAAU,SAAQ,WAAW;IACtC,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,IAAI,2HAyJf,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Result } from "../api/result.js";
|
|
2
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
+
import { chunkEvery } from "../utils/array.js";
|
|
4
|
+
const usageHint = `Usage: workers exec <capabilityName> <capabilityFunction> [<argName1>=<value1> <argName2>=<value2>...]`;
|
|
5
|
+
const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
6
|
+
const { workerId } = this.config;
|
|
7
|
+
if (!workerId) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
const capabilityName = args[0];
|
|
13
|
+
const capabilityFunction = args[1] ?? null;
|
|
14
|
+
const functionArgs = args.slice(2).flatMap((arg) => arg.split(/[=]/));
|
|
15
|
+
if (!capabilityName) {
|
|
16
|
+
throw usageError();
|
|
17
|
+
}
|
|
18
|
+
if (functionArgs.length % 2 !== 0) {
|
|
19
|
+
throw usageError();
|
|
20
|
+
}
|
|
21
|
+
const argsList = chunkEvery(functionArgs, 2).map(([key, value]) => {
|
|
22
|
+
if (!key || !value) {
|
|
23
|
+
throw usageError();
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
name: key,
|
|
27
|
+
value
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
this.writer.writeErr(`Executing capability "${capabilityName}"...`);
|
|
31
|
+
if (flags.stream) {
|
|
32
|
+
const result = await this.apiClient.runCapability(
|
|
33
|
+
workerId,
|
|
34
|
+
capabilityName,
|
|
35
|
+
capabilityFunction,
|
|
36
|
+
argsList,
|
|
37
|
+
true
|
|
38
|
+
);
|
|
39
|
+
if (Result.isSuccess(result)) {
|
|
40
|
+
const decoder = new TextDecoder();
|
|
41
|
+
let buffer = "";
|
|
42
|
+
const allOutput = [];
|
|
43
|
+
const onBodyLine = async (jsonLine) => {
|
|
44
|
+
try {
|
|
45
|
+
const parsedLine = JSON.parse(jsonLine);
|
|
46
|
+
switch (parsedLine._tag) {
|
|
47
|
+
case "log":
|
|
48
|
+
if (parsedLine.event.stream === "stdout") {
|
|
49
|
+
allOutput.push(parsedLine.event.data);
|
|
50
|
+
}
|
|
51
|
+
parsedLine.event.data.trim().split("\n").forEach((dataLine) => {
|
|
52
|
+
this.writer.writeErr(
|
|
53
|
+
`[worker:${parsedLine.event.stream}] ${dataLine.trim()}`
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
57
|
+
case "result":
|
|
58
|
+
this.writer.writeOut(JSON.stringify(parsedLine.result, null, 2));
|
|
59
|
+
break;
|
|
60
|
+
case "error":
|
|
61
|
+
this.writer.writeErr(`Error: ${parsedLine.error}`);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
this.writer.writeErr(`Error parsing log line: ${jsonLine}: ${error}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
for await (const log of result.value) {
|
|
69
|
+
const output = decoder.decode(log);
|
|
70
|
+
buffer += output;
|
|
71
|
+
const lines = buffer.split("\n");
|
|
72
|
+
buffer = lines.pop() ?? "";
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
await onBodyLine(line);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (buffer) {
|
|
78
|
+
await onBodyLine(buffer);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
} else {
|
|
82
|
+
this.writer.writeErr(`
|
|
83
|
+
\u2717 Failed to execute capability`);
|
|
84
|
+
if (result.error.validationError) {
|
|
85
|
+
this.writer.writeErr(` \u2717 HTTP Error: ${result.error.status}`);
|
|
86
|
+
this.writer.writeErr(
|
|
87
|
+
` \u2717 ${result.error.validationError.debugMessage}`
|
|
88
|
+
);
|
|
89
|
+
this.writer.writeErr(`
|
|
90
|
+
${usageHint}`);
|
|
91
|
+
throw new Error(result.error.validationError.debugMessage);
|
|
92
|
+
} else {
|
|
93
|
+
this.writer.writeErr(` \u2717 HTTP Error: ${result.error.status}`);
|
|
94
|
+
this.writer.writeErr(` \u2717 ${result.error.message}`);
|
|
95
|
+
throw new Error(result.error.message);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
const result = await this.apiClient.runCapability(
|
|
100
|
+
workerId,
|
|
101
|
+
capabilityName,
|
|
102
|
+
capabilityFunction,
|
|
103
|
+
argsList,
|
|
104
|
+
false
|
|
105
|
+
);
|
|
106
|
+
if (Result.isSuccess(result)) {
|
|
107
|
+
const data = Result.unwrap(result);
|
|
108
|
+
this.writer.writeOut(JSON.stringify(data.result, null, 2));
|
|
109
|
+
} else {
|
|
110
|
+
this.writer.writeErr(`
|
|
111
|
+
\u2717 Failed to execute capability`);
|
|
112
|
+
this.writer.writeErr(` \u2717 ${result.error.message}`);
|
|
113
|
+
throw new Error(result.error.message);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
function usageError() {
|
|
118
|
+
return new Error(`Invalid arguments provided. ${usageHint}`);
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
exec
|
|
122
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { buildCommand } from "@stricli/core";
|
|
2
|
+
import { globalFlags } from "../flags.js";
|
|
3
|
+
var exec_default = buildCommand({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Execute a worker capability with optional function and arguments"
|
|
6
|
+
},
|
|
7
|
+
parameters: {
|
|
8
|
+
positional: {
|
|
9
|
+
kind: "array",
|
|
10
|
+
parameter: {
|
|
11
|
+
brief: "Capability name, optional function name, and arguments (key value pairs)",
|
|
12
|
+
parse: String,
|
|
13
|
+
placeholder: "capabilityName [functionName] [key value]..."
|
|
14
|
+
},
|
|
15
|
+
minimum: 1
|
|
16
|
+
},
|
|
17
|
+
flags: {
|
|
18
|
+
...globalFlags,
|
|
19
|
+
stream: {
|
|
20
|
+
kind: "boolean",
|
|
21
|
+
brief: "Stream the output of the capability",
|
|
22
|
+
default: true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
loader: () => import("./exec.impl.js").then((m) => m.exec)
|
|
27
|
+
});
|
|
28
|
+
export {
|
|
29
|
+
exec_default as default
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runs.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/runs.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,wEA6CvB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
2
|
+
export declare const listRuns: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
3
|
+
export declare const getRunLogs: (this: import("../context.js").LocalContext, flags: GlobalFlags, runId: string) => Promise<void>;
|
|
4
|
+
//# sourceMappingURL=runs.impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runs.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/runs.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG5D,eAAO,MAAM,QAAQ,iGA2CnB,CAAC;AAEH,eAAO,MAAM,UAAU,kGAqCrB,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Result } from "../api/result.js";
|
|
2
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
+
const listRuns = buildAuthedHandler(async function(flags) {
|
|
4
|
+
const { workerId } = this.config;
|
|
5
|
+
if (!workerId) {
|
|
6
|
+
throw new Error(
|
|
7
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
this.process.stderr.write("Fetching runs...");
|
|
11
|
+
const result = await this.apiClient.listRunsForWorker(workerId);
|
|
12
|
+
if (Result.isSuccess(result)) {
|
|
13
|
+
this.process.stderr.write("OK\n\n");
|
|
14
|
+
const data = Result.unwrap(result);
|
|
15
|
+
if (data.runs.length === 0) {
|
|
16
|
+
this.writer.writeErr("No runs found for this worker.");
|
|
17
|
+
} else {
|
|
18
|
+
this.writer.writeTableOut({
|
|
19
|
+
headers: ["Run ID", "Name", "Started At", "Ended At", "Exit Code"],
|
|
20
|
+
rows: data.runs.map((run) => [
|
|
21
|
+
run.runId,
|
|
22
|
+
run.name,
|
|
23
|
+
run.startedAt,
|
|
24
|
+
run.endedAt,
|
|
25
|
+
run.exitCode
|
|
26
|
+
]),
|
|
27
|
+
plain: flags.plain
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
this.process.stderr.write("ERROR\n\n");
|
|
32
|
+
if (result.error.validationError) {
|
|
33
|
+
this.writer.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
34
|
+
throw new Error(result.error.validationError.debugMessage);
|
|
35
|
+
} else {
|
|
36
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
37
|
+
throw new Error(result.error.message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
const getRunLogs = buildAuthedHandler(async function(_flags, runId) {
|
|
42
|
+
const { workerId } = this.config;
|
|
43
|
+
if (!workerId) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
if (!runId) {
|
|
49
|
+
throw new Error("Run ID is required");
|
|
50
|
+
}
|
|
51
|
+
this.process.stderr.write(`Fetching logs for run ${runId}...`);
|
|
52
|
+
const result = await this.apiClient.getRunLogs(workerId, runId);
|
|
53
|
+
if (Result.isSuccess(result)) {
|
|
54
|
+
this.process.stderr.write("OK\n\n");
|
|
55
|
+
const data = Result.unwrap(result);
|
|
56
|
+
this.writer.writeOut(data.logs);
|
|
57
|
+
} else {
|
|
58
|
+
this.process.stderr.write("ERROR\n\n");
|
|
59
|
+
if (result.error.validationError) {
|
|
60
|
+
this.writer.writeErr(`\u2717 ${result.error.validationError.debugMessage}`);
|
|
61
|
+
throw new Error(result.error.validationError.debugMessage);
|
|
62
|
+
} else {
|
|
63
|
+
this.writer.writeErr(`\u2717 ${result.error.message}`);
|
|
64
|
+
throw new Error(result.error.message);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
export {
|
|
69
|
+
getRunLogs,
|
|
70
|
+
listRuns
|
|
71
|
+
};
|