@tyvm/knowhow 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/package.json +1 -1
  2. package/src/plugins/PluginBase.ts +48 -0
  3. package/src/plugins/asana.ts +12 -2
  4. package/src/plugins/downloader/plugin.ts +12 -2
  5. package/src/plugins/embedding.ts +12 -2
  6. package/src/plugins/figma.ts +18 -2
  7. package/src/plugins/github.ts +34 -5
  8. package/src/plugins/jira.ts +11 -2
  9. package/src/plugins/language.ts +11 -2
  10. package/src/plugins/linear.ts +11 -2
  11. package/src/plugins/notion.ts +11 -2
  12. package/src/plugins/plugins.ts +90 -24
  13. package/src/plugins/types.ts +15 -2
  14. package/src/plugins/url.ts +12 -1
  15. package/src/plugins/vim.ts +12 -2
  16. package/ts_build/src/plugins/EmbeddingPluginV2.d.ts +7 -0
  17. package/ts_build/src/plugins/EmbeddingPluginV2.js +41 -0
  18. package/ts_build/src/plugins/EmbeddingPluginV2.js.map +1 -0
  19. package/ts_build/src/plugins/GitHubPluginV2.d.ts +10 -0
  20. package/ts_build/src/plugins/GitHubPluginV2.js +57 -0
  21. package/ts_build/src/plugins/GitHubPluginV2.js.map +1 -0
  22. package/ts_build/src/plugins/PluginBase.d.ts +15 -0
  23. package/ts_build/src/plugins/PluginBase.js +32 -0
  24. package/ts_build/src/plugins/PluginBase.js.map +1 -0
  25. package/ts_build/src/plugins/asana.d.ts +3 -2
  26. package/ts_build/src/plugins/asana.js +10 -1
  27. package/ts_build/src/plugins/asana.js.map +1 -1
  28. package/ts_build/src/plugins/downloader/plugin.d.ts +4 -2
  29. package/ts_build/src/plugins/downloader/plugin.js +10 -1
  30. package/ts_build/src/plugins/downloader/plugin.js.map +1 -1
  31. package/ts_build/src/plugins/embedding.d.ts +4 -2
  32. package/ts_build/src/plugins/embedding.js +10 -1
  33. package/ts_build/src/plugins/embedding.js.map +1 -1
  34. package/ts_build/src/plugins/figma.d.ts +4 -1
  35. package/ts_build/src/plugins/figma.js +16 -2
  36. package/ts_build/src/plugins/figma.js.map +1 -1
  37. package/ts_build/src/plugins/github.d.ts +4 -2
  38. package/ts_build/src/plugins/github.js +28 -4
  39. package/ts_build/src/plugins/github.js.map +1 -1
  40. package/ts_build/src/plugins/jira.d.ts +3 -2
  41. package/ts_build/src/plugins/jira.js +10 -1
  42. package/ts_build/src/plugins/jira.js.map +1 -1
  43. package/ts_build/src/plugins/language.d.ts +3 -1
  44. package/ts_build/src/plugins/language.js +8 -1
  45. package/ts_build/src/plugins/language.js.map +1 -1
  46. package/ts_build/src/plugins/linear.d.ts +3 -2
  47. package/ts_build/src/plugins/linear.js +10 -1
  48. package/ts_build/src/plugins/linear.js.map +1 -1
  49. package/ts_build/src/plugins/notion.d.ts +3 -2
  50. package/ts_build/src/plugins/notion.js +10 -1
  51. package/ts_build/src/plugins/notion.js.map +1 -1
  52. package/ts_build/src/plugins/plugins.d.ts +9 -5
  53. package/ts_build/src/plugins/plugins.js +90 -23
  54. package/ts_build/src/plugins/plugins.js.map +1 -1
  55. package/ts_build/src/plugins/types.d.ts +12 -2
  56. package/ts_build/src/plugins/url.d.ts +4 -1
  57. package/ts_build/src/plugins/url.js +10 -1
  58. package/ts_build/src/plugins/url.js.map +1 -1
  59. package/ts_build/src/plugins/vim.d.ts +4 -2
  60. package/ts_build/src/plugins/vim.js +10 -1
  61. package/ts_build/src/plugins/vim.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tyvm/knowhow",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "ai cli with plugins and agents",
5
5
  "main": "ts_build/src/index.js",
6
6
  "bin": {
@@ -0,0 +1,48 @@
1
+ import { MinimalEmbedding } from "../types";
2
+ import { Plugin, PluginMeta } from "./types";
3
+
4
+ export abstract class PluginBase implements Plugin {
5
+ /** Manual on/off toggle (default ON) */
6
+ private active = true;
7
+
8
+ constructor(public readonly meta: PluginMeta) {}
9
+
10
+ /* ------------------------------------------------------------------ */
11
+ /** Public helpers called by PluginService -------------------------- */
12
+ /* ------------------------------------------------------------------ */
13
+ enable(): void {
14
+ this.active = true;
15
+ }
16
+
17
+ disable(): void {
18
+ this.active = false;
19
+ }
20
+
21
+ async isEnabled(): Promise<boolean> {
22
+ if (!this.active) return false;
23
+
24
+ const envOk = this.hasRequiredEnv();
25
+
26
+ const extraOk = await this.customEnableCheck();
27
+ return envOk && extraOk;
28
+ }
29
+
30
+ protected hasRequiredEnv(): boolean {
31
+ return (
32
+ !this.meta.requires ||
33
+ this.meta.requires.every((k) => process.env[k] && process.env[k] !== "")
34
+ );
35
+ }
36
+
37
+ protected customEnableCheck(): boolean | Promise<boolean> {
38
+ return true; // subclasses override if needed
39
+ }
40
+
41
+ /* ------------------------------------------------------------------ */
42
+ /** Mandatory plugin actions ---------------------------------------- */
43
+ /* ------------------------------------------------------------------ */
44
+ abstract call(input?: string): Promise<string>;
45
+ abstract embed(input: string): Promise<MinimalEmbedding[]>;
46
+ }
47
+
48
+ export { PluginMeta, Plugin } from "./types";
@@ -1,10 +1,20 @@
1
- import { Plugin } from "./types";
1
+ import { PluginBase, PluginMeta } from "./PluginBase";
2
2
  import { Embeddable, MinimalEmbedding } from "../types";
3
3
 
4
- export class AsanaPlugin implements Plugin {
4
+ export class AsanaPlugin extends PluginBase {
5
+ static readonly meta: PluginMeta = {
6
+ key: "asana",
7
+ name: "Asana Plugin",
8
+ requires: ["ASANA_TOKEN"]
9
+ };
10
+
5
11
  private asanaClient = require("asana").ApiClient.instance;
6
12
 
7
13
  constructor() {
14
+ super(AsanaPlugin.meta);
15
+
16
+ if (!this.isEnabled()) return;
17
+
8
18
  this.asanaClient.authentications.token = process.env.ASANA_TOKEN;
9
19
  this.asanaClient.defaultHeaders = {
10
20
  "Asana-Enable": "new_user_task_lists,new_goal_memberships",
@@ -1,10 +1,20 @@
1
1
  import fs from "fs";
2
- import { Plugin } from "../types";
2
+ import { PluginBase, PluginMeta } from "../PluginBase";
3
3
  import { MinimalEmbedding } from "../../types";
4
4
  import { convertToText, processVideo } from "../../conversion";
5
5
  import { Downloader } from "./downloader";
6
6
 
7
- export class DownloaderPlugin implements Plugin {
7
+ export class DownloaderPlugin extends PluginBase {
8
+ static readonly meta: PluginMeta = {
9
+ key: "downloader",
10
+ name: "Downloader Plugin",
11
+ requires: []
12
+ };
13
+
14
+ constructor() {
15
+ super(DownloaderPlugin.meta);
16
+ }
17
+
8
18
  skipExt = ["jpg", "jpeg", "png", "gif"];
9
19
 
10
20
  extractUrls(userInput: string): string[] {
@@ -6,9 +6,19 @@ import {
6
6
  pruneMetadata,
7
7
  } from "../embeddings";
8
8
 
9
- import { Plugin } from "./types";
9
+ import { PluginBase, PluginMeta } from "./PluginBase";
10
+
11
+ export class EmbeddingPlugin extends PluginBase {
12
+ static readonly meta: PluginMeta = {
13
+ key: "embeddings",
14
+ name: "Embedding Plugin",
15
+ requires: []
16
+ };
17
+
18
+ constructor() {
19
+ super(EmbeddingPlugin.meta);
20
+ }
10
21
 
11
- export class EmbeddingPlugin implements Plugin {
12
22
  async embed() {
13
23
  return [];
14
24
  }
@@ -1,5 +1,6 @@
1
1
  import { Client } from "figma-js";
2
2
  import qs from "qs"; // Assumed to be installed
3
+ import { PluginBase, PluginMeta } from "./PluginBase";
3
4
  import { Plugin } from "./types";
4
5
  import { MinimalEmbedding } from "../types";
5
6
  import { askGptVision } from "../ai";
@@ -30,13 +31,28 @@ interface FigmaApiResponse {
30
31
  nodes: Record<string, FigmaNodeData>;
31
32
  }
32
33
 
33
- export class FigmaPlugin implements Plugin {
34
+ export class FigmaPlugin extends PluginBase implements Plugin {
34
35
  private figmaToken: string;
35
36
  private client: ReturnType<typeof Client>;
36
37
 
38
+ static readonly meta: PluginMeta = {
39
+ key: "figma",
40
+ name: "Figma Plugin",
41
+ requires: ["FIGMA_API_KEY"],
42
+ };
43
+
37
44
  constructor() {
45
+ super(FigmaPlugin.meta);
46
+ if (!this.isEnabled()) return;
47
+
38
48
  this.figmaToken = process.env.FIGMA_API_KEY;
39
- this.client = Client({ personalAccessToken: this.figmaToken });
49
+ this.client = this.figmaToken
50
+ ? Client({ personalAccessToken: this.figmaToken })
51
+ : null;
52
+ }
53
+
54
+ customEnableCheck(): boolean {
55
+ return !!this.figmaToken && !!this.client;
40
56
  }
41
57
 
42
58
  async loadFigmaData(url: string) {
@@ -1,15 +1,44 @@
1
1
  import { Octokit } from "@octokit/rest";
2
- import { Plugin } from "./types";
2
+ import { PluginBase, PluginMeta } from "./PluginBase";
3
3
  import { parseHunks, hunksToPatch } from "../agents/tools/patch";
4
4
  import { MinimalEmbedding } from "../types";
5
5
 
6
- export class GitHubPlugin implements Plugin {
6
+ export class GitHubPlugin extends PluginBase {
7
+ static readonly meta: PluginMeta = {
8
+ key: "github",
9
+ name: "GitHub Plugin",
10
+ requires: ["GITHUB_TOKEN"],
11
+ };
12
+
7
13
  octokit: Octokit;
8
14
 
9
15
  constructor() {
10
- this.octokit = new Octokit({
11
- auth: process.env.GITHUB_TOKEN,
12
- });
16
+ super(GitHubPlugin.meta);
17
+
18
+ const key = process.env.GITHUB_TOKEN;
19
+ if (key && this.isEnabled()) {
20
+ this.octokit = new Octokit({
21
+ auth: key,
22
+ });
23
+ }
24
+ }
25
+
26
+ protected customEnableCheck(): boolean {
27
+ // Additional check: ensure we can create the Octokit client
28
+ try {
29
+ const key = process.env.GITHUB_TOKEN;
30
+ if (key) {
31
+ this.octokit = new Octokit({ auth: key });
32
+ return true;
33
+ }
34
+ return false;
35
+ } catch (error) {
36
+ console.error(
37
+ "GITHUB PLUGIN: Failed to initialize Octokit client",
38
+ error
39
+ );
40
+ return false;
41
+ }
13
42
  }
14
43
 
15
44
  async embed(userPrompt: string): Promise<MinimalEmbedding[]> {
@@ -1,11 +1,20 @@
1
1
  import JiraClient from "jira-client";
2
- import { Plugin } from "./types";
2
+ import { PluginBase, PluginMeta } from "./PluginBase";
3
3
  import { MinimalEmbedding } from "../types";
4
4
 
5
- export class JiraPlugin implements Plugin {
5
+ export class JiraPlugin extends PluginBase {
6
+ static readonly meta: PluginMeta = {
7
+ key: "jira",
8
+ name: "Jira Plugin",
9
+ requires: ["JIRA_HOST", "JIRA_USER", "JIRA_PASSWORD"]
10
+ };
11
+
6
12
  jiraClient: JiraClient;
7
13
 
8
14
  constructor() {
15
+ super(JiraPlugin.meta);
16
+
17
+ if (!this.isEnabled()) return;
9
18
  this.jiraClient = new JiraClient({
10
19
  protocol: "https",
11
20
  host: process.env.JIRA_HOST,
@@ -1,6 +1,7 @@
1
1
  import { readFile, fileExists, fileStat } from "../utils";
2
2
  import { Language } from "../types";
3
3
  import { getConfig, getLanguageConfig } from "../config";
4
+ import { PluginBase, PluginMeta } from "./PluginBase";
4
5
  import { Plugin } from "./types";
5
6
  import { GitHubPlugin } from "./github";
6
7
  import { AsanaPlugin } from "./asana";
@@ -8,8 +9,16 @@ import { JiraPlugin } from "./jira";
8
9
  import { LinearPlugin } from "./linear";
9
10
  import { PluginService } from "./plugins";
10
11
 
11
- export class LanguagePlugin implements Plugin {
12
- constructor(private pluginService: PluginService) {}
12
+ export class LanguagePlugin extends PluginBase implements Plugin {
13
+ static readonly meta: PluginMeta = {
14
+ key: "language",
15
+ name: "Language Plugin",
16
+ requires: []
17
+ };
18
+
19
+ constructor(private pluginService: PluginService) {
20
+ super(LanguagePlugin.meta);
21
+ }
13
22
 
14
23
  async embed(userPrompt: string) {
15
24
  return [];
@@ -1,11 +1,20 @@
1
1
  import { LinearClient } from "@linear/sdk";
2
- import { Plugin } from "./types";
2
+ import { PluginBase, PluginMeta } from "./PluginBase";
3
3
  import { MinimalEmbedding } from "../types";
4
4
 
5
- export class LinearPlugin implements Plugin {
5
+ export class LinearPlugin extends PluginBase {
6
+ static readonly meta: PluginMeta = {
7
+ key: "linear",
8
+ name: "Linear Plugin",
9
+ requires: ["LINEAR_API_KEY"],
10
+ };
11
+
6
12
  linearClient: LinearClient;
7
13
 
8
14
  constructor() {
15
+ super(LinearPlugin.meta);
16
+
17
+ if (!this.isEnabled()) return;
9
18
  this.linearClient = new LinearClient({
10
19
  apiKey: process.env.LINEAR_API_KEY,
11
20
  });
@@ -1,12 +1,21 @@
1
1
  import { Client } from "@notionhq/client";
2
- import { Plugin } from "./types";
2
+ import { PluginBase, PluginMeta } from "./PluginBase";
3
3
  import { PageObjectResponse } from "@notionhq/client/build/src/api-endpoints";
4
4
  import { Embeddable, MinimalEmbedding } from "../types";
5
5
 
6
- export class NotionPlugin implements Plugin {
6
+ export class NotionPlugin extends PluginBase {
7
+ static readonly meta: PluginMeta = {
8
+ key: "notion",
9
+ name: "Notion Plugin",
10
+ requires: ["NOTION_TOKEN"]
11
+ };
12
+
7
13
  notionClient: Client;
8
14
 
9
15
  constructor() {
16
+ super(NotionPlugin.meta);
17
+
18
+ if (!this.isEnabled()) return;
10
19
  this.notionClient = new Client({
11
20
  auth: process.env.NOTION_TOKEN,
12
21
  });
@@ -13,43 +13,109 @@ import { FigmaPlugin } from "./figma";
13
13
  import { UrlPlugin } from "./url";
14
14
 
15
15
  export class PluginService {
16
- plugins = {
17
- embeddings: new EmbeddingPlugin(),
18
- vim: new VimPlugin(),
19
- github: new GitHubPlugin(),
20
- asana: new AsanaPlugin(),
21
- linear: new LinearPlugin(),
22
- jira: new JiraPlugin(),
23
- notion: new NotionPlugin(),
24
- download: new DownloaderPlugin(),
25
- figma: new FigmaPlugin(),
26
- language: new LanguagePlugin(this),
27
- url: new UrlPlugin(),
28
- } as Record<string, Plugin>;
16
+ private pluginMap = new Map<string, Plugin>();
17
+
18
+ constructor() {
19
+ // Register migrated PluginBase plugins
20
+ this.pluginMap.set("embeddings", new EmbeddingPlugin());
21
+ this.pluginMap.set("vim", new VimPlugin());
22
+ this.pluginMap.set("github", new GitHubPlugin());
23
+ this.pluginMap.set("asana", new AsanaPlugin());
24
+ this.pluginMap.set("linear", new LinearPlugin());
25
+ this.pluginMap.set("jira", new JiraPlugin());
26
+ this.pluginMap.set("notion", new NotionPlugin());
27
+ this.pluginMap.set("download", new DownloaderPlugin());
28
+ this.pluginMap.set("figma", new FigmaPlugin());
29
+ this.pluginMap.set("language", new LanguagePlugin(this));
30
+ this.pluginMap.set("url", new UrlPlugin());
31
+
32
+ // Keep legacy plugins for backward compatibility
33
+ // These will be removed once all consumers are updated
34
+ }
35
+
36
+ /* -------- lifecycle helpers ------------------------------------ */
37
+
38
+ /**
39
+ * Dynamically import a package / file and register it.
40
+ * @param spec ESM import specifier, e.g. "my-linear-plugin" or "./plugins/foo"
41
+ * @returns the key under which it was stored
42
+ */
43
+ async loadPlugin(spec: string): Promise<string> {
44
+ const { default: PluginCtor } = await import(spec);
45
+ const instance: Plugin = new PluginCtor(this); // assumes default export
46
+ this.pluginMap.set(instance.meta.key, instance);
47
+ return instance.meta.key;
48
+ }
49
+
50
+ /** Disable a plugin by its key; returns `true` if found. */
51
+ disablePlugin(key: string): boolean {
52
+ const p = this.pluginMap.get(key);
53
+ if (!p) return false;
54
+ p.disable();
55
+ return true;
56
+ }
57
+
58
+ /** Enable a plugin by its key; returns `true` if found. */
59
+ enablePlugin(key: string): boolean {
60
+ const p = this.pluginMap.get(key);
61
+ if (!p) return false;
62
+ p.enable();
63
+ return true;
64
+ }
65
+
66
+ /* -------- existing public API (updated for compatibility) ---------------------- */
29
67
 
30
68
  listPlugins() {
31
- return Object.keys(this.plugins);
69
+ const newPlugins = [...this.pluginMap.keys()];
70
+ return newPlugins;
32
71
  }
33
72
 
34
73
  isPlugin(name: string) {
35
- return name in this.plugins;
74
+ return this.pluginMap.has(name);
36
75
  }
37
76
 
38
- registerPlugin(name, plugin: Plugin) {
39
- this.plugins[name] = plugin;
77
+ registerPlugin(name: string, plugin: Plugin) {
78
+ this.pluginMap.set(name, plugin);
40
79
  }
41
80
 
42
- async callMany(plugins: string[], user_input?: string) {
43
- const calls = plugins.map((p) => this.plugins[p].call(user_input));
44
- return (await Promise.all(calls)).join("\n\n");
81
+ async callMany(plugins: string[], userInput?: string) {
82
+ const calls = plugins.map(async (p) => {
83
+ return this.call(p, userInput);
84
+ });
85
+
86
+ const results = await Promise.all(calls);
87
+ return results.filter((result) => result !== "").join("\n\n");
45
88
  }
46
89
 
47
- async call(kind: string, user_input?: string) {
48
- return this.plugins[kind].call(user_input);
90
+ async call(kind: string, userInput?: string) {
91
+ // Check new plugin system first
92
+ const newPlugin = this.pluginMap.get(kind);
93
+
94
+ if (!newPlugin) {
95
+ throw new Error(`Plugin ${kind} not found`);
96
+ }
97
+
98
+ const enabled = await newPlugin.isEnabled();
99
+ if (!enabled) {
100
+ console.log(`Plugin ${kind} is disabled, skipping`);
101
+ return "";
102
+ }
103
+ return newPlugin.call(userInput);
49
104
  }
50
105
 
51
- async embed(kind: string, user_input: string) {
52
- return this.plugins[kind].embed(user_input);
106
+ async embed(kind: string, userInput: string) {
107
+ // Check new plugin system first
108
+ const newPlugin = this.pluginMap.get(kind);
109
+ if (!newPlugin) {
110
+ throw new Error(`Plugin ${kind} not found`);
111
+ }
112
+
113
+ const enabled = await newPlugin.isEnabled();
114
+ if (!enabled) {
115
+ console.log(`Plugin ${kind} is disabled, skipping`);
116
+ return [];
117
+ }
118
+ return newPlugin.embed ? newPlugin.embed(userInput) : [];
53
119
  }
54
120
  }
55
121
 
@@ -1,5 +1,18 @@
1
1
  import { Embeddable, MinimalEmbedding } from "../types";
2
+
3
+ export interface PluginMeta {
4
+ key: string;
5
+ name: string;
6
+ description?: string;
7
+ requires?: string[]; // Environment variables required
8
+ }
9
+
2
10
  export interface Plugin {
3
- call(user_input?: string): Promise<string>;
4
- embed(user_input?: string): Promise<MinimalEmbedding[]>;
11
+ call(userInput?: string): Promise<string>;
12
+ embed(userInput?: string): Promise<MinimalEmbedding[]>;
13
+ enable(): void;
14
+ disable(): void;
15
+ isEnabled(): Promise<boolean>;
16
+
17
+ meta: PluginMeta;
5
18
  }
@@ -1,10 +1,21 @@
1
+ import { PluginBase, PluginMeta } from "./PluginBase";
1
2
  import { Plugin } from "./types";
2
3
  import { MinimalEmbedding } from "../types";
3
4
  import axios from "axios";
4
5
  import * as cheerio from "cheerio";
5
6
  import loadWebpage from "../agents/tools/loadWebpage";
6
7
 
7
- export class UrlPlugin implements Plugin {
8
+ export class UrlPlugin extends PluginBase implements Plugin {
9
+ static readonly meta: PluginMeta = {
10
+ key: "url",
11
+ name: "URL Plugin",
12
+ requires: []
13
+ };
14
+
15
+ constructor() {
16
+ super(UrlPlugin.meta);
17
+ }
18
+
8
19
  async embed(userPrompt: string): Promise<MinimalEmbedding[]> {
9
20
  const urls = this.extractUrls(userPrompt);
10
21
  const embeddings = await Promise.all(urls.map(this.fetchAndParseUrl));
@@ -1,8 +1,18 @@
1
1
  import glob from "glob";
2
2
  import { readFile, fileExists, fileStat } from "../utils";
3
- import { Plugin } from "./types";
3
+ import { PluginBase, PluginMeta } from "./PluginBase";
4
+
5
+ export class VimPlugin extends PluginBase {
6
+ static readonly meta: PluginMeta = {
7
+ key: "vim",
8
+ name: "Vim Plugin",
9
+ requires: []
10
+ };
11
+
12
+ constructor() {
13
+ super(VimPlugin.meta);
14
+ }
4
15
 
5
- export class VimPlugin implements Plugin {
6
16
  async embed(userPrompt: string) {
7
17
  return [];
8
18
  }
@@ -0,0 +1,7 @@
1
+ import { PluginBase } from "./PluginBase";
2
+ import { MinimalEmbedding } from "../types";
3
+ export declare class EmbeddingPluginV2 extends PluginBase {
4
+ constructor();
5
+ embed(): Promise<MinimalEmbedding[]>;
6
+ call(userPrompt?: string): Promise<string>;
7
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EmbeddingPluginV2 = void 0;
4
+ const PluginBase_1 = require("./PluginBase");
5
+ const config_1 = require("../config");
6
+ const embeddings_1 = require("../embeddings");
7
+ class EmbeddingPluginV2 extends PluginBase_1.PluginBase {
8
+ constructor() {
9
+ const meta = {
10
+ key: "embeddings-v2",
11
+ name: "Embeddings Plugin V2",
12
+ description: "Enhanced embedding plugin with enable/disable support",
13
+ requires: [],
14
+ };
15
+ super(meta);
16
+ }
17
+ async embed() {
18
+ return [];
19
+ }
20
+ async call(userPrompt) {
21
+ if (!userPrompt) {
22
+ return "EMBEDDING PLUGIN V2: No prompt provided";
23
+ }
24
+ const count = 7;
25
+ const embeddings = await (0, embeddings_1.getConfiguredEmbeddings)();
26
+ const config = await (0, config_1.getConfig)();
27
+ const results = await (0, embeddings_1.queryEmbedding)(userPrompt, embeddings, config.embeddingModel);
28
+ const context = results.slice(0, count);
29
+ (0, embeddings_1.pruneVector)(context);
30
+ (0, embeddings_1.pruneMetadata)(context);
31
+ for (const entry of context) {
32
+ console.log(`EMBEDDING PLUGIN V2: Reading entry ${entry.id}`);
33
+ }
34
+ const contextLength = JSON.stringify(context).split(" ").length;
35
+ console.log(`EMBEDDING PLUGIN V2: Found ${context.length} entries. Loading ${contextLength} words`);
36
+ return `EMBEDDING PLUGIN V2: Our knowledgebase contains this information which can be used to answer the question:
37
+ ${JSON.stringify(context)}`;
38
+ }
39
+ }
40
+ exports.EmbeddingPluginV2 = EmbeddingPluginV2;
41
+ //# sourceMappingURL=EmbeddingPluginV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmbeddingPluginV2.js","sourceRoot":"","sources":["../../../src/plugins/EmbeddingPluginV2.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAEtD,sCAAsC;AACtC,8CAKuB;AAEvB,MAAa,iBAAkB,SAAQ,uBAAU;IAC/C;QACE,MAAM,IAAI,GAAe;YACvB,GAAG,EAAE,eAAe;YACpB,IAAI,EAAE,sBAAsB;YAC5B,WAAW,EAAE,uDAAuD;YACpE,QAAQ,EAAE,EAAE;SACb,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAmB;QAC5B,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,yCAAyC,CAAC;SAClD;QAED,MAAM,KAAK,GAAG,CAAC,CAAC;QAChB,MAAM,UAAU,GAAG,MAAM,IAAA,oCAAuB,GAAE,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,IAAA,kBAAS,GAAE,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,IAAA,2BAAc,EAClC,UAAU,EACV,UAAU,EACV,MAAM,CAAC,cAAc,CACtB,CAAC;QACF,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QAExC,IAAA,wBAAW,EAAC,OAAO,CAAC,CAAC;QACrB,IAAA,0BAAa,EAAC,OAAO,CAAC,CAAC;QAEvB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,sCAAsC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;SAC/D;QAED,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;QAChE,OAAO,CAAC,GAAG,CACT,8BAA8B,OAAO,CAAC,MAAM,qBAAqB,aAAa,QAAQ,CACvF,CAAC;QAEF,OAAO;MACL,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9B,CAAC;CACF;AA7CD,8CA6CC"}
@@ -0,0 +1,10 @@
1
+ import { PluginBase } from "./PluginBase";
2
+ import { MinimalEmbedding } from "../types";
3
+ export declare class GitHubPluginV2 extends PluginBase {
4
+ private octokit?;
5
+ constructor();
6
+ protected customEnableCheck(): boolean;
7
+ embed(userPrompt: string): Promise<MinimalEmbedding[]>;
8
+ extractUrls(userPrompt: string): string[];
9
+ call(userPrompt?: string): Promise<string>;
10
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GitHubPluginV2 = void 0;
4
+ const PluginBase_1 = require("./PluginBase");
5
+ const rest_1 = require("@octokit/rest");
6
+ class GitHubPluginV2 extends PluginBase_1.PluginBase {
7
+ octokit;
8
+ constructor() {
9
+ const meta = {
10
+ key: "github-v2",
11
+ name: "GitHub Plugin V2",
12
+ description: "Enhanced GitHub plugin with automatic enable/disable based on token availability",
13
+ requires: ["GITHUB_TOKEN"],
14
+ };
15
+ super(meta);
16
+ }
17
+ customEnableCheck() {
18
+ try {
19
+ const key = process.env.GITHUB_TOKEN;
20
+ if (key) {
21
+ this.octokit = new rest_1.Octokit({ auth: key });
22
+ return true;
23
+ }
24
+ return false;
25
+ }
26
+ catch (error) {
27
+ console.error("GITHUB PLUGIN V2: Failed to initialize Octokit client", error);
28
+ return false;
29
+ }
30
+ }
31
+ async embed(userPrompt) {
32
+ const urls = this.extractUrls(userPrompt);
33
+ if (!urls.length)
34
+ return [];
35
+ return [];
36
+ }
37
+ extractUrls(userPrompt) {
38
+ const prUrlRegex = /https:\/\/github\.com\/([\w-]+)\/([\w-]+)\/pull\/(\d+)/g;
39
+ const matches = userPrompt.match(prUrlRegex);
40
+ return matches || [];
41
+ }
42
+ async call(userPrompt) {
43
+ if (!userPrompt) {
44
+ return "GITHUB PLUGIN V2: No prompt provided";
45
+ }
46
+ if (!this.octokit) {
47
+ return "GITHUB PLUGIN V2: GitHub client not initialized";
48
+ }
49
+ const urls = this.extractUrls(userPrompt);
50
+ if (!urls.length) {
51
+ return "GITHUB PLUGIN V2: No pull request URLs detected.";
52
+ }
53
+ return `GITHUB PLUGIN V2: Found ${urls.length} GitHub URLs. Enhanced processing with enable/disable support.`;
54
+ }
55
+ }
56
+ exports.GitHubPluginV2 = GitHubPluginV2;
57
+ //# sourceMappingURL=GitHubPluginV2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GitHubPluginV2.js","sourceRoot":"","sources":["../../../src/plugins/GitHubPluginV2.ts"],"names":[],"mappings":";;;AAAA,6CAAsD;AAEtD,wCAAwC;AAExC,MAAa,cAAe,SAAQ,uBAAU;IACpC,OAAO,CAAW;IAE1B;QACE,MAAM,IAAI,GAAe;YACvB,GAAG,EAAE,WAAW;YAChB,IAAI,EAAE,kBAAkB;YACxB,WAAW,EAAE,kFAAkF;YAC/F,QAAQ,EAAE,CAAC,cAAc,CAAC;SAC3B,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,CAAC;IACd,CAAC;IAES,iBAAiB;QAEzB,IAAI;YACF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;YACrC,IAAI,GAAG,EAAE;gBACP,IAAI,CAAC,OAAO,GAAG,IAAI,cAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;gBAC1C,OAAO,IAAI,CAAC;aACb;YACD,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,CAAC,KAAK,CAAC,uDAAuD,EAAE,KAAK,CAAC,CAAC;YAC9E,OAAO,KAAK,CAAC;SACd;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,UAAkB;QAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAG5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,WAAW,CAAC,UAAkB;QAC5B,MAAM,UAAU,GACd,yDAAyD,CAAC;QAC5D,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,OAAO,IAAI,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAAmB;QAC5B,IAAI,CAAC,UAAU,EAAE;YACf,OAAO,sCAAsC,CAAC;SAC/C;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,OAAO,iDAAiD,CAAC;SAC1D;QAED,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAE1C,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YAChB,OAAO,kDAAkD,CAAC;SAC3D;QAED,OAAO,2BAA2B,IAAI,CAAC,MAAM,gEAAgE,CAAC;IAChH,CAAC;CACF;AA5DD,wCA4DC"}
@@ -0,0 +1,15 @@
1
+ import { MinimalEmbedding } from "../types";
2
+ import { Plugin, PluginMeta } from "./types";
3
+ export declare abstract class PluginBase implements Plugin {
4
+ readonly meta: PluginMeta;
5
+ private active;
6
+ constructor(meta: PluginMeta);
7
+ enable(): void;
8
+ disable(): void;
9
+ isEnabled(): Promise<boolean>;
10
+ protected hasRequiredEnv(): boolean;
11
+ protected customEnableCheck(): boolean | Promise<boolean>;
12
+ abstract call(input?: string): Promise<string>;
13
+ abstract embed(input: string): Promise<MinimalEmbedding[]>;
14
+ }
15
+ export { PluginMeta, Plugin } from "./types";