@project-ajax/sdk 0.0.31 → 0.0.33

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.
@@ -13,18 +13,30 @@ export interface ToolConfiguration<I extends JSONValue, O extends JSONValue = JS
13
13
  */
14
14
  export declare class InvalidToolInputError extends Error {
15
15
  constructor(message: string);
16
+ toJSON(): {
17
+ name: string;
18
+ message: string;
19
+ };
16
20
  }
17
21
  /**
18
22
  * An error returned when the output from a tool doesn't match the output schema.
19
23
  */
20
24
  export declare class InvalidToolOutputError extends Error {
21
25
  constructor(message: string);
26
+ toJSON(): {
27
+ name: string;
28
+ message: string;
29
+ };
22
30
  }
23
31
  /**
24
32
  * An error returned when the tool execution fails.
25
33
  */
26
34
  export declare class ToolExecutionError extends Error {
27
35
  constructor(message: string);
36
+ toJSON(): {
37
+ name: string;
38
+ message: string;
39
+ };
28
40
  }
29
41
  /**
30
42
  * Creates a capability definition for a tool to be used by an agent.
@@ -1 +1 @@
1
- {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/capabilities/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAE/C,KAAK,SAAS,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEhC,MAAM,WAAW,iBAAiB,CACjC,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,SAAS,GAAG,SAAS;IAE/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;CAI3B;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI3B;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI3B;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,GAAG,SAAS,EACxE,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;mBAeT,SAAS,GAAG,OAAO,CACrC;QACA,IAAI,EAAE,SAAS,CAAC;QAChB,KAAK,EAAE,CAAC,CAAC;KACR,GACD;QACA,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EACF,qBAAqB,GACrB,sBAAsB,GACtB,kBAAkB,CAAC;KACrB,CACH;EA4CF"}
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/capabilities/tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAE/C,KAAK,SAAS,GACX,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,EAAE,GACX;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAEhC,MAAM,WAAW,iBAAiB,CACjC,CAAC,SAAS,SAAS,EACnB,CAAC,SAAS,SAAS,GAAG,SAAS;IAE/B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1B,YAAY,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACjC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;gBACnC,OAAO,EAAE,MAAM;IAK3B,MAAM;;;;CAMN;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;IAK3B,MAAM;;;;CAMN;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;IAK3B,MAAM;;;;CAMN;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,SAAS,EAAE,CAAC,SAAS,SAAS,GAAG,SAAS,EACxE,MAAM,EAAE,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;;;;;;;mBAeT,SAAS,GAAG,OAAO,CACrC;QACA,IAAI,EAAE,SAAS,CAAC;QAChB,KAAK,EAAE,CAAC,CAAC;KACR,GACD;QACA,IAAI,EAAE,OAAO,CAAC;QACd,KAAK,EACF,qBAAqB,GACrB,sBAAsB,GACtB,kBAAkB,CAAC;KACrB,CACH;EA0DF"}
@@ -4,18 +4,36 @@ class InvalidToolInputError extends Error {
4
4
  super(message);
5
5
  this.name = "InvalidToolInputError";
6
6
  }
7
+ toJSON() {
8
+ return {
9
+ name: this.name,
10
+ message: this.message
11
+ };
12
+ }
7
13
  }
8
14
  class InvalidToolOutputError extends Error {
9
15
  constructor(message) {
10
16
  super(message);
11
17
  this.name = "InvalidToolOutputError";
12
18
  }
19
+ toJSON() {
20
+ return {
21
+ name: this.name,
22
+ message: this.message
23
+ };
24
+ }
13
25
  }
14
26
  class ToolExecutionError extends Error {
15
27
  constructor(message) {
16
28
  super(message);
17
29
  this.name = "ToolExecutionError";
18
30
  }
31
+ toJSON() {
32
+ return {
33
+ name: this.name,
34
+ message: this.message
35
+ };
36
+ }
19
37
  }
20
38
  function tool(config) {
21
39
  const ajv = new Ajv();
@@ -35,22 +53,32 @@ function tool(config) {
35
53
  "Unexpected: No validation errors after failed validation"
36
54
  );
37
55
  }
38
- return {
56
+ const result = {
39
57
  _tag: "error",
40
58
  error: new InvalidToolInputError(
41
59
  JSON.stringify(validateInput.errors, null, 2)
42
60
  )
43
61
  };
62
+ process.stdout.write(`
63
+ <output>${JSON.stringify(result)}</output>
64
+ `);
65
+ return result;
44
66
  }
45
67
  try {
46
68
  const result = await config.execute(input);
47
69
  if (validateOutput && !validateOutput(result)) {
48
- return {
70
+ const result2 = {
49
71
  _tag: "error",
50
72
  error: new InvalidToolOutputError(
51
73
  JSON.stringify(validateOutput.errors, null, 2)
52
74
  )
53
75
  };
76
+ process.stdout.write(
77
+ `
78
+ <output>${JSON.stringify(result2)}</output>
79
+ `
80
+ );
81
+ return result2;
54
82
  }
55
83
  process.stdout.write(`
56
84
  <output>${JSON.stringify(result)}</output>
@@ -60,12 +88,16 @@ function tool(config) {
60
88
  value: result
61
89
  };
62
90
  } catch (err) {
63
- return {
91
+ const result = {
64
92
  _tag: "error",
65
93
  error: new ToolExecutionError(
66
94
  err instanceof Error ? err.message : String(err)
67
95
  )
68
96
  };
97
+ process.stdout.write(`
98
+ <output>${JSON.stringify(result)}</output>
99
+ `);
100
+ return result;
69
101
  }
70
102
  }
71
103
  };
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAYG"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.ts"],"names":[],"mappings":";AAGA,wBAkBG"}
@@ -1,2 +1,6 @@
1
- export declare const deploy: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags) => Promise<void>;
1
+ interface DeployFlags {
2
+ name?: string;
3
+ }
4
+ export declare const deploy: (this: import("../context.js").LocalContext, flags: import("../flags.js").GlobalFlags & DeployFlags) => Promise<void>;
5
+ export {};
2
6
  //# sourceMappingURL=deploy.impl.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/deploy.impl.ts"],"names":[],"mappings":"AAMA,UAAU,WAAW;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM,uHAmEjB,CAAC"}
@@ -1,7 +1,8 @@
1
+ import prompts from "prompts";
1
2
  import { Result } from "../api/result.js";
2
3
  import { deployWorker } from "../deploy.js";
3
4
  import { buildAuthedHandler } from "../handler.js";
4
- const deploy = buildAuthedHandler(async function() {
5
+ const deploy = buildAuthedHandler(async function(flags) {
5
6
  const { token } = this.config.tokenInfo;
6
7
  const workerId = this.config.workerId;
7
8
  const environment = this.config.environment;
@@ -10,12 +11,46 @@ const deploy = buildAuthedHandler(async function() {
10
11
  }
11
12
  const workerPath = this.process.cwd();
12
13
  this.writer.writeErr("Deploying worker...");
13
- const result = await deployWorker(this, {
14
- workerPath,
15
- workerId,
16
- token,
17
- environment
18
- });
14
+ const name = flags.name;
15
+ if (workerId && name) {
16
+ throw new Error("Cannot specify a name when updating an existing worker");
17
+ }
18
+ let result;
19
+ if (workerId) {
20
+ result = await deployWorker(this, {
21
+ workerPath,
22
+ workerId,
23
+ token,
24
+ environment
25
+ });
26
+ } else {
27
+ let validatedName;
28
+ if (name) {
29
+ validatedName = name;
30
+ } else {
31
+ const { name: nameInput } = await prompts({
32
+ type: "text",
33
+ name: "name",
34
+ message: "Enter a name for the worker",
35
+ validate: (value) => {
36
+ if (value.length < 1) {
37
+ return "Name is required";
38
+ }
39
+ return true;
40
+ }
41
+ });
42
+ if (!nameInput?.trim()) {
43
+ throw new Error("Name is required");
44
+ }
45
+ validatedName = nameInput.trim();
46
+ }
47
+ result = await deployWorker(this, {
48
+ name: validatedName,
49
+ workerPath,
50
+ token,
51
+ environment
52
+ });
53
+ }
19
54
  if (Result.isSuccess(result)) {
20
55
  const { workerId: workerId2 } = Result.unwrap(result);
21
56
  await this.config.setWorkerId(workerId2);
@@ -6,7 +6,13 @@ var deploy_default = buildCommand({
6
6
  },
7
7
  parameters: {
8
8
  flags: {
9
- ...globalFlags
9
+ ...globalFlags,
10
+ name: {
11
+ kind: "parsed",
12
+ parse: String,
13
+ brief: "The name of the worker (if it has not yet been created)",
14
+ optional: true
15
+ }
10
16
  }
11
17
  },
12
18
  loader: () => import("./deploy.impl.js").then((m) => m.deploy)
@@ -1,7 +1,7 @@
1
1
  import type { ApiError, Environment } from "./api/client.js";
2
2
  import { Result } from "./api/result.js";
3
3
  import type { AuthedContext } from "./handler.js";
4
- export interface DeployOptions {
4
+ export interface BaseDeployOptions {
5
5
  /**
6
6
  * Path to the worker directory to deploy
7
7
  */
@@ -14,8 +14,20 @@ export interface DeployOptions {
14
14
  * Environment to deploy to
15
15
  */
16
16
  environment: Environment;
17
- workerId?: string | null;
18
17
  }
18
+ export interface CreateDeployOptions extends BaseDeployOptions {
19
+ /**
20
+ * Name of the worker (if it has not yet been created)
21
+ */
22
+ name: string;
23
+ }
24
+ export interface UpdateDeployOptions extends BaseDeployOptions {
25
+ /**
26
+ * ID of the worker to update
27
+ */
28
+ workerId: string;
29
+ }
30
+ export type DeployOptions = CreateDeployOptions | UpdateDeployOptions;
19
31
  /**
20
32
  * Deploy a worker to the specified environment
21
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,aAAa;IAC7B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;IAEzB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,CAAC,CAAC,CAiEjD"}
1
+ {"version":3,"file":"deploy.d.ts","sourceRoot":"","sources":["../../src/cli/deploy.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;CACzB;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB;IAC7D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAEtE;;GAEG;AACH,wBAAsB,YAAY,CACjC,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,CAAC,CAAC,CAkEjD"}
@@ -4,19 +4,17 @@ import * as path from "node:path";
4
4
  import * as esbuild from "esbuild";
5
5
  import { Result } from "./api/result.js";
6
6
  async function deployWorker(context, options) {
7
- const { workerPath, workerId: workerIdForUpdate } = options;
7
+ const { workerPath } = options;
8
8
  const absPath = path.resolve(process.cwd(), workerPath);
9
9
  context.writer.debug(`Deploying worker from: ${absPath}`);
10
10
  const client = context.apiClient;
11
11
  let uploadUrl;
12
12
  let uploadFields;
13
13
  let workerId;
14
- context.writer.writeErr(
15
- workerIdForUpdate ? `Updating worker...` : `Creating worker...`
16
- );
17
- if (workerIdForUpdate) {
18
- workerId = workerIdForUpdate;
19
- const updateResult = await client.updateWorkerBundle(workerIdForUpdate);
14
+ if ("workerId" in options) {
15
+ context.writer.writeErr(`Updating worker...`);
16
+ workerId = options.workerId;
17
+ const updateResult = await client.updateWorkerBundle(workerId);
20
18
  if (Result.isSuccess(updateResult)) {
21
19
  const res = Result.unwrap(updateResult);
22
20
  uploadUrl = res.url;
@@ -28,7 +26,8 @@ async function deployWorker(context, options) {
28
26
  throw new Error(updateResult.error.message);
29
27
  }
30
28
  } else {
31
- const createResult = await client.createWorker("tmp-give-me-a-good-name");
29
+ context.writer.writeErr(`Creating worker...`);
30
+ const createResult = await client.createWorker(options.name);
32
31
  if (Result.isSuccess(createResult)) {
33
32
  const res = Result.unwrap(createResult);
34
33
  uploadUrl = res.url;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@project-ajax/sdk",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "An SDK for building workers for the Project Ajax platform",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -74,6 +74,7 @@
74
74
  "@stricli/core": "^1.2.4",
75
75
  "@visulima/tabular": "^3.1.1",
76
76
  "ajv": "^8.17.1",
77
- "esbuild": "^0.25.12"
77
+ "esbuild": "^0.25.12",
78
+ "prompts": "^2.4.2"
78
79
  }
79
80
  }
@@ -26,6 +26,13 @@ export class InvalidToolInputError extends Error {
26
26
  super(message);
27
27
  this.name = "InvalidToolInputError";
28
28
  }
29
+
30
+ toJSON() {
31
+ return {
32
+ name: this.name,
33
+ message: this.message,
34
+ };
35
+ }
29
36
  }
30
37
 
31
38
  /**
@@ -36,6 +43,13 @@ export class InvalidToolOutputError extends Error {
36
43
  super(message);
37
44
  this.name = "InvalidToolOutputError";
38
45
  }
46
+
47
+ toJSON() {
48
+ return {
49
+ name: this.name,
50
+ message: this.message,
51
+ };
52
+ }
39
53
  }
40
54
 
41
55
  /**
@@ -46,6 +60,13 @@ export class ToolExecutionError extends Error {
46
60
  super(message);
47
61
  this.name = "ToolExecutionError";
48
62
  }
63
+
64
+ toJSON() {
65
+ return {
66
+ name: this.name,
67
+ message: this.message,
68
+ };
69
+ }
49
70
  }
50
71
 
51
72
  /**
@@ -109,23 +130,33 @@ export function tool<I extends JSONValue, O extends JSONValue = JSONValue>(
109
130
  );
110
131
  }
111
132
 
112
- return {
133
+ const result = {
113
134
  _tag: "error" as const,
114
135
  error: new InvalidToolInputError(
115
136
  JSON.stringify(validateInput.errors, null, 2),
116
137
  ),
117
138
  };
139
+
140
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
141
+
142
+ return result;
118
143
  }
119
144
 
120
145
  try {
121
146
  const result = await config.execute(input);
122
147
  if (validateOutput && !validateOutput(result)) {
123
- return {
148
+ const result = {
124
149
  _tag: "error" as const,
125
150
  error: new InvalidToolOutputError(
126
151
  JSON.stringify(validateOutput.errors, null, 2),
127
152
  ),
128
153
  };
154
+
155
+ process.stdout.write(
156
+ `\n<output>${JSON.stringify(result)}</output>\n`,
157
+ );
158
+
159
+ return result;
129
160
  }
130
161
 
131
162
  process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
@@ -135,12 +166,16 @@ export function tool<I extends JSONValue, O extends JSONValue = JSONValue>(
135
166
  value: result,
136
167
  };
137
168
  } catch (err) {
138
- return {
169
+ const result = {
139
170
  _tag: "error" as const,
140
171
  error: new ToolExecutionError(
141
172
  err instanceof Error ? err.message : String(err),
142
173
  ),
143
174
  };
175
+
176
+ process.stdout.write(`\n<output>${JSON.stringify(result)}</output>\n`);
177
+
178
+ return result;
144
179
  }
145
180
  },
146
181
  };
@@ -1,8 +1,14 @@
1
+ import prompts from "prompts";
2
+ import type { ApiError } from "../api/client.js";
1
3
  import { Result } from "../api/result.js";
2
4
  import { deployWorker } from "../deploy.js";
3
5
  import { buildAuthedHandler } from "../handler.js";
4
6
 
5
- export const deploy = buildAuthedHandler(async function () {
7
+ interface DeployFlags {
8
+ name?: string;
9
+ }
10
+
11
+ export const deploy = buildAuthedHandler(async function (flags: DeployFlags) {
6
12
  const { token } = this.config.tokenInfo;
7
13
  const workerId = this.config.workerId;
8
14
 
@@ -15,12 +21,50 @@ export const deploy = buildAuthedHandler(async function () {
15
21
 
16
22
  this.writer.writeErr("Deploying worker...");
17
23
 
18
- const result = await deployWorker(this, {
19
- workerPath,
20
- workerId,
21
- token,
22
- environment,
23
- });
24
+ const name = flags.name;
25
+ if (workerId && name) {
26
+ throw new Error("Cannot specify a name when updating an existing worker");
27
+ }
28
+
29
+ let result: Result<{ workerId: string }, ApiError>;
30
+ if (workerId) {
31
+ result = await deployWorker(this, {
32
+ workerPath,
33
+ workerId,
34
+ token,
35
+ environment,
36
+ });
37
+ } else {
38
+ let validatedName: string;
39
+ if (name) {
40
+ validatedName = name;
41
+ } else {
42
+ const { name: nameInput } = await prompts({
43
+ type: "text",
44
+ name: "name",
45
+ message: "Enter a name for the worker",
46
+ validate: (value) => {
47
+ if (value.length < 1) {
48
+ return "Name is required";
49
+ }
50
+ return true;
51
+ },
52
+ });
53
+
54
+ if (!nameInput?.trim()) {
55
+ throw new Error("Name is required");
56
+ }
57
+
58
+ validatedName = nameInput.trim();
59
+ }
60
+
61
+ result = await deployWorker(this, {
62
+ name: validatedName,
63
+ workerPath,
64
+ token,
65
+ environment,
66
+ });
67
+ }
24
68
 
25
69
  if (Result.isSuccess(result)) {
26
70
  const { workerId } = Result.unwrap(result);
@@ -9,6 +9,12 @@ export default buildCommand({
9
9
  parameters: {
10
10
  flags: {
11
11
  ...globalFlags,
12
+ name: {
13
+ kind: "parsed",
14
+ parse: String,
15
+ brief: "The name of the worker (if it has not yet been created)",
16
+ optional: true,
17
+ },
12
18
  },
13
19
  },
14
20
 
package/src/cli/deploy.ts CHANGED
@@ -9,7 +9,7 @@ import { Result } from "./api/result.js";
9
9
  import type { LocalContext } from "./context.js";
10
10
  import type { AuthedContext } from "./handler.js";
11
11
 
12
- export interface DeployOptions {
12
+ export interface BaseDeployOptions {
13
13
  /**
14
14
  * Path to the worker directory to deploy
15
15
  */
@@ -24,10 +24,24 @@ export interface DeployOptions {
24
24
  * Environment to deploy to
25
25
  */
26
26
  environment: Environment;
27
+ }
27
28
 
28
- workerId?: string | null;
29
+ export interface CreateDeployOptions extends BaseDeployOptions {
30
+ /**
31
+ * Name of the worker (if it has not yet been created)
32
+ */
33
+ name: string;
29
34
  }
30
35
 
36
+ export interface UpdateDeployOptions extends BaseDeployOptions {
37
+ /**
38
+ * ID of the worker to update
39
+ */
40
+ workerId: string;
41
+ }
42
+
43
+ export type DeployOptions = CreateDeployOptions | UpdateDeployOptions;
44
+
31
45
  /**
32
46
  * Deploy a worker to the specified environment
33
47
  */
@@ -35,7 +49,7 @@ export async function deployWorker(
35
49
  context: AuthedContext,
36
50
  options: DeployOptions,
37
51
  ): Promise<Result<{ workerId: string }, ApiError>> {
38
- const { workerPath, workerId: workerIdForUpdate } = options;
52
+ const { workerPath } = options;
39
53
 
40
54
  // Resolve absolute path
41
55
  const absPath = path.resolve(process.cwd(), workerPath);
@@ -48,13 +62,12 @@ export async function deployWorker(
48
62
  let uploadFields: Record<string, string>;
49
63
  let workerId: string;
50
64
 
51
- context.writer.writeErr(
52
- workerIdForUpdate ? `Updating worker...` : `Creating worker...`,
53
- );
65
+ if ("workerId" in options) {
66
+ context.writer.writeErr(`Updating worker...`);
54
67
 
55
- if (workerIdForUpdate) {
56
- workerId = workerIdForUpdate;
57
- const updateResult = await client.updateWorkerBundle(workerIdForUpdate);
68
+ workerId = options.workerId;
69
+
70
+ const updateResult = await client.updateWorkerBundle(workerId);
58
71
  if (Result.isSuccess(updateResult)) {
59
72
  const res = Result.unwrap(updateResult);
60
73
  uploadUrl = res.url;
@@ -66,7 +79,9 @@ export async function deployWorker(
66
79
  throw new Error(updateResult.error.message);
67
80
  }
68
81
  } else {
69
- const createResult = await client.createWorker("tmp-give-me-a-good-name");
82
+ context.writer.writeErr(`Creating worker...`);
83
+
84
+ const createResult = await client.createWorker(options.name);
70
85
  if (Result.isSuccess(createResult)) {
71
86
  const res = Result.unwrap(createResult);
72
87
  uploadUrl = res.url;