repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import { createClient, SupabaseClient } from "@supabase/supabase-js"; |
| #2 | import { v4 as uuidv4 } from "uuid"; |
| #3 | import { HistoryManager } from "./base"; |
| #4 | |
| #5 | interface HistoryEntry { |
| #6 | id: string; |
| #7 | memory_id: string; |
| #8 | previous_value: string | null; |
| #9 | new_value: string | null; |
| #10 | action: string; |
| #11 | created_at: string; |
| #12 | updated_at: string | null; |
| #13 | is_deleted: number; |
| #14 | } |
| #15 | |
| #16 | interface SupabaseHistoryConfig { |
| #17 | supabaseUrl: string; |
| #18 | supabaseKey: string; |
| #19 | tableName?: string; |
| #20 | } |
| #21 | |
| #22 | export class SupabaseHistoryManager implements HistoryManager { |
| #23 | private supabase: SupabaseClient; |
| #24 | private readonly tableName: string; |
| #25 | |
| #26 | constructor(config: SupabaseHistoryConfig) { |
| #27 | this.tableName = config.tableName || "memory_history"; |
| #28 | this.supabase = createClient(config.supabaseUrl, config.supabaseKey); |
| #29 | this.initializeSupabase().catch(console.error); |
| #30 | } |
| #31 | |
| #32 | private async initializeSupabase(): Promise<void> { |
| #33 | // Check if table exists |
| #34 | const { error } = await this.supabase |
| #35 | .from(this.tableName) |
| #36 | .select("id") |
| #37 | .limit(1); |
| #38 | |
| #39 | if (error) { |
| #40 | console.error( |
| #41 | "Error: Table does not exist. Please run this SQL in your Supabase SQL Editor:", |
| #42 | ); |
| #43 | console.error(` |
| #44 | create table ${this.tableName} ( |
| #45 | id text primary key, |
| #46 | memory_id text not null, |
| #47 | previous_value text, |
| #48 | new_value text, |
| #49 | action text not null, |
| #50 | created_at timestamp with time zone default timezone('utc', now()), |
| #51 | updated_at timestamp with time zone, |
| #52 | is_deleted integer default 0 |
| #53 | ); |
| #54 | `); |
| #55 | throw error; |
| #56 | } |
| #57 | } |
| #58 | |
| #59 | async addHistory( |
| #60 | memoryId: string, |
| #61 | previousValue: string | null, |
| #62 | newValue: string | null, |
| #63 | action: string, |
| #64 | createdAt?: string, |
| #65 | updatedAt?: string, |
| #66 | isDeleted: number = 0, |
| #67 | ): Promise<void> { |
| #68 | const historyEntry: HistoryEntry = { |
| #69 | id: uuidv4(), |
| #70 | memory_id: memoryId, |
| #71 | previous_value: previousValue, |
| #72 | new_value: newValue, |
| #73 | action: action, |
| #74 | created_at: createdAt || new Date().toISOString(), |
| #75 | updated_at: updatedAt || null, |
| #76 | is_deleted: isDeleted, |
| #77 | }; |
| #78 | |
| #79 | const { error } = await this.supabase |
| #80 | .from(this.tableName) |
| #81 | .insert(historyEntry); |
| #82 | |
| #83 | if (error) { |
| #84 | console.error("Error adding history to Supabase:", error); |
| #85 | throw error; |
| #86 | } |
| #87 | } |
| #88 | |
| #89 | async getHistory(memoryId: string): Promise<any[]> { |
| #90 | const { data, error } = await this.supabase |
| #91 | .from(this.tableName) |
| #92 | .select("*") |
| #93 | .eq("memory_id", memoryId) |
| #94 | .order("created_at", { ascending: false }) |
| #95 | .limit(100); |
| #96 | |
| #97 | if (error) { |
| #98 | console.error("Error getting history from Supabase:", error); |
| #99 | throw error; |
| #100 | } |
| #101 | |
| #102 | return data || []; |
| #103 | } |
| #104 | |
| #105 | async reset(): Promise<void> { |
| #106 | const { error } = await this.supabase |
| #107 | .from(this.tableName) |
| #108 | .delete() |
| #109 | .neq("id", ""); |
| #110 | |
| #111 | if (error) { |
| #112 | console.error("Error resetting Supabase history:", error); |
| #113 | throw error; |
| #114 | } |
| #115 | } |
| #116 | |
| #117 | close(): void { |
| #118 | // No need to close anything as connections are handled by the client |
| #119 | return; |
| #120 | } |
| #121 | } |
| #122 |