Skip to content

Commit

Permalink
Merge pull request #6 from sshivaditya2019/development
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 authored Oct 22, 2024
2 parents ad22930 + d9cd798 commit e45db81
Show file tree
Hide file tree
Showing 14 changed files with 277 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .github/knip.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { KnipConfig } from "knip";

const config: KnipConfig = {
entry: ["build/index.ts"],
entry: ["build/index.ts", "src/main.ts"],
project: ["src/**/*.ts"],
ignore: ["src/types/config.ts", "**/__mocks__/**", "**/__fixtures__/**"],
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", "tsx"],
ignoreDependencies: ["eslint-config-prettier", "eslint-plugin-prettier"],
eslint: true,
};

Expand Down
52 changes: 52 additions & 0 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "@ubiquity-os-marketplace/command-ask"

on:
workflow_dispatch:
inputs:
stateId:
description: "State Id"
eventName:
description: "Event Name"
eventPayload:
description: "Event Payload"
settings:
description: "Settings"
authToken:
description: "Auth Token"
ref:
description: "Ref"
signature:
description: "Signature sent from the Kernel"

jobs:
compute:
name: "LLM Reply"
runs-on: ubuntu-latest
permissions: write-all
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
UBIQUITY_OS_APP_NAME: ${{ secrets.UBIQUITY_OS_APP_NAME }}

steps:
- uses: actions/checkout@v4

- name: setup node
uses: actions/setup-node@v4
with:
node-version: "20.10.0"

- name: install dependencies
run: yarn

- name: execute directive
run: yarn tsx ./src/main.ts
id: command-ask
env:
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
UBIQUITY_OS_APP_NAME: ${{ secrets.UBIQUITY_OS_APP_NAME }}
21 changes: 21 additions & 0 deletions .github/workflows/update-configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Update Manifest and Commit Changes

on:
workflow_dispatch:
push:

jobs:
update-manifest:
name: "Update Manifest and Commit Changes"
runs-on: ubuntu-latest
steps:
- name: Update Manifest and Commit Changes
uses: ubiquity-os/action-deploy-plugin@main
with:
manifestPath: ${{ github.workspace }}/manifest.json
schemaPath: ${{ github.workspace }}/src/types/plugin-input.ts
pluginEntry: ${{ github.workspace }}/src/plugin.ts
commitMessage: "chore: updated manifest.json and dist build"
nodeVersion: "20.10.0"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"voyageai": "^0.0.1-5"
},
"devDependencies": {
"@actions/core": "^1.11.1",
"@actions/github": "^6.0.0",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@cspell/dict-node": "5.0.1",
Expand Down Expand Up @@ -66,7 +68,7 @@
"tsx": "4.15.6",
"typescript": "5.4.5",
"typescript-eslint": "7.13.1",
"wrangler": "3.60.3"
"wrangler": "^3.81.0"
},
"lint-staged": {
"*.ts": [
Expand Down
4 changes: 3 additions & 1 deletion src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export class Comment extends SuperSupabase {
}
return data;
}

async findSimilarComments(query: string, threshold: number, currentId: string): Promise<CommentSimilaritySearchResult[] | null> {
const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: query, prompt: "This is a query for the stored documents:" });
//Escape the any special characters in the query for use in the SQL query
query = query.replace(/'/g, "''").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "\\%").replace(/_/g, "\\_");
this.context.logger.info(`Query: ${query}`);
const { data, error } = await this.supabase.rpc("find_similar_comments", {
current_id: currentId,
query_text: query,
Expand Down
1 change: 1 addition & 0 deletions src/adapters/supabase/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Issue extends SuperSupabase {
}
async findSimilarIssues(plaintext: string, threshold: number, currentId: string): Promise<IssueSimilaritySearchResult[] | null> {
const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: plaintext, prompt: "This is a query for the stored documents:" });
plaintext = plaintext.replace(/'/g, "''").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "\\%").replace(/_/g, "\\_");
const { data, error } = await this.supabase.rpc("find_similar_issue_ftse", {
current_id: currentId,
query_text: plaintext,
Expand Down
1 change: 0 additions & 1 deletion src/handlers/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export function streamlineComments(comments: SimplifiedComment[]) {
if (user?.type === "Bot") continue;
const key = createKey(url);
const [owner, repo] = splitKey(key);

if (!streamlined[key]) {
streamlined[key] = [];
}
Expand Down
4 changes: 1 addition & 3 deletions src/helpers/format-chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ function createComment(comment: StreamlinedComments) {
if (!comment.comments) {
return "";
}
// Remove duplicates
const uniqueComments = comment.comments.filter((c, i, a) => a.findIndex((cc) => cc.id === c.id) === i);
// Format comments
const formattedComments = uniqueComments.map((c) => `${c.id} ${c.user}: ${c.body}\n`);
const formattedComments = comment.comments.map((c) => `${c.id} ${c.user}: ${c.body}\n`);
return formattedComments.join("");
}

Expand Down
1 change: 0 additions & 1 deletion src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export async function fetchLinkedIssues(params: FetchParams) {
for (const comment of comments) {
const foundIssues = idIssueFromComment(comment.body);
const foundCodes = comment.body ? await fetchCodeLinkedFromIssue(comment.body, params.context, comment.issueUrl) : [];

if (foundIssues) {
for (const linkedIssue of foundIssues) {
const linkedKey = createKey(linkedIssue.url, linkedIssue.issueNumber);
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ export async function fetchCodeLinkedFromIssue(
path: parsedUrl.path,
});
}

if ("content" in response.data) {
const content = Buffer.from(response.data.content, "base64").toString();
return { body: content, id: parsedUrl.path };
Expand All @@ -163,7 +162,7 @@ export async function fetchCodeLinkedFromIssue(
repo: context.payload.repository.name,
issueNumber: parseInt(issue.match(/\/issues\/(\d+)/)?.[1] || "0", 10),
issueUrl: url,
user: null,
user: context.payload.sender,
}));
}

Expand Down
39 changes: 39 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as core from "@actions/core";
import * as github from "@actions/github";
import { Value } from "@sinclair/typebox/value";
import { envSchema } from "./types/env";
import { pluginSettingsSchema, PluginInputs, pluginSettingsValidator } from "./types";
import { plugin } from "./plugin";

/**
* How a GitHub action executes the plugin.
*/
export async function run() {
const payload = github.context.payload.inputs;
const env = Value.Decode(envSchema, process.env);
const settings = Value.Decode(pluginSettingsSchema, Value.Default(pluginSettingsSchema, JSON.parse(payload.settings)));

if (!pluginSettingsValidator.test(settings)) {
throw new Error("Invalid settings provided");
}

const inputs: PluginInputs = {
stateId: payload.stateId,
eventName: payload.eventName,
eventPayload: JSON.parse(payload.eventPayload),
settings,
authToken: payload.authToken,
ref: payload.ref,
};

await plugin(inputs, env);
}

run()
.then((result) => {
core.setOutput("result", result);
})
.catch((error) => {
console.error(error);
core.setFailed(error);
});
4 changes: 2 additions & 2 deletions src/types/github-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type LinkedIssues = {
};

export type SimplifiedComment = {
user: User | null;
user: User | Partial<User>;
body: string;
id: string;
org: string;
Expand All @@ -37,7 +37,7 @@ export type SimplifiedComment = {

export type FetchedCodes = {
body: string;
user: User | null;
user: User | Partial<User>;
issueUrl: string;
id: string;
org: string;
Expand Down
1 change: 1 addition & 0 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe("Ask plugin tests", () => {
=== Linked Issue #3 Conversation === ubiquity/test-repo #3 ===
4 ubiquity: Just a comment [#1](https://www.github.com/ubiquity/test-repo/issues/1)
4 ubiquity: Just a comment [#1](https://www.github.com/ubiquity/test-repo/issues/1)
=== End Linked Issue #3 Conversation ===\n
`;
Expand Down
Loading

0 comments on commit e45db81

Please sign in to comment.