Skip to content

Commit 93eba54

Browse files
authored
chore: Specify API host for runtime, deriving other addresses as needed (#1818)
chore: Specify API host for runtime, deriving other addresses as needed, and check in shell that runtime is live. Currently, when the runtime connects to an incorrect/invalid server (e.g. forgetting to run local server), the web socket connection retries until success, leaving the runtime initialization hanging. A general "API host" URL is needed for the runtime in order to ping the status, which would circumvent this socket loop scenario and alert that the server is invalid. With an API host URL, other runtime values can be derived, removing redundant params. With static asset cache no longer explicit, and all but runtime usage of StaticCache being in a Deno environment, the StaticCache functionality now explicitly uses HTTP or the filesystem (StaticCacheHTTP and StaticCacheFS).
1 parent 9ead191 commit 93eba54

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+226
-173
lines changed

packages/background-charm-service/cast-admin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ async function castRecipe() {
5555

5656
// Create runtime with proper configuration
5757
const runtime = new Runtime({
58+
apiUrl: new URL(toolshedUrl),
5859
storageManager: StorageManager.open({
5960
as: identity,
6061
address: new URL("/api/storage/memory", toolshedUrl),
6162
}),
62-
blobbyServerUrl: toolshedUrl,
6363
});
6464

6565
try {

packages/background-charm-service/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const workerTimeoutMs = (() => {
2626

2727
const identity = await getIdentity(env.IDENTITY, env.OPERATOR_PASS);
2828
const runtime = new Runtime({
29+
apiUrl: new URL(env.API_URL),
2930
storageManager: StorageManager.open({
3031
as: identity,
3132
address: new URL("/api/storage/memory", env.API_URL),
3233
}),
33-
blobbyServerUrl: env.API_URL,
3434
});
3535
const service = new BackgroundCharmService({
3636
identity,

packages/background-charm-service/src/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ async function initialize(
101101

102102
// Initialize runtime and charm manager
103103
runtime = new Runtime({
104+
apiUrl: new URL(toolshedUrl),
104105
storageManager: StorageManager.open({
105106
as: identity,
106107
address: new URL("/api/storage/memory", toolshedUrl),
107108
}),
108-
blobbyServerUrl: toolshedUrl,
109109
recipeEnvironment: { apiUrl },
110110
consoleHandler: consoleHandler,
111111
errorHandlers: [errorHandler],

packages/charm/src/ops/charms-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ export class CharmsController<T = unknown> {
120120
};
121121

122122
const runtime = new Runtime({
123+
apiUrl: new URL(apiUrl),
123124
storageManager: StorageManager.open({
124125
as: session.as,
125126
address: new URL("/api/storage/memory", apiUrl),
126127
}),
127-
blobbyServerUrl: apiUrl.toString(),
128128
});
129129

130130
const manager = new CharmManager(session, runtime);

packages/charm/test/iterate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("scrub function", () => {
2121
// Create runtime with the shared storage provider
2222
// We need to bypass the URL-based configuration for this test
2323
runtime = new Runtime({
24-
blobbyServerUrl: import.meta.url,
24+
apiUrl: new URL(import.meta.url),
2525
storageManager,
2626
});
2727
});

packages/cli/commands/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Command } from "@cliffy/command";
22
import { Engine } from "@commontools/runner";
33
import { join } from "@std/path/join";
44
import { getCompilerOptions } from "@commontools/js-runtime/typescript";
5-
import { StaticCache } from "@commontools/static";
5+
import { StaticCacheFS } from "@commontools/static";
66
import { dirname } from "@std/path/dirname";
77

88
export const init = new Command()
@@ -79,7 +79,7 @@ function createTsConfig() {
7979
//
8080
// Also copies recipe documentation from docs/common to .ct-docs for reference.
8181
async function initWorkspace(cwd: string) {
82-
const cache = new StaticCache();
82+
const cache = new StaticCacheFS();
8383
const runtimeModuleTypes = await Engine.getRuntimeModuleTypes(
8484
cache,
8585
);

packages/cli/lib/charm.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ export async function loadManager(config: SpaceConfig): Promise<CharmManager> {
7676
// Use a const ref object so we can assign later while keeping const binding
7777
const charmManagerRef: { current?: CharmManager } = {};
7878
const runtime = new Runtime({
79+
apiUrl: new URL(config.apiUrl),
7980
storageManager: StorageManager.open({
8081
as: session.as,
8182
address: new URL("/api/storage/memory", config.apiUrl),
8283
}),
83-
blobbyServerUrl: config.apiUrl,
8484
navigateCallback: (target) => {
8585
try {
8686
const id = charmId(target);
@@ -110,6 +110,11 @@ export async function loadManager(config: SpaceConfig): Promise<CharmManager> {
110110
}
111111
},
112112
});
113+
114+
if (!(await runtime.healthCheck())) {
115+
throw new Error(`Could not connect to "${config.apiUrl.toString()}".`);
116+
}
117+
113118
const charmManager = new CharmManager(session, runtime);
114119
charmManagerRef.current = charmManager;
115120
await charmManager.synced();

packages/cli/lib/dev.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ async function createRuntime() {
1111
const storageManager = StorageManager.emulate({
1212
as: await Identity.fromPassphrase("builder"),
1313
});
14-
return new Runtime({ storageManager, blobbyServerUrl: import.meta.url });
14+
return new Runtime({
15+
storageManager,
16+
apiUrl: new URL(import.meta.url),
17+
});
1518
}
1619

1720
export interface ProcessOptions {

packages/generated-patterns/integration/pattern-harness.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function resolveModulePath(moduleRef: string | URL): string {
8282
export async function runPatternScenario(scenario: PatternIntegrationScenario) {
8383
const storageManager = StorageManager.emulate({ as: signer });
8484
const runtime = new Runtime({
85-
blobbyServerUrl: import.meta.url,
85+
apiUrl: new URL(import.meta.url),
8686
storageManager,
8787
});
8888

packages/html/test/html-recipes.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("recipes with HTML", () => {
3636
// Create runtime with the shared storage provider
3737
// We need to bypass the URL-based configuration for this test
3838
runtime = new Runtime({
39-
blobbyServerUrl: import.meta.url,
39+
apiUrl: new URL(import.meta.url),
4040
storageManager,
4141
});
4242

0 commit comments

Comments
 (0)