core/README.md
This module includes functions for communicating with core APIs, registering app extensions, and exporting type definitions.
// Web / extension runtime
import * as core from '@janhq/core'
Download an extension template, for example, https://github.com/janhq/extension-template.
Update the source code:
Open index.ts in your code editor.
Rename the extension class from SampleExtension to your preferred extension name.
Import modules from the core package.
import * as core from '@janhq/core'
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,
}
}
}
Build the extension:
yarn install
yarn build