0.1.11 • Published 4 months ago

@janhq/core v0.1.11

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
4 months ago

@janhq/core

This module includes functions for communicating with core APIs, registering app extensions, and exporting type definitions.

Usage

Import the package

// Web / extension runtime
import * as core from "@janhq/core";

// Node runtime
import * as node from "@janhq/core/node";

Build an Extension

  1. Download an extension template, for example, https://github.com/janhq/extension-template.

  2. Update the source code:

    1. Open index.ts in your code editor.
    2. Rename the extension class from SampleExtension to your preferred extension name.
    3. Import modules from the core package.
      import * as core from "@janhq/core";
    4. In the onLoad() method, add your code:

      // Example of listening to app events and providing customized inference logic:
      import * as core from "@janhq/core";
      
      export default class MyExtension extends BaseExtension {
        // On extension load
        onLoad() {
          core.events.on(MessageEvent.OnMessageSent, (data) => MyExtension.inference(data, this));
        }
      
        // Customized inference logic
        private static inference(incomingMessage: MessageRequestData) {
      
          // Prepare customized message content
          const content: ThreadContent = {
            type: ContentType.Text,
            text: {
              value: "I'm Jan Assistant!",
              annotations: [],
            },
          };
      
          // Modify message and send out
          const outGoingMessage: ThreadMessage = {
            ...incomingMessage,
            content
          };
        }
      }
  3. Build the extension:

    1. Navigate to the extension directory.
    2. Install dependencies.
      yarn install
    3. Compile the source code. The following command keeps running in the terminal and rebuilds the extension when you modify the source code.
      yarn build
    4. Select the generated .tgz from Jan > Settings > Extension > Manual Installation.
0.1.11

4 months ago

0.1.10

6 months ago

0.1.9

6 months ago

0.1.8

7 months ago

0.1.7

7 months ago

0.1.6

7 months ago

0.1.5

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago