From f3f46e4275c709663ac4b1b814c25e0201961f6e Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Mon, 23 Sep 2024 09:54:55 -0700 Subject: [PATCH 1/2] Refactor HttpContextProvider to support an array of ContextItems from the response --- core/context/providers/HttpContextProvider.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/context/providers/HttpContextProvider.ts b/core/context/providers/HttpContextProvider.ts index a33bcb775..9e6aaa8c7 100644 --- a/core/context/providers/HttpContextProvider.ts +++ b/core/context/providers/HttpContextProvider.ts @@ -39,14 +39,15 @@ class HttpContextProvider extends BaseContextProvider { }), }); - const json: any = await response.json(); - return [ - { - description: json.description || "HTTP Context Item", - content: json.content || "", - name: json.name || this.options.title || "HTTP", - }, - ]; + const json = await response.json(); + + const createContextItem = (item: any) => ({ + description: item.description ?? "HTTP Context Item", + content: item.content ?? "", + name: item.name ?? this.options.title ?? "HTTP", + }); + + return Array.isArray(json) ? json.map(createContextItem) : [createContextItem(json)]; } } From c4281b275ab01a0925a0957ffdf32408ce52318a Mon Sep 17 00:00:00 2001 From: Steve Rhoades Date: Mon, 23 Sep 2024 10:11:25 -0700 Subject: [PATCH 2/2] add docs for http context provider --- docs/docs/customize/context-providers.md | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/docs/docs/customize/context-providers.md b/docs/docs/customize/context-providers.md index daed6d63b..4891f85ec 100644 --- a/docs/docs/customize/context-providers.md +++ b/docs/docs/customize/context-providers.md @@ -435,6 +435,49 @@ Reference the architecture and platform of your current operating system. } ``` +### `@HTTP` + +The HttpContextProvider makes a POST request to the url passed in the configuration. The server must return 200 OK with a ContextItem object or an array of ContextItems. + +```json title="config.json" +{ + "contextProviders": [ + { + "name": "http", + "params": { + "url": "https://api.example.com/v1/users", + } + } + ] +} +``` + +The receiving URL should expect to receive the following parameters: +```json title="POST parameters" +{ + query: string, + fullInput: string +} +``` + +The response 200 OK should be a JSON object with the following structure: +```json title="Response" +[ + { + "name": "", + "description": "", + "content": "" + } +] + +// OR +{ + "name": "", + "description": "", + "content": "" +} +``` + ### Requesting Context Providers Not seeing what you want? Create an issue [here](https://github.com/continuedev/continue/issues/new?assignees=TyDunn&labels=enhancement&projects=&template=feature-request-%F0%9F%92%AA.md&title=) to request a new Context Provider.