Skip to content

Commit

Permalink
make default client available in the REPL
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jan 22, 2024
1 parent a4fe9b7 commit 7286d39
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/prelude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,38 @@ import startAgent, {
listAgents,
} from "https://deno.land/x/fluentci@v0.10.9/src/cmd/agent.ts";
import whoami from "https://deno.land/x/fluentci@v0.10.9/src/cmd/whoami.ts";
import { Client } from "https://esm.sh/@dagger.io/dagger@0.9.7";
import GraphQLClient from "https://esm.sh/graphql-client@2.0.1";

const ls = listJobs;

let client: Client;

// Prefer DAGGER_SESSION_PORT if set
const daggerSessionPort = Deno.env.get("DAGGER_SESSION_PORT");
if (daggerSessionPort) {
const sessionToken = Deno.env.get("DAGGER_SESSION_TOKEN");
if (!sessionToken) {
throw new Error(
"DAGGER_SESSION_TOKEN must be set when using DAGGER_SESSION_PORT"
);
}

client = new Client({
ctx: {
connection: async () => {
return new GraphQLClient(
`http://127.0.0.1:${daggerSessionPort}/query`,
{
headers: {
Authorization: `Bearer ${btoa(sessionToken + ":")}`,
},
}
);
},
close: () => {},
},
});
} else {
throw new Error("DAGGER_SESSION_PORT must be set");
}

0 comments on commit 7286d39

Please sign in to comment.