@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.
Files changed (145) hide show
  1. package/README.md +22 -0
  2. package/dist/block.d.ts +321 -0
  3. package/dist/block.d.ts.map +1 -0
  4. package/dist/block.js +0 -0
  5. package/dist/builder.d.ts +12 -0
  6. package/dist/builder.d.ts.map +1 -0
  7. package/dist/builder.js +22 -0
  8. package/dist/capabilities/slashCommand.d.ts +56 -0
  9. package/dist/capabilities/slashCommand.d.ts.map +1 -0
  10. package/dist/capabilities/slashCommand.js +32 -0
  11. package/dist/capabilities/sync.d.ts +58 -0
  12. package/dist/capabilities/sync.d.ts.map +1 -0
  13. package/dist/capabilities/sync.js +26 -0
  14. package/dist/capabilities/tool.d.ts +69 -0
  15. package/dist/capabilities/tool.d.ts.map +1 -0
  16. package/dist/capabilities/tool.js +75 -0
  17. package/dist/capabilities/tool.test.d.ts +2 -0
  18. package/dist/capabilities/tool.test.d.ts.map +1 -0
  19. package/dist/cli/api/client.d.ts +185 -0
  20. package/dist/cli/api/client.d.ts.map +1 -0
  21. package/dist/cli/api/client.js +315 -0
  22. package/dist/cli/api/result.d.ts +43 -0
  23. package/dist/cli/api/result.d.ts.map +1 -0
  24. package/dist/cli/api/result.js +43 -0
  25. package/dist/cli/bin/cli.d.ts +3 -0
  26. package/dist/cli/bin/cli.d.ts.map +1 -0
  27. package/dist/cli/bin/cli.js +5 -0
  28. package/dist/cli/commands/auth.d.ts +2 -0
  29. package/dist/cli/commands/auth.d.ts.map +1 -0
  30. package/dist/cli/commands/auth.impl.d.ts +10 -0
  31. package/dist/cli/commands/auth.impl.d.ts.map +1 -0
  32. package/dist/cli/commands/auth.impl.js +68 -0
  33. package/dist/cli/commands/auth.js +71 -0
  34. package/dist/cli/commands/bundle.d.ts +2 -0
  35. package/dist/cli/commands/bundle.d.ts.map +1 -0
  36. package/dist/cli/commands/bundle.impl.d.ts +2 -0
  37. package/dist/cli/commands/bundle.impl.d.ts.map +1 -0
  38. package/dist/cli/commands/bundle.impl.js +21 -0
  39. package/dist/cli/commands/bundle.js +23 -0
  40. package/dist/cli/commands/capabilities.d.ts +2 -0
  41. package/dist/cli/commands/capabilities.d.ts.map +1 -0
  42. package/dist/cli/commands/capabilities.impl.d.ts +3 -0
  43. package/dist/cli/commands/capabilities.impl.d.ts.map +1 -0
  44. package/dist/cli/commands/capabilities.impl.js +40 -0
  45. package/dist/cli/commands/capabilities.js +24 -0
  46. package/dist/cli/commands/deploy.d.ts +3 -0
  47. package/dist/cli/commands/deploy.d.ts.map +1 -0
  48. package/dist/cli/commands/deploy.impl.d.ts +2 -0
  49. package/dist/cli/commands/deploy.impl.d.ts.map +1 -0
  50. package/dist/cli/commands/deploy.impl.js +31 -0
  51. package/dist/cli/commands/deploy.js +16 -0
  52. package/dist/cli/commands/exec.d.ts +3 -0
  53. package/dist/cli/commands/exec.d.ts.map +1 -0
  54. package/dist/cli/commands/exec.impl.d.ts +7 -0
  55. package/dist/cli/commands/exec.impl.d.ts.map +1 -0
  56. package/dist/cli/commands/exec.impl.js +122 -0
  57. package/dist/cli/commands/exec.js +30 -0
  58. package/dist/cli/commands/runs.d.ts +2 -0
  59. package/dist/cli/commands/runs.d.ts.map +1 -0
  60. package/dist/cli/commands/runs.impl.d.ts +4 -0
  61. package/dist/cli/commands/runs.impl.d.ts.map +1 -0
  62. package/dist/cli/commands/runs.impl.js +71 -0
  63. package/dist/cli/commands/runs.js +45 -0
  64. package/dist/cli/commands/secrets.d.ts +2 -0
  65. package/dist/cli/commands/secrets.d.ts.map +1 -0
  66. package/dist/cli/commands/secrets.impl.d.ts +5 -0
  67. package/dist/cli/commands/secrets.impl.d.ts.map +1 -0
  68. package/dist/cli/commands/secrets.impl.js +93 -0
  69. package/dist/cli/commands/secrets.js +64 -0
  70. package/dist/cli/config.d.ts +38 -0
  71. package/dist/cli/config.d.ts.map +1 -0
  72. package/dist/cli/config.js +133 -0
  73. package/dist/cli/context.d.ts +15 -0
  74. package/dist/cli/context.d.ts.map +1 -0
  75. package/dist/cli/context.js +16 -0
  76. package/dist/cli/deploy.d.ts +25 -0
  77. package/dist/cli/deploy.d.ts.map +1 -0
  78. package/dist/cli/deploy.js +101 -0
  79. package/dist/cli/flags.d.ts +16 -0
  80. package/dist/cli/flags.d.ts.map +1 -0
  81. package/dist/cli/flags.js +24 -0
  82. package/dist/cli/handler.d.ts +14 -0
  83. package/dist/cli/handler.d.ts.map +1 -0
  84. package/dist/cli/handler.js +30 -0
  85. package/dist/cli/routes.d.ts +2 -0
  86. package/dist/cli/routes.d.ts.map +1 -0
  87. package/dist/cli/routes.js +44 -0
  88. package/dist/cli/utils/array.d.ts +2 -0
  89. package/dist/cli/utils/array.d.ts.map +1 -0
  90. package/dist/cli/utils/array.js +10 -0
  91. package/dist/cli/utils/string.d.ts +2 -0
  92. package/dist/cli/utils/string.d.ts.map +1 -0
  93. package/dist/cli/utils/string.js +12 -0
  94. package/dist/cli/writer.d.ts +48 -0
  95. package/dist/cli/writer.d.ts.map +1 -0
  96. package/dist/cli/writer.js +73 -0
  97. package/dist/error.d.ts +8 -0
  98. package/dist/error.d.ts.map +1 -0
  99. package/dist/error.js +11 -0
  100. package/dist/index.d.ts +4 -0
  101. package/dist/index.d.ts.map +1 -0
  102. package/dist/index.js +8 -0
  103. package/dist/schema.d.ts +45 -0
  104. package/dist/schema.d.ts.map +1 -0
  105. package/dist/schema.js +14 -0
  106. package/dist/types.d.ts +11 -0
  107. package/dist/types.d.ts.map +1 -0
  108. package/dist/types.js +0 -0
  109. package/package.json +79 -0
  110. package/src/block.ts +529 -0
  111. package/src/builder.ts +26 -0
  112. package/src/capabilities/slashCommand.ts +71 -0
  113. package/src/capabilities/sync.ts +76 -0
  114. package/src/capabilities/tool.test.ts +181 -0
  115. package/src/capabilities/tool.ts +145 -0
  116. package/src/cli/api/client.ts +588 -0
  117. package/src/cli/api/result.ts +71 -0
  118. package/src/cli/bin/cli.ts +7 -0
  119. package/src/cli/commands/auth.impl.ts +92 -0
  120. package/src/cli/commands/auth.ts +77 -0
  121. package/src/cli/commands/bundle.impl.ts +21 -0
  122. package/src/cli/commands/bundle.ts +23 -0
  123. package/src/cli/commands/capabilities.impl.ts +47 -0
  124. package/src/cli/commands/capabilities.ts +25 -0
  125. package/src/cli/commands/deploy.impl.ts +34 -0
  126. package/src/cli/commands/deploy.ts +16 -0
  127. package/src/cli/commands/exec.impl.ts +169 -0
  128. package/src/cli/commands/exec.ts +32 -0
  129. package/src/cli/commands/runs.impl.ts +87 -0
  130. package/src/cli/commands/runs.ts +49 -0
  131. package/src/cli/commands/secrets.impl.ts +124 -0
  132. package/src/cli/commands/secrets.ts +73 -0
  133. package/src/cli/config.ts +175 -0
  134. package/src/cli/context.ts +26 -0
  135. package/src/cli/deploy.ts +175 -0
  136. package/src/cli/flags.ts +43 -0
  137. package/src/cli/handler.ts +62 -0
  138. package/src/cli/routes.ts +43 -0
  139. package/src/cli/utils/array.ts +7 -0
  140. package/src/cli/utils/string.ts +9 -0
  141. package/src/cli/writer.ts +97 -0
  142. package/src/error.ts +12 -0
  143. package/src/index.ts +3 -0
  144. package/src/schema.ts +54 -0
  145. 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,2 @@
1
+ export declare const bundleCommands: import("@stricli/core").RouteMap<import("../context.js").LocalContext>;
2
+ //# sourceMappingURL=bundle.d.ts.map
@@ -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,2 @@
1
+ export declare const downloadBundle: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags) => Promise<void>;
2
+ //# sourceMappingURL=bundle.impl.d.ts.map
@@ -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,2 @@
1
+ export declare const capabilitiesCommands: import("@stricli/core").RouteMap<import("../context.js").LocalContext>;
2
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -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,3 @@
1
+ import type { FormatFlags } from "../flags.js";
2
+ export declare const listCapabilities: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & FormatFlags) => Promise<void>;
3
+ //# sourceMappingURL=capabilities.impl.d.ts.map
@@ -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,3 @@
1
+ declare const _default: import("@stricli/core").Command<import("../context.js").LocalContext>;
2
+ export default _default;
3
+ //# sourceMappingURL=deploy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAYG"}
@@ -0,0 +1,2 @@
1
+ export declare const deploy: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags) => Promise<void>;
2
+ //# sourceMappingURL=deploy.impl.d.ts.map
@@ -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,3 @@
1
+ declare const _default: import("@stricli/core").Command<import("../context.js").LocalContext>;
2
+ export default _default;
3
+ //# sourceMappingURL=exec.d.ts.map
@@ -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,2 @@
1
+ export declare const runsCommands: import("@stricli/core").RouteMap<import("../context.js").LocalContext>;
2
+ //# sourceMappingURL=runs.d.ts.map
@@ -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
+ };