|
| 1 | +/** |
| 2 | + * This file describes the code-server plugin API for adding new applications. |
| 3 | + * |
| 4 | + * This API is not stable and subject to change as we refine it. |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * Overlay |
| 9 | + * |
| 10 | + * The homepage of code-server will launch into VS Code. However, there will be an overlay |
| 11 | + * button that when clicked, will show all available applications with their names, |
| 12 | + * icons and provider plugins. When one clicks on an app's icon, they will be directed |
| 13 | + * to <code-server-root>/<plugin-name>/<app-name> to access the application. |
| 14 | + * |
| 15 | + * At some point we will adjust this API and the overlay to also easily allow installing |
| 16 | + * new plugins and applications. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * Plugins |
| 21 | + * |
| 22 | + * Plugins are just node modules. |
| 23 | + * |
| 24 | + * code-server will use $CS_PLUGIN_PATH to find plugins. Each subdirectory in |
| 25 | + * $CS_PLUGIN_PATH with a package.json where the engine is code-server is a plugin. |
| 26 | + * |
| 27 | + * e.g. CS_PLUGIN_PATH=/tmp/nhooyr:/tmp/ash will cause code-server to search |
| 28 | + * /tmp/nhooyr and then /tmp/ash for plugins. |
| 29 | + * |
| 30 | + * After the search is complete, plugins will be required in first found order and |
| 31 | + * inited via the API described below. |
| 32 | + * |
| 33 | + * There will also be a /api/applications endpoint to allow programmatic access to all |
| 34 | + * available applications. It could be used to create a custom application dashboard for |
| 35 | + * example. |
| 36 | + */ |
| 37 | +import { Logger } from "@coder/logger" |
| 38 | + |
| 39 | +/** |
| 40 | + * Your plugin module must implement this interface. |
| 41 | + * |
| 42 | + * The plugin's name, description and version are fetched from its module's package.json |
| 43 | + * |
| 44 | + * All routes registered by a plugin will be automatically under |
| 45 | + * <code-server-root>/<plugin-name> |
| 46 | + * |
| 47 | + * If two plugins are found with the exact same name, then code-server will |
| 48 | + * use the last one found and emit a warning. |
| 49 | + */ |
| 50 | +export interface Plugin { |
| 51 | + /** |
| 52 | + * |
| 53 | + * This is called when /api/applications is hit or the code-server overlay |
| 54 | + * needs to refresh the list of applications and so code-server is collecting |
| 55 | + * each plugin's list of applications. |
| 56 | + * |
| 57 | + * Ensure this is as fast as possible. |
| 58 | + */ |
| 59 | + applications(): Application[] | Promise<Application[]> |
| 60 | + |
| 61 | + /** |
| 62 | + * init passes the API interface to the plugin so that it may register its routes. |
| 63 | + */ |
| 64 | + init(api: API): void |
| 65 | +} |
| 66 | + |
| 67 | +/** |
| 68 | + * Application represents a user accessible application. |
| 69 | + * |
| 70 | + * When the user clicks on the icon, they will be redirected to |
| 71 | + * <code-server-root>/<plugin-name>/<app-name> |
| 72 | + * where the application should be accessible. |
| 73 | + * |
| 74 | + * If the app's name is the same as the plugin's name then |
| 75 | + * <code-server-root>/<plugin-name> will be used instead. |
| 76 | + */ |
| 77 | +export interface Application { |
| 78 | + readonly name: string |
| 79 | + |
| 80 | + /** |
| 81 | + * The path at which the icon for this application can be accessed. |
| 82 | + * <code-server-root>/<plugin-name>/<app-name>/<icon-path> |
| 83 | + */ |
| 84 | + readonly iconPath: string |
| 85 | + |
| 86 | + /** |
| 87 | + * Used to indicate the version of the application. |
| 88 | + */ |
| 89 | + readonly version: string |
| 90 | +} |
| 91 | + |
| 92 | +/** |
| 93 | + * API is passed to plugins so that they may register their routes. |
| 94 | + */ |
| 95 | +export interface API { |
| 96 | + /** |
| 97 | + * All plugin logs should be logged via this logger. |
| 98 | + */ |
| 99 | + readonly log: Logger |
| 100 | + |
| 101 | + /** |
| 102 | + * .... |
| 103 | + * |
| 104 | + * API idential to express to register routes under the plugin's subpath. |
| 105 | + * plugins can use proxy middlewhere to send their requests to their own |
| 106 | + * server if they cannot or do not want to use node/express. |
| 107 | + */ |
| 108 | +} |
0 commit comments