| 103 | } |
| 104 | |
| 105 | async registerEndpoint(options: { url: string; name: string }): Promise<EndpointRecord> { |
| 106 | const apiKey = await this.#apiKey(); |
| 107 | |
| 108 | this.#logger.debug("Registering endpoint", { |
| 109 | url: options.url, |
| 110 | name: options.name, |
| 111 | }); |
| 112 | |
| 113 | const response = await fetch(`${this.#apiUrl}/api/v1/endpoints`, { |
| 114 | method: "POST", |
| 115 | headers: { |
| 116 | "Content-Type": "application/json", |
| 117 | Authorization: `Bearer ${apiKey}`, |
| 118 | }, |
| 119 | body: JSON.stringify({ |
| 120 | url: options.url, |
| 121 | name: options.name, |
| 122 | }), |
| 123 | }); |
| 124 | |
| 125 | if (response.status >= 400 && response.status < 500) { |
| 126 | const body = await response.json(); |
| 127 | |
| 128 | throw new Error(body.error); |
| 129 | } |
| 130 | |
| 131 | if (response.status !== 200) { |
| 132 | throw new Error(`Failed to register entry point, got status code ${response.status}`); |
| 133 | } |
| 134 | |
| 135 | return await response.json(); |
| 136 | } |
| 137 | |
| 138 | async runTask( |
| 139 | runId: string, |