Skip to content

Commit d6bab4a

Browse files
committed
Fix silly double config parsing in pyodide agent
- Remove redundant tempConfig creation - Parse CLI args once with parseBaseRuntimeArgs - Extract syncUrl and authToken directly from parsed config - Pass adapter explicitly to PyodideRuntimeAgent - Add proper error handling for missing auth token This eliminates the silly pattern of parsing Deno.args twice.
1 parent 9ad2a50 commit d6bab4a

File tree

1 file changed

+15
-8
lines changed
  • packages/pyodide-runtime-agent/src

1 file changed

+15
-8
lines changed

packages/pyodide-runtime-agent/src/mod.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { PyodideRuntimeAgent } from "./pyodide-agent.ts";
1010
export { PyodideRuntimeAgent } from "./pyodide-agent.ts";
1111
import { logger, LogLevel } from "@runt/lib";
1212
import { discoverUserIdentity } from "./auth.ts";
13-
import { createPyodideRuntimeConfig } from "./pyodide-config.ts";
13+
import { parseBaseRuntimeArgs } from "./config-cli.ts";
1414
import { makeAdapter } from "npm:@livestore/adapter-node";
1515
import { makeCfSync } from "npm:@livestore/sync-cf";
1616

@@ -51,15 +51,22 @@ if (import.meta.main) {
5151

5252
logger.info("Authenticating...");
5353

54-
// Create temporary config to get auth details
55-
const tempConfig = createPyodideRuntimeConfig(Deno.args, {
56-
clientId: "temp", // Will be replaced
57-
});
54+
// Parse CLI args once to get auth details
55+
const cliConfig = parseBaseRuntimeArgs(Deno.args);
56+
const syncUrl = cliConfig.syncUrl ||
57+
"wss://anode-docworker.rgbkrk.workers.dev";
58+
const authToken = cliConfig.authToken;
59+
60+
if (!authToken) {
61+
console.error("❌ Configuration Error: Missing auth token");
62+
console.error("Use --auth-token or set RUNT_API_KEY environment variable");
63+
Deno.exit(1);
64+
}
5865

5966
// Discover user identity first
6067
const clientId = await discoverUserIdentity({
61-
authToken: tempConfig.authToken,
62-
syncUrl: tempConfig.syncUrl,
68+
authToken,
69+
syncUrl,
6370
});
6471

6572
logger.info("Authenticated successfully", { clientId });
@@ -68,7 +75,7 @@ if (import.meta.main) {
6875
const adapter = makeAdapter({
6976
storage: { type: "in-memory" },
7077
sync: {
71-
backend: makeCfSync({ url: tempConfig.syncUrl }),
78+
backend: makeCfSync({ url: syncUrl }),
7279
onSyncError: "ignore",
7380
},
7481
});

0 commit comments

Comments
 (0)