Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Nov 30, 2024
2 parents 6fa432f + ca03b56 commit b70c18a
Show file tree
Hide file tree
Showing 27 changed files with 57,904 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .github/knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: KnipConfig = {
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**", "src/types/database.ts"],
ignoreExportsUsedInFile: true,
// eslint can also be safely ignored as per the docs: https://knip.dev/guides/handling-issues#eslint--jest
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "ts-node", "hono"],
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier", "ts-node"],
eslint: true,
};

Expand Down
9 changes: 8 additions & 1 deletion .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ jobs:
runs-on: ubuntu-latest
permissions: write-all
environment: ${{ github.ref == 'refs/heads/main' && 'main' || 'development' }}
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{secrets.VOYAGEAI_API_KEY}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KERNEL_PUBLIC_KEY: ${{ secrets.KERNEL_PUBLIC_KEY }}

steps:
- uses: actions/checkout@v4
Expand All @@ -41,5 +47,6 @@ jobs:
PLUGIN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }}
VOYAGEAI_API_KEY: ${{secrets.VOYAGEAI_API_KEY}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KERNEL_PUBLIC_KEY: ${{ secrets.KERNEL_PUBLIC_KEY }}
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
steps:
- uses: ubiquity-os/action-deploy-plugin@main
with:
treatAsEsm: true
treatAsEsm: false
sourcemap: false
pluginEntry: "src/main.ts"
pluginEntry: "${{ github.workspace }}/src/main.ts"
env:
APP_ID: ${{ secrets.APP_ID }}
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
Binary file modified bun.lockb
Binary file not shown.
57,353 changes: 57,350 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions graphql.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
schema:
- https://api.github.com/graphql:
headers:
Authorization: Bearer ${GITHUB_TOKEN}
documents: src/*
projects: {}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Generate vector embeddings",
"name": "Text Vector Embeddings",
"description": "Enables the storage, updating, and deletion of issue comment embeddings.",
"ubiquity:listeners": [
"issue_comment.created",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"dotenv": "16.4.5",
"markdown-it": "^14.1.0",
"markdown-it-plain-text": "^0.3.0",
"voyageai": "^0.0.1-5"
"voyageai": "^0.0.1-5",
"hono": "^4.6.4"
},
"devDependencies": {
"@commitlint/cli": "19.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { SuperSupabase } from "./supabase/helpers/supabase";
import { Embedding as VoyageEmbedding } from "./voyage/helpers/embedding";
import { SuperVoyage } from "./voyage/helpers/voyage";
import { VoyageAIClient } from "voyageai";
import { Issues } from "./supabase/helpers/issues";
import { Issue } from "./supabase/helpers/issues";

export function createAdapters(supabaseClient: SupabaseClient, voyage: VoyageAIClient, context: Context) {
return {
supabase: {
comment: new Comment(supabaseClient, context),
issue: new Issues(supabaseClient, context),
issue: new Issue(supabaseClient, context),
super: new SuperSupabase(supabaseClient, context),
},
voyage: {
Expand Down
152 changes: 102 additions & 50 deletions src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,91 +12,143 @@ export interface CommentType {
embedding: number[];
}

interface CommentData {
markdown: string | null;
id: string;
author_id: number;
payload: Record<string, unknown> | null;
isPrivate: boolean;
issue_id: string;
}

export class Comment extends SuperSupabase {
constructor(supabase: SupabaseClient, context: Context) {
super(supabase, context);
}

async createComment(
markdown: string | null,
commentNodeId: string,
authorId: number,
payload: Record<string, unknown> | null,
isPrivate: boolean,
issueId: string
) {
async createComment(commentData: CommentData) {
const { isPrivate } = commentData;
//First Check if the comment already exists
const { data, error } = await this.supabase.from("issue_comments").select("*").eq("id", commentNodeId);
if (error) {
this.context.logger.error("Error creating comment", { err: error });
const { data: existingData, error: existingError } = await this.supabase.from("issue_comments").select("*").eq("id", commentData.id);
if (existingError) {
this.context.logger.error("Error creating comment", {
Error: existingError,
commentData,
});
return;
}
if (data && data.length > 0) {
this.context.logger.info("Comment already exists");
if (existingData && existingData.length > 0) {
this.context.logger.error("Comment already exists", {
commentData: commentData,
});
return;
} else {
//Create the embedding for this comment
const embedding = await this.context.adapters.voyage.embedding.createEmbedding(markdown);
let plaintext: string | null = markdownToPlainText(markdown);
if (isPrivate) {
markdown = null as string | null;
payload = null as Record<string, unknown> | null;
plaintext = null as string | null;
}
const { error } = await this.supabase
.from("issue_comments")
.insert([{ id: commentNodeId, markdown, plaintext, author_id: authorId, payload, embedding: embedding, issue_id: issueId }]);
if (error) {
this.context.logger.error("Error creating comment", { err: error });
return;
}
}
this.context.logger.info("Comment created successfully");
//Create the embedding for this comment
const embedding = await this.context.adapters.voyage.embedding.createEmbedding(commentData.markdown);
let plaintext: string | null = markdownToPlainText(commentData.markdown);
let finalMarkdown = commentData.markdown;
let finalPayload = commentData.payload;

if (isPrivate) {
finalMarkdown = null;
finalPayload = null;
plaintext = null;
}
const { data, error } = await this.supabase.from("issue_comments").insert([
{
id: commentData.id,
markdown: finalMarkdown,
author_id: commentData.author_id,
embedding,
payload: finalPayload,
issue_id: commentData.issue_id,
plaintext,
},
]);
if (error) {
this.context.logger.error("Failed to create comment in database", {
Error: error,
commentData,
});
return;
}
this.context.logger.info(`Comment created successfully with id: ${commentData.id}`, { data });
}

async updateComment(
markdown: string | null,
commentNodeId: string,
authorId: number,
payload: Record<string, unknown> | null,
isPrivate: boolean,
issueId: string
) {
async updateComment(commentData: CommentData) {
const { isPrivate } = commentData;
//Create the embedding for this comment
const embedding = Array.from(await this.context.adapters.voyage.embedding.createEmbedding(markdown));
let plaintext: string | null = markdownToPlainText(markdown);
const embedding = Array.from(await this.context.adapters.voyage.embedding.createEmbedding(commentData.markdown));
let plaintext: string | null = markdownToPlainText(commentData.markdown);
let finalMarkdown = commentData.markdown;
let finalPayload = commentData.payload;

if (isPrivate) {
markdown = null as string | null;
payload = null as Record<string, unknown> | null;
plaintext = null as string | null;
finalMarkdown = null;
finalPayload = null;
plaintext = null;
}
const comments = await this.getComment(commentNodeId);
const comments = await this.getComment(commentData.id);
if (comments && comments.length == 0) {
this.context.logger.info("Comment does not exist, creating a new one");
await this.createComment(markdown, commentNodeId, authorId, payload, isPrivate, issueId);
await this.createComment({ ...commentData, markdown: finalMarkdown, payload: finalPayload, isPrivate });
} else {
const { error } = await this.supabase
.from("issue_comments")
.update({ markdown, plaintext, embedding: embedding, payload, modified_at: new Date() })
.eq("id", commentNodeId);
.update({ markdown: finalMarkdown, plaintext, embedding: embedding, payload: finalPayload, modified_at: new Date() })
.eq("id", commentData.id);
if (error) {
this.context.logger.error("Error updating comment", { err: error });
this.context.logger.error("Error updating comment", {
Error: error,
commentData: {
commentData,
markdown: finalMarkdown,
plaintext,
embedding,
payload: finalPayload,
modified_at: new Date(),
},
});
return;
}
this.context.logger.info("Comment updated successfully with id: " + commentData.id, {
commentData: {
commentData,
markdown: finalMarkdown,
plaintext,
embedding,
payload: finalPayload,
modified_at: new Date(),
},
});
}
}

async getComment(commentNodeId: string): Promise<CommentType[] | null> {
const { data, error } = await this.supabase.from("issue_comments").select("*").eq("id", commentNodeId);
if (error) {
this.context.logger.error("Error getting comment", { err: error });
this.context.logger.error("Error getting comment", {
Error: error,
commentData: {
id: commentNodeId,
},
});
return null;
}
return data;
}

async deleteComment(commentNodeId: string) {
const { error } = await this.supabase.from("issue_comments").delete().eq("id", commentNodeId);
if (error) {
this.context.logger.error("Error deleting comment", { err: error });
this.context.logger.error("Error deleting comment", {
Error: error,
commentData: {
id: commentNodeId,
},
});
return;
}
this.context.logger.info("Comment deleted successfully with id: " + commentNodeId);
}
}
Loading

0 comments on commit b70c18a

Please sign in to comment.