1.1.2 • Published 8 months ago

@mavenagi/knowledge-base-integration v1.1.2

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

@mavenagi/knowledge-base-integration

This library facilitates integration between MavenAGI and external knowledge bases. It allows you to create the hooks necessary to sync data from various sources into a MavenAGI knowledge base from a Maven AGI App Studio app.

Installation

npm install @mavenagi/knowledge-base-integration

Usage

To use this library, create an instance of MavenAGIKnowledgeBaseIntegration with custom functions for your specific integration:

import MavenAGIKnowledgeBaseIntegration, { KnowledgeDocumentContentType } from '@mavenagi/knowledge-base-integration';

const integration = new MavenAGIKnowledgeBaseIntegration({
  preInstallTest: async ({ settings, organizationId, agentId }) => {
    // Implement your pre-install test logic here
  },
  generatePaginatedResults: async function* ({ settings, organizationId, agentId }) {
    // Implement your data fetching logic in an async generator here
    // yield results as an array of { id, title, content } objects
  },
  translateContent: (content: string) => {
    // Optional: Implement your content translation logic here
    // If not provided, content will be passed through unchanged
  },
  contentType: KnowledgeDocumentContentType.Html, // Optional, defaults to HTML
  maxConcurrentDocumentCreate: 1 // Optional, defaults to 1... controls how many documents are created concurrently
});

Returned Methods

preInstall(config: IntegrationConfig): Promise

This method tests the connection to your data provider before installation.

postInstall(config: IntegrationConfig): Promise

This method creates or updates the knowledge base and syncs all data after installation.

knowledgeBaseRefreshed(config: IntegrationConfig): Promise

This method syncs all data when the knowledge base is refreshed.

Example

// src/index.ts
import MavenAGIKnowledgeBaseIntegration, { type IntegrationConfig, KnowledgeDocumentContentType } from '@mavenagi/knowledge-base-integration';

const { preInstall, postInstall, knowledgeBaseRefreshed } = 
  new MavenAGIKnowledgeBaseIntegration({
    preInstallTest: async ({ settings }: IntegrationConfig) => {
      const response = await fetch(
        `${settings.apiURL}/api/v2/test_endpoint`,
        {
          headers: {
            AUTH_HEADER: settings.authHeader
          }
        }
      );
      if (!response.ok) throw new Error('Failed to connect to API');
    },
    generatePaginatedResults: async function* ({ settings }: IntegrationConfig) {
      let nextPageUrl =
        `${settings.confluenceUrl}/api/v2/documents`;
      while (nextPageUrl) {
        const response = await fetch(nextPageUrl, {
          headers: {
            AUTH_HEADER: settings.authHeader
          }
        });
        const data = await response.json();
        yield data.results.map(({ title, id, body }) => ({ title, id, content: body.html }));
        nextPageUrl = data._links.next;
      }
    },
    translateContent: (content: string) => {
      // Optional: Implement content translation if needed
      return content;
    },
    contentType: KnowledgeDocumentContentType.Html
  })

export default {
  preInstall,
  postInstall,
  knowledgeBaseRefreshed,
  executeAction() {}
}

Development

To build the project:

npm run build

To run tests:

npm run test
1.1.1

8 months ago

1.1.0

11 months ago

1.1.2

8 months ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago