Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 8 additions & 33 deletions core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,16 @@ export enum EventName {
OnDownloadError = "onDownloadError",
}

export type MessageHistory = {
role: string;
content: string;
};
/**
* The `NewMessageRequest` type defines the shape of a new message request object.
*/
export type NewMessageRequest = {
id?: string;
conversationId?: string;
user?: string;
avatar?: string;
message?: string;
createdAt?: string;
updatedAt?: string;
history?: MessageHistory[];
};

/**
* The `NewMessageRequest` type defines the shape of a new message request object.
*/
export type NewMessageResponse = {
id?: string;
conversationId?: string;
user?: string;
avatar?: string;
message?: string;
createdAt?: string;
updatedAt?: string;
};

/**
* Adds an observer for an event.
*
* @param eventName The name of the event to observe.
* @param handler The handler function to call when the event is observed.
*/
const on: (eventName: string, handler: Function) => void = (eventName, handler) => {
const on: (eventName: string, handler: Function) => void = (
eventName,
handler
) => {
window.corePlugin?.events?.on(eventName, handler);
};

Expand All @@ -59,7 +31,10 @@ const on: (eventName: string, handler: Function) => void = (eventName, handler)
* @param eventName The name of the event to stop observing.
* @param handler The handler function to call when the event is observed.
*/
const off: (eventName: string, handler: Function) => void = (eventName, handler) => {
const off: (eventName: string, handler: Function) => void = (
eventName,
handler
) => {
window.corePlugin?.events?.off(eventName, handler);
};

Expand Down
2 changes: 1 addition & 1 deletion core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ export { fs } from "./fs";
* Plugin base module export.
* @module
*/
export { JanPlugin, PluginType } from "./plugin";
export * from "./plugin";
6 changes: 3 additions & 3 deletions core/src/plugins/conversational.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Thread } from "../index";
import { JanPlugin } from "../plugin";
import { Conversation } from "../types/index";

/**
* Abstract class for conversational plugins.
Expand All @@ -17,10 +17,10 @@ export abstract class ConversationalPlugin extends JanPlugin {
/**
* Saves a conversation.
* @abstract
* @param {Conversation} conversation - The conversation to save.
* @param {Thread} conversation - The conversation to save.
* @returns {Promise<void>} A promise that resolves when the conversation is saved.
*/
abstract saveConversation(conversation: Conversation): Promise<void>;
abstract saveConversation(conversation: Thread): Promise<void>;

/**
* Deletes a conversation.
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/inference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NewMessageRequest } from "../events";
import { MessageRequest } from "../index";
import { JanPlugin } from "../plugin";

/**
Expand All @@ -21,5 +21,5 @@ export abstract class InferencePlugin extends JanPlugin {
* @param data - The data for the inference request.
* @returns The result of the inference request.
*/
abstract inferenceRequest(data: NewMessageRequest): Promise<any>;
abstract inferenceRequest(data: MessageRequest): Promise<any>;
}
229 changes: 136 additions & 93 deletions core/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,140 +1,183 @@
export interface Conversation {
id: string;
modelId?: string;
botId?: string;
name: string;
message?: string;
summary?: string;
createdAt?: string;
updatedAt?: string;
messages: Message[];
lastMessage?: string;
}
/**
* Message Request and Response
* ============================
* */

export interface Message {
id: string;
message?: string;
user?: string;
createdAt?: string;
updatedAt?: string;
/**
* The role of the author of this message.
* @data_transfer_object
*/
export enum ChatCompletionRole {
System = "system",
Assistant = "assistant",
User = "user",
}

export interface RawMessage {
/**
* The `MessageRequest` type defines the shape of a new message request object.
* @data_transfer_object
*/
export type ChatCompletionMessage = {
/** The contents of the message. **/
content?: string;
/** The role of the author of this message. **/
role: ChatCompletionRole;
};

/**
* The `MessageRequest` type defines the shape of a new message request object.
* @data_transfer_object
*/
export type MessageRequest = {
id?: string;
conversationId?: string;
user?: string;
avatar?: string;
message?: string;
/** The thread id of the message request. **/
threadId?: string;
/** Messages for constructing a chat completion request **/
messages?: ChatCompletionMessage[];
};

/**
* Thread and Message
* ========================
* */

/**
* The status of the message.
* @data_transfer_object
*/
export enum MessageStatus {
/** Message is fully loaded. **/
Ready = "ready",
/** Message is not fully loaded. **/
Pending = "pending",
}
/**
* The `ThreadMessage` type defines the shape of a thread's message object.
* @stored
*/
export type ThreadMessage = {
/** Unique identifier for the message, generated by default using the ULID method. **/
id?: string;
/** Thread id, default is a ulid. **/
threadId?: string;
/** The role of the author of this message. **/
role?: ChatCompletionRole;
/** The content of this message. **/
content?: string;
/** The status of this message. **/
status: MessageStatus;
/** The timestamp indicating when this message was created, represented in ISO 8601 format. **/
createdAt?: string;
};

/**
* The `Thread` type defines the shape of a thread object.
* @stored
*/
export interface Thread {
/** Unique identifier for the thread, generated by default using the ULID method. **/
id: string;
/** The summary of this thread. **/
summary?: string;
/** The messages of this thread. **/
messages: ThreadMessage[];
/** The timestamp indicating when this thread was created, represented in ISO 8601 format. **/
createdAt?: string;
/** The timestamp indicating when this thread was updated, represented in ISO 8601 format. **/
updatedAt?: string;
}

export interface Model {
/**
* Combination of owner and model name.
* Being used as file name. MUST be unique.
* @deprecated This field is deprecated and should not be used.
* Read from model file instead.
*/
modelId?: string;
}

/**
* Model type defines the shape of a model object.
* @stored
*/
export interface Model {
/** Combination of owner and model name.*/
id: string;
/** The name of the model.*/
name: string;
quantMethod: string;
/** Quantization method name.*/
quantizationName: string;
/** The the number of bits represents a number.*/
bits: number;
/** The size of the model file in bytes.*/
size: number;
/** The maximum RAM required to run the model in bytes.*/
maxRamRequired: number;
/** The use case of the model.*/
usecase: string;
/** The download link of the model.*/
downloadLink: string;
modelFile?: string;
/**
* For tracking download info
*/
startDownloadAt?: number;
finishDownloadAt?: number;
productId: string;
productName: string;
/** The short description of the model.*/
shortDescription: string;
/** The long description of the model.*/
longDescription: string;
/** The avatar url of the model.*/
avatarUrl: string;
/** The author name of the model.*/
author: string;
/** The version of the model.*/
version: string;
/** The origin url of the model repo.*/
modelUrl: string;
createdAt: number;
updatedAt?: number;
status: string;
/** The timestamp indicating when this model was released.*/
releaseDate: number;
/** The tags attached to the model description */
tags: string[];
}

/**
* Model type of the presentation object which will be presented to the user
* @data_transfer_object
*/
export interface ModelCatalog {
/** The unique id of the model.*/
id: string;
/** The name of the model.*/
name: string;
shortDescription: string;
/** The avatar url of the model.*/
avatarUrl: string;
/** The short description of the model.*/
shortDescription: string;
/** The long description of the model.*/
longDescription: string;
/** The author name of the model.*/
author: string;
/** The version of the model.*/
version: string;
/** The origin url of the model repo.*/
modelUrl: string;
createdAt: number;
updatedAt?: number;
status: string;
/** The timestamp indicating when this model was released.*/
releaseDate: number;
/** The tags attached to the model description **/
tags: string[];

/** The available versions of this model to download. */
availableVersions: ModelVersion[];
}
/**
* Model type which will be stored in the database
* Model type which will be present a version of ModelCatalog
* @data_transfer_object
*/
export type ModelVersion = {
/**
* Combination of owner and model name.
* Being used as file name. Should be unique.
*/
id: string;
/** The name of this model version.*/
name: string;
quantMethod: string;
/** The quantization method name.*/
quantizationName: string;
/** The the number of bits represents a number.*/
bits: number;
/** The size of the model file in bytes.*/
size: number;
/** The maximum RAM required to run the model in bytes.*/
maxRamRequired: number;
/** The use case of the model.*/
usecase: string;
/** The download link of the model.*/
downloadLink: string;
productId: string;
/**
* For tracking download state
*/
startDownloadAt?: number;
finishDownloadAt?: number;
};

export interface ChatMessage {
id: string;
conversationId: string;
messageType: MessageType;
messageSenderType: MessageSenderType;
senderUid: string;
senderName: string;
senderAvatarUrl: string;
text: string | undefined;
imageUrls?: string[] | undefined;
createdAt: number;
status: MessageStatus;
}

export enum MessageType {
Text = "Text",
Image = "Image",
ImageWithText = "ImageWithText",
Error = "Error",
}

export enum MessageSenderType {
Ai = "assistant",
User = "user",
}

export enum MessageStatus {
Ready = "ready",
Pending = "pending",
}

export type ConversationState = {
hasMore: boolean;
waitingForResponse: boolean;
error?: Error;
};
Loading