Skip to content

Commit

Permalink
chore: pass StorageClient to SupabaseWorkspace constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrzn committed Jan 23, 2024
1 parent 07b414e commit c7ec0f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/browser/lib/hooks/useEvoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const useEvoService = (
const workspace = (() => {
if (session?.supabaseAccessToken) {
const supabase = createSupabaseBrowserClient(session.supabaseAccessToken)
return new SupabaseWorkspace(chatId, supabase)
return new SupabaseWorkspace(chatId, supabase.storage)
} else {
return new InMemoryWorkspace()
}
Expand Down
24 changes: 12 additions & 12 deletions apps/browser/lib/supabase/SupabaseWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { DirectoryEntry, Workspace } from "@evo-ninja/agent-utils";
import { SupabaseClient } from "@supabase/supabase-js";
import { StorageClient } from "@supabase/storage-js";
import * as path from "path-browserify";

const BUCKET_NAME = "workspaces";

export class SupabaseWorkspace implements Workspace {
constructor(
public readonly chatId: string,
public readonly supabase: SupabaseClient
public readonly supabaseStorage: StorageClient
) {}

async writeFile(subpath: string, data: string): Promise<void> {
const path = this.toWorkspacePath(subpath);

const { error } = await this.supabase.storage
const { error } = await this.supabaseStorage
.from(BUCKET_NAME)
.upload(path, data, { upsert: true });

Expand All @@ -27,7 +27,7 @@ export class SupabaseWorkspace implements Workspace {
async readFile(subpath: string): Promise<string> {
const path = this.toWorkspacePath(subpath);

const { data, error } = await this.supabase.storage
const { data, error } = await this.supabaseStorage
.from(BUCKET_NAME)
.download(path);

Expand All @@ -45,7 +45,7 @@ export class SupabaseWorkspace implements Workspace {
async exists(subpath: string): Promise<boolean> {
const path = this.toWorkspacePath(subpath);

const { data, error } = await this.supabase.storage
const { data, error } = await this.supabaseStorage
.from(BUCKET_NAME)
.download(path);

Expand All @@ -60,7 +60,7 @@ export class SupabaseWorkspace implements Workspace {
const absOldPath = this.toWorkspacePath(oldPath);
const absNewPath = this.toWorkspacePath(newPath);

const { error } = await this.supabase.storage
const { error } = await this.supabaseStorage
.from(BUCKET_NAME)
.move(absOldPath, absNewPath);

Expand All @@ -78,7 +78,7 @@ export class SupabaseWorkspace implements Workspace {

const path = this.toWorkspacePath(subpath);

const { data: list, error: listError } = await this.supabase.storage
const { data: list, error: listError } = await this.supabaseStorage
.from(BUCKET_NAME)
.list(path);

Expand All @@ -91,7 +91,7 @@ export class SupabaseWorkspace implements Workspace {
return;
}

const { error: removeError } = await this.supabase.storage
const { error: removeError } = await this.supabaseStorage
.from(BUCKET_NAME)
.remove(filesToRemove);

Expand All @@ -103,7 +103,7 @@ export class SupabaseWorkspace implements Workspace {
async readdir(subpath: string): Promise<DirectoryEntry[]> {
const path = this.toWorkspacePath(subpath);

const { data, error } = await this.supabase.storage
const { data, error } = await this.supabaseStorage
.from(BUCKET_NAME)
.list(path);

Expand All @@ -126,7 +126,7 @@ export class SupabaseWorkspace implements Workspace {
async appendFile(subpath: string, data: string): Promise<void> {
const path = this.toWorkspacePath(subpath);

const { data: existingData, error: readError } = await this.supabase.storage
const { data: existingData, error: readError } = await this.supabaseStorage
.from(BUCKET_NAME)
.download(path);

Expand All @@ -136,7 +136,7 @@ export class SupabaseWorkspace implements Workspace {

const newData = existingData ? existingData.text() + data : data;

const { error: writeError } = await this.supabase.storage
const { error: writeError } = await this.supabaseStorage
.from(BUCKET_NAME)
.upload(path, newData, { upsert: true });

Expand All @@ -148,7 +148,7 @@ export class SupabaseWorkspace implements Workspace {
async rm(subpath: string): Promise<void> {
const path = this.toWorkspacePath(subpath);

const { error } = await this.supabase.storage
const { error } = await this.supabaseStorage
.from(BUCKET_NAME)
.remove([path]);

Expand Down

0 comments on commit c7ec0f8

Please sign in to comment.