| 1 | import { getControlPlaneEnv } from "../../control-plane/env.js"; |
| 2 | import { |
| 3 | ContextItem, |
| 4 | ContextProviderDescription, |
| 5 | ContextProviderExtras, |
| 6 | ContextSubmenuItem, |
| 7 | LoadSubmenuItemsArgs, |
| 8 | } from "../../index.js"; |
| 9 | import { BaseContextProvider } from "../index.js"; |
| 10 | |
| 11 | class ContinueProxyContextProvider extends BaseContextProvider { |
| 12 | static description: ContextProviderDescription = { |
| 13 | title: "continue-proxy", |
| 14 | displayTitle: "Continue Proxy", |
| 15 | description: "Retrieve a context item from a Continue for Teams add-on", |
| 16 | type: "submenu", |
| 17 | }; |
| 18 | |
| 19 | workOsAccessToken: string | undefined = undefined; |
| 20 | |
| 21 | override get description(): ContextProviderDescription { |
| 22 | return { |
| 23 | title: |
| 24 | this.options.title || ContinueProxyContextProvider.description.title, |
| 25 | displayTitle: |
| 26 | this.options.displayTitle || |
| 27 | this.options.name || |
| 28 | ContinueProxyContextProvider.description.displayTitle, |
| 29 | description: |
| 30 | this.options.description || |
| 31 | ContinueProxyContextProvider.description.description, |
| 32 | type: this.options.type || ContinueProxyContextProvider.description.type, |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | async loadSubmenuItems( |
| 37 | args: LoadSubmenuItemsArgs, |
| 38 | ): Promise<ContextSubmenuItem[]> { |
| 39 | const env = await getControlPlaneEnv(args.ide.getIdeSettings()); |
| 40 | const response = await args.fetch( |
| 41 | new URL(`/proxy/context/${this.options.id}/list`, env.CONTROL_PLANE_URL), |
| 42 | { |
| 43 | method: "GET", |
| 44 | headers: { |
| 45 | "Content-Type": "application/json", |
| 46 | Authorization: `Bearer ${this.workOsAccessToken}`, |
| 47 | }, |
| 48 | }, |
| 49 | ); |
| 50 | const data = await response.json(); |
| 51 | return data.items; |
| 52 | } |
| 53 | |
| 54 | async getContextItems( |
| 55 | query: string, |
| 56 | extras: ContextProviderExtras, |
| 57 | ): Promise<ContextItem[]> { |
| 58 | const env = await getControlPlaneEnv(extras.ide.getIdeSettings()); |
| 59 | const response = await extras.fetch( |
| 60 | new URL( |
| 61 | `/proxy/context/${this.options.id}/retrieve`, |
| 62 | env.CONTROL_PLANE_URL, |
| 63 | ), |
| 64 | { |
| 65 | method: "POST", |
| 66 | headers: { |
| 67 | "Content-Type": "application/json", |
| 68 | Authorization: `Bearer ${this.workOsAccessToken}`, |
| 69 | }, |
| 70 | body: JSON.stringify({ |
| 71 | query: query || "", |
| 72 | fullInput: extras.fullInput, |
| 73 | }), |
| 74 | }, |
| 75 | ); |
| 76 | |
| 77 | const items: any = await response.json(); |
| 78 | return items; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | export default ContinueProxyContextProvider; |