diff --git a/bun.lockb b/bun.lockb index cdd6e8eaa..b446dea7f 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docs/integrations/sources/README.md b/docs/integrations/sources/README.md new file mode 100644 index 000000000..d26f3f101 --- /dev/null +++ b/docs/integrations/sources/README.md @@ -0,0 +1,40 @@ +# Content sources + +Integrations can act as sources for computing content from external sources. Use-cases include: + +- Translation: auto-translate another content and keeping it updated +- Changelog +- Code documentation + + +## Flow + +## Create a content source + +First of all, content sources should be listed in the `gitbook-manifest.yaml` file, under `sources`: + +```yaml +sources: + - id: pirate + title: Content as a Pirate +``` + +Then the content source can be implemented: + +```ts +import { createContentSource } from '@gitbook/runtime'; + +const pirate = createContentSource({ + sourceId: 'pirate', + getPages: () => { + + }, + getPageDocument: () => { + + } +}); +``` + +## Refreshing content when source has changed + +At the moment, an integration source can only depend on a GitBook space as a dependency. But we plan on implementing supporting for custom dependencies that can be refreshed. diff --git a/integrations/github-copilot/src/configuration.tsx b/integrations/github-copilot/src/configuration.tsx index 131b994a9..bad78ee2d 100644 --- a/integrations/github-copilot/src/configuration.tsx +++ b/integrations/github-copilot/src/configuration.tsx @@ -1,22 +1,20 @@ import { ContentKitIcon } from '@gitbook/api'; -import { createComponent, getOAuthToken } from '@gitbook/runtime'; +import { InstallationConfigurationProps, createComponent, getOAuthToken } from '@gitbook/runtime'; import { fetchGitHubInstallations } from './github'; import { getGitHubOAuthConfiguration } from './oauth'; -import type { GitHubCopilotConfiguration, GitHubCopilotRuntimeContext } from './types'; +import type { + GitHubCopilotConfiguration, + GitHubCopilotRuntimeContext, + GitHubCopilotRuntimeEnvironment, +} from './types'; import { createGitHubSetupState } from './setup'; -type ConfigureProps = { - installation: { - configuration?: GitHubCopilotConfiguration; - }; -}; - /** * ContentKit component to configure the GitHub Copilot integration. */ export const configurationComponent = createComponent< - ConfigureProps, + InstallationConfigurationProps, { installations: string[]; }, diff --git a/integrations/openai-translate/assets/icon.png b/integrations/openai-translate/assets/icon.png new file mode 100644 index 000000000..fc71f647c Binary files /dev/null and b/integrations/openai-translate/assets/icon.png differ diff --git a/integrations/openai-translate/gitbook-manifest.yaml b/integrations/openai-translate/gitbook-manifest.yaml new file mode 100644 index 000000000..e284e2044 --- /dev/null +++ b/integrations/openai-translate/gitbook-manifest.yaml @@ -0,0 +1,31 @@ +name: openai-translate +title: Translate with OpenAI +organization: gitbook +visibility: public +description: Automatically generate translation content using OpenAI +icon: ./assets/icon.png +externalLinks: + - label: OpenAI Platform + url: https://platform.openai.com/ +categories: + - collaboration +summary: | + # Overview + + Automically generate translations of your content that are kept to date to any changes using OpenAI GPT models. + + # How to use it + + Install the integration on your account and grant access to the source space and the target space. +script: src/index.ts +scopes: + - space:content:read +configurations: + account: + componentId: configure +contentSources: + - id: translate + title: Translate with AI + description: Generate automatic translation from a space using AI. + configuration: + componentId: configureSource diff --git a/integrations/openai-translate/package.json b/integrations/openai-translate/package.json new file mode 100644 index 000000000..a7b55a0e3 --- /dev/null +++ b/integrations/openai-translate/package.json @@ -0,0 +1,23 @@ +{ + "name": "@gitbook/integration-openai-translate", + "version": "0.0.0", + "private": true, + "scripts": { + "typecheck": "tsc --noEmit", + "check": "gitbook check", + "publish-integrations": "gitbook publish .", + "publish-integrations-staging": "gitbook publish .", + "logs": "gitbook tail", + "dev": "gitbook dev", + "test": "bun test" + }, + "dependencies": { + "@gitbook/api": "*", + "@gitbook/runtime": "*", + "openai": "^4.67.1" + }, + "devDependencies": { + "@gitbook/cli": "workspace:*", + "@gitbook/tsconfig": "workspace:*" + } +} diff --git a/integrations/openai-translate/src/configureComponent.tsx b/integrations/openai-translate/src/configureComponent.tsx new file mode 100644 index 000000000..609023019 --- /dev/null +++ b/integrations/openai-translate/src/configureComponent.tsx @@ -0,0 +1,90 @@ +import { createComponent, InstallationConfigurationProps } from '@gitbook/runtime'; + +import { + DEFAULT_MODEL, + type OpenAITranslateRuntimeContext, + type OpenAITranslateRuntimeEnvironment, +} from './types'; + +/** + * ContentKit component to configure the integration. + */ +export const configureComponent = createComponent< + InstallationConfigurationProps, + { + apiKey: string; + model: string; + apiUrl: string; + }, + { action: 'save' }, + OpenAITranslateRuntimeContext +>({ + componentId: 'configure', + initialState: (props, _, context) => { + return { + apiKey: props.installation.configuration.apiKey ?? '', + model: props.installation.configuration.model ?? DEFAULT_MODEL, + apiUrl: props.installation.configuration.apiUrl ?? '', + }; + }, + action: async (element, action, ctx) => { + const { integration, installation } = ctx.environment; + if (action.action === 'save' && installation) { + await ctx.api.integrations.updateIntegrationInstallation( + integration.name, + installation.id, + { + configuration: { + apiKey: element.state.apiKey, + model: element.state.model, + apiUrl: element.state.apiUrl, + }, + }, + ); + } + + return element; + }, + render: async (element, context) => { + return ( + + } + /> + } + /> + + } + /> +