{"id":26541406,"url":"https://github.com/focusreactive/contentful-ai-sdk","last_synced_at":"2026-04-12T20:55:47.545Z","repository":{"id":283307587,"uuid":"934113513","full_name":"focusreactive/contentful-ai-sdk","owner":"focusreactive","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-19T14:35:40.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-19T15:35:42.133Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/focusreactive.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-17T09:49:25.000Z","updated_at":"2025-03-19T14:35:44.000Z","dependencies_parsed_at":"2025-03-19T15:46:55.428Z","dependency_job_id":null,"html_url":"https://github.com/focusreactive/contentful-ai-sdk","commit_stats":null,"previous_names":["focusreactive/contentful-ai-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusreactive%2Fcontentful-ai-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusreactive%2Fcontentful-ai-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusreactive%2Fcontentful-ai-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/focusreactive%2Fcontentful-ai-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/focusreactive","download_url":"https://codeload.github.com/focusreactive/contentful-ai-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244893481,"owners_count":20527603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-22T01:32:04.529Z","updated_at":"2026-04-12T20:55:42.499Z","avatar_url":"https://github.com/focusreactive.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca  href=\"https://focusreactive.com/\"  align=\"center\"\u003e\n\t\t\u003cimg width=\"25%\" height=\"auto\" src=\"https://cdn.sanity.io/images/vftxng62/production/25e191578a3c3d4ddfaf69c5f6f7070aead0bff4-507x168.png?auto=format\"  alt=\"FocusReactive logo\"\u003e\n\u003c/a\u003e\n\n# Contentful AI SDK\n\n## Installation\n\nTo add the SDK to your project, run the following command:\n\n```sh\nyarn add @focus-reactive/contentful-ai-sdk\n```\n\n## Usage\n\n### Initialization\n\nBefore using the SDK, you must initialize it with the Contentful client and a valid OpenAI token.\nIn React apps, you can use the `useSDK` hook from the `@contentful/react-apps-toolkit` package:\n\n```typescript\nimport type { SidebarAppSDK } from '@contentful/app-sdk'\nimport { useSDK } from '@contentful/react-apps-toolkit'\nimport { initSDK } from '@focus-reactive/contentful-ai-sdk'\nimport { useEffect } from 'react'\n\nconst LocationComponent = () =\u003e {\n  const sdk = useSDK\u003cSidebarAppSDK\u003e()\n\n  useEffect(() =\u003e {\n    initSDK({ client: sdk.cma, openAiKey: process.env.REACT_APP_OPENAI_TOKEN! })\n  }, [])\n\n  return ...;\n}\n\nexport default LocationComponent\n\n```\n\nAlternatively, you can directly initialize the client via `createClient` with your access token and pass it to the `initSDK` function.\n\n### Using the SDK\n\n```typescript\nimport type { SidebarAppSDK } from '@contentful/app-sdk'\\\nimport { useSDK } from '@contentful/react-apps-toolkit'\nimport { Form } from '@contentful/f36-components'\nimport { localize } from '@focus-reactive/contentful-ai-sdk'\nimport { useForm } from 'react-hook-form'\nimport { useMutation } from '@tanstack/react-query'\n\nexport default function Translate() {\n  const sdk = useSDK\u003cSidebarAppSDK\u003e()\n  const { handleSubmit } = useForm()\n\n  const { mutate } = useMutation({\n    mutationFn: localize,\n  })\n\n  const onSubmit = (values) =\u003e {\n    mutate({\n      targetLanguage: values.targetLanguage,\n      translationLevel: values.translationLevel,\n      entryId: sdk.entry.getSys().id,\n      localEntryId: values.local,\n      globalEntryId: values.global,\n    })\n  }\n\n  return (\n    \u003cForm onSubmit={handleSubmit(onSubmit)}\u003e\n      ...\n    \u003c/Form\u003e\n  )\n}\n```\n\n## API\n\n### **localize**\n\nTranslate the fields of an entry to the target language. The field values in the default locale will be used as the source. It can be used for both field-level and entry-level localizations.\n\n#### **Parameters**\n\n```typescript\ntype LocalizeFieldsProps = {\n  translationLevel: 'field';\n  targetLanguage: string;\n  entryId: string;\n};\n\ntype LocalizeEntryProps = {\n  translationLevel: 'entry';\n  targetLanguage: string;\n  localEntryId: string;\n  globalEntryId: string;\n};\n\ntype LocalizeProps = LocalizeFieldsProps | LocalizeEntryProps;\n```\n\n- `targetLanguage` - language (or locale) to which you want to translate your entry. **Available locales must be configured in space settings.**\n- `translationLevel` - which localization level to use.\n  - `field` - add target localization to the current entry\n     - `entryId` - ID of the entry that you want to translate.\n  - `entry` -  create a new entry with translated values stored in the default locale and link the global entry (container) with the newly created entry\n     - `localEntryId` - ID of the entry that will be used as a data source.\n     - `globalEntryId` - ID of the entry that will be used as a container for the newly created entry.\n\n#### **Return**\n\n`Promise\u003cvoid\u003e`\n\n### **resolveEntries**\n\nIdentify global and local entries based on whether a given entry refers to any other entries or is being referenced.\n\n#### **Parameters**\n\n- `entryId` - ID of the entry\n\n#### **Return**\n\n`{ global: RecognizedEntry; local: RecognizedEntry }`, where `RecognizedEntry` is an object with the following structure:\n\n```typescript\ntype RecognizedEntry = {\n  id: string;\n  name: string;\n  contentType: { id: string; name: string };\n} | null\n```\n\nIf entry is isolated (no references), `{ global: null, local: entry }` will be returned.\n\n### **findTags**\n\nFind the most relevant tags for the entry's content from the space's configured tags.\n\n#### **Parameters**\n\n- `entryId` - ID of the entry\n- `contentTitle` - content title for more context\n\n#### **Return**\n\nAn array of tags, where each tag is an object with the following structure:\n\n```typescript\ntype Tag = {\n  id: string\n  title: string\n}\n```\n\n### **applyTags**\n\nApply tags (with overwrite) to the given entry\n\n#### **Parameters**\n\n- `entryId` - ID of the entry\n- `tags` - Array of objects with `id` property, where `id` is the ID of the tag\n\n#### **Return**\n\n`Promise\u003cvoid\u003e`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffocusreactive%2Fcontentful-ai-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffocusreactive%2Fcontentful-ai-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffocusreactive%2Fcontentful-ai-sdk/lists"}