Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: returnDataToKernel #44

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
81d4859
fix: logger errors
sshivaditya Nov 9, 2024
1019900
fix: error handling
sshivaditya Nov 9, 2024
8d4d414
fix: error handling supabase
sshivaditya Nov 9, 2024
c531db0
fix: error handling supabase
sshivaditya Nov 9, 2024
465c9ba
fix: error handling supabase
sshivaditya Nov 9, 2024
0a89090
fix: error handling supabase
sshivaditya Nov 9, 2024
ce65ef2
fix: error handling and return data to kernel
sshivaditya Nov 9, 2024
3f4e89b
fix: update issue fix
sshivaditya Nov 9, 2024
2148051
fix: update issue fix
sshivaditya Nov 9, 2024
516d799
fix: issue dedup
sshivaditya Nov 9, 2024
d33e1f9
fix: issue dedup
sshivaditya Nov 9, 2024
c771ea2
fix: updated the match filter for the issues
sshivaditya Nov 9, 2024
3752ce8
fix: tests
sshivaditya Nov 9, 2024
a435509
fix: error handling
sshivaditya Nov 20, 2024
e79710f
fix: error handling better logging
sshivaditya Nov 24, 2024
ef2add5
fix: error handling
sshivaditya Nov 25, 2024
43edc46
fix: tests
sshivaditya Nov 25, 2024
75acb26
fix: erro handling
sshivaditya Nov 26, 2024
3cc8931
fix: add parens to strings
sshivaditya Nov 26, 2024
1f602c6
fix: compute.yml with PLUGIN_GITHUB_TOKEN
sshivaditya Nov 26, 2024
5e50d8a
fix: bypassSignatureVerification config
sshivaditya Nov 26, 2024
48ba7bc
fix: remove bypass signature verif
sshivaditya Nov 26, 2024
011933e
fix: update compute.yml with kernel public key
sshivaditya Nov 26, 2024
23fa19d
fix: context adapters init
sshivaditya Nov 26, 2024
d21531e
feat: switch to bun and fix deploy
whilefoo Nov 25, 2024
bc0feb5
fix: ncc build
whilefoo Nov 26, 2024
8ac24e7
fix: error handling supabase
sshivaditya Nov 9, 2024
f911a1e
fix: error handling
sshivaditya Nov 25, 2024
8a0d643
fix: compute.yml with PLUGIN_GITHUB_TOKEN
sshivaditya Nov 26, 2024
af9207d
fix: update compute.yml with kernel public key
sshivaditya Nov 26, 2024
9161919
fix: supabase
sshivaditya Nov 26, 2024
12b60d4
fix: worker launch
sshivaditya Nov 26, 2024
90f4f3c
chore: updated manifest.json and dist build
github-actions[bot] Nov 26, 2024
14265b8
fix: ncc compiled dist not working replace by old for testing
sshivaditya Nov 26, 2024
a7676ce
fix: find similar issues
sshivaditya Nov 26, 2024
7e2d025
fix: database types
sshivaditya Nov 26, 2024
32639dd
chore: updated manifest.json and dist build
github-actions[bot] Nov 26, 2024
fdd9b79
fix: similar issue search
sshivaditya Nov 26, 2024
7eeef8d
chore: updated manifest.json and dist build
github-actions[bot] Nov 26, 2024
88aa042
fix: update the compute plugin to use ncc
sshivaditya Nov 26, 2024
d0196c7
fix: add-issue error
sshivaditya Nov 26, 2024
c35db7b
chore: updated manifest.json and dist build
test-app-ubo[bot] Nov 26, 2024
5f9c29f
Update index.js
sshivaditya2019 Nov 26, 2024
53279bd
chore: updated manifest.json and dist build
test-app-ubo[bot] Nov 26, 2024
6a621b1
Update index.js
sshivaditya2019 Nov 26, 2024
3b2b147
Update index.js
sshivaditya2019 Nov 27, 2024
97a90a7
fix: change the flags in deploy.yml
sshivaditya Nov 27, 2024
6218d52
fix: removed sourcemap
sshivaditya Nov 27, 2024
cd4a015
chore: updated manifest.json and dist build
test-app-ubo[bot] Nov 27, 2024
4889bdf
fix: knip
sshivaditya Nov 27, 2024
e532c3c
fix: prettier
sshivaditya Nov 27, 2024
f0df22b
fix: removed node and port to 4004
sshivaditya Nov 28, 2024
a5dca27
fix: add /* GraphQL */
sshivaditya Nov 28, 2024
e2abc2d
chore: updated manifest.json and dist build
test-app-ubo[bot] Nov 28, 2024
e582b1f
feat: adds graphql.config.yml
sshivaditya Nov 28, 2024
0087217
fix: prettier
sshivaditya Nov 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
6 changes: 3 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: {}
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");
sshivaditya2019 marked this conversation as resolved.
Show resolved Hide resolved
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